-
Notifications
You must be signed in to change notification settings - Fork 0
/
items.c
134 lines (116 loc) · 3.38 KB
/
items.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
// 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
#define TILE_BEER 75
#define TILE_WHETSTONE 39
#define TILE_BOMB 73
#define BEER 1
#define WHETSTONE 2
#define BOMB 3
#include "items.h"
#include "player.h"
#include "hud.h"
#include "engine.h"
struct s_tools_t o_pickaxe;
struct s_tools_t o_steel_pickaxe;
///init
void p_items_init (void) __nonbanked
{
o_pickaxe.v_status = 5; o_pickaxe.v_max_status = 5;
o_steel_pickaxe.v_status = 8; o_steel_pickaxe.v_max_status = 8;
}
///use food
void p_items_use_proviant (void) __nonbanked
{
if (o_player.v_steps == 255) {
o_player.v_steps = 0;
if (o_player.inventory.food != 0) {
--o_player.inventory.food;
p_hud_show_food ();
}
else if (o_player.inventory.food == 0) {
--o_player.lifepoints;
p_hud_show_lifepoints ();
}
}
}
///
void p_items_use_tool (void) __nonbanked
{
if (o_player.v_hitcounter == 80) {
o_player.v_hitcounter = 0;
if (o_pickaxe.v_status != 0) {
--o_pickaxe.v_status;
p_hud_show_tool_status ();
}
}
}
///use whetstone
void p_items_use_whetstone (void) __nonbanked
{
if ((o_player.inventory.whetstone != 0) && (o_pickaxe.v_status != o_pickaxe.v_max_status)) {
--o_player.inventory.whetstone;
o_pickaxe.v_status = o_pickaxe.v_max_status;
p_hud_show_tool_status ();
if (o_player.inventory.whetstone == 0) p_engine_set_tile (8, 14, 40);
}
}
///use beer
void p_items_use_beer (void) __nonbanked
{
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 ();
--o_player.inventory.beer;
if (o_player.inventory.beer == 0) p_engine_set_tile (8, 14, 41);
}
///use items
void p_items_use (void) __nonbanked
{
if (o_player.v_active_item == WHETSTONE) p_items_use_whetstone ();
else if (o_player.v_active_item == BEER) p_items_use_beer ();
}
///select an items
void p_items_select (void) __nonbanked
{
if (o_player.v_active_item == 0) {
p_engine_set_tile (8, 14, 41);
if (o_player.inventory.beer != 0) p_engine_set_tile (8, 14, TILE_BEER);
o_player.v_active_item = BEER;
}
else if (o_player.v_active_item == BEER) {
p_engine_set_tile (8, 14, 40);
if (o_player.inventory.whetstone != 0) p_engine_set_tile (8, 14, TILE_WHETSTONE);
o_player.v_active_item = WHETSTONE;
}
else if (o_player.v_active_item == WHETSTONE) {
p_engine_set_tile (8, 14, 42);
if (o_player.inventory.bombs != 0) p_engine_set_tile (8, 14, TILE_BOMB);
o_player.v_active_item = BOMB;
}
else if (o_player.v_active_item == BOMB) {
p_engine_set_tile (8, 14, TILE_CLEAN);
o_player.v_active_item = 0;
}
delay (200);
}