Files
pico8/zeldagochi.p8
2025-07-25 11:46:41 +02:00

519 lines
19 KiB
Lua
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

pico-8 cartridge // http://www.pico-8.com
version 42
__lua__
-- notes about memory layout
--0 is flag if time has
--been set yet
--1 is the start date i think
--2 is the start time i think
--10 and onward gonna use
--for persistent storage of
--the kid stuff
--10 is the modifier
function _init()
printh("init")
cartdata("savedgame")
timeset = dget(0)
stime=dt:new()
if (timeset==0) then
stime:from(currenttime())
printh("save:"..stime:tostring())
stime:save()
else
stime:read()
printh("read:"..stime:tostring())
-- printh("starttime = ".. )
end
cls()
-- printh("goaltime"..goaltime)
m:draw()
ui:draw()
end
function _update60()
ctime=dt:new()
m:update()
ctime:from(currenttime())
if (btn()) and
(btn()) and
(btn()) and
(btn()) and
(btn()) and
(btn(🅾)) then
dset(10,0) --reset kid state
dset(0,0) --reset timesaved flag
printh("save reset")
end
k:update(stime,ctimed)
k:save()
state[stated]:update()
end
function _draw()
state[stated]:draw()
end
-->8
p = { --player
s=0,
x=64,
y=64,
w=8,
h=8,
s=1,
xv = 0,
yv = 0,
draw = function(self)
spr(s,self.x,self.y)
end,
input = function(self, xv, yv)
self.xv = xv
self.yv = yv
end,
move = function(self)
if not (hitx(self.x+self.xv,self.y,self.w,self.h)) then
self.x+= self.xv
end
if not (hity(self.x,self.y+self.yv,self.w,self.h)) then
self.y+= self.yv
end
end
}
k={ --him
s=1,
x=196,
y=64,
m=1, --modifier
t = 0,
growtime=3.600,
update = function(self,start,current)
self.m = dget(10) --get last m
temp = tts()
self.t=temp-self.m
if (self.t<0) then
self.t=0
self.m=0
dset(10,self.m)
end
pa = self.t/self.growtime
if (self.t<self.growtime) then
self.s=3*pa+1
else
self.s=4
end
if flr(p.x/8)==flr(self.x/8) and flr(p.y/8)==flr(self.y/8) then
self.x=64+(128*(flr(rnd(2))))
self.y=64+(128*(flr(rnd(2))))
self.m+=1
fx=3/self.growtime*self.t
printh(fx)
sfx(flr(3/self.growtime*self.t),-1,0,0)
end
end,
draw = function(self)
spr(self.s,self.x,self.y)
end,
save=function(self)
dset(10,self.m)
end
}
-->8
m = { --map
cx=0,--camera x
cy=0,--camera y
--camera velocity
cvx=0,
cvy=0,
--target x and y
tx=0,
ty=0,
t=false,--transition
update= function(self)
tile = (mget(p.x/8,p.y/8))
f=fget(tile)
if (f>1) then
printh(f)
printh(p.x)
printh(p.y)
self.t = true
if ((f & 0x2)!=0) then
--n
printh("n")
self.cy-=128
p.y-=16
elseif ((f&0x4)!=0) then
--e
self.cx+=128
p.x+=16
printh("e")
elseif ((f&0x8)!=0) then
--s
printh("s")
self.cy+=128
p.y+=16
else
--w
self.cx-=128
p.x-=16
printh("oops")
end
else
self.t=false
end
end,
draw = function(self)
cls()
camera(self.cx,self.cy)
map()
end
}
dt = {
s=0,
m=0,
h=0,
d=0,
mo=0,
y=0,
tostring=
function(self)
return self.s..":"
..self.m..":"
..self.h.." "
..self.d.."-"
..self.mo.."-"
..self.y
end,
from=function(self, obj)
self.s = obj.s
self.m = obj.m
self.h = obj.h
self.d = obj.d
self.mo = obj.mo
self.y = obj.y
end,
save=function(self)
-- dset(1,self:dat())
-- dset(2,self:tim())
dset(0,1)
dset(1, self.s)
dset(2, self.m)
dset(3, self.h)
dset(4, self.d)
dset(5, self.mo)
dset(6, self.y)
end,
read=function(self)
self.s=dget(1)
self.m=dget(2)
self.h=dget(3)
self.d=dget(4)
self.mo=dget(5)
self.y=dget(6)
end,
dat=function(self)
return self.y*10+self.mo/10+self.d/1000
end,
tim=function(self)
return self.h*100+self.m+self.s/100
end,
tdiff=function(self,obj)
return self:tim()-obj:tim()
end,
ddiff=function(self,obj)
return self:dat()-obj:dat()
end
}
function dt:new(obj)
obj = obj or {}
setmetatable(obj, {__index = self})
return obj
end
-->8
-- check hit on top or bottom
function hity(x,y,w,h) --check hit on top or bottom
hit=false
for i=x,x+w do
tile1=mget(i/8,y/8)
tile2=mget(i/8,(y+h)/8)
if (fget(tile1,0)) then
hit=true
elseif (fget(tile2,0)) then
hit=true
end
end
return hit
end
--check hit on sides
function hitx(x,y,w,h) --check hit on sides
hit = false
for i=y,y+h do
tile1=mget(x/8,i/8)
tile2=mget((x+w)/8,i/8)
if (fget(tile1,0)) then
hit=true
elseif (fget(tile2,0)) then
hit=true
end
end
return hit
end
-- returns the current time.
--i have to split it up fml
function currenttime()
t = {
s=stat(95),
m=stat(94),
h=stat(93),
d=stat(92),
mo=stat(91),
y=stat(90)
}
return t
end
--timetosec
function tts()
temp = (ctime.s-stime.s)/1000
temp += (ctime.m-stime.m)*.06
temp += (ctime.h-stime.h)*3.6
temp += (ctime.d-stime.d)*86.4
temp += (ctime.mo-stime.mo)*1036.8
if (temp > 32767.99)
or ((ctime.y-stime.y)>0)
then
stated = 3 --game over
end
return temp
end
-->8
state={
{--1 menu
update=function(self)
--pause toggle
if (btnp()) then
stated=2
end
end,
draw=function(self)
ui:draw()
end
},
{--2 gameplay
update=function(self)
if (btn(🅾)) printh(ctime:tostring())
xv = 0
yv = 0
if (btn()) xv+=p.s
if (btn()) xv-=p.s
if (btn()) yv-=p.s
if (btn()) yv+=p.s
p:input(xv,yv)
p:move()
--pause toggle
if (btnp()) then
stated=1
end
end,
draw=function(self)
m:draw()
p:draw()
k:draw()
end
},
{ --3 game over
update=function(self)
end,
draw=function(self)
cls()
print("you lose... the creature grew too much")
print("hold ⬆️⬇️⬅️➡️❎🅾️ to reset save")
end,
},
{--4 intro
update=function(self)
if (btnp()) stated=2
end,
draw=function(self)
cls()
x=rnd(2)
y=rnd(2)
if (timeset==0) then
print("the is growing",0,0,7)
print("creature",x+16,y+1,2)
print("creature",x+16,y,8)
else
print("the growth never stops",0,0,7)
print("creature's",x+16,y+1,2)
print("creature's",x+16,y,8)
end
print(" seeks comfort.",0,8,7)
print("it",x,7+y,2)
print("it",x,8+y,8)
print("find .",0,16,7)
print("it",x+18,15+y,2)
print("it",x+18,16+y,8)
print("soothe .",0,24,7)
print("it",x+27,23+y,2)
print("it",x+27,24+y,8)
print("pres x to continue",0,80,7)
print(k.t)
end,
}
}
-->8
ui = {
elements={
kidgrowth={
text="-his- growth%: ",
x=40,
y=64,
c=7, --color
w=20,
h=20,
draw=function(self)
print(self.text..k.t/k.growtime*100,self.x, self.y, self.c)
end
},
kidalive={
text="your kid's been alive for: ",
x=0,
y=4,
c=7, --color
w=20,
h=20,
draw=function(self)
print(self.text,self.x, self.y, self.c)
print(k.t.."s",self.x, self.y+8, self.c)
end
},
testing={
text="-his- state: ",
x=40,
y=72,
c=7, --color
w=20,
h=20,
draw=function(self)
print(self.text..k.m,self.x, self.y, self.c)
end
}
},
draw= function(self)
cls()--clear screen
camera() --reset the camera to default pos
rectfill(0,0,128,128,1)
for k,v in pairs(self.elements) do
v:draw()
end
end
}
-->8
--global vars
stated=4
twodays=172800
timescale=1
stime={}
ctime={}
timeset=0
__gfx__
00000000000000000000000000000000111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000001111110166116610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000011110001611610166116610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000110000011610001612610166116610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000110000011110001111110111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000011110001211110111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000001111110111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
22222222555555555555555555555554555555554444444455555555555444445555555544445555000000000000000000000000000000000000000000000000
2222222256dddd655555555555555554555555555555555555555555555444445555555544445555000000000000000000000000000000000000000000000000
222222225dddddd55555555555555554555555555555555555555555555444445555555544445555000000000000000000000000000000000000000000000000
222222225dddddd55555555555555554555555555555555544444555555444445555555544445555000000000000000000000000000000000000000000000000
222222225dddddd55555555555555554555555555555555544444555555444445554444455555555000000000000000000000000000000000000000000000000
222222225dddddd55555555555555554555555555555555544444555555555555554444455555555000000000000000000000000000000000000000000000000
2222222256dddd655555555555555554555555555555555544444555555555555554444455555555000000000000000000000000000000000000000000000000
22222222555555555555555555555554444444445555555544444555555555555554444455555555000000000000000000000000000000000000000000000000
22222222007777002222222222222222222222222222222200000000000000000000000000000000000000000000000000000000000000000000000000000000
22222222007777002222222222222222222222222222222200000000000000000000000000000000000000000000000000000000000000000000000000000000
22222222077cc7702211112222111122221111222211112200000000000000000000000000000000000000000000000000000000000000000000000000000000
2222222207cccc702212212222122122221221222212212200000000000000000000000000000000000000000000000000000000000000000000000000000000
22222222077777702212212222122122221221222212212200000000000000000000000000000000000000000000000000000000000000000000000000000000
22222222077777702211112222111122221111222211112200000000000000000000000000000000000000000000000000000000000000000000000000000000
22222222077777702222222222222222222222222222222200000000000000000000000000000000000000000000000000000000000000000000000000000000
22222222007777002222222222222222222222222222222200000000000000000000000000000000000000000000000000000000000000000000000000000000
__gff__
0000000000000000000000000000000000010101010101010101000000000000000002040810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010102325101010101010101010101010101023251010101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010102325101010101010101010101010101023251010101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010102325101010101010101010101010101023251010101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111111111111111111111111111111111111111111110101010111111111111111111111111111010101011111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111111111111111111111111111111111111111111124242424111111111111111111111111112424242411111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111111111111111111111111111111111111111111122222222111111111111111111111111112222222211111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111111111111111111111111111111111111111111110101010111111111111111111111111111010101011111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010102325101010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010102325101010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101023251010101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101023251010101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111101010101010101010101010111111111010101010101010101010101111111110101010101010101010101011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__sfx__
000200000251002510085103a310363202c3201f3300f33039330263302131014420032200b2203042034220184202422016420164200352021520194202e52013520174200c5300742008420014201151000000
000200000a3200a3200a3200a3200a3200a3200a3100b3100c3100d3100f310113101231015310183101c3201f3201e2202023021230202301f2301e2201c2201b2221a6221762215620146200a6200062000000
000200000437004370043700437004360043600436004360043600936009360083600837007370063700637006370063700637005370053700537004370043700436004360053700537005370000700000000000