-
Notifications
You must be signed in to change notification settings - Fork 0
/
pentago.c
166 lines (136 loc) · 3.84 KB
/
pentago.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
/*
The Uzebox Implementation of Pentago
Copyright 2010, Kenton Hamaluik
This file is part of The Uzebox Implementation of Pentago.
The Uzebox Implementation of Pentago is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
The Uzebox Implementation of Pentago is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Uzebox Implementation of Pentago. If not, see
<http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <avr/io.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <uzebox.h>
// graphics
#include "mammoth.c"
#include "atascii.c"
#include "screen.c"
// sounds
#include "patches.c"
// type definitions
#define STATE_MAINMENU (1)
#define STATE_PLAYERSTART (2)
#define STATE_HOWTOPLAY (3)
#define STATE_CREDITS (4)
#define STATE_PLAYING (5)
#define STATE_GAMEOVER (6)
// globals
char gameState = 0;
char nextState = STATE_MAINMENU;
char musicOn = 0;
// text renderer
#include "text.c"
// joypad states
int padHeld[2] = {0,0};
int padPressed[2] = {0,0};
int padReleased[2] = {0,0};
// global variables passed between states
char startPlayer;
char wonPlayer;
// include the states
#include "state_mainmenu.c"
#include "state_playerstart.c"
#include "state_playing.c"
#include "state_gameover.c"
#include "state_howtoplay.c"
#include "state_credits.c"
// intro screen
void DoIntro()
{
// random number generator seed
int rndSeed = 0;
SetTileTable(tiles_mammoth);
DrawMap2(0, 0, map_mammoth);
// game loop
char quit = 0;
while(!quit)
{
// wait for v sync
WaitVsync(1);
// update the seed
rndSeed += 7;
if(ReadJoypad(0) & BTN_START)
quit = 1;
}
// seed the prng
srand(rndSeed);
}
int main()
{
// clear the video
ClearVram();
// init the music
InitMusicPlayer(patches);
// show the intro screen
DoIntro();
// joystick previous states
int padPrev[2] = {0,0};
// now the game loop
while(1)
{
// wait for v sync
WaitVsync(1);
// load the next state if we need to
if(nextState > 0)
{
// set the new game state and reset the next state
gameState = nextState;
nextState = 0;
// fade out
FadeOut(1, true);
// init the state
if(gameState == STATE_MAINMENU)
InitState_MainMenu();
else if(gameState == STATE_PLAYING)
InitState_Playing();
else if(gameState == STATE_HOWTOPLAY)
InitState_HowToPlay();
else if(gameState == STATE_CREDITS)
InitState_Credits();
else if(gameState == STATE_PLAYERSTART)
InitState_PlayerStart();
else if(gameState == STATE_GAMEOVER)
InitState_GameOver();
}
// handle the input
padHeld[0] = ReadJoypad(0);
padPressed[0] = padHeld[0] & (padHeld[0] ^ padPrev[0]);
padReleased[0] = padPrev[0] & (padHeld[0] ^ padPrev[0]);
padPrev[0] = padHeld[0];
padHeld[1] = ReadJoypad(0);//1);
padPressed[1] = padHeld[1] & (padHeld[1] ^ padPrev[1]);
padReleased[1] = padPrev[1] & (padHeld[1] ^ padPrev[1]);
padPrev[1] = padHeld[1];
// handle the states
if(gameState == STATE_MAINMENU)
DoState_MainMenu();
else if(gameState == STATE_PLAYING)
DoState_Playing();
else if(gameState == STATE_HOWTOPLAY)
DoState_HowToPlay();
else if(gameState == STATE_CREDITS)
DoState_Credits();
else if(gameState == STATE_PLAYERSTART)
DoState_PlayerStart();
else if(gameState == STATE_GAMEOVER)
DoState_GameOver();
}
}