add bolt ghosts
This commit is contained in:
parent
6e754155dc
commit
6ab0b2eb4a
@ -23,7 +23,9 @@ local function loadAsepriteSprite(filename)
|
||||
local frames = {}
|
||||
local tags = {}
|
||||
local layers = {}
|
||||
local first_tag
|
||||
|
||||
love.graphics.push("transform")
|
||||
love.graphics.origin()
|
||||
|
||||
for i, ase_frame in ipairs(ase.header.frames) do
|
||||
for _, chunk in ipairs(ase_frame.chunks) do
|
||||
@ -50,11 +52,6 @@ local function loadAsepriteSprite(filename)
|
||||
love.graphics.setCanvas()
|
||||
elseif chunk.type == TAG_CHUNK then
|
||||
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
|
||||
-- but in lua, everthing starts in 1
|
||||
tag.to = tag.to + 1
|
||||
@ -68,6 +65,8 @@ local function loadAsepriteSprite(filename)
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.push()
|
||||
|
||||
for _, tag in pairs(tags) do
|
||||
local variant = {}
|
||||
sprite.variants[tag.name] = variant
|
||||
@ -77,7 +76,7 @@ local function loadAsepriteSprite(filename)
|
||||
end
|
||||
|
||||
if not sprite.variants.default then
|
||||
sprite.variants.default = {frames[0]}
|
||||
sprite.variants.default = {frames[1]}
|
||||
end
|
||||
|
||||
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
|
||||
local tileSize = 16
|
||||
local screenW, screenH = love.graphics.getDimensions()
|
||||
local w = 16 * tileSize
|
||||
local h = 16 * screenH/screenW * tileSize
|
||||
self.canvas = love.graphics.newCanvas(w, h)
|
||||
self.screenWidth = 16 * tileSize
|
||||
self.screenHeight = 16 * screenH/screenW * tileSize
|
||||
|
||||
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, border, 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)
|
||||
if btn == quit_btn then
|
||||
love.event.quit()
|
||||
elseif btn == host_btn then
|
||||
Gamestate.switch(require("states.main"), self.host_socket)
|
||||
end
|
||||
end)
|
||||
end
|
||||
@ -107,7 +110,7 @@ end
|
||||
function MainMenu:draw()
|
||||
local ScreenScaler = self.ecs:getSystem(require("systems.screen-scaler"))
|
||||
|
||||
ScreenScaler:start(self.canvas)
|
||||
ScreenScaler:start(self.screenWidth, self.screenHeight)
|
||||
self.ecs:emit("draw")
|
||||
ScreenScaler:finish()
|
||||
|
||||
|
@ -52,11 +52,8 @@ function MainState:refreshDownscaledCanvas(map)
|
||||
end
|
||||
end
|
||||
|
||||
self.downscaled_canvas = love.graphics.newCanvas(
|
||||
map.width * map.tilewidth,
|
||||
map.height * map.tileheight
|
||||
)
|
||||
self.downscaled_canvas:setFilter("nearest", "nearest")
|
||||
self.screenWidth = map.width * map.tilewidth
|
||||
self.screenHeight = map.height * map.tileheight
|
||||
end
|
||||
|
||||
function MainState:update(dt)
|
||||
@ -96,7 +93,7 @@ end
|
||||
function MainState:draw()
|
||||
local ScreenScaler = self.ecs:getSystem(require("systems.screen-scaler"))
|
||||
|
||||
ScreenScaler:start(self.downscaled_canvas)
|
||||
ScreenScaler:start(self.screenWidth, self.screenHeight)
|
||||
self.ecs:emit("draw")
|
||||
ScreenScaler:finish()
|
||||
end
|
||||
|
@ -232,15 +232,27 @@ end
|
||||
|
||||
function Player:draw()
|
||||
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 pos = e.pos + e.aim_dir * AIMED_BOLT_DISTANCE*0
|
||||
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)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user