Created the client program's framework
There are six scenes here, each of which representing roughly one part of the final program's backbone.
This commit is contained in:
@@ -0,0 +1,139 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Static declarations
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
SDL_Surface* BaseScene::screen = nullptr;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
BaseScene::BaseScene() {
|
||||||
|
nextScene = SceneList::CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseScene::~BaseScene() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Program control
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
SDL_Surface* BaseScene::SetScreen(int w, int h, int bpp, Uint32 flags) {
|
||||||
|
if (!bpp) {
|
||||||
|
bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
|
||||||
|
}
|
||||||
|
|
||||||
|
screen = SDL_SetVideoMode(w, h, bpp, flags);
|
||||||
|
|
||||||
|
if (!screen) {
|
||||||
|
throw(std::runtime_error("Failed to create the screen surface"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return screen;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Surface* BaseScene::GetScreen() {
|
||||||
|
return screen;
|
||||||
|
}
|
||||||
|
|
||||||
|
SceneList BaseScene::SetNextScene(SceneList sceneIndex) {
|
||||||
|
return nextScene = sceneIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
SceneList BaseScene::GetNextScene() const {
|
||||||
|
return nextScene;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void BaseScene::RunFrame(double delta) {
|
||||||
|
FrameStart();
|
||||||
|
HandleEvents();
|
||||||
|
Update(delta);
|
||||||
|
FrameEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseScene::RenderFrame() {
|
||||||
|
SDL_FillRect(screen, 0, 0);
|
||||||
|
Render(screen);
|
||||||
|
SDL_Flip(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void BaseScene::HandleEvents() {
|
||||||
|
SDL_Event event;
|
||||||
|
|
||||||
|
while(SDL_PollEvent(&event)) {
|
||||||
|
switch(event.type) {
|
||||||
|
case SDL_QUIT:
|
||||||
|
QuitEvent();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_VIDEORESIZE:
|
||||||
|
SetScreen(event.resize.w, event.resize.h, 0, screen->flags);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
MouseMotion(event.motion);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
MouseButtonDown(event.button);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
MouseButtonUp(event.button);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
KeyDown(event.key);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_KEYUP:
|
||||||
|
KeyUp(event.key);
|
||||||
|
break;
|
||||||
|
|
||||||
|
#ifdef USE_EVENT_JOYSTICK
|
||||||
|
//TODO: joystick/gamepad support
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_EVENT_UNKNOWN
|
||||||
|
default:
|
||||||
|
UnknownEvent(event);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
}//switch
|
||||||
|
}//while
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef BASESCENE_HPP_
|
||||||
|
#define BASESCENE_HPP_
|
||||||
|
|
||||||
|
#include "scene_list.hpp"
|
||||||
|
|
||||||
|
#include "SDL/SDL.h"
|
||||||
|
|
||||||
|
class BaseScene {
|
||||||
|
public:
|
||||||
|
/* Public access members */
|
||||||
|
BaseScene();
|
||||||
|
virtual ~BaseScene();
|
||||||
|
|
||||||
|
/* Program control */
|
||||||
|
static SDL_Surface* SetScreen(int w, int h, int bpp = 0, Uint32 flags = SDL_HWSURFACE|SDL_DOUBLEBUF);
|
||||||
|
static SDL_Surface* GetScreen();
|
||||||
|
|
||||||
|
SceneList SetNextScene(SceneList sceneIndex);
|
||||||
|
SceneList GetNextScene() const;
|
||||||
|
|
||||||
|
/* Frame loop */
|
||||||
|
virtual void RunFrame(double delta);
|
||||||
|
virtual void RenderFrame();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void FrameStart() {}
|
||||||
|
virtual void HandleEvents();
|
||||||
|
virtual void Update(double delta) {}
|
||||||
|
virtual void FrameEnd() {}
|
||||||
|
virtual void Render(SDL_Surface* const screen) {}
|
||||||
|
|
||||||
|
/* Event handlers */
|
||||||
|
virtual void QuitEvent() { SetNextScene(SceneList::QUIT); }
|
||||||
|
virtual void MouseMotion(SDL_MouseMotionEvent const&) {}
|
||||||
|
virtual void MouseButtonDown(SDL_MouseButtonEvent const&) {}
|
||||||
|
virtual void MouseButtonUp(SDL_MouseButtonEvent const&) {}
|
||||||
|
virtual void KeyDown(SDL_KeyboardEvent const&) {}
|
||||||
|
virtual void KeyUp(SDL_KeyboardEvent const&) {}
|
||||||
|
|
||||||
|
#ifdef USE_EVENT_JOYSTICK
|
||||||
|
//TODO: joystick/gamepad support
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_EVENT_UNKNOWN
|
||||||
|
virtual void UnknownEvent(SDL_Event const&) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
static SDL_Surface* screen;
|
||||||
|
SceneList nextScene;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#include "in_combat.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
InCombat::InCombat() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "entering InCombat" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
InCombat::~InCombat() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "leaving InCombat" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void InCombat::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InCombat::Update(double delta) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InCombat::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InCombat::Render(SDL_Surface* const screen) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void InCombat::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InCombat::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InCombat::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InCombat::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
QuitEvent();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InCombat::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef INCOMBAT_HPP_
|
||||||
|
#define INCOMBAT_HPP_
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
class InCombat : public BaseScene {
|
||||||
|
public:
|
||||||
|
/* Public access members */
|
||||||
|
InCombat();
|
||||||
|
~InCombat();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* Frame loop */
|
||||||
|
void FrameStart();
|
||||||
|
void Update(double delta);
|
||||||
|
void FrameEnd();
|
||||||
|
void Render(SDL_Surface* const);
|
||||||
|
|
||||||
|
/* Event handlers */
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const&);
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||||
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#include "in_world.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
InWorld::InWorld() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "entering InWorld" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
InWorld::~InWorld() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "leaving InWorld" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void InWorld::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::Update(double delta) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::Render(SDL_Surface* const screen) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void InWorld::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
QuitEvent();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef INWORLD_HPP_
|
||||||
|
#define INWORLD_HPP_
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
class InWorld : public BaseScene {
|
||||||
|
public:
|
||||||
|
/* Public access members */
|
||||||
|
InWorld();
|
||||||
|
~InWorld();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* Frame loop */
|
||||||
|
void FrameStart();
|
||||||
|
void Update(double delta);
|
||||||
|
void FrameEnd();
|
||||||
|
void Render(SDL_Surface* const);
|
||||||
|
|
||||||
|
/* Event handlers */
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const&);
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||||
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#include "lobby.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
Lobby::Lobby() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "entering Lobby" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
Lobby::~Lobby() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "leaving Lobby" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void Lobby::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lobby::Update(double delta) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lobby::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lobby::Render(SDL_Surface* const screen) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void Lobby::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lobby::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lobby::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lobby::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
QuitEvent();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Lobby::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef LOBBY_HPP_
|
||||||
|
#define LOBBY_HPP_
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
class Lobby : public BaseScene {
|
||||||
|
public:
|
||||||
|
/* Public access members */
|
||||||
|
Lobby();
|
||||||
|
~Lobby();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* Frame loop */
|
||||||
|
void FrameStart();
|
||||||
|
void Update(double delta);
|
||||||
|
void FrameEnd();
|
||||||
|
void Render(SDL_Surface* const);
|
||||||
|
|
||||||
|
/* Event handlers */
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const&);
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||||
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "scene_manager.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int, char**) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "Beginning program" << endl;
|
||||||
|
#endif
|
||||||
|
try {
|
||||||
|
SceneManager app;
|
||||||
|
app.Init();
|
||||||
|
app.Proc();
|
||||||
|
app.Quit();
|
||||||
|
}
|
||||||
|
catch(exception& e) {
|
||||||
|
cerr << "Fatal error: " << e.what() << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "Clean exit" << endl;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#include "main_menu.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
MainMenu::MainMenu() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "entering MainMenu" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
MainMenu::~MainMenu() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "leaving MainMenu" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void MainMenu::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::Update(double delta) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::Render(SDL_Surface* const screen) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void MainMenu::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
QuitEvent();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef MAINMENU_HPP_
|
||||||
|
#define MAINMENU_HPP_
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
class MainMenu : public BaseScene {
|
||||||
|
public:
|
||||||
|
/* Public access members */
|
||||||
|
MainMenu();
|
||||||
|
~MainMenu();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* Frame loop */
|
||||||
|
void FrameStart();
|
||||||
|
void Update(double delta);
|
||||||
|
void FrameEnd();
|
||||||
|
void Render(SDL_Surface* const);
|
||||||
|
|
||||||
|
/* Event handlers */
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const&);
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||||
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#config
|
||||||
|
LIBDIR=../libs
|
||||||
|
LIB=-lmingw32 -lSDLmain -lSDL $(LIBDIR)/out/libCodebase.a $(LIBDIR)/out/libSDL_net.a
|
||||||
|
INCLUDES=$(LIBDIR)/Codebase $(LIBDIR)/SDL_net
|
||||||
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
SRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=../out
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,client)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIB)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#include "option_screen.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
OptionScreen::OptionScreen() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "entering OptionScreen" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionScreen::~OptionScreen() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "leaving OptionScreen" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void OptionScreen::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionScreen::Update(double delta) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionScreen::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionScreen::Render(SDL_Surface* const screen) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void OptionScreen::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionScreen::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionScreen::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionScreen::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
QuitEvent();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionScreen::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef OPTIONSCREEN_HPP_
|
||||||
|
#define OPTIONSCREEN_HPP_
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
class OptionScreen : public BaseScene {
|
||||||
|
public:
|
||||||
|
/* Public access members */
|
||||||
|
OptionScreen();
|
||||||
|
~OptionScreen();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* Frame loop */
|
||||||
|
void FrameStart();
|
||||||
|
void Update(double delta);
|
||||||
|
void FrameEnd();
|
||||||
|
void Render(SDL_Surface* const);
|
||||||
|
|
||||||
|
/* Event handlers */
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const&);
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||||
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef SCENELIST_HPP_
|
||||||
|
#define SCENELIST_HPP_
|
||||||
|
|
||||||
|
enum class SceneList {
|
||||||
|
//these are reserved
|
||||||
|
QUIT,
|
||||||
|
CONTINUE,
|
||||||
|
FIRST,
|
||||||
|
|
||||||
|
//custom indexes
|
||||||
|
INCOMBAT,
|
||||||
|
INWORLD,
|
||||||
|
LOBBY,
|
||||||
|
MAINMENU,
|
||||||
|
OPTIONSCREEN,
|
||||||
|
SPLASHSCREEN,
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "scene_manager.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Scene headers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//Add the custom scene headers here
|
||||||
|
#include "in_combat.hpp"
|
||||||
|
#include "in_world.hpp"
|
||||||
|
#include "lobby.hpp"
|
||||||
|
#include "main_menu.hpp"
|
||||||
|
#include "option_screen.hpp"
|
||||||
|
#include "splash_screen.hpp"
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
SceneManager::SceneManager() {
|
||||||
|
activeScene = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
SceneManager::~SceneManager() {
|
||||||
|
UnloadScene();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneManager::Init() {
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO))
|
||||||
|
throw(std::runtime_error("Failed to initialize SDL"));
|
||||||
|
|
||||||
|
BaseScene::SetScreen(800, 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneManager::Proc() {
|
||||||
|
LoadScene(SceneList::FIRST);
|
||||||
|
|
||||||
|
//prepare the time system
|
||||||
|
typedef std::chrono::high_resolution_clock Clock;
|
||||||
|
|
||||||
|
Clock::duration delta(16 * Clock::duration::period::den / std::milli::den);
|
||||||
|
Clock::time_point simTime = Clock::now();
|
||||||
|
Clock::time_point realTime;
|
||||||
|
|
||||||
|
//The main loop
|
||||||
|
while(activeScene->GetNextScene() != SceneList::QUIT) {
|
||||||
|
//switch scenes when necessary
|
||||||
|
if (activeScene->GetNextScene() != SceneList::CONTINUE) {
|
||||||
|
LoadScene(activeScene->GetNextScene());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the current time
|
||||||
|
realTime = Clock::now();
|
||||||
|
|
||||||
|
//simulate game time
|
||||||
|
while (simTime < realTime) {
|
||||||
|
//call each user defined function
|
||||||
|
activeScene->RunFrame(double(delta.count()) / Clock::duration::period::den);
|
||||||
|
simTime += delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
//draw the game to the screen
|
||||||
|
activeScene->RenderFrame();
|
||||||
|
|
||||||
|
//give the computer a break
|
||||||
|
SDL_Delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
UnloadScene();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneManager::Quit() {
|
||||||
|
UnloadScene();
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Private access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void SceneManager::LoadScene(SceneList sceneIndex) {
|
||||||
|
UnloadScene();
|
||||||
|
|
||||||
|
switch(sceneIndex) {
|
||||||
|
//add scene creation calls here
|
||||||
|
case SceneList::INCOMBAT:
|
||||||
|
activeScene = new InCombat();
|
||||||
|
break;
|
||||||
|
case SceneList::INWORLD:
|
||||||
|
activeScene = new InWorld();
|
||||||
|
break;
|
||||||
|
case SceneList::LOBBY:
|
||||||
|
activeScene = new Lobby();
|
||||||
|
break;
|
||||||
|
case SceneList::MAINMENU:
|
||||||
|
activeScene = new MainMenu();
|
||||||
|
break;
|
||||||
|
case SceneList::OPTIONSCREEN:
|
||||||
|
activeScene = new OptionScreen();
|
||||||
|
break;
|
||||||
|
case SceneList::FIRST:
|
||||||
|
case SceneList::SPLASHSCREEN:
|
||||||
|
activeScene = new SplashScreen();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw(std::logic_error("Failed to recognize the scene index"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneManager::UnloadScene() {
|
||||||
|
delete activeScene;
|
||||||
|
activeScene = nullptr;
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef SCENEMANAGER_HPP_
|
||||||
|
#define SCENEMANAGER_HPP_
|
||||||
|
|
||||||
|
#include "scene_list.hpp"
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
#include "SDL/SDL.h"
|
||||||
|
|
||||||
|
class SceneManager {
|
||||||
|
public:
|
||||||
|
/* Public access members */
|
||||||
|
SceneManager();
|
||||||
|
~SceneManager();
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
void Proc();
|
||||||
|
void Quit();
|
||||||
|
|
||||||
|
private:
|
||||||
|
/* Private access members */
|
||||||
|
void LoadScene(SceneList sceneIndex);
|
||||||
|
void UnloadScene();
|
||||||
|
|
||||||
|
BaseScene* activeScene;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#include "splash_screen.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
SplashScreen::SplashScreen() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "entering SplashScreen" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
SplashScreen::~SplashScreen() {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "leaving SplashScreen" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void SplashScreen::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreen::Update(double delta) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreen::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreen::Render(SDL_Surface* const screen) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void SplashScreen::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreen::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreen::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreen::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
QuitEvent();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplashScreen::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef SPLASHSCREEN_HPP_
|
||||||
|
#define SPLASHSCREEN_HPP_
|
||||||
|
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
class SplashScreen : public BaseScene {
|
||||||
|
public:
|
||||||
|
/* Public access members */
|
||||||
|
SplashScreen();
|
||||||
|
~SplashScreen();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* Frame loop */
|
||||||
|
void FrameStart();
|
||||||
|
void Update(double delta);
|
||||||
|
void FrameEnd();
|
||||||
|
void Render(SDL_Surface* const);
|
||||||
|
|
||||||
|
/* Event handlers */
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const&);
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||||
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -12,7 +12,7 @@ OBJ=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o))
|
|||||||
|
|
||||||
#output
|
#output
|
||||||
OUTDIR=../out
|
OUTDIR=../out
|
||||||
OUT=$(addprefix $(OUTDIR)/,Codebase.a)
|
OUT=$(addprefix $(OUTDIR)/,libCodebase.a)
|
||||||
|
|
||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
|
|||||||
Reference in New Issue
Block a user