aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornathansmithsmith <thenathansmithsmith@gmail.com>2023-12-03 01:09:04 -0700
committernathansmithsmith <thenathansmithsmith@gmail.com>2023-12-03 01:09:04 -0700
commit8bd37d4fe75a43deab8d6f24b481c23d7f965c5a (patch)
tree3a606dae6993778919e2ce94c6216d2f8f74d1b2
parenta8e21e0ac702fc7bcdcaf144f384cbce8aae03d0 (diff)
More and more level stuff
-rw-r--r--src/entities/soldato.c19
-rw-r--r--src/entities/soldato.h2
-rw-r--r--src/entityGrouping.c37
-rw-r--r--src/entityGrouping.h11
-rw-r--r--src/levels/level1.c3
-rw-r--r--src/levels/level2.c3
-rw-r--r--src/levels/level3.c50
-rw-r--r--src/levels/level3.h4
-rw-r--r--src/world.h1
9 files changed, 103 insertions, 27 deletions
diff --git a/src/entities/soldato.c b/src/entities/soldato.c
index 917a615..3df328e 100644
--- a/src/entities/soldato.c
+++ b/src/entities/soldato.c
@@ -220,22 +220,3 @@ void setSoldatoLeader(Entity * entity1, Entity * entity2) {
leader->follow.followerId = follower->id;
leader->follow.followerFingerprint = follower->fingerprint;
}
-
-void addSoldatoGroupToWorld(Game * game, int groupSize, Vector3 position, Vector3 spacing) {
- int i;
- WorldEntry entries[groupSize];
-
- for (i = 0; i < groupSize; ++i)
- entries[i] = (WorldEntry){
- ENTITY_SOLDATO,
- Vector3Add(position, Vector3Multiply((Vector3){i, i, i}, spacing)),
- QuaternionIdentity()
- };
-
- addEntriesToWorld(
- &game->world,
- game,
- entries,
- sizeof(entries) / sizeof(WorldEntry)
- );
-}
diff --git a/src/entities/soldato.h b/src/entities/soldato.h
index d05a42d..392be54 100644
--- a/src/entities/soldato.h
+++ b/src/entities/soldato.h
@@ -26,6 +26,4 @@ void drawSoldato(Game * game, Entity * entity);
void setSoldatoLeader(Entity * entity1, Entity * entity2);
-void addSoldatoGroupToWorld(Game * game, int groupSize, Vector3 position, Vector3 spacing);
-
#endif
diff --git a/src/entityGrouping.c b/src/entityGrouping.c
new file mode 100644
index 0000000..1fa8a81
--- /dev/null
+++ b/src/entityGrouping.c
@@ -0,0 +1,37 @@
+#include "entityGrouping.h"
+#include "entitiesInclude.h"
+#include "game.h"
+#include "world.h"
+
+void addEntityGroupToWorld(Game * game, EntityId id, int groupSize, Vector3 position, Vector3 spacing) {
+ int i;
+ WorldEntry entries[groupSize];
+
+ for (i = 0; i < groupSize; ++i)
+ entries[i] = (WorldEntry){
+ id,
+ Vector3Add(position, Vector3Multiply((Vector3){i, i, i}, spacing)),
+ QuaternionIdentity()
+ };
+
+ addEntriesToWorld(
+ &game->world,
+ game,
+ entries,
+ sizeof(entries) / sizeof(WorldEntry)
+ );
+}
+
+void addSoldatoGroupWithLeader(Game * game, EntityId leader, int groupSize, Vector3 position, Vector3 spacing) {
+ // Add leader.
+ addEntryToWorld(&game->world, game, (WorldEntry){leader, position, QuaternionIdentity()});
+
+ // Add soldato
+ addEntityGroupToWorld(
+ game,
+ ENTITY_SOLDATO,
+ groupSize,
+ Vector3Add(position, spacing),
+ spacing
+ );
+}
diff --git a/src/entityGrouping.h b/src/entityGrouping.h
new file mode 100644
index 0000000..0ab25e8
--- /dev/null
+++ b/src/entityGrouping.h
@@ -0,0 +1,11 @@
+#include "gameCommon.h"
+#include "entity.h"
+#include <raylib.h>
+
+#ifndef ENTITY_GROUPING_H
+#define ENTITY_GROUPING_H
+
+void addEntityGroupToWorld(Game * game, EntityId id, int groupSize, Vector3 position, Vector3 spacing);
+void addSoldatoGroupWithLeader(Game * game, EntityId leader, int groupSize, Vector3 position, Vector3 spacing);
+
+#endif
diff --git a/src/levels/level1.c b/src/levels/level1.c
index 06bd518..882f314 100644
--- a/src/levels/level1.c
+++ b/src/levels/level1.c
@@ -3,6 +3,7 @@
#include "world.h"
#include "entity.h"
#include "entitiesInclude.h"
+#include "entityGrouping.h"
void initLevel1(Game * game, Levels * levels) {
int i;
@@ -47,7 +48,7 @@ bool updateLevel1(Game * game, Levels * levels) {
if (game->world.entitiesCount == 1) {
Vector3 position = Vector3Add(player->position, (Vector3){0.0, 0.0, 1000.0});
Vector3 spacing = (Vector3){0.0, 10.0, 10.0};
- addSoldatoGroupToWorld(game, 10, position, spacing);
+ addEntityGroupToWorld(game, ENTITY_SOLDATO, 10, position, spacing);
data->stage = 1;
}
diff --git a/src/levels/level2.c b/src/levels/level2.c
index 74e58c3..561ff75 100644
--- a/src/levels/level2.c
+++ b/src/levels/level2.c
@@ -3,6 +3,7 @@
#include "world.h"
#include "entity.h"
#include "entitiesInclude.h"
+#include "entityGrouping.h"
void initLevel2(Game * game, Levels * levels) {
int i;
@@ -29,7 +30,7 @@ void initLevel2(Game * game, Levels * levels) {
for (i = 0; i < sizeof(groups) / sizeof(Vector3); ++i) {
Vector3 spacing = (Vector3){0.0, 10.0, 10.0};
- addSoldatoGroupToWorld(game, 7, groups[i], spacing);
+ addEntityGroupToWorld(game, ENTITY_SOLDATO, 7, groups[i], spacing);
}
}
diff --git a/src/levels/level3.c b/src/levels/level3.c
index 799a5ee..4d688fc 100644
--- a/src/levels/level3.c
+++ b/src/levels/level3.c
@@ -1,8 +1,19 @@
#include "level3.h"
#include "game.h"
#include "world.h"
+#include "entityGrouping.h"
void initLevel3(Game * game, Levels * levels) {
+ levels->data = KF_MALLOC((sizeof(Level3)));
+
+ if (levels->data == NULL) {
+ ALLOCATION_ERROR;
+ return;
+ }
+
+ Level3 * data = (Level3*)levels->data;
+ data->stage = 0;
+
WorldEntry entries[] = {
(WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, 0.0}, QuaternionIdentity()},
(WorldEntry){ENTITY_CAPORALE, (Vector3){0.0, 0.0, 300.0}, QuaternionIdentity()}
@@ -17,12 +28,43 @@ void initLevel3(Game * game, Levels * levels) {
}
void closelevel3(Levels * levels) {
-
+ if (levels->data != NULL)
+ KF_FREE(levels->data);
}
bool updateLevel3(Game * game, Levels * levels) {
- if (game->world.entitiesCount == 1)
- return true;
+ int i;
+ Level3 * data = (Level3*)levels->data;
+ bool levelDone = false;
+
+ Vector3 groups[] = {
+ (Vector3){0.0, 0.0, 800.0},
+ (Vector3){0.0, 0.0, -800.0}
+ };
+
+ switch (data->stage) {
+ case 0:
+ if (game->world.entitiesCount == 1) {
+ Vector3 playerPosition = getEntityFromWorld(game->world, 0)->position;
+ Vector3 spacing = (Vector3){0.0, 15.0, 15.0};
+
+ for (i = 0; i < sizeof(groups) / sizeof(Vector3); ++i)
+ addSoldatoGroupWithLeader(game, ENTITY_CAPORALE, 3, Vector3Add(groups[i], playerPosition), spacing);
+
+ data->stage = 1;
+ }
+
+ break;
+ case 1:
+ if (game->world.entitiesCount == 1) {
+ levelDone = true;
+ }
+
+ break;
+ default:
+ levelDone = true;
+ break;
+ }
- return false;
+ return levelDone;
}
diff --git a/src/levels/level3.h b/src/levels/level3.h
index 85501a6..329627a 100644
--- a/src/levels/level3.h
+++ b/src/levels/level3.h
@@ -4,6 +4,10 @@
#ifndef LEVEL3_H
#define LEVEL3_H
+typedef struct Level3 {
+ int stage;
+} Level3;
+
void initLevel3(Game * game, Levels * levels);
void closelevel3(Levels * levels);
bool updateLevel3(Game * game, Levels * levels);
diff --git a/src/world.h b/src/world.h
index b364270..c28cfab 100644
--- a/src/world.h
+++ b/src/world.h
@@ -1,5 +1,6 @@
#include "gameCommon.h"
#include "entity.h"
+#include <raylib.h>
#ifndef WORLD_H
#define WORLD_H