add platformer
This commit is contained in:
parent
b9ab91e8a8
commit
045f985cd2
137
right_coin.lua
137
right_coin.lua
|
@ -16,6 +16,105 @@ coinBlue=0
|
||||||
coinRed=0
|
coinRed=0
|
||||||
coinYellow=0
|
coinYellow=0
|
||||||
|
|
||||||
|
solids={}
|
||||||
|
do
|
||||||
|
local sols={1, 2, 3, 17}
|
||||||
|
for i,v in pairs(sols) do
|
||||||
|
solids[v]=true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function sol(x,y) return solids[mget(x//8,y//8)] end
|
||||||
|
g = .3
|
||||||
|
j = -4
|
||||||
|
|
||||||
|
anis={
|
||||||
|
idle={257},
|
||||||
|
run={273,274},
|
||||||
|
jump={289},
|
||||||
|
fall={290}
|
||||||
|
}
|
||||||
|
|
||||||
|
do -- Player
|
||||||
|
Player = {
|
||||||
|
spr=0,
|
||||||
|
ani=anis.idle,
|
||||||
|
x=8,y=120,
|
||||||
|
w=8,h=8,
|
||||||
|
vx=0,vy=0,
|
||||||
|
isFlipped=false
|
||||||
|
}
|
||||||
|
|
||||||
|
function Player:direct()
|
||||||
|
if btn(2) then
|
||||||
|
self.vx = -2
|
||||||
|
self.isFlipped = true
|
||||||
|
elseif btn(3) then
|
||||||
|
self.vx = 2
|
||||||
|
self.isFlipped = false
|
||||||
|
else self.vx = 0
|
||||||
|
end
|
||||||
|
if btnp(0) and self.vy == 0 then self.vy = j end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:update()
|
||||||
|
self:resolve()
|
||||||
|
self.x = self.x + self.vx
|
||||||
|
self.y = self.y + self.vy
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:resolve()
|
||||||
|
if sol(self.x + self.vx, self.y + self.h-1) or sol(self.x + self.vx + self.w-1, self.y + self.h-1) then
|
||||||
|
self.vx = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local roof = self:distanceToRoof()
|
||||||
|
local floor = self:distanceToFloor()
|
||||||
|
if self.vy < roof then
|
||||||
|
self.vy = roof
|
||||||
|
end
|
||||||
|
if self.vy >= floor then self.vy = floor
|
||||||
|
else self.vy = self.vy + g
|
||||||
|
end
|
||||||
|
if self.vy < 0 then
|
||||||
|
self.ani = anis.jump
|
||||||
|
elseif self.vy > 0 then
|
||||||
|
self.ani = anis.fall
|
||||||
|
elseif not (self.vx == 0) then
|
||||||
|
self.ani = anis.run
|
||||||
|
else
|
||||||
|
self.ani = anis.idle
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:distanceToFloor()
|
||||||
|
local y = 0
|
||||||
|
while (not sol(self.x + self.vx, self.y + y + self.h))
|
||||||
|
and (not sol(self.x + self.vx + self.w-1, self.y + y + self.h))
|
||||||
|
and (self.y + y < 128) do
|
||||||
|
y = y + 1
|
||||||
|
end
|
||||||
|
return y
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:distanceToRoof()
|
||||||
|
local y = 0
|
||||||
|
while (not sol(self.x + self.vx, self.y + y - 1))
|
||||||
|
and (not sol(self.x + self.vx + self.w-1, self.y + y - 1))
|
||||||
|
and (self.y + y > 0) do
|
||||||
|
y = y - 1
|
||||||
|
end
|
||||||
|
return y
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:draw()
|
||||||
|
self.spr=self.ani[(((t)//3)% #self.ani)+1]
|
||||||
|
local flip
|
||||||
|
if self.isFlipped then flip = 1 else flip = 0 end
|
||||||
|
spr(self.spr, self.x, self.y, 1, 1, flip)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function drawStart()
|
function drawStart()
|
||||||
cls(13)
|
cls(13)
|
||||||
print("The Right Coin",80,36)
|
print("The Right Coin",80,36)
|
||||||
|
@ -29,8 +128,10 @@ function drawGameOver()
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawGame()
|
function drawGame()
|
||||||
cls(0)
|
map(0,0,30,17)
|
||||||
spr(84,64,0)
|
p:direct()
|
||||||
|
p:update()
|
||||||
|
p:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawMarket()
|
function drawMarket()
|
||||||
|
@ -97,6 +198,7 @@ function update(state)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
p=Player
|
||||||
function TIC()
|
function TIC()
|
||||||
update(currentState)
|
update(currentState)
|
||||||
draw(currentState)
|
draw(currentState)
|
||||||
|
@ -104,6 +206,10 @@ function TIC()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- <TILES>
|
-- <TILES>
|
||||||
|
-- 001:0bbbbbbbbb5b55b5b54544545444444444444444444444c44c44444444444444
|
||||||
|
-- 002:bbbbbbbb5b55b55b454454454444444444444444444444c44c44444444444444
|
||||||
|
-- 003:bbbbbbb0b55b555b544544554444444544444444444444c44c44444444444444
|
||||||
|
-- 017:444444444444c4444c444444444444c444444444444444c444c4444444444444
|
||||||
-- 064:03aaaa3703aaaa3703aa3a3703aaaa3703aaaa3703aaaa3703a3aa3703aaaa37
|
-- 064:03aaaa3703aaaa3703aa3a3703aaaa3703aaaa3703aaaa3703a3aa3703aaaa37
|
||||||
-- 065:03aaaa3703aa3a3303aaaaaa03aaaaaa03aaaa3a033aaaaa0033333300000000
|
-- 065:03aaaa3703aa3a3303aaaaaa03aaaaaa03aaaa3a033aaaaa0033333300000000
|
||||||
-- 066:7777777777777777777777777777777777777777777777777777777777777777
|
-- 066:7777777777777777777777777777777777777777777777777777777777777777
|
||||||
|
@ -114,6 +220,33 @@ end
|
||||||
-- 084:000008880000880000880000008eeeee08ee00008ee666608666006680000000
|
-- 084:000008880000880000880000008eeeee08ee00008ee666608666006680000000
|
||||||
-- </TILES>
|
-- </TILES>
|
||||||
|
|
||||||
|
-- <SPRITES>
|
||||||
|
-- 001:00044000000cc000000cc000006666000606606000c88c000008080000080800
|
||||||
|
-- 017:00044000000cc000000cc0000006600000066c00000888000088080000000800
|
||||||
|
-- 018:00044000000cc000000cc000006666c000c66000000888800008008000880000
|
||||||
|
-- 033:00044000000cc0c0000cc060006666600066c600000888800888008000000080
|
||||||
|
-- 034:000440000c0cc0c0060cc0600666666000066600000888000080008008000008
|
||||||
|
-- </SPRITES>
|
||||||
|
|
||||||
|
-- <MAP>
|
||||||
|
-- 001:111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 002:110000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 003:110000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 004:110000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 005:110000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 006:110000000000000000000000000000000000000000000000000010202011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 007:110000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 008:110000000000000000000000000000000000000000001020300000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 009:110000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 010:110000000000000000000000000000000000001030000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 011:110000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 012:110000000000000000000000102020203000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 013:110000000000000000000000111111111100000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 014:110000001020202020300000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 015:110000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- 016:112020202020202020202020202020202020202020202020202020202011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
-- </MAP>
|
||||||
|
|
||||||
-- <WAVES>
|
-- <WAVES>
|
||||||
-- 000:00000000ffffffff00000000ffffffff
|
-- 000:00000000ffffffff00000000ffffffff
|
||||||
-- 001:0123456789abcdeffedcba9876543210
|
-- 001:0123456789abcdeffedcba9876543210
|
||||||
|
|
Loading…
Reference in a new issue