use Player static vars for texture loading, and load from the PROJECT_DATA_DIR path
Binary file data/share/skin.png has changed
Binary file pics/skin-mask.png has changed
Binary file pics/skin.png has changed
--- a/src/Config.hh Sat Dec 06 14:28:59 2008 +0000
+++ b/src/Config.hh Sat Dec 06 14:36:37 2008 +0000
@@ -1,6 +1,9 @@
#ifndef CONFIG_HH
#define CONFIG_HH
+// XXX: merge this as Config.hh.in?
+#include "config.h"
+
#include <ClanLib/display.h>
// This is a temporary way to declare different constants. Maybe we
@@ -43,4 +46,7 @@
const CL_Color COLOR_DIRT(144, 82, 23);
const CL_Color COLOR_ROCK(132, 136, 135);
+// Drawing
+const std::string PLAYER_SKIN_PATH = (PROJECT_DATA_DIR "/skin.png");
+
#endif
--- a/src/Player.cc Sat Dec 06 14:28:59 2008 +0000
+++ b/src/Player.cc Sat Dec 06 14:36:37 2008 +0000
@@ -7,19 +7,16 @@
#include <string>
#include <cassert>
-//Player::image = NULL;
+// player static state
+bool Player::skin_loaded = false;
+CL_Surface Player::skin_surface;
-//Player::image = CL_Surface("../../pics/skin.png");
-
-const std::string player_image_filename = "../../pics/skin.png";
+// XXX: give these better names and move elsewhere
const int img_num_aim = 9;
const int img_num_step = 4;
const int img_height = 9;
const int img_width = 10;
-CL_Surface player_image;
-bool player_image_created = false;
-
Player::Player(GameState &state, Vector position, bool visible) :
PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible), arsenal(), selectedWeapon(0), changing(false), animation_step(0) {
// TODO: arsenal's size should be affected by some value
@@ -28,23 +25,21 @@
arsenal.push_back(Weapon(10000, (5-i)*40+30, i*6+5, i*100+50, "asdf"));
}
- // XXX: sanitize
- if (Engine::graphicsEnabled() && !player_image_created) {
- player_image_created = true;
- player_image = CL_Surface(player_image_filename);
- }
-// if(Player::image == NULL) {
-// Player::image = CL_PNGProvider::create("../../pics/skin.png");
-// }
-
+ // build the player's shape
+ // XXX: these dimensions are incorrect...
std::vector<Vector> shape(4);
shape[0] = Vector(0,-9);
shape[1] = Vector(6,0);
shape[2] = Vector(0,9);
shape[3] = Vector(-6,0);
+
// Initialize the shape of the player (salmiakki shape)
setShape(shape);
+
+ // XXX: this should be a PhysicsObject constructor arg
collision_elasticity = PLAYER_COLLISION_ELASTICITY;
+
+ // add to player-object list
world.addPlayerObject(this);
}
@@ -151,18 +146,22 @@
}
void Player::draw(CL_GraphicContext *gc) {
- assert(Engine::graphicsEnabled());
-
int aim_img_idx = (int)((1 - (getAim()+KG_PI/2)/KG_PI)*img_num_aim);
int step_img_idx = animation_step%img_num_step;
+ // load skin image if not yet loaded
+ if (!skin_loaded) {
+ skin_surface = CL_Surface(PLAYER_SKIN_PATH);
+ skin_loaded = true;
+ }
+
CL_Rectf destination(position.x - 4, position.y - 4, position.x + 5, position.y + 4);
if (!getFacing()) {
destination = CL_Rect(position.x + 5, position.y - 4, position.x - 4, position.y + 4);
}
- player_image.draw_subpixel(
+ skin_surface.draw_subpixel(
CL_Rectf(1+step_img_idx*img_width, aim_img_idx*img_height+1, 1+(1+step_img_idx)*img_width, (aim_img_idx+1)*img_height+1),
destination,
gc);
--- a/src/Player.hh Sat Dec 06 14:28:59 2008 +0000
+++ b/src/Player.hh Sat Dec 06 14:36:37 2008 +0000
@@ -31,9 +31,13 @@
public:
void debugInfo ();
+
+ /*
+ * Drawing requires the skin texture, which is loaded on-demand when draw is called
+ */
+ static bool skin_loaded;
+ static CL_Surface skin_surface;
virtual void draw(CL_GraphicContext* gc);
-
- static CL_Surface image;
};
class LocalPlayer : public virtual Player {