diff --git a/sonic-bluestreak.love/core/modules/world/baseworld.lua b/sonic-bluestreak.love/core/modules/world/baseworld.lua index 46b2555..d805923 100644 --- a/sonic-bluestreak.love/core/modules/world/baseworld.lua +++ b/sonic-bluestreak.love/core/modules/world/baseworld.lua @@ -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) diff --git a/sonic-bluestreak.love/core/modules/world/world3D.lua b/sonic-bluestreak.love/core/modules/world/world3D.lua index 58b364c..7bcff69 100644 --- a/sonic-bluestreak.love/core/modules/world/world3D.lua +++ b/sonic-bluestreak.love/core/modules/world/world3D.lua @@ -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 diff --git a/sonic-bluestreak.love/game/modules/playstyle/init.lua b/sonic-bluestreak.love/game/modules/playstyle/init.lua index e699f86..499bd72 100644 --- a/sonic-bluestreak.love/game/modules/playstyle/init.lua +++ b/sonic-bluestreak.love/game/modules/playstyle/init.lua @@ -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:startLevel() + self.world:loadMap() +end + function PlayStyle:restartLevel() - + self.world:reset() end function PlayStyle:exitLevel() diff --git a/sonic-bluestreak.love/game/modules/playstyle/pause.lua b/sonic-bluestreak.love/game/modules/playstyle/pause.lua index 833eab2..c679a61 100644 --- a/sonic-bluestreak.love/game/modules/playstyle/pause.lua +++ b/sonic-bluestreak.love/game/modules/playstyle/pause.lua @@ -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) diff --git a/sonic-bluestreak.love/game/modules/world/actors/player.lua b/sonic-bluestreak.love/game/modules/world/actors/player.lua index b840bbc..5e30e28 100644 --- a/sonic-bluestreak.love/game/modules/world/actors/player.lua +++ b/sonic-bluestreak.love/game/modules/world/actors/player.lua @@ -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 diff --git a/sonic-bluestreak.love/scenes/test_scene/init.lua b/sonic-bluestreak.love/scenes/test_scene/init.lua index 939aa55..0c34a8b 100644 --- a/sonic-bluestreak.love/scenes/test_scene/init.lua +++ b/sonic-bluestreak.love/scenes/test_scene/init.lua @@ -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()