feat: different rooms added
feat: shooting bandit added
This commit is contained in:
11
code/first.c
11
code/first.c
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/types.h"
|
||||
#include "game/npc.h"
|
||||
#include "os/core.h"
|
||||
|
||||
#include "vulkan/core.h"
|
||||
@@ -77,7 +76,7 @@ int main(int argc, char **argv)
|
||||
World *world = M_ArenaPush(arena, World);
|
||||
game->world = world;
|
||||
world->random = Random_Seed(29237489723847);
|
||||
world->npcCount = 1;
|
||||
world->npcCount = 2;
|
||||
for(U32 i = 0; i < world->npcCount; i++) {
|
||||
NPC *npc1 = &world->npcs[i];
|
||||
npc1->collision.pos.x = 15;
|
||||
@@ -86,16 +85,17 @@ int main(int argc, char **argv)
|
||||
npc1->collision.size.y = 2;
|
||||
npc1->name = S("Matt");
|
||||
npc1->mode = NPC_ACTION_WAITING;
|
||||
npc1->currentArea = i;
|
||||
npc1->waitTime = 0;
|
||||
npc1->maxWaitTime = 5000;
|
||||
npc1->maxWaitTime = 5;
|
||||
npc1->currentNavNode = 0;
|
||||
}
|
||||
|
||||
Bandit *badman = &world->bandit;
|
||||
badman->collision.pos.x = 15;
|
||||
badman->collision.pos.y = 15;
|
||||
badman->collision.size.x = 10;
|
||||
badman->collision.size.y = 10;
|
||||
badman->collision.size.x = 1;
|
||||
badman->collision.size.y = 2;
|
||||
badman->name = S("Leroy Brown");
|
||||
badman->mode = BANDIT_WAITING;
|
||||
badman->waitTime = 0;
|
||||
@@ -111,6 +111,7 @@ int main(int argc, char **argv)
|
||||
world->player.pos.y = 0;
|
||||
world->player.bulletsLoaded = PLAYER_BULLET_COUNT;
|
||||
world->player.reloadTimer = 0;
|
||||
world->player.currentArea = 0;
|
||||
}
|
||||
|
||||
bool running = true;
|
||||
|
||||
@@ -14,6 +14,7 @@ struct Bandit {
|
||||
//// Personal
|
||||
AABB collision;
|
||||
Str8 name;
|
||||
World_Area currentArea;
|
||||
|
||||
//// Actions
|
||||
BANDIT_ACTION mode;
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
#include "game/bandit.h"
|
||||
|
||||
void UpdateBandit(F32 delta, Bandit *bandit, World *world) {
|
||||
if(
|
||||
world->player.controls.shot
|
||||
&& AABB_Point(bandit->collision, world->player.shotPos)
|
||||
&& bandit->currentArea == world->player.currentArea
|
||||
) {
|
||||
printf("You shot the bandit %*.s\n", Sv(bandit->name));
|
||||
bandit->health--;
|
||||
}
|
||||
switch (bandit->mode) {
|
||||
case BANDIT_WAITING:
|
||||
bandit->waitTime+=delta;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
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) {
|
||||
@@ -52,6 +51,7 @@ void PlayerInput(SDL_Event *event, Player *player)
|
||||
}
|
||||
|
||||
void PlayerUpdate(F32 delta, Player *player) {
|
||||
player->controls.shot = false;
|
||||
V2f dir = V2F(0, 0);
|
||||
if(player->controls.upDown) {
|
||||
dir.y -= 1;
|
||||
|
||||
@@ -15,10 +15,14 @@ void UpdateNPCs(F32 delta, World *world)
|
||||
{
|
||||
for (U32 i = 0; i < world->npcCount; i++)
|
||||
{
|
||||
UpdateNPC(delta, &world->npcs[i], world);
|
||||
if(world->player.controls.shot && AABB_Point(world->npcs[i].collision, world->player.shotPos)) {
|
||||
// TODO we need to unproject the mouse location !!!
|
||||
printf("You shot %.*s\n", Sv(world->npcs[i].name));
|
||||
NPC *npc = &world->npcs[i];
|
||||
UpdateNPC(delta, npc, world);
|
||||
if(
|
||||
world->player.controls.shot
|
||||
&& AABB_Point(npc->collision, world->player.shotPos)
|
||||
&& npc->currentArea == world->player.currentArea
|
||||
) {
|
||||
printf("You shot %*.s\n", Sv(world->npcs[i].name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,11 +35,17 @@ 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];
|
||||
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);
|
||||
if(npc.currentArea == world->player.currentArea) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
if(world->bandit.currentArea == world->player.currentArea) {
|
||||
V2f drawPos = AABB_Centre(world->bandit.collision);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 9);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 0, .dim = world->bandit.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,6 +22,7 @@ struct NPC {
|
||||
AABB collision;
|
||||
Str8 name;
|
||||
NPC_LOOK look;
|
||||
World_Area currentArea;
|
||||
|
||||
bool customPOI;
|
||||
U32 customPOICount;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#if !defined(LD_GAME_WORLD_H_)
|
||||
#define LD_GAME_WORLD_H_
|
||||
|
||||
#include "npc.h"
|
||||
#include "bandit.h"
|
||||
#include "../core/math.h"
|
||||
|
||||
// Areas are which
|
||||
@@ -14,6 +12,8 @@ enum World_Area {
|
||||
|
||||
typedef struct World World;
|
||||
#include "player.h"
|
||||
#include "npc.h"
|
||||
#include "bandit.h"
|
||||
|
||||
struct World {
|
||||
//// Static stuff
|
||||
|
||||
Reference in New Issue
Block a user