consistent indentation

This commit is contained in:
lustlion 2022-02-26 03:56:53 +01:00
parent 42cf9cfec8
commit 1580dc3463
38 changed files with 2071 additions and 2071 deletions

View File

@ -1,17 +1,17 @@
Animation = {}
function Animation:New(anim_data)
local o = {}
local o = {}
o.path = anim_data.path
o.path = anim_data.path
o.frames = anim_data.frames
o.imgs = anim_data.imgs
o.imgs = anim_data.imgs
o.subframe = 0
o.frame = 1
setmetatable(o, self)
self.__index = self
return o
setmetatable(o, self)
self.__index = self
return o
end
function Animation:ChangeTo(anim_data)
@ -44,20 +44,20 @@ end
-- to linearly animate
function Animation:Animate()
if self.frames[self.frame] ~= 0 then
-- try to animate
self.subframe = self.subframe + current_dt
if self.frames[self.frame] ~= 0 then
-- try to animate
self.subframe = self.subframe + current_dt
if self.subframe > self.frames[self.frame] then
self.subframe = self.subframe - self.frames[self.frame]
self.frame = self.frame + 1
end
if self.subframe > self.frames[self.frame] then
self.subframe = self.subframe - self.frames[self.frame]
self.frame = self.frame + 1
end
-- cycle
if self.frame >= #self.frames+1 then
self.frame = self.frame - #self.frames
end
end
-- cycle
if self.frame >= #self.frames+1 then
self.frame = self.frame - #self.frames
end
end
end
-- to draw the current frame

View File

@ -2,46 +2,46 @@
-- https://love2d.org/wiki/Minimalist_Sound_Manager
-- <3
do
-- will hold the currently playing sources
local sources = {}
-- will hold the currently playing sources
local sources = {}
-- check for sources that finished playing and remove them
-- add to love.update
function love.audio.update()
local remove = {}
for _,s in pairs(sources) do
if not s:isPlaying() then
remove[#remove + 1] = s
end
end
-- check for sources that finished playing and remove them
-- add to love.update
function love.audio.update()
local remove = {}
for _,s in pairs(sources) do
if not s:isPlaying() then
remove[#remove + 1] = s
end
end
for i,s in ipairs(remove) do
sources[s] = nil
end
end
for i,s in ipairs(remove) do
sources[s] = nil
end
end
-- overwrite love.audio.play to create and register source if needed
local play = love.audio.play
function love.audio.play(audio)
local what = audio.path
local how = audio.type
local loop = audio.loop
local src = what
if type(what) ~= "userdata" or not what:typeOf("Source") then
src = love.audio.newSource(what, how)
src:setLooping(loop or false)
end
-- overwrite love.audio.play to create and register source if needed
local play = love.audio.play
function love.audio.play(audio)
local what = audio.path
local how = audio.type
local loop = audio.loop
local src = what
if type(what) ~= "userdata" or not what:typeOf("Source") then
src = love.audio.newSource(what, how)
src:setLooping(loop or false)
end
play(src)
sources[src] = src
return src
end
play(src)
sources[src] = src
return src
end
-- stops a source
local stop = love.audio.stop
function love.audio.stop(src)
if not src then return end
stop(src)
sources[src] = nil
end
-- stops a source
local stop = love.audio.stop
function love.audio.stop(src)
if not src then return end
stop(src)
sources[src] = nil
end
end

View File

@ -1,15 +1,15 @@
Canvas = {class = "Canvas"}
function Canvas:New(name)
local o = {}
o.name = name
o.width = game.width/game.scale
o.height = game.height/game.scale
o.canvas = love.graphics.newCanvas(o.width,o.height)
local o = {}
o.name = name
o.width = game.width/game.scale
o.height = game.height/game.scale
o.canvas = love.graphics.newCanvas(o.width,o.height)
setmetatable(o, self)
setmetatable(o, self)
self.__index = self
return o
return o
end
function Canvas:Recreate()
@ -19,7 +19,7 @@ end
function Canvas:Reset()
love.graphics.setCanvas(self.canvas)
love.graphics.setBlendMode("replace")
love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0)
love.graphics.rectangle(
"fill",
@ -39,11 +39,11 @@ end
function Canvas:DrawingEnd()
love.graphics.setCanvas()
love.graphics.setBlendMode("alpha")
love.graphics.setColor(1,1,1,1)
love.graphics.setColor(1,1,1,1)
end
function Canvas:Draw()
love.graphics.draw(self.canvas)
love.graphics.draw(self.canvas)
end
require "code/canvasses/darkness"

View File

@ -2,7 +2,7 @@ Canvas.Darkness = Canvas:New("Darkness")
function Canvas.Darkness:Reset()
love.graphics.setCanvas(Canvas.Darkness.canvas)
love.graphics.setBlendMode("replace")
love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0.95)
love.graphics.rectangle(
"fill",

View File

@ -8,22 +8,22 @@ LoadedObjects.Hazards = {}
--[[
Collision
[bool flag] isDisabled
[bool flag] isDisabled
> if true used for collision
[bool flag] isColliding
[bool flag] isColliding
> if true, this collision is colliding
[vec2 position] from - x, y
> top right corner of collision box
[vec2 position] from - x, y
> top right corner of collision box
[vec2 position] to - x, y
[vec2 position] to - x, y
> bottom left corner of collision box
[int property] width
[int property] width
> width of collision box
[int property] height
[int property] height
> height of collision box
--]]

View File

@ -11,28 +11,28 @@ function DebugUI()
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(--[["CPUtime: "..checkCPUTime("total")..", CPU: "..(math.floor(checkCPUTime("get")*10000)/100).."%,]] "memoryUsage: "..memoryUsage.."kB", 10*textScale, 20*textScale, 0, textScale)
love.graphics.setColor(1,1,1)
-- lots of variables
love.graphics.print("LoadedObjects",10*textScale,40*textScale, 0, textScale)
love.graphics.setColor(1,1,1)
-- lots of variables
love.graphics.print("LoadedObjects",10*textScale,40*textScale, 0, textScale)
local i = 1
for k, v in pairs(LoadedObjects) do
if type(v) == "table" then
love.graphics.print("<"..k.."> ".. #v,10*textScale,(40+(10*i))*textScale, 0, textScale)
love.graphics.print("<"..k.."> ".. #v,10*textScale,(40+(10*i))*textScale, 0, textScale)
i = i + 1
end
end
-- player isOnGroundCheck
love.graphics.setColor(1,0,0)
-- player isOnGroundCheck
love.graphics.setColor(1,0,0)
end
function DebugColisions()
love.graphics.setScale(game.scale)
-- DrawColisionTable()
LoadedObjects.DrawCollisions()
love.graphics.setScale(game.scale)
-- DrawColisionTable()
LoadedObjects.DrawCollisions()
end
function DebugEntities()
love.graphics.setScale(game.scale)
love.graphics.setScale(game.scale)
for _, particle in pairs(LoadedParticles) do
particle:Debug()
end

View File

@ -5,61 +5,61 @@ DemoAction = nil -- Table of actions
CurrentDemoFrame = nil
function Demo:Draw()
if DemoRecording then
love.graphics.setColor(1,0,0,1)
elseif DemoPlayback then
love.graphics.setColor(0,0,1,1)
end
love.graphics.rectangle("line",0,0,game.width ,game.height)
if DemoRecording then
love.graphics.setColor(1,0,0,1)
elseif DemoPlayback then
love.graphics.setColor(0,0,1,1)
end
love.graphics.rectangle("line",0,0,game.width ,game.height)
end
function Demo:PlaybackStart()
DemoPlayback = true
CurrentDemoFrame = 0
dofile("demos/play_demo.lua")
DemoPlayback = true
CurrentDemoFrame = 0
dofile("demos/play_demo.lua")
end
function Demo:PlaybackEnd()
DemoPlayback = false
DemoAction = nil
DemoPlayback = false
DemoAction = nil
end
function Demo:RecordAction(action)
if DemoRecording
and action ~= nil
then
DemoFile:write("\""..action.."\",")
end
if DemoRecording
and action ~= nil
then
DemoFile:write("\""..action.."\",")
end
end
function Demo:RecordStart()
-- Make demo stuff
os.execute( "mkdir \"./demos\"" )
DemoFile = io.open("demos/play_demo.lua", "w+")
--DemoFile = io.open("demo/mothbackDemo_"..os.date("%Y-%m-%d_%H-%M-%S")..".lua", "w+")
DemoFile:write("main_Player.pos.x = "..main_Player.pos.x.."\n")
DemoFile:write("main_Player.pos.y = "..main_Player.pos.y.."\n")
DemoFile:write("DemoAction = {\n")
DemoRecording = true
CurrentDemoFrame = 1
-- Make demo stuff
os.execute( "mkdir \"./demos\"" )
DemoFile = io.open("demos/play_demo.lua", "w+")
--DemoFile = io.open("demo/mothbackDemo_"..os.date("%Y-%m-%d_%H-%M-%S")..".lua", "w+")
DemoFile:write("main_Player.pos.x = "..main_Player.pos.x.."\n")
DemoFile:write("main_Player.pos.y = "..main_Player.pos.y.."\n")
DemoFile:write("DemoAction = {\n")
DemoRecording = true
CurrentDemoFrame = 1
end
function Demo:RecordEnd()
DemoFile:write("}\n}")
DemoFile:close()
DemoFile = nil
DemoRecording = false
DemoFile:write("}\n}")
DemoFile:close()
DemoFile = nil
DemoRecording = false
end
function Demo:Step()
if DemoRecording then
if CurrentDemoFrame == 1 then
DemoFile:write("\t{")
else
DemoFile:write("},\n\t{")
end
elseif DemoPlayback then
if DemoAction[CurrentDemoFrame + 1] == nil then Demo:PlaybackEnd() end
end
CurrentDemoFrame = CurrentDemoFrame + 1
if DemoRecording then
if CurrentDemoFrame == 1 then
DemoFile:write("\t{")
else
DemoFile:write("},\n\t{")
end
elseif DemoPlayback then
if DemoAction[CurrentDemoFrame + 1] == nil then Demo:PlaybackEnd() end
end
CurrentDemoFrame = CurrentDemoFrame + 1
end

View File

@ -1,6 +1,6 @@
function love.graphics.setScale(scale_x, scale_y)
local scale_x = scale_x or 1
local scale_y = scale_y or scale_x
love.graphics.origin()
love.graphics.scale(scale_x,scale_y)
local scale_x = scale_x or 1
local scale_y = scale_y or scale_x
love.graphics.origin()
love.graphics.scale(scale_x,scale_y)
end

View File

@ -1,65 +1,65 @@
function EditorStep()
palette = palette or false
AnimateTiles()
palette = palette or false
AnimateTiles()
if Keybind:CheckPressed(Keybind.editor.palette) then
if palette then
palette = false
palette_scroll_x = nil
palette_scroll_y = nil
else
palette = true
palette_scroll_x = 0
palette_scroll_y = 0
end
end
if love.keyboard.isDown('a',"left") then
Camera.pos.x = Camera.pos.x - 3*game.scale
end
if love.keyboard.isDown('d',"right") then
Camera.pos.x = Camera.pos.x + 3*game.scale
end
if love.keyboard.isDown("up", "w") then
Camera.pos.y = Camera.pos.y - 3*game.scale
end
if Keybind:CheckPressed(Keybind.editor.palette) then
if palette then
palette = false
palette_scroll_x = nil
palette_scroll_y = nil
else
palette = true
palette_scroll_x = 0
palette_scroll_y = 0
end
end
if love.keyboard.isDown('a',"left") then
Camera.pos.x = Camera.pos.x - 3*game.scale
end
if love.keyboard.isDown('d',"right") then
Camera.pos.x = Camera.pos.x + 3*game.scale
end
if love.keyboard.isDown("up", "w") then
Camera.pos.y = Camera.pos.y - 3*game.scale
end
if love.keyboard.isDown("down", "s") then
Camera.pos.y = Camera.pos.y + 3*game.scale
end
if palette then
if Keybind:CheckPressed(Keybind.debug.debug) then
local next = false
local export = nil
for k, v in pairs(tileset) do
if export == nil then
export = v
end
if next then
LevelData.tileset = v
next = false
break
end
if palette then
if Keybind:CheckPressed(Keybind.debug.debug) then
local next = false
local export = nil
for k, v in pairs(tileset) do
if export == nil then
export = v
end
if next then
LevelData.tileset = v
next = false
break
end
if v == LevelData.tileset then
next = true
end
end
if next then
LevelData.tileset = export
end
LevelGetTileData()
LevelIndexTiles()
end
end
if v == LevelData.tileset then
next = true
end
end
if next then
LevelData.tileset = export
end
LevelGetTileData()
LevelIndexTiles()
end
end
if Keybind:CheckPressed(Keybind.debug.reload) then
ExportLevel("test")
end
if Keybind:CheckPressed(Keybind.debug.reload) then
ExportLevel("test")
end
if Keybind:CheckPressed(Keybind.debug.editor) then
editor_mode = false
TileCreateObjects()
end
if Keybind:CheckPressed(Keybind.debug.editor) then
editor_mode = false
TileCreateObjects()
end
end
function EditorScroll(y)
@ -76,163 +76,163 @@ function EditorScroll(y)
end
function EditorDraw()
GameworldDrawPrepare()
GameworldDrawBackground()
GridDisplay()
GameworldDrawForeground()
GameworldDrawEnd()
EditorDoEdit()
GameworldDrawPrepare()
GameworldDrawBackground()
GridDisplay()
GameworldDrawForeground()
GameworldDrawEnd()
EditorDoEdit()
DrawSelectingPaletteTile()
if palette then
EditorDoPalette()
end
DrawSelectingPaletteTile()
if palette then
EditorDoPalette()
end
end
function EditorDoEdit()
local mouse_x = love.mouse.getX()
local mouse_y = love.mouse.getY()
local horizontal = 1+math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width))
local vertical = 1+math.floor(((mouse_y/game.scale) / tileProperties.height) + (Camera.pos.y / tileProperties.height))
local expand_h = 0
local expand_v = 0
local LevelWidth = LevelGetTileWidth()
local LevelHeight = LevelGetTileHeight()
local mouse_x = love.mouse.getX()
local mouse_y = love.mouse.getY()
local horizontal = 1+math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width))
local vertical = 1+math.floor(((mouse_y/game.scale) / tileProperties.height) + (Camera.pos.y / tileProperties.height))
local expand_h = 0
local expand_v = 0
local LevelWidth = LevelGetTileWidth()
local LevelHeight = LevelGetTileHeight()
if horizontal > LevelWidth then
expand_h = horizontal-LevelWidth
elseif horizontal < 0 then
expand_h = horizontal
if horizontal > LevelWidth then
expand_h = horizontal-LevelWidth
elseif horizontal < 0 then
expand_h = horizontal
end
if vertical > LevelHeight then
expand_v = vertical-LevelHeight
expand_v = vertical-LevelHeight
elseif vertical < 0 then
expand_v = vertical
expand_v = vertical
end
love.graphics.print("> " .. horizontal .. ", " .. vertical .. "; " .. math.floor(mouse_x / game.scale + Camera.pos.x) .. ", " .. math.floor(mouse_y / game.scale + Camera.pos.y))
love.graphics.print("> " .. LevelWidth .. "(" .. expand_h .. "), " .. LevelHeight .. "(".. expand_v .. ")", 0, 10)
love.graphics.print("> " .. horizontal .. ", " .. vertical .. "; " .. math.floor(mouse_x / game.scale + Camera.pos.x) .. ", " .. math.floor(mouse_y / game.scale + Camera.pos.y))
love.graphics.print("> " .. LevelWidth .. "(" .. expand_h .. "), " .. LevelHeight .. "(".. expand_v .. ")", 0, 10)
if not palette then
if LevelTiles[vertical] ~= nil
and LevelTiles[vertical][horizontal] ~= nil
and love.keyboard.isDown("lshift") ~= true
and love.keyboard.isDown("lctrl") ~= true
then
if Keybind:CheckDown(Keybind.generic.lclick)
and selecting_tile ~= nil
then
SetTile(vertical,horizontal,selecting_tile)
elseif Keybind:CheckDown(Keybind.generic.rclick) then
SetTile(vertical,horizontal,0)
end
LevelReloadTiles()
if not palette then
if LevelTiles[vertical] ~= nil
and LevelTiles[vertical][horizontal] ~= nil
and love.keyboard.isDown("lshift") ~= true
and love.keyboard.isDown("lctrl") ~= true
then
if Keybind:CheckDown(Keybind.generic.lclick)
and selecting_tile ~= nil
then
SetTile(vertical,horizontal,selecting_tile)
elseif Keybind:CheckDown(Keybind.generic.rclick) then
SetTile(vertical,horizontal,0)
end
LevelReloadTiles()
elseif Keybind:CheckPressed(Keybind.generic.lshift) then
LevelExpandCanvas(math.sign(expand_h),math.sign(expand_v))
LevelReloadTiles()
elseif Keybind:CheckPressed(Keybind.generic.lctrl) then
LevelReduceCanvas(math.sign(expand_h),math.sign(expand_v))
LevelReloadTiles()
end
end
elseif Keybind:CheckPressed(Keybind.generic.lshift) then
LevelExpandCanvas(math.sign(expand_h),math.sign(expand_v))
LevelReloadTiles()
elseif Keybind:CheckPressed(Keybind.generic.lctrl) then
LevelReduceCanvas(math.sign(expand_h),math.sign(expand_v))
LevelReloadTiles()
end
end
end
function DrawSelectingPaletteTile()
if selecting_tile ~= nil and selecting_tile ~= 0 then
if selecting_tile ~= nil and selecting_tile ~= 0 then
local mouse_x = love.mouse.getX()
local mouse_y = love.mouse.getY()
local horizontal = math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width))
local vertical = math.floor(((mouse_y/game.scale) / tileProperties.height) + (Camera.pos.y / tileProperties.height))
local draw_x = tileProperties.width * horizontal - Camera.pos.x
local draw_y = tileProperties.height * vertical - Camera.pos.y
local mouse_x = love.mouse.getX()
local mouse_y = love.mouse.getY()
local horizontal = math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width))
local vertical = math.floor(((mouse_y/game.scale) / tileProperties.height) + (Camera.pos.y / tileProperties.height))
local draw_x = tileProperties.width * horizontal - Camera.pos.x
local draw_y = tileProperties.height * vertical - Camera.pos.y
love.graphics.draw(
LevelData.tileset,
TileIndex[selecting_tile],
draw_x,
draw_y
)
end
love.graphics.draw(
LevelData.tileset,
TileIndex[selecting_tile],
draw_x,
draw_y
)
end
end
function EditorDoPalette()
local width = LevelData.tileset:getPixelWidth()/tileProperties.width
local width = LevelData.tileset:getPixelWidth()/tileProperties.width
local height = LevelData.tileset:getPixelHeight()/tileProperties.height
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle(
"fill",
(palette_scroll_x + 1) * (tileProperties.width+1),
(palette_scroll_y + 1) * (tileProperties.height+1),
1 + LevelData.tileset:getPixelWidth() * ((tileProperties.width+1) / tileProperties.width),
1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height)
)
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle(
"fill",
(palette_scroll_x + 1) * (tileProperties.width+1),
(palette_scroll_y + 1) * (tileProperties.height+1),
1 + LevelData.tileset:getPixelWidth() * ((tileProperties.width+1) / tileProperties.width),
1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height)
)
love.graphics.setColor(1,1,1,1)
local position_x = 1
local position_y = 1
for i = 1, #TileIndex-width-1 do
love.graphics.setColor(1,1,1,1)
local position_x = 1
local position_y = 1
for i = 1, #TileIndex-width-1 do
local tile_x = (palette_scroll_x + position_x) * (tileProperties.width+1)
local tile_y = (palette_scroll_y + position_y) * (tileProperties.height+1)
local tile_x = (palette_scroll_x + position_x) * (tileProperties.width+1)
local tile_y = (palette_scroll_y + position_y) * (tileProperties.height+1)
love.graphics.draw(
LevelData.tileset,
TileIndex[i],
tile_x,
tile_y,
0,
1,
1
)
if Keybind:CheckDown(Keybind.generic.lclick) then
local mouse_x = love.mouse.getX()
local mouse_y = love.mouse.getY()
love.graphics.draw(
LevelData.tileset,
TileIndex[i],
tile_x,
tile_y,
0,
1,
1
)
if Keybind:CheckDown(Keybind.generic.lclick) then
local mouse_x = love.mouse.getX()
local mouse_y = love.mouse.getY()
if mouse_x > (tile_x) * game.scale
and mouse_x < (tile_x + tileProperties.width) * game.scale
and mouse_y > (tile_y) * game.scale
and mouse_y < (tile_y + tileProperties.height) * game.scale
then
selecting_tile = position_x + ((position_y-1) * width)
if mouse_x > (tile_x) * game.scale
and mouse_x < (tile_x + tileProperties.width) * game.scale
and mouse_y > (tile_y) * game.scale
and mouse_y < (tile_y + tileProperties.height) * game.scale
then
selecting_tile = position_x + ((position_y-1) * width)
love.graphics.print(selecting_tile .. " | " .. tile_x .. ", " .. tile_y, 0, 20)
end
end
love.graphics.print(selecting_tile .. " | " .. tile_x .. ", " .. tile_y, 0, 20)
end
end
if Keybind:CheckDown(Keybind.generic.rclick) then
selecting_tile = nil
end
if Keybind:CheckDown(Keybind.generic.rclick) then
selecting_tile = nil
end
if selecting_tile ~= nil and selecting_tile ~= 0 and i == selecting_tile then
love.graphics.setColor(1,0,1,1)
if selecting_tile ~= nil and selecting_tile ~= 0 and i == selecting_tile then
love.graphics.setColor(1,0,1,1)
love.graphics.rectangle(
"line",
tile_x,
tile_x,
tile_y,
tileProperties.width,
tileProperties.height
)
love.graphics.setColor(1,1,1,1)
end
love.graphics.setColor(1,1,1,1)
end
position_x = position_x + 1
position_x = position_x + 1
if position_x > width then
position_x = position_x - width
position_y = position_y + 1
end
if position_x > width then
position_x = position_x - width
position_y = position_y + 1
end
end
love.graphics.rectangle(
"line",
(palette_scroll_x + 1) * (tileProperties.width+1),
(palette_scroll_y + 1) * (tileProperties.height+1),
1 + LevelData.tileset:getPixelWidth() * ((tileProperties.width+1) / tileProperties.width),
1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height)
love.graphics.rectangle(
"line",
(palette_scroll_x + 1) * (tileProperties.width+1),
(palette_scroll_y + 1) * (tileProperties.height+1),
1 + LevelData.tileset:getPixelWidth() * ((tileProperties.width+1) / tileProperties.width),
1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height)
)
end

