0

Again this question is on PyParticles4.
Link to last question for reference

Comment if unclear...

I am working on a Shooter game, much like this, but on a flat land with a wall that varies it's height on every turn(something for fun in the game) and with 2 players,each with a cannon that can move some distance (there's a limit, and they can't move beyond a certain amount from their start position) on each turn(the player decides if he wishes to move).

My code:

class Bullet(PyParticles.Particle):
    def hit_s(self,shooterlist):
        for shoot in shooterlist:
            #collision with the rect
            dist = math.hypot(dx,dy)
    def hit_w(self,wall):
-------------------------
        #confusion
-------------------------
    # other funcs to added
class Shooter:
    def __init__(self,pos,size):
        self.rect = pygame.Rect(pos,size)
    # other funcs to added
class Wall:
    def __init__(self,(sx,sy),(ex,ey),width):
        self.start = (sx,sy)
        self.end = (ex,ey)
        self.width = width
# (things needed for pygame.draw.line()).

My Problems

Collision of the bullet with the Wall. Any Ideas on how to know when the bullet hits the wall?

I think something faster would be better..

Also, if the ball hits the wall, the ball should bounce back so it has a chance to hit the player who shot it at first(Strong Wall!), and so the wall doesn't get cut, like in the game(mentioned at the start).

Community
  • 1
  • 1
pradyunsg
  • 18,287
  • 11
  • 43
  • 96
  • how about using rect collision to filter out most of the frames, and the use cos and sine to see if the bullet has collided? – Bartlomiej Lewandowski Jan 11 '13 at 10:36
  • Line Circle collision detection: http://devmag.org.za/2009/04/17/basic-collision-detection-in-2d-part-2/ , Bouncing off varible angled surfaces: http://stackoverflow.com/a/2845106/341744 – ninMonkey Jan 11 '13 at 10:36
  • @monkey The collision detection is the problem, not the movement after collision. – pradyunsg Jan 11 '13 at 10:39
  • @monkey Point is subtracted from another point, what does that mean? (on the [site](http://devmag.org.za/2009/04/17/basic-collision-detection-in-2d-part-2/)) Is it the distance between the two points?? – pradyunsg Jan 11 '13 at 10:55
  • Will the wall always be vertical (x values the same), or will it sometimes be diagonal? – ThisIsAQuestion Jan 11 '13 at 17:56
  • Oh, I posted that link because I thought the wall rotated. For horizontal walls just multiply `yvelocity * -1`. For vertical multiply `xvelocity * -1` on collision. That will bounce. – ninMonkey Jan 11 '13 at 19:31

0 Answers0