initial commit
This commit is contained in:
282
timetest.p8
Normal file
282
timetest.p8
Normal file
@@ -0,0 +1,282 @@
|
||||
pico-8 cartridge // http://www.pico-8.com
|
||||
version 42
|
||||
__lua__
|
||||
twodays=172800
|
||||
timescale=1
|
||||
stime={}
|
||||
ctime={}
|
||||
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 _update()
|
||||
ctime=dt:new()
|
||||
|
||||
ctime:from(currenttime())
|
||||
if (btn(⬆️)) and
|
||||
(btn(⬇️)) and
|
||||
(btn(⬅️)) and
|
||||
(btn(➡️)) and
|
||||
(btn(❎)) and
|
||||
(btn(🅾️)) then
|
||||
dset(0,0)
|
||||
printh("save reset")
|
||||
end
|
||||
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()
|
||||
what=ctime:tdiff(stime)
|
||||
if (btn(❎)) printh(what)--printh(stime:tostring())
|
||||
|
||||
k:update(what)
|
||||
end
|
||||
|
||||
function _draw()
|
||||
m:draw()
|
||||
ui:draw()
|
||||
p:draw()
|
||||
k:draw()
|
||||
end
|
||||
-->8
|
||||
p = { --player
|
||||
s=0,
|
||||
x=64,
|
||||
y=32,
|
||||
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={ --kid
|
||||
s=1,
|
||||
x=20,
|
||||
y=20,
|
||||
m=1, --modifier
|
||||
t = 0,
|
||||
growtime=1.30, -- 1 min 30 sec
|
||||
update = function(self,t)
|
||||
self.t=t*self.m
|
||||
pa = self.t/self.growtime
|
||||
if (pa<self.growtime) then
|
||||
self.s=3*pa+1
|
||||
else
|
||||
self.s=4
|
||||
end
|
||||
|
||||
end,
|
||||
draw = function(self)
|
||||
spr(self.s,self.x,self.y)
|
||||
end
|
||||
}
|
||||
|
||||
-->8
|
||||
m = { --map
|
||||
rox=0,
|
||||
roy=0,
|
||||
draw = function(self)
|
||||
map(0,0,0,0,16,8)
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
ui = {
|
||||
draw= function(self)
|
||||
rectfill(0,128,256,256,1)
|
||||
|
||||
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)
|
||||
end,
|
||||
read=function(self)
|
||||
dat=dget(1)
|
||||
tim=dget(2)
|
||||
dat/=10
|
||||
self.y = flr(dat)
|
||||
dat = (dat-self.y)*100
|
||||
self.mo= flr(dat)
|
||||
dat = (dat-self.mo)*100
|
||||
self.d=flr(dat)
|
||||
tim/=100
|
||||
self.h=flr(tim)
|
||||
tim = (tim - self.h)*100
|
||||
self.m=flr(tim)
|
||||
tim = (tim-self.m)*100
|
||||
self.s = flr(tim)
|
||||
|
||||
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
|
||||
__gfx__
|
||||
00000000000000000000000000000000111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000001111110166116610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00700700000000000011110001611610166116610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00077000000110000011610001612610166116610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00077000000110000011110001111110111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00700700000000000011110001211110111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000001111110111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
22222222dddddddd5555555555555554555555554444444455555555555444445555555544445555000000000000000000000000000000000000000000000000
|
||||
22222222d555555d5555555555555554555555555555555555555555555444445555555544445555000000000000000000000000000000000000000000000000
|
||||
22222222d555555d5555555555555554555555555555555555555555555444445555555544445555000000000000000000000000000000000000000000000000
|
||||
22222222d555555d5555555555555554555555555555555544444555555444445555555544445555000000000000000000000000000000000000000000000000
|
||||
22222222d555555d5555555555555554555555555555555544444555555444445554444455555555000000000000000000000000000000000000000000000000
|
||||
22222222d555555d5555555555555554555555555555555544444555555555555554444455555555000000000000000000000000000000000000000000000000
|
||||
22222222d555555d5555555555555554555555555555555544444555555555555554444455555555000000000000000000000000000000000000000000000000
|
||||
22222222dddddddd5555555555555554444444445555555544444555555555555554444455555555000000000000000000000000000000000000000000000000
|
||||
00000000007777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000007777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000077cc7700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000007cccc700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000077777700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000077777700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000077777700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000007777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
__gff__
|
||||
0000000000000000000000000000000000010101010101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
__map__
|
||||
1212121212121212121212121212121200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
1218141414141414141414141414161200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
1213101010101010101010101010111200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
1213101010101010101010101010111200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
1213101010101010101010101010111200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
1213101010101010101010101010111200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
1213101010101010101010101010111200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
1217151515151515151515151515191200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
1212121212121212121212121212121200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
Reference in New Issue
Block a user