-- main函数
displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)
function setup()
blocks = {}
table.insert(blocks, Block(300,500))
newBlock = Block(400,700)
table.insert(blocks, newBlock)
trans = vec2(0,0)
ftrans = vec2(0,0)
chess = Chess(300,500)
m1 = mesh()
m1.vertices = {vec2(0,0),vec2(0,HEIGHT),vec2(WIDTH,0)}
c1 = {color(145, 183, 191, 255),color(100, 170, 198, 255),color(255, 255, 255, 255)}
m1.colors = c1
m2 = mesh()
m2.vertices = {vec2(WIDTH,0),vec2(WIDTH,HEIGHT),vec2(0,HEIGHT)}
c2 = {color(255, 255, 255, 255),color(145, 183, 191, 255),color(100, 170, 198, 255)}
m2.colors = c2
score = 0
end
function clone()
score = score + 10
local front = vec2(blocks[#blocks].x,blocks[#blocks].y)
trans = vec2(math.random(-200,300),math.random(200,250))
ftrans = ftrans + trans
newBlock = Block(front.x,front.y,trans)
newBlock.isInDrop = true
table.insert(blocks, newBlock)
newBlock:drop()
end
function jump()
local next = vec2(blocks[#blocks].x,blocks[#blocks].y)
local front = vec2(blocks[#blocks-1].x,blocks[#blocks-1].y)
chess.x = next.x
chess.y = next.y
chess.fx = front.x
chess.fy = front.y
chess:jump()
end
function draw()
background(232, 229, 232, 255)
strokeWidth(5)
m1:draw()
m2:draw()
pushStyle()
textMode(CENTER)
fontSize(50)
font("AmericanTypewriter-Bold")
fill(227, 96, 96, 255)
local w = textSize(score)
text(score,30+w/2,HEIGHT-30)
popStyle()
-- 整个画面平移
translate(-ftrans.x,-ftrans.y)
for k,v in pairs(blocks) do
v:draw()
end
chess:draw()
end
function touched(touch)
local currentBlock = blocks[#blocks-1]
if not chess.isInJump then
currentBlock.height = currentBlock.height - 1
chess.y = chess.y - 0.5
end
if touch.state == ENDED and not chess.isInJump and not newBlock.isInDrop then
currentBlock.height = 200
jump()
end
end