1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
#include "rodeo.h"
#include <inttypes.h>
#include "input.h"
#include "player.h"
#include "bullet.h"
#include "enemies.h"
#include "rodeo/collision.h"
cstr renderer;
float time_var;
rodeo_audio_sound_t *scratch = NULL;
rodeo_audio_music_t *music = NULL;
typedef
struct
{
float x;
float y;
}
summon_t;
summon_t box1_position = { .x = 100, .y = 100 };
summon_t box2_position = { .x = 100, .y = 100 };
float orc_size[] = {13.0f * 2.0f, 19.0f * 2.0f};
rodeo_vector2_t units[UINT16_MAX][2] = {0};
uint16_t num_of_units = 0;
const rodeo_color_RGBAFloat_t red =
{
.colors.red = 1.0f, .colors.green = 0.0f, .colors.blue = 0.0f,
.colors.alpha = 1.0f
};
const rodeo_color_RGBAFloat_t green =
{
.colors.red = 0.0f, .colors.green = 1.0f, .colors.blue = 0.0f,
.colors.alpha = 1.0f
};
const rodeo_color_RGBAFloat_t blue =
{
.colors.red = 0.0f, .colors.green = 0.0f, .colors.blue = 1.0f,
.colors.alpha = 1.0f
};
const rodeo_color_RGBAFloat_t pink =
{
.colors.red = 1.0f, .colors.green = 0.0f, .colors.blue = 1.0f,
.colors.alpha = 1.0f
};
const rodeo_color_RGBAFloat_t red_clear =
{
.colors.red = 1.0f, .colors.green = 0.0f, .colors.blue = 0.0f,
.colors.alpha = 0.5f
};
const rodeo_color_RGBAFloat_t green_clear =
{
.colors.red = 0.0f, .colors.green = 1.0f, .colors.blue = 0.0f,
.colors.alpha = 0.5f
};
const rodeo_color_RGBAFloat_t blue_clear =
{
.colors.red = 0.0f, .colors.green = 0.0f, .colors.blue = 1.0f,
.colors.alpha = 0.5f
};
const rodeo_color_RGBAFloat_t pink_clear =
{
.colors.red = 1.0f, .colors.green = 0.0f, .colors.blue = 1.0f,
.colors.alpha = 0.5f
};
rodeo_collision_2d_world_t world_orc;
rodeo_collision_2d_world_t world_other;
world_id orc_collision_id;
world_id box_collision_ids[2] = { 0 };
void collision_resolve(
rodeo_collision_2d_world_item_t *a,
rodeo_collision_2d_world_item_t *b
) {
rodeo_log(
rodeo_logLevel_info,
"%d collided with %d",
a->id.id, b->id.id
);
rodeo_collision_2d_world_item_destroy(b);
}
void
main_loop(void)
{
if(rodeo_frame_count_get() % 10 == 0)
{
/* for testing
rodeo_input_scene_unregister_callback(
*summon_units_input,
&scene,
register_type_e
);
rodeo_input_scene_register_callback(
*summon_units_input,
&scene,
register_type_q
);
*/
time_var = rodeo_frame_perSecond_get();
}
mrodeo_frame_do()
{
parse_player_input();
move_player();
rodeo_collision_2d_world_compare_self(&world_orc, collision_resolve);
if(*(bool*)play_sound_input(NULL, NULL))
{
rodeo_audio_sound_play(scratch);
}
if(*(bool*)play_sound_input2(NULL, NULL))
{
rodeo_audio_music_play_fadeIn(music, 1000);
}
if(*(bool*)play_sound_input3(NULL, NULL))
{
rodeo_audio_music_stop_fadeOut(1000);
}
if(*(bool*)summon_units_input(NULL, NULL))
{
player_shoot(get_player_bullet_world());
}
rodeo_rectangle_draw(
&(rodeo_rectangle_t){ 100, 100, 50, 50 },
&red
);
rodeo_rectangle_draw(
&(rodeo_rectangle_t){ 100, 160, 50, 50 },
&green
);
rodeo_rectangle_draw(
&(rodeo_rectangle_t){ 160, 100, 50, 50 },
&blue
);
rodeo_rectangle_draw(
&(rodeo_rectangle_t){ 160, 160, 50, 50 },
&pink
);
rodeo_rectangle_draw(
&(rodeo_rectangle_t){ 300, 300, 50, 50 },
&red_clear
);
rodeo_rectangle_draw(
&(rodeo_rectangle_t){ 310, 310, 50, 50 },
&green_clear
);
rodeo_rectangle_draw(
&(rodeo_rectangle_t){ 320, 320, 50, 50 },
&blue_clear
);
rodeo_rectangle_draw(
&(rodeo_rectangle_t){ 330, 330, 50, 50 },
&pink_clear
);
// debug test for collisions
/*
for(uint64_t i = 0; i < (sizeof(box_collision_ids) / sizeof(box_collision_ids[0])); ++i)
{
rodeo_collision_2d_world_item_t *box = rodeo_collision_2d_world_item_get_by_id(box_collision_ids[i]);
if(box != NULL)
{
rodeo_rectangle_draw(
&(rodeo_rectangle_t){ box->x, box->y, box->width, box->height },
&pink
);
}
}
*/
move_bullets();
move_enemies();
group_follow_target(get_player_position());
draw_bullets();
draw_player();
draw_enemies();
detect_bullet_enemy_collisions();
detect_player_enemy_collisions();
rodeo_debug_text_draw(
1,
1,
" using %s renderer ",
cstr_str(
&renderer
)
);
rodeo_debug_text_draw(
2,
2,
" frame count: %"PRIu64" ",
rodeo_frame_count_get()
);
rodeo_debug_text_draw(
2,
3,
" fps: %.2f ",
time_var
);
}
}
int
main(void)
{
register_inputs();
rodeo_log(
rodeo_logLevel_info,
"Testing logging... It seems to work!"
);
rodeo_log(
rodeo_logLevel_warning,
"Testing warning log level... It seems to work!"
);
rodeo_log(
rodeo_logLevel_error,
"Testing error log level... It seems to work!"
);
mrodeo_window_do(480, 640, cstr_lit("Rodeo Window"))
{
renderer = rodeo_renderer_name_get();
rodeo_frame_limit_set(60);
world_orc = rodeo_collision_2d_world_create();
world_other = rodeo_collision_2d_world_create();
/*
rodeo_collision_2d_world_item_t test_collision_params = {
.x = 320,
.y = 240,
.width = orc_size[0],
.height = orc_size[1]
};
box_collision_ids[0] = rodeo_collision_2d_world_item_create(&world_orc, test_collision_params)->id;
rodeo_collision_2d_world_item_t test2_collision_params = {
.x = 0,
.y = 240,
.width = orc_size[0],
.height = orc_size[1]
};
box_collision_ids[1] = rodeo_collision_2d_world_item_create(&world_orc, test2_collision_params)->id;
*/
scratch = rodeo_audio_sound_create_from_path(cstr_lit("assets/sample.wav"));
music = rodeo_audio_music_create_from_path(cstr_lit("assets/music.ogg"));
init_bullets();
init_player();
init_enemies();
spawn_enemy(240, 240);
//spawn_enemy(100, 100);
spawn_enemy(300, 100);
spawn_enemy(200, 330);
rodeo_mainLoop_run(
main_loop
);
deinit_player();
rodeo_collision_2d_world_destroy(&world_orc);
rodeo_collision_2d_world_destroy(&world_other);
deinit_enemies();
}
unregister_inputs();
return 0;
}
|