diff options
author | NielsCoding <48092678+heavydemon21@users.noreply.github.com> | 2023-03-15 15:37:21 +0100 |
---|---|---|
committer | NielsCoding <48092678+heavydemon21@users.noreply.github.com> | 2023-03-15 15:37:21 +0100 |
commit | 3891486b368f4cdd1c5e00019a2a66ca05e656e6 (patch) | |
tree | cd27ef74ef917bed16c90be9552dd007b4a7f2b5 /src/engine/bullet.c | |
parent | 67bbe8dc3e7e0eb5eeb00b84f9766ef3d3b6b4b4 (diff) |
game loop and bullet
TODO game loop:
-(startingscreen) read correct indexes
-(shop) read correct indexes
-gameplay still needs alot with different levels etc..
rest not yet done
bullet needs testing and correct PAL and tilemap reading
Diffstat (limited to 'src/engine/bullet.c')
-rw-r--r-- | src/engine/bullet.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/engine/bullet.c b/src/engine/bullet.c new file mode 100644 index 0000000..eafd4e7 --- /dev/null +++ b/src/engine/bullet.c @@ -0,0 +1,39 @@ +#include "bullet.h" +#include "engine/sprite_controller.h" + +void shootBullet(vec2 playerPos, Bullet* bullet){ + // Set bullet's x and y coordinates to player's coordinates + bullet->x = playerPos.x; + bullet->y = playerPos.y; + // Set bullet's velocity to a fixed value + bullet->velocity = 1; + // Set bullet's status to active + bullet->isActive = true; +} +void updateBullet(Bullet* bullet, int deltaTime){ + // Only update bullet if it is active + static int latestLocationBullet = 0; + if (bullet->isActive) { + // Move bullet based on velocity and deltaTime + bullet->x += bullet->velocity * deltaTime; + drawBullet(bullet); + // Check if bullet has moved 16 pixels + if (bullet->x - latestLocationBullet > 16) { + // Set bullet's status to inactive + bullet->isActive = false; + } + } + else{ + latestLocationBullet = bullet->x; + } +} +void drawBullet(Bullet* bullet){ + + hh_ppu_update_foreground(1, (hh_s_ppu_loc_fam_entry) + { + .horizontal_flip = false, + .vertical_flip = false, + .palette_index = 7, + .tilemap_index = 2, // change tilemap to the correct foreground index; + }); +} |