-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.c
77 lines (63 loc) · 1.99 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
// main.c
//
// Copyright (C) 2020 Dan Rodrigues <danrr.gh.oss@gmail.com>
//
// SPDX-License-Identifier: MIT
#include <stdint.h>
#include <stdbool.h>
#include "vdp.h"
#include "assert.h"
#include "game_loop.h"
#include "affine.h"
#include "music.h"
#include "camera.h"
#include "camera_init.h"
#include "level_loading.h"
#include "hero.h"
#include "debug_playfield.h"
#include "debug_custom_assert.h"
#include "fade_task.h"
#include "sprite_loading.h"
#include "title_loop.h"
static void handle_gl_action(GameLoopAction action, GameContext *context);
int main() {
vdp_enable_copper(false);
assert_set_handler(custom_assert_handler);
vdp_enable_layers(0);
vdp_set_single_palette_color(0, 0x0000);
GameContext context;
Hero hero;
Camera camera;
SpriteLoadingContext sprite_loading_context;
const uint8_t initial_level = 0;
gl_reset_context(&context, &hero, &camera, &sprite_loading_context, initial_level);
handle_gl_action(GL_ACTION_SHOW_TITLE, &context);
while (true) {
GameLoopAction action = gl_run_frame(&context);
handle_gl_action(action, &context);
}
fatal_error("Unexpected exit of game loop");
}
static void handle_gl_action(GameLoopAction action, GameContext *context) {
const PlayerContext *p1 = &context->players[0];
switch (action) {
case GL_ACTION_RESET_WORLD:
gl_reset_context(context, p1->hero, p1->camera, p1->sprite_context, context->level);
level_init(level_attributes(context->level), context);
music_start(TRACK_LEVEL_1);
break;
case GL_ACTION_SHOW_TITLE:
gl_load_title(context);
break;
case GL_ACTION_RELOAD_LEVEL:
level_init(level_attributes(context->level), context);
break;
case GL_ACTION_SHOW_CREDITS:
gl_load_credits(context);
break;
case GL_ACTION_NONE:
break;
default:
fatal_error("Unexpected game loop action");
}
}