--- a/src/Player.cc Sat Dec 06 12:35:40 2008 +0000
+++ b/src/Player.cc Sat Dec 06 13:52:07 2008 +0000
@@ -3,11 +3,17 @@
#include <cstdlib>
#include <ClanLib/display.h>
+#include <string>
//Player::image = NULL;
//Player::image = CL_Surface("../../pics/skin.png");
+const std::string player_image_filename = "../../pics/skin.png";
+
+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) {
// TODO: arsenal's size should be affected by some value
@@ -16,6 +22,10 @@
arsenal.push_back(Weapon(10000, (5-i)*40+30, i*6+5, i*100+50, "asdf"));
}
+ if(!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");
// }
@@ -36,7 +46,7 @@
Vector(-std::cos(aim), -std::sin(aim));
float shotspeed = 0*PHYSICS_TICK_MS;
Vector shotVelocity = unitVectorAim*shotspeed;
- new Projectile(this->state, this->position, shotVelocity, false, radius, 0);
+ new Projectile(this->state, this->position, shotVelocity, false, radius, 1);
}
@@ -133,20 +143,25 @@
void Player::draw(CL_GraphicContext *gc) {
- CL_Surface dimage = CL_Surface("../../pics/skin.png");
-
- dimage.draw(position.x, position.y, gc);
+ 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;
+ player_image.draw_subpixel(CL_Rectf(1, aim_img_idx*img_height+1, 1+img_width, (aim_img_idx+1)*img_height+1),
+ CL_Rectf(position.x-4, position.y-4, position.x+5, position.y+4), gc);
const uint16_t chlen = 10;
uint16_t x = position.x;
uint16_t y = position.y;
if (facingRight) {
- gc->draw_line(x, y,
+ gc->draw_line(x + std::cos(aim)*chlen/2,
+ y - std::sin(aim)*chlen/2,
x + std::cos(aim)*chlen,
y - std::sin(aim)*chlen,
CL_Color::black);
} else {
- gc->draw_line(x, y,
+ gc->draw_line(x - std::cos(aim)*chlen/2,
+ y - std::sin(aim)*chlen/2,
x - std::cos(aim)*chlen,
y - std::sin(aim)*chlen,
CL_Color::black);