-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
371 lines (297 loc) · 9.79 KB
/
main.lua
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
--! Assets
local menuSprites:SpriteSheet = gdt.ROM.User.SpriteSheets.Digimon1 -- Menu Sprites for main game
local bgs:SpriteSheet = gdt.ROM.User.SpriteSheets.bgs -- Background sprites for the game
local digimonSprites:SpriteSheet = gdt.ROM.User.SpriteSheets.digimonNIGHTMARE1 -- digimon Sprites looking left
local digimonSpritesFlip:SpriteSheet = gdt.ROM.User.SpriteSheets.digimonNIGHTMARE1Flip -- digimon Sprites looking right
local shitsing:AudioSample = gdt.ROM.User.AudioSamples["shitsing.wav"]
local flushing:AudioSample = gdt.ROM.User.AudioSamples["flushing.wav"]
local bootsnd:AudioSample = gdt.ROM.User.AudioSamples["boot.wav"]
--! Code modules
local digiCare = require("digiCare")
local timeTools = require("timeTools")
local webTools = require("webTools")
local gfx = require("gfx")
local dt = require("debugTools")
local debugPrint = dt.debugPrint
local createTimer = timeTools.createTimer
--! Hardware
local cpu:CPU = gdt.CPU0
local vid:VideoChip = gdt.VideoChip0 -- graphics chip
local web:Wifi = gdt.Wifi0 -- wifi web conectivity
local but0 = gdt.LedButton0 -- bottom button
local but1 = gdt.LedButton1 -- mid button
local but2 = gdt.LedButton2 -- top button
--? Flag to enable debugging messages
local debugBool = true
--? keep track of room info
local room = {
lights = true, -- room lights if on then true if off then false
r = 0 -- random number between (1, 0)
}
--? keep track of time deltas and frames
local timeDlt = {
counter = 0, -- this will keep track of DeltaTime
frameDuration = 1, -- how long in seconds it runs
frameNum = 0 -- keep track of the current frame
}
--? Time data i cant give info on this its pretty self explanatory
local time = {
seconds = 0,
minutes = 0,
hours = 0,
days = 0,
weeks = 0,
months = 0,
years = 0,
counter = 0,
health = {
condition = false, -- a warning to see if the condition of the time is bad and unupdated
updating = true -- if its updating or not
}}
--? keep track of digimon position and stats
local digimon = {
pos = vec2(35,24), -- possition of Digimon
r = 0, -- Random value
sleepTime0 = 0, -- Sleep timer
looking = 0, -- facing (0 = left, 1 = right)
sleeping = false -- if its sleeping or not
}
--? flush data
flush = {
ing = false, -- check if currently "flush-ing"
queue = 0, -- asks a queue if it can flush
posX = 55, -- possition of water
posY = 16 -- possition of water
}
--? keep track of menu
local menu = {
current = 0, -- current menu from (0, 9)
maxItems = 9, -- max number of items
isInsideMenu = false, -- check if its inside sub menu
isUnselected = false,-- check if its unselected
--? Define an array of menu items and their associated actions.
-- (0:info)
-- (1:feed)
-- (2:train)
-- (3:challange)
-- (4:flush)
-- (5:lights)
-- (6:patch)
-- (7:inteligence training)
-- (8:online)
-- (9:wip)
items = {
{name = "info", action = function()
debugPrint(time, debugBool,"info","Menu position 0 selected")
end},
{name = "feed", action = function()
debugPrint(time, debugBool,"info","Menu position 1 selected")
end},
{name = "train", action = function()
debugPrint(time, debugBool,"info","Menu position 2 selected")
end},
{name = "quest", action = function()
debugPrint(time, debugBool,"info","Menu position 3 selected")
end},
{name = "flush", action = function()
debugPrint(time, debugBool,"info","Menu position 4 selected")
-- if sleeping = true we cant flush
if not digimon.sleeping then
-- if room lights are of theres also no reason to flush
if room.lights then
gdt.AudioChip0:Play(flushing,2)
flush.queue = 1
flush.ing = 1
end
end
end},
{name = "Lights", action = function()
debugPrint(time, debugBool,"info","Menu position 5 selected")
-- turn on and off room lights
if not room.lights then
room.lights = true
elseif room.lights then
room.lights = false
end
end},
{name = "Patch", action = function()
debugPrint(time, debugBool,"info","Menu position 6 selected")
end},
{name = "Evo/info Album", action = function()
debugPrint(time, debugBool,"info","Menu position 7 selected")
end},
{name = "Online", action = function()
debugPrint(time, debugBool,"info","Menu position 8 selected")
end},
{name = "Alert", action = function()
debugPrint(time, debugBool,"info","Menu position 9 selected")
end},
},
-- This is a method of the `menu` object. It iterates over the `items` array and
-- executes the appropriate action based on the value of the `current` property.
select = function(self)
for i, item in ipairs(self.items) do
if self.current == i - 1 then
item.action()
end
end
end
}
--? keep track of position of selector
local cursor = {
pos = vec2(0,5), -- possition of the cursor
posX = 0, -- X possition of the cursor
posY = 5 -- Y possition of the cursor
}
--? as much as i dont want to we need to keep track of poop
local poop = {
r = 0,-- random number from 0, 10000
value = 0, -- time until digimon shits itself
hasHappend = false, -- if it has shat itself
anim = 0, -- number between 1, 0
pos = vec2(35, 35) -- shit position
}
--* this function handles the cursor position
--$ the object this function is attached to is menu and cursor
function CursorHandler()
-- everytime the button is clicked
menu.current += 1 -- menu position add 1
cursor.pos += vec2(15,0) -- move the position to 15 units
-- if the cursor position is over the screen we go to next
if cursor.pos.X > 60 then
cursor.pos = vec2(0, 50)
end
-- if its over the max options we go bac
if menu.current > menu.maxItems then
-- reseting positions
menu.current = 0
cursor.pos = vec2(0,5)
end
end
--* this function checks if we made a request to flush
--$ the object this function is attached to is flush, poop and it uses debugprint
function flushPoop()
--* check if we made a flush request
if flush.queue > 0.5 then
-- move the water left
flush.posX += -10
--$ if flush moved out of screen we set all values to default
if flush.posX < 2 then
flush.queue = 0
flush.posX = 55
flush.ing = false
if poop.hasHappend then
poop.hasHappend = false
poop.value = 0
debugPrint(time, debugBool,"info", "poop has been flushed")
else
debugPrint(time, debugBool,"info", "pressed flush with no shit") -- what a funny print
end
--$ endof poophashappend
end
--$ endof posX check
end
--$ endof flushqueue
end
--* this variable will count up to 8004 and then reset to 0 to run the time update
local webtimeC = 0
local timer = createTimer(
gdt.CPU0,
0.5,
function()
webtimeC = timeTools.runEvery(function()
time = webTools.getTimeFromWeb(time)
end,
webtimeC,
8004 -- 2 hours and 13 minutes
)
time = timeTools.incrementTime(time)
-- add 1 to the poop value
poop.value += 1
-- keeps track of time
-- timeTracker()
digimon.r = math.random(0, 1)
poop.anim = math.random(2, 3)
room.r = math.random(0, 1)
digimon = digiCare.digimonMover(digimon)
flushPoop()
end
)
local debugTimer = createTimer(
gdt.CPU0,
5,
function()
--todo| info about positions for debugging
debugPrint(time, debugBool,"digimon", "Digimon", "X" .. digimon.pos.X, "Y" .. digimon.pos.Y )
debugPrint(time, debugBool,"debug", "Cursor", "X".. cursor.pos.X, "Y".. cursor.pos.Y, "Menu:", menu.current)
--$ check if condition of time health is ok
if not time.health.condition and time.health.updating then
debugPrint(time, debugBool,"warning", "TimeNotStarted/NotUpdated YOU ARE OFFLINE")
local countRestart = 0
countRestart += 1
if countRestart == 12 then
time = webTools.getTimeFromWeb(time)
end
end --$ endof timeHealth check
end)
local boot = false
--! ################################################
--! ######## MAIN GAME LOOP ########################
--! ################################################
function update()
if not boot then
gdt.AudioChip0:Play(bootsnd,1)
gfx.drawBoot()
sleep(2)
boot = true
end
--! important updater
timer.update()
debugTimer.update()
-- clears the screen
vid:Clear(Color(18,14,32))
-- draws the background
gfx.drawbg(room)
-- increase the counter by the CPU's DeltaTime
timeDlt.counter += gdt.CPU0.DeltaTime
-- does colision for digimon
digimon = digiCare.colision(digimon)
-- handdler for digimon stuff
digimon = digicare.digimonHandler(digimon)
-- checks if you shat yourself
poop = digiCare.poopCheck(digimon, poop)
-- draw funny poopoo.... uhhhh
gfx.drawPoop(poop)
-- draws the little waves to flush shit
gfx.drawflush(flush)
-- draws the digimon
gfx.drawDigimon(digimon)
-- this function will draw the menu sprites
gfx.drawMenuSprites(digimon, room)
-- draws the cursor
gfx.drawSelSprite(cursor)
if but2.ButtonDown then
if flush.ing == false and room.lights == true then
-- every time we exec this cursor moves to apropiate place
-- cycle tru menu
CursorHandler()
end
end
if but1.ButtonDown then
-- selects the item you where hovered over
menu:select()
end
if but0.ButtonDown then
-- debug shityourself button
poop.value += 5000
-- digimon.pos += vec2(4, 0)
-- digimon.sleepTime0 += 28799
--if not debugBool then
-- debugBool = true
--elseif debugBool then
-- debugBool = false
--end
end
-- Time tracker
local elapsed = timer.getTotalTime()
end