11 extern Y
* mk_ent0(void);
16 static Y
* entities
[MAX_ENTS
];
17 static struct {int x
, y
;} ent_v
[MAX_ENTS
];
18 static int next_ent
= MAX_PLAYERS
;
22 int inside_rect(int x
, int y
, int x0
, int y0
, int x1
, int y1
){
23 return !(x
< x0
|| x
> x1
|| y
< y0
|| y
> y1
);
26 int rects_overlap(rect r1
, rect r2
){
37 int update_noop(Y
* e
){
41 int stage_noop(Y
* e
, struct stghit hit
){
45 int overlap_noop(Y
* e
, Y
* f
){
49 int diverge_noop(Y
* e
, Y
* f
){
52 static void find_visible_ents(int ents
[], int* count
){
56 void entity_master_simulate(){
57 int visible_ents
[MAX_ENTS
];
58 int visible_count
= 0;
60 find_visible_ents(visible_ents
, &visible_count
);
77 hit
= stage_collide_rect(
88 /* for all pairs, if overlapping do events */
89 /* for all overlaps, if not overlapping do events */
90 /* for all in screen, move and record v */
91 /* for all in screen, stage collision */
97 for(i
=0; i
<MAX_ENTS
; i
++){
98 if(entities
[i
] != NULL
){
100 draw_gfx(0, e
->x
/1024, e
->y
/1024, 16, 0, 8, 8);
105 void setup_test_entities(){
107 for(i
=0; i
<MAX_ENTS
; i
++){
111 entities
[0] = mk_ent0();
114 void player_press(int player
, enum input_button button
){
117 case LEFT_BUTTON
: e
->r
.a
= -1000; break;
118 case RIGHT_BUTTON
: e
->r
.a
= 1000; break;
119 case UP_BUTTON
: e
->r
.b
= -1000; break;
120 case DOWN_BUTTON
: e
->r
.b
= 1000; break;
121 case FIRE_BUTTON
: stage_debug(); break;
126 void player_release(int player
, enum input_button button
){
129 case LEFT_BUTTON
: e
->r
.a
= 0; break;
130 case RIGHT_BUTTON
: e
->r
.a
= 0; break;
131 // case UP_BUTTON: e->r.b = 0; break;
132 // case DOWN_BUTTON: e->r.b = 0; break;
139 int x; int y; spatial
141 unsigned flbits; common class
143 struct {int a,b,c,d,e,f;} r;
144 struct {int x, y, w, h;} box; used to detect collision
146 int (*stage)(Y*,int,int);
147 int (*overlap)(Y*,Y*);
148 int (*diverge)(Y*,Y*);
152 Y
* mk_dummy_ent(int x
, int y
){
153 memory clear_r
= {0,0,0,0,0,0};
154 rect standard
= {0,0,16,16};
155 Y
* ent
= malloc(sizeof(Y
));
163 ent
->update
= update_noop
;
164 ent
->stage
= stage_noop
;
165 ent
->overlap
= overlap_noop
;
166 ent
->diverge
= diverge_noop
;
173 int mini_rand(int g
){
174 return (g
*9 + 171) % 256;