generated from sigonasr2/CPlusPlusProjectTemplate
Completed all basic battle mechanics
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
3106bfb1ce
commit
3d33b0ed49
@ -255,6 +255,7 @@ public:
|
||||
int PLAYER_HP=PLAYER_MAXHP;
|
||||
int BATTLE_CURRENT_TURN_ENTITY=-1;
|
||||
int CURRENT_ENCOUNTER_IND=-1;
|
||||
int RAND_CALLS=0;
|
||||
std::vector<DisplayNumber*> BATTLE_DISPLAY_NUMBERS;
|
||||
bool PLAYER_TURN_COMPLETE=false;
|
||||
|
||||
@ -1106,10 +1107,10 @@ public:
|
||||
srand((int)(yOffset+y)*MAP_WIDTH+(int)(xOffset+x));
|
||||
int tileX=0;
|
||||
int tileRot=0;
|
||||
while (tileX<3&&rand()%4==0) {
|
||||
while (tileX<3&&std::rand()%4==0) {
|
||||
tileX++;
|
||||
}
|
||||
while (tileRot<3&&rand()%8<5) {
|
||||
while (tileRot<3&&std::rand()%8<5) {
|
||||
tileRot++;
|
||||
}
|
||||
if ((int)(xOffset+x)>=0&&(int)(xOffset+x)<MAP_WIDTH&&(int)(yOffset+y)>=0&&(int)(yOffset+y)<MAP_HEIGHT) {
|
||||
@ -1388,8 +1389,9 @@ public:
|
||||
BATTLE_DISPLAY_NUMBERS.push_back(numb);
|
||||
} else {
|
||||
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
|
||||
finalDamage=power->damage+rand()%power->damageRoll*sign(power->damage);
|
||||
Entity*ent=CURRENT_ENCOUNTER.entities[i];
|
||||
if (distancetoCoords({(ent->x+CURRENT_ENCOUNTER.x)*32,(ent->y+CURRENT_ENCOUNTER.y)*32},coords*32)<=power->range) {
|
||||
if (ent->hp>0&&distancetoCoords({(ent->x+CURRENT_ENCOUNTER.x)*32,(ent->y+CURRENT_ENCOUNTER.y)*32},coords*32)<=power->range) {
|
||||
ent->hp=std::clamp(ent->hp-finalDamage,0,ent->maxhp);
|
||||
DisplayNumber*numb = new DisplayNumber(finalDamage,ent->x+CURRENT_ENCOUNTER.x,ent->y+CURRENT_ENCOUNTER.y,frameCount);
|
||||
BATTLE_DISPLAY_NUMBERS.push_back(numb);
|
||||
@ -1401,9 +1403,10 @@ public:
|
||||
//Damaging effect.
|
||||
if (playerForce) {
|
||||
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
|
||||
finalDamage=power->damage+rand()%power->damageRoll*sign(power->damage);
|
||||
Entity*ent=CURRENT_ENCOUNTER.entities[i];
|
||||
std::cout<<"Distance was "<<distancetoCoords({(ent->x+CURRENT_ENCOUNTER.x)*32,(ent->y+CURRENT_ENCOUNTER.y)*32},coords*32)<<"\n";
|
||||
if (distancetoCoords({(ent->x+CURRENT_ENCOUNTER.x)*32,(ent->y+CURRENT_ENCOUNTER.y)*32},coords*32)<=power->range) {
|
||||
if (ent->hp>0&&distancetoCoords({(ent->x+CURRENT_ENCOUNTER.x)*32,(ent->y+CURRENT_ENCOUNTER.y)*32},coords*32)<=power->range) {
|
||||
ent->hp=std::clamp(ent->hp-finalDamage,0,ent->maxhp);
|
||||
DisplayNumber*numb = new DisplayNumber(finalDamage,ent->x+CURRENT_ENCOUNTER.x,ent->y+CURRENT_ENCOUNTER.y,frameCount);
|
||||
BATTLE_DISPLAY_NUMBERS.push_back(numb);
|
||||
@ -1425,6 +1428,11 @@ public:
|
||||
int sign(int x) {
|
||||
return (x > 0) - (x < 0);
|
||||
}
|
||||
|
||||
int rand() {
|
||||
srand(time(NULL)+RAND_CALLS++);
|
||||
return std::rand();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user