improvement: improve level starting again

This commit is contained in:
Kazhnuz 2019-12-29 10:04:16 +01:00
parent 0625c8d82c
commit 99621a756c
6 changed files with 53 additions and 23 deletions

View file

@ -238,7 +238,7 @@ end
function BaseWorld:addPlayer(x, y, z, id) function BaseWorld:addPlayer(x, y, z, id)
local player = {} local player = {}
if id <= self.playerNumber then if id <= self.playerNumber then
player.actor = self:newPlayer(x, y, z) player.actor = self:newPlayer(id, x, y, z)
player.sourceid = sourceid or 1 player.sourceid = sourceid or 1
table.insert(self.players, player) table.insert(self.players, player)
@ -247,8 +247,8 @@ function BaseWorld:addPlayer(x, y, z, id)
end end
end end
function BaseWorld:newPlayer(x, y, z) function BaseWorld:newPlayer(id, x, y, z)
return self.obj.Player(self, x, y) return self.obj.Player(self, x, y, id)
end end
function BaseWorld:sendInputToPlayers(actor) function BaseWorld:sendInputToPlayers(actor)

View file

@ -89,8 +89,8 @@ end
-- PLAYER FUNCTIONS -- PLAYER FUNCTIONS
-- Load player stuff -- Load player stuff
function World3D:newPlayer(x, y, z) function World3D:newPlayer(id, x, y, z)
return self.obj.Player(self, x, y, z) return self.obj.Player(self, x, y, z, id)
end end
-- BODIES MANAGEMENT FUNCTIONS -- BODIES MANAGEMENT FUNCTIONS

View file

@ -5,9 +5,8 @@ local PauseMenu = require("game.modules.playstyle.pause")
local TestWorld = require("game.modules.world.parent") local TestWorld = require("game.modules.world.parent")
function PlayStyle:new(playerNumber, cameraMode) function PlayStyle:new(playerList)
local playerNumber = playerNumber or 1 local playerList = playerList or {"sonic"}
local cameraMode = cameraMode or "split"
PlayStyle.super.new(self) PlayStyle.super.new(self)
self.timer = 0 self.timer = 0
@ -16,12 +15,38 @@ function PlayStyle:new(playerNumber, cameraMode)
PauseMenu(self) PauseMenu(self)
self:initWorld() self:initWorld()
self:initMission()
self:initCharacters(playerList)
self:startLevel()
end end
function PlayStyle:initWorld() function PlayStyle:initWorld()
TestWorld(self) TestWorld(self)
end end
function PlayStyle:initMission()
-- NOTHING
end
function PlayStyle:initCharacters(characterList)
self.characterList = characterList
self.world:setPlayerNumber(#characterList)
self.world.cameras:setMode("split")
for i, characterName in ipairs(characterList) do
self:initCharacterRessources(characterName)
end
end
function PlayStyle:initCharacterRessources(characterName)
local folder = "assets/sprites/characters/"
self.assets:addSprite(characterName, folder .. characterName)
end
function PlayStyle:getCharacterName(charID)
return self.characterList[charID]
end
function PlayStyle:update(dt) function PlayStyle:update(dt)
PlayStyle.super.update(self, dt) PlayStyle.super.update(self, dt)
if self.menusystem.menus["pauseMenu"].isActive == false then if self.menusystem.menus["pauseMenu"].isActive == false then
@ -46,8 +71,12 @@ function PlayStyle:update(dt)
end end
end end
function PlayStyle:restartLevel() function PlayStyle:startLevel()
self.world:loadMap()
end
function PlayStyle:restartLevel()
self.world:reset()
end end
function PlayStyle:exitLevel() function PlayStyle:exitLevel()

View file

@ -54,8 +54,12 @@ function RestartWidget:new(menu, font)
end end
function RestartWidget:action() function RestartWidget:action()
self.menu.playstyle:flushKeys()
self.menu.playstyle:restartLevel() self.menu.playstyle:restartLevel()
self.menu.isActive = false
self.menu.isVisible = false
self.menu.playstyle.world.isActive = true
self.menu.playstyle.assets.isActive = true
self.menu.playstyle:flushKeys()
end end
function ExitWidget:new(menu, font) function ExitWidget:new(menu, font)

View file

@ -8,14 +8,20 @@ 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, 12, 24, true)
self:setGravity(480*2) self:setGravity(480*2)
self:setSprite("sonic", 8, 10) self:init(id)
self:cloneSprite()
self.frame = Frame() self.frame = Frame()
self.action = "normal" self.action = "normal"
end end
function Player:init(id)
self.playerID = id
self.charName = self.scene:getCharacterName(self.playerID)
self:setSprite(self.charName, 8, 10)
self:cloneSprite()
end
function Player:updateStart(dt) function Player:updateStart(dt)
self.xfrc, self.yfrc = 480*3, 480*3 self.xfrc, self.yfrc = 480*3, 480*3

View file

@ -28,17 +28,8 @@ local TestWorld = require "game.modules.world.parent"
local ShootWorld = require "game.modules.world.shoot" local ShootWorld = require "game.modules.world.shoot"
local BattleWorld = require "game.modules.world.battle" local BattleWorld = require "game.modules.world.battle"
function MovePlayer:new(playerNumber, cameraMode) function MovePlayer:new()
local playerNumber = playerNumber or 1 MovePlayer.super.new(self, {"sonic"})
local cameraMode = cameraMode or "split"
MovePlayer.super.new(self, playerNumber, cameraMode)
self.assets:batchImport("scenes.test_scene.assets")
self.world:setPlayerNumber(playerNumber)
self.world.cameras:setMode(cameraMode)
self.world:loadMap()
end end
function MovePlayer:initWorld() function MovePlayer:initWorld()