That was #4.
This commit is contained in:
parent
7fbc5c8597
commit
c686c29952
BIN
4/cour.ttf
Normal file
BIN
4/cour.ttf
Normal file
Binary file not shown.
103
4/levels.lua
Normal file
103
4/levels.lua
Normal file
|
@ -0,0 +1,103 @@
|
|||
|
||||
local LEVELS = {}
|
||||
local function level (new_level) table.insert(LEVELS, new_level) end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
level {
|
||||
player = {(800-40)/2, 100},
|
||||
goal = {(800-40)/2, 600-80, 40, 40},
|
||||
blocks = {
|
||||
{0, 600-40, 800, 40},
|
||||
{300, 200, 200, 40},
|
||||
{100, 300, 600, "<- / -> or A / D"},
|
||||
}
|
||||
}
|
||||
|
||||
level {
|
||||
player = {200-40, 100},
|
||||
goal = {600, 600-80, 40, 40},
|
||||
blocks = {
|
||||
}
|
||||
}
|
||||
|
||||
level {
|
||||
player = {(800-40)/2, 500-80},
|
||||
goal = {(800-40)/2, 200-80, 40, 40},
|
||||
blocks = {
|
||||
{300, 200-40, 200, 40},
|
||||
{300, 500-40, 200, 40},
|
||||
}
|
||||
}
|
||||
|
||||
level {
|
||||
player = {(800-40)/2, 500-80},
|
||||
goal = {(800-40)/2, 200-80, 40, 40},
|
||||
blocks = {
|
||||
{300, 400-40, 200, 40},
|
||||
{300, 500-40, 200, 40},
|
||||
}
|
||||
}
|
||||
|
||||
level {
|
||||
player = {(800-40)/2, 500-80},
|
||||
goal = {(800-40)/2, 200-80, 40, 40},
|
||||
blocks = {
|
||||
{300+200-40, 300-40, 40, 200},
|
||||
{300, 300-40, 40, 200},
|
||||
{300, 500-40, 200, 40},
|
||||
{300, 300-40, 200, 40},
|
||||
}
|
||||
}
|
||||
|
||||
level {
|
||||
player = {80, 400-80},
|
||||
goal = {800-40, 400-80, 40, 40},
|
||||
blocks = {
|
||||
{0, 0, 40, 600, true},
|
||||
{0, 600-40, 800, 40, true},
|
||||
{0+240*3, 400-40, 120, 40},
|
||||
{0+240*2, 400-40, 120, 40},
|
||||
{0+240*1, 400-40, 120, 40},
|
||||
{0+240*0+80, 400-40, 40, 40},
|
||||
}
|
||||
}
|
||||
|
||||
level {
|
||||
player = {40, 400-80},
|
||||
goal = {800-40, 400-80, 40, 40},
|
||||
blocks = {
|
||||
{0, 0, 40, 600, true},
|
||||
{0, 600-40, 800, 40, true},
|
||||
{0+240*0, 400-40, 120, 400},
|
||||
{0+240*3, 400-40, 120, 400},
|
||||
}
|
||||
}
|
||||
|
||||
level {
|
||||
player = {80, 600-80},
|
||||
goal = {800-120, 40, 40, 40},
|
||||
blocks = {
|
||||
{0, 0, 40, 600, true},
|
||||
{80+120*4, 600-40-120*4, 300, 600},
|
||||
{80+120*3, 600-40-120*3, 120, 600},
|
||||
{80+120*2, 600-40-120*2, 120, 600},
|
||||
{80+120*1, 600-40-120*1, 120, 600},
|
||||
{80, 600-40, 800, 40},
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
level {
|
||||
player = {(800-40)/2, 100},
|
||||
goal = {1000, 1000, 0, 0},
|
||||
blocks = {
|
||||
{300, 200, 200, 40},
|
||||
{100, 300, 600, "Thanks for playing! :D"}
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
return LEVELS
|
123
4/main.lua
Normal file
123
4/main.lua
Normal file
|
@ -0,0 +1,123 @@
|
|||
|
||||
|
||||
local FONT = love.graphics.newFont("cour.ttf", 30)
|
||||
love.graphics.setFont(FONT)
|
||||
|
||||
local LEVELS = require "levels"
|
||||
local CURRENT_LEVEL = 0
|
||||
|
||||
local LONGEST_FRAME = 0
|
||||
|
||||
local GRAVITY = 100
|
||||
|
||||
local LVL_HEIGHT = 600
|
||||
local LVL_WIDTH = 800
|
||||
|
||||
local PLAYER = {
|
||||
x = 0, y = 0,
|
||||
w = 40, h = 40,
|
||||
dx = 0, dy = 0,
|
||||
speed = 500,
|
||||
jump = 400,
|
||||
color = {140, 198, 63}
|
||||
}
|
||||
|
||||
local COLOR_WHITE = {255,255,255}
|
||||
local COLOR_RED = {241, 90, 36}
|
||||
|
||||
local GOAL = {x = 0, y = 0, w = 40, h = 40, color={41, 171, 226}}
|
||||
|
||||
local BLOCKS = {}
|
||||
|
||||
local function add_block(x,y,w,h, d)
|
||||
if type(x) == "table" then
|
||||
table.insert(BLOCKS, x)
|
||||
elseif type(h) == "string" then
|
||||
table.insert(BLOCKS,{x=x,y=y,w=w,h=-30,text=h, color = COLOR_WHITE})
|
||||
elseif d then
|
||||
table.insert(BLOCKS,{x=x,y=y,w=w,h=h, color = COLOR_RED})
|
||||
else
|
||||
table.insert(BLOCKS,{x=x,y=y,w=w,h=h, color = COLOR_WHITE})
|
||||
end
|
||||
end
|
||||
|
||||
local function load_level (lvl_obj)
|
||||
BLOCKS = {}
|
||||
|
||||
GOAL.x = lvl_obj.goal[1]
|
||||
GOAL.y = lvl_obj.goal[2]
|
||||
GOAL.w = lvl_obj.goal[3]
|
||||
GOAL.h = lvl_obj.goal[4]
|
||||
add_block(GOAL)
|
||||
|
||||
PLAYER.x = lvl_obj.player[1]
|
||||
PLAYER.y = lvl_obj.player[2]
|
||||
PLAYER.dx = lvl_obj.player[3] or 0
|
||||
PLAYER.dy = lvl_obj.player[4] or 0
|
||||
add_block(PLAYER)
|
||||
|
||||
for _, block_data in ipairs(lvl_obj.blocks) do
|
||||
add_block(block_data[1],block_data[2],block_data[3],block_data[4], block_data[5])
|
||||
end
|
||||
end
|
||||
|
||||
local function update_player_pos (player, dt)
|
||||
--if love.keyboard.isDown("w") then
|
||||
-- player.dy = player.dy - player.jump * dt
|
||||
--end
|
||||
if love.keyboard.isDown("a") or love.keyboard.isDown("left") then
|
||||
player.dx = player.dx - player.speed * dt
|
||||
end
|
||||
if love.keyboard.isDown("d") or love.keyboard.isDown("right") then
|
||||
player.dx = player.dx + player.speed * dt
|
||||
end
|
||||
player.dx = player.dx * 0.99
|
||||
player.dy = player.dy + GRAVITY * dt
|
||||
player.x = (player.x + player.dx * dt + LVL_WIDTH) % LVL_WIDTH
|
||||
player.y = (player.y + player.dy * dt + LVL_HEIGHT) % LVL_HEIGHT
|
||||
|
||||
local collided = nil
|
||||
for _, block in ipairs(BLOCKS) do
|
||||
if block ~= player and
|
||||
block.x < player.x + player.w and player.x < block.x + block.w and
|
||||
player.y < block.y + block.h and player.y + player.h > block.y then
|
||||
collided = block
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if collided == GOAL then
|
||||
CURRENT_LEVEL = CURRENT_LEVEL + 1
|
||||
load_level(LEVELS[CURRENT_LEVEL])
|
||||
elseif collided then
|
||||
if collided.color == COLOR_RED then
|
||||
load_level(LEVELS[CURRENT_LEVEL])
|
||||
player.dy = 0
|
||||
elseif not collided.text then
|
||||
player.y = collided.y - player.h
|
||||
player.dy = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function love.load ()
|
||||
love.graphics.setBackgroundColor(26,26,26)
|
||||
CURRENT_LEVEL = 1
|
||||
load_level(LEVELS[CURRENT_LEVEL])
|
||||
end
|
||||
|
||||
function love.update (dt)
|
||||
LONGEST_FRAME = math.max(LONGEST_FRAME, dt)
|
||||
update_player_pos(PLAYER, dt)
|
||||
end
|
||||
|
||||
function love.draw ()
|
||||
for _, block in ipairs(BLOCKS) do
|
||||
love.graphics.setColor(block.color)
|
||||
if block.text then
|
||||
love.graphics.printf(block.text, block.x, block.y, block.w, "center")
|
||||
else
|
||||
love.graphics.rectangle("fill", block.x, block.y, block.w, block.h)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user