pico-8 cartridge // http://www.pico-8.com version 16 __lua__ c=0 snowan=0 state_playing=1 state_gameover=2 state_win=3 state = state_playing player={} flag={x=0,y=0} packagetype=0 numpackages=15 particles={} enemies = {} m={} camx=0 function neigh(x,y) if x<0 or y<0 or x>512 or y>15 then return 0 end return m[x][y] end function _init() srand(0) music(0) sfx(1,1) player = { x=30, y=0, vy=0, vx=0, d=1, a=0, jump=false, ground=false, climb=false } local hy = 10 local lastsize=1 for x=0,512 do m[x]={} if lastsize>2 and rnd(100)<50 then hy += (rnd(2)-1)*5 hy=max(5,min(hy,15)) lastsize=1 else lastsize+=1 end for y=15,hy,-1 do m[x][y]=1 end end for x=0,512 do for y=0,16 do local t=m[x][y] local right=neigh(x+1,y) local left=neigh(x-1,y) local down=neigh(x,y+1) local up=neigh(x,y-1) if t then if right and left and down and up then if y%6==0 and rnd(100)<20 then m[x][y]=35 else m[x][y]=17 end elseif right and left and up then m[x][y]=17 elseif right and left and down then m[x][y]=20 elseif right and down and up then m[x][y]=34 elseif left and down and up then m[x][y]=18 elseif right and down then m[x][y]=19 elseif left and down then m[x][y]=21 elseif left then m[x][y]=18 elseif right then m[x][y]=34 elseif down then m[x][y]=22 else m[x][y]=1 end end end end local winx=400 for y=0,15 do if m[winx][y] then m[winx][y-1]=43 flag.x=winx*8 flag.y=(y-1)*8 break end end end function makeenemy(x, y) add(enemies, { x=x, y=y, vy=0, vx=0, d=1, a=0, jump=false, ground=false, climb=false }) end checkres={tx=0,ty=0} function check(x,y) local tx=flr(x/8) local ty=flr(y/8) local xt=m[tx][ty] local mf=fget(xt,1) if mf then checkres.tx=tx checkres.ty=ty return true end return false end walking=false function updateplayer() player.vx=0 if btn(0) then player.vx=-1 player.d=-1 elseif btn(1) then player.vx=1 player.d=1 end local result = checkentity(player) if player.vx~=0 and player.ground then if not walking then sfx(1,1) end walking = true else sfx(-1,1) walking = false end if btn(2) then if result == 0 then player.jump=true else player.climb=true end else player.climb=false player.jump=false end if btnp(4) and player.ground and numpackages>0 then local tx=flr(player.x/8) local ty=flr(player.y/8) if packagetype==1 and tx>0 and m[tx-1][ty+1] then m[tx-1][ty-1]=39 m[tx][ty-1]=40 m[tx-1][ty]=55 m[tx][ty]=56 numpackages-=3 else m[tx][ty]=38 numpackages-=1 end end if entitiesoverlap(player,flag) then state=state_win explode(player.x,player.y,7) end end function updateenemy(enemy) enemy.vx=0 if enemy.ground or enemy.climb then if player.xenemy.x then enemy.vx=2 enemy.d=1 end end local result = checkentity(enemy) if result ~= 0 then enemy.climb = true end if entitiesoverlap(enemy,player) then state=state_gameover end end function explode(x,y,color) for i=0,10 do local an=rnd(0.25)+0.125 local len=rnd(4)*0.5 local dx=cos(an)*len local dy=sin(an)*len add(particles,{x=x,y=y,vx=dx,vy=dy,color=color}) end end function updateparticle(particle) particle.x+=particle.vx particle.y+=particle.vy particle.vy+=0.05 if particle.y > 128 then del(particles,particle) end end function entitiesoverlap(first,second) return first.x+6>=second.x and first.xsecond.y-7 end function checkentity(entity) result = 0 local newx=entity.x+entity.vx --horizontal movement check if newx > entity.x then --right if check(newx+7,entity.y+5) then newx=checkres.tx*8-7 entity.vx=0 result = 1 end elseif newx < entity.x then --left if newx<0 then newx=0 entity.vx=0 result = -1 elseif check(newx,entity.y+5) then newx=checkres.tx*8+7 entity.vx=0 result = -1 end end --animation if c%8==0 then if newx==entity.x then entity.a=0 else entity.a=(entity.a+1)%2 end end --jump? if entity.jump and entity.ground then --btnp(2) and entity.ground then entity.vy=-3.5 sfx(0) end --gravity if not entity.climb then entity.vy+=0.2 if entity.vy>2 then entity.vy=2 end else if result==0 then entity.climb=false else entity.vy=-1 end end local newy=entity.y+entity.vy --vertical movement check if entity.vy>0 then if check(newx+6,newy+7) or check(newx+1,newy+7) then newy=checkres.ty*8-8 entity.ground=true entity.vy=1 else entity.ground=false end end if entity.vy<0 then entity.ground=false if check(newx+1,newy+4) or check(newx+6,newy+4) then entity.vy=0 newy=checkres.ty*8+4 end end entity.x=newx entity.y=newy return result end function drawmap() for x=0,16 do for y=0,16 do spr(6+snowan,x*8,y*8) end end spr(23,100,10) local camy = 0 local offsetx=camx%8 local offsety=camy%8 local tilex=flr(camx/8) local tiley=flr(camy/8) for x=0,16 do local tx=x+tilex for y=0,16 do if m[tx][y] then spr(m[tx][y],x*8-offsetx,y*8) end end end end function drawplayer() local screenx = 60 if player.x < 60 then screenx = player.x end spr(2+player.a,screenx,player.y,1,1,player.d==-1) end function drawenemy(enemy) spr(25+enemy.a,enemy.x-camx,enemy.y) end function drawparticle(particle) pset(particle.x-camx,particle.y,particle.color) end function _draw() cls(1) palt() palt(0,false) palt(14,true) camx = player.x - 60 if player.x < 60 then camx = 0 end drawmap() drawplayer() for enemy in all(enemies) do drawenemy(enemy) end for paket in all(packages) do drawpaket(paket) end for particle in all(particles) do drawparticle(particle) end spr(38,0,0) print(numpackages,10,2) spr(41+packagetype,0,10) if state==state_win then print("you saved xmas!",30,60,c) elseif state==state_gameover then print("the kids stole your presents!",6,60,c) end local closestenemyx=0 for enemy in all(enemies) do if enemy.x>closestenemyx then closestenemyx=enemy.x end end local playerdistpercent = (player.x / flag.x) * 68 local enemydistpercent = (closestenemyx / flag.x) * 68 rectfill(30,1,98,1,8) pset(playerdistpercent+30,1,7) pset(enemydistpercent+30,1,11) end spawned=false function _update60() if not spawned and c>60*5 then for i=0,9 do makeenemy(i*8,30) end spawned = true end if c%2==0 then snowan=(snowan+1)%8 end for particle in all(particles) do updateparticle(particle) end if state==state_playing then updateplayer() for enemy in all(enemies) do updateenemy(enemy) end if btnp(5) then packagetype=(packagetype+1)%2 end end c+=1 end __gfx__ 00000000ee7888eeeeeeeeeeeee788ee0000000000000000eeeeeeeeeeeeeeeeeeeeeeeeceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeceeeee0000000000000000 00000000eeeefffeeee888eeeeeeffee0000000000000000eeeceeeeeeeeeeeeeeeeeeeeeeeeeeeeeceeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000 00700700ee44fffeee7effeeee44ffee0000000000000000eeeeeeeeeeeeceeeeeeeeeeeeeeeeeeeeeeeeeeeeeceeeeeeeeeeeeeeeeeeeee0000000000000000 00077000e448fffeee44ffeee4488eee0000000000000000eeeeeeeeeeeeeeeeeeeeeceeeeeeeeeeeeeeeeeeeeeeeeeeeeeceeeeeeeeeeee0000000000000000 00077000e44888eee4488eeee4487eee0000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeceeeeeeeeeeeeeeeeeeeeeeeeeeeeeceee0000000000000000 00700700e44878eee4478eeeee888eee0000000000000000eeeeeceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeceeeeeeeeeeeeeeeeeeeeeeee0000000000000000 00000000ee8888eeee888eeeee0e0eee0000000000000000eeeeeeeeeeeeeeceeeeeeeeeeeeeeeeeeeeeeeeeceeeeeeeeeeeeeeeeeeeeeee0000000000000000 00000000eee0e0eeee000eeeeeeeeeee0000000000000000eeeeeeeeeeeeeeeeeeeeeeeceeeeeeeeeeeeeeeeeeeeeeeeeceeeeeeeeeeeeee0000000000000000 00000000888888888888885e77777777777777777777777777777777eeeeeeee00000000eeeeeeeeeeeeeeee0000000000000000000000000000000000000000 00000000222228222222285e00007700777700777777770088887788eee77eee00000000eeeeeeeeeeeaaeee0000000000000000000000000000000000000000 00000000222228222222285e000000000700000007000000e222222eee77eeee00000000eeeaaeeeeeaafaee0000000000000000000000000000000000000000 00000000222222222222225e000000000000000000000000e882222eee77eeee00000000eeaafaeeee3ffeee0000000000000000000000000000000000000000 00000000888888888888885e888888888888888888888888e222222eee77eeee00000000ee3ffeeeeef33fee0000000000000000000000000000000000000000 000000002282222222822266ee82222222822222228222eee222288eee77eeee00000000eef33feeee333eee0000000000000000000000000000000000000000 00000000228222222282225e668222222282222222822266e222222eeee77eee00000000ee333eeeee0e0eee0000000000000000000000000000000000000000 00000000222222222222225ee5222222222222222222225ee222222eeeeeeeee00000000ee00eeeeeeeeeeee0000000000000000000000000000000000000000 0000000000000000e5888888888888880000000000000000eeeeeeeeee999999899999ee88eeee8888eeee88eeeeeeee00000000000000000000000000000000 0000000000000000e5222822244444440000000000000000ee888eeee99889998999999e8eeeeee88eeeeee8e470707000000000000000000000000000000000 0000000000000000e5222822240040040000000000000000e99899ee9987889989999999eeeeeeeeee7777eee407070700000000000000000000000000000000 0000000000000000662222222477400400000000000000009998799e9988899889999999eee77eeeee7777eee470707000000000000000000000000000000000 0000000000000000e58888888447444400000000000000009998999e9998999899998888eee77eeeee7777eee4eeeeee00000000000000000000000000000000 0000000000000000e58222222400470400000000000000008888888e9999999888888999eeeeeeeeee7777eee4eeeeee00000000000000000000000000000000 0000000000000000e58222222407777400000000000000009998999e99998888999999998eeeeee88eeeeee8e4eeeeee00000000000000000000000000000000 0000000000000000e5222222244444440000000000000000e99899ee998899989999099988eeee8888eeee88777e7eee00000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000888999989990999900000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000999999989909999900000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000999999989999099900000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000999999989990990900000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000999999989999909900000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000999999889999099900000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000e99999899999999e00000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000ee999989999999ee00000000000000000000000000000000000000000000000000000000 __gff__ 0000000000000000000000000000000000020202020202000000000000000000000002020000020202000000000000000000000000000002020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 __map__ 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000131414150000000000131500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000131414141414150000000000000000221111120000000000221200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000221111111111120000001600000000221111120000000000221200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000221111111111120013141414150000221111120000000000221200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000221111111111120022111111120000221111120000000000221200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000221111111111120022111111120000221111120000000000221200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000221111111111120022111111120000221111111414141414111114141400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000221111111111120022111111120000221111111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000221111111111111411111111111414111111111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 __sfx__ 0003000004350073500a3501035015300183001d300203000c1000d1000f0000f0000f0000f0000f0000f000130000f000100000e000100000d00004000030000500008000180001300014000000000000000000 00060004206100110003600012002760024600226001f6001c6001a600176001560012600106000e6000c6000b60009600086000660005600036000160001600196001d600000000000000000000000000000000 00150004245502655029550285502450026500295002c0002c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0015000000000000000c0300c0300c0300c0300c0300c0300c0300c0300e0300e0300e0300e0300e0300e0300e0300e03011030110301103011030110301103011030110300c0300c0300c0300c0300c0300c030 001000200a6100c6100e6100f6100f61010610106101061010610106100f6100f6100e6100d6100c6100b6100a6100961008610086100861008610086100861008610096100a6100b6100c6100d6100e6100f610 __music__ 02 42430444 01 42444344 02 42444344