Switched TestSystems and InGame
This commit is contained in:
+5
-83
@@ -14,17 +14,9 @@ InGame::InGame(ConfigUtility* cUtil, SurfaceManager* sMgr) {
|
|||||||
#endif
|
#endif
|
||||||
configUtil = cUtil;
|
configUtil = cUtil;
|
||||||
surfaceMgr = sMgr;
|
surfaceMgr = sMgr;
|
||||||
|
|
||||||
playerCounter = currentPlayer = 0;
|
|
||||||
|
|
||||||
playerMgr.New(playerCounter++, surfaceMgr->Get("elliot"));
|
|
||||||
playerMgr.New(playerCounter++, surfaceMgr->Get("elliot"));
|
|
||||||
playerMgr.New(playerCounter++, surfaceMgr->Get("coa"));
|
|
||||||
playerMgr.New(playerCounter++, surfaceMgr->Get("coa"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InGame::~InGame() {
|
InGame::~InGame() {
|
||||||
playerMgr.DeleteAll();
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "leaving InGame" << endl;
|
cout << "leaving InGame" << endl;
|
||||||
#endif
|
#endif
|
||||||
@@ -35,7 +27,7 @@ InGame::~InGame() {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void InGame::FrameStart() {
|
void InGame::FrameStart() {
|
||||||
frameRate.Calculate();
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
void InGame::FrameEnd() {
|
void InGame::FrameEnd() {
|
||||||
@@ -43,12 +35,11 @@ void InGame::FrameEnd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InGame::Update() {
|
void InGame::Update() {
|
||||||
delta.Calculate();
|
//
|
||||||
playerMgr.UpdateAll(delta.GetDelta());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InGame::Render(SDL_Surface* const screen) {
|
void InGame::Render(SDL_Surface* const screen) {
|
||||||
playerMgr.DrawAllTo(screen);
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -70,80 +61,11 @@ void InGame::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
|||||||
void InGame::KeyDown(SDL_KeyboardEvent const& key) {
|
void InGame::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
switch(key.keysym.sym) {
|
switch(key.keysym.sym) {
|
||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
SetNextScene(SceneList::MAINMENU);
|
QuitEvent();
|
||||||
break;
|
|
||||||
|
|
||||||
case SDLK_w:
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::NORTH);
|
|
||||||
break;
|
|
||||||
case SDLK_s:
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::SOUTH);
|
|
||||||
break;
|
|
||||||
case SDLK_a:
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::WEST);
|
|
||||||
break;
|
|
||||||
case SDLK_d:
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::EAST);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDLK_1:
|
|
||||||
SwitchToPlayer(0);
|
|
||||||
break;
|
|
||||||
case SDLK_2:
|
|
||||||
SwitchToPlayer(1);
|
|
||||||
break;
|
|
||||||
case SDLK_3:
|
|
||||||
SwitchToPlayer(2);
|
|
||||||
break;
|
|
||||||
case SDLK_4:
|
|
||||||
SwitchToPlayer(3);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InGame::KeyUp(SDL_KeyboardEvent const& key) {
|
void InGame::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
switch(key.keysym.sym) {
|
//
|
||||||
case SDLK_w:
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::SOUTH);
|
|
||||||
break;
|
|
||||||
case SDLK_s:
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::NORTH);
|
|
||||||
break;
|
|
||||||
case SDLK_a:
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::EAST);
|
|
||||||
break;
|
|
||||||
case SDLK_d:
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::WEST);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//Utilities
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void InGame::NewPlayer(int index, std::string avatarName, int x, int y) {
|
|
||||||
Player* p = playerMgr.New(index, surfaceMgr->Get(avatarName));
|
|
||||||
p->SetPosition(Vector2(x, y));
|
|
||||||
}
|
|
||||||
|
|
||||||
void InGame::SwitchToPlayer(int index) {
|
|
||||||
//dirty hacks for smooth movement
|
|
||||||
playerMgr[currentPlayer]->SetMotion(Vector2(0,0));
|
|
||||||
currentPlayer = index;
|
|
||||||
|
|
||||||
Uint8* key = SDL_GetKeyState(nullptr);
|
|
||||||
|
|
||||||
if (key[SDLK_w]) {
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::NORTH);
|
|
||||||
}
|
|
||||||
if (key[SDLK_s]) {
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::SOUTH);
|
|
||||||
}
|
|
||||||
if (key[SDLK_a]) {
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::WEST);
|
|
||||||
}
|
|
||||||
if (key[SDLK_d]) {
|
|
||||||
playerMgr[currentPlayer]->WalkInDirection(Direction::EAST);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,15 +3,9 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "player_manager.hpp"
|
|
||||||
|
|
||||||
#include "delta.hpp"
|
|
||||||
#include "frame_rate.hpp"
|
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "surface_manager.hpp"
|
#include "surface_manager.hpp"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class InGame : public BaseScene {
|
class InGame : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
@@ -32,20 +26,9 @@ protected:
|
|||||||
virtual void KeyDown(SDL_KeyboardEvent const&);
|
virtual void KeyDown(SDL_KeyboardEvent const&);
|
||||||
virtual void KeyUp(SDL_KeyboardEvent const&);
|
virtual void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//utilities
|
|
||||||
void NewPlayer(int index, std::string avatarName, int x, int y);
|
|
||||||
void SwitchToPlayer(int index);
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
PlayerManager playerMgr;
|
|
||||||
|
|
||||||
Delta delta;
|
|
||||||
FrameRate frameRate;
|
|
||||||
ConfigUtility* configUtil;
|
ConfigUtility* configUtil;
|
||||||
SurfaceManager* surfaceMgr;
|
SurfaceManager* surfaceMgr;
|
||||||
|
|
||||||
int playerCounter;
|
|
||||||
int currentPlayer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
|||||||
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
if (buttonMap["start"]->MouseButtonUp(button) == Button::State::HOVER) {
|
if (buttonMap["start"]->MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
//TODO
|
//TODO
|
||||||
SetNextScene(SceneList::INGAME);
|
SetNextScene(SceneList::TESTSYSTEMS);
|
||||||
cout << "start" << endl;
|
cout << "start" << endl;
|
||||||
}
|
}
|
||||||
if (buttonMap["options"]->MouseButtonUp(button) == Button::State::HOVER) {
|
if (buttonMap["options"]->MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "surface_manager.hpp"
|
#include "surface_manager.hpp"
|
||||||
|
#include "network.hpp"
|
||||||
|
|
||||||
#include "SDL/SDL.h"
|
#include "SDL/SDL.h"
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ private:
|
|||||||
|
|
||||||
ConfigUtility configUtil;
|
ConfigUtility configUtil;
|
||||||
SurfaceManager surfaceMgr;
|
SurfaceManager surfaceMgr;
|
||||||
|
TCPSocket socket;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+83
-5
@@ -14,9 +14,17 @@ TestSystems::TestSystems(ConfigUtility* cUtil, SurfaceManager* sMgr) {
|
|||||||
#endif
|
#endif
|
||||||
configUtil = cUtil;
|
configUtil = cUtil;
|
||||||
surfaceMgr = sMgr;
|
surfaceMgr = sMgr;
|
||||||
|
|
||||||
|
playerCounter = currentPlayer = 0;
|
||||||
|
|
||||||
|
playerMgr.New(playerCounter++, surfaceMgr->Get("elliot"));
|
||||||
|
playerMgr.New(playerCounter++, surfaceMgr->Get("elliot"));
|
||||||
|
playerMgr.New(playerCounter++, surfaceMgr->Get("coa"));
|
||||||
|
playerMgr.New(playerCounter++, surfaceMgr->Get("coa"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestSystems::~TestSystems() {
|
TestSystems::~TestSystems() {
|
||||||
|
playerMgr.DeleteAll();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "leaving TestSystems" << endl;
|
cout << "leaving TestSystems" << endl;
|
||||||
#endif
|
#endif
|
||||||
@@ -27,7 +35,7 @@ TestSystems::~TestSystems() {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void TestSystems::FrameStart() {
|
void TestSystems::FrameStart() {
|
||||||
//
|
frameRate.Calculate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSystems::FrameEnd() {
|
void TestSystems::FrameEnd() {
|
||||||
@@ -35,11 +43,12 @@ void TestSystems::FrameEnd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TestSystems::Update() {
|
void TestSystems::Update() {
|
||||||
//
|
delta.Calculate();
|
||||||
|
playerMgr.UpdateAll(delta.GetDelta());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSystems::Render(SDL_Surface* const screen) {
|
void TestSystems::Render(SDL_Surface* const screen) {
|
||||||
//
|
playerMgr.DrawAllTo(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -61,11 +70,80 @@ void TestSystems::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
|||||||
void TestSystems::KeyDown(SDL_KeyboardEvent const& key) {
|
void TestSystems::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
switch(key.keysym.sym) {
|
switch(key.keysym.sym) {
|
||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
QuitEvent();
|
SetNextScene(SceneList::MAINMENU);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDLK_w:
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::NORTH);
|
||||||
|
break;
|
||||||
|
case SDLK_s:
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::SOUTH);
|
||||||
|
break;
|
||||||
|
case SDLK_a:
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::WEST);
|
||||||
|
break;
|
||||||
|
case SDLK_d:
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::EAST);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDLK_1:
|
||||||
|
SwitchToPlayer(0);
|
||||||
|
break;
|
||||||
|
case SDLK_2:
|
||||||
|
SwitchToPlayer(1);
|
||||||
|
break;
|
||||||
|
case SDLK_3:
|
||||||
|
SwitchToPlayer(2);
|
||||||
|
break;
|
||||||
|
case SDLK_4:
|
||||||
|
SwitchToPlayer(3);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSystems::KeyUp(SDL_KeyboardEvent const& key) {
|
void TestSystems::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
//
|
switch(key.keysym.sym) {
|
||||||
|
case SDLK_w:
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::SOUTH);
|
||||||
|
break;
|
||||||
|
case SDLK_s:
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::NORTH);
|
||||||
|
break;
|
||||||
|
case SDLK_a:
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::EAST);
|
||||||
|
break;
|
||||||
|
case SDLK_d:
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::WEST);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Utilities
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void TestSystems::NewPlayer(int index, std::string avatarName, int x, int y) {
|
||||||
|
Player* p = playerMgr.New(index, surfaceMgr->Get(avatarName));
|
||||||
|
p->SetPosition(Vector2(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestSystems::SwitchToPlayer(int index) {
|
||||||
|
//dirty hacks for smooth movement
|
||||||
|
playerMgr[currentPlayer]->SetMotion(Vector2(0,0));
|
||||||
|
currentPlayer = index;
|
||||||
|
|
||||||
|
Uint8* key = SDL_GetKeyState(nullptr);
|
||||||
|
|
||||||
|
if (key[SDLK_w]) {
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::NORTH);
|
||||||
|
}
|
||||||
|
if (key[SDLK_s]) {
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::SOUTH);
|
||||||
|
}
|
||||||
|
if (key[SDLK_a]) {
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::WEST);
|
||||||
|
}
|
||||||
|
if (key[SDLK_d]) {
|
||||||
|
playerMgr[currentPlayer]->WalkInDirection(Direction::EAST);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,15 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
#include "player_manager.hpp"
|
||||||
|
|
||||||
|
#include "delta.hpp"
|
||||||
|
#include "frame_rate.hpp"
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "surface_manager.hpp"
|
#include "surface_manager.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class TestSystems : public BaseScene {
|
class TestSystems : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
@@ -26,9 +32,20 @@ protected:
|
|||||||
virtual void KeyDown(SDL_KeyboardEvent const&);
|
virtual void KeyDown(SDL_KeyboardEvent const&);
|
||||||
virtual void KeyUp(SDL_KeyboardEvent const&);
|
virtual void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
|
//utilities
|
||||||
|
void NewPlayer(int index, std::string avatarName, int x, int y);
|
||||||
|
void SwitchToPlayer(int index);
|
||||||
|
|
||||||
//members
|
//members
|
||||||
|
PlayerManager playerMgr;
|
||||||
|
|
||||||
|
Delta delta;
|
||||||
|
FrameRate frameRate;
|
||||||
ConfigUtility* configUtil;
|
ConfigUtility* configUtil;
|
||||||
SurfaceManager* surfaceMgr;
|
SurfaceManager* surfaceMgr;
|
||||||
|
|
||||||
|
int playerCounter;
|
||||||
|
int currentPlayer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
Client:
|
||||||
|
SceneManager:
|
||||||
|
TCPSocket
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Server:
|
||||||
|
TCPServerSocket
|
||||||
|
SocketList --list of all client sockets if one is closed, remove it.
|
||||||
|
end
|
||||||
|
|
||||||
|
When the player enters the lobby, they can choose what server to connect to. When they connect to the server, they'll enter a sort of character creation screen. Once that is done, they will enter the game world proper.
|
||||||
|
|
||||||
|
This is controlled through the config files for now.
|
||||||
|
|
||||||
|
using ';' delimited commands, how can I get it to work?
|
||||||
Reference in New Issue
Block a user