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)
local player = {}
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
table.insert(self.players, player)
@ -247,8 +247,8 @@ function BaseWorld:addPlayer(x, y, z, id)
end
end
function BaseWorld:newPlayer(x, y, z)
return self.obj.Player(self, x, y)
function BaseWorld:newPlayer(id, x, y, z)
return self.obj.Player(self, x, y, id)
end
function BaseWorld:sendInputToPlayers(actor)

View file

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

View file

@ -5,9 +5,8 @@ local PauseMenu = require("game.modules.playstyle.pause")
local TestWorld = require("game.modules.world.parent")
function PlayStyle:new(playerNumber, cameraMode)
local playerNumber = playerNumber or 1
local cameraMode = cameraMode or "split"
function PlayStyle:new(playerList)
local playerList = playerList or {"sonic"}
PlayStyle.super.new(self)
self.timer = 0
@ -16,12 +15,38 @@ function PlayStyle:new(playerNumber, cameraMode)
PauseMenu(self)
self:initWorld()
self:initMission()
self:initCharacters(playerList)
self:startLevel()
end
function PlayStyle:initWorld()
TestWorld(self)
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)
PlayStyle.super.update(self, dt)
if self.menusystem.menus["pauseMenu"].isActive == false then
@ -46,8 +71,12 @@ function PlayStyle:update(dt)
end
end
function PlayStyle:restartLevel()
function PlayStyle:startLevel()
self.world:loadMap()
end
function PlayStyle:restartLevel()
self.world:reset()
end
function PlayStyle:exitLevel()

View file

@ -54,8 +54,12 @@ function RestartWidget:new(menu, font)
end
function RestartWidget:action()
self.menu.playstyle:flushKeys()
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
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)
self:setGravity(480*2)
self:setSprite("sonic", 8, 10)
self:cloneSprite()
self:init(id)
self.frame = Frame()
self.action = "normal"
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)
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 BattleWorld = require "game.modules.world.battle"
function MovePlayer:new(playerNumber, cameraMode)
local playerNumber = playerNumber or 1
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()
function MovePlayer:new()
MovePlayer.super.new(self, {"sonic"})
end
function MovePlayer:initWorld()