125 lines
2.7 KiB
Plaintext
125 lines
2.7 KiB
Plaintext
|
pico-8 cartridge // http://www.pico-8.com
|
||
|
version 42
|
||
|
__lua__
|
||
|
|
||
|
function _init()
|
||
|
cmgr0=cloud_manager:new(15,51,5,1,5,13)
|
||
|
cmgr1=cloud_manager:new(12,51-8,7,4,13,6)
|
||
|
cmgr2=cloud_manager:new(6,51-14,9,3,15,7)
|
||
|
cmgr0.step=5
|
||
|
cmgr1.step=4
|
||
|
cmgr2.step=3
|
||
|
last_x=0
|
||
|
x=0
|
||
|
dx=0
|
||
|
end
|
||
|
|
||
|
|
||
|
function _update60()
|
||
|
if (btn(4)) dx+=1.0
|
||
|
dx*=0.75
|
||
|
x+=dx
|
||
|
while last_x<x do
|
||
|
cmgr0:update()
|
||
|
cmgr1:update()
|
||
|
cmgr2:update()
|
||
|
last_x+=1
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function _draw()
|
||
|
cls(12)
|
||
|
cmgr0:draw()
|
||
|
cmgr1:draw()
|
||
|
cmgr2:draw()
|
||
|
end
|
||
|
|
||
|
cloud_manager={}
|
||
|
function cloud_manager:new(sparseness,y,h,oval_h,c0,c1)
|
||
|
local c={
|
||
|
frame=0,
|
||
|
clouds={},
|
||
|
bitplanes=split"241,242,244,248",
|
||
|
step=1,
|
||
|
sparseness=sparseness,
|
||
|
y=y,
|
||
|
c0=c0,
|
||
|
c1=c1,
|
||
|
h=h,
|
||
|
oval_h=oval_h
|
||
|
}
|
||
|
setmetatable(c,{__index=cloud_manager})
|
||
|
return c
|
||
|
end
|
||
|
|
||
|
function cloud_manager:update()
|
||
|
self.frame+=1
|
||
|
if self.frame%(self.step*self.sparseness) == 0 then
|
||
|
local bp=deli(self.bitplanes,1)
|
||
|
add(self.clouds,{x=127,y=rnd()*self.h,w=flr(rnd()*16)+16,plane=bp})
|
||
|
add(self.bitplanes,bp)
|
||
|
end
|
||
|
|
||
|
if self.frame%self.step==0 then
|
||
|
local clouds2={}
|
||
|
for c in all(self.clouds) do
|
||
|
c.x-=1
|
||
|
if (c.x+c.w>0) add(clouds2,c)
|
||
|
end
|
||
|
self.clouds=clouds2
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function cloud_manager:draw()
|
||
|
local r0=96
|
||
|
local r1=96+16
|
||
|
local h=self.h+self.oval_h+1
|
||
|
assert(h<=16)
|
||
|
|
||
|
-- render to spritesheet
|
||
|
poke(0x5f55,0x00)
|
||
|
rectfill(0,r0,127,r0+h,0)
|
||
|
|
||
|
-- use bitplanes
|
||
|
for c in all(self.clouds) do
|
||
|
poke(0x5f5e,c.plane)
|
||
|
ovalfill(c.x,r0+c.y,c.x+c.w,r0+c.y+self.oval_h,15)
|
||
|
end
|
||
|
poke(0x5f5e,255)
|
||
|
|
||
|
-- render from high memory
|
||
|
-- to higher memory
|
||
|
rectfill(0,r1,127,r1+h,0)
|
||
|
|
||
|
for i in all(split"0,1,2,4,8") do
|
||
|
palt(i,true)
|
||
|
end
|
||
|
for i=0,15 do
|
||
|
pal(i,7)
|
||
|
end
|
||
|
|
||
|
poke(0x5f5e,0xf1)
|
||
|
sspr(0,r0,128,h,0,r1)
|
||
|
poke(0x5f5e,0xf2)
|
||
|
sspr(0,r0,128,h,1,r1+1)
|
||
|
sspr(0,r0,128,h,5,r1+1)
|
||
|
poke(0x5f5e,255)
|
||
|
|
||
|
-- render to screen
|
||
|
poke(0x5f55,0x60)
|
||
|
pal()
|
||
|
pal(1,self.c1)
|
||
|
pal(2,self.c0)
|
||
|
pal(3,self.c1)
|
||
|
sspr(0,r1,128,h,0,self.y)
|
||
|
pal()
|
||
|
end
|
||
|
|
||
|
__gfx__
|
||
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
|
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
|
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|