Skip to content

Commit

Permalink
add pig
Browse files Browse the repository at this point in the history
  • Loading branch information
computermouth committed Nov 7, 2023
1 parent 059cfa2 commit d7d5b4d
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 13 deletions.
4 changes: 2 additions & 2 deletions entity_demon.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#ifndef ENTITY_ENEMY_DEMON_H
#define ENTITY_ENEMY_DEMON_H
#ifndef ENTITY_DEMON_H
#define ENTITY_DEMON_H

#include "entity.h"

Expand Down
145 changes: 145 additions & 0 deletions entity_minobaur.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@

#include "entity.h"
#include "game.h"
#include "audio.h"
#include "map.h"
#include "vector.h"

void entity_minobaur_init(entity_t * e);
void entity_minobaur_update(entity_t * e);

animation_t minobaur_animations[] = {
{ // 0: T pose
.time = 0.5,
.num_frames = 1,
.frames = (animation_frame_t[]) {
{.name = "default"},
},
},
{ // 1: Swipe
.time = 0.09,
.num_frames = 20,
.frames = (animation_frame_t[]) {
{.name = "swipe.000"},
{.name = "swipe.001"},
{.name = "swipe.002"},
{.name = "swipe.003"},
{.name = "swipe.004"},
{.name = "swipe.005"},
{.name = "swipe.006"},
{.name = "swipe.007"},
{.name = "swipe.008"},
{.name = "swipe.009"},
{.name = "swipe.010"},
{.name = "swipe.011"},
{.name = "swipe.012"},
{.name = "swipe.013"},
{.name = "swipe.014"},
{.name = "swipe.015"},
{.name = "swipe.016"},
{.name = "swipe.017"},
{.name = "swipe.018"},
{.name = "swipe.019"},
},
},
{ // 2: Charge
.time = 0.10,
.num_frames = 5,
.frames = (animation_frame_t[]) {
{.name = "charge.000"},
{.name = "charge.001"},
{.name = "charge.002"},
{.name = "charge.003"},
{.name = "charge.004"},
},
},
{ // 3: Land
.time = .50,
.num_frames = 7,
.frames = (animation_frame_t[]) {
{.name = "land.000"},
{.name = "land.000"},
{.name = "land.000"},
{.name = "land.000"},
{.name = "land.001"},
{.name = "land.002"},
{.name = "land.003"},
{.name = "land.004"},
{.name = "swipe.000"},
},
},
{ // 4: Die
.time = 0.15,
.num_frames = 20,
.frames = (animation_frame_t[]) {
{.name = "die.000"},
{.name = "die.001"},
{.name = "die.002"},
{.name = "die.003"},
{.name = "die.004"},
{.name = "die.005"},
{.name = "die.006"},
{.name = "die.007"},
{.name = "die.008"},
{.name = "die.009"},
{.name = "die.010"},
{.name = "die.011"},
{.name = "die.012"},
{.name = "die.013"},
{.name = "die.013"},
{.name = "die.013"},
{.name = "die.013"},
{.name = "die.013"},
{.name = "die.013"},
{.name = "die.013"},
},
},
{ // 5: Bump
.time = 0.12,
.num_frames = 9,
.frames = (animation_frame_t[]) {
{.name = "bump.000"},
{.name = "bump.001"},
{.name = "bump.002"},
{.name = "bump.003"},
{.name = "bump.004"},
{.name = "bump.005"},
{.name = "bump.006"},
{.name = "bump.007"},
{.name = "bump.008"},
},
},
};

// hack for caching parsed frame names per-map
static ref_entt_t * last_ref_entt = NULL;

void entity_minobaur_constructor(entity_t * e) {
entity_constructor(e);
e->_update = entity_minobaur_update;
entity_minobaur_init(e);
}

void entity_minobaur_init(entity_t * e) {

entity_parse_animation_frames(
e->_params->entity_generic_params.ref_entt,
minobaur_animations,
sizeof(minobaur_animations)/sizeof(minobaur_animations[0]),
&last_ref_entt
);

e->_animation_collection = (animation_collection_t) {
.animations = minobaur_animations,
.num_animations = sizeof(minobaur_animations)/sizeof(minobaur_animations[0]),
};

e->_anim = &(e->_animation_collection.animations[1]);
e->_anim_time = 0;

entity_set_model(e);
}

void entity_minobaur_update(entity_t * e) {
e->_draw_model(e);
}
10 changes: 10 additions & 0 deletions entity_minobaur.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#ifndef ENTITY_MINOBAUR_H
#define ENTITY_MINOBAUR_H

#include "entity.h"

void entity_minobaur_constructor(entity_t *e);
void entity_minobaur_update(entity_t * e);

#endif
39 changes: 29 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "text.h"
#include "vector.h"
#include "entity_demon.h"
#include "entity_minobaur.h"

void game_load() {
// text has to come before render init
Expand Down Expand Up @@ -53,20 +54,35 @@ text_surface_t * c1k3 = NULL;
text_surface_t * dq = NULL;
text_surface_t * dennis = NULL;
entity_t * demon = NULL;
entity_t * minobaur = NULL;

void menu_init() {
// set level to menu
map_set_level(2);

entity_params_t d = {
.id = ENTITY_ID_DEMON,
.position = vec3(0,-12,-18),
.entity_generic_params.ref_entt = map_ref_entt_from_eid(ENTITY_ID_DEMON),
};
demon = calloc(sizeof(entity_t), 1);
demon->_params = &d;
demon->_yaw = PI * 36.0f/40.0f;
entity_demon_constructor(demon);
{
entity_params_t d = {
.id = ENTITY_ID_DEMON,
.position = vec3(0,-12,-18),
.entity_generic_params.ref_entt = map_ref_entt_from_eid(ENTITY_ID_DEMON),
};
demon = calloc(sizeof(entity_t), 1);
demon->_params = &d;
demon->_yaw = PI * 36.0f/40.0f;
entity_demon_constructor(demon);
}

{
entity_params_t mb = {
.id = ENTITY_ID_MINOBAUR,
.position = vec3(0,0,32),
.entity_generic_params.ref_entt = map_ref_entt_from_eid(ENTITY_ID_MINOBAUR),
};
minobaur = calloc(sizeof(entity_t), 1);
minobaur->_params = &mb;
minobaur->_yaw = PI;
entity_minobaur_constructor(minobaur);
}
}

void menu_run(float time_now) {
Expand Down Expand Up @@ -107,7 +123,8 @@ void menu_run(float time_now) {

r_prepare_frame(0.0f, 0.0f, 0.0f);

entity_demon_update(demon);
// entity_demon_update(demon);
entity_minobaur_update(minobaur);

// ref_entt_t * re = map_ref_entt_from_eid(ENTITY_ID_TORCH);
// uint32_t * uframes = vector_begin(re->frames);
Expand Down Expand Up @@ -240,6 +257,8 @@ int main(int argc, char* argv[]) {
text_free_surface(dennis);
if (demon)
free(demon);
if (minobaur)
free(minobaur);
}

// perform based on state
Expand Down
4 changes: 4 additions & 0 deletions map.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "entity_pickup_key.h"
#include "entity_torch.h"
#include "entity_demon.h"
#include "entity_minobaur.h"

#include "mpack.h"
#include "vector.h"
Expand Down Expand Up @@ -156,6 +157,9 @@ void map_init() {
map_entity_table[ENTITY_ID_DEMON] = (map_entity_table_t) {
"demon", entity_demon_constructor
};
map_entity_table[ENTITY_ID_MINOBAUR] = (map_entity_table_t) {
"minobaur", entity_minobaur_constructor
};
}

typedef void (*constfunc)(entity_t *);
Expand Down
1 change: 1 addition & 0 deletions map.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef enum {
ENTITY_ID_GIBS005,
ENTITY_ID_GIBS006,
ENTITY_ID_DEMON,
ENTITY_ID_MINOBAUR,
__ENTITY_ID_END,
} entity_id_t;

Expand Down

0 comments on commit d7d5b4d

Please sign in to comment.