View File

@ -1,56 +1,56 @@
Arrow = Entity:New(x,y)
function Arrow:New(x,y,rotation,speed)
local o = Entity:New(x,y)
function Arrow:New(x,y,rotation,speed)
local o = Entity:New(x,y)
o.type = "arrow"
o.type = "arrow"
o.pos = {x = x, y = y}
o.speed = speed or 10
o.sprite_rotation = rotation or 0
o.vel = {
x = o.speed * math.cos(o.sprite_rotation),
y = o.speed * math.sin(o.sprite_rotation)
}
o.pos = {x = x, y = y}
o.speed = speed or 10
o.sprite_rotation = rotation or 0
o.vel = {
x = o.speed * math.cos(o.sprite_rotation),
y = o.speed * math.sin(o.sprite_rotation)
}
o.sprite_offset = {x = 13, y = 1}
o.stuck = false
o.illuminated = true
o.stuck = false
o.illuminated = true
-- animations
o.body = Animation:New(animation.kupo.arrow)
-- animations
o.body = Animation:New(animation.kupo.arrow)
o.boxCollision = {
from = {x = -0.5, y = -0.5}, --gameworld pixels
to = {x = 0.5, y = 0.5} -- gameworld pixels
}
o.boxCollision = {
from = {x = -0.5, y = -0.5}, --gameworld pixels
to = {x = 0.5, y = 0.5} -- gameworld pixels
}
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
setmetatable(o, self)
self.__index = self
return o
end
function Arrow:DrawBackground()
self:Draw(self.body)
self:Draw(self.body)
end
function Arrow:DoPhysics()
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x
else
self.stuck = true
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
self.pos.y = self.pos.y + self.vel.y
else
self.stuck = true
end
if self.stuck then
self.pos.x = self.pos.x + self.vel.x * (2/3)
self.pos.y = self.pos.y + self.vel.y * (2/3)
self.vel.x = 0
self.vel.y = 0
end
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x
else
self.stuck = true
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
self.pos.y = self.pos.y + self.vel.y
else
self.stuck = true
end
if self.stuck then
self.pos.x = self.pos.x + self.vel.x * (2/3)
self.pos.y = self.pos.y + self.vel.y * (2/3)
self.vel.x = 0
self.vel.y = 0
end
end

View File

@ -1,112 +1,112 @@
CursedBook = Entity:New(x,y)
function CursedBook:New(x,y)
local o = Entity:New(x,y)
function CursedBook:New(x,y)
local o = Entity:New(x,y)
o.type = "cursed_book"
-- behaviour
o.pos = {x = x, y = y}
o.speed = 0.01
o.range = 20
o.target = {x = x, y = y}
o.type = "cursed_book"
-- behaviour
o.pos = {x = x, y = y}
o.speed = 0.01
o.range = 20
o.target = {x = x, y = y}
o.status = 0
-- 0 - sleep
-- 1 - getting up
-- 2 - flying
-- 3 - attack windup
-- 4 - attack
o.spawn_range = 100
o.attack_range = 50
o.status = 0
-- 0 - sleep
-- 1 - getting up
-- 2 - flying
-- 3 - attack windup
-- 4 - attack
o.spawn_range = 100
o.attack_range = 50
-- animations
o.body = Animation:New(animation.cursed_book.spawn)
o.sprite_tint = {0.7,0.7,0.7}
o:centerOffset(o.body)
o:getBoundingBox(o.body)
-- animations
o.body = Animation:New(animation.cursed_book.spawn)
o.sprite_tint = {0.7,0.7,0.7}
o:centerOffset(o.body)
o:getBoundingBox(o.body)
-- light
o.light_range = 500
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
-- light
o.light_range = 500
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
setmetatable(o, self)
self.__index = self
return o
end
function CursedBook:Smart()
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if self.status == 0 then
if distance < self.spawn_range then
self.status = 1
end
elseif self.status == -1 then
if distance < self.range then
self.vel.x = 0
self.vel.y = 0
else
self.vel.x = math.cos(angle)*self.speed*distance
self.vel.y = math.sin(angle)*self.speed*distance
end
elseif self.status == 2 then
if distance < self.attack_range then
self.status = 3
end
elseif self.status == 4 then
if self.status == 0 then
if distance < self.spawn_range then
self.status = 1
end
elseif self.status == -1 then
if distance < self.range then
self.vel.x = 0
self.vel.y = 0
else
self.vel.x = math.cos(angle)*self.speed*distance
self.vel.y = math.sin(angle)*self.speed*distance
end
elseif self.status == 2 then
if distance < self.attack_range then
self.status = 3
end
elseif self.status == 4 then
end
end
end
function CursedBook:HandleAnimation()
if self.status == 1 then
if self.body.path == "assets/entities/cursed_book/spawn" then
self.body.speed = 1/3
local tint = 0.7 + 0.3 * (self.body.frame-1)/self.body.frames
self.sprite_tint = {tint,tint,tint}
if self.body.frame == self.body.frames then
self.status = 2
self.body = self.body:ChangeTo(animation.cursed_book.flying)
self.sprite_tint = {1,1,1}
--self:getBoundingBox(self.body,2,2,-2,-2)
self:centerOffset(self.body)
end
end
elseif self.status == 3 then
if self.body.path == "assets/entities/cursed_book/flying" then
self.body = self.body:ChangeTo(animation.cursed_book.attack_transition)
self.body.speed = 1/3
self:centerOffset(self.body)
if self.body.frame == self.body.frames then
self.status = 4
self.body = self.body:ChangeTo(animation.cursed_book.attack_loop)
self:centerOffset(self.body)
end
end
end
self.body:Animate()
self:Draw(self.body)
if self.status == 1 then
if self.body.path == "assets/entities/cursed_book/spawn" then
self.body.speed = 1/3
local tint = 0.7 + 0.3 * (self.body.frame-1)/self.body.frames
self.sprite_tint = {tint,tint,tint}
if self.body.frame == self.body.frames then
self.status = 2
self.body = self.body:ChangeTo(animation.cursed_book.flying)
self.sprite_tint = {1,1,1}
--self:getBoundingBox(self.body,2,2,-2,-2)
self:centerOffset(self.body)
end
end
elseif self.status == 3 then
if self.body.path == "assets/entities/cursed_book/flying" then
self.body = self.body:ChangeTo(animation.cursed_book.attack_transition)
self.body.speed = 1/3
self:centerOffset(self.body)
if self.body.frame == self.body.frames then
self.status = 4
self.body = self.body:ChangeTo(animation.cursed_book.attack_loop)
self:centerOffset(self.body)
end
end
end
self.body:Animate()
self:Draw(self.body)
end
function CursedBook:DoPhysics()
if self.isFlying then
local random_x = math.random(-4, 4)/100
local random_y = math.random(-4, 4)/100
self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y
end
-- move
if self.isFlying then
local random_x = math.random(-4, 4)/100
local random_y = math.random(-4, 4)/100
self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y
end
-- move
self:CollisionMove()
self:LightAdjust()
self:CollisionMove()
self:LightAdjust()
end
function CursedBook:Debug()
@ -115,5 +115,5 @@ function CursedBook:Debug()
love.graphics.circle("line", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, self.spawn_range)
love.graphics.setColor(1,0,0)
love.graphics.circle("line", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, self.attack_range)
Entity.Debug(self)
Entity.Debug(self)
end

View File

@ -1,33 +1,33 @@
Decoration = Entity:New(x,y)
function Decoration:New(x,y,animation,lightRange)
local o = Entity:New(x,y)
local o = Entity:New(x,y)
o.type = "decoration"
o.type = "decoration"
o.pos = {x = x, y = y}
o.pos = {x = x, y = y}
-- animations
o.body = Animation:New(animation)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
-- animations
o.body = Animation:New(animation)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
if lightRange ~= nil then
o.lightRange = lightRange
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
end
if lightRange ~= nil then
o.lightRange = lightRange
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
end
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
setmetatable(o, self)
self.__index = self
return o
end
function Decoration:HandleAnimation()
self.body:Animate()
self:Draw(self.body)
self.body:Animate()
self:Draw(self.body)
end
function Decoration:DoPhysics()

View File

@ -1,115 +1,115 @@
Fairy = Entity:New(x,y)
function Fairy:New(x,y)
local o = Entity:New(x,y)
function Fairy:New(x,y)
local o = Entity:New(x,y)
o.type = "fairy"
o.type = "fairy"
-- behaviour
o.pos = {x = x, y = y}
o.speed = 1.4
o.range = 20
o.vision_range = 120
o.target = {x = x, y = y}
o.hover_distance = 60
-- behaviour
o.pos = {x = x, y = y}
o.speed = 1.4
o.range = 20
o.vision_range = 120
o.target = {x = x, y = y}
o.hover_distance = 60
-- animations
o.body = Animation:New(animation.fairy.flying)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
-- animations
o.body = Animation:New(animation.fairy.flying)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
-- light
o.light_range = 80
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,nil,HEX2RGB("#fed100"))
-- light
o.light_range = 80
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,nil,HEX2RGB("#fed100"))
-- timer
o.particle_timer = 0
o.particle_time = 5
-- timer
o.particle_timer = 0
o.particle_time = 5
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
setmetatable(o, self)
self.__index = self
return o
end
function Fairy:Smart()
if self:CheckVisionLine(main_Player,self.vision_range) then
if self:CheckVisionLine(main_Player,self.vision_range) then
self.target.x = main_Player.pos.x + main_Player.target_offset.x
self.target.y = main_Player.pos.y + main_Player.target_offset.y
self.target.x = main_Player.pos.x + main_Player.target_offset.x
self.target.y = main_Player.pos.y + main_Player.target_offset.y
local below = 1
while not isThereObjectAt(
self.target.x,
self.target.y + below * game.scale,
LoadedObjects.Collisions
) do
below = below + 1
if below >= self.hover_distance then break end
end
local top = 1
while not isThereObjectAt(
self.target.x,
self.target.y - top * game.scale,
LoadedObjects.Collisions
) do
top = top + 1
if top >= self.hover_distance then break end
end
self.target.y = self.target.y - top + below
end
local below = 1
while not isThereObjectAt(
self.target.x,
self.target.y + below * game.scale,
LoadedObjects.Collisions
) do
below = below + 1
if below >= self.hover_distance then break end
end
local top = 1
while not isThereObjectAt(
self.target.x,
self.target.y - top * game.scale,
LoadedObjects.Collisions
) do
top = top + 1
if top >= self.hover_distance then break end
end
self.target.y = self.target.y - top + below
end
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if distance < self.range then
self.vel.x = self.vel.x * 0.9
self.vel.y = self.vel.y * 0.9
else
self.vel.x = math.cos(angle)*self.speed
self.vel.y = math.sin(angle)*self.speed
end
self.particle_timer = self.particle_timer + 1
if self.particle_timer >= self.particle_time then
self.particle_timer = 0
if distance < self.range then
self.vel.x = self.vel.x * 0.9
self.vel.y = self.vel.y * 0.9
else
self.vel.x = math.cos(angle)*self.speed
self.vel.y = math.sin(angle)*self.speed
end
self.particle_timer = self.particle_timer + 1
if self.particle_timer >= self.particle_time then
self.particle_timer = 0
local particle_data = {
animation = animation.particle.simple,
sprite_tint = HEX2RGB("#fed100"),
direction = angle-math.rad(180+math.random(60)-30),
speed = 0.8*(distance/50),
speed_increase = -0.01,
}
Particle:New(self.pos.x,self.pos.y,particle_data)
end
local particle_data = {
animation = animation.particle.simple,
sprite_tint = HEX2RGB("#fed100"),
direction = angle-math.rad(180+math.random(60)-30),
speed = 0.8*(distance/50),
speed_increase = -0.01,
}
Particle:New(self.pos.x,self.pos.y,particle_data)
end
end
function Fairy:HandleAnimation()
self.body:Animate()
--if self:isCollidingWith(main_Player) then self.sprite_tint = {1,0,0} else self.sprite_tint = {1,1,1} end
self:Draw(self.body)
self.body:Animate()
--if self:isCollidingWith(main_Player) then self.sprite_tint = {1,0,0} else self.sprite_tint = {1,1,1} end
self:Draw(self.body)
end
function Fairy:DoPhysics()
local random_x = math.random(-4, 4)/10
local random_y = math.random(-4, 4)/10
local random_x = math.random(-4, 4)/10
local random_y = math.random(-4, 4)/10
self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y
self.vel.x = self.vel.x + random_x
self.vel.y = self.vel.y + random_y
self:CollisionMove()
self.vel.x = 0
self.vel.y = 0
self:CollisionMove()
self.vel.x = 0
self.vel.y = 0
self:LightAdjust()
self:LightAdjust()
end
function Fairy:Debug()
Entity.Debug(self)
self:CheckVisionLineDebug(main_Player,self.vision_range)
Entity.Debug(self)
self:CheckVisionLineDebug(main_Player,self.vision_range)
end

View File

@ -1,40 +1,40 @@
HookAnchor = Entity:New(x,y)
function HookAnchor:New(x,y,hookDistance)
local o = Entity:New(x,y)
local o = Entity:New(x,y)
o.type = "hook_anchor"
o.type = "hook_anchor"
o.pos = {x = x, y = y}
o.hookDistance = hookDistance or 100
-- animations
o.body = Animation:New(animation.fairy.flying)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
o.pos = {x = x, y = y}
o.hookDistance = hookDistance or 100
-- animations
o.body = Animation:New(animation.fairy.flying)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
setmetatable(o, self)
self.__index = self
return o
end
function HookAnchor:HandleAnimation()
self.body:Animate()
self:Draw(self.body)
self.body:Animate()
self:Draw(self.body)
end
function HookAnchor:DrawBackground()
Entity.DrawBackground(self)
love.graphics.setColor(1,1,1,0)
love.graphics.circle(
"fill",
-Camera.pos.x + self.pos.x,
-Camera.pos.y + self.pos.y,
self.hookDistance
)
Entity.DrawBackground(self)
love.graphics.setColor(1,1,1,0)
love.graphics.circle(
"fill",
-Camera.pos.x + self.pos.x,
-Camera.pos.y + self.pos.y,
self.hookDistance
)
end
function HookAnchor:DoPhysics()
@ -42,5 +42,5 @@ end
function Fairy:Debug()
Entity.Debug(self)
Entity.Debug(self)
end

View File

@ -1,161 +1,161 @@
Kupo = Entity:New(x,y)
function Kupo:New(x,y)
local o = Entity:New(x,y)
function Kupo:New(x,y)
local o = Entity:New(x,y)
o.type = "kupo"
o.type = "kupo"
o.pos = {x = x, y = y}
o.speed = 20
o.range = 200
o.target = {x = x, y = y}
o.pos = {x = x, y = y}
o.speed = 20
o.range = 200
o.target = {x = x, y = y}
o.sprite_offset = {x = 8, y = 5}
-- animations
o.body = Animation:New(animation.kupo.body)
o.bow = Animation:New(animation.kupo.bow)
-- animations
o.body = Animation:New(animation.kupo.body)
o.bow = Animation:New(animation.kupo.bow)
-- bow
o.bow_flip = 1
o.bow_rotation = 0
o.bow_frame = 1
o.bow_subframe = 1
o.bow_aim_frame = 0
o.bow_speed = 1/10
o.bow_frames = 6
o.bow_extraframes = 18
-- bow
o.bow_flip = 1
o.bow_rotation = 0
o.bow_frame = 1
o.bow_subframe = 1
o.bow_aim_frame = 0
o.bow_speed = 1/10
o.bow_frames = 6
o.bow_extraframes = 18
o.bow_aim_frames = 8
o.hostile = true
o.hostile = true
o.lightRange = o.range/2
o.lightRange = o.range/2
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
setmetatable(o, self)
self.__index = self
return o
end
function Kupo:Smart()
self.light.pos.x = self.pos.x-self.target_offset.x
self.light.pos.y = self.pos.y-self.target_offset.y
self.light.pos.x = self.pos.x-self.target_offset.x
self.light.pos.y = self.pos.y-self.target_offset.y
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local angle = GetAngleFromVector(distance_x,distance_y)
self.draw_bow = false
if distance <= self.range then
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
self.target.x = main_Player.pos.x - main_Player.target_offset.x
self.target.y = main_Player.pos.y - main_Player.target_offset.y
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local angle = GetAngleFromVector(distance_x,distance_y)
self.draw_bow = false
if distance <= self.range then
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
-- 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
-- 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
-- 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 affects arrows
if self.bow_rotation == angle then
self.bow_rotation = self.bow_rotation + math.rad(math.random(math.abs(math.floor(self.bow_frame-self.bow_aim_frames-self.bow_frames)/2)))
end
-- holding tight dispersion -- also affects arrows
if self.bow_rotation == angle then
self.bow_rotation = self.bow_rotation + math.rad(math.random(math.abs(math.floor(self.bow_frame-self.bow_aim_frames-self.bow_frames)/2)))
end
-- AIMING AI
-- AIMING AI
self.bow_subframe = self.bow_subframe + current_dt
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,10)
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
-- rest bow animation
if distance_x > 0 then
if self.bow_rotation > math.rad(45) then
self.bow_rotation = self.bow_rotation - math.rad(3)
elseif self.bow_rotation < math.rad(45) then
self.bow_rotation = self.bow_rotation + math.rad(3)
end
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,10)
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
-- rest bow animation
if distance_x > 0 then
if self.bow_rotation > math.rad(45) then
self.bow_rotation = self.bow_rotation - math.rad(3)
elseif self.bow_rotation < math.rad(45) then
self.bow_rotation = self.bow_rotation + math.rad(3)
end
-- set in place
if math.abs(math.deg(self.bow_rotation) - 45) < 3 then
self.bow_rotation = math.rad(45)
end
self.sprite_flip.x = 1
else
if self.bow_rotation > math.rad(135) then
self.bow_rotation = self.bow_rotation - math.rad(3)
elseif self.bow_rotation < math.rad(135) then
self.bow_rotation = self.bow_rotation + math.rad(3)
end
-- set in place
if math.abs(math.deg(self.bow_rotation) - 135) < 3 then
self.bow_rotation = math.rad(135)
end
self.sprite_flip.x = -1
end
end
self.angle = angle
-- set in place
if math.abs(math.deg(self.bow_rotation) - 45) < 3 then
self.bow_rotation = math.rad(45)
end
self.sprite_flip.x = 1
else
if self.bow_rotation > math.rad(135) then
self.bow_rotation = self.bow_rotation - math.rad(3)
elseif self.bow_rotation < math.rad(135) then
self.bow_rotation = self.bow_rotation + math.rad(3)
end
-- set in place
if math.abs(math.deg(self.bow_rotation) - 135) < 3 then
self.bow_rotation = math.rad(135)
end
self.sprite_flip.x = -1
end
end
self.angle = angle
end
function Kupo:HandleAnimation()
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
local distance_x = self.target.x - self.pos.x
local distance_y = self.target.y - self.pos.y
if distance_x > 0 then
self.sprite_flip.x = 1
else
self.sprite_flip.x = -1
end
if distance_x > 0 then
self.sprite_flip.x = 1
else
self.sprite_flip.x = -1
end
-- 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
-- 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
self.body:Animate()
self:Draw(self.body)
self.body:Animate()
self:Draw(self.body)
if self.draw_bow == true then
self.bow:DrawFrame(
math.min(self.bow_frame,self.bow_frames),
self.pos.x + ( 8 * math.sin(self.bow_rotation)),
self.pos.y + (2 - 6 * math.cos(self.bow_rotation)),
self.bow_rotation
)
end
if self.draw_bow == true then
self.bow:DrawFrame(
math.min(self.bow_frame,self.bow_frames),
self.pos.x + ( 8 * math.sin(self.bow_rotation)),
self.pos.y + (2 - 6 * math.cos(self.bow_rotation)),
self.bow_rotation
)
end
end
function Kupo:DoPhysics()
self:CollisionMove()
self:CollisionMove()
end

View File

@ -1,100 +1,100 @@
Particle = Entity:New(x,y)
LoadedObjects.Particles = {}
function Particle:New(x,y,particle_data)
local o = Entity:New(x,y)
function Particle:New(x,y,particle_data)
local o = Entity:New(x,y)
o.pos = {x = x, y = y}
o.pos = {x = x, y = y}
o.speed = particle_data.speed or 0
o.direction = particle_data.direction or o.direction
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation
o.sprite_offset = particle_data.sprite_offset or o.sprite_offset
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
o.sprite_alpha_base = o.sprite_alpha
o.speed = particle_data.speed or 0
o.direction = particle_data.direction or o.direction
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation
o.sprite_offset = particle_data.sprite_offset or o.sprite_offset
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
o.sprite_alpha_base = o.sprite_alpha
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
o.animation_active = particle_data.animation_active or false
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
o.animation_active = particle_data.animation_active or false
o.time = 0.5
o.timer = 0
o.time = 0.5
o.timer = 0
o.vel = {
x = o.speed * math.cos(o.direction),
y = o.speed * math.sin(o.direction)
}
o.vel = {
x = o.speed * math.cos(o.direction),
y = o.speed * math.sin(o.direction)
}
o.speed_increase = particle_data.speed_increase or 0
o.speed_increase = particle_data.speed_increase or 0
if particle_data.light ~= nil then
o.lightRange = particle_data.light
local flicker = particle_data.light_flicker or nil
local color = particle_data.light_color or nil
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange,flicker,color)
end
if particle_data.light ~= nil then
o.lightRange = particle_data.light
local flicker = particle_data.light_flicker or nil
local color = particle_data.light_color or nil
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange,flicker,color)
end
-- animations
if particle_data.animation ~= nil then
o.body = Animation:New(particle_data.animation)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
if not o.animation_active then
o.body.speed = 0
end
end
-- animations
if particle_data.animation ~= nil then
o.body = Animation:New(particle_data.animation)
o:centerOffset(o.body)
o:getBoundingBox(o.body)
if not o.animation_active then
o.body.speed = 0
end
end
table.insert(LoadedObjects.Particles,o)
o.id = #LoadedObjects.Particles
table.insert(LoadedObjects.Particles,o)
o.id = #LoadedObjects.Particles
setmetatable(o, self)
self.__index = self
return o
end
setmetatable(o, self)
self.__index = self
return o
end
function Particle:Kill()
if self.light ~= nil then
self.light:Kill()
end
if self.id ~= nil then
for _, e in pairs(LoadedObjects.Particles) do
if e.id > self.id then
e.id = e.id - 1
end
end
table.remove(LoadedObjects.Particles,self.id)
end
self = nil
end
if self.light ~= nil then
self.light:Kill()
end
if self.id ~= nil then
for _, e in pairs(LoadedObjects.Particles) do
if e.id > self.id then
e.id = e.id - 1
end
end
table.remove(LoadedObjects.Particles,self.id)
end
self = nil
end
function Particle:HandleAnimation()
self.timer = self.timer + current_dt
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
if self.light ~= nil then
self:LightAdjust()
self.light.range = self.lightRange * self.sprite_alpha/2
end
if self.sprite_alpha < 0 then self:Kill() end
if self.body ~= nil then
self.body:Animate()
self:Draw(self.body)
end
self.timer = self.timer + current_dt
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
if self.light ~= nil then
self:LightAdjust()
self.light.range = self.lightRange * self.sprite_alpha/2
end
if self.sprite_alpha < 0 then self:Kill() end
if self.body ~= nil then
self.body:Animate()
self:Draw(self.body)
end
end
function Particle:DoPhysics()
-- adjust speed
if self.speed_increase ~= 0 then
self.speed = self.speed + self.speed_increase
self.vel.x = self.speed * math.cos(self.direction)
self.vel.y = self.speed * math.sin(self.direction)
end
-- move
self:CollisionMove()
-- adjust speed
if self.speed_increase ~= 0 then
self.speed = self.speed + self.speed_increase
self.vel.x = self.speed * math.cos(self.direction)
self.vel.y = self.speed * math.sin(self.direction)
end
-- move
self:CollisionMove()
end
function Particle:Debug()
-- draw center CYAN
love.graphics.setColor(0,1,1)
love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1)
-- draw center CYAN
love.graphics.setColor(0,1,1)
love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1)
end

View File

@ -1,316 +1,316 @@
Player = Entity:New(x,y)
function Player:New(x,y)
local o = Entity:New(x,y)
o.type = "player"
-- physics
o.moveSpeed = 1.3 -- gameworld pixels
o.zeroSpeed = 0.01 -- gameworld pixels
o.move_x = 0 -- gameworld pixels
o.airFriction = 0.01 -- gameworld pixels
o.groundFriction = 0.3 -- gameworld pixels
o.jumpImpulse = 3.5 -- gameworld pixels
o.coyoteAmount = 5 -- int
o.coyoteValue = 5 -- frames
o.dashCooldownTime = 0.1 -- seconds
o.dashCooldownTimer = 0 -- seconds
-- dash values
o.dashTimer = 0 -- seconds
o.dashTime = 0.15 -- seconds
o.dashDistance = 40 -- gameworld pixels
o.dashSpeed = o.dashDistance / (o.dashTime*60) -- pixels
o.dashCount = 1 -- int
o.dashAmount = 10 -- int
-- hook values
o.hookAnchor = {
x = nil,
y = nil
}
o.lightRange = 40 -- screen pixels
-- status
o.isDashing = false
o.isJumping = false
o.isHooked = false
o.isOnGround = true
o.isOnLadder = false
o.canJump = true
o.canFall = true
o.canFriction = true
o.maskType = animation.moth_mask
o.anchorRespawn = {
x = o.pos.x,
y = o.pos.y
}
-- sprite
o.target_offset = {x = 0, y = 0}
o.body = Animation:New(animation.nancy.idle)
o.mask = Animation:New(animation.moth_mask.idle)
o:centerOffset(o.body)
o:getBoundingBox(o.body,0,3,-1,-3)
-- lights
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
function Player:Smart()
self:LightAdjust(self.target_offset.x,self.target_offset.y)
-- reset coyoteValue
if self.isOnGround then
self.coyoteValue = self.coyoteAmount
elseif self.coyoteValue > 0 then
self.coyoteValue = self.coyoteValue - 1
end
if self.dashTimer <= 0 then
-- horizontal movement
if Keybind:CheckDown(Keybind.move.left) then
self.move_x = -self.moveSpeed
elseif Keybind:CheckDown(Keybind.move.right) then
self.move_x = self.moveSpeed
end
-- jump if on ground (coyotevalue)
if Keybind:CheckDown(Keybind.move.jump) then
if self.coyoteValue > 0 then
self.vel.y = -self.jumpImpulse
self.coyoteValue = 0
end
end
end
-- dash timer
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt)
-- try to dash
if Keybind:CheckDown(Keybind.move.dash) then
if self.dashCooldownTimer == 0
and not self.isDashing
and self.dashCount > 0 then
self:Unhook()
-- state player
self.isDashing = true
self.dashCount = self.dashCount - 1
-- get dash direction
local vertical = 0
if Keybind:CheckDown(Keybind.move.down) then vertical = vertical + 1 end
if Keybind:CheckDown(Keybind.move.up) then vertical = vertical - 1 end
local horizontal = 0
if Keybind:CheckDown(Keybind.move.right) then horizontal = horizontal + 1 end
if Keybind:CheckDown(Keybind.move.left) then horizontal = horizontal - 1 end
-- if no direction, then dash forward
if horizontal == 0 and vertical == 0 then
horizontal = self.sprite_flip.x
end
-- set dash values
self.dashDirection = GetAngleFromVector(horizontal, vertical)
self.dashTimer = self.dashTime
end
else
-- not dashing!
self.isDashing = false
end
if Keybind:CheckPressed(Keybind.move.hook) then
if self.isHooked then
self:Unhook()
else
local anchor = self:CheckNearest("hook_anchor",self.hookDistance)
if anchor then
self.isHooked = true
self.hookDistance = anchor.hookDistance
self.hookAnchor = {
x = anchor.pos.x,
y = anchor.pos.y
}
end
end
end
end
function Player:DoPhysics()
if self.dashTimer <= 0 then
if self.isOnGround then
self.vel.x = self.vel.x * (1-self.groundFriction)
else
self.vel.x = self.vel.x * (1-self.airFriction)
end
self.vel.y = self.vel.y * (1-self.airFriction)
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end
end
-- reset state
self.canFall = true
self.isOnGround = false
-- adjust timers
self.dashTimer = self.dashTimer - current_dt
-- DASH STATE
if self.dashTimer > 0 then
self.canFall = false
-- dash particle
local particle_data = {
animation = self.body,
sprite_tint = HEX2RGB("#fed100"),
sprite_alpha = 0.5,
sprite_flip = {
x = self.sprite_flip.x,
y = self.sprite_flip.y
}
}
Particle:New(self.pos.x,self.pos.y,particle_data)
self.dashCooldownTimer = self.dashCooldownTime
-- dash movement
self.vel.x = self.dashSpeed * math.cos(self.dashDirection)
self.vel.y = self.dashSpeed * math.sin(self.dashDirection)
end
-- hook state
if self.isHooked then
local hook = Vector(self.pos.x, self.pos.y, self.hookAnchor.x, self.hookAnchor.y)
if GetVectorValue(hook) > self.hookDistance then
local hook_angle = GetAngleFromVector(hook[1],hook[2])-math.rad(180)
if Keybind:CheckDown(Keybind.move.right) then
hook_angle = hook_angle - math.rad(0.05)
self.move_x = 0
end
if Keybind:CheckDown(Keybind.move.left) then
hook_angle = hook_angle + math.rad(0.05)
self.move_x = 0
end
local particle_data = {
animation = self.body,
sprite_tint = HEX2RGB("#fed100"),
sprite_alpha = 0.5,
sprite_flip = {
x = self.sprite_flip.x,
y = self.sprite_flip.y
}
}
Particle:New(self.pos.x,self.pos.y,particle_data)
local pos_x = self.hookAnchor.x + self.hookDistance * math.cos(hook_angle)
local pos_y = self.hookAnchor.y + self.hookDistance * math.sin(hook_angle)
self.vel.x = self.vel.x + pos_x - self.pos.x
self.vel.y = self.vel.y + pos_y - self.pos.y
self.pos.x = pos_x
self.pos.y = pos_y
end
end
if self.canFall then
-- not in dash
self.dashTimer = 0
self.vel.y = self.vel.y + gravity
end
-- horizontal collision
if not self:isCollidingAt(self.pos.x + self.vel.x + self.move_x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x + self.move_x
else
self.vel.x = 0
end
-- vertical collision
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
self.pos.y = self.pos.y + self.vel.y
else
if self.vel.y > 0 then
self.isOnGround = true
self.dashCount = self.dashAmount
end
self.vel.y = 0
end
-- if u collision w hazard, respawn
if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then
self:Respawn()
end
end
function Player:Respawn()
self.pos.x = self.anchorRespawn.x
self.pos.y = self.anchorRespawn.y
end
function Player:HandleAnimation()
-- flip sprite to look in the direction is moving
if self.isHooked then
if self.vel.x ~= 0 then
self.sprite_flip.x = math.sign(self.vel.x)
end
elseif self.move_x ~= 0 then
self.sprite_flip.x = math.sign(self.move_x)
end
-- animation priority
if self.vel.y > 1.25 then
self.body = self.body:ChangeTo(animation.nancy.fall)
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.maskType.jump)
elseif self.vel.x + self.move_x ~= 0 then
self.body = self.body:ChangeTo(animation.nancy.run)
self.mask = self.mask:ChangeTo(self.maskType.run)
else
self.body = self.body:ChangeTo(animation.nancy.idle)
self.mask = self.mask:ChangeTo(self.maskType.idle)
end
-- special case: idle animation gets slower by time
if self.body.anim_path == animation.nancy.idle.path then
if self.body.anim_speed < 0.5 then
self.body.anim_speed = self.body.anim_speed + 0.001
end
end
if self.isHooked then
love.graphics.line(
-Camera.pos.x + self.pos.x,
-Camera.pos.y + self.pos.y,
-Camera.pos.x + self.hookAnchor.x,
-Camera.pos.y + self.hookAnchor.y
)
end
self.body:Animate()
self:Draw(self.body)
if self.dashCount > 0 then
self:Draw(self.mask)
end
self.move_x = 0
end
function Player:Unhook()
self.isHooked = false
self.hookAnchor = nil
end
Player = Entity:New(x,y)
function Player:New(x,y)
local o = Entity:New(x,y)
o.type = "player"
-- physics
o.moveSpeed = 1.3 -- gameworld pixels
o.zeroSpeed = 0.01 -- gameworld pixels
o.move_x = 0 -- gameworld pixels
o.airFriction = 0.01 -- gameworld pixels
o.groundFriction = 0.3 -- gameworld pixels
o.jumpImpulse = 3.5 -- gameworld pixels
o.coyoteAmount = 5 -- int
o.coyoteValue = 5 -- frames
o.dashCooldownTime = 0.1 -- seconds
o.dashCooldownTimer = 0 -- seconds
-- dash values
o.dashTimer = 0 -- seconds
o.dashTime = 0.15 -- seconds
o.dashDistance = 40 -- gameworld pixels
o.dashSpeed = o.dashDistance / (o.dashTime*60) -- pixels
o.dashCount = 1 -- int
o.dashAmount = 10 -- int
-- hook values
o.hookAnchor = {
x = nil,
y = nil
}
o.lightRange = 40 -- screen pixels
-- status
o.isDashing = false
o.isJumping = false
o.isHooked = false
o.isOnGround = true
o.isOnLadder = false
o.canJump = true
o.canFall = true
o.canFriction = true
o.maskType = animation.moth_mask
o.anchorRespawn = {
x = o.pos.x,
y = o.pos.y
}
-- sprite
o.target_offset = {x = 0, y = 0}
o.body = Animation:New(animation.nancy.idle)
o.mask = Animation:New(animation.moth_mask.idle)
o:centerOffset(o.body)
o:getBoundingBox(o.body,0,3,-1,-3)
-- lights
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
table.insert(LoadedObjects.Entities,o)
o.id = #LoadedObjects.Entities
setmetatable(o, self)
self.__index = self
return o
end
function Player:Smart()
self:LightAdjust(self.target_offset.x,self.target_offset.y)
-- reset coyoteValue
if self.isOnGround then
self.coyoteValue = self.coyoteAmount
elseif self.coyoteValue > 0 then
self.coyoteValue = self.coyoteValue - 1
end
if self.dashTimer <= 0 then
-- horizontal movement
if Keybind:CheckDown(Keybind.move.left) then
self.move_x = -self.moveSpeed
elseif Keybind:CheckDown(Keybind.move.right) then
self.move_x = self.moveSpeed
end
-- jump if on ground (coyotevalue)
if Keybind:CheckDown(Keybind.move.jump) then
if self.coyoteValue > 0 then
self.vel.y = -self.jumpImpulse
self.coyoteValue = 0
end
end
end
-- dash timer
self.dashCooldownTimer = math.max(0,self.dashCooldownTimer - current_dt)
-- try to dash
if Keybind:CheckDown(Keybind.move.dash) then
if self.dashCooldownTimer == 0
and not self.isDashing
and self.dashCount > 0 then
self:Unhook()
-- state player
self.isDashing = true
self.dashCount = self.dashCount - 1
-- get dash direction
local vertical = 0
if Keybind:CheckDown(Keybind.move.down) then vertical = vertical + 1 end
if Keybind:CheckDown(Keybind.move.up) then vertical = vertical - 1 end
local horizontal = 0
if Keybind:CheckDown(Keybind.move.right) then horizontal = horizontal + 1 end
if Keybind:CheckDown(Keybind.move.left) then horizontal = horizontal - 1 end
-- if no direction, then dash forward
if horizontal == 0 and vertical == 0 then
horizontal = self.sprite_flip.x
end
-- set dash values
self.dashDirection = GetAngleFromVector(horizontal, vertical)
self.dashTimer = self.dashTime
end
else
-- not dashing!
self.isDashing = false
end
if Keybind:CheckPressed(Keybind.move.hook) then
if self.isHooked then
self:Unhook()
else
local anchor = self:CheckNearest("hook_anchor",self.hookDistance)
if anchor then
self.isHooked = true
self.hookDistance = anchor.hookDistance
self.hookAnchor = {
x = anchor.pos.x,
y = anchor.pos.y
}
end
end
end
end
function Player:DoPhysics()
if self.dashTimer <= 0 then
if self.isOnGround then
self.vel.x = self.vel.x * (1-self.groundFriction)
else
self.vel.x = self.vel.x * (1-self.airFriction)
end
self.vel.y = self.vel.y * (1-self.airFriction)
if math.abs(self.vel.x) < self.zeroSpeed then self.vel.x = 0 end
end
-- reset state
self.canFall = true
self.isOnGround = false
-- adjust timers
self.dashTimer = self.dashTimer - current_dt
-- DASH STATE
if self.dashTimer > 0 then
self.canFall = false
-- dash particle
local particle_data = {
animation = self.body,
sprite_tint = HEX2RGB("#fed100"),
sprite_alpha = 0.5,
sprite_flip = {
x = self.sprite_flip.x,
y = self.sprite_flip.y
}
}
Particle:New(self.pos.x,self.pos.y,particle_data)
self.dashCooldownTimer = self.dashCooldownTime
-- dash movement
self.vel.x = self.dashSpeed * math.cos(self.dashDirection)
self.vel.y = self.dashSpeed * math.sin(self.dashDirection)
end
-- hook state
if self.isHooked then
local hook = Vector(self.pos.x, self.pos.y, self.hookAnchor.x, self.hookAnchor.y)
if GetVectorValue(hook) > self.hookDistance then
local hook_angle = GetAngleFromVector(hook[1],hook[2])-math.rad(180)
if Keybind:CheckDown(Keybind.move.right) then
hook_angle = hook_angle - math.rad(0.05)
self.move_x = 0
end
if Keybind:CheckDown(Keybind.move.left) then
hook_angle = hook_angle + math.rad(0.05)
self.move_x = 0
end
local particle_data = {
animation = self.body,
sprite_tint = HEX2RGB("#fed100"),
sprite_alpha = 0.5,
sprite_flip = {
x = self.sprite_flip.x,
y = self.sprite_flip.y
}
}
Particle:New(self.pos.x,self.pos.y,particle_data)
local pos_x = self.hookAnchor.x + self.hookDistance * math.cos(hook_angle)
local pos_y = self.hookAnchor.y + self.hookDistance * math.sin(hook_angle)
self.vel.x = self.vel.x + pos_x - self.pos.x
self.vel.y = self.vel.y + pos_y - self.pos.y
self.pos.x = pos_x
self.pos.y = pos_y
end
end
if self.canFall then
-- not in dash
self.dashTimer = 0
self.vel.y = self.vel.y + gravity
end
-- horizontal collision
if not self:isCollidingAt(self.pos.x + self.vel.x + self.move_x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x + self.move_x
else
self.vel.x = 0
end
-- vertical collision
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
self.pos.y = self.pos.y + self.vel.y
else
if self.vel.y > 0 then
self.isOnGround = true
self.dashCount = self.dashAmount
end
self.vel.y = 0
end
-- if u collision w hazard, respawn
if self:isCollidingAt(self.pos.x, self.pos.y, LoadedObjects.Hazards) then
self:Respawn()
end
end
function Player:Respawn()
self.pos.x = self.anchorRespawn.x
self.pos.y = self.anchorRespawn.y
end
function Player:HandleAnimation()
-- flip sprite to look in the direction is moving
if self.isHooked then
if self.vel.x ~= 0 then
self.sprite_flip.x = math.sign(self.vel.x)
end
elseif self.move_x ~= 0 then
self.sprite_flip.x = math.sign(self.move_x)
end
-- animation priority
if self.vel.y > 1.25 then
self.body = self.body:ChangeTo(animation.nancy.fall)
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.maskType.jump)
elseif self.vel.x + self.move_x ~= 0 then
self.body = self.body:ChangeTo(animation.nancy.run)
self.mask = self.mask:ChangeTo(self.maskType.run)
else
self.body = self.body:ChangeTo(animation.nancy.idle)
self.mask = self.mask:ChangeTo(self.maskType.idle)
end
-- special case: idle animation gets slower by time
if self.body.anim_path == animation.nancy.idle.path then
if self.body.anim_speed < 0.5 then
self.body.anim_speed = self.body.anim_speed + 0.001
end
end
if self.isHooked then
love.graphics.line(
-Camera.pos.x + self.pos.x,
-Camera.pos.y + self.pos.y,
-Camera.pos.x + self.hookAnchor.x,
-Camera.pos.y + self.hookAnchor.y
)
end
self.body:Animate()
self:Draw(self.body)
if self.dashCount > 0 then
self:Draw(self.mask)
end
self.move_x = 0
end
function Player:Unhook()
self.isHooked = false
self.hookAnchor = nil
end

View File

@ -1,270 +1,270 @@
Entity = {class = "Entity"}
LoadedObjects.Entities = {}
function Entity:New(x,y)
o = {}
o.pos = {x = x, y = y}
o.vel = {x = 0, y = 0}
o.direction = 0
o.boxCollision = {
from = {x = x, y = y},
to = {x = x, y = y},
}
o.target_offset = {x = 0, y = 0}
o.sprite_offset = {x = 0, y = 0}
o.sprite_scale = {x = 1, y = 1}
o.sprite_rotation = math.rad(0)
o.sprite_tint = {1,1,1}
o.sprite_alpha = 1
o.sprite_flip = { x = 1, y = 1}
o.illuminated = false
setmetatable(o, self)
self.__index = self
return o
end
function Entity:CheckNearest(type,maxdistance)
local return_entity = nil
local shortest = -1
for _, entity in pairs(LoadedObjects.Entities) do
if not type or entity.type == type then
local distance_x = entity.pos.x - self.pos.x
local distance_y = entity.pos.y - self.pos.y
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if not maxdistance or distance < maxdistance then
if shortest == -1 or distance < shortest then
shortest = distance
return_entity = entity
end
end
end
end
return return_entity
end
function Entity:Smart()
end
function Entity:Move()
self.pos.x = self.pos.x + self.vel.x
self.pos.y = self.pos.y + self.vel.y
end
function Entity:CollisionMove()
local r = false
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x
else
self.vel.x = 0
r = true
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
self.pos.y = self.pos.y + self.vel.y
else
self.vel.y = 0
r = true
end
return r
end
function Entity:LightAdjust(x,y)
if self.light ~= nil then
local x = x or 0
local y = y or 0
self.light.pos.x = self.pos.x
self.light.pos.y = self.pos.y
end
end
function Entity:Kill()
if self.light ~= nil then
self.light:Kill()
end
if self.id ~= nil then
for _, e in pairs(LoadedObjects.Entities) do
if e.id > self.id then
e.id = e.id - 1
end
end
table.remove(LoadedObjects.Entities,self.id)
end
self = nil
end
function Entity:CheckVisionLine(entity,range)
local target_x = entity.pos.x + entity.target_offset.x
local target_y = entity.pos.y + entity.target_offset.y
local distance_x = target_x - self.pos.x
local distance_y = target_y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local is_colliding = true
if distance < range then
is_colliding = false
for i=1, distance, game.scale do
if isThereObjectAt(
self.pos.x+math.cos(angle)*i,
self.pos.y+math.sin(angle)*i,
LoadedObjects.Collisions
) then
is_colliding = true
end
end
end
return not is_colliding
end
function Entity:Draw(animation)
local c1, c2, c3, a = love.graphics.getColor()
love.graphics.setColor(self.sprite_tint[1],self.sprite_tint[2],self.sprite_tint[3],self.sprite_alpha)
animation: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,
self.sprite_rotation,
self.sprite_scale.x * self.sprite_flip.x,
self.sprite_scale.y * self.sprite_flip.y
)
love.graphics.setColor(c1,c2,c3,a)
end
function Entity:centerOffset(animation,x,y)
local x = x or 0
local y = y or 0
self.sprite_offset.x = animation.imgs[1]:getWidth()/2 + x
self.sprite_offset.y = animation.imgs[1]:getHeight()/2 + y
end
function Entity:getBoundingBox(animation,top,left,bottom,right)
local left = left or 0
local right = right or 0
local top = top or 0
local bottom = bottom or 0
self.boxCollision.from.x = -animation.imgs[1]:getWidth()/2 + left
self.boxCollision.to.x = animation.imgs[1]:getWidth()/2 + right
self.boxCollision.from.y = -animation.imgs[1]:getHeight()/2 + top
self.boxCollision.to.y = animation.imgs[1]:getHeight()/2 + bottom
end
-- returns true if theres a collision at that point. also marks collisioned tile as collision true
function Entity:isCollidingAt(x,y,object)
for _, collision in pairs(object) do
if collision.disable then
-- Dont calculate if disabled
elseif x + self.boxCollision.from.x < collision.to.x
and x + self.boxCollision.to.x > collision.from.x
and y + self.boxCollision.from.y < collision.to.y
and y + self.boxCollision.to.y > collision.from.y
then
collision.isColliding = true
return true
end
end
return false
end
function Entity:isCollidingWith(entity)
return self.pos.x + self.boxCollision.from.x < entity.pos.x + entity.boxCollision.to.x
and entity.pos.x + entity.boxCollision.from.x < self.pos.x + self.boxCollision.to.x
and self.pos.y + self.boxCollision.from.y < entity.pos.y + entity.boxCollision.to.y
and entity.pos.y + entity.boxCollision.from.y < self.pos.y + self.boxCollision.to.y
end
function Entity:isCollidingAtAll(x,y)
local result = false
if not result then
result = self:isCollidingAt(x,y,LoadedObjects.Platforms)
end
if not result then
result = self:isCollidingAt(x,y,LoadedObjects.Platforms)
end
if not result then
result = self:isCollidingAt(x,y,LoadedObjects.Platforms)
end
return result
end
function Entity:CheckVisionLineDebug(entity,range)
local c1, c2, c3, a = love.graphics.getColor()
local target_x = entity.pos.x + entity.target_offset.x
local target_y = entity.pos.y + entity.target_offset.y
local distance_x = target_x - self.pos.x
local distance_y = target_y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if distance < range then
for i=1, distance, game.scale do
if isThereObjectAt(
self.pos.x+math.cos(angle)*i,
self.pos.y+math.sin(angle)*i,
LoadedObjects.Collisions
) then
love.graphics.setColor(1,0,0)
else
love.graphics.setColor(0,1,0)
end
love.graphics.line(
self.pos.x+math.cos(angle)*i-1 - Camera.pos.x,
self.pos.y+math.sin(angle)*i-1 - Camera.pos.y,
self.pos.x+math.cos(angle)*i - Camera.pos.x,
self.pos.y+math.sin(angle)*i - Camera.pos.y
)
end
end
love.graphics.setColor(c1,c2,c3,a)
end
function Entity:Debug()
-- draw center GREEN
love.graphics.setColor(0,1,0)
love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1)
-- draw collision box PURPLE
love.graphics.setColor(1,0,1)
love.graphics.rectangle(
"line",
-Camera.pos.x + self.pos.x + self.boxCollision.from.x,
-Camera.pos.y + self.pos.y + self.boxCollision.from.y,
-Camera.pos.x + self.pos.x + self.boxCollision.to.x -(-Camera.pos.x + self.pos.x + self.boxCollision.from.x),
-Camera.pos.y + self.pos.y + self.boxCollision.to.y -(-Camera.pos.y + self.pos.y + self.boxCollision.from.y)
)
if self.target ~= nil then
love.graphics.line(
-Camera.pos.x + self.pos.x,
-Camera.pos.y + self.pos.y,
-Camera.pos.x + self.target.x,
-Camera.pos.y + self.target.y
)
end
end
function Entity:HandleAnimation()
end
function Entity:DrawBackground()
end
require "code/entities/kupo"
require "code/entities/arrow"
require "code/entities/decoration"
require "code/entities/player"
require "code/entities/fairy"
require "code/entities/cursed_book"
require "code/entities/hook_anchor"
require "code/entities/particle"
Entity = {class = "Entity"}
LoadedObjects.Entities = {}
function Entity:New(x,y)
o = {}
o.pos = {x = x, y = y}
o.vel = {x = 0, y = 0}
o.direction = 0
o.boxCollision = {
from = {x = x, y = y},
to = {x = x, y = y},
}
o.target_offset = {x = 0, y = 0}
o.sprite_offset = {x = 0, y = 0}
o.sprite_scale = {x = 1, y = 1}
o.sprite_rotation = math.rad(0)
o.sprite_tint = {1,1,1}
o.sprite_alpha = 1
o.sprite_flip = { x = 1, y = 1}
o.illuminated = false
setmetatable(o, self)
self.__index = self
return o
end
function Entity:CheckNearest(type,maxdistance)
local return_entity = nil
local shortest = -1
for _, entity in pairs(LoadedObjects.Entities) do
if not type or entity.type == type then
local distance_x = entity.pos.x - self.pos.x
local distance_y = entity.pos.y - self.pos.y
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if not maxdistance or distance < maxdistance then
if shortest == -1 or distance < shortest then
shortest = distance
return_entity = entity
end
end
end
end
return return_entity
end
function Entity:Smart()
end
function Entity:Move()
self.pos.x = self.pos.x + self.vel.x
self.pos.y = self.pos.y + self.vel.y
end
function Entity:CollisionMove()
local r = false
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x
else
self.vel.x = 0
r = true
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
self.pos.y = self.pos.y + self.vel.y
else
self.vel.y = 0
r = true
end
return r
end
function Entity:LightAdjust(x,y)
if self.light ~= nil then
local x = x or 0
local y = y or 0
self.light.pos.x = self.pos.x
self.light.pos.y = self.pos.y
end
end
function Entity:Kill()
if self.light ~= nil then
self.light:Kill()
end
if self.id ~= nil then
for _, e in pairs(LoadedObjects.Entities) do
if e.id > self.id then
e.id = e.id - 1
end
end
table.remove(LoadedObjects.Entities,self.id)
end
self = nil
end
function Entity:CheckVisionLine(entity,range)
local target_x = entity.pos.x + entity.target_offset.x
local target_y = entity.pos.y + entity.target_offset.y
local distance_x = target_x - self.pos.x
local distance_y = target_y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
local is_colliding = true
if distance < range then
is_colliding = false
for i=1, distance, game.scale do
if isThereObjectAt(
self.pos.x+math.cos(angle)*i,
self.pos.y+math.sin(angle)*i,
LoadedObjects.Collisions
) then
is_colliding = true
end
end
end
return not is_colliding
end
function Entity:Draw(animation)
local c1, c2, c3, a = love.graphics.getColor()
love.graphics.setColor(self.sprite_tint[1],self.sprite_tint[2],self.sprite_tint[3],self.sprite_alpha)
animation: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,
self.sprite_rotation,
self.sprite_scale.x * self.sprite_flip.x,
self.sprite_scale.y * self.sprite_flip.y
)
love.graphics.setColor(c1,c2,c3,a)
end
function Entity:centerOffset(animation,x,y)
local x = x or 0
local y = y or 0
self.sprite_offset.x = animation.imgs[1]:getWidth()/2 + x
self.sprite_offset.y = animation.imgs[1]:getHeight()/2 + y
end
function Entity:getBoundingBox(animation,top,left,bottom,right)
local left = left or 0
local right = right or 0
local top = top or 0
local bottom = bottom or 0
self.boxCollision.from.x = -animation.imgs[1]:getWidth()/2 + left
self.boxCollision.to.x = animation.imgs[1]:getWidth()/2 + right
self.boxCollision.from.y = -animation.imgs[1]:getHeight()/2 + top
self.boxCollision.to.y = animation.imgs[1]:getHeight()/2 + bottom
end
-- returns true if theres a collision at that point. also marks collisioned tile as collision true
function Entity:isCollidingAt(x,y,object)
for _, collision in pairs(object) do
if collision.disable then
-- Dont calculate if disabled
elseif x + self.boxCollision.from.x < collision.to.x
and x + self.boxCollision.to.x > collision.from.x
and y + self.boxCollision.from.y < collision.to.y
and y + self.boxCollision.to.y > collision.from.y
then
collision.isColliding = true
return true
end
end
return false
end
function Entity:isCollidingWith(entity)
return self.pos.x + self.boxCollision.from.x < entity.pos.x + entity.boxCollision.to.x
and entity.pos.x + entity.boxCollision.from.x < self.pos.x + self.boxCollision.to.x
and self.pos.y + self.boxCollision.from.y < entity.pos.y + entity.boxCollision.to.y
and entity.pos.y + entity.boxCollision.from.y < self.pos.y + self.boxCollision.to.y
end
function Entity:isCollidingAtAll(x,y)
local result = false
if not result then
result = self:isCollidingAt(x,y,LoadedObjects.Platforms)
end
if not result then
result = self:isCollidingAt(x,y,LoadedObjects.Platforms)
end
if not result then
result = self:isCollidingAt(x,y,LoadedObjects.Platforms)
end
return result
end
function Entity:CheckVisionLineDebug(entity,range)
local c1, c2, c3, a = love.graphics.getColor()
local target_x = entity.pos.x + entity.target_offset.x
local target_y = entity.pos.y + entity.target_offset.y
local distance_x = target_x - self.pos.x
local distance_y = target_y - self.pos.y
local angle = GetAngleFromVector(distance_x,distance_y)
local distance = math.sqrt(distance_x ^ 2 + distance_y ^ 2)
if distance < range then
for i=1, distance, game.scale do
if isThereObjectAt(
self.pos.x+math.cos(angle)*i,
self.pos.y+math.sin(angle)*i,
LoadedObjects.Collisions
) then
love.graphics.setColor(1,0,0)
else
love.graphics.setColor(0,1,0)
end
love.graphics.line(
self.pos.x+math.cos(angle)*i-1 - Camera.pos.x,
self.pos.y+math.sin(angle)*i-1 - Camera.pos.y,
self.pos.x+math.cos(angle)*i - Camera.pos.x,
self.pos.y+math.sin(angle)*i - Camera.pos.y
)
end
end
love.graphics.setColor(c1,c2,c3,a)
end
function Entity:Debug()
-- draw center GREEN
love.graphics.setColor(0,1,0)
love.graphics.circle("fill", -Camera.pos.x + self.pos.x, -Camera.pos.y + self.pos.y, 1)
-- draw collision box PURPLE
love.graphics.setColor(1,0,1)
love.graphics.rectangle(
"line",
-Camera.pos.x + self.pos.x + self.boxCollision.from.x,
-Camera.pos.y + self.pos.y + self.boxCollision.from.y,
-Camera.pos.x + self.pos.x + self.boxCollision.to.x -(-Camera.pos.x + self.pos.x + self.boxCollision.from.x),
-Camera.pos.y + self.pos.y + self.boxCollision.to.y -(-Camera.pos.y + self.pos.y + self.boxCollision.from.y)
)
if self.target ~= nil then
love.graphics.line(
-Camera.pos.x + self.pos.x,
-Camera.pos.y + self.pos.y,
-Camera.pos.x + self.target.x,
-Camera.pos.y + self.target.y
)
end
end
function Entity:HandleAnimation()
end
function Entity:DrawBackground()
end
require "code/entities/kupo"
require "code/entities/arrow"
require "code/entities/decoration"
require "code/entities/player"
require "code/entities/fairy"
require "code/entities/cursed_book"
require "code/entities/hook_anchor"
require "code/entities/particle"

View File

@ -1,24 +1,24 @@
function GameStep()
SetCollisionFlags()
if menu_type == "no" then
for _, particle in pairs(LoadedParticles) do
particle:Smart()
end
for _, enty in pairs(LoadedObjects.Entities) do
enty:Smart()
end
end
SetCollisionFlags()
if menu_type == "no" then
for _, particle in pairs(LoadedParticles) do
particle:Smart()
end
for _, enty in pairs(LoadedObjects.Entities) do
enty:Smart()
end
end
for _, particle in pairs(LoadedObjects.Particles) do
particle:DoPhysics()
end
for _, enty in pairs(LoadedObjects.Entities) do
enty:DoPhysics()
end
for _, particle in pairs(LoadedObjects.Particles) do
particle:DoPhysics()
end
for _, enty in pairs(LoadedObjects.Entities) do
enty:DoPhysics()
end
AnimateTiles()
Camera:positionCenterAt(main_Player.pos.x, main_Player.pos.y)
--camera:positionAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
AnimateTiles()
Camera:positionCenterAt(main_Player.pos.x, main_Player.pos.y)
--camera:positionAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
if Keybind:CheckPressed(Keybind.debug.debug) then
if debug then
@ -38,8 +38,8 @@ function GameStep()
end
if Keybind:CheckPressed(Keybind.debug.reload) then
MenuClear()
menu_type = "dialog"
MenuClear()
menu_type = "dialog"
MenuInit("dialog",DialogSequence.Example)
end
@ -49,50 +49,50 @@ function GameStep()
if Keybind:CheckPressed(Keybind.debug.recording) then
if DemoRecording then
Demo:RecordEnd()
else
Demo:RecordStart()
end
Demo:RecordEnd()
else
Demo:RecordStart()
end
end
if Keybind:CheckPressed(Keybind.debug.playback) then
if DemoPlayback then
Demo:PlaybackEnd()
else
Demo:PlaybackStart()
end
end
if Keybind:CheckPressed(Keybind.debug.playback) then
if DemoPlayback then
Demo:PlaybackEnd()
else
Demo:PlaybackStart()
end
end
end
function GameDraw()
-- prepare
GameworldDrawPrepare()
GameWorldUpdateLights()
-- prepare
GameworldDrawPrepare()
GameWorldUpdateLights()
-- background
GameworldDrawBackground()
GameworldDrawLights()
GameworldDrawEntitiesBackground()
-- background
GameworldDrawBackground()
GameworldDrawLights()
GameworldDrawEntitiesBackground()
-- foreground
GameworldDrawForeground()
GameworldDrawParticles()
GameworldDrawEntities()
-- foreground
GameworldDrawForeground()
GameworldDrawParticles()
GameworldDrawEntities()
if LevelData.properties.darkness then
GameworldDrawDarkness()
end
-- end
GameworldDrawEnd()
if LevelData.properties.darkness then
GameworldDrawDarkness()
end
-- end
GameworldDrawEnd()
-- hud
textScale = 1
-- debug
if debug then DebugUI() end
if debug_collision then
DebugColisions()
DebugEntities()
end
-- debug
if debug then DebugUI() end
if debug_collision then
DebugColisions()
DebugEntities()
end
end

View File

@ -1,21 +1,21 @@
function GameworldDrawPrepare()
if game_resize then
Camera.height = game.height
Camera.width = game.width
Canvas.Darkness:Recreate()
end
pcr, pcg, pcb, pca = love.graphics.getColor()
if game_resize then
Camera.height = game.height
Camera.width = game.width
Canvas.Darkness:Recreate()
end
pcr, pcg, pcb, pca = love.graphics.getColor()
love.graphics.setScale(game.scale,game.scale)
love.graphics.setColor(1,1,1,1)
end
function GameworldDrawEnd()
love.graphics.setColor(pcr, pcg, pcb, pca)
pcr, pcg, pcb, pca = nil, nil, nil, nil
love.graphics.setColor(pcr, pcg, pcb, pca)
pcr, pcg, pcb, pca = nil, nil, nil, nil
end
function GameworldDrawBackground()
-- obscure a bit
-- obscure a bit
love.graphics.setColor(0.7,0.7,0.7)
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
@ -35,32 +35,32 @@ function GameworldDrawBackground()
end
function GameworldDrawParticles()
love.graphics.setColor(0.7,0.7,0.7)
for _, particle in pairs(LoadedObjects.Particles) do
particle:HandleAnimation()
end
love.graphics.setColor(0.7,0.7,0.7)
for _, particle in pairs(LoadedObjects.Particles) do
particle:HandleAnimation()
end
end
function GameworldDrawEntitiesBackground()
for _, enty in pairs(LoadedObjects.Entities) do
enty:DrawBackground()
end
for _, enty in pairs(LoadedObjects.Entities) do
enty:DrawBackground()
end
end
function GameworldDrawEntities()
love.graphics.setColor(0.7,0.7,0.7)
love.graphics.setColor(0.7,0.7,0.7)
for _, enty in pairs(LoadedObjects.Entities) do
enty:HandleAnimation()
end
end
function GameworldDrawForeground()
love.graphics.setColor(1,1,1)
love.graphics.setColor(1,1,1)
for i = 1, #LevelTiles do
for j = 1, #LevelTiles[i] do
if LevelTiles[i][j].id ~= 0 then
local depth = TileData[LevelTiles[i][j].id].depth
local depth = TileData[LevelTiles[i][j].id].depth
DrawTile(
LevelTiles[i][j],
tileProperties.scale * j * tileProperties.width + tileProperties.scale * (levelProperties.offset.x - tileProperties.width) - Camera.pos.x,
@ -74,53 +74,53 @@ function GameworldDrawForeground()
end
function GameworldDrawDarkness()
Canvas.Darkness:Reset()
Canvas.Darkness:DrawingStart()
love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0)
for _, light in pairs(LoadedObjects.Lights) do
if light.range ~= 0 then
local position = {
x = (light.pos.x - Camera.pos.x) / game.scale,
y = (light.pos.y - Camera.pos.y) / game.scale
}
local range = (light.range + light.flicker) / game.scale
love.graphics.circle(
"fill",
position.x,
position.y,
range
)
end
end
Canvas.Darkness:DrawingEnd()
Canvas.Darkness:Draw()
Canvas.Darkness:Reset()
Canvas.Darkness:DrawingStart()
love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0)
for _, light in pairs(LoadedObjects.Lights) do
if light.range ~= 0 then
local position = {
x = (light.pos.x - Camera.pos.x) / game.scale,
y = (light.pos.y - Camera.pos.y) / game.scale
}
local range = (light.range + light.flicker) / game.scale
love.graphics.circle(
"fill",
position.x,
position.y,
range
)
end
end
Canvas.Darkness:DrawingEnd()
Canvas.Darkness:Draw()
end
function GameworldDrawLights()
for _, light in pairs(LoadedObjects.Lights) do
if light.range ~= 0 then
love.graphics.setColor(light.color[1],light.color[2],light.color[3],1)
for _, light in pairs(LoadedObjects.Lights) do
if light.range ~= 0 then
love.graphics.setColor(light.color[1],light.color[2],light.color[3],1)
Shader.RadiusGradient:send("pos_x",- Camera.pos.x + light.pos.x)
Shader.RadiusGradient:send("pos_y",- Camera.pos.y + light.pos.y)
Shader.RadiusGradient:send("range",light.range)
Shader.RadiusGradient:send("scale",game.scale)
Shader.RadiusGradient:send("pos_x",- Camera.pos.x + light.pos.x)
Shader.RadiusGradient:send("pos_y",- Camera.pos.y + light.pos.y)
Shader.RadiusGradient:send("range",light.range)
Shader.RadiusGradient:send("scale",game.scale)
love.graphics.setShader(Shader.RadiusGradient)
love.graphics.circle(
"fill",
- Camera.pos.x + light.pos.x,
- Camera.pos.y + light.pos.y,
light.range
)
love.graphics.setShader()
end
end
love.graphics.setShader(Shader.RadiusGradient)
love.graphics.circle(
"fill",
- Camera.pos.x + light.pos.x,
- Camera.pos.y + light.pos.y,
light.range
)
love.graphics.setShader()
end
end
end
function GameWorldUpdateLights()
for _, light in pairs(LoadedObjects.Lights) do
light:Flicker()
end
for _, light in pairs(LoadedObjects.Lights) do
light:Flicker()
end
end

View File

@ -10,7 +10,7 @@ function HEX2RGB(color)
end
function HEX2DEX(hex)
if hex == "0" then return 0
if hex == "0" then return 0
elseif hex == "1" then return 1
elseif hex == "2" then return 2
elseif hex == "3" then return 3

View File

@ -20,7 +20,7 @@ function ExportLevel(levelname, filename)
logPrint("- properties")
exportFile:write("\n properties = {")
exportFile:write("\n darkness = true")
exportFile:write("\n darkness = true")
exportFile:write("\n },")
logPrint("- tiles")
@ -53,30 +53,30 @@ end
-- Source https://stackoverflow.com/a/11130774
function scandir(directory)
local i, t, popen = 0, {}, io.popen
local pfile = popen('ls "'..directory..'"')
for filename in pfile:lines() do
i = i + 1
t[i] = filename
end
pfile:close()
return t
local i, t, popen = 0, {}, io.popen
local pfile = popen('ls "'..directory..'"')
for filename in pfile:lines() do
i = i + 1
t[i] = filename
end
pfile:close()
return t
end
--[[
return {
name = "level1",
tileset = tileset.library,
tiles = {
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,25,26, 6,25,26, 7, 0, 5,25,26, 7, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,37,38, 6,37,38, 7, 0, 5,37,38, 7, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,37,38, 6,37,38, 7, 0, 5,37,38, 7, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,49,50, 6,49,50, 7, 0, 5,49,50, 7, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
},
objects = {}
name = "level1",
tileset = tileset.library,
tiles = {
{13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,25,26, 6,25,26, 7, 0, 5,25,26, 7, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,37,38, 6,37,38, 7, 0, 5,37,38, 7, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,37,38, 6,37,38, 7, 0, 5,37,38, 7, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 5,49,50, 6,49,50, 7, 0, 5,49,50, 7, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
},
objects = {}
}
]]
if logging then

View File

@ -18,95 +18,95 @@ Keybind.editor = {}
Keybind.generic = {}
function Keybind:CheckDown(action)
if DemoPlayback then
for _, demo_action in pairs(DemoAction[CurrentDemoFrame]) do
if demo_action == action.demo then
return true
end
end
return false
else
for _, keyname in pairs(action.keys) do
local check = false
if type(keyname) == "string" then
check = love.keyboard.isDown(keyname)
else
check = love.mouse.isDown(keyname)
end
if check then
if action.demo ~= nil then
Demo:RecordAction(action.demo)
end
return true
end
end
return false
end
if DemoPlayback then
for _, demo_action in pairs(DemoAction[CurrentDemoFrame]) do
if demo_action == action.demo then
return true
end
end
return false
else
for _, keyname in pairs(action.keys) do
local check = false
if type(keyname) == "string" then
check = love.keyboard.isDown(keyname)
else
check = love.mouse.isDown(keyname)
end
if check then
if action.demo ~= nil then
Demo:RecordAction(action.demo)
end
return true
end
end
return false
end
end
function Keybind:CheckPressed(action)
if Keybind:CheckDown(action) then
if not action.pressed then
action.pressed = true
return true
end
else
action.pressed = nil
end
return false
if Keybind:CheckDown(action) then
if not action.pressed then
action.pressed = true
return true
end
else
action.pressed = nil
end
return false
end
function Keybind:CheckCollision(cat, key)
for _, action in pairs(cat) do
for _, keyname in pairs(action.keys) do
if key == keyname then return true end
end
end
return false
for _, action in pairs(cat) do
for _, keyname in pairs(action.keys) do
if key == keyname then return true end
end
end
return false
end
function Keybind:AddKey(action, key)
table.insert(action.keys, key)
table.insert(action.keys, key)
end
function Keybind:ChangeKey(action, position, key)
action.keys[position] = key
action.keys[position] = key
end
function Keybind:RemoveKeys(action)
action.keys = {}
action.keys = {}
end
function Keybind:Default()
--Menu
Keybind.menu.pause.keys = {"escape"}
Keybind.menu.confirm.keys = {"z", "space", 1}
--Menu
Keybind.menu.pause.keys = {"escape"}
Keybind.menu.confirm.keys = {"z", "space", 1}
--Move
Keybind.move.left.keys = {"left", "a"}
Keybind.move.right.keys = {"right", "d"}
Keybind.move.up.keys = {"up", "w"}
Keybind.move.down.keys = {"down", "s"}
Keybind.move.jump.keys = {"z", "space"}
Keybind.move.hook.keys = {"x", 1}
Keybind.move.dash.keys = {"c", 2}
--Move
Keybind.move.left.keys = {"left", "a"}
Keybind.move.right.keys = {"right", "d"}
Keybind.move.up.keys = {"up", "w"}
Keybind.move.down.keys = {"down", "s"}
Keybind.move.jump.keys = {"z", "space"}
Keybind.move.hook.keys = {"x", 1}
Keybind.move.dash.keys = {"c", 2}
--Debug
Keybind.debug.debug = { keys = {"f1"}}
Keybind.debug.reposition = { keys = {"f2"}}
Keybind.debug.reload = { keys = {"f3"}}
Keybind.debug.editor = { keys = {"f4"}}
Keybind.debug.recording = { keys = {"f5"}}
Keybind.debug.playback = { keys = {"f6"}}
--Debug
Keybind.debug.debug = { keys = {"f1"}}
Keybind.debug.reposition = { keys = {"f2"}}
Keybind.debug.reload = { keys = {"f3"}}
Keybind.debug.editor = { keys = {"f4"}}
Keybind.debug.recording = { keys = {"f5"}}
Keybind.debug.playback = { keys = {"f6"}}
-- Editor
Keybind.editor.palette = { keys = {"tab"}}
-- Editor
Keybind.editor.palette = { keys = {"tab"}}
-- Generic
Keybind.generic.lclick = { keys = {1}}
Keybind.generic.rclick = { keys = {2}}
Keybind.generic.lshift = { keys = {"lshift"}}
Keybind.generic.lctrl = { keys = {"lctrl"}}
-- Generic
Keybind.generic.lclick = { keys = {1}}
Keybind.generic.rclick = { keys = {2}}
Keybind.generic.lshift = { keys = {"lshift"}}
Keybind.generic.lctrl = { keys = {"lctrl"}}
end
-- Set default values at start

View File

@ -262,7 +262,7 @@ function TileOptimizeObjects()
local n = 1
local check = true
while check do
check = false
check = false
if LevelTiles[i][j+n] ~= nil
and TileData[LevelTiles[i][j+n].id] ~= nil
then
@ -279,7 +279,7 @@ function TileOptimizeObjects()
local m = 1
local check = true
while check do
check = false
check = false
local checkline = true
-- for as long as line, check
for l = 0, n-1 do

View File

@ -1,5 +1,5 @@
function LocaleLoad(ISO639)
local ISO639 = ISO639 or "ENG"
dofile("data/locale/"..ISO639..".lua")
dofile("data/dialog_sequences.lua")
local ISO639 = ISO639 or "ENG"
dofile("data/locale/"..ISO639..".lua")
dofile("data/dialog_sequences.lua")
end

View File

@ -1,21 +1,21 @@
function math.sign(x)
if x<0 then
return -1
elseif x>0 then
return 1
else
return 0
end
if x<0 then
return -1
elseif x>0 then
return 1
else
return 0
end
end
function Vector(init_x, init_y, final_x, final_y)
local distance_x = final_x - init_x
local distance_y = final_y - init_y
return {distance_x, distance_y}
local distance_x = final_x - init_x
local distance_y = final_y - init_y
return {distance_x, distance_y}
end
function GetVectorValue(vector)
return math.sqrt(vector[1] ^ 2 + vector[2] ^ 2)
return math.sqrt(vector[1] ^ 2 + vector[2] ^ 2)
end
function GetAngleFromVector(x,y)

View File

@ -1,146 +1,146 @@
function MenuDraw(menu)
local font = love.graphics.getFont()
love.graphics.setFont(LocaleFont)
local font = love.graphics.getFont()
love.graphics.setFont(LocaleFont)
-- reset scale
love.graphics.setScale()
-- reset scale
love.graphics.setScale()
if menu == "pause" then
MenuDrawPauseScreen()
elseif menu == "dialog" then
MenuDrawDialog()
end
if menu == "pause" then
MenuDrawPauseScreen()
elseif menu == "dialog" then
MenuDrawDialog()
end
for _, element in pairs(UIElement) do
element:Draw()
end
for _, element in pairs(UIElement) do
element:Draw()
end
love.graphics.setFont(font)
love.graphics.setFont(font)
end
function MenuDrawPauseScreen()
-- Parameters
local pauseWidth = 640
local pauseHeight = 480
local pauseX = (game.width/2)-(pauseWidth/2)
local pauseY = (game.height/2)-(pauseHeight/2)
local mouse_x, mouse_y = love.mouse.getPosition()
-- Base items
love.graphics.setColor(0,0,0,0.3)
love.graphics.rectangle("fill", 0, 0, game.width, game.height)
love.graphics.setColor(1,1,1,1)
love.graphics.rectangle("fill", pauseX, pauseY, pauseWidth, pauseHeight)
-- Parameters
local pauseWidth = 640
local pauseHeight = 480
local pauseX = (game.width/2)-(pauseWidth/2)
local pauseY = (game.height/2)-(pauseHeight/2)
local mouse_x, mouse_y = love.mouse.getPosition()
-- Base items
love.graphics.setColor(0,0,0,0.3)
love.graphics.rectangle("fill", 0, 0, game.width, game.height)
love.graphics.setColor(1,1,1,1)
love.graphics.rectangle("fill", pauseX, pauseY, pauseWidth, pauseHeight)
end
function MenuDrawDialog()
end
function MenuStep(menu)
-- first get mouse
local mouse_x, mouse_y = love.mouse.getPosition()
for _, element in pairs(UIElement) do
if element.type == "Button" then
element:checkMouse(mouse_x, mouse_y)
elseif element.type == "Dialog" then
element:checkConfirm()
end
end
if menu == 0 then
elseif menu == "pause" then
MenuStepPauseScreen()
elseif menu == "dialog" then
MenuStepDialog()
end
-- first get mouse
local mouse_x, mouse_y = love.mouse.getPosition()
for _, element in pairs(UIElement) do
if element.type == "Button" then
element:checkMouse(mouse_x, mouse_y)
elseif element.type == "Dialog" then
element:checkConfirm()
end
end
if menu == 0 then
elseif menu == "pause" then
MenuStepPauseScreen()
elseif menu == "dialog" then
MenuStepDialog()
end
end
function MenuStepPauseScreen()
if PauseResume:getVariable() == true then
PauseResume = nil
PauseOptions = nil
PauseExit = nil
MenuExit()
elseif PauseExit:getVariable() == true then
love.event.quit()
end
if PauseResume:getVariable() == true then
PauseResume = nil
PauseOptions = nil
PauseExit = nil
MenuExit()
elseif PauseExit:getVariable() == true then
love.event.quit()
end
end
function MenuStepDialog()
if DialogContainer.value >= DialogContainer.target_value then
DialogContainer = nil
MenuExit()
end
if DialogContainer.value >= DialogContainer.target_value then
DialogContainer = nil
MenuExit()
end
end
function MenuClear()
for _, element in pairs(UIElement) do
element = nil
end
UIElement = {}
for _, element in pairs(UIElement) do
element = nil
end
UIElement = {}
end
function MenuExit(to)
MenuClear()
local to = to or "no"
menu_type = to
MenuClear()
local to = to or "no"
menu_type = to
end
function MenuInit(menu,parameter)
-- main menu
if menu == "pause" then
MenuInitPauseScreen()
elseif menu == "dialog" then
if parameter == nil then
parameter = DialogSequence.Example
end
MenuInitDialog(parameter)
end
-- main menu
if menu == "pause" then
MenuInitPauseScreen()
elseif menu == "dialog" then
if parameter == nil then
parameter = DialogSequence.Example
end
MenuInitDialog(parameter)
end
end
function MenuInitDialog(parameter)
DialogContainer = interfaceDialog:New()
DialogContainer:loadSequence(parameter)
DialogContainer = interfaceDialog:New()
DialogContainer:loadSequence(parameter)
end
function MenuInitPauseScreen()
local buttonStandard = {width = 200, height = 30, separation = 10}
-- elements
PauseResume = interfaceButton:New(
game.width/2,
game.height/2-buttonStandard.height-buttonStandard.separation,
buttonStandard.width,
buttonStandard.height,
{false,true},
1,
{
text = Locale.ui.pause_screen_resume,
color = {0,0,0.5},
color2 = {1,1,1}
}
)
PauseOptions = interfaceButton:New(
game.width/2,
game.height/2,
buttonStandard.width,
buttonStandard.height,
{false,true},
1,
{
text = Locale.ui.pause_screen_options,
color = {0,0,0.5},
color2 = {1,1,1}
}
)
PauseExit = interfaceButton:New(
game.width/2,
game.height/2+buttonStandard.height+buttonStandard.separation,
buttonStandard.width,
buttonStandard.height,
{false,true},
1,
{
text = Locale.ui.pause_screen_exit,
color = {0,0,0.5},
color2 = {1,1,1}
}
)
local buttonStandard = {width = 200, height = 30, separation = 10}
-- elements
PauseResume = interfaceButton:New(
game.width/2,
game.height/2-buttonStandard.height-buttonStandard.separation,
buttonStandard.width,
buttonStandard.height,
{false,true},
1,
{
text = Locale.ui.pause_screen_resume,
color = {0,0,0.5},
color2 = {1,1,1}
}
)
PauseOptions = interfaceButton:New(
game.width/2,
game.height/2,
buttonStandard.width,
buttonStandard.height,
{false,true},
1,
{
text = Locale.ui.pause_screen_options,
color = {0,0,0.5},
color2 = {1,1,1}
}
)
PauseExit = interfaceButton:New(
game.width/2,
game.height/2+buttonStandard.height+buttonStandard.separation,
buttonStandard.width,
buttonStandard.height,
{false,true},
1,
{
text = Locale.ui.pause_screen_exit,
color = {0,0,0.5},
color2 = {1,1,1}
}
)
end

View File

@ -7,7 +7,7 @@ function LoadedObjects.DrawCollisions()
end
for _, platform in pairs(LoadedObjects.Platforms) do
if platform.disable == true then platform:Draw(2) end
if platform.disable == true then platform:Draw(2) end
if platform.disable == false then platform:Draw(1) end
end
@ -37,7 +37,7 @@ function isThereObjectAt(x,y,objectType)
end
function isThereCollisionAt(x,y)
if x >= 0 and x < #CollisionTable
if x >= 0 and x < #CollisionTable
and y >= 0 and y < #CollisionTable[0] then
return CollisionTable[math.floor(y)][math.floor(x)]
end

View File

@ -1,50 +1,50 @@
Particle = Entity:New(x,y)
function Particle:New(x,y,particle_data)
local o = Entity:New(x,y)
function Particle:New(x,y,particle_data)
local o = Entity:New(x,y)
o.pos = {x = x, y = y}
o.pos = {x = x, y = y}
o.speed = particle_data.speed or 0
o.direction = particle_data.direction or o.direction
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation
o.sprite_offset = particle_data.sprite_offset or o.sprite_offset
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
o.sprite_alpha_base = o.sprite_alpha
o.speed = particle_data.speed or 0
o.direction = particle_data.direction or o.direction
o.sprite_rotation = particle_data.sprite_rotation or o.sprite_rotation
o.sprite_offset = particle_data.sprite_offset or o.sprite_offset
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
o.sprite_alpha_base = o.sprite_alpha
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
o.animation_active = particle_data.animation_active or false
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
o.animation_active = particle_data.animation_active or false
o.time = 0.5
o.timer = 0
o.time = 0.5
o.timer = 0
o.vel = {
x = o.speed * math.cos(o.direction),
y = o.speed * math.sin(o.direction)
}
o.vel = {
x = o.speed * math.cos(o.direction),
y = o.speed * math.sin(o.direction)
}
if particle_data.light ~= nil then
o.lightRange = particle_data.light
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
end
if particle_data.light ~= nil then
o.lightRange = particle_data.light
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
end
-- animations
o.body = Animation:New(particle_data.animation)
o:centerOffset(o.body)
if not o.animation_active then
o.body.speed = 0
end
-- animations
o.body = Animation:New(particle_data.animation)
o:centerOffset(o.body)
if not o.animation_active then
o.body.speed = 0
end
table.insert(LoadedParticles,o)
o.id = #LoadedParticles
table.insert(LoadedParticles,o)
o.id = #LoadedParticles
setmetatable(o, self)
self.__index = self
return o
end
setmetatable(o, self)
self.__index = self
return o
end
function Particle:Kill()
if self.light ~= nil then
@ -62,21 +62,21 @@ function Particle:Kill()
end
function Particle:HandleAnimation()
self.body:Animate()
self.timer = self.timer + current_dt
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
if self.light ~= nil then
self.light.range = self.lightRange * self.sprite_alpha/2
end
if self.sprite_alpha < 0 then self:Kill() end
self:Draw(self.body)
self.body:Animate()
self.timer = self.timer + current_dt
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
if self.light ~= nil then
self.light.range = self.lightRange * self.sprite_alpha/2
end
if self.sprite_alpha < 0 then self:Kill() end
self:Draw(self.body)
end
function Particle:DoPhysics()
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, objects.collisions) then
self.pos.x = self.pos.x + self.vel.x
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, objects.collisions) then
self.pos.y = self.pos.y + self.vel.y
end
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, objects.collisions) then
self.pos.x = self.pos.x + self.vel.x
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, objects.collisions) then
self.pos.y = self.pos.y + self.vel.y
end
end

View File

@ -1,8 +1,8 @@
UIElement = {}
function AddElement(self)
table.insert(UIElement,self)
self.id = #UIElement
table.insert(UIElement,self)
self.id = #UIElement
end
require "code/ui/button"

View File

@ -3,99 +3,99 @@ interfaceButton = {type = "Button"}
-- centered buttons
function interfaceButton:New(x,y,w,h,table_values,value,style)
o = {}
o.pos = {
x = x,
y = y
}
o.size = {
w = w,
h = h
o = {}
o.pos = {
x = x,
y = y
}
o.size = {
w = w,
h = h
}
}
o.values = table_values or {false,true}
o.value = value or 1
o.target_variable = o.values[o.value]
o.values = table_values or {false,true}
o.value = value or 1
o.target_variable = o.values[o.value]
o.clicked = false
o.clicked = false
o.style = {
text = style.text or nil,
color = style.color or {1,1,1},
color2 = style.color2 or {0,0,0},
--color3 = style.color3 or style.color2 or {0,0,0},
alpha = style.alpha or 1,
scale = style.scale or 1,
scale_x = style.scale_x or 1,
scale_y = style.scale_y or 1,
scale_proportion = 1
}
o.style = {
text = style.text or nil,
color = style.color or {1,1,1},
color2 = style.color2 or {0,0,0},
--color3 = style.color3 or style.color2 or {0,0,0},
alpha = style.alpha or 1,
scale = style.scale or 1,
scale_x = style.scale_x or 1,
scale_y = style.scale_y or 1,
scale_proportion = 1
}
o.style.unselected = {
scale_proportion = o.style.scale_proportion
}
o.style.unselected = {
scale_proportion = o.style.scale_proportion
}
o.style.selected = {
scale_proportion = 1.5
}
o.style.selected = {
scale_proportion = 1.5
}
AddElement(o)
AddElement(o)
setmetatable(o, self)
self.__index = self
setmetatable(o, self)
self.__index = self
return o
return o
end
function interfaceButton:getVariable()
return self.target_variable
return self.target_variable
end
function interfaceButton:checkMouse(mouse_x, mouse_y)
if not self.clicked
and mouse_x < self.pos.x + self.size.w/2
and mouse_x > self.pos.x - self.size.w/2
and mouse_y < self.pos.y + self.size.h/2
and mouse_y > self.pos.y - self.size.h/2 then
self.style.scale_proportion = o.style.selected.scale_proportion
if love.mouse.isDown(1) then
self.clicked = true
self.value = self.value + 1
if self.value > #self.values then
self.value = 1
end
self.target_variable = self.values[self.value]
end
elseif not love.mouse.isDown(1) then
self.style.scale_proportion = o.style.unselected.scale_proportion
self.clicked = false
end
if not self.clicked
and mouse_x < self.pos.x + self.size.w/2
and mouse_x > self.pos.x - self.size.w/2
and mouse_y < self.pos.y + self.size.h/2
and mouse_y > self.pos.y - self.size.h/2 then
self.style.scale_proportion = o.style.selected.scale_proportion
if love.mouse.isDown(1) then
self.clicked = true
self.value = self.value + 1
if self.value > #self.values then
self.value = 1
end
self.target_variable = self.values[self.value]
end
elseif not love.mouse.isDown(1) then
self.style.scale_proportion = o.style.unselected.scale_proportion
self.clicked = false
end
end
function interfaceButton:Draw()
local c1, c2, c3, a = love.graphics.getColor()
local c1, c2, c3, a = love.graphics.getColor()
love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha)
love.graphics.rectangle(
"fill",
self.pos.x-(self.size.w/2)*self.style.scale_x*self.style.scale_proportion,
self.pos.y-(self.size.h/2)*self.style.scale_y*self.style.scale_proportion,
self.size.w *self.style.scale_x*self.style.scale_proportion,
self.size.h *self.style.scale_y*self.style.scale_proportion)
love.graphics.setColor(self.style.color2[1],self.style.color2[2],self.style.color2[3],self.style.alpha)
love.graphics.rectangle(
"line",
self.pos.x-(self.size.w/2)*self.style.scale_x*self.style.scale_proportion,
self.pos.y-(self.size.h/2)*self.style.scale_y*self.style.scale_proportion,
self.size.w *self.style.scale_x*self.style.scale_proportion,
self.size.h *self.style.scale_y*self.style.scale_proportion)
love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha)
love.graphics.rectangle(
"fill",
self.pos.x-(self.size.w/2)*self.style.scale_x*self.style.scale_proportion,
self.pos.y-(self.size.h/2)*self.style.scale_y*self.style.scale_proportion,
self.size.w *self.style.scale_x*self.style.scale_proportion,
self.size.h *self.style.scale_y*self.style.scale_proportion)
love.graphics.setColor(self.style.color2[1],self.style.color2[2],self.style.color2[3],self.style.alpha)
love.graphics.rectangle(
"line",
self.pos.x-(self.size.w/2)*self.style.scale_x*self.style.scale_proportion,
self.pos.y-(self.size.h/2)*self.style.scale_y*self.style.scale_proportion,
self.size.w *self.style.scale_x*self.style.scale_proportion,
self.size.h *self.style.scale_y*self.style.scale_proportion)
if self.style.text ~= nil then
love.graphics.print(self.style.text,self.pos.x,self.pos.y)
else
love.graphics.print(tostring(self.target_variable),self.pos.x,self.pos.y)
end
love.graphics.setColor(c1,c2,c3,a)
if self.style.text ~= nil then
love.graphics.print(self.style.text,self.pos.x,self.pos.y)
else
love.graphics.print(tostring(self.target_variable),self.pos.x,self.pos.y)
end
love.graphics.setColor(c1,c2,c3,a)
end

View File

@ -2,96 +2,96 @@ interfaceDialog = {type = "Dialog"}
-- dialog boxes
function interfaceDialog:New(style)
o = {}
o.pos = {
x = 0,
y = game.height*80/100
}
o.size = {
w = game.width,
h = game.height*20/100
o = {}
o.pos = {
x = 0,
y = game.height*80/100
}
o.size = {
w = game.width,
h = game.height*20/100
}
}
o.value = 0
o.target_value = 0
o.value = 0
o.target_value = 0
local style = {}
local style = {}
o.style = {
content = style.content or nil,
color = style.color or {1,1,1},
color2 = style.color2 or {0,0,0},
--color3 = style.color3 or style.color2 or {0,0,0},
alpha = style.alpha or 1,
scale = style.scale or 1,
scale_x = style.scale_x or 1,
scale_y = style.scale_y or 1,
scale_proportion = 1
}
o.style = {
content = style.content or nil,
color = style.color or {1,1,1},
color2 = style.color2 or {0,0,0},
--color3 = style.color3 or style.color2 or {0,0,0},
alpha = style.alpha or 1,
scale = style.scale or 1,
scale_x = style.scale_x or 1,
scale_y = style.scale_y or 1,
scale_proportion = 1
}
AddElement(o)
AddElement(o)
setmetatable(o, self)
self.__index = self
setmetatable(o, self)
self.__index = self
return o
return o
end
function interfaceDialog:updateContents()
if self.value < self.target_value then
self.contents = self.sequence[self.value]
if self.contents[1] == nil then self.contents[1] = "" end
if self.contents[2] == nil then self.contents[2] = "" end
if self.contents[3] == nil then self.contents[3] = "" end
end
if self.value < self.target_value then
self.contents = self.sequence[self.value]
if self.contents[1] == nil then self.contents[1] = "" end
if self.contents[2] == nil then self.contents[2] = "" end
if self.contents[3] == nil then self.contents[3] = "" end
end
end
function interfaceDialog:loadSequence(sequence)
self.sequence = sequence
self.value = 1
self.target_value = 1+#sequence
self:updateContents()
self.sequence = sequence
self.value = 1
self.target_value = 1+#sequence
self:updateContents()
end
function interfaceDialog:checkConfirm()
if not self.clicked then
if love.mouse.isDown(1) then
self.clicked = true
self.value = self.value + 1
logPrint("Dialog: "..self.value.." of "..self.target_value)
self:updateContents()
end
elseif not love.mouse.isDown(1) then
self.clicked = false
end
if not self.clicked then
if love.mouse.isDown(1) then
self.clicked = true
self.value = self.value + 1
logPrint("Dialog: "..self.value.." of "..self.target_value)
self:updateContents()
end
elseif not love.mouse.isDown(1) then
self.clicked = false
end
end
function interfaceDialog:Draw()
local c1, c2, c3, a = love.graphics.getColor()
local c1, c2, c3, a = love.graphics.getColor()
love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha)
love.graphics.rectangle(
"fill",
self.pos.x*self.style.scale_x*self.style.scale_proportion,
self.pos.y*self.style.scale_y*self.style.scale_proportion,
self.size.w*self.style.scale_x*self.style.scale_proportion,
self.size.h*self.style.scale_y*self.style.scale_proportion)
love.graphics.setColor(self.style.color2[1],self.style.color2[2],self.style.color2[3],self.style.alpha)
love.graphics.rectangle(
"line",
self.pos.x*self.style.scale_x*self.style.scale_proportion,
self.pos.y*self.style.scale_y*self.style.scale_proportion,
self.size.w*self.style.scale_x*self.style.scale_proportion,
self.size.h*self.style.scale_y*self.style.scale_proportion)
love.graphics.setColor(self.style.color[1],self.style.color[2],self.style.color[3],self.style.alpha)
love.graphics.rectangle(
"fill",
self.pos.x*self.style.scale_x*self.style.scale_proportion,
self.pos.y*self.style.scale_y*self.style.scale_proportion,
self.size.w*self.style.scale_x*self.style.scale_proportion,
self.size.h*self.style.scale_y*self.style.scale_proportion)
love.graphics.setColor(self.style.color2[1],self.style.color2[2],self.style.color2[3],self.style.alpha)
love.graphics.rectangle(
"line",
self.pos.x*self.style.scale_x*self.style.scale_proportion,
self.pos.y*self.style.scale_y*self.style.scale_proportion,
self.size.w*self.style.scale_x*self.style.scale_proportion,
self.size.h*self.style.scale_y*self.style.scale_proportion)
if self.contents ~= nil then
love.graphics.printf(self.contents[2],self.pos.x+10,self.pos.y+(self.size.h/2),100,"left")
love.graphics.printf(self.contents[1],self.pos.x+(self.size.w/2),self.pos.y+(self.size.h/2),100,"center")
love.graphics.printf(self.contents[3],self.pos.x+(self.size.w)-10,self.pos.y+(self.size.h/2),100,"right")
else
love.graphics.printf("ERROR",self.pos.x+(self.size.w/2),self.pos.y+(self.size.h/2),100,"center")
end
if self.contents ~= nil then
love.graphics.printf(self.contents[2],self.pos.x+10,self.pos.y+(self.size.h/2),100,"left")
love.graphics.printf(self.contents[1],self.pos.x+(self.size.w/2),self.pos.y+(self.size.h/2),100,"center")
love.graphics.printf(self.contents[3],self.pos.x+(self.size.w)-10,self.pos.y+(self.size.h/2),100,"right")
else
love.graphics.printf("ERROR",self.pos.x+(self.size.w/2),self.pos.y+(self.size.h/2),100,"center")
end
love.graphics.setColor(c1,c2,c3,a)
love.graphics.setColor(c1,c2,c3,a)
end

View File

@ -1,7 +1,7 @@
DialogSequence = {}
DialogSequence.Example = {
{Locale.dialogue.example[1],Locale.name.fairy},
{Locale.dialogue.example[2],Locale.name.chaos},
{Locale.dialogue.example[3],Locale.name.life}
{Locale.dialogue.example[1],Locale.name.fairy},
{Locale.dialogue.example[2],Locale.name.chaos},
{Locale.dialogue.example[3],Locale.name.life}
}

View File

@ -2,7 +2,7 @@ return {
name = "test",
tileset = tileset.library,
properties = {
darkness = true
darkness = true
},
tiles = {
{ 1, 4, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},

View File

@ -1,6 +1,6 @@
music = {}
music.placeholder = {
path = "assets/music/communistmanifesto.mp3",
type = "stream",
loop = true
path = "assets/music/communistmanifesto.mp3",
type = "stream",
loop = true
}

View File

@ -1,23 +1,23 @@
Shader = {}
Shader.RadiusGradient = love.graphics.newShader[[
uniform float pos_x;
uniform float pos_y;
uniform float range;
uniform float scale;
uniform float pos_x;
uniform float pos_y;
uniform float range;
uniform float scale;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
float distance_x = pos_x - screen_coords.x / scale;
float distance_y = pos_y - screen_coords.y / scale;
float distance = sqrt( pow(distance_x,2) + pow(distance_y,2) ) ;
if (distance < range){
float alpha = 1-(5*distance/range);
if (pixel.a > alpha){
pixel.a = alpha;
}
}
return pixel * color * color;
}
float distance_x = pos_x - screen_coords.x / scale;
float distance_y = pos_y - screen_coords.y / scale;
float distance = sqrt( pow(distance_x,2) + pow(distance_y,2) ) ;
if (distance < range){
float alpha = 1-(5*distance/range);
if (pixel.a > alpha){
pixel.a = alpha;
}
}
return pixel * color * color;
}
]]

View File

@ -1,349 +1,349 @@
local properties = {}
properties[1] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[2] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[3] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[4] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[5] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[6] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[7] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[8] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[9] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[10] = {
type = "half_bottom",
depth = "foreground"
type = "half_bottom",
depth = "foreground"
}
properties[11] = {
type = "half_bottom",
depth = "foreground"
type = "half_bottom",
depth = "foreground"
}
properties[12] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[13] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[14] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[15] = {
type = "half_right",
depth = "foreground"
type = "half_right",
depth = "foreground"
}
properties[16] = {
type = "half_left",
depth = "foreground"
type = "half_left",
depth = "foreground"
}
properties[17] = {
type = "half_bottom",
depth = "foreground"
type = "half_bottom",
depth = "foreground"
}
properties[18] = {
type = "half_top",
depth = "foreground"
type = "half_top",
depth = "foreground"
}
properties[19] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[20] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[21] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[22] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[23] = {
type = "half_top",
depth = "foreground"
type = "half_top",
depth = "foreground"
}
properties[24] = {
type = "half_top",
depth = "foreground"
type = "half_top",
depth = "foreground"
}
properties[25] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[26] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[27] = {
type = "ramp2_bot_right_half",
depth = "foreground"
type = "ramp2_bot_right_half",
depth = "foreground"
}
properties[28] = {
type = "ramp2_bot_right_whole",
depth = "foreground"
type = "ramp2_bot_right_whole",
depth = "foreground"
}
properties[29] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[30] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[31] = {
type = "ramp2_bot_left_whole",
depth = "foreground"
type = "ramp2_bot_left_whole",
depth = "foreground"
}
properties[32] = {
type = "ramp2_bot_left_half",
depth = "foreground"
type = "ramp2_bot_left_half",
depth = "foreground"
}
properties[33] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[34] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[35] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[36] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[37] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[38] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[39] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[40] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[41] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[42] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[43] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[44] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[45] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[46] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[47] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[48] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[49] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[50] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[51] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[52] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[53] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[54] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[55] = {
type = "empty",
depth = "foreground",
light = 60
type = "empty",
depth = "foreground",
light = 60
}
properties[56] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[57] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[58] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[59] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[60] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[61] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[62] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[63] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[64] = {
type = "empty",
depth = "foreground"
type = "empty",
depth = "foreground"
}
properties[65] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[66] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[67] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[68] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[119] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
return properties

View File

@ -1,94 +1,94 @@
local properties = {}
properties[1] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[2] = {
type = "emtpy",
depth = "foreground"
type = "emtpy",
depth = "foreground"
}
properties[3] = {
type = "emtpy",
depth = "foreground"
type = "emtpy",
depth = "foreground"
}
properties[4] = {
type = "emtpy",
depth = "foreground"
type = "emtpy",
depth = "foreground"
}
properties[5] = {
type = "emtpy",
depth = "background"
type = "emtpy",
depth = "background"
}
properties[6] = {
type = "emtpy",
depth = "background"
type = "emtpy",
depth = "background"
}
properties[7] = {
type = "emtpy",
depth = "background"
type = "emtpy",
depth = "background"
}
properties[13] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[14] = {
type = "whole",
depth = "foreground"
type = "whole",
depth = "foreground"
}
properties[25] = {
overlay = {17,19,21,23},
type = "emtpy",
depth = "background"
overlay = {17,19,21,23},
type = "emtpy",
depth = "background"
}
properties[26] = {
overlay = {18,20,22,24},
type = "emtpy",
depth = "background"
overlay = {18,20,22,24},
type = "emtpy",
depth = "background"
}
properties[37] = {
overlay = {29,31,33,35,41,43,45,47},
type = "emtpy",
depth = "background"
overlay = {29,31,33,35,41,43,45,47},
type = "emtpy",
depth = "background"
}
properties[38] = {
overlay = {30,32,34,36,42,44,46,48},
type = "emtpy",
depth = "background"
overlay = {30,32,34,36,42,44,46,48},
type = "emtpy",
depth = "background"
}
properties[49] = {
overlay = {53,55,57,59},
type = "emtpy",
depth = "background"
overlay = {53,55,57,59},
type = "emtpy",
depth = "background"
}
properties[50] = {
overlay = {54,56,58,60},
type = "emtpy",
depth = "background"
overlay = {54,56,58,60},
type = "emtpy",
depth = "background"
}
properties[61] = {
type = "bottom_hazard",
depth = "foreground"
type = "bottom_hazard",
depth = "foreground"
}
properties[62] = {
type = "top_hazard",
depth = "foreground"
type = "top_hazard",
depth = "foreground"
}
return properties