Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. // All arguments apart from enemyId1 are optional and default to -1 (disabled)
  2. void InitBattle(int enemyId1, int enemyId2)
  3. {
  4. battleEnemy[0] = enemyId1;
  5. battleEnemy[1] = enemyId2;
  6.  
  7. if(enemyId1 >= 0)
  8. liveEnemyCount++;
  9. if(enemyId2 >= 0)
  10. liveEnemyCount++;
  11. }
  12.  
  13. // All the enemies in the battle attack in turn
  14. bool EnemyTurn()
  15. {
  16. int i=0;
  17. while(i<4)
  18. {
  19. int e = battleEnemy[i];
  20. if(e != -1 && enemy[e].IsAlive())
  21. {
  22. int damage = enemy[e].Attack();
  23. Character* body = enemy[e].body;
  24. body.AttackAnimation();
  25. GetGlobalInt(2) - damage; // myHealth might be a globalvar
  26. if(GetGlobalInt(2) <= 0)
  27. return true; // Do whatever happens when you lose a battle
  28. }
  29. i++;
  30. }
  31. return false;
  32. }
  33.  
  34. bool AttackEnemy(int id)
  35. {
  36. int e = battleEnemy[id];
  37. if(e != -1 && enemy[e].IsAlive())
  38. {
  39. int damage = Random(GetGlobalInt(6)); // Again, here myStrength could be a globalVar
  40. enemy[e].health = enemy[e].health - damage;
  41. // PlayerAttackAnimation(); // Defined somewhere
  42. if(!enemy[e].IsAlive())
  43. {
  44. Character* body = enemy[e].body;
  45. // body.DeathAnimation(); // Which you define just like AttackAnimation
  46. liveEnemyCount--;
  47. return true;
  48. }
  49. else return false;
  50. }
  51. return true;
  52. }
  53.  
  54. void FightBattle()
  55. {
  56. InitBattle(Enemy.Find("Fuzball"),Enemy.Find("Kate"));
  57.  
  58. // Then we just run battle turns until the player or all the enemies are dead
  59. while(GetGlobalInt(2) > 0 && liveEnemyCount > 0)
  60. {
  61. // int target = PlayerPicksTarget(); // A method you've written to pick who to attack
  62. AttackEnemy(FUZBALL);
  63. EnemyTurn();
  64. }
  65. if(GetGlobalInt(2) > 0)
  66. {
  67. // Victory!
  68. }
  69. else
  70. {
  71. // Game Over
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement