-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
93 lines (71 loc) · 2.56 KB
/
main.c
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
#include <stdio.h>
#include <allegro5/allegro5.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_image.h>
#include "music.h"
#include "display.h"
#include "animation.h"
#include "utils.h"
#include "input.h"
#include "logic.h"
#include "loops.h"
#include "sounds.h"
int main()
{
// Initial Setup:
// Initialize ALLEGRO funcionalities
must_init(al_init(), "allegro");
must_init(al_install_keyboard(), "allegro keyboard");
// Run the game on 60 FPS
ALLEGRO_TIMER* timer = al_create_timer(1.0 / 60.0);
must_init(timer, "allegro timer");
// Display module
ALLEGRO_DISPLAY* disp = create_display();
must_init(disp, "display");
must_init(al_init_primitives_addon(), "primitives addon");
must_init(al_init_image_addon(), "image addon");
// Images:
ALLEGRO_BITMAP* stage = al_load_bitmap("resources/animation/stage4.png");
must_init(stage, "Stage");
ALLEGRO_BITMAP*** animations; // 2d array of bitmap pointers
animations = load_sprites();
// Music
ALLEGRO_AUDIO_STREAM* music = play_music("resources/music/SFVGuile.opus");
must_init(music, "music");
// Sounds
ALLEGRO_SAMPLE** sounds = load_sounds();
must_init(sounds, "sounds");
// Allegro "Events" are interruptions to be handled
ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
must_init(queue, "allegro queue");
ALLEGRO_EVENT event;
al_register_event_source(queue, al_get_keyboard_event_source());
al_register_event_source(queue, al_get_display_event_source(disp));
al_register_event_source(queue, al_get_timer_event_source(timer));
al_start_timer(timer);
// GAME/MENU:
long frame_count;
int menu_option = 0;
while (menu_option != QUIT)
{
menu_option = main_menu_loop(event, queue, sounds);
if (menu_option == HELP)
help_menu_loop(event, queue, sounds);
int cpu_level = 0;
if (menu_option == IS_CPU)
cpu_level = level_menu_loop(event, queue, sounds);
if ((menu_option == IS_CPU && cpu_level != -1) || menu_option == IS_PLAYER2)
frame_count = match_loop(event, queue, animations, stage, sounds, menu_option, cpu_level);
if (menu_option == IS_CPU && cpu_level != -1)
check_for_highscore(cpu_level, frame_count);
}
// Game over, destroy everything we made
destroy_music(music);
destroy_sounds(sounds);
al_destroy_bitmap(stage);
destroy_sprites(animations);
destroy_display(disp);
al_destroy_timer(timer);
al_destroy_event_queue(queue);
return 0;
}