forked from n64brew/N64brew-GameJam2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.c
166 lines (129 loc) · 3.75 KB
/
core.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
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
/***************************************************************
core.c
The file contains Core minigame code, which handles stuff like
player, AI, and game loop information.
***************************************************************/
#include <libdragon.h>
#include "core.h"
#include "config.h"
/*********************************
Structures
*********************************/
typedef struct {
PlyNum number;
joypad_port_t port;
} Player;
/*********************************
Globals
*********************************/
// Player info
static Player global_core_players[JOYPAD_PORT_COUNT];
static uint32_t global_core_playercount;
static AiDiff global_core_aidifficulty = AI_DIFFICULTY;
// Minigame info
static bool global_core_playeriswinner[MAXPLAYERS];
// Core info
static double global_core_subtick = 0;
/*==============================
core_get_subtick
Gets the current subtick. Use this to help smooth
movements in your draw loop
@return The current subtick
==============================*/
void core_set_subtick(double subtick)
{
global_core_subtick = subtick;
}
/*==============================
core_set_playercount
Sets the number of human players
@param The number of players
==============================*/
void core_set_playercount(uint32_t playercount)
{
int lastcont = 0;
// Attempt to find the first N left-most available controllers
for (int i=0; i<playercount; i++)
{
bool found = false;
for (int j=lastcont; j<JOYPAD_PORT_COUNT; j++)
{
if (joypad_is_connected(j))
{
global_core_players[i].port = j;
found = true;
lastcont = ++j;
break;
}
}
assertf(found, "Unable to find an available controller for player %d\n", i+1);
}
global_core_playercount = playercount;
}
/*==============================
core_set_aidifficulty
Sets the AI difficulty
@param The AI difficulty
==============================*/
void core_set_aidifficulty(AiDiff difficulty)
{
global_core_aidifficulty = difficulty;
}
/*==============================
core_set_winner
Set the winner of the minigame. You can call this
multiple times to set multiple winners.
@param The winning player
==============================*/
void core_set_winner(PlyNum ply)
{
global_core_playeriswinner[ply] = true;
}
/*==============================
core_get_aidifficulty
Gets the current AI difficulty
@return The AI difficulty
==============================*/
AiDiff core_get_aidifficulty()
{
return global_core_aidifficulty;
}
/*==============================
core_get_subtick
Gets the subtick of the current frame
@return The frame's subtick
==============================*/
double core_get_subtick()
{
return global_core_subtick;
}
/*==============================
core_get_playercount
Get the number of human players
@return The number of players
==============================*/
uint32_t core_get_playercount()
{
return global_core_playercount;
}
/*==============================
core_get_playercontroller
Get the controller port of this player.
Because player 1's controller might not be plugged
into port number 1.
@param The player we want
@return The controller port
==============================*/
joypad_port_t core_get_playercontroller(PlyNum ply)
{
return global_core_players[ply].port;
}
/*==============================
core_reset_winners
Resets the winners
==============================*/
void core_reset_winners()
{
for (int i=0; i<MAXPLAYERS; i++)
global_core_playeriswinner[i] = false;
}