improvement: new character handling functions
This commit is contained in:
parent
0b7c594daa
commit
6f480cfef1
15 changed files with 339 additions and 7 deletions
|
@ -0,0 +1 @@
|
|||
return {"sonic"}
|
57
sonic-bluestreak.love/datas/gamedata/characters/default.lua
Normal file
57
sonic-bluestreak.love/datas/gamedata/characters/default.lua
Normal file
|
@ -0,0 +1,57 @@
|
|||
return {
|
||||
name = "Default",
|
||||
name_full = "Default the Character",
|
||||
class = "Speedster",
|
||||
startlevel = 1,
|
||||
isUnlockedAtStart = true,
|
||||
|
||||
base_stats = {
|
||||
hpmax = 200, --
|
||||
ppmax = 50, --
|
||||
|
||||
attack = 50, --
|
||||
power = 50, --
|
||||
defense = 50, --
|
||||
technic = 50, --
|
||||
mind = 50, --
|
||||
speed = 50, --
|
||||
|
||||
turns = 3, -- number of attacks by turn (unused)
|
||||
move = 2, -- how far the character can get in one turn
|
||||
},
|
||||
|
||||
color = {1, 1, 1},
|
||||
|
||||
skill_list = {
|
||||
--{attack_name, level},
|
||||
},
|
||||
|
||||
flags = {
|
||||
canGoSuper = true,
|
||||
},
|
||||
|
||||
assets = {
|
||||
charset = {"", 1},
|
||||
lifeicon = 1,
|
||||
spriteset = "sonic",
|
||||
},
|
||||
|
||||
inventory = {
|
||||
haveShoes = true,
|
||||
haveMechs = false,
|
||||
haveGlove = true,
|
||||
haveHammer= false,
|
||||
accessories_number = 3,
|
||||
chao_number = 1,
|
||||
},
|
||||
|
||||
boost_stats = {
|
||||
spd = 5,
|
||||
jmp = 3,
|
||||
jumpaction = "doublejump",
|
||||
jumpaction_power = 2,
|
||||
action = "spinattack",
|
||||
action_power = 1,
|
||||
canBreakCraft = false,
|
||||
}
|
||||
}
|
9
sonic-bluestreak.love/datas/gamedata/characters/init.lua
Normal file
9
sonic-bluestreak.love/datas/gamedata/characters/init.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
return {
|
||||
"sonic",
|
||||
"tails",
|
||||
"knuckles",
|
||||
"amy",
|
||||
"cream",
|
||||
"shadow",
|
||||
"rouge",
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
local actions = {}
|
||||
|
||||
actions.aerial = {}
|
||||
actions.special = {}
|
||||
|
||||
function actions.aerial.start(n, actor)
|
||||
|
||||
end
|
||||
|
||||
function actions.aerial.update(dt, actor)
|
||||
|
||||
end
|
||||
|
||||
function actions.aerial.onGround(actor)
|
||||
|
||||
end
|
||||
|
||||
function actions.special.start(n, actor)
|
||||
|
||||
end
|
||||
|
||||
function actions.special.update(dt, actor)
|
||||
|
||||
end
|
||||
|
||||
function actions.special.onGround(actor)
|
||||
|
||||
end
|
||||
|
||||
return actions
|
|
@ -0,0 +1,4 @@
|
|||
return {
|
||||
lifeicon = 1,
|
||||
spriteset = "sonic",
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
return {
|
||||
name = "Sonic",
|
||||
fullname = "Sonic the Hedgehog",
|
||||
|
||||
class = "speed",
|
||||
alignement = "hero",
|
||||
team = "heroes",
|
||||
|
||||
description = "Lorem Ipsum...",
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
return {
|
||||
--{skill_flag},
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
return {
|
||||
startlevel = 1,
|
||||
hpmax = 50, -- Les points de vie du personnages
|
||||
spd = 5,
|
||||
jmp = 3,
|
||||
atk = 5,
|
||||
jumpaction_power = 2,
|
||||
action_power = 1,
|
||||
action_cost = 30,
|
||||
|
||||
canGoSuper = true,
|
||||
canBreakCraft = false
|
||||
}
|
Binary file not shown.
Binary file not shown.
149
sonic-bluestreak.love/game/characters.lua
Normal file
149
sonic-bluestreak.love/game/characters.lua
Normal file
|
@ -0,0 +1,149 @@
|
|||
-- game/characters :: The character handler. This object handle all the character
|
||||
-- and is able to get and set datas about them.
|
||||
|
||||
--[[
|
||||
Copyright © 2019 Kazhnuz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local CharacterManager = Object:extend()
|
||||
|
||||
function CharacterManager:new(controller)
|
||||
self.controller = controller
|
||||
self.namelist = require "datas.gamedata.characters"
|
||||
self.list = {}
|
||||
self.team = require "datas.gamedata.characters.baseteam"
|
||||
self.active = 1
|
||||
self:init()
|
||||
end
|
||||
|
||||
function CharacterManager:init()
|
||||
for k, v in pairs(self.namelist) do
|
||||
local dir = "datas/gamedata/characters/" .. v .. "/init.lua"
|
||||
local fileinfo = love.filesystem.getInfo(dir)
|
||||
if fileinfo ~= nil then
|
||||
self:initCharacter(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function CharacterManager:getCharacterData(charname)
|
||||
-- va eprmettre de récupérer les données d'un personnage
|
||||
local charfolder = "datas.gamedata.characters." .. charname
|
||||
local character = require(charfolder)
|
||||
character.stats = require(charfolder .. ".stats")
|
||||
character.assets = require(charfolder .. ".assets")
|
||||
character.skills = require(charfolder .. ".skills")
|
||||
character.actions = require(charfolder .. ".actions")
|
||||
|
||||
return character
|
||||
end
|
||||
|
||||
function CharacterManager:initCharacter(id)
|
||||
local character = self:getCharacterData(id)
|
||||
|
||||
local startlevel = character.stats.startlevel
|
||||
character.stats.level = startlevel
|
||||
character.stats.exp = self:getExpValue(startlevel)
|
||||
character.stats.exp_next = self:getExpValue(startlevel + 1)
|
||||
|
||||
character.stats.hp = character.stats.hpmax
|
||||
character.stats.pp = 100
|
||||
character.stats.status = 0
|
||||
|
||||
self.list[id] = character
|
||||
end
|
||||
|
||||
function CharacterManager:getExpValue(level)
|
||||
return math.floor( ( 4 * ( level ^ 3 ) ) / 5 )
|
||||
end
|
||||
|
||||
function CharacterManager:setLevel(id, newlevel)
|
||||
self.list[id].stats.level = newlevel
|
||||
local stats = self.list[id].stats
|
||||
local exp, exp_next, exp_current
|
||||
exp = self:getExpValue(stats.level)
|
||||
exp_next = self:getExpValue(stats.level + 1)
|
||||
exp_current = self.list[id].stats.exp
|
||||
|
||||
self.list[id].stats.exp = math.max(math.min(exp_current, exp_next - 1), exp)
|
||||
self.list[id].stats.exp_next = exp_next
|
||||
end
|
||||
|
||||
function CharacterManager:levelUp(id)
|
||||
self:setLevel(id, self.list[id].stats.level + 1)
|
||||
end
|
||||
|
||||
function CharacterManager:getStatValue(level, base)
|
||||
return math.floor( (((base * 2) * level)/100) ) + 5
|
||||
end
|
||||
|
||||
function CharacterManager:getHPValue(level, base)
|
||||
return math.floor( (((base * 2.7) * level)/100) ) + 15 + level
|
||||
end
|
||||
|
||||
function CharacterManager:getData()
|
||||
local data = {}
|
||||
data.list = self.list
|
||||
data.team = self.team
|
||||
return data
|
||||
end
|
||||
|
||||
function CharacterManager:setData(data)
|
||||
local data = data
|
||||
self.list = data.list
|
||||
self.team = data.team
|
||||
end
|
||||
|
||||
function CharacterManager:heal(id)
|
||||
self.list[id].stats.hp = self.list[id].stats.hpmax
|
||||
self.list[id].stats.pp = 100
|
||||
self.list[id].stats.status = 0
|
||||
end
|
||||
|
||||
function CharacterManager:addToTeam(id)
|
||||
self:heal(id)
|
||||
table.insert(self.team, id)
|
||||
end
|
||||
|
||||
function CharacterManager:removeToTeam(teamid)
|
||||
self.team[teamid] = ""
|
||||
end
|
||||
|
||||
function CharacterManager:getActiveCharacter()
|
||||
return self.team[self.active]
|
||||
end
|
||||
|
||||
-- DEBUG FUNCTIONS
|
||||
|
||||
function CharacterManager:printCharacter(id)
|
||||
local character = self.list[id]
|
||||
local stats = character.stats
|
||||
print(id .. ". " .. character.fullname)
|
||||
print("Lvl " .. character.stats.level .. " (" .. stats.exp .. "/" .. stats.exp_next .. " exp)")
|
||||
end
|
||||
|
||||
function CharacterManager:printTeam()
|
||||
for i,v in ipairs(self.team) do
|
||||
self:printCharacter(v)
|
||||
print("-----")
|
||||
end
|
||||
end
|
||||
|
||||
return CharacterManager
|
15
sonic-bluestreak.love/game/ennemies.lua
Normal file
15
sonic-bluestreak.love/game/ennemies.lua
Normal file
|
@ -0,0 +1,15 @@
|
|||
local EnnemyManager = Object:extend()
|
||||
|
||||
function EnnemyManager:new(controller)
|
||||
self.controller = controller
|
||||
end
|
||||
|
||||
function EnnemyManager:getEnnemyData(ennemy)
|
||||
local data = require("datas.gamedata.ennemies." .. ennemy)
|
||||
data.skills = require("datas.gamedata.ennemies." .. ennemy .. ".skills")
|
||||
data.stats = require("datas.gamedata.ennemies." .. ennemy .. ".stats")
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
return EnnemyManager
|
|
@ -23,28 +23,33 @@
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
|
||||
local Game = Object:extend()
|
||||
local Game = Object:extend()
|
||||
local Characters = require "game.characters"
|
||||
local Ennemies = require "game.ennemies"
|
||||
|
||||
local SonicBoost = require "game.subgame.sonic-boost"
|
||||
local binser = require "core.modules.gamesystem.libs.binser"
|
||||
|
||||
local binser = require "libs.binser"
|
||||
Game.utils = require "game.modules.utils"
|
||||
Game.gui = require "game.modules.gui"
|
||||
|
||||
function Game:new()
|
||||
self.slot = -1
|
||||
self.gametime = 0
|
||||
|
||||
self.subgame = {}
|
||||
self.subgame.sonicboost = SonicBoost(self)
|
||||
self.characters = Characters(self)
|
||||
self.ennemies = Ennemies(self)
|
||||
end
|
||||
|
||||
function Game:setData(data)
|
||||
local data = data
|
||||
self.gametime = data.gametime
|
||||
self.gametime = data.gametime
|
||||
self.characters:setData(data.characters)
|
||||
end
|
||||
|
||||
function Game:getData()
|
||||
local data = {}
|
||||
data.gametime = self.gametime
|
||||
data.characters = self.characters:getData()
|
||||
|
||||
return data
|
||||
end
|
||||
|
|
36
sonic-bluestreak.love/game/modules/utils/init.lua
Normal file
36
sonic-bluestreak.love/game/modules/utils/init.lua
Normal file
|
@ -0,0 +1,36 @@
|
|||
local gameutils = {}
|
||||
|
||||
function gameutils.getMapPath(maptype, mapname)
|
||||
local dir = gameutils.getMapDirectory(maptype, mapname)
|
||||
local path = ""
|
||||
if maptype == "sti" then
|
||||
path = dir .. "map.lua"
|
||||
else
|
||||
path = "datas.gamedata.maps." .. maptype .. "." .. mapname
|
||||
end
|
||||
core.debug:print("game/utils", "path is " .. path)
|
||||
return path
|
||||
end
|
||||
|
||||
function gameutils.getMapDirectory(maptype, mapname)
|
||||
if not gameutils.validateMapType(maptype) then
|
||||
error("Map type " .. maptype .. " doesn't exist.")
|
||||
end
|
||||
|
||||
return "datas/gamedata/maps/" .. maptype .. "/" .. mapname .. "/"
|
||||
end
|
||||
|
||||
function gameutils.validateMapType(maptype)
|
||||
local types = {"battle", "sti", "test", "shoot"}
|
||||
local validated = false
|
||||
|
||||
for i, type in ipairs(types) do
|
||||
if (type == maptype) then
|
||||
validated = true
|
||||
end
|
||||
end
|
||||
|
||||
return validated
|
||||
end
|
||||
|
||||
return gameutils
|
|
@ -82,7 +82,7 @@ function Character:new(charcontroller, rail, character, id)
|
|||
end
|
||||
|
||||
function Character:characterInit(char)
|
||||
self.data = game.subgame.sonicboost:getCharacterData(char)
|
||||
self.data = game.characters:getCharacterData(char)
|
||||
|
||||
self.lifeicon = self.data.assets.lifeicon
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue