New lighting!
This commit is contained in:
@@ -5,11 +5,11 @@ Camera = {
|
||||
}
|
||||
|
||||
function Camera:CenterAt(x,y,cx,cy)
|
||||
self.pos.x = x-self.width/(2*game.scale)
|
||||
self.pos.y = y-self.height/(2*game.scale)
|
||||
cx = cx - self.width
|
||||
cy = cy - self.height
|
||||
self.pos.x = x-self.width/game.scale/2
|
||||
self.pos.y = y-self.height/game.scale/2
|
||||
if not (cx == nil or cy == nil) then
|
||||
cx = cx - self.width
|
||||
cy = cy - self.height
|
||||
if self.pos.x > cx then self.pos.x = cx end
|
||||
if self.pos.y > cy then self.pos.y = cy end
|
||||
if self.pos.x < 0 then self.pos.x = 0 end
|
||||
|
||||
@@ -12,7 +12,8 @@ Arrow = Entity:New(x,y)
|
||||
}
|
||||
o.sprite_offset = {x = 13, y = 1}
|
||||
o.stuck = false
|
||||
|
||||
o.illuminated = true
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
table.insert(LoadedEntities,o)
|
||||
@@ -53,5 +54,6 @@ function Arrow:DoPhysics()
|
||||
self.pos.y = self.pos.y + self.vel.y / 5
|
||||
self.vel.x = 0
|
||||
self.vel.y = 0
|
||||
self.illuminated = false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,10 +19,11 @@ Kupo = Entity:New(x,y)
|
||||
o.bow_frames = 6
|
||||
o.bow_extraframes = 18
|
||||
o.bow_aim_frames = 8
|
||||
|
||||
o.lightRange = o.range
|
||||
o.hostile = false
|
||||
|
||||
o.lightRange = o.range/10
|
||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
@@ -37,9 +38,8 @@ function Kupo:Smart()
|
||||
local distance_y = self.target.y - self.pos.y
|
||||
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
|
||||
local angle = math.atan(distance_y/distance_x)
|
||||
|
||||
self.draw_bow = false
|
||||
if distance <= self.range then
|
||||
self.draw_bow = true
|
||||
|
||||
if distance_x > 0 then
|
||||
self.sprite_flip.x = 1
|
||||
@@ -48,55 +48,57 @@ function Kupo:Smart()
|
||||
self.sprite_flip.x = -1
|
||||
end
|
||||
|
||||
-- fix so it can rotate from 0 to 360
|
||||
if math.deg(self.bow_rotation - angle) < 0 then
|
||||
self.bow_rotation = self.bow_rotation + math.rad(360)
|
||||
end
|
||||
|
||||
-- fix so it can rotate from 360 to 0
|
||||
if math.deg(self.bow_rotation - angle) > 180 then
|
||||
self.bow_rotation = self.bow_rotation - math.rad(360)
|
||||
end
|
||||
|
||||
-- actual rotation
|
||||
if self.bow_rotation < angle then
|
||||
self.bow_rotation = self.bow_rotation + math.rad(2)
|
||||
else
|
||||
self.bow_rotation = self.bow_rotation - math.rad(2)
|
||||
end
|
||||
--set in place
|
||||
if math.abs(math.deg(self.bow_rotation) - math.deg(angle)) < 2 then
|
||||
self.bow_rotation = angle
|
||||
end
|
||||
|
||||
-- holding tight dispersion -- also affets arrows
|
||||
if self.bow_rotation == angle then
|
||||
self.bow_rotation = self.bow_rotation + math.rad(math.random(math.abs(self.bow_frame-self.bow_aim_frames-self.bow_frames)/2))
|
||||
end
|
||||
|
||||
-- AIMING AI
|
||||
|
||||
self.bow_subframe = self.bow_subframe + current_dt
|
||||
|
||||
if self.bow_subframe > self.bow_speed then
|
||||
self.bow_subframe = self.bow_subframe - self.bow_speed
|
||||
if self.bow_frame == 3 then
|
||||
self.bow_aim_frame = self.bow_aim_frame + 1
|
||||
if self.bow_aim_frame > self.bow_aim_frames then
|
||||
self.bow_aim_frame = self.bow_aim_frame - self.bow_aim_frames
|
||||
self.bow_frame = self.bow_frame + 1
|
||||
Arrow:New(self.pos.x,self.pos.y,self.bow_rotation,15)
|
||||
end
|
||||
else
|
||||
self.bow_frame = self.bow_frame + 1
|
||||
if self.hostile == true then
|
||||
self.draw_bow = true
|
||||
-- fix so it can rotate from 0 to 360
|
||||
if math.deg(self.bow_rotation - angle) < 0 then
|
||||
self.bow_rotation = self.bow_rotation + math.rad(360)
|
||||
end
|
||||
if self.bow_frame > self.bow_frames + self.bow_extraframes then
|
||||
self.bow_frame = self.bow_frame - self.bow_frames - self.bow_extraframes
|
||||
|
||||
-- fix so it can rotate from 360 to 0
|
||||
if math.deg(self.bow_rotation - angle) > 180 then
|
||||
self.bow_rotation = self.bow_rotation - math.rad(360)
|
||||
end
|
||||
|
||||
-- actual rotation
|
||||
if self.bow_rotation < angle then
|
||||
self.bow_rotation = self.bow_rotation + math.rad(2)
|
||||
else
|
||||
self.bow_rotation = self.bow_rotation - math.rad(2)
|
||||
end
|
||||
--set in place
|
||||
if math.abs(math.deg(self.bow_rotation) - math.deg(angle)) < 2 then
|
||||
self.bow_rotation = angle
|
||||
end
|
||||
|
||||
-- holding tight dispersion -- also affets arrows
|
||||
if self.bow_rotation == angle then
|
||||
self.bow_rotation = self.bow_rotation + math.rad(math.random(math.abs(self.bow_frame-self.bow_aim_frames-self.bow_frames)/2))
|
||||
end
|
||||
|
||||
-- AIMING AI
|
||||
|
||||
self.bow_subframe = self.bow_subframe + current_dt
|
||||
|
||||
if self.bow_subframe > self.bow_speed then
|
||||
self.bow_subframe = self.bow_subframe - self.bow_speed
|
||||
if self.bow_frame == 3 then
|
||||
self.bow_aim_frame = self.bow_aim_frame + 1
|
||||
if self.bow_aim_frame > self.bow_aim_frames then
|
||||
self.bow_aim_frame = self.bow_aim_frame - self.bow_aim_frames
|
||||
self.bow_frame = self.bow_frame + 1
|
||||
Arrow:New(self.pos.x,self.pos.y,self.bow_rotation,15)
|
||||
end
|
||||
else
|
||||
self.bow_frame = self.bow_frame + 1
|
||||
end
|
||||
if self.bow_frame > self.bow_frames + self.bow_extraframes then
|
||||
self.bow_frame = self.bow_frame - self.bow_frames - self.bow_extraframes
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
self.bow_frame = 6
|
||||
self.draw_bow = true
|
||||
-- rest bow animation
|
||||
if distance_x > 0 then
|
||||
if self.bow_rotation > math.rad(45) then
|
||||
|
||||
@@ -15,6 +15,7 @@ function Entity:New(x,y)
|
||||
o.sprite_scale = {x = 1, y = 1}
|
||||
o.sprite_rotation = math.rad(0)
|
||||
o.sprite_flip = { x = 1, y = 1}
|
||||
o.illuminated = false
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
@@ -113,7 +114,7 @@ function DrawAnimation(animation, x, y, rotate, sx, sy)
|
||||
end
|
||||
|
||||
function Entity:Animate()
|
||||
if game_paused ~= true then
|
||||
if game_paused ~= true and self.anim.path ~= nil then
|
||||
-- try to animate
|
||||
self.anim.subframe = self.anim.subframe + current_dt
|
||||
|
||||
|
||||
@@ -136,6 +136,14 @@ function TileGetDepth(tile_id)
|
||||
end
|
||||
end
|
||||
|
||||
function TileGetLight(tile_id)
|
||||
for _, properties in ipairs(Tiles) do
|
||||
if properties.id == tile_id then
|
||||
return properties.light
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function GridDisplay()
|
||||
for i = 1, #LevelTiles do
|
||||
for j = 1, #LevelTiles[i] do
|
||||
@@ -160,10 +168,19 @@ function TileCreateObjects()
|
||||
if LevelTiles[i][j] ~= 0 then
|
||||
|
||||
local type = TileGetType(LevelTiles[i][j])
|
||||
|
||||
local light = TileGetLight(LevelTiles[i][j])
|
||||
local base_x = tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.height)
|
||||
local base_y = tileProperties.scale * i * tileProperties.height + tileProperties.scale * (levelProperties.offset.y - tileProperties.height)
|
||||
|
||||
|
||||
if light ~= 0 and light ~= nil then
|
||||
CreateLight(
|
||||
base_x + tileProperties.width/2 * tileProperties.scale,
|
||||
base_y + tileProperties.height/2 * tileProperties.scale,
|
||||
light
|
||||
)
|
||||
end
|
||||
|
||||
if type == "whole" then
|
||||
local col = Collision:New(
|
||||
base_x,
|
||||
|
||||
@@ -13,46 +13,67 @@ function CreateLight(x,y,range)
|
||||
}
|
||||
o.range = range
|
||||
o.flicker = 0
|
||||
o.dim = 0
|
||||
table.insert(Lights,o)
|
||||
return o
|
||||
end
|
||||
|
||||
function SetDarkness()
|
||||
love.graphics.setColor(0,0,0,1)
|
||||
love.graphics.rectangle("fill",0,0,game.width,game.height)
|
||||
end
|
||||
|
||||
function DoDarkness()
|
||||
love.graphics.setColor(0,0,0)
|
||||
love.graphics.setColor(0,0,0,0.3)
|
||||
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
|
||||
light.flicker = math.random(-2,2)
|
||||
light.dim = (light.range+light.flicker)/5
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
love.graphics.setBlendMode("replace")
|
||||
-- first, border
|
||||
love.graphics.setColor(1,1,1)
|
||||
for _, light in pairs(Lights) do
|
||||
|
||||
love.graphics.circle(
|
||||
"fill",
|
||||
|
||||
--[[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
|
||||
)]]
|
||||
end
|
||||
for _, enty in pairs(LoadedEntities) do
|
||||
if enty.illuminated == true then
|
||||
enty:Draw()
|
||||
end
|
||||
end
|
||||
love.graphics.setColor(0,0,0,0.5)
|
||||
for _, light in pairs(Lights) do
|
||||
love.graphics.circle(
|
||||
"fill",
|
||||
"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
|
||||
)
|
||||
end
|
||||
love.graphics.setBlendMode("alpha")
|
||||
end
|
||||
@@ -62,4 +83,4 @@ end
|
||||
|
||||
function DrawDarkness()
|
||||
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 0.5, 0.5)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user