Skip to content

Commit

Permalink
Add a "loading map" state that does nothing
Browse files Browse the repository at this point in the history
but draw a blank screen while loading the map.
  • Loading branch information
rohit-n committed Dec 21, 2015
1 parent 74bf57f commit a6668ff
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 9 deletions.
12 changes: 9 additions & 3 deletions draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,16 @@ void Renderer::drawState(BaseState* state)
{
size_t i;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (dynamic_cast<MenuState*>(state))
bool is_menu = dynamic_cast<MenuState*>(state);
bool is_game = dynamic_cast<GameState*>(state);
if (is_menu)
{
for (i = 0; i < static_cast<MenuState*>(state)->getButtonCount(); i++)
{
drawButton(static_cast<MenuState*>(state)->getButtonAt(i));
}
}
else
else if (is_game)
{
drawScene(static_cast<GameState*>(state)->getScene());
}
Expand All @@ -448,7 +450,11 @@ void Renderer::drawState(BaseState* state)
{
drawTextLabel(state->getLabelAt(i));
}
drawMouseCursor(state);

if (is_menu || is_game)
{
drawMouseCursor(state);
}
}

void Renderer::drawMouseCursor(BaseState* state)
Expand Down
63 changes: 63 additions & 0 deletions loadingmapstate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2013-2015 Rohit Nirmal
This file is part of Clonepoint.
Clonepoint is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clonepoint is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clonepoint. If not, see <http://www.gnu.org/licenses/>.
*/

#include "loadingmapstate.h"

LoadingMapState::LoadingMapState(StateManager* sm) : BaseState(sm)
{
_mapFilename = "";
_timer = 0;
_loaded = false;
}

LoadingMapState::~LoadingMapState()
{
}

void LoadingMapState::update(unsigned int dT)
{
_timer += dT;

if (_timer > 50 && ! _loaded)
{
_manager->initSceneAndMap(_mapFilename.c_str());
_manager->makeStartSave();
Locator::getAudio()->playMusic("groove_grove.ogg");
_loaded = true;
}

if (_timer > 100)
{
//give a little extra time before displaying to avoid seeing the last
//game (if you exited to the main menu and loaded another map).
_manager->switchToState(GAME_SCREEN);
}
}

void LoadingMapState::handleKeyDown(SDL_Keycode){}
void LoadingMapState::handleKeyUp(SDL_Keycode){}
void LoadingMapState::handleMouseDown(SDL_MouseButtonEvent event){}
void LoadingMapState::handleMouseUp(SDL_MouseButtonEvent event){}

void LoadingMapState::setMap(std::string mapFilename)
{
_mapFilename = mapFilename;
_timer = 0;
_loaded = false;
}
42 changes: 42 additions & 0 deletions loadingmapstate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2013-2015 Rohit Nirmal
This file is part of Clonepoint.
Clonepoint is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clonepoint is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clonepoint. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LOADINGMAPSTATE_H
#define LOADINGMAPSTATE_H
#include "state.h"
#include "statemanager.h"

class LoadingMapState : public BaseState
{
public:
LoadingMapState(StateManager* sm);
~LoadingMapState();
void update(unsigned int dT);
void handleKeyDown(SDL_Keycode);
void handleKeyUp(SDL_Keycode);
void handleMouseDown(SDL_MouseButtonEvent event);
void handleMouseUp(SDL_MouseButtonEvent event);
void setMap(std::string mapFilename);
private:
std::string _mapFilename;
unsigned int _timer;
bool _loaded;
};

#endif
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ along with Clonepoint. If not, see <http://www.gnu.org/licenses/>.
#include "levelendstate.cpp"
#include "linkableentity.cpp"
#include "livingentity.cpp"
#include "loadingmapstate.cpp"
#include "loadmapstate.cpp"
#include "locator.cpp"
#include "map.cpp"
Expand Down
5 changes: 4 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CXX=g++
CFLAGS= -Wall -pedantic
OBJECTS = statemanager.o audio.o locator.o draw.o static_sprites.o animations.o vec.o matrix.o map.o texture.o button.o scene.o scene_guards.o scene_trace.o bindings.o \
scene_physics.o scene_saved_game.o intersect.o state.o file.o entity.o enemy.o linkableentity.o player.o elevators.o fieldofview.o config.o font.o \
livingentity.o stairs.o menustate.o mainmenustate.o creditsstate.o gamestate.o levelendstate.o pausestate.o loadmapstate.o optionsstate.o upgradesstate.o sprite.o \
livingentity.o stairs.o menustate.o mainmenustate.o creditsstate.o gamestate.o loadingmapstate.o levelendstate.o pausestate.o loadmapstate.o optionsstate.o upgradesstate.o sprite.o \
tinyxml/tinyxml.o tinyxml/tinystr.o tinyxml/tinyxmlparser.o tinyxml/tinyxmlerror.o

