Skip to content

Commit

Permalink
particle slug and fix shotgun collision
Browse files Browse the repository at this point in the history
  • Loading branch information
computermouth committed Oct 26, 2023
1 parent fe9afe8 commit 713d28c
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 80 deletions.
2 changes: 1 addition & 1 deletion c1k3-assets
30 changes: 29 additions & 1 deletion entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void entity_constructor(entity_t *e, vec3_t pos, uint8_t p1, uint8_t p2) {
e->_did_collide_with_entity = entity_did_collide_with_entity;
e->_draw_model = entity_draw_model;
e->_spawn_particles = entity_spawn_particles;
e->_spawn_particles_ng = entity_spawn_particles_ng;
e->_receive_damage = entity_receive_damage;
e->_play_sound = entity_play_sound;
e->_kill = entity_kill;
Expand Down Expand Up @@ -307,7 +308,11 @@ void entity_draw_model(entity_t * e) {

void entity_spawn_particles(entity_t * e, int amount, int speed, model_t * model, int texture, float lifetime) {
for (uint32_t i = 0; i < amount; i++) {
entity_t * particle = game_spawn((void (*)(entity_t *, vec3_t, uint8_t, uint8_t))entity_particle_constructor, e->p, 0, 0, NULL);

vec3_t move_dist = vec3_mulf(e->v, game_tick);
vec3_t tickdist = vec3_divf(move_dist, 16.0f);

entity_t * particle = game_spawn((void (*)(entity_t *, vec3_t, uint8_t, uint8_t))entity_particle_constructor, vec3_sub(e->p, tickdist), 0, 0, NULL);
particle->_model = model;
particle->_texture = texture;
particle->_expires = true;
Expand All @@ -320,6 +325,29 @@ void entity_spawn_particles(entity_t * e, int amount, int speed, model_t * model
}
}

void entity_spawn_particles_ng(entity_t * e, int amount, int speed, entity_id_t eid, float lifetime){

entity_params_t ep = map_entt_params_from_eid(eid);

// scooch back 1/16th, so the particles aren't
// just stuck in a wall
vec3_t move_dist = vec3_mulf(e->v, game_tick);
vec3_t tickdist = vec3_divf(move_dist, 16.0f);

ep.entity_generic_params.position = vec3_sub(e->p, tickdist);

for (uint32_t i = 0; i < amount; i++) {
entity_t * particle = game_spawn_ng(&ep);
particle->_expires = true;
particle->_die_at = game_time + lifetime + randf() * lifetime * 0.2;
particle->v = vec3(
(randf() - 0.5) * speed,
randf() * speed,
(randf() - 0.5) * speed
);
}
}

void entity_receive_damage(entity_t * e, entity_t * from, int32_t amount) {
if (e->_dead)
return;
Expand Down
2 changes: 2 additions & 0 deletions entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ typedef struct entity_t {
void (*_did_collide_with_entity)(struct entity_t * e, struct entity_t * other);
void (*_draw_model)(struct entity_t * e);
void (*_spawn_particles)(struct entity_t * e, int amount, int speed, model_t * model, int texture, float lifetime);
void (*_spawn_particles_ng)(struct entity_t * e, int amount, int speed, entity_id_t eid, float lifetime);
void (*_set_state)(struct entity_t * e, uint32_t state);
struct entity_t * (*_spawn_projectile)(struct entity_t * e, void (*func)(struct entity_t *, vec3_t, uint8_t, uint8_t), float speed, float yaw_offset, float pitch_offset);
struct entity_t * (*_spawn_projectile_ng)(struct entity_t * e, entity_id_t eid, float speed, float yaw_offset, float pitch_offset);
Expand All @@ -170,6 +171,7 @@ void entity_did_collide(entity_t * e, int axis); // todo, axis should probably b
void entity_did_collide_with_entity(entity_t * e, entity_t * other);
void entity_draw_model(entity_t * e);
void entity_spawn_particles(entity_t * e, int amount, int speed, model_t * model, int texture, float lifetime);
void entity_spawn_particles_ng(entity_t * e, int amount, int speed, entity_id_t eid, float lifetime);
void entity_receive_damage(entity_t * e, entity_t * from, int32_t amount);
void entity_play_sound(entity_t * e, Mix_Chunk * sound);
void entity_kill(entity_t * e);
Expand Down
2 changes: 2 additions & 0 deletions entity_door.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void entity_door_constructor(entity_t *e, vec3_t pos, uint8_t p1, uint8_t p2) {

e->_texture = e->_params->entity_generic_params.ref_entt->tex_id;
e->_model->frames = vector_begin(e->_params->entity_generic_params.ref_entt->frames);
e->_model->nv = e->_params->entity_generic_params.ref_entt->vert_len;
e->s = e->_params->entity_generic_params.ref_entt->size;
}

void entity_door_init(entity_t * e, uint8_t texture, uint8_t dir) {
Expand Down
18 changes: 18 additions & 0 deletions entity_particle.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@

#include "entity_particle.h"
#include "model.h"
#include <sys/types.h>

void entity_particle_init(entity_t * e, uint8_t p1, uint8_t p2);
void entity_particle_update(entity_t * e);

// todo, put the models on the stack,
// copy data in
model_t empty = { 0 };

void entity_particle_constructor(entity_t * e, vec3_t pos, uint8_t p1, uint8_t p2) {
entity_constructor(e, pos, p1, p2);

Expand All @@ -14,6 +20,18 @@ void entity_particle_constructor(entity_t * e, vec3_t pos, uint8_t p1, uint8_t p
// todo, kinda goofy paradigm to set the callback, immediately invoke
// then never call again. could just combine constructor and init I think
e->_init(e, p1, p2);

// todo, remove once all the _ng's are implemented
if ( e->_params != NULL && e->_params->entity_generic_params.ref_entt != NULL ){
e->_texture = e->_params->entity_generic_params.ref_entt->tex_id;
vector * frames = e->_params->entity_generic_params.ref_entt->frames;
uint32_t * uframes = vector_begin(frames);
e->_model = &empty;
e->_model->frames = uframes;
e->_model->nv = e->_params->entity_generic_params.ref_entt->vert_len;
e->s = e->_params->entity_generic_params.ref_entt->size;
}

}

void entity_particle_init(entity_t * e, uint8_t p1, uint8_t p2) {
Expand Down
11 changes: 1 addition & 10 deletions entity_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,7 @@ void entity_player_update(entity_t * e) {

text_push_surface(hud.hlth_surface);
text_push_surface(hud.ammo_surface);
/*
// todo, text
h.textContent = this._health|0;
a.textContent = weapon._needs_ammo ? weapon._ammo : '∞';
// Debug: a light around the player
// r_push_light(vec3_add(this.p, vec3(0,64,0)), 10, 255, 192, 32);
*/

}

void entity_player_receive_damage(entity_t * e, entity_t * from, int32_t amount) {
Expand All @@ -260,8 +253,6 @@ uint32_t entity_player_reset_level(uint32_t interval, void *param) {

void entity_player_kill(entity_t * e) {
entity_kill(e);
// todo
// h.textContent = this._health|0;

// timed_surfaces free at the end of their timer
text_surface_t * died_text = text_create_surface(
Expand Down
7 changes: 6 additions & 1 deletion entity_projectile_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "entity_projectile_shell.h"
#include "entity.h"
#include "game.h"
#include "map.h"
#include "math.h"
#include "entity_light.h"

Expand All @@ -19,6 +20,9 @@ void entity_projectile_shell_constructor(entity_t * e, vec3_t pos, uint8_t p1, u
e->_did_collide = entity_projectile_shell_did_collide;
e->_did_collide_with_entity = entity_projectile_shell_did_collide_with_entity;

/* shells are invis
* so no model setup */

// todo, kinda goofy paradigm to set the callback, immediately invoke
// then never call again. could just combine constructor and init I think
e->_init(e, p1, p2);
Expand All @@ -36,7 +40,8 @@ void entity_projectile_shell_update(entity_t * e) {

void entity_projectile_shell_did_collide(entity_t * e, int axis) {
e->_kill(e);
e->_spawn_particles(e, 2, 80, &model_explosion, 4, 0.4);
// e->_spawn_particles(e, 2, 80, &model_explosion, 4, 0.4);
e->_spawn_particles_ng(e, 2, 80, ENTITY_ID_PARTICLE_SLUG, 0.4);
// todo, change parameter types to float, fuck it
// entity_t * tmp_light = game_spawn(entity_light_constructor, e->p, 0.5, 0xff);
entity_t * tmp_light = game_spawn(entity_light_constructor, e->p, 1, 0xff, NULL);
Expand Down
132 changes: 66 additions & 66 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,100 +65,100 @@ void game_load() {
0.3,0.6,0.3
});

tmp_mod = vector_at(model_data, 1);
model_grunt = model_load(tmp_mod->data, (vec3_t) {
2.5,2.2,2.5
});
// tmp_mod = vector_at(model_data, 1);
// model_grunt = model_load(tmp_mod->data, (vec3_t) {
// 2.5,2.2,2.5
// });

tmp_mod = vector_at(model_data, 1);
model_enforcer = model_load(tmp_mod->data, (vec3_t) {
3,2.7,3
});
// tmp_mod = vector_at(model_data, 1);
// model_enforcer = model_load(tmp_mod->data, (vec3_t) {
// 3,2.7,3
// });

tmp_mod = vector_at(model_data, 1);
model_zombie = model_load(tmp_mod->data, (vec3_t) {
1.5,2,1.5
});

tmp_mod = vector_at(model_data, 1);
model_ogre = model_load(tmp_mod->data, (vec3_t) {
4,3,4
});
// tmp_mod = vector_at(model_data, 1);
// model_ogre = model_load(tmp_mod->data, (vec3_t) {
// 4,3,4
// });

tmp_mod = vector_at(model_data, 4);
model_hound = model_load(tmp_mod->data, (vec3_t) {
2.5,2.5,2.5
});
// tmp_mod = vector_at(model_data, 4);
// model_hound = model_load(tmp_mod->data, (vec3_t) {
// 2.5,2.5,2.5
// });

tmp_mod = vector_at(model_data, 2);
model_barrel = model_load(tmp_mod->data, (vec3_t) {
2, 2, 2
});
// tmp_mod = vector_at(model_data, 2);
// model_barrel = model_load(tmp_mod->data, (vec3_t) {
// 2, 2, 2
// });

tmp_mod = vector_at(model_data, 7);
model_torch = model_load(tmp_mod->data, (vec3_t) {
0.6,1,0.6
});

tmp_mod = vector_at(model_data, 6);
model_pickup_nailgun = model_load(tmp_mod->data, (vec3_t) {
1, 1, 1
});
// tmp_mod = vector_at(model_data, 6);
// model_pickup_nailgun = model_load(tmp_mod->data, (vec3_t) {
// 1, 1, 1
// });

tmp_mod = vector_at(model_data, 2);
model_pickup_grenadelauncher = model_load(tmp_mod->data, (vec3_t) {
1, 0.5, 0.5
});
// tmp_mod = vector_at(model_data, 2);
// model_pickup_grenadelauncher = model_load(tmp_mod->data, (vec3_t) {
// 1, 0.5, 0.5
// });

tmp_mod = vector_at(model_data, 5);
model_pickup_box = model_load(tmp_mod->data, (vec3_t) {
0.7, 0.7, 0.7
});

tmp_mod = vector_at(model_data, 5);
model_pickup_grenades = model_load(tmp_mod->data, (vec3_t) {
0.5, 1, 0.5
});
// tmp_mod = vector_at(model_data, 5);
// model_pickup_grenades = model_load(tmp_mod->data, (vec3_t) {
// 0.5, 1, 0.5
// });

tmp_mod = vector_at(model_data, 5);
model_pickup_key = model_load(tmp_mod->data, (vec3_t) {
0.1, 0.7, 0.1
});

tmp_mod = vector_at(model_data, 5);
model_door = model_load(tmp_mod->data, (vec3_t) {
5, 5, 0.5
});

tmp_mod = vector_at(model_data, 2);
model_shotgun = model_load(tmp_mod->data, (vec3_t) {
1,0.2,0.2
});

tmp_mod = vector_at(model_data, 2);
model_grenadelauncher = model_load(tmp_mod->data, (vec3_t) {
0.7,0.4,0.4
});

tmp_mod = vector_at(model_data, 6);
model_nailgun = model_load(tmp_mod->data, (vec3_t) {
0.7,0.7,0.7
});

tmp_mod = vector_at(model_data, 2);
model_grenade = model_load(tmp_mod->data, (vec3_t) {
0.3,0.3,0.3
});

tmp_mod = vector_at(model_data, 2);
model_nail = model_load(tmp_mod->data, (vec3_t) {
0.5,0.1,0.1
});

tmp_mod = vector_at(model_data, 2);
model_plasma = model_load(tmp_mod->data, (vec3_t) {
0.5,0.1,0.1
});
// tmp_mod = vector_at(model_data, 5);
// model_door = model_load(tmp_mod->data, (vec3_t) {
// 5, 5, 0.5
// });

// tmp_mod = vector_at(model_data, 2);
// model_shotgun = model_load(tmp_mod->data, (vec3_t) {
// 1,0.2,0.2
// });

// tmp_mod = vector_at(model_data, 2);
// model_grenadelauncher = model_load(tmp_mod->data, (vec3_t) {
// 0.7,0.4,0.4
// });

// tmp_mod = vector_at(model_data, 6);
// model_nailgun = model_load(tmp_mod->data, (vec3_t) {
// 0.7,0.7,0.7
// });

// tmp_mod = vector_at(model_data, 2);
// model_grenade = model_load(tmp_mod->data, (vec3_t) {
// 0.3,0.3,0.3
// });

// tmp_mod = vector_at(model_data, 2);
// model_nail = model_load(tmp_mod->data, (vec3_t) {
// 0.5,0.1,0.1
// });

// tmp_mod = vector_at(model_data, 2);
// model_plasma = model_load(tmp_mod->data, (vec3_t) {
// 0.5,0.1,0.1
// });

// Take some parts from the grunt model and build individual giblet models
// from it. Arms and legs and stuff...
Expand Down
6 changes: 5 additions & 1 deletion map.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "entity_projectile_nail.h"
#include "entity_projectile_plasma.h"
#include "entity_projectile_shell.h"
#include "entity_particle.h"
#include "entity_barrel.h"
#include "entity_light.h"
#include "entity_trigger_level.h"
Expand Down Expand Up @@ -103,7 +104,10 @@ void map_init() {
"projectile_plasma", entity_projectile_plasma_constructor
};
map_entity_table[ENTITY_ID_PROJECTILE_SHELL] = (map_entity_table_t) {
"projectile_slug", entity_projectile_shell_constructor
"", entity_projectile_shell_constructor
};
map_entity_table[ENTITY_ID_PARTICLE_SLUG] = (map_entity_table_t) {
"particle_slug", entity_particle_constructor
};
map_entity_table[ENTITY_ID_BARREL] = (map_entity_table_t) {
"barrel", entity_barrel_constructor
Expand Down
1 change: 1 addition & 0 deletions map.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ typedef enum {
ENTITY_ID_PROJECTILE_NAIL,
ENTITY_ID_PROJECTILE_PLASMA,
ENTITY_ID_PROJECTILE_SHELL,
ENTITY_ID_PARTICLE_SLUG,
ENTITY_ID_BARREL,
ENTITY_ID_LIGHT,
ENTITY_ID_TRIGGER_LEVEL,
Expand Down
6 changes: 6 additions & 0 deletions math.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ vec3_t vec3_mulf(vec3_t a, float b) {
};
}

vec3_t vec3_divf(vec3_t a, float b) {
return (vec3_t) {
a.x / b, a.y / b, a.z / b
};
}

vec3_t vec3_cross(vec3_t a, vec3_t b) {
return (vec3_t) {
a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x
Expand Down
1 change: 1 addition & 0 deletions math.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ float vec3_dot(vec3_t a, vec3_t b);
vec3_t vec3_add(vec3_t a, vec3_t b);
vec3_t vec3_mul(vec3_t a, vec3_t b);
vec3_t vec3_mulf(vec3_t a, float b);
vec3_t vec3_divf(vec3_t a, float b);
vec3_t vec3_cross(vec3_t a, vec3_t b);
vec3_t vec3_normalize(vec3_t v);
vec3_t vec3_face_normal(vec3_t v0, vec3_t v1, vec3_t v2);
Expand Down

0 comments on commit 713d28c

Please sign in to comment.