uh, a lot happened, i murdered physics code, redesigned tiles & levels, now i need to make another level editor. I'm sorry game. I'm sorry git.

This commit is contained in:
lustlion
2021-11-28 03:38:30 +01:00
parent 8607399d16
commit dd2debc0bd
30 changed files with 701 additions and 693 deletions

View File

@@ -6,7 +6,7 @@ for _, light in pairs(Lights) do
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)
-- lots of variables
@@ -25,9 +25,24 @@ love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..m
-- player isOnGroundCheck
love.graphics.setColor(1,0,0)
love.graphics.points(-Camera.pos.x + main_Player.pos.x, -Camera.pos.y + main_Player.pos.y)
end
function DebugColisions()
objects.DrawCollisions()
end
function DebugEntities()
for _, enty in pairs(LoadedEntities) do
-- draw center GREEN
love.graphics.setColor(0,1,0)
love.graphics.circle("fill", -Camera.pos.x + enty.pos.x, -Camera.pos.y + enty.pos.y, 1)
-- draw collision box PURPLE
love.graphics.setColor(0,1,1)
love.graphics.points(
-Camera.pos.x + enty.pos.x + enty.boxCollision.from.x, -Camera.pos.y + enty.pos.y + enty.boxCollision.from.y,
-Camera.pos.x + enty.pos.x + enty.boxCollision.from.x, -Camera.pos.y + enty.pos.y + enty.boxCollision.to.y,
-Camera.pos.x + enty.pos.x + enty.boxCollision.to.x, -Camera.pos.y + enty.pos.y + enty.boxCollision.from.y,
-Camera.pos.x + enty.pos.x + enty.boxCollision.to.x, -Camera.pos.y + enty.pos.y + enty.boxCollision.to.y
)
end
end

View File

@@ -39,19 +39,33 @@ end
function Arrow:DoPhysics()
-- horizontal collisions
if not isThereAnyCollisionAt(self.pos.x + self.vel.x, self.pos.y) then
if not isThereAnyCollisionAt(
self.pos.x + self.vel.x,
self.pos.y
) then
self.pos.x = self.pos.x + self.vel.x
else
while not isThereCollisionAt(self.pos.x + math.sign(self.vel.x), self.pos.y) do
while not isThereObjectAt(
self.pos.x + math.sign(self.vel.x),
self.pos.y,
objects.collisions
) do
self.pos.x = self.pos.x + math.sign(self.vel.x)
end
self.stuck = true
end
-- vertical collision
if not isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then
if not isThereAnyCollisionAt(
self.pos.x,
self.pos.y + self.vel.y
) then
self.pos.y = self.pos.y + self.vel.y
else
while not isThereCollisionAt(self.pos.x, self.pos.y + math.sign(self.vel.y)) do
while not isThereObjectAt(
self.pos.x,
self.pos.y + math.sign(self.vel.y),
objects.collisions
) do
self.pos.y = self.pos.y + math.sign(self.vel.y)
end
self.stuck = true

View File

