nominally working hopping demo
This commit is contained in:
84
arena.lua
Normal file
84
arena.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
|
||||
|
||||
local sideHeight = 35
|
||||
local width = 55
|
||||
local topHeight = 20
|
||||
local polys = {
|
||||
{
|
||||
0, 0, width/2, topHeight/2,
|
||||
0, topHeight, -width/2, topHeight/2,
|
||||
},
|
||||
{
|
||||
0, topHeight, width/2, topHeight/2,
|
||||
width/2, topHeight/2 + sideHeight, 0, topHeight + sideHeight,
|
||||
},
|
||||
{
|
||||
0, topHeight, -width/2, topHeight/2,
|
||||
-width/2, topHeight/2 + sideHeight, 0, topHeight + sideHeight,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return function(size, discs, topCol, rightCol, leftCol)
|
||||
assert(size > 0)
|
||||
for disc in pairs(discs) do
|
||||
assert(disc >= -size and disc <= size)
|
||||
end
|
||||
|
||||
local colours = {topCol, rightCol, leftCol}
|
||||
local function drawCube(x, y)
|
||||
love.graphics.push()
|
||||
love.graphics.translate(x, y)
|
||||
for ix, poly in ipairs(polys) do
|
||||
love.graphics.setColor(colours[ix])
|
||||
love.graphics.polygon("fill", poly)
|
||||
end
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
||||
local function getHeight()
|
||||
return size*(topHeight/2 + sideHeight) + topHeight/2
|
||||
end
|
||||
|
||||
local x = love.graphics.getWidth()/2
|
||||
local y = love.graphics.getHeight()/2 - getHeight()/2;
|
||||
|
||||
local function qpos2Coords(se, sw)
|
||||
return x + se * width/2 - sw * width/2,
|
||||
y + (se + sw)*(topHeight/2+sideHeight)
|
||||
end
|
||||
|
||||
return {
|
||||
getWidth = function()
|
||||
return size*width*2
|
||||
end,
|
||||
|
||||
getHeight = getHeight,
|
||||
|
||||
getSize = function() return size; end,
|
||||
getCubeSideHeight = function() return sideHeight; end,
|
||||
getCubeTopHeight = function() return topHeight; end,
|
||||
getCubeHeight = function() return sideHeight+topHeight; end,
|
||||
getCubeWidth = function() return width; end,
|
||||
getRowHeight = function() return sideHeight+topHeight/2; end,
|
||||
getColWidth = function() return width/2; end,
|
||||
qpos2Coords = qpos2Coords,
|
||||
|
||||
draw = function()
|
||||
for se = 0, size-1 do
|
||||
for sw = 0, size-1 do
|
||||
if (se + sw < size) then
|
||||
local x, y = qpos2Coords(se, sw)
|
||||
drawCube(x, y)
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
update = function(dt)
|
||||
end,
|
||||
}
|
||||
end
|
||||
Reference in New Issue
Block a user