bullet testing
This commit is contained in:
parent
cad25d24b2
commit
bcbf9c9588
BIN
res/graphics/bullet.ase
(Stored with Git LFS)
Normal file
BIN
res/graphics/bullet.ase
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
res/graphics/gun.ase
(Stored with Git LFS)
BIN
res/graphics/gun.ase
(Stored with Git LFS)
Binary file not shown.
19
src/entity.c
19
src/entity.c
@ -32,9 +32,11 @@ GLOBAL READONLY struct entity g_entity_default = {
|
||||
* Store allocation
|
||||
* ========================== */
|
||||
|
||||
INTERNAL struct entity *entity_alloc_internal(struct entity_store *store);
|
||||
|
||||
INTERNAL void store_make_root(struct entity_store *store)
|
||||
{
|
||||
struct entity *root = entity_alloc_unlinked(store);
|
||||
struct entity *root = entity_alloc_internal(store);
|
||||
root->is_root = true;
|
||||
root->local_xform = XFORM_IDENT;
|
||||
root->cached_global_xform = XFORM_IDENT;
|
||||
@ -80,7 +82,7 @@ void entity_store_reset(struct entity_store *store)
|
||||
* Allocation
|
||||
* ========================== */
|
||||
|
||||
struct entity *entity_alloc_unlinked(struct entity_store *store)
|
||||
INTERNAL struct entity *entity_alloc_internal(struct entity_store *store)
|
||||
{
|
||||
struct entity *entity = NULL;
|
||||
struct entity_handle handle = { 0 };
|
||||
@ -100,18 +102,10 @@ struct entity *entity_alloc_unlinked(struct entity_store *store)
|
||||
return entity;
|
||||
}
|
||||
|
||||
struct entity *entity_alloc_top(struct entity_store *store)
|
||||
{
|
||||
struct entity *e = entity_alloc_unlinked(store);
|
||||
struct entity *root = entity_from_handle(store, store->root);
|
||||
entity_link_parent_child(root, e);
|
||||
return e;
|
||||
}
|
||||
|
||||
struct entity *entity_alloc_child(struct entity *parent)
|
||||
struct entity *entity_alloc(struct entity *parent)
|
||||
{
|
||||
struct entity_store *store = entity_get_store(parent);
|
||||
struct entity *e = entity_alloc_unlinked(store);
|
||||
struct entity *e = entity_alloc_internal(store);
|
||||
entity_link_parent_child(parent, e);
|
||||
return e;
|
||||
}
|
||||
@ -288,6 +282,7 @@ void entity_set_local_xform(struct entity *ent, struct xform xf)
|
||||
* Tree
|
||||
* ========================== */
|
||||
|
||||
/* FIXME: Unlink existing */
|
||||
void entity_link_parent_child(struct entity *parent, struct entity *child)
|
||||
{
|
||||
struct entity_store *store = entity_get_store(parent);
|
||||
|
||||
@ -222,9 +222,7 @@ void entity_store_copy_replace(struct entity_store *dest, struct entity_store *s
|
||||
void entity_store_reset(struct entity_store *store);
|
||||
|
||||
/* Entity */
|
||||
struct entity *entity_alloc_unlinked(struct entity_store *store);
|
||||
struct entity *entity_alloc_top(struct entity_store *store);
|
||||
struct entity *entity_alloc_child(struct entity *parent);
|
||||
struct entity *entity_alloc(struct entity *parent);
|
||||
void entity_release(struct entity_store *store, struct entity *ent);
|
||||
|
||||
/* Xform */
|
||||
|
||||
37
src/game.c
37
src/game.c
@ -103,6 +103,8 @@ INTERNAL struct game_cmd_array pop_cmds(struct arena *arena)
|
||||
|
||||
INTERNAL void spawn_test_entities(void)
|
||||
{
|
||||
struct entity *root = entity_from_handle(G.tick.entity_store, G.tick.entity_store->root);
|
||||
|
||||
/* Player */
|
||||
struct entity *player_ent;
|
||||
{
|
||||
@ -110,7 +112,7 @@ INTERNAL void spawn_test_entities(void)
|
||||
struct v2 size = V2(1, 1);
|
||||
f32 r = 0;
|
||||
|
||||
struct entity *e = entity_alloc_top(G.tick.entity_store);
|
||||
struct entity *e = entity_alloc(root);
|
||||
|
||||
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
|
||||
entity_set_xform(e, xf);
|
||||
@ -132,11 +134,18 @@ INTERNAL void spawn_test_entities(void)
|
||||
|
||||
/* Weapon */
|
||||
{
|
||||
#if 0
|
||||
struct v2 pos = V2(1, 0);
|
||||
struct v2 size = V2(1, 1);
|
||||
f32 r = PI / 4;
|
||||
struct entity *e = entity_alloc(root);
|
||||
#else
|
||||
struct v2 pos = V2(0.1, 0);
|
||||
struct v2 size = V2(1, 1);
|
||||
f32 r = 0;
|
||||
struct entity *e = entity_alloc(player_ent);
|
||||
#endif
|
||||
|
||||
struct entity *e = entity_alloc_top(G.tick.entity_store);
|
||||
|
||||
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
|
||||
entity_set_local_xform(e, xf);
|
||||
@ -151,7 +160,7 @@ INTERNAL void spawn_test_entities(void)
|
||||
|
||||
/* Camera */
|
||||
{
|
||||
struct entity *e = entity_alloc_top(G.tick.entity_store);
|
||||
struct entity *e = entity_alloc(root);
|
||||
entity_set_xform(e, XFORM_IDENT);
|
||||
|
||||
entity_enable_prop(e, ENTITY_PROP_CAMERA);
|
||||
@ -417,12 +426,6 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
|
||||
|
||||
/* Fire weapon */
|
||||
if (entity_has_prop(ent, ENTITY_PROP_WEAPON)) {
|
||||
#if 1
|
||||
f32 r = 1.0f * ((f32)sys_rand_u32() / U32_MAX);
|
||||
f32 g = 1.0f * ((f32)sys_rand_u32() / U32_MAX);
|
||||
f32 b = 1.0f * ((f32)sys_rand_u32() / U32_MAX);
|
||||
ent->sprite_tint = RGBA_32_F(r, g, b, 1);
|
||||
#else
|
||||
struct xform xf = entity_get_xform(ent);
|
||||
|
||||
struct sprite_tag sprite = ent->sprite;
|
||||
@ -432,12 +435,18 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
|
||||
|
||||
struct sprite_sheet_slice out_slice = sprite_sheet_get_slice(sheet, STR("out"), animation_frame);
|
||||
struct v2 out_pos = xform_mul_v2(sprite_xform, out_slice.center);
|
||||
struct v2 out_dir = xform_basis_mul_v2(sprite_xform, out_slice.dir);
|
||||
|
||||
(UNUSED)out_pos;
|
||||
(UNUSED)out_dir;
|
||||
#endif
|
||||
struct v2 out_vec = xform_basis_mul_v2(sprite_xform, out_slice.dir);
|
||||
out_vec = v2_norm(out_vec);
|
||||
out_vec = v2_mul(out_vec, 2);
|
||||
|
||||
{
|
||||
/* Spawn bullet */
|
||||
struct entity *bullet = entity_alloc(root);
|
||||
bullet->sprite = sprite_tag_from_path(STR("res/graphics/bullet.ase"));
|
||||
struct xform bullet_xf = XFORM_POS(out_pos);
|
||||
entity_set_xform(bullet, bullet_xf);
|
||||
bullet->velocity = out_vec;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user