feat: add damage system

Fixes: #90
This commit is contained in:
Kazhnuz 2021-04-19 18:04:29 +02:00
parent 36e30be245
commit e7878c1efa
9 changed files with 157 additions and 5 deletions

View file

@ -70,7 +70,7 @@ return {
forceAction = nil,
level=-8,
height=0,
speedFactor = 0.66,
speedFactor = 0.5,
canJump = false,
}
},
@ -79,7 +79,7 @@ return {
forceAction = nil,
level=0,
height=8,
speedFactor = 0.66,
speedFactor = 0.5,
canJump = false,
}
}

View file

@ -93,6 +93,17 @@ function CharacterManager:heal(name)
self.list[name]:heal()
end
function CharacterManager:sendDamageFromMap(name, damageRatio)
local character = self.list[name]
if (character.hp > 0) then
local newHP = math.floor(character.hp - (character.stats.hpmax * damageRatio))
if (not game.difficulty:get("hazardMakesKo")) then
newHP = math.max(1, newHP)
end
self.list[name]:setHP(newHP, false)
end
end
function CharacterManager:addToTeam(name)
self:heal(name)
if (#self.team < 4) then

View file

@ -8,6 +8,7 @@ function PlayerHealth:initHealth()
self.hpbar = ComplexHPBar(HPBAR_SIZE)
self.hpbar:setColorForeground(248/255, 160/255, 0, 1)
self.hpbar:setColorBackground(112/255, 0, 0)
self.fallDamage = 0
end
function PlayerHealth:drawHealth(x, y)
@ -20,4 +21,16 @@ function PlayerHealth:drawHealth(x, y)
end
end
function PlayerHealth:takeDamage(damage)
local damage = damage or 10
damage = damage / 100
if (game.difficulty:get("allDamage")) then
for _, name in ipairs(game.characters.team) do
game.characters:sendDamageFromMap(name, damage)
end
else
game.characters:sendDamageFromMap(game.characters.team[game.characters.active], damage)
end
end
return PlayerHealth

View file

@ -81,6 +81,7 @@ function Player:checkGround()
if (self.z <= RESPAWN_LIMIT) then
self.x = self.lastPos.x
self.y = self.lastPos.y
self:takeDamage(self.fallDamage)
end
end
end

View file

@ -129,8 +129,10 @@ function PlayerInteractions:setTerrainData(data)
if (self.onGround) then
self.speedFactor = data.speedFactor or 1
self.canJump = data.canJump ~= false
self.canAct = data.canAct ~= false
self.forceAction = data.forceAction
end
self.fallDamage = data.fallDamage or 0
self.terrain.data = data
end

View file

@ -16,8 +16,19 @@ function Team:initTeam()
end
function Team:updateActiveCharacter()
if ((self.active.hp == 0) and not game.difficulty:get("playerKoChar")) then
self:switchActiveCharacter()
local everybodyIsKo = true
for id, name in ipairs(game.characters.team) do
if (game.characters.list[name].hp > 0) then
everybodyIsKo = false
break;
end
end
if (everybodyIsKo) then
self.scene:gameover()
else
if ((self.active.hp == 0) and not game.difficulty:get("playerKoChar")) then
self:switchActiveCharacter()
end
end
end

View file

@ -139,6 +139,15 @@ function OverWorld:pause()
screens.mainmenu.pause(self)
end
function OverWorld:gameover()
self.tweens:newTween(0,0.2, {backGroundOpacity=0.75}, "inQuad")
self.tweens:newTween(0,0.3, {borderPosition=30}, "inOutQuad")
self.tweens:newTween(0, 0.3, {emblemPosition=500}, "inOutQuad")
self.tweens:newTween(0, 0.3, {ringBorder=-16}, "inOutQuad")
self.world.isActive = false
screens.gameover(self)
end
function OverWorld:restored()
self.world:restoreActions()
end

View file

@ -0,0 +1,104 @@
local BaseScreen = require "scenes.overworld.screens.parent"
local GameOver = BaseScreen:extend()
local TweenManager = require "game.modules.tweenmanager"
local gui = require "game.modules.gui"
local tw, th = 128, 32
local ConfirmDialog = require "game.modules.confirmdialog"
local defTransitions = require "core.modules.transitions"
local radTransitions = require "game.modules.transitions"
local ConfirmDialog = require "game.modules.confirmdialog"
function GameOver:new(scene)
GameOver.super.new(self, scene, "")
self.assets = scene.assets
self.turnSystem = scene.turns
self:setVariables()
self.continueBox = gui.newTextBox("assets/gui/dialogbox.png", tw, th)
self.tweens = TweenManager(self)
self:prepareAnimation()
end
function GameOver:setVariables()
-- Vignette Opacity
self.vignetteOpacity = 0
-- Battle FInished Label
self.labelOpacity = 0
local width, height = core.screen:getDimensions()
self.labelX = width/2
-- Infobox
self.tbSize = 0.6
self.tbOpacity = 0
self.continue = false
self.continueValue = -1
end
function GameOver:prepareAnimation()
-- Label
self.tweens:newTween(0, 0.6, {labelOpacity=1}, 'inExpo')
self.tweens:newTween(0.9, 0.4, {labelX=4}, 'inExpo')
self.tweens:newSwitch(1.8, {"continue"})
end
function GameOver:update(dt)
self.tweens:update(dt)
if (self.continue) then
self.continue = false
local confirm = ConfirmDialog(self.scene, "Do you want to return to title ? \nYou can also reload your latest save.",
function() self:returnToTitle() end, "Return to title",
function() self:loadLastSave() end, "Reload last save")
confirm.darken = false
end
end
function GameOver:draw()
local width, height = core.screen:getDimensions()
self:drawLabel(width/2, 48, self.labelX, self.labelOpacity)
end
function GameOver:drawVignette(width, height)
love.graphics.setColor(0, 0, 0, self.vignetteOpacity)
love.graphics.rectangle("fill", 0, 0, width, height)
end
function GameOver:drawLabel(x, y, x2, opacity)
love.graphics.setColor(1, 1, 1, opacity)
self.assets.fonts["SA2font"]:print("GAME", x - x2, y, "right")
self.assets.fonts["SA2font"]:print("OVER", x + x2, y, "left")
end
function GameOver:drawContinueBox(x, y, continueValue, size, opacity)
love.graphics.setColor(1, 1, 1, opacity)
love.graphics.draw(self.continueBox, x, y, 0, size, size, tw/2, th/2)
local text = "continue"
if (continueValue == 1) then
text = "quit"
end
self.assets.images["arrow"]:draw(x - continueValue*64, y, math.rad(-90) * continueValue, continueValue, 1, 13, 13)
self.assets.fonts["SA2font"]:print(text, x, y-13, "center")
end
function GameOver:returnToTitle()
core.screen:startTransition(defTransitions.default, defTransitions.circle, function() scenes.title(true) end, 424/2, 240/2)
end
function GameOver:loadLastSave()
self.scene.tweens:newTween(0, 0.3, {borderPosition=0}, "inOutQuad")
core.screen:startTransition(defTransitions.default, defTransitions.default, function() game:reload() scenes.overworld() end, 424/2, 240/2)
end
return GameOver

View file

@ -1,3 +1,4 @@
return {
mainmenu = require "scenes.overworld.screens.mainmenu"
mainmenu = require "scenes.overworld.screens.mainmenu",
gameover = require "scenes.overworld.screens.gameover"
}