6 uint8_t obj_slot_used
[OBJ_MAX
];
8 // return -1 on error or gameobj slot id.
9 int gameobj_alloc(void) {
10 if(obj_count
>= OBJ_MAX
) return -1;
11 // fast path: try next slot
13 if(!obj_slot_used
[i
]) {
20 for (i
= 0; i
< OBJ_MAX
; i
++) {
21 if(!obj_slot_used
[i
]) goto return_slot
;
26 void gameobj_free(int id
) {
27 assert(obj_slot_used
[id
] == 1);
28 obj_slot_used
[id
] = 0;
32 extern uint32_t tickcounter
;
33 void gameobj_start_anim(int obj_id
, enum animation_id aid
) {
34 if(obj_id
== -1) return;
35 objs
[obj_id
].animid
= aid
;
36 objs
[obj_id
].anim_curr
= ANIM_STEP_INIT
;
37 size_t tick_frames
= objs
[obj_id
].objtype
== OBJ_BIG_EXPLOSION
? 8 : 4;
38 objs
[obj_id
].anim_frame
= tickcounter
% tick_frames
;
41 void gameobj_init(int id
, vec2f
*pos
, vec2f
* vel
,
42 enum sprite_index spritemap_id
,
43 enum animation_id animid
, enum objtype objtype
) {
45 struct gameobj
*o
= &objs
[id
];
48 o
->spritemap_id
= spritemap_id
;
50 gameobj_start_anim(id
, animid
);
53 void gameobj_init_bulletdata(int id
, int steps
) {
55 struct gameobj
*o
= &objs
[id
];
56 o
->objspecific
.bullet
.step_curr
= 0;
57 o
->objspecific
.bullet
.step_max
= steps
;