-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.adept
183 lines (154 loc) · 6.1 KB
/
main.adept
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
pragma compiler_version '2.3'
pragma project_name 'tadpole'
#default indev false
import '2.3/basics.adept'
import '2.3/captain.adept'
import '2.3/List.adept'
import '2.3/random.adept'
import '2.3/where.adept'
import 'GameData.adept'
import 'Textures.adept'
import 'Player.adept'
import 'House.adept'
import 'Label.adept'
import 'Text.adept'
import 'Pet.adept'
import 'util.adept'
import 'AABB.adept'
import 'Inventory.adept'
import 'SaveDialog.adept'
import 'savegame.adept'
gamedata GameData
textures Textures
func main {
unless captPrepare(), return
captOnSetup(func &onSetup)
captOnStep(func &onStep)
captOnClick(func &onClick, true)
captOnKey(func &onKey)
captOnDraw(func &onDraw)
captOnExit(func &onExit)
captCustomView(640.0f, 480.0f)
captStart('Tadpole', (640 * 1.5) as int, (480 * 1.5) as int, false)
}
func onSetup {
randomize()
#unless indev
captHideCursor(true)
#end
assetsFolder String = where() + "assets/"
textures.load(assetsFolder)
gamedata.init()
}
func onExit {
textures.destroy()
}
func onStep {
// Don't update anything if save dialog is open
if gamedata.save_dialog.shown, return
switch gamedata.scene_kind {
case SceneKind::OVERWORLD
unless gamedata.inventory.shown {
gamedata.player.update()
each House in gamedata.houses, it.update()
} else {
gamedata.inventory.update()
}
if captKeyHeld(GLFW_KEY_SPACE) {
unless gamedata.inventory_lock {
gamedata.inventory.toggle()
gamedata.inventory_lock = true
}
} else gamedata.inventory_lock = false
case SceneKind::BATTLE
if gamedata.inventory.getTotalPets() > 0 {
pet Pet = gamedata.inventory.getPet(0)
gamedata.friendly_pet_label.set("friend\n" + pet.getName() + "\n" + pet.getHealthBar())
gamedata.move_labels[0].set("tickle")
gamedata.move_labels[1].set("pounch")
gamedata.move_labels[2].set("bounce")
gamedata.move_labels[3].set("skidaddle")
gamedata.enemy_pet_label.set("foe\n" + gamedata.enemy.getName() + "\n" + gamedata.enemy.getHealthBar())
}
if captKeyHeld(GLFW_KEY_UP) {
unless gamedata.select_lock || gamedata.selected_a_move, gamedata.select--; gamedata.select_lock = true; gamedata.reset_time = glfwGetTime()
} else if captKeyHeld(GLFW_KEY_DOWN) {
unless gamedata.select_lock || gamedata.selected_a_move, gamedata.select++; gamedata.select_lock = true; gamedata.reset_time = glfwGetTime()
} else if captKeyHeld(GLFW_KEY_SPACE) {
unless gamedata.select_lock || gamedata.selected_a_move {
gamedata.selected_a_move = true
gamedata.select_lock = true
gamedata.reset_time = glfwGetTime()
gamedata.enemy.health -= gamedata.select
if gamedata.enemy.isDead() {
gamedata.inventory.getPetPointer(0).giveXp(gamedata.enemy.max_health)
gamedata.enemy.health = gamedata.enemy.max_health
gamedata.inventory.addPet(gamedata.enemy)
gamedata.gotoScene(gamedata.return_from_battle)
}
}
} else {
gamedata.select_lock = false
}
}
}
func onClick(x, y float, button int) {
#if indev
if button == 1, print("% %" % (x as int / 32 * 32) % (y as int / 32 * 32))
#end
}
func onKey(key, scancode, action, mods int) {
if action == GLFW_PRESS {
if key == GLFW_KEY_ENTER && gamedata.scene_kind == SceneKind::OVERWORLD && !gamedata.inventory.shown {
gamedata.save_dialog.toggle()
} else if gamedata.save_dialog.shown {
gamedata.save_dialog.keyPress(key)
}
}
}
func onDraw {
drawBackground()
switch gamedata.scene_kind {
case SceneKind::OVERWORLD
each House in gamedata.houses, it.draw()
total_pets int = gamedata.inventory.getTotalPets()
repeat total_pets {
pet Pet = gamedata.inventory.getPet(idx)
pet.draw(gamedata.player.getPetPosition(idx))
}
gamedata.player.draw()
if gamedata.save_dialog.shown {
gamedata.save_dialog.draw()
} else if gamedata.inventory.shown {
gamedata.inventory.draw()
}
case SceneKind::BATTLE
if gamedata.inventory.getTotalPets() > 0 {
gamedata.friendly_pet_label.draw(32.0f, 320.0f - 48.0f)
captDrawTexture(gamedata.inventory.getPetPointer(0).texture, 32.0f, 320.0f, 128.0f, 128.0f)
arrow_x_offset float = gamedata.selected_a_move as float * (glfwGetTime() - gamedata.reset_time) as float * 4096.0f
captDrawTexture(textures.arrow, 192.0f + arrow_x_offset + 8.0f + 4.0f * sin((glfwGetTime() - gamedata.reset_time) * 8.0f), 320.0f + 32.0f * gamedata.select as float, 32.0f, 32.0f)
if arrow_x_offset > 640.0f {
gamedata.selected_a_move = false
gamedata.reset_time = glfwGetTime()
}
repeat 4 {
if gamedata.selected_a_move && gamedata.select == idx, continue
x_offset float = cast float (gamedata.select == idx) * 4.0f * sin((glfwGetTime() - gamedata.reset_time) * 8.0f)
gamedata.move_labels[idx].draw(240.0f + x_offset, 320.0f + 12.0f + 32.0f * idx as float)
}
gamedata.enemy_pet_label.draw(416.0f, 64.0f - 48.0f)
captDrawTexture(gamedata.enemy.texture, 416.0f, 64.0f, 128.0f, 128.0f)
}
}
}
func drawBackground {
switch gamedata.background {
case Background::GRASS
drawTiled(textures.grass, 0.0f, 0.0f, 32.0f, 32.0f, 640.0f, 480.0f)
case Background::ABYSS
drawTiled(textures.abyss, 0.0f, 0.0f, 32.0f, 32.0f, 640.0f, 480.0f)
case Background::ABYSS_GREY
drawTiled(textures.abyss_grey, 0.0f, 0.0f, 32.0f, 32.0f, 640.0f, 480.0f)
}
}