Week 5 – Enemy hitboxes and death
|
New week, new assignments and my focus this time was on successfully managing to get the enemy hitbox to work with the players bullets as well as getting the enemy to “die” after getting hit by the projectiles. This was supposed to be done last week, be due to the amount of work we had left to do we had to cut some things out. However we had to prioritize those cut assets this week since they were a must for the alpha to be shipped. Firstly I had to decide what kind of hitboxing we wanted for our game and I had two versions in mind. Firstly the standard intersecting bounding boxes which works by checking if area x intersects with area y. Which is an if statement as well, so if they are intersecting you can make pretty much anything happen. Easier to make, easier to use. But isn’t exactly as The other “hitbox” i was thinking about creating was a circular one which works almost in the same way as a bounding box. However, it uses a cosinus and sinus equation which constantly checks the direction to the object you want it to be able to collide with. Since it checks the distance constantly it’s more fitting to use it where there aren’t that many objects. But since I was trying to get all shot projectiles to be able to collide with the enemy. It would drain too much on the memory to justify the somewhat better hitbox. So I decided to use the intersecting bounding boxes instead of a circular one and the first thing I had to do was to create a box that had the same size as each of the sprites we used. So I created one rectangle for the enemy and one for the projectile and used getGlobalBounds to get the global bounding rectangle of the said entity. After that I made it so that if they were to intersect, the enemy would take an x amount of damage and each of the projectiles that hit would get deleted. Since we already had a life function for the enemy all I had to do was to point to that function and say that it would go down by x amount. If the life went down to equal to 0 or below the enemy would die (get deleted). Same thing with the projectiles. We already had a way to delete them, so all I did was to point at that certain function and it deleted the projectiles everytime they hit the other hitbox. However, some minor adjustments needs to be made on the enemy hitbox since it’s way too big in the front.
|
