// Player.cpp
#pragma once
#include "Player.h"
#include <string>
#include <sstream>
#include <cstring>
#include <string.h>
Player::Player (string name , bool player, int StandFrames , int WalkFrames, int AttackFrames,
int SAFrames, int WeakFrames) {
wcounter = 0;
acounter = 0;
sacounter = 0;
wecounter = 0;
player1 = player;
Name = name;
walkcounter = 0;
atkcounter = 0;
secondcounter = 0;
weakcounter = 0;
for (int i = 1; i <= StandFrames; i++) { // note i put <= to in standframes
stringstream str;
str << "Final Battle\\" << name << "\\" << name << "Stand" << i <<".bmp";
StandImage [i] = load_bitmap ((str.str()).c_str(),NULL);
if(!StandImage [i]) {
allegro_message("Error loading %s.", (str.str()).c_str());
exit(EXIT_FAILURE);
}
}
for (int i = 1; i < WalkFrames; i++)
{
stringstream str;
str << "Final Battle\\" << name << "\\" << name << "Walk" << i << ".bmp";
wcounter += 1;
WalkImage[i] = load_bitmap ((str.str()).c_str(), NULL);
if(!WalkImage [i]) {
allegro_message("Error loading %s.", (str.str()).c_str());
exit(EXIT_FAILURE);
}
}
for (int i = 1; i < AttackFrames; i++) { // note i put <= to in standframes
stringstream str;
str << "Final Battle\\" << name << "\\" << name << "Attack" << i <<".bmp";
acounter += 1;
AttackImage [i] = load_bitmap ((str.str()).c_str(),NULL);
if(!AttackImage [i]) {
allegro_message("Error loading %s.", (str.str()).c_str());
exit(EXIT_FAILURE);
}
}
for (int i = 1; i < SAFrames; i++) { // note i put <= to in standframes
stringstream str;
str << "Final Battle\\" << name << "\\" << name << "SecondAttack" << i <<".bmp";
sacounter += 1;
SAImage [i] = load_bitmap ((str.str()).c_str(),NULL);
if(!SAImage [i]) {
allegro_message("Error loading %s.", (str.str()).c_str());
exit(EXIT_FAILURE);
}
}
// for foing a weak attack
for (int i = 1; i < WeakFrames; i++) { // note i put <= to in standframes
stringstream str;
str << "Final Battle\\" << name << "\\" << name << "Weak" << i <<".bmp";
wecounter += 1;
WeakImage [i] = load_bitmap ((str.str()).c_str(),NULL);
if(!WeakImage [i]) {
allegro_message("Error loading %s.", (str.str()).c_str());
exit(EXIT_FAILURE);
}
}
Transport = load_bitmap ("Final Battle\\Cloud\\CloudTransport.bmp",NULL);
dir = -90;
//buffer = create_bitmap (640,480);
//y = 360;
attacking = false;
transporty = 400;
atknum = 0;
secondactivate = false;
Aatkx = 0;
weakend = false;
}// end of Player::Player
void Player::think (BITMAP *Buffer) {
Player::Controls ();
Player::move (Name , dir , Buffer);
Player::attack (Name , Buffer );
Player::secondattack (Name , Buffer );
Player::weak (Name , Buffer);
}
// used to control the player
void Player::Controls () {
if (player1 == false) {
if (key [KEY_RIGHT] && attacking == false)
dir = 90;
else if (key [KEY_LEFT] && attacking == false)
dir = 180;
else if (key [KEY_DOWN] && attacking == false)
atknum = 1;
else if (key [KEY_SLASH] && attacking == false)
atknum = 2;
if (!key [KEY_RIGHT] && dir == 90 ) {
dir = -90;
walkcounter = 0; }
else if (dir == 180 && !key [KEY_LEFT]) {
dir = -180;
walkcounter = 0; }
}
else if (player1 == true) {
if (key [KEY_D] && attacking == false)
dir = 90;
else if (key [KEY_A] && attacking == false)
dir = 180;
else if (key [KEY_S] && attacking == false)
atknum = 1;
else if (key [KEY_Q] && attacking == false)
atknum = 2;
if (!key [KEY_D] && dir == 90) {
dir = -90;
walkcounter = 0;}
else if (!key[KEY_A] && dir == 180) {
dir = -180;
walkcounter = 0;}
}
}
// for player movement
void Player::move (string name , int dir, BITMAP *buffer) {
if (dir == 90 && attacking == false ){
walkcounter += 1;
if (name == "Cloud") {
x += 15;
draw_sprite (buffer, Transport , x , transporty);
}
else {
x += 5;
if (walkcounter >= wcounter / 2 )
walkcounter = 1;
draw_sprite (buffer, WalkImage [walkcounter] , x , y );
}
} // end of dir = 90
if (dir == 180 && attacking == false) {
if (walkcounter < wcounter / 2 )
walkcounter = wcounter / 2 + 1;
walkcounter += 1;
if (name == "Cloud") {
x -= 15;
draw_sprite (buffer, Transport , x ,transporty );
}
else {
x -= 5;
if (walkcounter >= wcounter )
walkcounter = wcounter / 2 + 2;
draw_sprite (buffer, WalkImage [walkcounter], x , y );
}
}
if (dir == -90 && attacking == false)
draw_sprite (buffer, StandImage [1], x, y);
if (dir == -180 && attacking == false)
draw_sprite (buffer, StandImage [2], x ,y);
} // end of Player Move
// for weak attacks
void Player::attack (string name , BITMAP *buffer) {
if (dir == 90 && atknum == 1 && secondactivate == false || dir == -90 && atknum == 1 &&
secondactivate == false) {
attacking = true;
atkcounter += 1;
x += 5;
if (name == "Cloud") {
y -= 6;
rest (10);
}
draw_sprite (buffer, AttackImage [atkcounter] , x , y );
if (atkcounter >= acounter / 2) {
if (name == "Cloud")
y += 6 * atkcounter;
atkcounter = 0;
atknum = 0;
attacking = false;
}
} // end of dir = 90
else if (dir == 180 && atknum == 1 && secondactivate == false || dir == -180 && atknum == 1 &&
secondactivate == false) {
attacking = true;
if (atkcounter < acounter / 2 )
atkcounter = acounter / 2;
atkcounter += 1;
x -= 5;
if (name == "Cloud") {
y -= 6;
rest (10);
}
draw_sprite (buffer, AttackImage [atkcounter] , x , y );
if (atkcounter >= acounter) {
if (name == "Cloud")
y += 6 * atkcounter / 2;
atkcounter = 0;
atknum = 0;
attacking = false;
}
} // end of dir = 180
} // end of player attack
void Player::secondattack (string name , BITMAP *buffer) {
if (dir == 90 && atkcounter >= acounter / 2 - 1 || dir == - 90 && atkcounter >= acounter / 2 -1 ) {
if (key[KEY_S]) {
secondactivate = true;}
if (secondactivate == true) {
rest (20);
secondcounter += 1;
draw_sprite (buffer, SAImage [secondcounter] , x , y );
if (secondcounter >= sacounter / 2) {
if (name == "Cloud")
y += 6 * atkcounter;
atkcounter = 0;
secondcounter = 0;
atknum = 0;
attacking = false;
secondactivate = false;
} // when the attack is finished
} // if secondactivate is true
} // if dir = 90;
else if (dir == 180 && atkcounter >= acounter - 1 || dir == - 180 && atkcounter >= acounter -1 ) {
if (key[KEY_S]) {
secondactivate = true;}
if (secondactivate == true) {
if (secondcounter < sacounter / 2 )
secondcounter = sacounter / 2;
rest (20);
secondcounter += 1;
draw_sprite (buffer, SAImage [secondcounter] , x ,y );
if (secondcounter >= sacounter) {
if (name == "Cloud")
y += 6 * atkcounter / 2;
atkcounter = 0;
secondcounter = 0;
atknum = 0;
attacking = false;
secondactivate = false;
} // when the attack is finished
} // if secondactivate is true
} // if dir = 180;
} // end of player second attack
void Player::weak (string name , BITMAP *buffer) {
if (dir == 90 && atknum == 2 || dir == -90 && atknum == 2 ) {
attacking = true;
if (weakend == false) {
weakcounter += 1;
if (name == "Cloud") {
rest (20);
y = 360; }
draw_sprite (buffer, WeakImage [weakcounter] , x , y); }
if (name != "Axel" && weakcounter >= wecounter / 2 ) {
if (name == "Cloud") {
rest (70);
y = 350;}
weakcounter = 0;
atknum = 0;
attacking = false;
}
if (name == "Axel" && weakcounter >= 3) {
weakend = true;
Aatkx += 25;
draw_sprite (buffer, WeakImage [9] , x + Aatkx , y );
draw_sprite (buffer, WeakImage [4] , x , y );
if (x + Aatkx >= 640) {
Aatkx = 0;
weakcounter = 0;
atknum = 0;
attacking = false;
weakend = false;
} // axel weak finished
} // if player is Axel
} // dir == 90
if (dir == 180 && atknum == 2 || dir == -180 && atknum == 2 ) {
attacking = true;
if (weakend == false) {
if (weakcounter < wecounter / 2 ) {
weakcounter = wecounter / 2;
if (name == "Cloud")
weakcounter = wecounter / 2 + 1;
}
weakcounter += 1;
if (name == "Cloud") {
rest (20);
y = 360; }
draw_sprite (buffer, WeakImage [weakcounter] , x , y); }
if (name != "Axel" && weakcounter >= wecounter) {
if (name == "Cloud") {
rest (70);
y = 350; }
weakcounter = 0;
atknum = 0;
attacking = false;
}
if (name == "Axel" && weakcounter >= 7) {
weakend = true;
Aatkx += 25;
draw_sprite (buffer, WeakImage [9] , x - Aatkx , y );
draw_sprite (buffer, WeakImage [8] , x , y );
if (x - Aatkx <= 0) {
Aatkx = 0;
weakcounter = 0;
atknum = 0;
attacking = false;
weakend = false;
} // axel weak finished
} // if player is Axel
}
} // end of player weak
|