From 318e29709519c4a18b432b72451e5c619f7406f5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 25 Apr 2020 12:15:12 +0200 Subject: [PATCH] feat: basic weapon system --- .../assets/sprites/items/ringtoss.lua | 18 ++++++++++ .../assets/sprites/items/ringweapon.lua | 16 +++++++++ .../assets/sprites/items/ringweapon.png | Bin 0 -> 10165 bytes .../datas/gamedata/weapons.lua | 20 +++++++++++ .../game/modules/playstyle/assets.lua | 4 ++- .../game/modules/world/actors/init.lua | 1 + .../game/modules/world/actors/items/ring.lua | 4 +-- .../game/modules/world/actors/player.lua | 28 ++++++++++++--- .../modules/world/actors/weapons/parent.lua | 33 ++++++++++++++++++ 9 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 sonic-bluestreak.love/assets/sprites/items/ringtoss.lua create mode 100644 sonic-bluestreak.love/assets/sprites/items/ringweapon.lua create mode 100644 sonic-bluestreak.love/assets/sprites/items/ringweapon.png create mode 100644 sonic-bluestreak.love/datas/gamedata/weapons.lua create mode 100644 sonic-bluestreak.love/game/modules/world/actors/weapons/parent.lua diff --git a/sonic-bluestreak.love/assets/sprites/items/ringtoss.lua b/sonic-bluestreak.love/assets/sprites/items/ringtoss.lua new file mode 100644 index 0000000..1e5f432 --- /dev/null +++ b/sonic-bluestreak.love/assets/sprites/items/ringtoss.lua @@ -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, + }, + } +} diff --git a/sonic-bluestreak.love/assets/sprites/items/ringweapon.lua b/sonic-bluestreak.love/assets/sprites/items/ringweapon.lua new file mode 100644 index 0000000..5e1c1e0 --- /dev/null +++ b/sonic-bluestreak.love/assets/sprites/items/ringweapon.lua @@ -0,0 +1,16 @@ +return { + metadata = { + height = 16, + width = 16, + defaultAnim = "default" + }, + animations = { + ["default"] = { + startAt = 1, + endAt = 8, + loop = 1, + speed = 8, + pauseAtEnd = false, + }, + } +} diff --git a/sonic-bluestreak.love/assets/sprites/items/ringweapon.png b/sonic-bluestreak.love/assets/sprites/items/ringweapon.png new file mode 100644 index 0000000000000000000000000000000000000000..a2b5e8697fb6fcecf0c272d4cbd7a840e7fdeac8 GIT binary patch literal 10165 zcmeHsXIPWlwr&uRCW3+#X)&On5J)1B&_QbGARtXKB!L77fh2U0CcOy)b_4~)Mw22S z9YlmsEFfK}Ql%*!Z&3Hzu6x(r=d9;B=idrXLgx71@s2sie8-&M{1Rhotjo@NlobE~ zup{-f%xV8aXm3vD{j|?vYoBNUfTP#n!kS`^@&S5~h)#GnERf>ofdyiH@lF7MZ-34W z0!dUMG4lHgcL2ksaOHydXvi6x5|4pHsseX4TM>3 z_|E)X1njIcUPtYRJJz~-tATn6+EbYqBpZvzU{X&6*Iou-RCecGqRT9SrFu1 z?&93GQ}s~9&aggsEPMv&8|5Y3;4|jqm(+?@zh?B>C-N}^60kM_TvAvK(3~ALlCF@xtFa@X}JO6WF#C zf37?0Z0~;6s)e$xbd_&|v*TwEDy#0i;&;x#wuYowy4F|5u-__^wyv7!8E~&9wcPR9 znd>iq{C#RkgaQt#N_Tj$O69*&wZHyly4c$$u87kg)cU@ z`K?OYLATZ>v!9!H%B8xTEWdT>+d@*uj&2ZJ^=@0uMD0Mu$ERB|N^6@uPj=pv*M9Ez z92hP@i}3gxp+kdS5dAIOula-I6r<1;`{c~tUqZ=7XnMQ3E|iPA`W&Ph6bL-eDq^yk z`FOlQ(z`R8Ba1`J_{yu}y~b0Ub~ZXZsYyY?(x$zk=M^$e5{kOW4?By%BE=M~rHl-921hU(r|norlRHL*dc z5$i&qi4XZnw&g^y-F0+Z@f}Mm{#L~r@>+AP8*0$4wTu&Jp~A=sk#fCF zu>Z#LC;!g_=bXR41%YUmvSD0P{cSPJ?ptv+d%iiNH>2`G$R_7wI+lv)kn@0Z0VnN??l)KcF(tf z6+I<<>J36(*``{2T(3N$J_t?Y+W$@M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a&dE$CS{qFkS6g!vI;WgA}!?B+85@qka8Al zZbk>`YhRCISKgYPAbE87*`)gh1zEnly66bntm%BXIdHT|e!i*Gj2l@*pT;M|GEnS_yX8^rht;KHER7p8nIw|(5XD){QA3TguWB>pF literal 0 HcmV?d00001 diff --git a/sonic-bluestreak.love/datas/gamedata/weapons.lua b/sonic-bluestreak.love/datas/gamedata/weapons.lua new file mode 100644 index 0000000..628ba7f --- /dev/null +++ b/sonic-bluestreak.love/datas/gamedata/weapons.lua @@ -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, + }, +} diff --git a/sonic-bluestreak.love/game/modules/playstyle/assets.lua b/sonic-bluestreak.love/game/modules/playstyle/assets.lua index 8813876..5614728 100644 --- a/sonic-bluestreak.love/game/modules/playstyle/assets.lua +++ b/sonic-bluestreak.love/game/modules/playstyle/assets.lua @@ -8,7 +8,9 @@ return { {"hudring", "assets/gui/hud/ring.png"} }, ["sprites"] = { - {"ring", "assets/sprites/items/ring"} + {"ring", "assets/sprites/items/ring"}, + {"ringweapon", "assets/sprites/items/ringweapon"}, + {"ringtoss", "assets/sprites/items/ringtoss"} }, ["imagefonts"] = { {"menu", "assets/gui/fonts/SA2font"}, diff --git a/sonic-bluestreak.love/game/modules/world/actors/init.lua b/sonic-bluestreak.love/game/modules/world/actors/init.lua index fea28f9..a0afc5e 100644 --- a/sonic-bluestreak.love/game/modules/world/actors/init.lua +++ b/sonic-bluestreak.love/game/modules/world/actors/init.lua @@ -4,6 +4,7 @@ local Obj = {} local cwd = (...):gsub('%.init$', '') .. "." Obj.Player = require(cwd .. "player") Obj.Ring = require(cwd .. "items.ring") +Obj.Weapon = require(cwd .. "weapons.parent") Obj.index = {} Obj.index["player"] = Obj.Player diff --git a/sonic-bluestreak.love/game/modules/world/actors/items/ring.lua b/sonic-bluestreak.love/game/modules/world/actors/items/ring.lua index 9b6d572..b999bea 100644 --- a/sonic-bluestreak.love/game/modules/world/actors/items/ring.lua +++ b/sonic-bluestreak.love/game/modules/world/actors/items/ring.lua @@ -8,8 +8,8 @@ function Ring:new(world, x, y, z) end function Ring:getPicked(player) - --player.rings = player.rings + 1 - --player:addScore(10) + player:setRing(1, true) + player:setScore(10, true) self:destroy() end diff --git a/sonic-bluestreak.love/game/modules/world/actors/player.lua b/sonic-bluestreak.love/game/modules/world/actors/player.lua index 60e96f8..a678862 100644 --- a/sonic-bluestreak.love/game/modules/world/actors/player.lua +++ b/sonic-bluestreak.love/game/modules/world/actors/player.lua @@ -5,8 +5,10 @@ local Player = Parent:extend() local Frame = require("game.modules.gui.frame") local Statusbar = require("game.modules.gui.status") +local WeaponList = require("datas.gamedata.weapons") + 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:init(id) @@ -14,6 +16,9 @@ function Player:new(world, x, y, z, id) self.frame = Frame() self.action = "normal" + + self.rings = 0 + self.score = 0 end function Player:init(id) @@ -22,7 +27,7 @@ function Player:init(id) self:setSprite(self.charName, 8, 10) self:cloneSprite() self.statusbar = Statusbar(self, "speed", 50) - self.statusbar:setWeapon(2) + self.statusbar:setWeapon(1) end function Player:updateStart(dt) @@ -34,8 +39,8 @@ function Player:updateStart(dt) self.zsp = 280*1.33 end - if self.keys["B"].isPressed and (self.onGround) then - -- Nothing for the moment + if self.keys["B"].isPressed then + self.obj.Weapon(self.world, self.x, self.y+1, self.z+8, 1, WeaponList[1]); end end @@ -120,4 +125,19 @@ function Player:drawHUD(id) self.statusbar:draw(8, 12) 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 diff --git a/sonic-bluestreak.love/game/modules/world/actors/weapons/parent.lua b/sonic-bluestreak.love/game/modules/world/actors/weapons/parent.lua new file mode 100644 index 0000000..c858973 --- /dev/null +++ b/sonic-bluestreak.love/game/modules/world/actors/weapons/parent.lua @@ -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