feat: Random npc walkabouts
This commit is contained in:
@@ -63,6 +63,7 @@ int main(int argc, char **argv) {
|
|||||||
game->draw.camera = camera;
|
game->draw.camera = camera;
|
||||||
World *world = M_ArenaPush(arena, World);
|
World *world = M_ArenaPush(arena, World);
|
||||||
game->world = world;
|
game->world = world;
|
||||||
|
world->random = Random_Seed(29237489723847);
|
||||||
world->npcCount = 2;
|
world->npcCount = 2;
|
||||||
NPC *npc1 = &world->npcs[0];
|
NPC *npc1 = &world->npcs[0];
|
||||||
npc1->collision.pos.x = 15;
|
npc1->collision.pos.x = 15;
|
||||||
@@ -79,7 +80,7 @@ int main(int argc, char **argv) {
|
|||||||
npc1->collision.size.x = 10;
|
npc1->collision.size.x = 10;
|
||||||
npc1->collision.size.y = 10;
|
npc1->collision.size.y = 10;
|
||||||
|
|
||||||
NPC *npc2 = &world->npcs[0];
|
NPC *npc2 = &world->npcs[1];
|
||||||
npc2->collision.pos.x = 15;
|
npc2->collision.pos.x = 15;
|
||||||
npc2->collision.pos.y = 15;
|
npc2->collision.pos.y = 15;
|
||||||
npc2->collision.size.x = 10;
|
npc2->collision.size.x = 10;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "game/npc.h"
|
#include "game/npc.h"
|
||||||
#include "game/world.h"
|
#include "game/world.h"
|
||||||
#include "core/types.h"
|
#include "core/types.h"
|
||||||
|
#include "core/math.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@@ -10,8 +11,8 @@ void updateNPC(F32 delta, NPC *npc, World *world) {
|
|||||||
npc->waitTime+=delta;
|
npc->waitTime+=delta;
|
||||||
if(npc->waitTime > npc->maxWaitTime) {
|
if(npc->waitTime > npc->maxWaitTime) {
|
||||||
npc->mode = NPC_ACTION_WALKING;
|
npc->mode = NPC_ACTION_WALKING;
|
||||||
U32 next = npc->targetNavNode == 100 ? 20 : 100;
|
// TODO change targets to poi's rather than just random nodes
|
||||||
npc->targetNavNode = next; // TODO RANDOM
|
npc->targetNavNode = Random_U32(&world->random, 0, world->navMesh->nodeCount);
|
||||||
printf("Starting to nav path\n");
|
printf("Starting to nav path\n");
|
||||||
npc->path = Nav_Path(world->navMesh, npc->currentNavNode, npc->targetNavNode);
|
npc->path = Nav_Path(world->navMesh, npc->currentNavNode, npc->targetNavNode);
|
||||||
printf("done\n");
|
printf("done\n");
|
||||||
@@ -26,7 +27,7 @@ void updateNPC(F32 delta, NPC *npc, World *world) {
|
|||||||
if(npc->path.nodeCount == npc->pathIndex+1){
|
if(npc->path.nodeCount == npc->pathIndex+1){
|
||||||
printf("Finished! so I'm waiting\n");
|
printf("Finished! so I'm waiting\n");
|
||||||
npc->mode = NPC_ACTION_WAITING;
|
npc->mode = NPC_ACTION_WAITING;
|
||||||
npc->maxWaitTime = 20; // TODO RANDOM
|
npc->maxWaitTime = Random_F32(&world->random, 10, 40);
|
||||||
npc->waitTime = 0;
|
npc->waitTime = 0;
|
||||||
npc->pathIndex = 0;
|
npc->pathIndex = 0;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "npc.h"
|
#include "npc.h"
|
||||||
#include "bandit.h"
|
#include "bandit.h"
|
||||||
|
#include "../core/math.h"
|
||||||
|
|
||||||
// Areas are which
|
// Areas are which
|
||||||
typedef U32 World_Area;
|
typedef U32 World_Area;
|
||||||
@@ -16,6 +17,7 @@ typedef struct World World;
|
|||||||
struct World {
|
struct World {
|
||||||
//// Static stuff
|
//// Static stuff
|
||||||
NavMesh *navMesh;
|
NavMesh *navMesh;
|
||||||
|
Random random;
|
||||||
|
|
||||||
//// Player
|
//// Player
|
||||||
Player player;
|
Player player;
|
||||||
|
|||||||
Reference in New Issue
Block a user