1

QUESTION ABOUT COLLISION DETECTION AND GRID PARAMETERS

This is what I use for movement

location_x=display_width/2
location_y=display_height/2
moveY=0
moveX=0

and then whenever W A S or D are pressed moveX or moveY changes, and location_x+=moveX and location_y+=moveY. You get the picture.

Essentially this is the collision detection

    bottomleft=location_y+50
    if location_x>=ball_x and location_x<(ball_x+25) and location_y>=ball_y and location_y<(ball_y+25):
       print("TOP LEFT CROSSOVER")
    if location_x+34>=ball_x and location_x+34<(ball_x+25) and location_y>=ball_y and location_y<(ball_y+25):
        print("TOP RIGHT CROSSOVER")
    if bottomleft>=ball_x and bottomleft<(ball_x+25) and bottomleft>=ball_y and bottomleft<(ball_y+25):
        print("BOTTOM LEFT CROSSOVER")

Basically the TOP LEFT CROSSOVER and the TOP RIGHT CROSSOVER work. How the code works is it basically sets lines on a grid. If this point is above this line and below that one and left of this one and right of that one then print.

I am trying to do the same collision detection for the bottom right hand corner of the sprite, however it seems to be very buggy and just doesnt work.

I am referencing this point with the location_y+50, which gets the bottom left point of the sprite (the sprite is 50 px tall). As far as I'm aware with these parameters four lines should be drawn and the collision should be detected. Is there something obvious I'm missing?

0 Answers0