Lighting system
This commit is contained in:
parent
531555a1d0
commit
f926723194
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 38e8c5a4db22269d5d63d39c733b3802452b4c0b
|
|
@ -11,6 +11,7 @@ require "data/scripts/collision"
|
||||||
require "data/scripts/level"
|
require "data/scripts/level"
|
||||||
-- data
|
-- data
|
||||||
require "data/scripts/camera"
|
require "data/scripts/camera"
|
||||||
|
require "data/scripts/lights"
|
||||||
require "data/scripts/objects"
|
require "data/scripts/objects"
|
||||||
-- UI functions
|
-- UI functions
|
||||||
require "data/scripts/debug"
|
require "data/scripts/debug"
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
function DebugUI()
|
function DebugUI()
|
||||||
|
|
||||||
|
for _, light in pairs(Lights) do
|
||||||
|
love.graphics.print(light.pos.x,light.pos.x,light.pos.y)
|
||||||
|
love.graphics.print(light.pos.y,light.pos.x,light.pos.y+20)
|
||||||
|
love.graphics.print(light.pos.x,light.pos.x,light.pos.y+40)
|
||||||
|
end
|
||||||
|
|
||||||
love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..math.floor(current_dt* 1000).."ms", 10*textScale, 0*textScale, 0, textScale)
|
love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..math.floor(current_dt* 1000).."ms", 10*textScale, 0*textScale, 0, textScale)
|
||||||
|
|
||||||
love.graphics.setColor(1,1,1)
|
love.graphics.setColor(1,1,1)
|
||||||
|
|
|
@ -15,7 +15,7 @@ Arrow = Entity:New(x,y)
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
table.insert(LoadedEntities,o)
|
table.insert(LoadedEntities,o)
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,11 @@ Kupo = Entity:New(x,y)
|
||||||
o.bow_speed = 1/10
|
o.bow_speed = 1/10
|
||||||
o.bow_frames = 6
|
o.bow_frames = 6
|
||||||
o.bow_extraframes = 18
|
o.bow_extraframes = 18
|
||||||
o.bow_aim_frames = 8
|
o.bow_aim_frames = 8
|
||||||
|
|
||||||
|
o.lightRange = o.range
|
||||||
|
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
||||||
|
|
|
@ -1,203 +1,214 @@
|
||||||
Player = Entity:New(x,y)
|
Player = Entity:New(x,y)
|
||||||
|
|
||||||
|
|
||||||
function Player:New(x,y)
|
function Player:New(x,y)
|
||||||
local o = Entity:New(x,y)
|
local o = Entity:New(x,y)
|
||||||
Player.health = 3
|
Player.health = 3
|
||||||
Player.coins = 0
|
Player.coins = 0
|
||||||
|
|
||||||
-- physics
|
-- physics
|
||||||
o.vel = {
|
o.vel = {
|
||||||
x = 0,
|
x = 0,
|
||||||
y = 0
|
y = 0
|
||||||
}
|
}
|
||||||
-- constants
|
|
||||||
o.acc = 45
|
-- constants
|
||||||
o.friction = 20
|
o.acc = 45
|
||||||
o.gravity = 9.81
|
o.friction = 20
|
||||||
o.climbHeight = 4
|
o.gravity = 9.81
|
||||||
o.jumpForce = 5
|
o.climbHeight = 4
|
||||||
o.maxSpeed = 600
|
o.jumpForce = 5
|
||||||
o.jumpMaxSpeed = 9.5
|
o.maxSpeed = 600
|
||||||
o.zeroSpeed = 0.001
|
o.jumpMaxSpeed = 9.5
|
||||||
-- bools
|
o.zeroSpeed = 0.001
|
||||||
o.isJumping = false
|
o.lightRange = 20
|
||||||
o.isOnGround = 0
|
|
||||||
o.coyoteValue = 5
|
-- status
|
||||||
o.isOnLadder = false
|
o.isJumping = false
|
||||||
o.canJump = true
|
o.isOnGround = 0
|
||||||
o.canFall = true
|
o.coyoteValue = 5
|
||||||
o.canFriction = true
|
o.isOnLadder = false
|
||||||
|
o.canJump = true
|
||||||
-- sprite
|
o.canFall = true
|
||||||
o.sprite_offset = {x = 8, y = 16}
|
o.canFriction = true
|
||||||
o.target_offset = {x = 4, y = 12}
|
|
||||||
setmetatable(o, self)
|
-- sprite
|
||||||
self.__index = self
|
o.sprite_offset = {x = 8, y = 16}
|
||||||
|
o.target_offset = {x = 0, y = 12}
|
||||||
return o
|
|
||||||
end
|
-- lights
|
||||||
|
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||||
function Player:Smart()
|
|
||||||
-- PLATFORMER INPUT
|
|
||||||
if self.isOnGround > 0 then
|
setmetatable(o, self)
|
||||||
-- apply friction
|
self.__index = self
|
||||||
|
|
||||||
-- horizontal input (slide~~)
|
return o
|
||||||
if love.keyboard.isDown('a',"left") then
|
end
|
||||||
self.vel.x = self.vel.x - self.acc*current_dt
|
|
||||||
end
|
function Player:Smart()
|
||||||
if love.keyboard.isDown('d',"right") then
|
-- PLATFORMER INPUT
|
||||||
self.vel.x = self.vel.x + self.acc*current_dt
|
if self.isOnGround > 0 then
|
||||||
end
|
-- apply friction
|
||||||
if self.canJump then
|
|
||||||
-- vertical input (jump!)
|
-- horizontal input (slide~~)
|
||||||
if love.keyboard.isDown("up", "w") and self.isJumping ~= true then
|
if love.keyboard.isDown('a',"left") then
|
||||||
self.vel.y = self.vel.y - self.jumpForce
|
self.vel.x = self.vel.x - self.acc*current_dt
|
||||||
self.isOnGround = 0
|
end
|
||||||
self.isJumping = true
|
if love.keyboard.isDown('d',"right") then
|
||||||
end
|
self.vel.x = self.vel.x + self.acc*current_dt
|
||||||
end
|
end
|
||||||
end
|
if self.canJump then
|
||||||
|
-- vertical input (jump!)
|
||||||
-- fall if down input on platforms
|
if love.keyboard.isDown("up", "w") and self.isJumping ~= true then
|
||||||
if not isThereCollisionAt(
|
self.vel.y = self.vel.y - self.jumpForce
|
||||||
self.pos.x,
|
self.isOnGround = 0
|
||||||
self.pos.y + self.vel.y
|
self.isJumping = true
|
||||||
) and not isThereLadderAt(
|
end
|
||||||
self.pos.x,
|
end
|
||||||
self.pos.y + self.vel.y
|
end
|
||||||
) and isTherePlatformAt(
|
|
||||||
self.pos.x,
|
-- fall if down input on platforms
|
||||||
self.pos.y + self.vel.y
|
if not isThereCollisionAt(
|
||||||
) and love.keyboard.isDown("down", "s")
|
self.pos.x,
|
||||||
then
|
self.pos.y + self.vel.y
|
||||||
self.pos.y = self.pos.y + tileProperties.height/3
|
) and not isThereLadderAt(
|
||||||
self.isOnGround = 0
|
self.pos.x,
|
||||||
end
|
self.pos.y + self.vel.y
|
||||||
end
|
) and isTherePlatformAt(
|
||||||
|
self.pos.x,
|
||||||
function Player:HandleAnimation()
|
self.pos.y + self.vel.y
|
||||||
|
) and love.keyboard.isDown("down", "s")
|
||||||
-- flip sprite to look in the direction is moving
|
then
|
||||||
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
|
self.pos.y = self.pos.y + tileProperties.height/3
|
||||||
|
self.isOnGround = 0
|
||||||
-- animation manager
|
end
|
||||||
if self.isOnLadder then
|
end
|
||||||
self:LoadAnimation(animation.nancy.jump)
|
|
||||||
elseif self.isOnGround == 0 and self.isJumping and self.vel.y > 1.25 then
|
function Player:HandleAnimation()
|
||||||
self:LoadAnimation(animation.nancy.fall)
|
-- move light to position, :D
|
||||||
elseif self.isOnGround == 0 and self.vel.y < 0 then
|
self.light.pos.x = self.pos.x - self.target_offset.x
|
||||||
self:LoadAnimation(animation.nancy.jump)
|
self.light.pos.y = self.pos.y - self.target_offset.y
|
||||||
elseif self.vel.x ~= 0 then
|
|
||||||
self:LoadAnimation(animation.nancy.run)
|
-- flip sprite to look in the direction is moving
|
||||||
else
|
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
|
||||||
self:LoadAnimation(animation.nancy.idle)
|
|
||||||
end
|
-- animation manager
|
||||||
|
if self.isOnLadder then
|
||||||
-- special case: idle animation gets slower by time
|
self:LoadAnimation(animation.nancy.jump)
|
||||||
if self.anim_path == animation.nancy.idle.path then
|
elseif self.isOnGround == 0 and self.isJumping and self.vel.y > 1.25 then
|
||||||
if self.anim_speed < 0.5 then self.anim_speed = self.anim_speed + 0.001 end
|
self:LoadAnimation(animation.nancy.fall)
|
||||||
end
|
elseif self.isOnGround == 0 and self.vel.y < 0 then
|
||||||
end
|
self:LoadAnimation(animation.nancy.jump)
|
||||||
|
elseif self.vel.x ~= 0 then
|
||||||
function Player:DoPhysics()
|
self:LoadAnimation(animation.nancy.run)
|
||||||
-- reset physics resolution
|
else
|
||||||
self.canFall = true
|
self:LoadAnimation(animation.nancy.idle)
|
||||||
self.canJump = true
|
end
|
||||||
self.canFriction = true
|
|
||||||
-- reset flags
|
-- special case: idle animation gets slower by time
|
||||||
self.isOnLadder = false
|
if self.anim_path == animation.nancy.idle.path then
|
||||||
-- truncate to max & min values
|
if self.anim_speed < 0.5 then self.anim_speed = self.anim_speed + 0.001 end
|
||||||
if math.abs(self.vel.x) > self.maxSpeed then
|
end
|
||||||
self.vel.x = self.maxSpeed * math.sign(self.vel.x)
|
end
|
||||||
end
|
|
||||||
if math.abs(self.vel.y) > self.maxSpeed then
|
function Player:DoPhysics()
|
||||||
self.vel.y = self.maxSpeed * math.sign(self.vel.y)
|
-- reset physics resolution
|
||||||
end
|
self.canFall = true
|
||||||
if math.abs(self.vel.x) < self.zeroSpeed then
|
self.canJump = true
|
||||||
self.vel.x = 0
|
self.canFriction = true
|
||||||
end
|
-- reset flags
|
||||||
if math.abs(self.vel.y) < self.zeroSpeed then
|
self.isOnLadder = false
|
||||||
self.vel.y = 0
|
-- truncate to max & min values
|
||||||
end
|
if math.abs(self.vel.x) > self.maxSpeed then
|
||||||
|
self.vel.x = self.maxSpeed * math.sign(self.vel.x)
|
||||||
-- if on air, say so!
|
end
|
||||||
if self.vel.y > 5 then
|
if math.abs(self.vel.y) > self.maxSpeed then
|
||||||
self.isJumping = true
|
self.vel.y = self.maxSpeed * math.sign(self.vel.y)
|
||||||
end
|
end
|
||||||
|
if math.abs(self.vel.x) < self.zeroSpeed then
|
||||||
-- if its on ground, then say so.
|
self.vel.x = 0
|
||||||
if self.vel.y > 0 then
|
end
|
||||||
if isThereAnyCollisionAt(
|
if math.abs(self.vel.y) < self.zeroSpeed then
|
||||||
self.pos.x,
|
self.vel.y = 0
|
||||||
self.pos.y + self.vel.y
|
end
|
||||||
) then
|
|
||||||
self.isOnGround = self.coyoteValue
|
-- if on air, say so!
|
||||||
self.isJumping = false
|
if self.vel.y > 5 then
|
||||||
end
|
self.isJumping = true
|
||||||
end
|
end
|
||||||
-- horizontal collisions
|
|
||||||
if isThereAnyCollisionAt(self.pos.x + self.vel.x, self.pos.y) then
|
-- if its on ground, then say so.
|
||||||
-- checks for ladders
|
if self.vel.y > 0 then
|
||||||
if isThereLadderAt(self.pos.x + self.vel.x, self.pos.y)
|
if isThereAnyCollisionAt(
|
||||||
and self.vel.x ~= 0
|
self.pos.x,
|
||||||
and not isThereLadderAt(self.pos.x, self.pos.y)
|
self.pos.y + self.vel.y
|
||||||
then
|
) then
|
||||||
self.vel.y = 0
|
self.isOnGround = self.coyoteValue
|
||||||
self.vel.x = 0
|
self.isJumping = false
|
||||||
|
end
|
||||||
self.pos.y = self.pos.y - 4 * current_dt
|
end
|
||||||
|
-- horizontal collisions
|
||||||
self.canFall = false
|
if isThereAnyCollisionAt(self.pos.x + self.vel.x, self.pos.y) then
|
||||||
self.canJump = false
|
-- checks for ladders
|
||||||
self.canFriction = false
|
if isThereLadderAt(self.pos.x + self.vel.x, self.pos.y)
|
||||||
|
and self.vel.x ~= 0
|
||||||
self.isOnLadder = true
|
and not isThereLadderAt(self.pos.x, self.pos.y)
|
||||||
self.isOnGround = self.coyoteValue
|
then
|
||||||
end
|
self.vel.y = 0
|
||||||
|
self.vel.x = 0
|
||||||
-- checks for slopes
|
|
||||||
for i = 1, self.climbHeight do
|
self.pos.y = self.pos.y - 4 * current_dt
|
||||||
if not isThereCollisionAt(self.pos.x + self.vel.x, self.pos.y - i)
|
|
||||||
and self.isOnGround > 0 then
|
self.canFall = false
|
||||||
|
self.canJump = false
|
||||||
self.pos.x = self.pos.x + self.vel.x * 4/5
|
self.canFriction = false
|
||||||
self.pos.y = self.pos.y - i
|
|
||||||
|
self.isOnLadder = true
|
||||||
self.canFriction = false
|
self.isOnGround = self.coyoteValue
|
||||||
break
|
end
|
||||||
end
|
|
||||||
end
|
-- checks for slopes
|
||||||
|
for i = 1, self.climbHeight do
|
||||||
-- hey, you arent permanently stopped while collisioning, just lose a bit of force!
|
if not isThereCollisionAt(self.pos.x + self.vel.x, self.pos.y - i)
|
||||||
if self.canFriction then
|
and self.isOnGround > 0 then
|
||||||
self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction/15, 1))
|
|
||||||
end
|
self.pos.x = self.pos.x + self.vel.x * 4/5
|
||||||
else
|
self.pos.y = self.pos.y - i
|
||||||
self.pos.x = self.pos.x + self.vel.x
|
|
||||||
end
|
self.canFriction = false
|
||||||
|
break
|
||||||
-- vertical collision
|
end
|
||||||
if self.vel.y > 0
|
end
|
||||||
and isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then
|
|
||||||
self.isOnGround = self.coyoteValue
|
-- hey, you arent permanently stopped while collisioning, just lose a bit of force!
|
||||||
self.isJumping = false
|
if self.canFriction then
|
||||||
self.vel.y = 0
|
self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction/15, 1))
|
||||||
else
|
end
|
||||||
self.pos.y = self.pos.y + self.vel.y
|
else
|
||||||
self.isOnGround = math.max(self.isOnGround - 1, 0)
|
self.pos.x = self.pos.x + self.vel.x
|
||||||
end
|
end
|
||||||
|
|
||||||
-- drop.
|
-- vertical collision
|
||||||
if self.canFall then
|
if self.vel.y > 0
|
||||||
self.vel.y = self.vel.y + 2*self.gravity * current_dt
|
and isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then
|
||||||
end
|
self.isOnGround = self.coyoteValue
|
||||||
|
self.isJumping = false
|
||||||
-- friction hard in ground, soft in air
|
self.vel.y = 0
|
||||||
if self.isOnGround > 0 then
|
else
|
||||||
self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction, 1))
|
self.pos.y = self.pos.y + self.vel.y
|
||||||
else
|
self.isOnGround = math.max(self.isOnGround - 1, 0)
|
||||||
self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction/20, 1))
|
end
|
||||||
end
|
|
||||||
end
|
-- drop.
|
||||||
|
if self.canFall then
|
||||||
|
self.vel.y = self.vel.y + 2*self.gravity * current_dt
|
||||||
|
end
|
||||||
|
|
||||||
|
-- friction hard in ground, soft in air
|
||||||
|
if self.isOnGround > 0 then
|
||||||
|
self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction, 1))
|
||||||
|
else
|
||||||
|
self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction/20, 1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,153 +1,153 @@
|
||||||
Entity = {
|
Entity = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Entity:New(x,y)
|
function Entity:New(x,y)
|
||||||
o = {}
|
o = {}
|
||||||
o.pos = {x = x, y = y}
|
o.pos = {x = x, y = y}
|
||||||
o.vel = {x = 0, y = 0}
|
o.vel = {x = 0, y = 0}
|
||||||
o.class = "Entity"
|
o.class = "Entity"
|
||||||
o.anim = {}
|
o.anim = {}
|
||||||
o.anim.subframe = 0
|
o.anim.subframe = 0
|
||||||
o.anim.frame = 1
|
o.anim.frame = 1
|
||||||
o.anim.imgs = {}
|
o.anim.imgs = {}
|
||||||
o.animations = {}
|
o.animations = {}
|
||||||
o.sprite_offset = {x = 0, y = 0}
|
o.sprite_offset = {x = 0, y = 0}
|
||||||
o.sprite_scale = {x = 1, y = 1}
|
o.sprite_scale = {x = 1, y = 1}
|
||||||
o.sprite_rotation = math.rad(0)
|
o.sprite_rotation = math.rad(0)
|
||||||
o.sprite_flip = { x = 1, y = 1}
|
o.sprite_flip = { x = 1, y = 1}
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:Move(target, speed) -- target = {tx int, ty int} / speed = int
|
function Entity:Move(target, speed) -- target = {tx int, ty int} / speed = int
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:Draw()
|
function Entity:Draw()
|
||||||
if self.sprite ~= nil then
|
if self.sprite ~= nil then
|
||||||
local relative_position_x = self.pos.x - Camera.pos.x
|
local relative_position_x = self.pos.x - Camera.pos.x
|
||||||
local relative_position_y = self.pos.y - Camera.pos.y
|
local relative_position_y = self.pos.y - Camera.pos.y
|
||||||
local origin_compensation_x = - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation))
|
local origin_compensation_x = - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation))
|
||||||
local origin_compensation_y = - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation))
|
local origin_compensation_y = - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation))
|
||||||
local dimensions_x = self.sprite_scale.x * self.sprite_flip.x
|
local dimensions_x = self.sprite_scale.x * self.sprite_flip.x
|
||||||
local dimensions_y = self.sprite_scale.y * self.sprite_flip.y
|
local dimensions_y = self.sprite_scale.y * self.sprite_flip.y
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
self.sprite,
|
self.sprite,
|
||||||
relative_position_x + origin_compensation_x * dimensions_x,
|
relative_position_x + origin_compensation_x * dimensions_x,
|
||||||
relative_position_y + origin_compensation_y * dimensions_y,
|
relative_position_y + origin_compensation_y * dimensions_y,
|
||||||
self.sprite_rotation,
|
self.sprite_rotation,
|
||||||
self.sprite_scale.x * self.sprite_flip.x,
|
self.sprite_scale.x * self.sprite_flip.x,
|
||||||
self.sprite_scale.y * self.sprite_flip.y
|
self.sprite_scale.y * self.sprite_flip.y
|
||||||
)
|
)
|
||||||
if debug_collision then
|
if debug_collision then
|
||||||
love.graphics.setColor(1, 0, 0)
|
love.graphics.setColor(1, 0, 0)
|
||||||
love.graphics.circle( "line", relative_position_x, relative_position_y, 2 )
|
love.graphics.circle( "line", relative_position_x, relative_position_y, 2 )
|
||||||
love.graphics.setColor(0, 1 ,0)
|
love.graphics.setColor(0, 1 ,0)
|
||||||
love.graphics.circle( "line",
|
love.graphics.circle( "line",
|
||||||
relative_position_x + origin_compensation_x * dimensions_x,
|
relative_position_x + origin_compensation_x * dimensions_x,
|
||||||
relative_position_y + origin_compensation_y * dimensions_y,
|
relative_position_y + origin_compensation_y * dimensions_y,
|
||||||
2
|
2
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
love.graphics.setColor(1, 1 ,1)
|
love.graphics.setColor(1, 1 ,1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:NewAnimation(anim,frames,speed)
|
function Entity:NewAnimation(anim,frames,speed)
|
||||||
local anim_data = {
|
local anim_data = {
|
||||||
frame = 1,
|
frame = 1,
|
||||||
subframe = 1,
|
subframe = 1,
|
||||||
path = anim.path,
|
path = anim.path,
|
||||||
frames = anim.frames,
|
frames = anim.frames,
|
||||||
speed = anim.speed,
|
speed = anim.speed,
|
||||||
imgs = anim.imgs
|
imgs = anim.imgs
|
||||||
}
|
}
|
||||||
self.animations[#self.animations+1] = anim_data
|
self.animations[#self.animations+1] = anim_data
|
||||||
|
|
||||||
return self.animations[#self.animations]
|
return self.animations[#self.animations]
|
||||||
end
|
end
|
||||||
|
|
||||||
function DrawAnimationFrame(animation, frame, x, y, rotate, sx, sy)
|
function DrawAnimationFrame(animation, frame, x, y, rotate, sx, sy)
|
||||||
local x = x or 0
|
local x = x or 0
|
||||||
local y = y or 0
|
local y = y or 0
|
||||||
local sx = sx or 1
|
local sx = sx or 1
|
||||||
local sy = sy or 1
|
local sy = sy or 1
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
animation.imgs[frame],
|
animation.imgs[frame],
|
||||||
x - Camera.pos.x,
|
x - Camera.pos.x,
|
||||||
y - Camera.pos.y,
|
y - Camera.pos.y,
|
||||||
rotate,
|
rotate,
|
||||||
sx,
|
sx,
|
||||||
sy
|
sy
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function DrawAnimation(animation, x, y, rotate, sx, sy)
|
function DrawAnimation(animation, x, y, rotate, sx, sy)
|
||||||
local x = x or 0
|
local x = x or 0
|
||||||
local y = y or 0
|
local y = y or 0
|
||||||
local sx = sx or 1
|
local sx = sx or 1
|
||||||
local sy = sy or 1
|
local sy = sy or 1
|
||||||
if game_paused ~= true then
|
if game_paused ~= true then
|
||||||
-- try to animate
|
-- try to animate
|
||||||
animation.subframe = animation.subframe + current_dt
|
animation.subframe = animation.subframe + current_dt
|
||||||
|
|
||||||
if animation.subframe >= animation.speed then
|
if animation.subframe >= animation.speed then
|
||||||
animation.frame = animation.frame + 1
|
animation.frame = animation.frame + 1
|
||||||
animation.subframe = animation.subframe - animation.speed
|
animation.subframe = animation.subframe - animation.speed
|
||||||
end
|
end
|
||||||
|
|
||||||
-- cycle
|
-- cycle
|
||||||
if animation.frame >= animation.frames+1 then
|
if animation.frame >= animation.frames+1 then
|
||||||
animation.frame = animation.frame - animation.frames
|
animation.frame = animation.frame - animation.frames
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
animation.imgs[animation.frame],
|
animation.imgs[animation.frame],
|
||||||
x - Camera.pos.x,
|
x - Camera.pos.x,
|
||||||
y - Camera.pos.y,
|
y - Camera.pos.y,
|
||||||
rotate,
|
rotate,
|
||||||
sx,
|
sx,
|
||||||
sy
|
sy
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:Animate()
|
function Entity:Animate()
|
||||||
if game_paused ~= true then
|
if game_paused ~= true then
|
||||||
-- try to animate
|
-- try to animate
|
||||||
self.anim.subframe = self.anim.subframe + current_dt
|
self.anim.subframe = self.anim.subframe + current_dt
|
||||||
|
|
||||||
if self.anim.subframe >= self.anim.speed then
|
if self.anim.subframe >= self.anim.speed then
|
||||||
self.anim.frame = self.anim.frame + 1
|
self.anim.frame = self.anim.frame + 1
|
||||||
self.anim.subframe = self.anim.subframe - self.anim.speed
|
self.anim.subframe = self.anim.subframe - self.anim.speed
|
||||||
end
|
end
|
||||||
|
|
||||||
-- cycle
|
-- cycle
|
||||||
if self.anim.frame >= self.anim.frames+1 then
|
if self.anim.frame >= self.anim.frames+1 then
|
||||||
self.anim.frame = self.anim.frame - self.anim.frames
|
self.anim.frame = self.anim.frame - self.anim.frames
|
||||||
end
|
end
|
||||||
|
|
||||||
-- change
|
-- change
|
||||||
self.sprite = self.anim.imgs[self.anim.frame]
|
self.sprite = self.anim.imgs[self.anim.frame]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:LoadAnimation(anim,frames,speed)
|
function Entity:LoadAnimation(anim,frames,speed)
|
||||||
if self.anim.path ~= anim and self.anim.path ~= anim.path then
|
if self.anim.path ~= anim and self.anim.path ~= anim.path then
|
||||||
if frames ~= nil and speed ~= nil then
|
if frames ~= nil and speed ~= nil then
|
||||||
self.anim.path = anim or nil
|
self.anim.path = anim or nil
|
||||||
self.anim.frames = frames or 4
|
self.anim.frames = frames or 4
|
||||||
self.anim.speed = speed or frames
|
self.anim.speed = speed or frames
|
||||||
else
|
else
|
||||||
self.anim.path = anim.path
|
self.anim.path = anim.path
|
||||||
self.anim.frames = anim.frames
|
self.anim.frames = anim.frames
|
||||||
self.anim.speed = anim.speed
|
self.anim.speed = anim.speed
|
||||||
end
|
end
|
||||||
|
|
||||||
self.anim.imgs = anim.imgs
|
self.anim.imgs = anim.imgs
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "data/scripts/entities/kupo"
|
require "data/scripts/entities/kupo"
|
||||||
require "data/scripts/entities/arrow"
|
require "data/scripts/entities/arrow"
|
||||||
require "data/scripts/entities/player"
|
require "data/scripts/entities/player"
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
Lights = {}
|
||||||
|
LightTimer = 0
|
||||||
|
|
||||||
|
function CreateDarkness()
|
||||||
|
return love.graphics.newCanvas(game.width/2, game.height/2)
|
||||||
|
end
|
||||||
|
|
||||||
|
function CreateLight(x,y,range)
|
||||||
|
local o = {}
|
||||||
|
o.pos = {
|
||||||
|
x = x,
|
||||||
|
y = y
|
||||||
|
}
|
||||||
|
o.range = range
|
||||||
|
o.flicker = 0
|
||||||
|
table.insert(Lights,o)
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function DoDarkness()
|
||||||
|
love.graphics.setColor(0,0,0)
|
||||||
|
love.graphics.rectangle("fill",0,0,game.width,game.height)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DoLights()
|
||||||
|
LightTimer = LightTimer + 1
|
||||||
|
|
||||||
|
if LightTimer >= 3 then
|
||||||
|
LightTimer = LightTimer - 3
|
||||||
|
for _, light in pairs(Lights) do
|
||||||
|
light.flicker = math.random(-1,1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.setBlendMode("replace")
|
||||||
|
-- first, border
|
||||||
|
love.graphics.setColor(1,1,1)
|
||||||
|
for _, light in pairs(Lights) do
|
||||||
|
|
||||||
|
love.graphics.circle(
|
||||||
|
"fill",
|
||||||
|
light.pos.x - Camera.pos.x,
|
||||||
|
light.pos.y - Camera.pos.y,
|
||||||
|
light.range + light.flicker + 1
|
||||||
|
)
|
||||||
|
end
|
||||||
|
love.graphics.setColor(0,0,0,0)
|
||||||
|
-- then, light
|
||||||
|
for _, light in pairs(Lights) do
|
||||||
|
love.graphics.circle(
|
||||||
|
"fill",
|
||||||
|
light.pos.x - Camera.pos.x,
|
||||||
|
light.pos.y - Camera.pos.y,
|
||||||
|
light.range + light.flicker
|
||||||
|
)
|
||||||
|
end
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
end
|
||||||
|
|
||||||
|
function DoBorder()
|
||||||
|
end
|
||||||
|
|
||||||
|
function DrawDarkness()
|
||||||
|
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 1, 1)
|
||||||
|
end
|
664
data/tiles.lua
664
data/tiles.lua
|
@ -1,332 +1,332 @@
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
id = 1,
|
id = 1,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 2,
|
id = 2,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 3,
|
id = 3,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 4,
|
id = 4,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 5,
|
id = 5,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 6,
|
id = 6,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 7,
|
id = 7,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 8,
|
id = 8,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 9,
|
id = 9,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 10,
|
id = 10,
|
||||||
type = "half_bottom",
|
type = "half_bottom",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 11,
|
id = 11,
|
||||||
type = "half_bottom",
|
type = "half_bottom",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 12,
|
id = 12,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 13,
|
id = 13,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 14,
|
id = 14,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 15,
|
id = 15,
|
||||||
type = "half_right",
|
type = "half_right",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 16,
|
id = 16,
|
||||||
type = "half_left",
|
type = "half_left",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 17,
|
id = 17,
|
||||||
type = "half_bottom",
|
type = "half_bottom",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 18,
|
id = 18,
|
||||||
type = "half_top",
|
type = "half_top",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 19,
|
id = 19,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 20,
|
id = 20,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 21,
|
id = 21,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 22,
|
id = 22,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 23,
|
id = 23,
|
||||||
type = "half_top",
|
type = "half_top",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 24,
|
id = 24,
|
||||||
type = "half_top",
|
type = "half_top",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 25,
|
id = 25,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 26,
|
id = 26,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 27,
|
id = 27,
|
||||||
type = "ramp2_bot_right_half",
|
type = "ramp2_bot_right_half",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 28,
|
id = 28,
|
||||||
type = "ramp2_bot_right_whole",
|
type = "ramp2_bot_right_whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 29,
|
id = 29,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 30,
|
id = 30,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 31,
|
id = 31,
|
||||||
type = "ramp2_bot_left_whole",
|
type = "ramp2_bot_left_whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 32,
|
id = 32,
|
||||||
type = "ramp2_bot_left_half",
|
type = "ramp2_bot_left_half",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 33,
|
id = 33,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 34,
|
id = 34,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 35,
|
id = 35,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 36,
|
id = 36,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 37,
|
id = 37,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 38,
|
id = 38,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 39,
|
id = 39,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 40,
|
id = 40,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 41,
|
id = 41,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 42,
|
id = 42,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 43,
|
id = 43,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 44,
|
id = 44,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 45,
|
id = 45,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 46,
|
id = 46,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 47,
|
id = 47,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 48,
|
id = 48,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 49,
|
id = 49,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 50,
|
id = 50,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 51,
|
id = 51,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 52,
|
id = 52,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 53,
|
id = 53,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 54,
|
id = 54,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 55,
|
id = 55,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 56,
|
id = 56,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 57,
|
id = 57,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 58,
|
id = 58,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 59,
|
id = 59,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 60,
|
id = 60,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 61,
|
id = 61,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 62,
|
id = 62,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 63,
|
id = 63,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 64,
|
id = 64,
|
||||||
type = "empty",
|
type = "empty",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 65,
|
id = 65,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id = 119,
|
id = 119,
|
||||||
type = "whole",
|
type = "whole",
|
||||||
depth = "foreground"
|
depth = "foreground"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
290
main.lua
290
main.lua
|
@ -1,138 +1,152 @@
|
||||||
function love.load()
|
function love.load()
|
||||||
do_pause = false
|
do_pause = false
|
||||||
debug = false
|
debug = false
|
||||||
debug_collision = false
|
debug_collision = false
|
||||||
textScale = 1
|
textScale = 1
|
||||||
fps_count = 0
|
fps_count = 0
|
||||||
fps_second = 0
|
fps_second = 0
|
||||||
fps_draw = 0
|
fps_draw = 0
|
||||||
fps_total = 0
|
fps_total = 0
|
||||||
love.graphics.setColor(1,1,1)
|
love.graphics.setColor(1,1,1)
|
||||||
love.keyboard.setKeyRepeat(true)
|
love.keyboard.setKeyRepeat(true)
|
||||||
love.graphics.setDefaultFilter("nearest") -- good pixel
|
love.graphics.setDefaultFilter("nearest") -- good pixel
|
||||||
game = {
|
game = {
|
||||||
scale = 2,
|
scale = 2,
|
||||||
width = love.graphics.getWidth(),
|
width = love.graphics.getWidth(),
|
||||||
height = love.graphics.getHeight(),
|
height = love.graphics.getHeight(),
|
||||||
paused = false
|
paused = false
|
||||||
}
|
}
|
||||||
require "data/scripts"
|
require "data/scripts"
|
||||||
Camera.width = game.width
|
Canvas = {
|
||||||
Camera.height = game.height
|
Darkness = CreateDarkness()
|
||||||
levelList = {"level1","2","3","ewae","tileset"}
|
}
|
||||||
levelNum = 1
|
Camera.width = game.width
|
||||||
currLevel = levelList[levelNum]
|
Camera.height = game.height
|
||||||
LevelLoadTiles()
|
levelList = {"level1","2","3","ewae","tileset"}
|
||||||
main_Player = Player:New(1220,220)
|
levelNum = 1
|
||||||
LoadedEntities = {}
|
currLevel = levelList[levelNum]
|
||||||
table.insert(LoadedEntities,main_Player)
|
LevelLoadTiles()
|
||||||
table.insert(LoadedEntities,Kupo:New(450,100))
|
main_Player = Player:New(0,20)
|
||||||
table.insert(LoadedEntities,Kupo:New(250,150))
|
LoadedEntities = {}
|
||||||
main_Player.sprite = love.graphics.newImage("assets/characters/nancy/idle1.png")
|
table.insert(LoadedEntities,main_Player)
|
||||||
main_Player:LoadAnimation(animation.nancy.idle)
|
table.insert(LoadedEntities,Kupo:New(450,100))
|
||||||
end
|
table.insert(LoadedEntities,Kupo:New(250,150))
|
||||||
|
main_Player.sprite = love.graphics.newImage("assets/characters/nancy/idle1.png")
|
||||||
function love.update(dt)
|
main_Player:LoadAnimation(animation.nancy.idle)
|
||||||
-- fps counter
|
end
|
||||||
if fps_second >= 1 then
|
|
||||||
fps_second = fps_second - 1
|
function love.update(dt)
|
||||||
fps_draw = fps_count
|
-- fps counter
|
||||||
fps_count = 0
|
if fps_second >= 1 then
|
||||||
fps_total = fps_total + 1
|
fps_second = fps_second - 1
|
||||||
end
|
fps_draw = fps_count
|
||||||
fps_second = fps_second + dt
|
fps_count = 0
|
||||||
fps_count = fps_count + 1
|
fps_total = fps_total + 1
|
||||||
current_dt = dt
|
end
|
||||||
|
fps_second = fps_second + dt
|
||||||
-- saveproof to game resize
|
fps_count = fps_count + 1
|
||||||
game.width = love.graphics.getWidth()
|
current_dt = dt
|
||||||
game.height = love.graphics.getHeight()
|
|
||||||
Camera.height = game.height
|
-- saveproof to game resize
|
||||||
Camera.width = game.width
|
if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then
|
||||||
-- GAME STEP
|
game.width = love.graphics.getWidth()
|
||||||
if not do_pause then
|
game.height = love.graphics.getHeight()
|
||||||
SetCollisionFlags(main_Player)
|
Camera.height = game.height
|
||||||
for _, enty in pairs(LoadedEntities) do
|
Camera.width = game.width
|
||||||
enty:Smart()
|
Canvas.Darkness:release()
|
||||||
enty:DoPhysics()
|
Canvas.Darkness = CreateDarkness()
|
||||||
end
|
end
|
||||||
AnimateTiles()
|
|
||||||
Camera:CenterAt(main_Player.pos.x, main_Player.pos.y,LevelInfo.Width,LevelInfo.Height)
|
-- GAME STEP
|
||||||
--camera:ScreenAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
|
if not do_pause then
|
||||||
end
|
SetCollisionFlags(main_Player)
|
||||||
end
|
for _, enty in pairs(LoadedEntities) do
|
||||||
|
enty:Smart()
|
||||||
function love.keypressed(key)
|
enty:DoPhysics()
|
||||||
|
end
|
||||||
if key == "escape" then
|
AnimateTiles()
|
||||||
if do_pause then
|
Camera:CenterAt(main_Player.pos.x, main_Player.pos.y,LevelInfo.Width,LevelInfo.Height)
|
||||||
do_pause = false
|
--camera:ScreenAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
|
||||||
else
|
end
|
||||||
pausepage = 1
|
end
|
||||||
do_pause = true
|
|
||||||
end
|
function love.keypressed(key)
|
||||||
end
|
|
||||||
|
if key == "escape" then
|
||||||
if key == "f1" then
|
if do_pause then
|
||||||
if debug then
|
do_pause = false
|
||||||
debug = false
|
else
|
||||||
debug_collision = true
|
pausepage = 1
|
||||||
elseif debug_collision then
|
do_pause = true
|
||||||
debug_collision = false
|
end
|
||||||
else
|
end
|
||||||
debug = true
|
|
||||||
end
|
if key == "f1" then
|
||||||
end
|
if debug then
|
||||||
|
debug = false
|
||||||
if key == "f2" then
|
debug_collision = true
|
||||||
main_Player.pos.x, main_Player.pos.y = 0,-0.1
|
elseif debug_collision then
|
||||||
end
|
debug_collision = false
|
||||||
|
else
|
||||||
if key == "f3" then
|
debug = true
|
||||||
LoadLevel()
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if key == "f5" then
|
if key == "f2" then
|
||||||
levelNum = levelNum + 1
|
main_Player.pos.x, main_Player.pos.y = 0,-0.1
|
||||||
if levelNum > #levelList then levelNum = levelNum - #levelList end
|
end
|
||||||
currLevel = levelList[levelNum]
|
|
||||||
LevelLoadTiles()
|
if key == "f3" then
|
||||||
main_Player.pos.x, main_Player.pos.y = 0,-0.1
|
LoadLevel()
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
if key == "f5" then
|
||||||
function love.draw()
|
levelNum = levelNum + 1
|
||||||
-- GAME WORLD
|
if levelNum > #levelList then levelNum = levelNum - #levelList end
|
||||||
love.graphics.scale(game.scale,game.scale)
|
currLevel = levelList[levelNum]
|
||||||
LevelDisplayBackground()
|
LevelLoadTiles()
|
||||||
for _, enty in pairs(LoadedEntities) do
|
main_Player.pos.x, main_Player.pos.y = 0,-0.1
|
||||||
enty:HandleAnimation()
|
end
|
||||||
enty:Animate()
|
end
|
||||||
enty:Draw()
|
|
||||||
end
|
function love.draw()
|
||||||
LevelDisplayForeground()
|
-- GAME WORLD
|
||||||
|
love.graphics.scale(game.scale,game.scale)
|
||||||
-- Save color
|
love.graphics.setColor(1,1,1,1)
|
||||||
local pcr, pcg, pcb, pca = love.graphics.getColor()
|
LevelDisplayBackground()
|
||||||
|
for _, enty in pairs(LoadedEntities) do
|
||||||
-- HUD
|
enty:HandleAnimation()
|
||||||
love.graphics.scale(1,1)
|
enty:Animate()
|
||||||
-- Scale control
|
enty:Draw()
|
||||||
if game.height > game.width then
|
end
|
||||||
textScale = game.height/480/2
|
LevelDisplayForeground()
|
||||||
else
|
|
||||||
textScale = game.width/640/2
|
-- Save color
|
||||||
end
|
local pcr, pcg, pcb, pca = love.graphics.getColor()
|
||||||
|
|
||||||
--debug
|
love.graphics.setCanvas(Canvas.Darkness)
|
||||||
if debug then DebugUI() end
|
DoDarkness()
|
||||||
if debug_collision then DebugColisions() end
|
DoLights()
|
||||||
|
DoBorder()
|
||||||
-- reset color
|
|
||||||
love.graphics.setColor(pcr,pcg,pcb,pca)
|
-- reset to screen
|
||||||
|
love.graphics.setColor(1,1,1,1)
|
||||||
|
love.graphics.setCanvas()
|
||||||
local pcr, pcg, pcb, pca = love.graphics.getColor()
|
love.graphics.scale(1,1)
|
||||||
if do_pause then PauseUI() end
|
DrawDarkness()
|
||||||
love.graphics.setColor(pcr,pcg,pcb,pca)
|
-- HUD
|
||||||
end
|
-- Scale control
|
||||||
|
textScale = 0.5
|
||||||
|
|
||||||
|
--debug
|
||||||
|
if debug then DebugUI() end
|
||||||
|
if debug_collision then DebugColisions() end
|
||||||
|
|
||||||
|
-- reset color
|
||||||
|
love.graphics.setColor(pcr,pcg,pcb,pca)
|
||||||
|
|
||||||
|
|
||||||
|
local pcr, pcg, pcb, pca = love.graphics.getColor()
|
||||||
|
if do_pause then PauseUI() end
|
||||||
|
love.graphics.setColor(pcr,pcg,pcb,pca)
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue