feat: basic weapon system

This commit is contained in:
Kazhnuz 2020-04-25 12:15:12 +02:00
parent a7a0bde8ea
commit 318e297095
9 changed files with 117 additions and 7 deletions

View 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,
},
}
}

View 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,
},
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

View 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,
},
}

View file

@ -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"},

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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