feat: basic weapon system
This commit is contained in:
parent
a7a0bde8ea
commit
318e297095
9 changed files with 117 additions and 7 deletions
18
sonic-bluestreak.love/assets/sprites/items/ringtoss.lua
Normal file
18
sonic-bluestreak.love/assets/sprites/items/ringtoss.lua
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
return {
|
||||||
|
metadata = {
|
||||||
|
height = 24,
|
||||||
|
width = 32,
|
||||||
|
defaultAnim = "default",
|
||||||
|
oy = 12,
|
||||||
|
ox = 20,
|
||||||
|
},
|
||||||
|
animations = {
|
||||||
|
["default"] = {
|
||||||
|
startAt = 1,
|
||||||
|
endAt = 2,
|
||||||
|
loop = 1,
|
||||||
|
speed = 20,
|
||||||
|
pauseAtEnd = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
16
sonic-bluestreak.love/assets/sprites/items/ringweapon.lua
Normal file
16
sonic-bluestreak.love/assets/sprites/items/ringweapon.lua
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
return {
|
||||||
|
metadata = {
|
||||||
|
height = 16,
|
||||||
|
width = 16,
|
||||||
|
defaultAnim = "default"
|
||||||
|
},
|
||||||
|
animations = {
|
||||||
|
["default"] = {
|
||||||
|
startAt = 1,
|
||||||
|
endAt = 8,
|
||||||
|
loop = 1,
|
||||||
|
speed = 8,
|
||||||
|
pauseAtEnd = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
BIN
sonic-bluestreak.love/assets/sprites/items/ringweapon.png
Normal file
BIN
sonic-bluestreak.love/assets/sprites/items/ringweapon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.9 KiB |
20
sonic-bluestreak.love/datas/gamedata/weapons.lua
Normal file
20
sonic-bluestreak.love/datas/gamedata/weapons.lua
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
return {
|
||||||
|
[1] = {
|
||||||
|
name = "basic",
|
||||||
|
launch = {{0, 0, 0}},
|
||||||
|
zspeed = 0,
|
||||||
|
xspeed = 360,
|
||||||
|
color = {1, 1, 1},
|
||||||
|
explode = false,
|
||||||
|
bounce = false,
|
||||||
|
},
|
||||||
|
[2] = {
|
||||||
|
name = "basic",
|
||||||
|
launch = {{0, 0, 0}},
|
||||||
|
zspeed = 360,
|
||||||
|
xspeed = 360,
|
||||||
|
color = {1, 0.2, 0.2},
|
||||||
|
explode = false,
|
||||||
|
bounce = false,
|
||||||
|
},
|
||||||
|
}
|
|
@ -8,7 +8,9 @@ return {
|
||||||
{"hudring", "assets/gui/hud/ring.png"}
|
{"hudring", "assets/gui/hud/ring.png"}
|
||||||
},
|
},
|
||||||
["sprites"] = {
|
["sprites"] = {
|
||||||
{"ring", "assets/sprites/items/ring"}
|
{"ring", "assets/sprites/items/ring"},
|
||||||
|
{"ringweapon", "assets/sprites/items/ringweapon"},
|
||||||
|
{"ringtoss", "assets/sprites/items/ringtoss"}
|
||||||
},
|
},
|
||||||
["imagefonts"] = {
|
["imagefonts"] = {
|
||||||
{"menu", "assets/gui/fonts/SA2font"},
|
{"menu", "assets/gui/fonts/SA2font"},
|
||||||
|
|
|
@ -4,6 +4,7 @@ local Obj = {}
|
||||||
local cwd = (...):gsub('%.init$', '') .. "."
|
local cwd = (...):gsub('%.init$', '') .. "."
|
||||||
Obj.Player = require(cwd .. "player")
|
Obj.Player = require(cwd .. "player")
|
||||||
Obj.Ring = require(cwd .. "items.ring")
|
Obj.Ring = require(cwd .. "items.ring")
|
||||||
|
Obj.Weapon = require(cwd .. "weapons.parent")
|
||||||
|
|
||||||
Obj.index = {}
|
Obj.index = {}
|
||||||
Obj.index["player"] = Obj.Player
|
Obj.index["player"] = Obj.Player
|
||||||
|
|
|
@ -8,8 +8,8 @@ function Ring:new(world, x, y, z)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Ring:getPicked(player)
|
function Ring:getPicked(player)
|
||||||
--player.rings = player.rings + 1
|
player:setRing(1, true)
|
||||||
--player:addScore(10)
|
player:setScore(10, true)
|
||||||
|
|
||||||
self:destroy()
|
self:destroy()
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,10 @@ local Player = Parent:extend()
|
||||||
local Frame = require("game.modules.gui.frame")
|
local Frame = require("game.modules.gui.frame")
|
||||||
local Statusbar = require("game.modules.gui.status")
|
local Statusbar = require("game.modules.gui.status")
|
||||||
|
|
||||||
|
local WeaponList = require("datas.gamedata.weapons")
|
||||||
|
|
||||||
function Player:new(world, x, y, z, id)
|
function Player:new(world, x, y, z, id)
|
||||||
Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true)
|
Player.super.new(self, world, "player", x, y, 0, 16, 16, 24, false)
|
||||||
self:setGravity(480*2)
|
self:setGravity(480*2)
|
||||||
|
|
||||||
self:init(id)
|
self:init(id)
|
||||||
|
@ -14,6 +16,9 @@ function Player:new(world, x, y, z, id)
|
||||||
self.frame = Frame()
|
self.frame = Frame()
|
||||||
|
|
||||||
self.action = "normal"
|
self.action = "normal"
|
||||||
|
|
||||||
|
self.rings = 0
|
||||||
|
self.score = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:init(id)
|
function Player:init(id)
|
||||||
|
@ -22,7 +27,7 @@ function Player:init(id)
|
||||||
self:setSprite(self.charName, 8, 10)
|
self:setSprite(self.charName, 8, 10)
|
||||||
self:cloneSprite()
|
self:cloneSprite()
|
||||||
self.statusbar = Statusbar(self, "speed", 50)
|
self.statusbar = Statusbar(self, "speed", 50)
|
||||||
self.statusbar:setWeapon(2)
|
self.statusbar:setWeapon(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:updateStart(dt)
|
function Player:updateStart(dt)
|
||||||
|
@ -34,8 +39,8 @@ function Player:updateStart(dt)
|
||||||
self.zsp = 280*1.33
|
self.zsp = 280*1.33
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.keys["B"].isPressed and (self.onGround) then
|
if self.keys["B"].isPressed then
|
||||||
-- Nothing for the moment
|
self.obj.Weapon(self.world, self.x, self.y+1, self.z+8, 1, WeaponList[1]);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,4 +125,19 @@ function Player:drawHUD(id)
|
||||||
self.statusbar:draw(8, 12)
|
self.statusbar:draw(8, 12)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Player:setRing(value, isRelative)
|
||||||
|
if (isRelative == false) then
|
||||||
|
self.rings = 0
|
||||||
|
end
|
||||||
|
self.rings = self.rings + value
|
||||||
|
self.statusbar.rings = self.rings
|
||||||
|
end
|
||||||
|
|
||||||
|
function Player:setScore(value, isRelative)
|
||||||
|
if (isRelative == false) then
|
||||||
|
self.score = 0
|
||||||
|
end
|
||||||
|
self.score = self.score + value
|
||||||
|
end
|
||||||
|
|
||||||
return Player
|
return Player
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
local Parent = require "game.modules.world.actors.parent"
|
||||||
|
local WeaponShot = Parent:extend()
|
||||||
|
|
||||||
|
function WeaponShot:new(world, x, y, z, direction, data)
|
||||||
|
WeaponShot.super.new(self, world, "shot", x, y, z, 16, 8, 16, false)
|
||||||
|
self:setSprite("ringweapon", 0, 0)
|
||||||
|
self.direction = direction
|
||||||
|
self.data = data
|
||||||
|
self.zsp = self.data.zspeed
|
||||||
|
self.xsp = self.data.xspeed * direction
|
||||||
|
self.xfrc, self.yfrc = 0, 0
|
||||||
|
if (self.zsp ~= 0) then
|
||||||
|
self:setGravity(480*2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function WeaponShot:updateStart(dt)
|
||||||
|
if (self.xsp == 0) then
|
||||||
|
self:destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function WeaponShot:draw()
|
||||||
|
love.graphics.setColor(self.data.color[1], self.data.color[2], self.data.color[3], 1)
|
||||||
|
WeaponShot.super.draw(self)
|
||||||
|
love.graphics.setColor(self.data.color[1], self.data.color[2], self.data.color[3], 0.6)
|
||||||
|
local x, y = self.x + self.y/2 + 8, self.y - self.z - 3
|
||||||
|
local angle = utils.math.pointDirection(0, 0, self.xsp, self.zsp * -1)
|
||||||
|
self.scene.assets.sprites["ringtoss"]:drawAnimation(x, y, angle)
|
||||||
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
return WeaponShot
|
Loading…
Reference in a new issue