Permalink
Browse files

FIX use constant for path

ADD position parameter for initPhysics and read from xml
  • Loading branch information...
1 parent 1aad993 commit ec9278c2bd8520fb4d7196bf3f41e61f442ac2e7 @PowerKiKi committed May 20, 2009
@@ -96,7 +96,7 @@ namespace Polukili
/*************************************************/
string Actor::getImagePath() const
{
- return "/app/polukili/data/default.png";
+ return Constants::basePath + "default.png";
}
/*************************************************/
@@ -89,7 +89,7 @@ namespace Polukili
/**
* Initialize physic data
*/
- virtual void initPhysic() = 0;
+ virtual void initPhysic(float x, float y) = 0;
/**
* Returns the path to the image for the sprite.
@@ -5,6 +5,8 @@ namespace Polukili
/*Sets the values of the constraints*/
+ const string Constants::basePath("/APPS/Polukili/data/");
+
// scale between Box2D units and Screen units(pixels)
const int Constants::pixelsPerUnits = 15;
@@ -1,6 +1,10 @@
#ifndef polukili_Constant_h_5932f181_5c91_439d_82ad_c1b3e506a9bf
#define polukili_Constant_h_5932f181_5c91_439d_82ad_c1b3e506a9bf
+#include <string>
+
+using namespace std;
+
namespace Polukili
{
/**
@@ -10,6 +14,11 @@ namespace Polukili
{
public :
+ /**
+ * Base path for data
+ */
+ static const string basePath;
+
static const int pixelsPerUnits;
static const float defaultGravity;
@@ -32,7 +32,7 @@ namespace Polukili
}
/*************************************************/
- void Ennemy::initPhysic()
+ void Ennemy::initPhysic(float x, float y)
{
// TODO: should do something here
}
@@ -25,7 +25,7 @@ namespace Polukili
*/
virtual ~Ennemy();
- virtual void initPhysic();
+ virtual void initPhysic(float x, float y);
/**
@@ -9,6 +9,8 @@
#include <Game.h>
#include <ImageLibrary.h>
+#include <Bullets/Bullet.h>
+#include <Pets/Pet.h>
#include <Players/Player.h>
#include <Players/Poupa.h>
#include <Players/Luna.h>
@@ -132,6 +134,11 @@ namespace Polukili
actor = new Ennemies::Earthworm(this);
else
continue;
+
+
+ float x = (float)atof(mxmlElementGetAttr(data->child, "x"));
+ float y = (float)atof(mxmlElementGetAttr(data->child, "y"));
+ actor->initPhysic(x, y);
Ennemies::Ennemy* ennemy = dynamic_cast<Ennemies::Ennemy*>(actor);
if (ennemy && stricmp(mxmlElementGetAttr(data, "isTarget"), "True") == 0)
@@ -196,7 +203,7 @@ namespace Polukili
for (list<Players::Player*>::iterator it = this->players.begin(); it != this->players.end(); it++)
(*it)->render();
- for (list<Bullets::Bullet*>::iterator it = this->pets.begin(); it != this->pets.end(); it++)
+ for (list<Pets::Pet*>::iterator it = this->pets.begin(); it != this->pets.end(); it++)
(*it)->render();
for (list<Bullets::Bullet*>::iterator it = this->bullets.begin(); it != this->bullets.end(); it++)
@@ -1,5 +1,6 @@
#include <Players/Player.h>
+#include <Constants.h>
#include <Level.h>
namespace Polukili
@@ -22,11 +23,29 @@ namespace Polukili
/*************************************************/
- void Player::initPhysic()
+ void Player::initPhysic(float x, float y)
{
// TODO: should do something here
}
+ /*************************************************/
+ string Player::getImagePath() const
+ {
+ return Constants::basePath + "player.png";
+ }
+
+ /*************************************************/
+ int Player::getImageWidth() const
+ {
+ return 96;
+ }
+
+ /*************************************************/
+ int Player::getImageHeight() const
+ {
+ return 48;
+ }
+
} /* End of namespace Polukili::Players */
} /* End of namespace Polukili */
@@ -23,13 +23,27 @@ namespace Polukili
/**
* Destructor
*/
- virtual ~Player();
-
+ virtual ~Player();
/**
* Initialize physic data
*/
- virtual void initPhysic();
+ virtual void initPhysic(float x, float y);
+
+ /**
+ * Returns the path to the image for the sprite.
+ */
+ virtual string getImagePath() const;
+
+ /**
+ * Returns the width of the tile in the image (must be multiple of 4).
+ */
+ virtual int getImageWidth() const;
+
+ /**
+ * Returns the height of the tile in the image (must be multiple of 4).
+ */
+ virtual int getImageHeight() const;
//end of class Player
@@ -1,9 +1,10 @@
+#include <Constants.h>
#include <Game.h>
int main( int argc, char **argv )
{
Polukili::Game game;
- game.run("/app/polukili/level_0.xml");
+ game.run(Polukili::Constants::basePath + "level_0.xml");
return 0;
}
View
@@ -0,0 +1 @@
+optimization de drawing avec requete AABB et dessin uniquement des acteurs dans l'ecran courant

0 comments on commit ec9278c

Please sign in to comment.