244 lines
6.9 KiB
Lua
244 lines
6.9 KiB
Lua
require("player")
|
|
require("platforms")
|
|
require("enemies")
|
|
require("collision")
|
|
require("menu")
|
|
require("maploader")
|
|
points=0
|
|
mp={
|
|
{0,0,0,0,0,0,0,0,0},
|
|
{0,0,0,0,0,0,"e",0,0},
|
|
{0,0,0,0,1,1,1,1,1},
|
|
{0,0,0,0,0,0,0,0,0},
|
|
{2,2,2,2,0,0,0,0,0},
|
|
{0,0,0,0,0,0,0,0,0},
|
|
{0,0,0,0,0,0,0,0,0}
|
|
}
|
|
function love.load()
|
|
lose=false
|
|
win=false
|
|
moveleft=true
|
|
moveright=true
|
|
player.x=0
|
|
player.y=0
|
|
loadmap(mp)
|
|
--[[
|
|
p:new(0, 200, 320, 30)
|
|
p:new(300, 300, 200, 30)
|
|
p:new(0, 300, 200, 30)
|
|
p:new(600, 300, 200, 30)
|
|
p:new(480, 200, 320, 30)
|
|
p:new(0, 400, 320, 30)
|
|
p:new(480, 400, 320, 30)
|
|
e:new(100, 0, 30, 30, 3)
|
|
e:new(300, 270, 30, 30, 3)
|
|
]]--
|
|
font=love.graphics.newFont("MerriweatherSans-ExtraBold.ttf", 20)
|
|
end
|
|
function love.draw()
|
|
if startmenu then
|
|
love.graphics.setColor(play.color[1], play.color[2], play.color[3])
|
|
love.graphics.rectangle("fill", play.x, play.y, play.w, play.h)
|
|
love.graphics.setColor(255-play.color[1], 255-play.color[2], 255-play.color[3])
|
|
love.graphics.translate((play.x+play.w/2)-45, (play.y+play.h/2)-13)
|
|
love.graphics.setFont(font)
|
|
love.graphics.print("Play", 0, 0, 0, 1, 1)
|
|
love.graphics.translate(-((play.x+play.w/2)-45), -((play.y+play.h/2)-13))
|
|
love.graphics.setColor(quit.color[1], quit.color[2], quit.color[3])
|
|
love.graphics.rectangle("fill", quit.x, quit.y, quit.w, quit.h)
|
|
love.graphics.setColor(255-quit.color[1], 255-quit.color[2], 255-quit.color[3])
|
|
love.graphics.translate((quit.x+quit.w/2)-45, (quit.y+quit.h/2)-13)
|
|
love.graphics.setFont(font)
|
|
love.graphics.print("Quit", 0, 0, 0, 1, 1)
|
|
else
|
|
if pausemenu then
|
|
love.graphics.setColor(play.color[1], play.color[2], play.color[3])
|
|
love.graphics.rectangle("fill", play.x, play.y, play.w, play.h)
|
|
love.graphics.setColor(255-play.color[1], 255-play.color[2], 255-play.color[3])
|
|
love.graphics.translate((play.x+play.w/2)-90, (play.y+play.h/2)-13)
|
|
love.graphics.setFont(font)
|
|
love.graphics.print("Back To Game", 0, 0, 0, 1, 1)
|
|
love.graphics.translate(-((play.x+play.w/2)-90), -((play.y+play.h/2)-13))
|
|
love.graphics.setColor(quit.color[1], quit.color[2], quit.color[3])
|
|
love.graphics.rectangle("fill", quit.x, quit.y, quit.w, quit.h)
|
|
love.graphics.setColor(255-quit.color[1], 255-quit.color[2], 255-quit.color[3])
|
|
love.graphics.translate((quit.x+quit.w/2)-90, (quit.y+quit.h/2)-13)
|
|
love.graphics.setFont(font)
|
|
love.graphics.print("Quit To Menu", 0, 0, 0, 1, 1)
|
|
love.graphics.translate(-((quit.x+quit.w/2)-90), -((quit.y+quit.h/2)-13))
|
|
end
|
|
if win then
|
|
startmenu=true
|
|
win=false
|
|
e:clear()
|
|
t:clear()
|
|
love.load()
|
|
elseif lose then
|
|
startmenu=true
|
|
lose=false
|
|
e:clear()
|
|
t:clear()
|
|
love.load()
|
|
else
|
|
love.graphics.setColor(239, 121, 89)
|
|
love.graphics.setFont(font)
|
|
love.graphics.print("Points: "..points, 0, 0, 0, 1, 1)
|
|
love.graphics.setColor(255, 255, 255)
|
|
love.graphics.draw(player.img, player.x, player.y)
|
|
love.graphics.setColor(182,182,109)
|
|
for _,b in pairs(player.bullets) do
|
|
love.graphics.rectangle("fill", b.x, b.y, b.w, b.h)
|
|
end
|
|
love.graphics.setColor(109, 182, 182)
|
|
for _,ti in pairs(t.tiles) do
|
|
love.graphics.draw(ti.type, ti.x, ti.y)
|
|
end
|
|
for _,e in pairs(e.enemies) do
|
|
love.graphics.setColor(182-109, 182*2-109, 109)
|
|
love.graphics.rectangle("fill", e.x, e.y, e.w, e.h)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
function love.keyreleased(key)
|
|
if key=='escape' and not startmenu then
|
|
if pausemenu then
|
|
pausemenu=false
|
|
else
|
|
pausemenu=true
|
|
end
|
|
end
|
|
end
|
|
function love.update(dt)
|
|
if love.mouse.isDown(1) then
|
|
if startmenu and quit.cooldown==0 then
|
|
if play.mouse() then
|
|
startmenu=false
|
|
end
|
|
if quit.mouse() then
|
|
love.event.quit()
|
|
end
|
|
elseif pausemenu then
|
|
if play.mouse() then
|
|
pausemenu=false
|
|
end
|
|
if quit.mouse() then
|
|
pausemenu=false
|
|
startmenu=true
|
|
quit.cooldown=20
|
|
e:clear()
|
|
p:clear()
|
|
love.load()
|
|
end
|
|
else
|
|
if player.cooldown==0 then
|
|
player:fire()
|
|
end
|
|
end
|
|
end
|
|
if not startmenu and not pausemenu then
|
|
if love.keyboard.isDown('d') and moveright then
|
|
player.x=player.x+player.speed
|
|
end
|
|
if love.keyboard.isDown('a') and moveleft then
|
|
player.x=player.x-player.speed
|
|
end
|
|
if love.keyboard.isDown('lshift') then
|
|
player.speed=4
|
|
else
|
|
player.speed=3
|
|
end
|
|
if player.jump then
|
|
if player.jumped==0 then
|
|
player.dy=-16
|
|
player.ddy=1
|
|
end
|
|
if player.dy==0 or player.onground then
|
|
player.jumped=0
|
|
player.jump=false
|
|
else
|
|
player.jumped=1
|
|
end
|
|
player.dy=player.dy+player.ddy
|
|
player.y=player.y+player.dy
|
|
end
|
|
for _,ti in pairs(t.tiles) do
|
|
if player.x+player.w>=ti.x and player.x<=ti.x+32 and player.y+player.h>=ti.y and player.y+player.h<=ti.y+32 then
|
|
player.onground=true
|
|
player.y=ti.y-player.h
|
|
end
|
|
end
|
|
if player.jump==false and player.onground==false then
|
|
player.dy=player.dy+1
|
|
player.y=player.y+player.dy
|
|
end
|
|
if love.keyboard.isDown('space') and player.onground then
|
|
player.jump=true
|
|
end
|
|
for q,bl in pairs(player.bullets) do
|
|
if bl.dirx>bl.diry then
|
|
bl.x=bl.x+20
|
|
bl.y=bl.y+(bl.diry/bl.dirx)*20
|
|
else
|
|
bl.y=bl.y+20
|
|
bl.x=bl.x+(bl.dirx/bl.diry)*20
|
|
end
|
|
for _,ti in pairs(t.tiles) do
|
|
if collision(bl, ti) then
|
|
table.remove(player.bullets, q)
|
|
end
|
|
end
|
|
for q1,en in pairs(e.enemies) do
|
|
if collision(en, bl) then
|
|
table.remove(player.bullets, q)
|
|
en.lifes=en.lifes-1
|
|
if en.lifes==0 then
|
|
table.remove(e.enemies, q1)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
for _,en in pairs(e.enemies) do
|
|
if collision(en, player) and not lose and not win then
|
|
lose=true
|
|
end
|
|
en.x=en.x+2*en.dir
|
|
for _,ti in pairs(t.tiles) do
|
|
if en.y+en.h>=ti.y and en.y+en.h<=ti.y+ti.h then
|
|
if ti.x>=en.x then
|
|
en.dir=1
|
|
elseif ti.x+ti.w<=en.x+en.w then
|
|
en.dir=-1
|
|
end
|
|
en.onground=true
|
|
end
|
|
end
|
|
if not en.onground then
|
|
en.dy=en.dy+1
|
|
en.y=en.y+en.dy
|
|
end
|
|
en.onground=false
|
|
end
|
|
if player.cooldown~=0 then
|
|
player.cooldown=player.cooldown-1
|
|
end
|
|
if #e.enemies==0 and not lose and not win then
|
|
win=true
|
|
end
|
|
player.onground=false
|
|
if player.x==0 then
|
|
moveleft=false
|
|
else
|
|
moveleft=true
|
|
end
|
|
if player.x==love.graphics.getWidth()-player.w then
|
|
moveright=false
|
|
else
|
|
moveright=true
|
|
end
|
|
else
|
|
if quit.cooldown~=0 then
|
|
quit.cooldown=quit.cooldown-1
|
|
end
|
|
end
|
|
end |