148 lines
6.2 KiB
Lua
148 lines
6.2 KiB
Lua
pico-8 cartridge // http://www.pico-8.com
|
|
version 42
|
|
__lua__
|
|
function _init()
|
|
add(entities,player:new())
|
|
for i=0,20 do
|
|
printh("")
|
|
end
|
|
end
|
|
|
|
function _update60()
|
|
b=btn()
|
|
for e in all(entities) do
|
|
e:update()
|
|
end
|
|
end
|
|
|
|
function _draw()
|
|
cls()
|
|
map()
|
|
for e in all(entities) do
|
|
e:draw()
|
|
|
|
end
|
|
|
|
end
|
|
-->8
|
|
--globals
|
|
--global environment
|
|
global=_ENV
|
|
|
|
--class
|
|
class=setmetatable({
|
|
new=function(_ENV,tbl)
|
|
tbl=setmetatable(tbl or {},{
|
|
__index=_ENV
|
|
})
|
|
|
|
tbl:init()
|
|
|
|
return tbl
|
|
end,
|
|
init=function()end
|
|
},{__index=_ENV})
|
|
|
|
|
|
--entity
|
|
entity=class:new({
|
|
x=1,
|
|
y=1,
|
|
w=8,
|
|
h=8
|
|
})
|
|
entities={}
|
|
|
|
--btn
|
|
b=0
|
|
|
|
--helper functions
|
|
function hitx(e)
|
|
fl=0
|
|
for x=0,e.w do
|
|
x1,y1,y2=(e.x+x)/8,e.y/8,(e.y+e.h)/8
|
|
fl=fl|fget(mget(x1,y1))|fget(mget(x1,y2))
|
|
end
|
|
return fl
|
|
end
|
|
|
|
function hity(e)
|
|
fl=0
|
|
for y=0,e.h do
|
|
x1,x2,y1=e.x/8,(e.x+e.w)/8,(e.y+y)/8
|
|
fl=fl|fget(mget(x1,y1))|fget(mget(x2,y1))
|
|
end
|
|
return fl
|
|
end
|
|
-->8
|
|
--npc
|
|
npc=entity:new({
|
|
spd=.5,
|
|
s=0,--sprite
|
|
|
|
update=function(_ENV)
|
|
|
|
end,
|
|
draw=function(_ENV)
|
|
|
|
spr(s,x,y)
|
|
end
|
|
|
|
})
|
|
|
|
player=npc:new({
|
|
x=6,
|
|
y=6,
|
|
s=0,
|
|
update=function(self)
|
|
-- hit(self)
|
|
b=global.b
|
|
xv,yv=0,0
|
|
--left,right,up,down
|
|
if ((b & 0x1)!=0) xv-=1
|
|
if ((b&0x2)!=0) xv+=1
|
|
if ((b&0x4)!=0) yv-=1
|
|
if ((b&0x8)!=0) yv+=1
|
|
if xv!=0 or yv!=0 then
|
|
-- if (hity(player:new({y=self.y+yv}))) self.y+=yv
|
|
-- if hit(player:new({
|
|
-- x=self.x+xv,
|
|
-- y=self.y+yv
|
|
-- })) then
|
|
-- printh("hit")
|
|
-- else
|
|
-- if (hitx(player:new({x=self.x+xv}))) printh("x?")
|
|
t=player:new({x=self.x+xv,y=self.y+yv})
|
|
fx=hitx(t) --flags x
|
|
fy=hity(t) --flags y
|
|
if ((fx&0x1)==0) self.x+=xv
|
|
if ((fy&0x1)==0) self.y+=yv
|
|
end
|
|
end
|
|
})
|
|
__gfx__
|
|
0000000088888888cccccccceeeeeeee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000088888888cccccccceeeeeeee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0070070088888888cccccccceeeeeeee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0007700088888888cccccccceeeeeeee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0007700088888888cccccccceeeeeeee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0070070088888888cccccccceeeeeeee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000088888888cccccccceeeeeeee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000088888888cccccccceeeeeeee000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
__gff__
|
|
0000010200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
__map__
|
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000200000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
0000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|