Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // All arguments apart from enemyId1 are optional and default to -1 (disabled)
- void InitBattle(int enemyId1, int enemyId2)
- {
- battleEnemy[0] = enemyId1;
- battleEnemy[1] = enemyId2;
- if(enemyId1 >= 0)
- liveEnemyCount++;
- if(enemyId2 >= 0)
- liveEnemyCount++;
- }
- // All the enemies in the battle attack in turn
- bool EnemyTurn()
- {
- int i=0;
- while(i<4)
- {
- int e = battleEnemy[i];
- if(e != -1 && enemy[e].IsAlive())
- {
- int damage = enemy[e].Attack();
- Character* body = enemy[e].body;
- body.AttackAnimation();
- GetGlobalInt(2) - damage; // myHealth might be a globalvar
- if(GetGlobalInt(2) <= 0)
- return true; // Do whatever happens when you lose a battle
- }
- i++;
- }
- return false;
- }
- bool AttackEnemy(int id)
- {
- int e = battleEnemy[id];
- if(e != -1 && enemy[e].IsAlive())
- {
- int damage = Random(GetGlobalInt(6)); // Again, here myStrength could be a globalVar
- enemy[e].health = enemy[e].health - damage;
- // PlayerAttackAnimation(); // Defined somewhere
- if(!enemy[e].IsAlive())
- {
- Character* body = enemy[e].body;
- // body.DeathAnimation(); // Which you define just like AttackAnimation
- liveEnemyCount--;
- return true;
- }
- else return false;
- }
- return true;
- }
- void FightBattle()
- {
- InitBattle(Enemy.Find("Fuzball"),Enemy.Find("Kate"));
- // Then we just run battle turns until the player or all the enemies are dead
- while(GetGlobalInt(2) > 0 && liveEnemyCount > 0)
- {
- // int target = PlayerPicksTarget(); // A method you've written to pick who to attack
- AttackEnemy(FUZBALL);
- EnemyTurn();
- }
- if(GetGlobalInt(2) > 0)
- {
- // Victory!
- }
- else
- {
- // Game Over
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement