add bolt ghosts
This commit is contained in:
parent
6e754155dc
commit
6ab0b2eb4a
@ -23,7 +23,9 @@ local function loadAsepriteSprite(filename)
|
|||||||
local frames = {}
|
local frames = {}
|
||||||
local tags = {}
|
local tags = {}
|
||||||
local layers = {}
|
local layers = {}
|
||||||
local first_tag
|
|
||||||
|
love.graphics.push("transform")
|
||||||
|
love.graphics.origin()
|
||||||
|
|
||||||
for i, ase_frame in ipairs(ase.header.frames) do
|
for i, ase_frame in ipairs(ase.header.frames) do
|
||||||
for _, chunk in ipairs(ase_frame.chunks) do
|
for _, chunk in ipairs(ase_frame.chunks) do
|
||||||
@ -50,11 +52,6 @@ local function loadAsepriteSprite(filename)
|
|||||||
love.graphics.setCanvas()
|
love.graphics.setCanvas()
|
||||||
elseif chunk.type == TAG_CHUNK then
|
elseif chunk.type == TAG_CHUNK then
|
||||||
for j, tag in ipairs(chunk.data.tags) do
|
for j, tag in ipairs(chunk.data.tags) do
|
||||||
-- first tag as default
|
|
||||||
if j == 1 then
|
|
||||||
first_tag = tag.name
|
|
||||||
end
|
|
||||||
|
|
||||||
-- aseprite use 0 notation to begin
|
-- aseprite use 0 notation to begin
|
||||||
-- but in lua, everthing starts in 1
|
-- but in lua, everthing starts in 1
|
||||||
tag.to = tag.to + 1
|
tag.to = tag.to + 1
|
||||||
@ -68,6 +65,8 @@ local function loadAsepriteSprite(filename)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
love.graphics.push()
|
||||||
|
|
||||||
for _, tag in pairs(tags) do
|
for _, tag in pairs(tags) do
|
||||||
local variant = {}
|
local variant = {}
|
||||||
sprite.variants[tag.name] = variant
|
sprite.variants[tag.name] = variant
|
||||||
@ -77,7 +76,7 @@ local function loadAsepriteSprite(filename)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not sprite.variants.default then
|
if not sprite.variants.default then
|
||||||
sprite.variants.default = {frames[0]}
|
sprite.variants.default = {frames[1]}
|
||||||
end
|
end
|
||||||
|
|
||||||
return sprite
|
return sprite
|
||||||
|
BIN
src/data/sprites/bolt-ghost.aseprite
Normal file
BIN
src/data/sprites/bolt-ghost.aseprite
Normal file
Binary file not shown.
@ -50,11 +50,12 @@ function MainMenu:init()
|
|||||||
do
|
do
|
||||||
local tileSize = 16
|
local tileSize = 16
|
||||||
local screenW, screenH = love.graphics.getDimensions()
|
local screenW, screenH = love.graphics.getDimensions()
|
||||||
local w = 16 * tileSize
|
self.screenWidth = 16 * tileSize
|
||||||
local h = 16 * screenH/screenW * tileSize
|
self.screenHeight = 16 * screenH/screenW * tileSize
|
||||||
self.canvas = love.graphics.newCanvas(w, h)
|
|
||||||
|
|
||||||
local border = 2.5
|
local border = 2.5
|
||||||
|
local w = self.screenWidth
|
||||||
|
local h = self.screenHeight
|
||||||
self.ecs:queue{ collider = {0, 0, w, border} }
|
self.ecs:queue{ collider = {0, 0, w, border} }
|
||||||
self.ecs:queue{ collider = {0, 0, border, h} }
|
self.ecs:queue{ collider = {0, 0, border, h} }
|
||||||
self.ecs:queue{ collider = {w-border, 0, w, h} }
|
self.ecs:queue{ collider = {w-border, 0, w, h} }
|
||||||
@ -80,6 +81,8 @@ function MainMenu:init()
|
|||||||
self.ecs:on("on_btn_pressed", function(btn)
|
self.ecs:on("on_btn_pressed", function(btn)
|
||||||
if btn == quit_btn then
|
if btn == quit_btn then
|
||||||
love.event.quit()
|
love.event.quit()
|
||||||
|
elseif btn == host_btn then
|
||||||
|
Gamestate.switch(require("states.main"), self.host_socket)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -107,7 +110,7 @@ end
|
|||||||
function MainMenu:draw()
|
function MainMenu:draw()
|
||||||
local ScreenScaler = self.ecs:getSystem(require("systems.screen-scaler"))
|
local ScreenScaler = self.ecs:getSystem(require("systems.screen-scaler"))
|
||||||
|
|
||||||
ScreenScaler:start(self.canvas)
|
ScreenScaler:start(self.screenWidth, self.screenHeight)
|
||||||
self.ecs:emit("draw")
|
self.ecs:emit("draw")
|
||||||
ScreenScaler:finish()
|
ScreenScaler:finish()
|
||||||
|
|
||||||
|
@ -52,11 +52,8 @@ function MainState:refreshDownscaledCanvas(map)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.downscaled_canvas = love.graphics.newCanvas(
|
self.screenWidth = map.width * map.tilewidth
|
||||||
map.width * map.tilewidth,
|
self.screenHeight = map.height * map.tileheight
|
||||||
map.height * map.tileheight
|
|
||||||
)
|
|
||||||
self.downscaled_canvas:setFilter("nearest", "nearest")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function MainState:update(dt)
|
function MainState:update(dt)
|
||||||
@ -96,7 +93,7 @@ end
|
|||||||
function MainState:draw()
|
function MainState:draw()
|
||||||
local ScreenScaler = self.ecs:getSystem(require("systems.screen-scaler"))
|
local ScreenScaler = self.ecs:getSystem(require("systems.screen-scaler"))
|
||||||
|
|
||||||
ScreenScaler:start(self.downscaled_canvas)
|
ScreenScaler:start(self.screenWidth, self.screenHeight)
|
||||||
self.ecs:emit("draw")
|
self.ecs:emit("draw")
|
||||||
ScreenScaler:finish()
|
ScreenScaler:finish()
|
||||||
end
|
end
|
||||||
|
@ -232,15 +232,27 @@ end
|
|||||||
|
|
||||||
function Player:draw()
|
function Player:draw()
|
||||||
for _, e in ipairs(self.pool.groups.controllable_player.entities) do
|
for _, e in ipairs(self.pool.groups.controllable_player.entities) do
|
||||||
if e.aim_dir.x ~= 0 or e.aim_dir.y ~= 0 then
|
if (e.aim_dir.x ~= 0 or e.aim_dir.y ~= 0) and #e.bolts > 0 then
|
||||||
local boltSystem = self.pool:getSystem(require("systems.bolt"))
|
local boltSystem = self.pool:getSystem(require("systems.bolt"))
|
||||||
local pos = e.pos + e.aim_dir * AIMED_BOLT_DISTANCE*0
|
local pos = e.pos + e.aim_dir * AIMED_BOLT_DISTANCE*0
|
||||||
local vel = (e.aim_dir * e.bolt_speed).normalized * AIMED_BOLT_DISTANCE*1
|
local vel = (e.aim_dir * e.bolt_speed).normalized * AIMED_BOLT_DISTANCE*1
|
||||||
|
|
||||||
local point_amount = 5
|
local point_amount = 8
|
||||||
local points = boltSystem:projectTrajectory(pos, vel, point_amount+3)
|
local points = boltSystem:projectTrajectory(pos, vel, point_amount+3)
|
||||||
for i=3, point_amount+3-1 do
|
for i=3, point_amount+3-1 do
|
||||||
love.graphics.circle("line", points[i].x, points[i].y, 5)
|
local ghost = data.sprites["bolt-ghost"]
|
||||||
|
local point = points[i]
|
||||||
|
local frame = ghost.variants.default[1]
|
||||||
|
love.graphics.setColor(1, 1, 1, (point_amount-(i-3))/point_amount)
|
||||||
|
love.graphics.draw(
|
||||||
|
frame.image,
|
||||||
|
point.x,
|
||||||
|
point.y,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
ghost.width/2, ghost.height/2
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user