PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/game/engine/actors/enemies/EnemyBossWolfsheim.as

https://bitbucket.org/charliehoey/gatsby
ActionScript | 118 lines | 100 code | 17 blank | 1 comment | 22 complexity | 7bb3adf32cc551cc39529015b273b348 MD5 | raw file
  1. package engine.actors.enemies {
  2. import engine.actors.enemies.EnemyWalker;
  3. import engine.ISubject;
  4. import engine.IObserver;
  5. import engine.actors.geoms.*;
  6. import engine.actors.Explosion;
  7. public class EnemyBossWolfsheim extends EnemyWalker {
  8. protected var actionDelay = 60;
  9. protected var actionCounter = 0;
  10. protected const JUMPING = 1;
  11. protected const POINTING = 2;
  12. protected var currentAction = JUMPING;
  13. protected var explodeStarted = false;
  14. protected var explodedYet = false;
  15. protected var explosionCounter = 0;
  16. override public function setup() {
  17. collide_left = 10; // what pixel do we collide on on the left
  18. collide_right = 22; // what pixel do we collide on on the right
  19. walkSpeed = 0;
  20. velx = walkSpeed;
  21. HP = 1000;
  22. points = 2500;
  23. myName = "EnemyBossWolfsheim"; // the generic name of our enemy
  24. mySkin = "WolfsheimSkin"; // the name of the skin for this enemy
  25. startFrame = 0; // the first frame to loop on
  26. endFrame = 1; // the final frame in the row
  27. nowFrame = 0; // current frame in row
  28. loopFrame = 0; // frame at which to loop
  29. loopType = 0; // 0 loops, 1 bounces
  30. loopRow = 0; // which row are we on
  31. loopDir = 1; // loop forward (to the right) by default
  32. speed = 10; // 5 replaced // how many frames should go by before we advance
  33. }
  34. override public function killMe():void {
  35. HP = 0;
  36. if(myStatus != 'DYING') {
  37. setLoop(2, 0, 1, 0, 0, 2); // make us die
  38. myStatus = 'DYING';
  39. gravity = 0;
  40. this.vely = -1;
  41. scoreboard.addToScore(this, points);
  42. if(hitDirection == 'LEFT') {
  43. this.velx = 3;
  44. } else if(hitDirection == 'RIGHT') {
  45. this.velx = -3;
  46. }
  47. }
  48. if(frameCount >= frameDelay) {
  49. //applyPhysics();
  50. if(!explodeStarted) {
  51. this.y += vely;
  52. if(this.y < 50) {
  53. explodeStarted = true;
  54. }
  55. } else if(!explodedYet) {
  56. actionDelay = 20;
  57. actionCounter++;
  58. if(actionCounter >= actionDelay) {
  59. var myExplosion = new Explosion();
  60. actionCounter = 0;
  61. explosionCounter++;
  62. myMap.spawnActor(myExplosion, (Math.floor(Math.random() * this.width) + this.x - 16), (Math.floor(Math.random() * this.height) + this.y - 16));
  63. }
  64. if(explosionCounter >= 12) {
  65. myStatus = 'DEAD';
  66. myMap.updateStatus(COMPLETE);
  67. myMap.removeFromMap(this);
  68. }
  69. }
  70. animate();
  71. } else {
  72. frameCount++;
  73. }
  74. }
  75. override public function moveMe():void {
  76. frameCount++;
  77. if(frameCount >= frameDelay) {
  78. if(actionCounter >= actionDelay) { // if we've waited long enough
  79. if(currentAction == JUMPING) { // and we're jumping
  80. setLoop(0, 2, 3, 2, 0); // make us point
  81. currentAction = POINTING; // switch us to pointing mode
  82. } else if(currentAction == POINTING) { // otherwise, if we're pointing
  83. setLoop(0, 0, 1, 0, 0); // make us jump
  84. currentAction = JUMPING; // and switch us to jumping mode
  85. }
  86. actionCounter = 0;
  87. }
  88. frameStarted = true;
  89. statusSet = false;
  90. this.y += vely / 2; // update our y variable
  91. notifyObservers(); // tell everybody where we are now
  92. applyPhysics(); // apply our enviromental variables
  93. updateStatus(); // update our status
  94. frameCount = 0;
  95. frameStarted = false;
  96. actionCounter++;
  97. }
  98. animate();
  99. }
  100. }
  101. }