-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.cpp
289 lines (238 loc) · 7.67 KB
/
sketch.cpp
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/* __
/___/
/ /
/-------------/ __/_/__
| |-------/ //===//__<*>_ //===//
| .----/ / / /
| .---/ / / /
| |------/ / / /
/----------/ L + V + E + N + T + U + R + E *=-
An Adventure Game for the Arduino/Video Game Shield
2011 - trodoss
This program 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 2 of the License, or
(at your option) any later version.
This program 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.
bitmap_funcs.cpp used from "Parachute" sketch by pocketscience.
For a full copy of that sketch, see:
http://nootropicdesign.com/hackvision/downloads/games/Parachute.zip
_____________________________________________________________________
Elventure: http://http://www.team-arg.org/ELV-manual.html
TV-out version 1.0 : http://www.team-arg.org/ELV-downloads.html
PUBLISHED by TEAM a.r.g. : http://www.team-arg.org/About.html
2013 - Trodoss
*/
//determine the game
#define GAME_ID 18
#include <stdlib.h>
#include <SPI.h>
#include <Gamebuino.h>
//#include <i2cmaster.h>
//#include <nunchuck.h>
//#include <TVout.h>
//#include <font4x6.h>
extern const uint8_t font3x5[];
#include "map.h"
#include "room.h"
#include "elf.h"
#include "sound.h"
#include "display.h"
#include "logo.h"
#include "other_bitmap.h"
#include "logo_bitmap.h"
//Require these for redrawing everything after pause menu
#include "bitmap_funcs.h"
#include "map_bitmap.h"
#include "elf_bitmap.h"
#define SIZEOF_ELF_RECORD 10
#define SIZEOF_MAP_RECORD 10
//Another example of the perils of Arduino IDE
void resetElf(bool reset_items);
void showElf();
void moveElf(unsigned char facing);
void throwSword();
RoomElement hitElf(RoomElement element);
Elf getElf();
void addElfItem(char type);
bool elfHasItem(char type);
char getElfState();
#define SCREENWIDTH 128
#define SCREENHEIGHT 96
#define PAUSE_BETWEEN_ACTIONS 100
#define GAME_TITLE 0
#define GAME_PLAYING 1
#define GAME_PAUSED 2
#define GAME_WON 3
#define GAME_OVER 4
//TVout TV;
Gamebuino gb;
//Nunchuck player1;
char game_state;
void start_game()
{
//clear the contents of the screen
gb.display.clear();
gb.display.persistence = true;
gb.setFrameRate(10);//100 ms per frame
gb.display.setColor(BLACK,WHITE);
gb.sound.command(1, 0, 0, 0);
//TV.clear_screen();
//start the game
setMapRoom(0);
showElf();
updateDisplay(getElf());
play_song(0);
game_state = GAME_PLAYING;
}
void start_title()
{
//clear the contents of the screen
gb.display.clear();
gb.display.persistence = true;
//gb.display.setColor(BLACK,WHITE);
//TV.clear_screen();
game_state = GAME_TITLE;
drawLogo(0);
play_song(4);
}
void start_game_over()
{
//clear the contents of the screen
gb.display.clear();
//TV.clear_screen();
game_state = GAME_OVER;
drawLogo(4);
play_song_once(2);
}
void start_game_won()
{
//clear the contents of the screen
gb.display.clear();
//TV.clear_screen();
game_state = GAME_WON;
drawLogo(8);
play_song(3);
}
void setup()
{
gb.begin();
//TV.begin(_NTSC, SCREENWIDTH, SCREENHEIGHT);
//TV.begin(_PAL, SCREENWIDTH, SCREENHEIGHT);
gb.display.setFont(font3x5);
//TV.select_font(font4x6);
randomSeed(analogRead(0));
//player1.begin(0);
gb.titleScreen(F("Original by TEAM ARG.\nPort by Wuff."),title_bitmap_unified);
//Skip the original title screen since we used the Gamebuino title screen.
start_game();
//start_title();
//TV.clear_screen();
//TV.bitmap(18,32,team_arg_bitmap);
//TV.delay(3000);
//TV.clear_screen();
//TV.bitmap(16,48,team_arg_bitmap);
//TV.delay(1500);
}
void loop()
{
static long next_action = 0;
switch (game_state)
{
case GAME_TITLE:
case GAME_OVER:
case GAME_WON:
if( gb.update() )
//if (TV.millis() >= next_action)
{
//player1.update();
//wait for a button to be pressed to continue
//if ((player1.button_c()) || (player1.button_z()))
if (gb.buttons.pressed(BTN_A) || gb.buttons.pressed(BTN_B))
{
//check to see what we are doing when we start the game
if (game_state > GAME_TITLE)
{
if (game_state == GAME_WON)
{
//if the game has been won, then reset the inventory of the elf
resetElf(true);
} else {
//if the game was just over (died) then do not reset the inventory
resetElf(false);
}
}
game_state = GAME_PLAYING;
start_game();
}
//next_action = TV.millis() + PAUSE_BETWEEN_ACTIONS;
update_sound();
}
break;
case GAME_PLAYING:
if( gb.update() )
//if (TV.millis() >= next_action)
{
//player1.update();
if (gb.buttons.repeat(BTN_UP,1)) moveElf(FACING_UP);
if (gb.buttons.repeat(BTN_DOWN,1)) moveElf(FACING_DOWN);
if (gb.buttons.repeat(BTN_RIGHT,1)) moveElf(FACING_RIGHT);
if (gb.buttons.repeat(BTN_LEFT,1)) moveElf(FACING_LEFT);
if (gb.buttons.pressed(BTN_A)) throwSword();
//if (gb.buttons.pressed(BTN_B)) game_state = GAME_PAUSED; //Remove pause state because menu works better
if (gb.buttons.pressed(BTN_C)){
gb.titleScreen(F("Press \25 to resume."),title_bitmap_unified);
gb.display.clear();
gb.display.persistence = true;
//For map tiles (not calling function because it loads room elements
for (char y=0;y<6; y++)
{
for (char x=0;x<10; x++)
{
//determine the current block before trying to draw
int curr_block = getMapBlock(x,y,-1);
gb.display.drawBitmap(x * 8, y * 8, map_bitmap + (curr_block * SIZEOF_MAP_RECORD));
}
}
updateDisplay(getElf()); //For hearts and items
//For elf
overlaybitmap(getElf().x, getElf().y, elf_bitmap + ( getElf().facing * SIZEOF_ELF_RECORD));
overlaybitmap(getElf().x, getElf().y+8, elf_bitmap + ((getElf().facing + getElf().step) * SIZEOF_ELF_RECORD));
}
//if (player1.joy_up()) moveElf(FACING_UP);
//if (player1.joy_down()) moveElf(FACING_DOWN);
//if (player1.joy_right()) moveElf(FACING_RIGHT);
//if (player1.joy_left()) moveElf(FACING_LEFT);
//if (player1.button_z()) throwSword();
//if (player1.button_c()) game_state = GAME_PAUSED;
//next_action = TV.millis() + PAUSE_BETWEEN_ACTIONS;
handleRoomElements();
//check the elf's state
if (getElfState() != ELFSTATE_PLAYING)
{
if (getElfState() == ELFSTATE_DEAD)
{
start_game_over();
} else {
start_game_won();
}
}
update_sound();
}
break;
case GAME_PAUSED:
if( gb.update() )
//if (TV.millis() >= next_action)
{
gb.display.print("Paused");
//player1.update();
if (gb.buttons.pressed(BTN_B)) game_state = GAME_PLAYING;
//if (player1.button_c()) game_state = GAME_PLAYING;
//next_action = TV.millis() + PAUSE_BETWEEN_ACTIONS;
}
break;
}
}