diff --git a/LoreMuseum b/LoreMuseum new file mode 160000 index 0000000..38e8c5a --- /dev/null +++ b/LoreMuseum @@ -0,0 +1 @@ +Subproject commit 38e8c5a4db22269d5d63d39c733b3802452b4c0b diff --git a/data/scripts.lua b/data/scripts.lua index 2e32271..b284590 100644 --- a/data/scripts.lua +++ b/data/scripts.lua @@ -11,6 +11,7 @@ require "data/scripts/collision" require "data/scripts/level" -- data require "data/scripts/camera" +require "data/scripts/lights" require "data/scripts/objects" -- UI functions require "data/scripts/debug" diff --git a/data/scripts/debug.lua b/data/scripts/debug.lua index 5ef3125..8c0fa0a 100644 --- a/data/scripts/debug.lua +++ b/data/scripts/debug.lua @@ -1,4 +1,11 @@ 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.setColor(1,1,1) diff --git a/data/scripts/entities/arrow.lua b/data/scripts/entities/arrow.lua index 4c2d6b1..5d13d77 100644 --- a/data/scripts/entities/arrow.lua +++ b/data/scripts/entities/arrow.lua @@ -15,7 +15,7 @@ Arrow = Entity:New(x,y) setmetatable(o, self) self.__index = self - table.insert(LoadedEntities,o) + table.insert(LoadedEntities,o) return o end diff --git a/data/scripts/entities/kupo.lua b/data/scripts/entities/kupo.lua index 1a47e7e..7bcb9bf 100644 --- a/data/scripts/entities/kupo.lua +++ b/data/scripts/entities/kupo.lua @@ -18,7 +18,11 @@ Kupo = Entity:New(x,y) o.bow_speed = 1/10 o.bow_frames = 6 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) self.__index = self diff --git a/data/scripts/entities/player.lua b/data/scripts/entities/player.lua index b80ee8c..855b8aa 100644 --- a/data/scripts/entities/player.lua +++ b/data/scripts/entities/player.lua @@ -1,203 +1,214 @@ - Player = Entity:New(x,y) - - - function Player:New(x,y) - local o = Entity:New(x,y) - Player.health = 3 - Player.coins = 0 - - -- physics - o.vel = { - x = 0, - y = 0 - } - -- constants - o.acc = 45 - o.friction = 20 - o.gravity = 9.81 - o.climbHeight = 4 - o.jumpForce = 5 - o.maxSpeed = 600 - o.jumpMaxSpeed = 9.5 - o.zeroSpeed = 0.001 - -- bools - o.isJumping = false - o.isOnGround = 0 - o.coyoteValue = 5 - o.isOnLadder = false - o.canJump = true - o.canFall = true - o.canFriction = true - - -- sprite - o.sprite_offset = {x = 8, y = 16} - o.target_offset = {x = 4, y = 12} - setmetatable(o, self) - self.__index = self - - return o - end - -function Player:Smart() - -- PLATFORMER INPUT - if self.isOnGround > 0 then - -- apply friction - - -- horizontal input (slide~~) - if love.keyboard.isDown('a',"left") then - self.vel.x = self.vel.x - self.acc*current_dt - end - if love.keyboard.isDown('d',"right") then - self.vel.x = self.vel.x + self.acc*current_dt - end - if self.canJump then - -- vertical input (jump!) - if love.keyboard.isDown("up", "w") and self.isJumping ~= true then - self.vel.y = self.vel.y - self.jumpForce - self.isOnGround = 0 - self.isJumping = true - end - end - end - - -- fall if down input on platforms - if not isThereCollisionAt( - self.pos.x, - self.pos.y + self.vel.y - ) and not isThereLadderAt( - self.pos.x, - self.pos.y + self.vel.y - ) and isTherePlatformAt( - self.pos.x, - self.pos.y + self.vel.y - ) and love.keyboard.isDown("down", "s") - then - self.pos.y = self.pos.y + tileProperties.height/3 - self.isOnGround = 0 - end -end - -function Player:HandleAnimation() - - -- flip sprite to look in the direction is moving - if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end - - -- animation manager - if self.isOnLadder then - self:LoadAnimation(animation.nancy.jump) - elseif self.isOnGround == 0 and self.isJumping and self.vel.y > 1.25 then - self:LoadAnimation(animation.nancy.fall) - elseif self.isOnGround == 0 and self.vel.y < 0 then - self:LoadAnimation(animation.nancy.jump) - elseif self.vel.x ~= 0 then - self:LoadAnimation(animation.nancy.run) - else - self:LoadAnimation(animation.nancy.idle) - end - - -- special case: idle animation gets slower by time - if self.anim_path == animation.nancy.idle.path then - if self.anim_speed < 0.5 then self.anim_speed = self.anim_speed + 0.001 end - end -end - -function Player:DoPhysics() - -- reset physics resolution - self.canFall = true - self.canJump = true - self.canFriction = true - -- reset flags - self.isOnLadder = false - -- truncate to max & min values - if math.abs(self.vel.x) > self.maxSpeed then - self.vel.x = self.maxSpeed * math.sign(self.vel.x) - end - if math.abs(self.vel.y) > self.maxSpeed then - self.vel.y = self.maxSpeed * math.sign(self.vel.y) - end - if math.abs(self.vel.x) < self.zeroSpeed then - self.vel.x = 0 - end - if math.abs(self.vel.y) < self.zeroSpeed then - self.vel.y = 0 - end - - -- if on air, say so! - if self.vel.y > 5 then - self.isJumping = true - end - - -- if its on ground, then say so. - if self.vel.y > 0 then - if isThereAnyCollisionAt( - self.pos.x, - self.pos.y + self.vel.y - ) then - self.isOnGround = self.coyoteValue - self.isJumping = false - end - end - -- horizontal collisions - if isThereAnyCollisionAt(self.pos.x + self.vel.x, self.pos.y) then - -- checks for ladders - if isThereLadderAt(self.pos.x + self.vel.x, self.pos.y) - and self.vel.x ~= 0 - and not isThereLadderAt(self.pos.x, self.pos.y) - then - self.vel.y = 0 - self.vel.x = 0 - - self.pos.y = self.pos.y - 4 * current_dt - - self.canFall = false - self.canJump = false - self.canFriction = false - - self.isOnLadder = true - self.isOnGround = self.coyoteValue - end - - -- checks for slopes - for i = 1, self.climbHeight do - if not isThereCollisionAt(self.pos.x + self.vel.x, self.pos.y - i) - and self.isOnGround > 0 then - - self.pos.x = self.pos.x + self.vel.x * 4/5 - self.pos.y = self.pos.y - i - - self.canFriction = false - break - end - end - - -- hey, you arent permanently stopped while collisioning, just lose a bit of force! - if self.canFriction then - self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction/15, 1)) - end - else - self.pos.x = self.pos.x + self.vel.x - end - - -- vertical collision - if self.vel.y > 0 - and isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then - self.isOnGround = self.coyoteValue - self.isJumping = false - self.vel.y = 0 - else - self.pos.y = self.pos.y + self.vel.y - self.isOnGround = math.max(self.isOnGround - 1, 0) - 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 + Player = Entity:New(x,y) + + + function Player:New(x,y) + local o = Entity:New(x,y) + Player.health = 3 + Player.coins = 0 + + -- physics + o.vel = { + x = 0, + y = 0 + } + + -- constants + o.acc = 45 + o.friction = 20 + o.gravity = 9.81 + o.climbHeight = 4 + o.jumpForce = 5 + o.maxSpeed = 600 + o.jumpMaxSpeed = 9.5 + o.zeroSpeed = 0.001 + o.lightRange = 20 + + -- status + o.isJumping = false + o.isOnGround = 0 + o.coyoteValue = 5 + o.isOnLadder = false + o.canJump = true + o.canFall = true + o.canFriction = true + + -- sprite + o.sprite_offset = {x = 8, y = 16} + o.target_offset = {x = 0, y = 12} + + -- lights + o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange) + + + setmetatable(o, self) + self.__index = self + + return o + end + +function Player:Smart() + -- PLATFORMER INPUT + if self.isOnGround > 0 then + -- apply friction + + -- horizontal input (slide~~) + if love.keyboard.isDown('a',"left") then + self.vel.x = self.vel.x - self.acc*current_dt + end + if love.keyboard.isDown('d',"right") then + self.vel.x = self.vel.x + self.acc*current_dt + end + if self.canJump then + -- vertical input (jump!) + if love.keyboard.isDown("up", "w") and self.isJumping ~= true then + self.vel.y = self.vel.y - self.jumpForce + self.isOnGround = 0 + self.isJumping = true + end + end + end + + -- fall if down input on platforms + if not isThereCollisionAt( + self.pos.x, + self.pos.y + self.vel.y + ) and not isThereLadderAt( + self.pos.x, + self.pos.y + self.vel.y + ) and isTherePlatformAt( + self.pos.x, + self.pos.y + self.vel.y + ) and love.keyboard.isDown("down", "s") + then + self.pos.y = self.pos.y + tileProperties.height/3 + self.isOnGround = 0 + end +end + +function Player:HandleAnimation() + -- move light to position, :D + self.light.pos.x = self.pos.x - self.target_offset.x + self.light.pos.y = self.pos.y - self.target_offset.y + + -- flip sprite to look in the direction is moving + if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end + + -- animation manager + if self.isOnLadder then + self:LoadAnimation(animation.nancy.jump) + elseif self.isOnGround == 0 and self.isJumping and self.vel.y > 1.25 then + self:LoadAnimation(animation.nancy.fall) + elseif self.isOnGround == 0 and self.vel.y < 0 then + self:LoadAnimation(animation.nancy.jump) + elseif self.vel.x ~= 0 then + self:LoadAnimation(animation.nancy.run) + else + self:LoadAnimation(animation.nancy.idle) + end + + -- special case: idle animation gets slower by time + if self.anim_path == animation.nancy.idle.path then + if self.anim_speed < 0.5 then self.anim_speed = self.anim_speed + 0.001 end + end +end + +function Player:DoPhysics() + -- reset physics resolution + self.canFall = true + self.canJump = true + self.canFriction = true + -- reset flags + self.isOnLadder = false + -- truncate to max & min values + if math.abs(self.vel.x) > self.maxSpeed then + self.vel.x = self.maxSpeed * math.sign(self.vel.x) + end + if math.abs(self.vel.y) > self.maxSpeed then + self.vel.y = self.maxSpeed * math.sign(self.vel.y) + end + if math.abs(self.vel.x) < self.zeroSpeed then + self.vel.x = 0 + end + if math.abs(self.vel.y) < self.zeroSpeed then + self.vel.y = 0 + end + + -- if on air, say so! + if self.vel.y > 5 then + self.isJumping = true + end + + -- if its on ground, then say so. + if self.vel.y > 0 then + if isThereAnyCollisionAt( + self.pos.x, + self.pos.y + self.vel.y + ) then + self.isOnGround = self.coyoteValue + self.isJumping = false + end + end + -- horizontal collisions + if isThereAnyCollisionAt(self.pos.x + self.vel.x, self.pos.y) then + -- checks for ladders + if isThereLadderAt(self.pos.x + self.vel.x, self.pos.y) + and self.vel.x ~= 0 + and not isThereLadderAt(self.pos.x, self.pos.y) + then + self.vel.y = 0 + self.vel.x = 0 + + self.pos.y = self.pos.y - 4 * current_dt + + self.canFall = false + self.canJump = false + self.canFriction = false + + self.isOnLadder = true + self.isOnGround = self.coyoteValue + end + + -- checks for slopes + for i = 1, self.climbHeight do + if not isThereCollisionAt(self.pos.x + self.vel.x, self.pos.y - i) + and self.isOnGround > 0 then + + self.pos.x = self.pos.x + self.vel.x * 4/5 + self.pos.y = self.pos.y - i + + self.canFriction = false + break + end + end + + -- hey, you arent permanently stopped while collisioning, just lose a bit of force! + if self.canFriction then + self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction/15, 1)) + end + else + self.pos.x = self.pos.x + self.vel.x + end + + -- vertical collision + if self.vel.y > 0 + and isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then + self.isOnGround = self.coyoteValue + self.isJumping = false + self.vel.y = 0 + else + self.pos.y = self.pos.y + self.vel.y + self.isOnGround = math.max(self.isOnGround - 1, 0) + 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 diff --git a/data/scripts/entity.lua b/data/scripts/entity.lua index ea87e94..10db048 100644 --- a/data/scripts/entity.lua +++ b/data/scripts/entity.lua @@ -1,153 +1,153 @@ -Entity = { - } - -function Entity:New(x,y) - o = {} - o.pos = {x = x, y = y} - o.vel = {x = 0, y = 0} - o.class = "Entity" - o.anim = {} - o.anim.subframe = 0 - o.anim.frame = 1 - o.anim.imgs = {} - o.animations = {} - o.sprite_offset = {x = 0, y = 0} - o.sprite_scale = {x = 1, y = 1} - o.sprite_rotation = math.rad(0) - o.sprite_flip = { x = 1, y = 1} - setmetatable(o, self) - self.__index = self - return o -end - -function Entity:Move(target, speed) -- target = {tx int, ty int} / speed = int - -end - -function Entity:Draw() - if self.sprite ~= nil then - local relative_position_x = self.pos.x - Camera.pos.x - 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_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_y = self.sprite_scale.y * self.sprite_flip.y - love.graphics.draw( - self.sprite, - relative_position_x + origin_compensation_x * dimensions_x, - relative_position_y + origin_compensation_y * dimensions_y, - self.sprite_rotation, - self.sprite_scale.x * self.sprite_flip.x, - self.sprite_scale.y * self.sprite_flip.y - ) - if debug_collision then - love.graphics.setColor(1, 0, 0) - love.graphics.circle( "line", relative_position_x, relative_position_y, 2 ) - love.graphics.setColor(0, 1 ,0) - love.graphics.circle( "line", - relative_position_x + origin_compensation_x * dimensions_x, - relative_position_y + origin_compensation_y * dimensions_y, - 2 - ) - end - love.graphics.setColor(1, 1 ,1) - end -end - -function Entity:NewAnimation(anim,frames,speed) - local anim_data = { - frame = 1, - subframe = 1, - path = anim.path, - frames = anim.frames, - speed = anim.speed, - imgs = anim.imgs - } - self.animations[#self.animations+1] = anim_data - - return self.animations[#self.animations] -end - -function DrawAnimationFrame(animation, frame, x, y, rotate, sx, sy) - local x = x or 0 - local y = y or 0 - local sx = sx or 1 - local sy = sy or 1 - love.graphics.draw( - animation.imgs[frame], - x - Camera.pos.x, - y - Camera.pos.y, - rotate, - sx, - sy - ) -end - -function DrawAnimation(animation, x, y, rotate, sx, sy) - local x = x or 0 - local y = y or 0 - local sx = sx or 1 - local sy = sy or 1 - if game_paused ~= true then - -- try to animate - animation.subframe = animation.subframe + current_dt - - if animation.subframe >= animation.speed then - animation.frame = animation.frame + 1 - animation.subframe = animation.subframe - animation.speed - end - - -- cycle - if animation.frame >= animation.frames+1 then - animation.frame = animation.frame - animation.frames - end - end - love.graphics.draw( - animation.imgs[animation.frame], - x - Camera.pos.x, - y - Camera.pos.y, - rotate, - sx, - sy - ) -end - -function Entity:Animate() - if game_paused ~= true then - -- try to animate - self.anim.subframe = self.anim.subframe + current_dt - - if self.anim.subframe >= self.anim.speed then - self.anim.frame = self.anim.frame + 1 - self.anim.subframe = self.anim.subframe - self.anim.speed - end - - -- cycle - if self.anim.frame >= self.anim.frames+1 then - self.anim.frame = self.anim.frame - self.anim.frames - end - - -- change - self.sprite = self.anim.imgs[self.anim.frame] - end -end - -function Entity:LoadAnimation(anim,frames,speed) - if self.anim.path ~= anim and self.anim.path ~= anim.path then - if frames ~= nil and speed ~= nil then - self.anim.path = anim or nil - self.anim.frames = frames or 4 - self.anim.speed = speed or frames - else - self.anim.path = anim.path - self.anim.frames = anim.frames - self.anim.speed = anim.speed - end - - self.anim.imgs = anim.imgs - end -end - -require "data/scripts/entities/kupo" -require "data/scripts/entities/arrow" -require "data/scripts/entities/player" +Entity = { + } + +function Entity:New(x,y) + o = {} + o.pos = {x = x, y = y} + o.vel = {x = 0, y = 0} + o.class = "Entity" + o.anim = {} + o.anim.subframe = 0 + o.anim.frame = 1 + o.anim.imgs = {} + o.animations = {} + o.sprite_offset = {x = 0, y = 0} + o.sprite_scale = {x = 1, y = 1} + o.sprite_rotation = math.rad(0) + o.sprite_flip = { x = 1, y = 1} + setmetatable(o, self) + self.__index = self + return o +end + +function Entity:Move(target, speed) -- target = {tx int, ty int} / speed = int + +end + +function Entity:Draw() + if self.sprite ~= nil then + local relative_position_x = self.pos.x - Camera.pos.x + 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_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_y = self.sprite_scale.y * self.sprite_flip.y + love.graphics.draw( + self.sprite, + relative_position_x + origin_compensation_x * dimensions_x, + relative_position_y + origin_compensation_y * dimensions_y, + self.sprite_rotation, + self.sprite_scale.x * self.sprite_flip.x, + self.sprite_scale.y * self.sprite_flip.y + ) + if debug_collision then + love.graphics.setColor(1, 0, 0) + love.graphics.circle( "line", relative_position_x, relative_position_y, 2 ) + love.graphics.setColor(0, 1 ,0) + love.graphics.circle( "line", + relative_position_x + origin_compensation_x * dimensions_x, + relative_position_y + origin_compensation_y * dimensions_y, + 2 + ) + end + love.graphics.setColor(1, 1 ,1) + end +end + +function Entity:NewAnimation(anim,frames,speed) + local anim_data = { + frame = 1, + subframe = 1, + path = anim.path, + frames = anim.frames, + speed = anim.speed, + imgs = anim.imgs + } + self.animations[#self.animations+1] = anim_data + + return self.animations[#self.animations] +end + +function DrawAnimationFrame(animation, frame, x, y, rotate, sx, sy) + local x = x or 0 + local y = y or 0 + local sx = sx or 1 + local sy = sy or 1 + love.graphics.draw( + animation.imgs[frame], + x - Camera.pos.x, + y - Camera.pos.y, + rotate, + sx, + sy + ) +end + +function DrawAnimation(animation, x, y, rotate, sx, sy) + local x = x or 0 + local y = y or 0 + local sx = sx or 1 + local sy = sy or 1 + if game_paused ~= true then + -- try to animate + animation.subframe = animation.subframe + current_dt + + if animation.subframe >= animation.speed then + animation.frame = animation.frame + 1 + animation.subframe = animation.subframe - animation.speed + end + + -- cycle + if animation.frame >= animation.frames+1 then + animation.frame = animation.frame - animation.frames + end + end + love.graphics.draw( + animation.imgs[animation.frame], + x - Camera.pos.x, + y - Camera.pos.y, + rotate, + sx, + sy + ) +end + +function Entity:Animate() + if game_paused ~= true then + -- try to animate + self.anim.subframe = self.anim.subframe + current_dt + + if self.anim.subframe >= self.anim.speed then + self.anim.frame = self.anim.frame + 1 + self.anim.subframe = self.anim.subframe - self.anim.speed + end + + -- cycle + if self.anim.frame >= self.anim.frames+1 then + self.anim.frame = self.anim.frame - self.anim.frames + end + + -- change + self.sprite = self.anim.imgs[self.anim.frame] + end +end + +function Entity:LoadAnimation(anim,frames,speed) + if self.anim.path ~= anim and self.anim.path ~= anim.path then + if frames ~= nil and speed ~= nil then + self.anim.path = anim or nil + self.anim.frames = frames or 4 + self.anim.speed = speed or frames + else + self.anim.path = anim.path + self.anim.frames = anim.frames + self.anim.speed = anim.speed + end + + self.anim.imgs = anim.imgs + end +end + +require "data/scripts/entities/kupo" +require "data/scripts/entities/arrow" +require "data/scripts/entities/player" diff --git a/data/scripts/lights.lua b/data/scripts/lights.lua new file mode 100644 index 0000000..d6b1104 --- /dev/null +++ b/data/scripts/lights.lua @@ -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 \ No newline at end of file diff --git a/data/tiles.lua b/data/tiles.lua index 62310a0..d7edb07 100644 --- a/data/tiles.lua +++ b/data/tiles.lua @@ -1,332 +1,332 @@ -return { - { - id = 1, - type = "whole", - depth = "foreground" - }, - { - id = 2, - type = "whole", - depth = "foreground" - }, - { - id = 3, - type = "whole", - depth = "foreground" - }, - { - id = 4, - type = "whole", - depth = "foreground" - }, - { - id = 5, - type = "whole", - depth = "foreground" - }, - { - id = 6, - type = "whole", - depth = "foreground" - }, - { - id = 7, - type = "whole", - depth = "foreground" - }, - { - id = 8, - type = "whole", - depth = "foreground" - }, - { - id = 9, - type = "whole", - depth = "foreground" - }, - { - id = 10, - type = "half_bottom", - depth = "foreground" - }, - { - id = 11, - type = "half_bottom", - depth = "foreground" - }, - { - id = 12, - type = "whole", - depth = "foreground" - }, - { - id = 13, - type = "whole", - depth = "foreground" - }, - { - id = 14, - type = "whole", - depth = "foreground" - }, - { - id = 15, - type = "half_right", - depth = "foreground" - }, - { - id = 16, - type = "half_left", - depth = "foreground" - }, - { - id = 17, - type = "half_bottom", - depth = "foreground" - }, - { - id = 18, - type = "half_top", - depth = "foreground" - }, - { - id = 19, - type = "whole", - depth = "foreground" - }, - { - id = 20, - type = "whole", - depth = "foreground" - }, - { - id = 21, - type = "whole", - depth = "foreground" - }, - { - id = 22, - type = "whole", - depth = "foreground" - }, - { - id = 23, - type = "half_top", - depth = "foreground" - }, - { - id = 24, - type = "half_top", - depth = "foreground" - }, - { - id = 25, - type = "whole", - depth = "foreground" - }, - { - id = 26, - type = "whole", - depth = "foreground" - }, - { - id = 27, - type = "ramp2_bot_right_half", - depth = "foreground" - }, - { - id = 28, - type = "ramp2_bot_right_whole", - depth = "foreground" - }, - { - id = 29, - type = "whole", - depth = "foreground" - }, - { - id = 30, - type = "whole", - depth = "foreground" - }, - { - id = 31, - type = "ramp2_bot_left_whole", - depth = "foreground" - }, - { - id = 32, - type = "ramp2_bot_left_half", - depth = "foreground" - }, - { - id = 33, - type = "empty", - depth = "foreground" - }, - { - id = 34, - type = "empty", - depth = "foreground" - }, - { - id = 35, - type = "empty", - depth = "foreground" - }, - { - id = 36, - type = "empty", - depth = "foreground" - }, - { - id = 37, - type = "empty", - depth = "foreground" - }, - { - id = 38, - type = "empty", - depth = "foreground" - }, - { - id = 39, - type = "whole", - depth = "foreground" - }, - { - id = 40, - type = "empty", - depth = "foreground" - }, - { - id = 41, - type = "empty", - depth = "foreground" - }, - { - id = 42, - type = "empty", - depth = "foreground" - }, - { - id = 43, - type = "empty", - depth = "foreground" - }, - { - id = 44, - type = "empty", - depth = "foreground" - }, - { - id = 45, - type = "empty", - depth = "foreground" - }, - { - id = 46, - type = "empty", - depth = "foreground" - }, - { - id = 47, - type = "empty", - depth = "foreground" - }, - { - id = 48, - type = "empty", - depth = "foreground" - }, - { - id = 49, - type = "whole", - depth = "foreground" - }, - { - id = 50, - type = "whole", - depth = "foreground" - }, - { - id = 51, - type = "whole", - depth = "foreground" - }, - { - id = 52, - type = "whole", - depth = "foreground" - }, - { - id = 53, - type = "empty", - depth = "foreground" - }, - { - id = 54, - type = "empty", - depth = "foreground" - }, - { - id = 55, - type = "empty", - depth = "foreground" - }, - { - id = 56, - type = "empty", - depth = "foreground" - }, - { - id = 57, - type = "empty", - depth = "foreground" - }, - { - id = 58, - type = "empty", - depth = "foreground" - }, - { - id = 59, - type = "empty", - depth = "foreground" - }, - { - id = 60, - type = "empty", - depth = "foreground" - }, - { - id = 61, - type = "empty", - depth = "foreground" - }, - { - id = 62, - type = "empty", - depth = "foreground" - }, - { - id = 63, - type = "empty", - depth = "foreground" - }, - { - id = 64, - type = "empty", - depth = "foreground" - }, - { - id = 65, - type = "whole", - depth = "foreground" - }, - { - id = 119, - type = "whole", - depth = "foreground" - } -} +return { + { + id = 1, + type = "whole", + depth = "foreground" + }, + { + id = 2, + type = "whole", + depth = "foreground" + }, + { + id = 3, + type = "whole", + depth = "foreground" + }, + { + id = 4, + type = "whole", + depth = "foreground" + }, + { + id = 5, + type = "whole", + depth = "foreground" + }, + { + id = 6, + type = "whole", + depth = "foreground" + }, + { + id = 7, + type = "whole", + depth = "foreground" + }, + { + id = 8, + type = "whole", + depth = "foreground" + }, + { + id = 9, + type = "whole", + depth = "foreground" + }, + { + id = 10, + type = "half_bottom", + depth = "foreground" + }, + { + id = 11, + type = "half_bottom", + depth = "foreground" + }, + { + id = 12, + type = "whole", + depth = "foreground" + }, + { + id = 13, + type = "whole", + depth = "foreground" + }, + { + id = 14, + type = "whole", + depth = "foreground" + }, + { + id = 15, + type = "half_right", + depth = "foreground" + }, + { + id = 16, + type = "half_left", + depth = "foreground" + }, + { + id = 17, + type = "half_bottom", + depth = "foreground" + }, + { + id = 18, + type = "half_top", + depth = "foreground" + }, + { + id = 19, + type = "whole", + depth = "foreground" + }, + { + id = 20, + type = "whole", + depth = "foreground" + }, + { + id = 21, + type = "whole", + depth = "foreground" + }, + { + id = 22, + type = "whole", + depth = "foreground" + }, + { + id = 23, + type = "half_top", + depth = "foreground" + }, + { + id = 24, + type = "half_top", + depth = "foreground" + }, + { + id = 25, + type = "whole", + depth = "foreground" + }, + { + id = 26, + type = "whole", + depth = "foreground" + }, + { + id = 27, + type = "ramp2_bot_right_half", + depth = "foreground" + }, + { + id = 28, + type = "ramp2_bot_right_whole", + depth = "foreground" + }, + { + id = 29, + type = "whole", + depth = "foreground" + }, + { + id = 30, + type = "whole", + depth = "foreground" + }, + { + id = 31, + type = "ramp2_bot_left_whole", + depth = "foreground" + }, + { + id = 32, + type = "ramp2_bot_left_half", + depth = "foreground" + }, + { + id = 33, + type = "empty", + depth = "foreground" + }, + { + id = 34, + type = "empty", + depth = "foreground" + }, + { + id = 35, + type = "empty", + depth = "foreground" + }, + { + id = 36, + type = "empty", + depth = "foreground" + }, + { + id = 37, + type = "empty", + depth = "foreground" + }, + { + id = 38, + type = "empty", + depth = "foreground" + }, + { + id = 39, + type = "whole", + depth = "foreground" + }, + { + id = 40, + type = "empty", + depth = "foreground" + }, + { + id = 41, + type = "empty", + depth = "foreground" + }, + { + id = 42, + type = "empty", + depth = "foreground" + }, + { + id = 43, + type = "empty", + depth = "foreground" + }, + { + id = 44, + type = "empty", + depth = "foreground" + }, + { + id = 45, + type = "empty", + depth = "foreground" + }, + { + id = 46, + type = "empty", + depth = "foreground" + }, + { + id = 47, + type = "empty", + depth = "foreground" + }, + { + id = 48, + type = "empty", + depth = "foreground" + }, + { + id = 49, + type = "whole", + depth = "foreground" + }, + { + id = 50, + type = "whole", + depth = "foreground" + }, + { + id = 51, + type = "whole", + depth = "foreground" + }, + { + id = 52, + type = "whole", + depth = "foreground" + }, + { + id = 53, + type = "empty", + depth = "foreground" + }, + { + id = 54, + type = "empty", + depth = "foreground" + }, + { + id = 55, + type = "empty", + depth = "foreground" + }, + { + id = 56, + type = "empty", + depth = "foreground" + }, + { + id = 57, + type = "empty", + depth = "foreground" + }, + { + id = 58, + type = "empty", + depth = "foreground" + }, + { + id = 59, + type = "empty", + depth = "foreground" + }, + { + id = 60, + type = "empty", + depth = "foreground" + }, + { + id = 61, + type = "empty", + depth = "foreground" + }, + { + id = 62, + type = "empty", + depth = "foreground" + }, + { + id = 63, + type = "empty", + depth = "foreground" + }, + { + id = 64, + type = "empty", + depth = "foreground" + }, + { + id = 65, + type = "whole", + depth = "foreground" + }, + { + id = 119, + type = "whole", + depth = "foreground" + } +} diff --git a/main.lua b/main.lua index 63c3406..898e379 100644 --- a/main.lua +++ b/main.lua @@ -1,138 +1,152 @@ -function love.load() - do_pause = false - debug = false - debug_collision = false - textScale = 1 - fps_count = 0 - fps_second = 0 - fps_draw = 0 - fps_total = 0 - love.graphics.setColor(1,1,1) - love.keyboard.setKeyRepeat(true) - love.graphics.setDefaultFilter("nearest") -- good pixel - game = { - scale = 2, - width = love.graphics.getWidth(), - height = love.graphics.getHeight(), - paused = false - } - require "data/scripts" - Camera.width = game.width - Camera.height = game.height - levelList = {"level1","2","3","ewae","tileset"} - levelNum = 1 - currLevel = levelList[levelNum] - LevelLoadTiles() - main_Player = Player:New(1220,220) - LoadedEntities = {} - table.insert(LoadedEntities,main_Player) - table.insert(LoadedEntities,Kupo:New(450,100)) - table.insert(LoadedEntities,Kupo:New(250,150)) - main_Player.sprite = love.graphics.newImage("assets/characters/nancy/idle1.png") - main_Player:LoadAnimation(animation.nancy.idle) -end - -function love.update(dt) - -- fps counter - if fps_second >= 1 then - fps_second = fps_second - 1 - fps_draw = fps_count - fps_count = 0 - fps_total = fps_total + 1 - end - fps_second = fps_second + dt - fps_count = fps_count + 1 - current_dt = dt - - -- saveproof to game resize - game.width = love.graphics.getWidth() - game.height = love.graphics.getHeight() - Camera.height = game.height - Camera.width = game.width - -- GAME STEP - if not do_pause then - SetCollisionFlags(main_Player) - for _, enty in pairs(LoadedEntities) do - enty:Smart() - enty:DoPhysics() - end - AnimateTiles() - Camera:CenterAt(main_Player.pos.x, main_Player.pos.y,LevelInfo.Width,LevelInfo.Height) - --camera:ScreenAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height) - end -end - -function love.keypressed(key) - - if key == "escape" then - if do_pause then - do_pause = false - else - pausepage = 1 - do_pause = true - end - end - - if key == "f1" then - if debug then - debug = false - debug_collision = true - elseif debug_collision then - debug_collision = false - else - debug = true - end - end - - if key == "f2" then - main_Player.pos.x, main_Player.pos.y = 0,-0.1 - end - - if key == "f3" then - LoadLevel() - end - - if key == "f5" then - levelNum = levelNum + 1 - if levelNum > #levelList then levelNum = levelNum - #levelList end - currLevel = levelList[levelNum] - LevelLoadTiles() - main_Player.pos.x, main_Player.pos.y = 0,-0.1 - end -end - -function love.draw() - -- GAME WORLD - love.graphics.scale(game.scale,game.scale) - LevelDisplayBackground() - for _, enty in pairs(LoadedEntities) do - enty:HandleAnimation() - enty:Animate() - enty:Draw() - end - LevelDisplayForeground() - - -- Save color - local pcr, pcg, pcb, pca = love.graphics.getColor() - - -- HUD - love.graphics.scale(1,1) - -- Scale control - if game.height > game.width then - textScale = game.height/480/2 - else - textScale = game.width/640/2 - end - - --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 +function love.load() + do_pause = false + debug = false + debug_collision = false + textScale = 1 + fps_count = 0 + fps_second = 0 + fps_draw = 0 + fps_total = 0 + love.graphics.setColor(1,1,1) + love.keyboard.setKeyRepeat(true) + love.graphics.setDefaultFilter("nearest") -- good pixel + game = { + scale = 2, + width = love.graphics.getWidth(), + height = love.graphics.getHeight(), + paused = false + } + require "data/scripts" + Canvas = { + Darkness = CreateDarkness() + } + Camera.width = game.width + Camera.height = game.height + levelList = {"level1","2","3","ewae","tileset"} + levelNum = 1 + currLevel = levelList[levelNum] + LevelLoadTiles() + main_Player = Player:New(0,20) + LoadedEntities = {} + table.insert(LoadedEntities,main_Player) + table.insert(LoadedEntities,Kupo:New(450,100)) + table.insert(LoadedEntities,Kupo:New(250,150)) + main_Player.sprite = love.graphics.newImage("assets/characters/nancy/idle1.png") + main_Player:LoadAnimation(animation.nancy.idle) +end + +function love.update(dt) + -- fps counter + if fps_second >= 1 then + fps_second = fps_second - 1 + fps_draw = fps_count + fps_count = 0 + fps_total = fps_total + 1 + end + fps_second = fps_second + dt + fps_count = fps_count + 1 + current_dt = dt + + -- saveproof to game resize + if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then + game.width = love.graphics.getWidth() + game.height = love.graphics.getHeight() + Camera.height = game.height + Camera.width = game.width + Canvas.Darkness:release() + Canvas.Darkness = CreateDarkness() + end + + -- GAME STEP + if not do_pause then + SetCollisionFlags(main_Player) + for _, enty in pairs(LoadedEntities) do + enty:Smart() + enty:DoPhysics() + end + AnimateTiles() + Camera:CenterAt(main_Player.pos.x, main_Player.pos.y,LevelInfo.Width,LevelInfo.Height) + --camera:ScreenAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height) + end +end + +function love.keypressed(key) + + if key == "escape" then + if do_pause then + do_pause = false + else + pausepage = 1 + do_pause = true + end + end + + if key == "f1" then + if debug then + debug = false + debug_collision = true + elseif debug_collision then + debug_collision = false + else + debug = true + end + end + + if key == "f2" then + main_Player.pos.x, main_Player.pos.y = 0,-0.1 + end + + if key == "f3" then + LoadLevel() + end + + if key == "f5" then + levelNum = levelNum + 1 + if levelNum > #levelList then levelNum = levelNum - #levelList end + currLevel = levelList[levelNum] + LevelLoadTiles() + main_Player.pos.x, main_Player.pos.y = 0,-0.1 + end +end + +function love.draw() + -- GAME WORLD + love.graphics.scale(game.scale,game.scale) + love.graphics.setColor(1,1,1,1) + LevelDisplayBackground() + for _, enty in pairs(LoadedEntities) do + enty:HandleAnimation() + enty:Animate() + enty:Draw() + end + LevelDisplayForeground() + + -- Save color + local pcr, pcg, pcb, pca = love.graphics.getColor() + + love.graphics.setCanvas(Canvas.Darkness) + DoDarkness() + DoLights() + DoBorder() + + -- reset to screen + love.graphics.setColor(1,1,1,1) + love.graphics.setCanvas() + love.graphics.scale(1,1) + DrawDarkness() + -- HUD + -- 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 diff --git a/to_do.txt b/to_do.txt new file mode 100644 index 0000000..5f05ffb --- /dev/null +++ b/to_do.txt @@ -0,0 +1,15 @@ +MAKE LIGHTING SYSTEM + Updates: + LOVE HAS CANVASES!!! + +MAKE ARROW CANVAS SO THAT ARROWS WHEN STUCK CAN BE STORED AS IMAGE AND ARE NOT LAGGY!!! + +DRAW GIANT ANIMALS AS POWER SOURCE + +DO FAIRY + +DO FLIES + +DO DAMAGE TO PLAYER + +DO UI \ No newline at end of file