New lighting!

This commit is contained in:
lustlion
2021-10-27 11:06:08 +02:00
parent 5e1148f49d
commit 538a1f77f8
11 changed files with 158 additions and 91 deletions

View File

@@ -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

View File

@@ -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