pico-8 cartridge // http://www.pico-8.com version 42 __lua__ --main function _init() printh("init") cartdata("lou") poke(0x5f34,0x2) --enable rfill lou:init() printh("lou age: "..lou.age) menuitem(1,pauseitems[pauseindex],pauseupdate()) menuitem(2,"wim's song", function(b) phraselen=64 phrases={ {n=16,l=phraselen}, {n=17,l=phraselen}, {n=18,l=phraselen}, {n=19,l=phraselen}, {n=20,l=phraselen}, {n=21,l=phraselen} } bgm:set(phrases) end ) cop=1 end function _update() lou.age+=sincelast() if (btn(❎) and btn(🅾️)) cs=1 if (btn(❎) and btn(🅾️) and btn(⬆️) and btn(⬇️) and btn(⬅️) and btn(➡️)) then lou:reset() end if (lcs!=cs) then printh(state[cs]) printh(cs) state[cs]:init() end lcs=cs savedate() state[cs]:update() bgm:loop() fc+=1 lou:update() end function _draw() -- cls() state[cs]:draw() for r in all(routines) do if (costatus(r)!="dead") assert(coresume(r)) end end -->8 --globals gameover=false cs=1 --current state fc=0 --frame counter lcs=0 --last cs maxtime=.30 --maximum time before lou fully grown routines={} --list of sprites --order contains a 2d array j -- with the sprite index in order --w width --h height --xo x offset --yo y offset sprites={ lou={ order={ 0,16 }, w=1, h=1, xo=0, yo=0 }, sam={ order={ 1,2, 17,18 }, w=2, h=2, xo=0, yo=0 } } gib="asdwuhvzbregtnyuiopmh●✽★🐱ˇ♪♥◆⌂웃😐?!#$%" sentences={ "hi", "lorem", "ipsum", "♥♥♥", "asdfkjasdf" } pauseitems={ "<- stats ->", "<- reset save ->" } pauseindex=1 -->8 --functions function savedate() dset(0,stat(90))--year dset(1,stat(91))--month dset(2,stat(92))--day dset(3,stat(93))--hour dset(4,stat(94))--minute dset(5,stat(95))--second end function sincelast() y=(stat(90)-dget(0)) if y>0 then gameover=true end y=0 mo=(stat(91)-dget(1))*25.920 --30 days in a month d=(stat(92)-dget(2))*864 h=(stat(93)-dget(3))*36 m=(stat(94)-dget(4))*.6 s=(stat(95)-dget(5))*.01 return s+m+h+d+mo+y end function inits() state[cs].init() end function isoverlap(x1min,x1max,x2min,x2max) return x1max>= x2min and x2max >= x1min end --bbox:{ --{ minx, miny}, --{ maxx, maxy} --} function touching(bbox1,bbox2) return isoverlap(bbox1[1][1], bbox1[2][1], bbox2[1][1], bbox2[2][1]) and isoverlap(bbox1[1][2], bbox1[2][2], bbox2[1][2], bbox2[2][2]) end function pauseupdate(key) if(not key) return if(key&1>0) pauseindex+=1 if(key&2>0) pauseindex-=1 pauseindex=min(max(pauseindex,0),count(pauseitems)+1) menuitem(1,pauseitems[pauseindex],pauseupdate()) return true end --animations --animcounter=0 --s = next state function lerp(x,y,t) return x+(y-x)*t end function async(func) printh("euh") add(routines,cocreate(func)) printh(count(routines)) end function fadeout() for i=0,32 do fillp(▒) circfill(64,64, lerp(128*.75,0,i/32),0|0x1800) fillp() circfill(64,64, lerp(128,0,i/32),0|0x1800) yield() end cs=ns end function fadein() for i=0,32 do fillp(▒) circfill(64,64, lerp(0,128*.75,i/32),0|0x1800) fillp() circfill(64,64, lerp(0,128,i/32),0|0x1800) yield() end end -->8 --state state={ {--1 menu update=function(self) menu:update() end, draw=function(self) menu:draw() end, init=function(self) menu:init() end }, { --2 gameplay update=function(self) play:update() end, draw=function(self) play:draw() end, init=function(self) play:init() end }, { --3 feed update=function(self) end, draw=function(self) end, init=function(self) end }, { --4 language update=function(self) end, draw=function(self) end, init=function(self) end }, { --5 stats update=function(self) stats:update() end, draw=function(self) stats:draw() end, init=function(self) end }, {--6 thecube update=function(self) cube:update() end, draw=function(self) cube:draw() end, init=function(self) cube:init() end } } --lou lou={ new=1, age=0, excitement=0, strength=2, s=1, --sprite index state sentence="", saychance=function(self) if(flr(time())%8)!=0 return 0 ca=self.age/1728*100 chance=ca+self.excitement s="" if chance<.30 then --not ready for language for i=0,rnd()*5 do le=flr( rnd()*#gib ) s=s..sub(gib,le,le) end else --potential first words s=sentences[flr(rnd(ca)*count(sentences))+1] end self.sentence=s return flr(rnd()*6) end, init=function(self) self.new=dget(10) if self.new == 0 then --new lou self.new=1 self.age=0 --overwrite date for first time savedate() self:update() else self.age=dget(11) self:update() end end, update=function(self) dset(10,self.new) dset(11,self.age) self.s=min(count(sprites.lou.order),flr(count(sprites.lou.order)*(self.age/maxtime))+1) end, reset=function(self) self.age=0 dset(10,0) self:init() end } --bgm bgm={ tracklist={ }, c=1, t=1, set=function(self,obj) self.tracklist=obj bgm.c=1 bgm.t=1 end, loop=function(self) if (self.t>self.tracklist[min(count(self.tracklist),self.c)].l) self.t=1 if self.t==1 then printh("playing") if self.c>count(self.tracklist) then self.c=1 end music(self.tracklist[self.c].n) printh(self.tracklist[self.c].n) self.c+=1 end self.t+=1 end } -->8 --gameplay --menu menu={ tracks={ { n=0, l=127 }, { n=1, l=127 }, }, items={ { text="play", x=3, y=12, w=16, h=6, c=11, b=13, s=2 }, { text="feed", x=3, y=22, w=16, h=6, c=1, b=13, s=3 }, { text="stats", x=3, y=32, w=20, h=6, c=1, b=13, s=5 }, { text="language", x=3, y=42, w=33, h=6, c=1, b=13, s=4 }, { text="thecube", x=3, y=52, w=28, h=6, c=2, b=8, s=6 }, }, speaktimer=0, selected=1, init=function(self) async(function() fadein() end) bgm:set(self.tracks) end, update=function(self) if btnp(⬆️) then self:up() elseif btnp(⬇️) then self:down() elseif btnp(❎) then ns=self.items[self.selected].s async(function() printh("euh") fadeout(ns) end) end end, draw=function(self) rectfill(0,0,127,127,12) map() for k,v in pairs(self.items) do rectfill(v.x-2,v.y-2,v.x+v.w,v.y+v.h,v.b) print(v.text,v.x,v.y,v.c) if (k == self.selected) rect(v.x-2,v.y-2,v.x+v.w,v.y+v.h,10) end rectfill(88,8,105,24,7) rectfill(89,9,104,23,4) self:drawlou() end, drawlou=function(self) if self.speaktimer>0 then local sen = lou.sentence print(sen, 88, 27,3) self.speaktimer-=1 else self.speaktimer=lou:saychance()*15 end spr(sprites.lou.order[lou.s], 92+(cos(time()*.12)*lou.strength), 14-(sin(time()*.08)*lou.strength)) end, up=function(self) t={h=-1,v=self.selected} for k,i in pairs(self.items) do if i.yt.h then t.h,t.v=i.y,k end end self.selected=t.v end, down=function(self) t={h=32000,v=self.selected} for k,i in pairs(self.items) do if i.y>self.items[self.selected].y and i.y