collision

PyGame Collision?

半城伤御伤魂 提交于 2019-12-17 20:10:35
问题 How do I find collisions between characters and images within PyGame? I have drawn a player from an image, and have drawn the walls from tiles, so how would I detect these collisions? 回答1: If you use the pygame Rect class to represent the boundaries of your object, you can detect whether two are colliding by using the Rect.colliderect function. For example: import pygame a = pygame.Rect((1, 1), (2, 2)) b = pygame.Rect((0, 0), (2, 2)) c = pygame.Rect((0, 0), (1, 1)) a.colliderect(b) # 1 a

2d html5 canvas collision, howto

安稳与你 提交于 2019-12-17 19:57:18
问题 As the title suggests, I am having trouble with object collision... I am currently working on a 2d Html5 canvas game using JavaScript. I know how to keep the "player" object from going outside the width/height of the game canvas, and i know how to do something when the player collides with an object (such as a power up or enemy or whatever) but i just don't know how to make a "solid" object meaning when the player hits the solid object, the player just stops, and cannot go through the solid

How do I avoid name collision with macros defined in Windows header files?

廉价感情. 提交于 2019-12-17 19:33:09
问题 I have some C++ code that includes a method called CreateDirectory(). Previously the code only used STL and Boost, but I recently had to include <windows.h> so I could look-up CSIDL_LOCAL_APPDATA . Now, this code: filesystem.CreateDirectory(p->Pathname()); // Actually create it... No longer compiles: error C2039: 'CreateDirectoryA' : is not a member of ... Which corresponds to this macro in winbase.h : #ifdef UNICODE #define CreateDirectory CreateDirectoryW #else #define CreateDirectory

Detecting collision of two sprites that can rotate [duplicate]

牧云@^-^@ 提交于 2019-12-17 03:44:11
问题 This question already has answers here : How to check intersection between 2 rotated rectangles? (10 answers) Closed 5 years ago . I have a problem with collision detection in a 2D Java game. Normally, what I would do is create a getBounds() method for an object that can collide with other objects. This method would return a new Rectangle(x,y,width,height) , where x and y are the coordinates for the top-left corner of the sprite, and width and height are the width and height of the sprite.

HashSet Collisions in Java

主宰稳场 提交于 2019-12-14 00:47:05
问题 I have a program for my Java class where I want to use hashSets to compare a directory of text documents. Essentially, my plan is to create a hashSet of strings for each paper, and then add two of the papers hashSets together into one hashSet and find the number of same 6-word sequences. My question is, do I have to manually check for, and handle, collisions, or does Java do that for me? 回答1: Java Hash Maps/Sets Automatically handel Hash collisions, this is why it is important to override

How do I have an object rebound off the canvas border?

早过忘川 提交于 2019-12-13 23:33:44
问题 I am using the canvas widget from tkinter to create an ellipse and have it move around in the canvas. However when the ellipse comes in contact with the border it gets stuck to wall instead of bouncing off. I'm struggling with debugging the code, thanks in advance! from tkinter import * from time import * import numpy as np root = Tk() root.wm_title("Bouncing Ball") canvas = Canvas(root, width=400, height=400, bg="black") canvas.grid() size=10 x = 50 y = 50 myBall = canvas.create_oval(x-size,

Shooting. Collision of the shot with a collection of List

放肆的年华 提交于 2019-12-13 23:00:00
问题 I'm making for learning purpose a space invaders clone. I'm stuck on the issue when an invader got shot. I'm not sure when there is a collision of a bullet with a part of the invader(who is a list of positions) how to erase it and the game to continue. Has anyone got an idea? Here is the code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SpaceInvader { class Program { static void Main() {

My collision detection isn't working

有些话、适合烂在心里 提交于 2019-12-13 08:56:12
问题 I'm trying to make a simple game where you are pacman and need to collect cherries while avoiding the ghosts. I can't seem to figure out how to check for collision and i've tried searching through other questions but none of them work. Here is my code: <script language="javascript" src="http://code.jquery.com/jquery-1.11.3.js"></script> <script language="javascript"> var pacman = { speed: 256, x: 0, y: 0, height: 50, width: 50 }; var blinky = { x: 0, y: 0 }; var inky = { x: 0, y: 0 }; var

Collision detection (CGRectIntersectRect)

点点圈 提交于 2019-12-13 08:19:37
问题 I have two images: first image size is 50x85 and second image size is 50x113. When I touch the screen image goes up and second image is shown and when I release the screen image goes down and first image is shown. Now the problem is when I'm touching the screen collision happens earlier than when I'm not touching the screen. How could I make that in second image about 30px at bottom won't collide, but image will still be there? Edit: Here is some of the code: -(void)AstronautMove { [self

Powerups not colliding with player (Pygame)

感情迁移 提交于 2019-12-12 04:58:00
问题 I've been having trouble getting my powerups to disappear upon colliding with the player character. I've been able to get powerups to drop upon killing enemies with bullets, but I can't seem to collect them. I've listed my project so far. I've tried messing with a couple functions (pygame.sprite.spritecollide() and pygame.rect.colliderect()) but neither seemed to work. I can't seem to figure out if the problem is in my Player or Power class or in the "while" loop at the bottom. import pygame,