-
Notifications
You must be signed in to change notification settings - Fork 12
/
elventure.ino
189 lines (156 loc) · 4.24 KB
/
elventure.ino
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
/* __
/___/
/ /
/-------------/ __/_/__
| |-------/ //===//__<*>_ //===//
| .----/ / / /
| .---/ / / /
| |------/ / / /
/----------/ 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
*/
#include <stdlib.h>
#include <i2cmaster.h>
#include <nunchuck.h>
#include <TVout.h>
#include <font4x6.h>
#include "map.h"
#include "room.h"
#include "elf.h"
#include "sound.h"
#include "display.h"
#include "logo.h"
#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;
Nunchuck player1;
char game_state;
void setup()
{
TV.begin(_NTSC, SCREENWIDTH, SCREENHEIGHT);
TV.select_font(font4x6);
randomSeed(analogRead(0));
player1.begin(0);
start_title();
}
void loop()
{
static long next_action = 0;
switch (game_state)
{
case GAME_TITLE:
case GAME_OVER:
case GAME_WON:
if (TV.millis() >= next_action)
{
player1.update();
//wait for a button to be pressed to continue
if ((player1.button_c()) || (player1.button_z()))
{
//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 (TV.millis() >= next_action)
{
player1.update();
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 (TV.millis() >= next_action)
{
player1.update();
if (player1.button_c()) game_state = GAME_PLAYING;
next_action = TV.millis() + PAUSE_BETWEEN_ACTIONS;
}
break;
}
}
void start_game()
{
//clear the contents of the screen
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
TV.clear_screen();
game_state = GAME_TITLE;
drawLogo(0);
play_song(4);
}
void start_game_over()
{
//clear the contents of the screen
TV.clear_screen();
game_state = GAME_OVER;
drawLogo(4);
play_song_once(2);
}
void start_game_won()
{
//clear the contents of the screen
TV.clear_screen();
game_state = GAME_WON;
drawLogo(8);
play_song(3);
}