xemerau

Character.cpp

Nov 3rd, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. ///File:       "Character.cpp"
  2. ///Project:    "Tilemap.cbp"
  3. ///
  4. /// Please refer to main.cpp for more information.
  5.  
  6. //Preprocessor Directives
  7. #include "Character.h"
  8. #include <allegro.h>
  9. #include "Projectile.h"
  10. //End of preprocessor directives
  11.  
  12. //Constructor
  13. Character::Character()
  14. {
  15.     sprite = load_bitmap("resources/sprites/roughPlayer.bmp", NULL);
  16.     DirectionFacing = 6;
  17.     Xcoordinate = 0;
  18.     Ycoordinate = 0;
  19. }
  20. //End of constructor
  21.  
  22. //Destructor
  23. Character::~Character()
  24. {
  25.     destroy_bitmap(sprite);
  26. }
  27. //End of destructor
  28.  
  29. //Walk function
  30. void Character::Walk(void)
  31. {
  32.     if (key[KEY_W]) { if (Ycoordinate > 0) { Ycoordinate--; DirectionFacing = 8;} }             // Ensuring that the character is not off the screen with the
  33.     else if (key[KEY_S]) { if (Ycoordinate < 576) { Ycoordinate++; DirectionFacing = 2;} }      // second 'if' in each line.
  34.     if (key[KEY_A]) { if (Xcoordinate > 0) { Xcoordinate--; DirectionFacing = 4;} }
  35.     else if (key[KEY_D]) if (Xcoordinate < 576) { { Xcoordinate++; DirectionFacing = 6;} }
  36. }
  37. //End of walk function
  38.  
  39. //Draw function
  40. void Character::Draw(BITMAP *buffer)
  41. {
  42.     masked_blit(sprite, buffer, 0, 0, Xcoordinate, Ycoordinate, 64, 64);
  43. }
  44. //End of draw function
  45.  
  46. //Fire member function
  47. void Character::FireWeapon(void)
  48. {
  49.     std::list<Projectile>::iterator i;
  50.    
  51.     if (key[KEY_F]) {
  52.         Bullet.Initialize(Xcoordinate, Ycoordinate, DirectionFacing);
  53.         BulletList.push_back(Bullet);
  54.     }
  55.    
  56.     for (i = BulletList.begin(); i != BulletList.end(), i++;)
  57.     {
  58.          i -> Update();
  59.     }
  60. }
  61. //End of fire weapon member function
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment