Permalink
Browse files

level end condition

  • Loading branch information...
1 parent 2cb0220 commit b7371140ac00e4ae43a5cd3788ac273f9566b307 Dmytro Lytovchenko committed Oct 1, 2011
View
@@ -1,4 +1,6 @@
.build-*/
-bin/
+*.ilk
+*.log
+*.pdb
linklib/
*.log
View
Binary file not shown.
View
Binary file not shown.
View
@@ -4,7 +4,7 @@
# ################ $ ####### ############# ##########
# $ # ############ #### ### #
# @ ##^^#### A ## $ # #### #
-# #A $ ##^######## ### ########### #### # #
+# #A !$ ##^######## ### ########### #### # #
# ###^^#### $ A $ $ A $ # ### $ ### $ A #
#############^###^^###################^^^^^^^^^^^##########^^^^^^^######################^^^^^^^^##############################
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <noInheritable/>
+ <assemblyIdentity
+ type="win32"
+ name="Microsoft.VC90.CRT"
+ version="9.0.21022.8"
+ processorArchitecture="x86"
+ publicKeyToken="1fc8b3b9a1e18e3b"
+ />
+ <file name="msvcr90.dll" /> <file name="msvcp90.dll" /> <file name="msvcm90.dll" />
+</assembly>
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -128,3 +128,21 @@ void WorldObject_Enemy1::Think()
}
}
}
+
+bool WorldObject_LevelEnd::TouchPlayer( Player * pl )
+{
+ // here add code for level end
+ m_world->GoalReached();
+ return true;
+}
+
+WorldObject_LevelEnd::WorldObject_LevelEnd( World * owner, float x, float y )
+ : WorldObject( owner,x,y )
+{
+ m_sprite = owner->m_sprite_manager.GetSprite( "textures/goal_princess.png" );
+}
+
+WorldObject_LevelEnd::~WorldObject_LevelEnd()
+{
+ delete m_sprite;
+}
View
@@ -58,6 +58,22 @@ class WorldObject_Money: public virtual WorldObject
};
+class WorldObject_LevelEnd: public virtual WorldObject
+{
+protected:
+ hgeSprite * m_sprite;
+
+public:
+ WorldObject_LevelEnd(World * owner, float x, float y );
+ virtual ~WorldObject_LevelEnd();
+
+ // no animation
+ virtual hgeSprite * GetSprite() { return m_sprite; }
+
+ virtual bool TouchPlayer( Player * pl );
+};
+
+
class WorldObject_Enemy1: public virtual WorldObject
{
protected:
View
@@ -500,6 +500,14 @@ bool GameState_Play::Think( MyGame * game )
// TODO: Design a way to return events from the World::Think, like inform about player taking damage/dying
if( m_world->Victory() ) {
+ // TODO: Design a intermediate splash screen between levels (like: Level 01 Get ready!)
+ // this should be done using a new GameState_* class
+
+ // for changing level see "OnEnterState()" in this class
+
+ // for now we just return to main menu
+ game->ShowMainMenuScreen();
+ return false;
}
return false;
View
@@ -42,19 +42,14 @@ Player::~Player()
void Player::EnterWorld( World * w )
{
- m_world = w;
-
- // we need a simple way to determine player starting position
- // we scan the world for '@' and use that as start
- for( uint32_t r = 0; r < w->m_world_height; ++r ) {
- for( uint32_t c = 0; c < w->m_world_width; ++c ) {
- if( w->At(r,c) == World::WORLD_CELL_PLAYER_START )
- {
- // found the @ character, set player position
- MoveTo( c * World::CELL_BOX_SIZE, r * World::CELL_BOX_SIZE );
- }
- }
- }
+ m_world = w;
+
+ // we need a simple way to determine player starting position
+ // we scan the world for '@' and use that as start
+ hgeVector player_start = w->FindCellInWorld( World::WORLD_CELL_PLAYER_START );
+
+ // found the @ character, set player position
+ MoveTo( player_start.x, player_start.y );
}
View
@@ -19,7 +19,7 @@
World::World( Player * plr, const std::string & filename )
: m_player(plr), m_world_width(0), m_world_height(0)
- , m_camera_pos(0, 0), m_pause_flag(false)
+ , m_camera_pos(0, 0), m_pause_flag(false), m_level_goal_reached(false)
{
LoadWorld( filename );
@@ -30,11 +30,13 @@ World::World( Player * plr, const std::string & filename )
m_sprite_brick1 = m_sprite_manager.GetSprite("textures/brick1.png");
m_sprite_sky = m_sprite_manager.GetSprite("textures/sky1.png");
m_sprite_spikes = m_sprite_manager.GetSprite("textures/spikes.png");
+ m_sprite_goal = m_sprite_manager.GetSprite("textures/goal_princess.png");
}
World::~World()
{
+ delete m_sprite_goal;
delete m_sprite_spikes;
delete m_sprite_brick1;
delete m_sprite_sky;
@@ -100,6 +102,10 @@ void World::LoadWorld( const std::string & filename )
WorldObject * o = new WorldObject_Enemy1( this, col * CELL_BOX_SIZE, row * CELL_BOX_SIZE );
m_objects.push_back( o );
}
+ else if( contents == WORLD_CELL_GOAL ) {
+ WorldObject * o = new WorldObject_LevelEnd( this, col * CELL_BOX_SIZE, row * CELL_BOX_SIZE );
+ m_objects.push_back( o );
+ }
else {
this->At( row, col ) = contents;
}
@@ -248,3 +254,30 @@ void World::RemoveObject( WorldObject * o )
}
}
}
+
+
+hgeVector World::FindCellInWorld( CellType celltype )
+{
+ // we need a simple way to determine player starting position
+ // we scan the world for '@' and use that as start
+ for( uint32_t r = 0; r < m_world_height; ++r ) {
+ for( uint32_t c = 0; c < m_world_width; ++c ) {
+ if( this->At(r,c) == celltype ) {
+ return hgeVector( c * CELL_BOX_SIZE, r * CELL_BOX_SIZE );
+ }
+ }
+ }
+
+ return hgeVector(-1, -1);
+}
+
+
+void World::GoalReached()
+{
+ m_level_goal_reached = true;
+}
+
+bool World::Victory()
+{
+ return m_level_goal_reached;
+}
View
@@ -58,6 +58,7 @@ class World
hgeSprite * m_sprite_brick1;
hgeSprite * m_sprite_sky;
hgeSprite * m_sprite_spikes;
+ hgeSprite * m_sprite_goal; // level end
// this also delimits max world width in cells, increase if your world grows wider
// actual world will be as wide as the widest line in your level file
@@ -70,6 +71,8 @@ class World
public:
// is the game running or paused (pause to animate player death for example)
bool m_pause_flag;
+ // marks the victory. If this is set, level should change
+ bool m_level_goal_reached;
HGE * m_hge;
@@ -102,12 +105,13 @@ class World
// characters used in map file to represent various world cells
enum {
- WORLD_CELL_EMPTY = ' ',
+ WORLD_CELL_EMPTY = ' ',
WORLD_CELL_PLAYER_START = '@',
- WORLD_CELL_WALL1 = '#',
- WORLD_CELL_MONEY = '$',
- WORLD_CELL_SPIKES = '^',
- WORLD_CELL_ENEMY1 = 'A' // enemy type 1 - edit this to add more enemies
+ WORLD_CELL_WALL1 = '#',
+ WORLD_CELL_MONEY = '$',
+ WORLD_CELL_SPIKES = '^',
+ WORLD_CELL_GOAL = '!', // a princess or other goal, that marks end of the level
+ WORLD_CELL_ENEMY1 = 'A' // enemy type 1 - edit this to add more enemies
};
public:
@@ -117,7 +121,7 @@ class World
// default world can never be "won", you have to inherit the world class
// and override Victory function to define own rules when player wins
- virtual bool Victory() { return false; }
+ virtual bool Victory();
// Animates the world, moves monsters, etc.
virtual void Think();
@@ -176,6 +180,14 @@ class World
// Removes given object from the m_objects, make sure you are not iterating over
// the m_objects list at this moment, or game will crash
void RemoveObject( WorldObject * o );
+
+ // Scans the world searching for value 'c' returns its world coordinates
+ // used to find player starting position and finish cell
+ hgeVector FindCellInWorld( CellType c );
+
+ // This marks end of the level. Inform the calling GameState_Play about level end
+ // and let it delete this world and move to next level
+ virtual void GoalReached();
};

0 comments on commit b737114

Please sign in to comment.