ifneq (, $(findstring mingw, $(SYS)))
Expand Down Expand Up @@ -94,6 +94,9 @@ intersect.o: intersect.cpp intersect.h vec.o
gamestate.o: gamestate.cpp gamestate.h state.o scene.o bindings.o
$(CXX) gamestate.cpp $(CFLAGS) -c

loadingmapstate.o: loadingmapstate.cpp loadingmapstate.h state.o scene.o
$(CXX) loadingmapstate.cpp $(CFLAGS) -c

menustate.o: menustate.cpp menustate.h state.o button.o
$(CXX) menustate.cpp $(CFLAGS) -c

Expand Down
10 changes: 9 additions & 1 deletion statemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ along with Clonepoint. If not, see <http://www.gnu.org/licenses/>.
#include "creditsstate.h"
#include "levelendstate.h"
#include "pausestate.h"
#include "loadingmapstate.h"
#include "loadmapstate.h"
#include "optionsstate.h"
#include "upgradesstate.h"
Expand All @@ -35,6 +36,7 @@ StateManager::StateManager()
_creditsState = new CreditsState(this);
_levelEndState = new LevelEndState(this);
_pauseState = new PauseState(this);
_loadingMapState = new LoadingMapState(this);
_loadMapState = new LoadMapState(this);
_optionsState = new OptionsState(this);
_upgradesState = new UpgradesState(this);
Expand All @@ -54,6 +56,7 @@ StateManager::~StateManager()
delete _creditsState;
delete _levelEndState;
delete _pauseState;
delete _loadingMapState;
delete _loadMapState;
delete _optionsState;
delete _upgradesState;
Expand All @@ -73,6 +76,7 @@ void StateManager::switchToState(eState state)
{
GameState* gs = static_cast<GameState*>(_gameState);
UpgradesState* us = static_cast<UpgradesState*>(_upgradesState);
LoadingMapState* lms = static_cast<LoadingMapState*>(_loadingMapState);
int jp, jt, timeToSniper, old_x, old_y;
unsigned int ammo, energy;
_activeState->getMousePosition(&old_x, &old_y);
Expand All @@ -83,7 +87,7 @@ void StateManager::switchToState(eState state)
_activeState = _mainMenuState;
break;
case GAME_SCREEN:
if (_activeState == _upgradesState)
if (_activeState == _loadingMapState)
{
us->getModifiers(&jp, &jt, &ammo, &timeToSniper, &energy);
gs->getScene()->addPlayerJumpPower((float)jp / 50.0f);
Expand All @@ -103,6 +107,10 @@ void StateManager::switchToState(eState state)
case PAUSE_SCREEN:
_activeState = _pauseState;
break;
case LOADINGMAP_SCREEN:
lms->setMap(_activeMapFilename);
_activeState = _loadingMapState;
break;
case LOADMAP_SCREEN:
_activeState = _loadMapState;
break;
Expand Down
2 changes: 2 additions & 0 deletions statemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum eState
CREDITS_SCREEN,
LEVELEND_SCREEN,
PAUSE_SCREEN,
LOADINGMAP_SCREEN,
LOADMAP_SCREEN,
OPTIONS_SCREEN,
UPGRADES_SCREEN
Expand Down Expand Up @@ -65,6 +66,7 @@ class StateManager
BaseState* _creditsState;
BaseState* _levelEndState;
BaseState* _pauseState;
BaseState* _loadingMapState;
BaseState* _loadMapState;
BaseState* _optionsState;
BaseState* _upgradesState;
Expand Down
5 changes: 1 addition & 4 deletions upgradesstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ void UpgradesState::handleButton(Button* button)
}
else if (button == _startMapButton)
{
_manager->initSceneAndMap(_mapFilename.c_str());
_manager->switchToState(GAME_SCREEN);
_manager->makeStartSave();
Locator::getAudio()->playMusic("groove_grove.ogg");
_manager->switchToState(LOADINGMAP_SCREEN);
}
else if (button == _jumpPowerDecr && _jumpPower > 0)
{
Expand Down

0 comments on commit a6668ff

Please sign in to comment.