summaryrefslogtreecommitdiffhomepage
path: root/src/main.c
blob: ba2c6b7f4ada899e0ada7790eca0bd49f5ea8719 (plain)
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

#include "rodeo.h"
#include <inttypes.h>
#include "input.h"
#include "player.h"
#include "bullet.h"
#include "enemies.h"
#include "wall.h"
#include "debug.h"
#include "init.h"

const uint16_t window_width = 1600;
const uint16_t window_height = 900;

// variables for storing debug info that can be displayed
cstr renderer_name;
float fps_display;

void
main_loop(void)
{
	if(rodeo_frame_count_get() % 10 == 0)
	{
		fps_display = rodeo_frame_perSecond_get();
	}


	mrodeo_frame_do()
	{
		// retrieve and apply player input
		parse_player_input();

		player_shoot(get_player_bullet_world());
		enemies_attempt_weapon_fire();

		// spawn enemies
		attempt_random_enemy_spawn((rodeo_rectangle_t){ 0, 0, window_width, window_height });
		
		// run enemy movement ai
		group_follow_target(get_player_position());

		detect_bullet_enemy_collisions();
		detect_bullet_wall_collisions();
		detect_player_enemy_collisions();
		detect_player_wall_collisions();
		detect_enemy_wall_collisions();

		// apply movements
		move_bullets();
		move_enemies();
		move_player();

		draw_level();
		draw_bullets();
		draw_player();
		draw_enemies();
		draw_hp_bar();

		draw_debug_text(
			renderer_name,
			fps_display
		);

	}
}

int
main(void)
{
	inputs_register_do()
	{
		mrodeo_window_do(window_height, window_width, cstr_lit("Rodeo Window"))
		{
			renderer_name = rodeo_renderer_name_get();
			rodeo_frame_limit_set(60);

			game_systems_init_do()
			{
				// use to test manually spawning enemies
				//spawn_enemy(400.0f,700.0f);
				//spawn_enemy(900.0f,700.0f);
				//spawn_enemy(400.0f,100.0f);
				//spawn_enemy(900.0f,100.0f);
				//for(int i = 0; i < 1500; ++i)
				//{
				//	float rng1 = ((float)rodeo_random_double_get() * 100) + 150;
				//	float rng2 = ((float)rodeo_random_double_get() * 100) + 150;
				//	spawn_ghost(rng1,rng2);
				//}
				rodeo_mainLoop_run(
						main_loop
						);
			}
		}
	}

	return 0;
}