feat: Initial bandit roaming

This commit is contained in:
2025-10-05 21:05:29 +01:00
parent b8f47b8f61
commit 635e7b1c1e
8 changed files with 104 additions and 23 deletions

View File

@@ -1,9 +1,11 @@
#include "../player.h"
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_keycode.h>
#include <stdio.h>
void PlayerInput(SDL_Event *event, Player *player)
{
player->controls.shot = false;
SDL_KeyboardEvent key = event->key;
SDL_MouseButtonEvent mouseBtn = event->button;
if(event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP) {
@@ -32,11 +34,21 @@ void PlayerInput(SDL_Event *event, Player *player)
}
}
}
if (mouseBtn.clicks == 1)
{
// shooting
player->bulletsLoaded -= 1;
}
if (
event->type == SDL_EVENT_MOUSE_BUTTON_DOWN
&& mouseBtn.button == SDL_BUTTON_LEFT
) {
if(player->bulletsLoaded > 0) {
// shooting
player->bulletsLoaded -= 1;
player->controls.shot = true;
player->shotPos = V2F(mouseBtn.x, mouseBtn.y);
printf("shot %f %f\n", mouseBtn.x, mouseBtn.y);
} else if(player->reloadTimer == 0) {
player->reloadTimer = PLAYER_RELOAD_TIME;
printf("reloading\n");
};
}
}
void PlayerUpdate(F32 delta, Player *player) {
@@ -53,6 +65,13 @@ void PlayerUpdate(F32 delta, Player *player) {
if(player->controls.rightDown) {
dir.x += 1;
}
if(player->reloadTimer > 0) {
player->reloadTimer-=delta;
if(player->reloadTimer <= 0) {
player->bulletsLoaded = PLAYER_BULLET_COUNT;
player->reloadTimer = 0;
}
}
dir = V2f_Scale(NormaliseV2F(dir), PLAYER_SPEED*delta);
player->pos.x += dir.x;
player->pos.y += dir.y;