@@ -3,26 +3,18 @@
function Player:New(x,y)
local o = Entity:New(x,y)
Player.health = 3
Player.health = 3
Player.coins = 0
-- physics
o.vel = {
x = 0,
y = 0
}
o.moveSpeed = 1.5
-- 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
o.boxCollision = {
from = {x = -8, y = -16},
to = {x = 8, y = 0}
}
o.lightRange = 32
-- status
o.isJumping = false
o.isOnGround = 0
@@ -31,14 +23,16 @@
o.canJump = true
o.canFall = true
o.canFriction = true
o.mask_type = animation.moth_mask
-- sprite
o.sprite_offset = {x = 8, y = 16}
o.target_offset = {x = 0, y = 12}
o.body = Animation:New(animation.nancy.idle)
o.mask = Animation:New(animation.moth_mask.idle)
-- lights
o.maskType = animation.moth_mask
-- sprite
o.sprite_offset = {x = 8, y = 16}
o.target_offset = {x = 0, y = 12}
o.body = Animation:New(animation.nancy.idle)
o.mask = Animation:New(animation.moth_mask.idle)
-- lights
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
setmetatable(o, self)
self.__index = self
@@ -47,64 +41,39 @@
end
function Player:Smart()
-- PLATFORMER INPUT
if self.isOnGround > 0 then
-- apply friction
if love.keyboard.isDown("a") then self.vel.x = -self.moveSpeed
elseif love.keyboard.isDown("d") then self.vel.x = self.moveSpeed
else self.vel.x = 0 end
if love.keyboard.isDown("w") then self.vel.y = -self.moveSpeed
elseif love.keyboard.isDown("s") then self.vel.y = self.moveSpeed
else self.vel.y = 0 end
end
-- 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
function Player:DoPhysics()
self.pos.x = self.pos.x + self.vel.x
self.pos.y = self.pos.y + self.vel.y
end
function Player:HandleAnimation()
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.body = self.body:ChangeTo(animation.nancy.jump)
self.mask = self.mask:ChangeTo(self.mask_type.jump)
elseif self.isOnGround == 0 and self.isJumping and self.vel.y > 1.25 then
-- animation priority
if self.vel.y > 1.25 then
self.body = self.body:ChangeTo(animation.nancy.fall)
self.mask = self.mask:ChangeTo(self.mask_type.fall)
elseif self.isOnGround == 0 and self.vel.y < 0 then
self.mask = self.mask:ChangeTo(self.maskType.fall)
elseif self.vel.y < 0 then
self.body = self.body:ChangeTo(animation.nancy.jump)
self.mask = self.mask:ChangeTo(self.mask_type.jump)
self.mask = self.mask:ChangeTo(self.maskType.jump)
elseif self.vel.x ~= 0 then
self.body = self.body:ChangeTo(animation.nancy.run)
self.mask = self.mask:ChangeTo(self.mask_type.run)
self.mask = self.mask:ChangeTo(self.maskType.run)
else
self.body = self.body:ChangeTo(animation.nancy.idle)
self.mask = self.mask:ChangeTo(self.mask_type.idle)
self.mask = self.mask:ChangeTo(self.maskType.idle)
end
-- special case: idle animation gets slower by time
@@ -114,124 +83,17 @@ function Player:HandleAnimation()
self.body:Animate()
self.body:Draw(
self.pos.x - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
self.pos.y - Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
math.floor(self.pos.x) - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
math.floor(self.pos.y)- Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
self.sprite_rotation,
self.sprite_scale.x * self.sprite_flip.x,
self.sprite_scale.y * self.sprite_flip.y
)
self.mask:Draw(
self.pos.x - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
self.pos.y - Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
math.floor(self.pos.x) - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
math.floor(self.pos.y)- Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
self.sprite_rotation,
self.sprite_scale.x * self.sprite_flip.x,
self.sprite_scale.y * self.sprite_flip.y
)
--[[
love.graphics.print(self.body.frame .. "/".. self.body.frames.." - "..self.body.subframe.."/"..self.body.speed.." ("..current_dt..")")
love.graphics.print(animation.nancy.idle.path,0,20)
love.graphics.print(self.body.path,0,30)
]]
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

View File

