Code: Select all
require('Script/camara')
function love.load()
CELLSIZE=32
createMap()
text = "Estado: "
Score = "0"
FontSize = love.graphics.newFont(20)
love.graphics.setFont(FontSize)
image = love.graphics.newImage("personaje/elicopter.png")
width = love.graphics.getWidth()
height = love.graphics.getHeight()
camera:setBounds(0, 0, width *500, height)
player = {
Cells={},
x = width / 2,
y = height / 2,
width = image:getWidth(),
height = image:getHeight(),
speed = 150
}
end
function createMap()
map = {
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},
{0,0,0,1,0,0,0,0,0,0,},
{0,0,0,1,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,1,0,},
{0,0,0,0,0,0,0,1,0,0,},
{0,0,0,0,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,},
{0,0,0,0,0,0,0,0,0,0,},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},
}
end
function love.draw()
camera:set()
love.graphics.print(text,900,100)
love.graphics.setColor(0, 0, 255)
for y=1,#map do
for x=1,#map[y] do
if map[y][x] == 1 then
love.graphics.rectangle("fill", x*CELLSIZE - 32, y*CELLSIZE - 42, CELLSIZE, CELLSIZE)
else
if DEBUG then
love.graphics.rectangle("line", x*CELLSIZE - 32, y*CELLSIZE - 42, CELLSIZE, CELLSIZE)
end
end
end
end
love.graphics.setColor(255, 255, 255)
love.graphics.print(Score, player.x - width + 400, 0)
love.graphics.draw(image, player.x, player.y)
camera:unset()
end
function love.update(dt)
player.x = player.x + player.speed * dt
Score = player.x
------------------------------------------------------------------------------------------------------------
if love.keyboard.isDown("return") then
player.y = height / 2
player.x = 10
text = "Estado: reset"
end
if love.keyboard.isDown("r") then
player.y = height / 2
player.x = 10
text = "Estado: reset"
end
if love.keyboard.isDown("x") then
player.y = player.y - player.speed * dt
else
player.y = player.y + player.speed * dt
end
camera:setPosition(player.x - width / 2, player.y - height / 2)
if isOffMap(player.x, player.y) then
text = "You loset"
player.y = height / 2
player.x = 10
end
end
function math.clamp(x, min, max)
return x < min and min or (x > max and max or x)
end
-- El usuario fuera del mapa?
function isOffMap(x, y)
if x<CELLSIZE -32 or x+player.width> (1+#map[1])*CELLSIZE - 32
or y<CELLSIZE -10 or y+player.height>(1+#map)*CELLSIZE - 75
then
return true
else
return false
end
end
function CheckCollider(x, y)
-- find which tile the point is in
local tx, ty = math.floor(x*CELLSIZE / 32), math.floor(y*CELLSIZE / 42)
-- check the tile
if map[tx][ty] == 1 then
return false
else
return true
end
end
--======================================================================================================================