Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

forgot to add the file

  • Loading branch information...
commit bf1d7a70f6abb174c75d564492ea0e3adb0a246a 1 parent 6eeddae
Dmytro Lytovchenko authored
View
3  src/player.cpp
@@ -167,7 +167,8 @@ void Player::Think()
bool hitting_the_ceiling = solid_above_top_left || solid_above_top_right;
if( hitting_the_ceiling ) {
// stop flying, hit the ceiling
- m_speed.y = 0;
+ m_speed.y = 0;
+ // doesn't work: m_speed.y = -m_speed.y;
} else {
hgeRect future_pos = m_position;
future_pos.y1 += m_speed.y * delta;
View
52 src/sprite_manager.cpp
@@ -0,0 +1,52 @@
+// base Creature class
+// represents a walking or stationary creature which is able to kill player
+// on touch.
+//
+// TODO: more various creature behaviours like ability to shoot, jump, fly?
+#include "sprite_manager.h"
+#include <hgesprite.h>
+
+
+SpriteManager::SpriteManager()
+{
+ // this will not create another HGE, instead we will get the global
+ // unique HGE object which is already started
+ m_hge = hgeCreate( HGE_VERSION );
+}
+
+hgeSprite * SpriteManager::GetSprite( const std::string & name )
+{
+ // attempt to find the requested texture in cache
+ string_to_htexture_map_t::iterator iter = m_tex_map.find( name );
+ HTEXTURE t = 0;
+
+ if( iter != m_tex_map.end() ) {
+ // use texture from cache
+ t = iter->second;
+ } else {
+ // attempt to load the texture
+ t = m_hge->Texture_Load( name.c_str() );
+ }
+
+ // if loading failed
+ if( ! t ) return NULL;
+
+ hgeSprite * spr = new hgeSprite(
+ t, 0.0f, 0.0f,
+ (float)m_hge->Texture_GetWidth(t), (float)m_hge->Texture_GetHeight(t)
+ );
+ return spr;
+}
+
+SpriteManager::~SpriteManager()
+{
+ // to free all textures we might have loaded during this world
+ for( string_to_htexture_map_t::iterator iter = m_tex_map.begin();
+ iter != m_tex_map.end();
+ ++iter )
+ {
+ m_hge->Texture_Free( iter->second );
+ }
+
+ m_hge->Release();
+}
View
29 src/sprite_manager.h
@@ -0,0 +1,29 @@
+// to prevent multiple compiling of this header
+#pragma once
+
+#include <map>
+#include <string>
+
+#include <hge.h>
+
+class hgeSprite;
+
+// SpriteManager class
+// Contains set of loaded textures, can load more textures
+// hands out sprites using those textures
+// frees textures it owns when manager is destroyed
+class SpriteManager
+{
+protected:
+ // Textures collection, this will be filled on world loading and freed on world end
+ typedef std::map <std::string, HTEXTURE> string_to_htexture_map_t;
+ string_to_htexture_map_t m_tex_map;
+
+ HGE * m_hge;
+
+public:
+ SpriteManager();
+ virtual ~SpriteManager();
+
+ hgeSprite * GetSprite( const std::string & name );
+};
View
10 src/world.h
@@ -77,14 +77,17 @@ class World
// pixel size of world cells
static const int CELL_BOX_SIZE = 64;
+ static const int SCREEN_WIDTH = 800;
+ static const int SCREEN_HEIGHT = 600;
+
// world visible height will be 9 rows
// roughly 600 pixels screen height divided by 64 pix cell size
// this can be actually more than 9 if your game can also scroll vertically, but you
// will be able to draw only currently visible 9 rows, but this also will require
// writing code to auto detect map height in the input file
- static const int VISIBLE_ROWS = 600/CELL_BOX_SIZE;
+ static const int VISIBLE_ROWS = SCREEN_HEIGHT/CELL_BOX_SIZE;
- static const int VISIBLE_COLS = 800/CELL_BOX_SIZE;
+ static const int VISIBLE_COLS = SCREEN_WIDTH/CELL_BOX_SIZE;
uint32_t m_world_width;
uint32_t m_world_height;
@@ -130,6 +133,9 @@ class World
// tests if cell type is solid or pass-through
inline bool IsSolidAt( float x, float y ) {
+ // always solid for ahead of the visible screen
+ if( x > m_camera_pos.x + SCREEN_WIDTH ) return true;
+
return IsSolid(
At( (uint32_t)(y / CELL_BOX_SIZE), (uint32_t)(x / CELL_BOX_SIZE) )
);
Please sign in to comment.
Something went wrong with that request. Please try again.