@@ -5,6 +5,12 @@ function Entity:New(x,y)
o = {}
o.pos = {x = x, y = y}
o.vel = {x = 0, y = 0}
o.boxCollision = {
from = {x = x, y = y},
to = {x = x, y = y}
}
o.class = "Entity"
o.sprite_offset = {x = 0, y = 0}
@@ -12,13 +18,44 @@ function Entity:New(x,y)
o.sprite_rotation = math.rad(0)
o.sprite_flip = { x = 1, y = 1}
o.illuminated = false
setmetatable(o, self)
self.__index = self
return o
end
function Entity:Move(target, speed) -- target = {tx int, ty int} / speed = int
-- returns true if theres a collision at that point. also marks collisioned tile as collision true
function Entity:isCollidingAt(x,y,object)
local result = false
for _, col in pairs(object) do
result = self.pos.x + self.boxCollision.from.x < col.to.x
and self.pos.x + self.boxCollision.to.x > col.from.x
and self.pos.y + self.boxCollision.from.y < col.to.y
and self.pos.y + self.boxCollision.to.y > col.from.y
if result == true then break end
end
return result
end
function Entity:isCollidingWith(entity)
return self.pos.x + self.boxCollision.from.x < entity.pos.x + entity.boxCollision.to.x
and self.pos.x + self.boxCollision.to.x > entity.pos.x + entity.boxCollision.from.x
and self.pos.y + self.boxCollision.from.y < entity.pos.y + entity.boxCollision.to.y
and self.pos.y + self.boxCollision.to.y > entity.pos.y + entity.boxCollision.from.y
end
function Entity:isCollidingAtAll(x,y)
local result = false
if not result then
result = self:isCollidingAt(x,y,objects.collisions)
end
if not result then
result = self:isCollidingAt(x,y,objects.ladders)
end
if not result then
result = self:isCollidingAt(x,y,objects.platforms)
end
return result
end
--[[function Entity:Draw()

View File

@@ -1,4 +1,5 @@
-- animations
-- animationsç
-- all these are linear animations, maybe in the future make proper animations?
animation = {
kupo = {
body = {
@@ -63,6 +64,9 @@ animation = {
}
}
-- animation loader
-- im unsure if this is too memory expensive (probably)
-- this should go elsewhere, maybe
for _, object in pairs(animation) do
for _, anim in pairs(object) do
anim.imgs = {}
@@ -77,15 +81,21 @@ levelProperties = {
x = 0,
y = 0
},
-- im unsure why there's offset at all, here
offset = {
x = 0,
y = 0
}
}
tileset = {
bricks = love.graphics.newImage("assets/tileset/bricks.png"),
books = love.graphics.newImage("assets/tileset/bricks.png"),
library = love.graphics.newImage("assets/tileset/library.png")
}
tileProperties = {
width = 16,
height = 16,
scale = 1,
tileset = love.graphics.newImage("assets/terrain/tileset.png")
}

View File

@@ -1,20 +1,22 @@
function LevelLoadTiles()
LevelInfo = {}
Tiles = dofile("Mothback/data/tiles.lua")
--[[
on level format:
id = tile identifier
depth = order in the render
force = rendering other tile instead of the one in this position
overlay = render another tile id
overlay = render another tile id or, if multiple tiles {id, id, id,} or
overlay_depth = foreground/background overlay depth
type = collision type
]]
LevelTiles = json.decode(getInput("Mothback/data/levels/"..currLevel..".json"))
LevelInfo.Width = LevelGetWidth()
LevelInfo.Height = LevelGetHeight()
LevelData = dofile("Mothback/data/levels/"..currLevel..".lua")
Tiles = dofile("Mothback/data/tileset/library.lua")
LevelTiles = LevelData.tiles
LevelData.Width = LevelGetWidth()
LevelData.Height = LevelGetHeight()
LevelIndexTiles()
TileCreateObjects()
end
@@ -35,8 +37,8 @@ function LevelIndexTiles()
TileIndex = {}
-- number of tiles in tileset!
local width = tileProperties.tileset:getPixelWidth()/tileProperties.width
local height = tileProperties.tileset:getPixelHeight()/tileProperties.height
local width = LevelData.tileset:getPixelWidth()/tileProperties.width
local height = LevelData.tileset:getPixelHeight()/tileProperties.height
for i = 0, height do
for j = 0, width do
TileIndex[i*width+j+1] = love.graphics.newQuad(
@@ -44,12 +46,12 @@ function LevelIndexTiles()
i*tileProperties.height,
tileProperties.width,
tileProperties.height,
tileProperties.tileset:getDimensions()
LevelData.tileset:getDimensions()
)
end
end
-- init animated tile properties
for _, properties in pairs(Tiles) do
if properties.animation ~= nil then
properties.tileset = love.graphics.newImage("assets/terrain/"..properties.animation..".png")
@@ -75,18 +77,44 @@ function LevelIndexTiles()
image_count = image_count + 1
table.insert(properties.imgs,quad)
end
end
properties.image_count = image_count
end
end
-- instance level tiles according to the properties
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
local id = LevelTiles[i][j]
LevelTiles[i][j] = {}
local tile = LevelTiles[i][j]
tile.id = id
for _, properties in pairs(Tiles) do
if properties.id == tile.id then
if type(properties.overlay) == "table" then
tile.display_overlay = properties.overlay[math.random(#properties.overlay)]
else
tile.display_overlay = properties.overlay
end
if type(properties.force) == "table" then
tile.display = properties.force[math.random(#properties.force)]
else
tile.display = properties.force
end
end
end
end
end
end
function LevelDisplayForeground()
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
if LevelTiles[i][j] ~= 0 then
if LevelTiles[i][j].id ~= 0 then
local depth = TileGetDepth(LevelTiles[i][j])
DrawTile(
@@ -102,9 +130,10 @@ function LevelDisplayForeground()
end
function LevelDisplayBackground()
love.graphics.setColor(0.7,0.7,0.7)
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
if LevelTiles[i][j] ~= 0 then
if LevelTiles[i][j].id ~= 0 then
local depth = TileGetDepth(LevelTiles[i][j])
DrawTile(
@@ -117,28 +146,28 @@ function LevelDisplayBackground()
end
end
end
love.graphics.setColor(1,1,1)
end
function TileGetType(tile_id)
function TileGetType(tile)
for _, properties in ipairs(Tiles) do
if properties.id == tile_id then
if properties.id == tile.id then
return properties.type
end
end
end
function TileGetDepth(tile_id)
function TileGetDepth(tile)
for _, properties in ipairs(Tiles) do
if properties.id == tile_id then
if properties.id == tile.id then
return properties.depth
end
end
end
function TileGetLight(tile_id)
function TileGetLight(tile)
for _, properties in ipairs(Tiles) do
if properties.id == tile_id then
if properties.id == tile.id then
return properties.light
end
end
@@ -165,7 +194,7 @@ function TileCreateObjects()
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
if LevelTiles[i][j] ~= 0 then
if LevelTiles[i][j].id ~= 0 then
local type = TileGetType(LevelTiles[i][j])
local light = TileGetLight(LevelTiles[i][j])
@@ -180,7 +209,7 @@ function TileCreateObjects()
light
)
end
if type == "whole" then
local col = Collision:New(
base_x,
@@ -471,9 +500,10 @@ function AnimateTiles()
end
end
function DrawTile(tile_id,x,y,depth)
function DrawTile(tile,x,y,depth)
for _, properties in pairs(Tiles) do
if tile_id == properties.id then
if tile.id == properties.id then
if properties.animation ~= nil then
if properties.imgs[properties.current_image] ~= nil
and properties.depth == depth
@@ -488,18 +518,20 @@ function DrawTile(tile_id,x,y,depth)
) end
elseif properties.depth == depth then
if properties.force ~= nil then
if properties.force ~= 0 then
love.graphics.draw(
tileProperties.tileset,
TileIndex[properties.force],
LevelData.tileset,
TileIndex[tile.display],
x,
y,
0,
tileProperties.scale,
tileProperties.scale
)
end
else
love.graphics.draw(
tileProperties.tileset,
LevelData.tileset,
TileIndex[properties.id],
x,
y,
@@ -528,8 +560,8 @@ function DrawTile(tile_id,x,y,depth)
end
else
love.graphics.draw(
tileProperties.tileset,
TileIndex[properties.overlay],
LevelData.tileset,
TileIndex[tile.display_overlay],
x,
y,
0,
@@ -539,6 +571,11 @@ function DrawTile(tile_id,x,y,depth)
end
end
end
--[[
love.graphics.setColor(0,0,1)
love.graphics.print(tostring(tile.display),x+16,y)
love.graphics.setColor(1,1,1)
]]
end
end
end

View File

@@ -5,15 +5,19 @@ function CreateDarkness()
return love.graphics.newCanvas(game.width, game.height)
end
function CreateLight(x,y,range)
function CreateLight(x,y,range,lum,flicker)
local o = {}
o.pos = {
x = x,
y = y
}
o.range = range
o.lum = lum or 1
o.flicker_value = flicker or 1
o.flicker = 0
o.dim = 0
o.flicker_speed = flicker_speed or 10
o.flicker_time = 0
table.insert(Lights,o)
return o
end
@@ -23,54 +27,46 @@ function SetDarkness()
love.graphics.rectangle("fill",0,0,game.width,game.height)
end
function DoDarkness()
love.graphics.setColor(0,0,0,1)
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)
light.dim = (light.range+light.flicker)/2
for _, light in pairs(Lights) do
light.flicker_time = light.flicker_time + 1
if light.flicker_time >= light.flicker_speed then
light.flicker_time = light.flicker_time - light.flicker_speed
light.flicker = 0 + math.random(-1,1)
light.flicker = math.min(math.max(light.flicker, -light.flicker_value),light.flicker_value)
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
)]]
love.graphics.circle(
"fill",
light.pos.x - Camera.pos.x,
light.pos.y - Camera.pos.y,
light.range + light.flicker + 1
)
end
]]
love.graphics.setBlendMode("replace")
for _, enty in pairs(LoadedEntities) do
end
love.graphics.setColor(0,0,0,0.5)
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
-- then, light
love.graphics.setColor(0,0,0,0)
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 - light.dim
)
local shades = 200
for i=1, shades do
for _, light in pairs(Lights) do
local luminosity = shades*light.lum/100
love.graphics.setColor(0,0,0,math.min(1,math.max(0,(shades-i-luminosity+1)/(shades-luminosity+1))))
love.graphics.circle(
"fill",
light.pos.x - Camera.pos.x,
light.pos.y - Camera.pos.y,
(light.range + light.flicker)*(shades-i+1)/shades
)
end
end
love.graphics.setBlendMode("alpha")
end

View File

@@ -6,7 +6,6 @@ objects = {
ladders = {}
}
-- level functions
function objects.DrawCollisions()
for _, col in pairs(objects.collisions) do
@@ -24,32 +23,14 @@ function objects.DrawCollisions()
end
-- returns true if theres a collision at that point. also marks collisioned tile as collision true
function isThereCollisionAt(x,y)
function isThereObjectAt(x,y,objectType)
local result = false
for _, col in pairs(objects.collisions) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y then
result = true
col.collision = true
end
end
return result
end
function isTherePlatformAt(x,y)
local result = false
for _, col in pairs(objects.platforms) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y and col.disable ~= true then
result = true
col.collision = true
end
end
return result
end
function isThereLadderAt(x,y)
local result = false
for _, col in pairs(objects.ladders) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y and col.disable ~= true then
for _, col in pairs(objectType) do
if x >= col.from.x
and x <= col.to.x
and y >= col.from.y
and y <= col.to.y
and col.disable ~= true then
result = true
col.collision = true
end
@@ -60,28 +41,13 @@ end
function isThereAnyCollisionAt(x,y)
local result = false
if not result then
for _, col in pairs(objects.collisions) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y then
result = true
col.collision = true
end
end
result = isThereObjectAt(x,y,objects.collisions)
end
if not result then
for _, col in pairs(objects.ladders) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y and col.disable ~= true then
result = true
col.collision = true
end
end
result = isThereObjectAt(x,y,objects.ladders)
end
if not result then
for _, col in pairs(objects.platforms) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y and col.disable ~= true then
result = true
col.collision = true
end
end
result = isThereObjectAt(x,y,objects.platforms)
end
return result
end