src/Player.cc
branchnew_graphics
changeset 412 721c60072091
parent 409 1a03ff151abc
child 417 c503e0c6a740
equal deleted inserted replaced
411:106aaf6eadfe 412:721c60072091
     1 
     1 
     2 #include "Player.hh"
     2 #include "Player.hh"
     3 #include "Weapons.hh"
     3 #include "Weapons.hh"
     4 #include "Engine.hh"
     4 #include "Engine.hh"
     5 #include "Graphics.hh"
     5 
       
     6 #include "Graphics/Graphics.hh"
     6 
     7 
     7 #include <cstdlib>
     8 #include <cstdlib>
     8 #include <ClanLib/display.h>
     9 #include <ClanLib/display.h>
     9 #include <algorithm>
    10 #include <algorithm>
    10 #include <string>
    11 #include <string>
   322 
   323 
   323 void Player::addKill () {
   324 void Player::addKill () {
   324     kills++;
   325     kills++;
   325 }
   326 }
   326 
   327 
   327 void Player::draw (Graphics *g, PixelCoordinate camera) {
   328 void Player::draw (graphics::Display &display, PixelCoordinate camera) {
   328     CL_GraphicContext *gc = g->get_gc();
   329     CL_GraphicContext *gc = display.get_gc();
   329 
   330 
   330     if (!isAlive())
   331     if (!isAlive())
   331         return;
   332         return;
   332 
   333 
   333     // draw rope behind player
   334     // draw rope behind player
   334     rope.draw(g, camera);
   335     rope.draw(display, camera);
   335     
   336     
   336     // animation indexes
   337     // animation indexes
   337     int aim_img_idx = (int)((1 - (getAim() + KG_PI / 2) / KG_PI) * img_num_aim);
   338     int aim_img_idx = (int)((1 - (getAim() + KG_PI / 2) / KG_PI) * img_num_aim);
   338     int step_img_idx = animation_step % img_num_step;
   339     int step_img_idx = animation_step % img_num_step;
   339 
   340 
   373             crosshair.y + PLAYER_CROSSHAIR_WIDTH / 2
   374             crosshair.y + PLAYER_CROSSHAIR_WIDTH / 2
   374         ), CL_Color::red
   375         ), CL_Color::red
   375     );    
   376     );    
   376 }
   377 }
   377 
   378 
   378 void LocalPlayer::draw (Graphics *g, bool displayWeapon, PixelCoordinate camera) {
   379 void LocalPlayer::draw (graphics::Display &display, bool displayWeapon, PixelCoordinate camera) {
   379     // superclass draw
   380     // superclass draw
   380     Player::draw(g, camera);
   381     Player::draw(display, camera);
   381 
   382 
   382     // display weapon name?
   383     // display weapon name?
   383     if (isAlive() && displayWeapon && getCurrentWeapon()) {
   384     if (isAlive() && displayWeapon && getCurrentWeapon()) {
   384         const std::string weaponName = getCurrentWeapon()->getName();
   385         const std::string weaponName = getCurrentWeapon()->getName();
   385 
   386         
       
   387         // position
   386         PixelCoordinate pc = getCoordinate() - camera;
   388         PixelCoordinate pc = getCoordinate() - camera;
       
   389 
       
   390         // get font
       
   391         CL_Font &font = graphics::graphics->fonts.getSimpleFont();
   387         
   392         
   388         // XXX: fix magic constants once we know how big the worm is
   393         // XXX: fix magic constants once we know how big the worm is
   389         g->getSimpleFont().draw(
   394         font.draw(
   390                 pc.x - g->getSimpleFont().get_width(weaponName) / 2,
   395             pc.x - font.get_width(weaponName) / 2,
   391                 pc.y - 20,
   396             pc.y - 20,
   392                 weaponName,
   397             weaponName,
   393                 g->get_gc()
   398             display.get_gc()
   394         );
   399         );
   395     }
   400     }
   396 }
   401 }
   397 
   402