Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///File: "Character.cpp"
- ///Project: "Tilemap.cbp"
- ///
- /// Please refer to main.cpp for more information.
- //Preprocessor Directives
- #include "Character.h"
- #include <allegro.h>
- #include "Projectile.h"
- //End of preprocessor directives
- //Constructor
- Character::Character()
- {
- sprite = load_bitmap("resources/sprites/roughPlayer.bmp", NULL);
- DirectionFacing = 6;
- Xcoordinate = 0;
- Ycoordinate = 0;
- }
- //End of constructor
- //Destructor
- Character::~Character()
- {
- destroy_bitmap(sprite);
- }
- //End of destructor
- //Walk function
- void Character::Walk(void)
- {
- if (key[KEY_W]) { if (Ycoordinate > 0) { Ycoordinate--; DirectionFacing = 8;} } // Ensuring that the character is not off the screen with the
- else if (key[KEY_S]) { if (Ycoordinate < 576) { Ycoordinate++; DirectionFacing = 2;} } // second 'if' in each line.
- if (key[KEY_A]) { if (Xcoordinate > 0) { Xcoordinate--; DirectionFacing = 4;} }
- else if (key[KEY_D]) if (Xcoordinate < 576) { { Xcoordinate++; DirectionFacing = 6;} }
- }
- //End of walk function
- //Draw function
- void Character::Draw(BITMAP *buffer)
- {
- masked_blit(sprite, buffer, 0, 0, Xcoordinate, Ycoordinate, 64, 64);
- }
- //End of draw function
- //Fire member function
- void Character::FireWeapon(void)
- {
- std::list<Projectile>::iterator i;
- if (key[KEY_F]) {
- Bullet.Initialize(Xcoordinate, Ycoordinate, DirectionFacing);
- BulletList.push_back(Bullet);
- }
- for (i = BulletList.begin(); i != BulletList.end(), i++;)
- {
- i -> Update();
- }
- }
- //End of fire weapon member function
Advertisement
Add Comment
Please, Sign In to add comment