feat: Added basic shooting
This commit is contained in:
@@ -13,5 +13,6 @@ struct AABB
|
||||
function bool AABB_Collide(AABB a, AABB b);
|
||||
function bool AABB_Point(AABB a, V2f v);
|
||||
function bool AABB_Slab(V2f origin, V2f point, AABB a);
|
||||
function V2f AABB_Centre(AABB a);
|
||||
|
||||
#endif // LD_GAME_AABB_H_
|
||||
|
||||
@@ -34,3 +34,7 @@ bool AABB_Slab(V2f origin, V2f point, AABB a)
|
||||
|
||||
return tMax >= tMin;
|
||||
}
|
||||
|
||||
V2f AABB_Centre(AABB a) {
|
||||
return V2F(a.pos.x + a.size.x/2, a.pos.y + a.size.y/2);
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ void PlayerInput(SDL_Event *event, Player *player)
|
||||
// shooting
|
||||
player->bulletsLoaded -= 1;
|
||||
player->controls.shot = true;
|
||||
player->shotPos = V2F(mouseBtn.x, mouseBtn.y);
|
||||
printf("shot %f %f\n", mouseBtn.x, mouseBtn.y);
|
||||
player->shotPos = player->world->mouseProjected;
|
||||
printf("shot %f %f\n", player->shotPos.x, player->shotPos.y);
|
||||
} else if(player->reloadTimer == 0) {
|
||||
player->reloadTimer = PLAYER_RELOAD_TIME;
|
||||
printf("reloading\n");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "../world.h"
|
||||
#include "../npc.h"
|
||||
#include "../player.h"
|
||||
#include "../aabb.h"
|
||||
#include <SDL3/SDL_events.h>
|
||||
|
||||
void UpdateWorld(F32 delta, World *world)
|
||||
@@ -30,8 +31,9 @@ void ProcessEvents(SDL_Event *event, World *world)
|
||||
void RenderWorld(World *world, D_Context *draw) {
|
||||
for(U32 i = 0; i < world->npcCount; i++) {
|
||||
NPC npc = world->npcs[i];
|
||||
D_Rect(draw, npc.collision.pos.x, npc.collision.pos.y, .texture = 1);
|
||||
D_Rect(draw, npc.collision.pos.x, npc.collision.pos.y, .texture = 0, .dim = npc.collision.size);
|
||||
V2f drawPos = AABB_Centre(npc.collision);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 1);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 0, .dim = npc.collision.size, .flags = D_RECT_IGNORE_ASPECT);
|
||||
}
|
||||
D_Rect(draw, world->bandit.collision.pos.x, world->bandit.collision.pos.y, .texture = 9);
|
||||
D_Rect(draw, world->player.pos.x, world->player.pos.y, .texture = 1);
|
||||
|
||||
@@ -22,7 +22,9 @@ struct ControlState {
|
||||
typedef struct Player Player;
|
||||
struct Player
|
||||
{
|
||||
World *world;
|
||||
V2f pos;
|
||||
World_Area currentArea;
|
||||
U32 bulletsLoaded;
|
||||
ControlState controls;
|
||||
V2f shotPos;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#if !defined(LD_GAME_WORLD_H_)
|
||||
#define LD_GAME_WORLD_H_
|
||||
|
||||
#include "player.h"
|
||||
#include "npc.h"
|
||||
#include "bandit.h"
|
||||
#include "../core/math.h"
|
||||
@@ -14,10 +13,13 @@ enum World_Area {
|
||||
};
|
||||
|
||||
typedef struct World World;
|
||||
#include "player.h"
|
||||
|
||||
struct World {
|
||||
//// Static stuff
|
||||
NavMesh *navMesh;
|
||||
Random random;
|
||||
V2f mouseProjected;
|
||||
|
||||
//// Player
|
||||
Player player;
|
||||
|
||||
Reference in New Issue
Block a user