-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.c
241 lines (206 loc) · 6.95 KB
/
environment.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
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
// Graeber2 - an digger adventure game
//
// Copyright (C) 2021 Heiko Wolf
//
// 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.
//
// You should have received a copy of the GNU General Public License along
// With this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// Contact: projekte@kabelmail.net
#include "environment.h"
#include "engine.h"
#include "text.h"
#include "player.h"
#include "hud.h"
#include "items.h"
#include "data/text/chest/chesttxt.h"
const uint8_t c_switches_values [2][2] = {
{8, 0}
};
void p_environment_modis (void) __banked
{
if (v_lvl == -1) {
if (v_lvlmodi [0] == 1) { p_engine_set_tile (8, 0, 14); }
}
}
void p_environment_init (void) __banked
{
for (v_i = 0; v_i != 10; ++v_i) {
v_lvlmodi [v_i] = 0;
}
}
///changes after an event
void p_environment_changes (unsigned char l_tile) __banked
{
o_engine.v_tile [0] = l_tile;
if (o_player.direction == UP) {
o_engine.v_leveldata [o_player.mk - 18] = l_tile;
set_bkg_tiles (o_player.xk / 8 - 1, o_player.yk / 8 - 3, 1, 1, o_engine.v_tile);
}
else if (o_player.direction == DOWN) {
o_engine.v_leveldata [o_player.mk + 18] = l_tile;
set_bkg_tiles (o_player.xk / 8 - 1, o_player.yk / 8 - 1, 1, 1, o_engine.v_tile);
}
else if (o_player.direction == LEFT) {
o_engine.v_leveldata [o_player.mk - 1] = l_tile;
set_bkg_tiles (o_player.xk / 8 - 2, o_player.yk / 8 - 2, 1, 1, o_engine.v_tile);
}
else if (o_player.direction == RIGHT) {
o_engine.v_leveldata [o_player.mk + 1] = l_tile;
set_bkg_tiles (o_player.xk / 8, o_player.yk / 8 - 2, 1, 1, o_engine.v_tile);
}
}
///
void p_environment_use_switch (void) __banked
{
p_environment_changes (TILE_SWITCH_ON);
//o_engine.v_tile [0] = TILE_DOOR_OPEN;
//set_bkg_tiles (c_switches_values [v_lvl][0] + 1, c_switches_values [v_lvl][1] + 1 , 1, 1, o_engine.v_tile);
if (v_lvl == 8) {
p_engine_set_tile (c_switches_values [0][0], c_switches_values [0][1], TILE_DOOR_OPEN);
}
}
void p_environment_use_chest (void) __banked
{
p_environment_changes (TILE_OPEN_CHEST);
//chest with food
if (v_lvl == 1) {
if (o_player.inventory.food != o_player.inventory.max_food) {
++o_player.inventory.food;
o_player.v_steps = 0;
p_set_txt (1, 1, foodtxt);
p_hud_show_food ();
}
}
//chest with 5 crystals
else if (v_lvl == 8) {
o_player.inventory.crystals += 5;
p_player_set_weapon_sprite ();
p_set_txt (1, 1, crystals5txt);
p_hud_show_value (o_player.inventory.crystals, 18, 15);
}
waitpad (J_A);
p_hide_txt ();
}
///trigger an event
void p_environment_get_ev (void) __banked
{
if (o_player.direction == UP) o_engine.v_tile [1] = p_engine_get_tile (o_player.mk - 18);
else if (o_player.direction == DOWN) o_engine.v_tile [1] = p_engine_get_tile (o_player.mk + 18);
else if (o_player.direction == LEFT) o_engine.v_tile [1] = p_engine_get_tile (o_player.mk - 1);
else if (o_player.direction == RIGHT) o_engine.v_tile [1] = p_engine_get_tile (o_player.mk + 1);
if (o_engine.v_tile [1] == TILE_SAND) p_environment_changes (TILE_PATH);
else if (o_engine.v_tile [1] == TILE_STONE) p_environment_changes (TILE_STONE_PHASE2);
else if (o_engine.v_tile [1] == TILE_STONE_PHASE2) p_environment_changes (TILE_PATH);
else if (o_engine.v_tile [1] == TILE_BLACK_STONE) p_environment_changes (TILE_BLACK_STONE_PHASE1);
else if (o_engine.v_tile [1] == TILE_BLACK_STONE_PHASE1) p_environment_changes (TILE_BLACK_STONE_PHASE2);
else if (o_engine.v_tile [1] == TILE_BLACK_STONE_PHASE2) p_environment_changes (TILE_PATH);
else if (o_engine.v_tile [1] == TILE_SWITCH_OFF) p_environment_use_switch ();
else if (o_engine.v_tile [1] == TILE_CHEST) p_environment_use_chest ();
}
///clear screen from collected item
void p_environment_clean_item (void) __banked
{
o_engine.v_tile [0] = TILE_PATH;
o_engine.v_leveldata [o_player.mk] = TILE_PATH;
set_bkg_tiles (o_player.xk / 8 - 1, o_player.yk / 8 - 2, 1, 1, o_engine.v_tile);
}
///collect gold
void p_environment_collect_gold (void) __banked
{
if (o_player.inventory.gold != 255) {
o_player.inventory.gold += 1;
p_environment_clean_item ();
p_hud_show_value (o_player.inventory.gold, 18, 16);
}
}
///collect crystal
void p_environment_collect_crystal (void) __banked
{
if (o_player.inventory.crystals != 255) {
o_player.inventory.crystals += 1;
p_environment_clean_item ();
p_hud_show_value (o_player.inventory.crystals, 18, 15);
}
}
///collect beer and increase lifepoints + 3
void p_environment_collect_beer (void) __banked
{
if (o_player.lifepoints != o_player.max_lifepoints - 3) {
o_player.lifepoints += 3;
}
else {
o_player.lifepoints = o_player.max_lifepoints;
}
p_hud_show_lifepoints ();
p_environment_clean_item ();
}
///collect key
void p_environment_collect_key (void) __banked
{
o_player.inventory.v_keys = true;
p_environment_clean_item ();
}
///collect big clock and increase dungeontime + 50
void p_environment_collect_big_clock (void) __banked
{
if (o_engine.v_dungeontimer <= 255 - 50) {
p_environment_clean_item ();
o_engine.v_dungeontimer += 50;
}
else {
p_environment_clean_item ();
o_engine.v_dungeontimer = 255;
}
p_hud_show_dungeontimer ();
}
///collect tiny clock and increase dungeontime + 25
void p_environment_collect_tiny_clock (void) __banked
{
if (o_engine.v_dungeontimer <= 255 - 25) {
p_environment_clean_item ();
o_engine.v_dungeontimer += 25;
}
else {
o_engine.v_dungeontimer = 255;
p_environment_clean_item ();
}
p_hud_show_dungeontimer ();
}
///collect black clock and decrease dungeontime - 15
void p_environment_collect_black_clock (void) __banked
{
o_engine.v_dungeontimer -= 15;
p_environment_clean_item ();
p_hud_show_dungeontimer ();
}
///collect items
void p_environment_collect_item (void) __banked
{
o_engine.v_tile [1] = p_engine_get_tile (o_player.mk);
if (o_engine.v_tile [1] == TILE_GOLD) p_environment_collect_gold ();
else if (o_engine.v_tile [1] == TILE_CRYSTAL) p_environment_collect_crystal ();
else if (o_engine.v_tile [1] == TILE_BEER) p_environment_collect_beer ();
else if (o_engine.v_tile [1] == TILE_KEY) p_environment_collect_key ();
else if (o_engine.v_tile [1] == TILE_BIG_CLOCK) p_environment_collect_big_clock ();
else if (o_engine.v_tile [1] == TILE_TINY_CLOCK) p_environment_collect_tiny_clock ();
else if (o_engine.v_tile [1] == TILE_BLACK_CLOCK) p_environment_collect_black_clock ();
}
void p_environment_shield (uint8_t l_mk, unsigned char l_txt[]) __banked
{
if (l_mk == o_player.mk) {
p_set_txt (1, 1, l_txt);
waitpad (J_A);
p_hide_txt ();
}
}