-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
255 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#ifndef _rockets_entitites_h | ||
#define _rockets_entitites_h | ||
|
||
// Entities | ||
typedef enum {EntityType_NAH, | ||
EntityType_SHIP, | ||
EntityType_BOUNDRY, | ||
EntityType_GOAL} EntityType; | ||
|
||
typedef enum {EntityFlag_COLLIDES = (1 << 0)} EntityFlag; | ||
|
||
// Start with a special case of just having all collision geometry be rectangles. | ||
// For now going to have rotation be about the entitiy's position. Makes math easy | ||
// and seems to make sense for things that are going to move around. | ||
|
||
// @NOTE: This is basically the same as bounding box but the names are different because this is | ||
// a different way to describe a rectangle. | ||
typedef struct { | ||
union { | ||
struct {float x, y;}; | ||
V2 offset; | ||
}; | ||
union { | ||
struct {float width, height; }; | ||
V2 size; | ||
}; | ||
} CollisionRect; | ||
|
||
|
||
// How do I determine entity equality? Just pointer equality? | ||
typedef struct entity_ { | ||
EntityType type; | ||
uint32_t flags; | ||
|
||
V2 position; | ||
int rotation; | ||
Thrusters thrusters; | ||
|
||
V2 velocity; | ||
|
||
// @TODO: I think I should probably use a memory area for this instead of allocating | ||
// 10 slots for every entity. Many will just have 1 piece and lots won't have any. | ||
// If I have a memory area I can track memory usage in it too. | ||
// Also could let me pack all collision pieces in a single array which might be dope | ||
// if I want to SIMD my collision checking. | ||
int num_collision_pieces; | ||
CollisionRect collision_pieces[10]; | ||
|
||
struct entity_* next_entity; | ||
} Entity; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// @NOTE: This is just so flymake doesn't get mad. | ||
#include "rockets.h" | ||
|
||
// Loads the entites for a given level. | ||
// @TODO: Handle boarders. | ||
void load_level(GameState* state, int level_number) | ||
{ | ||
memset(state->entities, 0, sizeof(Entity) * ARRAY_COUNT(state->entities)); | ||
state->num_entities = 0; | ||
state->first_free_entity = NULL; | ||
state->current_level = level_number; | ||
|
||
LevelSpec spec = get_level_spec(level_number); | ||
|
||
for (int i = 0; i < spec.num_entity_specs; i++) { | ||
EntitySpec entity = spec.entity_specs[i]; | ||
|
||
switch(entity.type) { | ||
case(ES_PLAYER_SHIP): { | ||
Entity* ship = push_entity(state); | ||
ship->type = EntityType_SHIP; | ||
ship->position = entity.position; | ||
ship->rotation = 0; | ||
|
||
entity_add_flags(ship, EntityFlag_COLLIDES); | ||
|
||
CollisionRect* s1 = &ship->collision_pieces[ship->num_collision_pieces++]; | ||
s1->offset = v2(-10, -15); | ||
s1->size = v2(20, 40); | ||
CollisionRect* s2 = &ship->collision_pieces[ship->num_collision_pieces++]; | ||
s2->offset = v2(-20, -25); | ||
s2->size = v2(15, 30); | ||
CollisionRect* s3 = &ship->collision_pieces[ship->num_collision_pieces++]; | ||
s3->offset = v2(5, -25); | ||
s3->size = v2(15, 30); | ||
|
||
} break; | ||
case(ES_GOAL): { | ||
Entity* goal = push_entity(state); | ||
goal->type = EntityType_GOAL; | ||
goal->position = entity.position; | ||
goal->rotation = 0; | ||
|
||
entity_add_flags(goal, EntityFlag_COLLIDES); | ||
|
||
CollisionRect* g = &goal->collision_pieces[goal->num_collision_pieces++]; | ||
g->offset = v2(-10, -10); | ||
g->size = v2(20, 20); | ||
} break; | ||
} | ||
} | ||
} |
Oops, something went wrong.