fixed walkingspeed and improved drawing
authornireco
Sat, 06 Dec 2008 14:28:59 +0000
changeset 219 ec472f8ac482
parent 218 86d22fe82b30
child 220 1c92222af6d3
fixed walkingspeed and improved drawing
src/Config.hh
src/Player.cc
src/Player.hh
--- a/src/Config.hh	Sat Dec 06 14:20:01 2008 +0000
+++ b/src/Config.hh	Sat Dec 06 14:28:59 2008 +0000
@@ -22,8 +22,8 @@
 
 // Player properties
 const float PLAYER_MASS = 10.0;
-const float PLAYER_MOVE_FORCE = 3500.0;
-const float PLAYER_MIN_SPEED = 30.0;
+const float PLAYER_MOVE_FORCE = 1100.0;
+const float PLAYER_MIN_SPEED = 10.0;
 const float PLAYER_JUMP_MIN_DISTANCE = 5.0;
 const float PLAYER_AIM_MIN = -KG_PI/4; 
 const float PLAYER_AIM_MAX = KG_PI/2;
@@ -31,8 +31,8 @@
 const float PLAYER_INITIAL_Y = 300.0;
 const float CROSSHAIR_ANGLE_SPEED = PI/40;
 
-const float PLAYER_MAX_SPEED = 130;
-const float PLAYER_WALK_SPEED = 100;
+const float PLAYER_MAX_SPEED = 43;
+const float PLAYER_WALK_SPEED = 33;
 
 const float PLAYER_COLLISION_ELASTICITY = 0.25; // TODO: This could be
                                         // different for different
--- a/src/Player.cc	Sat Dec 06 14:20:01 2008 +0000
+++ b/src/Player.cc	Sat Dec 06 14:28:59 2008 +0000
@@ -12,12 +12,16 @@
 //Player::image = CL_Surface("../../pics/skin.png");
 
 const std::string player_image_filename = "../../pics/skin.png";
+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) {
+    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
     // and weapons should be loaded from somewhere, not generated here
     for (int i = 0; i < 5; i++) {
@@ -132,6 +136,8 @@
     if (fx < 0) setFacing(false);
     else if (fx > 0) setFacing(true);
 
+    if (fx != 0) animation_step = (animation_step+1)%img_num_step;
+
 
     this->changeAim(da); // Move crosshair
 
@@ -147,10 +153,8 @@
 void Player::draw(CL_GraphicContext *gc) {
     assert(Engine::graphicsEnabled());
 
-    int img_num_aim = 9;
     int aim_img_idx = (int)((1 - (getAim()+KG_PI/2)/KG_PI)*img_num_aim);
-    int img_height = 9;
-    int img_width = 10;
+    int step_img_idx = animation_step%img_num_step;
 
     CL_Rectf destination(position.x - 4, position.y - 4, position.x + 5, position.y + 4);
 
@@ -159,9 +163,9 @@
     }
 
     player_image.draw_subpixel(
-            CL_Rectf(1, aim_img_idx * img_height + 1, 1 + img_width, (aim_img_idx + 1) * img_height + 1), 
-            destination, gc
-    );
+            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);
     
     const uint16_t chlen = 10;
     uint16_t x = position.x;
@@ -183,3 +187,4 @@
     }
 }
 
+
--- a/src/Player.hh	Sat Dec 06 14:20:01 2008 +0000
+++ b/src/Player.hh	Sat Dec 06 14:28:59 2008 +0000
@@ -19,6 +19,8 @@
         unsigned int selectedWeapon; //unsigned for x%sW not to fail
         bool changing;
 
+        int animation_step;
+
         // default constructor for use with virtual inheritance... it's not defined
         Player (void);
         Player (GameState &state, Vector position, bool visible);