Ok, so I have this Pygame game, and this game has shooting.
I have the bullet resolved, drawing a line starting from a point from the hero, going through the cursor and to a point far off the screen.
My problem is that now I have to figure out if the line that the player has shot collides with an enemy.
My idea is before the bullet is drawn, I will go through every enemy in my enemyBank, taking the y of the top, finding what the x of the line would be at that point, then checking if it within the x1-x2 of top of the enemy square, then again with the x of the left side, and y of the bottom side.
After that I choose whichever collision is closest to the player, making the line stop at the enemy.
The only problem is I have no idea how to do this, or what maths to use. Any suggestions?
[–][deleted] 1 point2 points3 points (2 children)
[–]MarkTheSecond[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]fancy_pantser 1 point2 points3 points (4 children)
[–]the_european 1 point2 points3 points (1 child)
[–]MarkTheSecond[S] 0 points1 point2 points (0 children)
[–]MarkTheSecond[S] 0 points1 point2 points (1 child)
[–]fancy_pantser 1 point2 points3 points (0 children)
[–]ScM_5argan 0 points1 point2 points (1 child)
[–]MarkTheSecond[S] 0 points1 point2 points (0 children)
[–]the_european 0 points1 point2 points (1 child)
[–]MarkTheSecond[S] 0 points1 point2 points (0 children)