PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/game/engine/actors/enemies/EnemyCrab.as

https://bitbucket.org/charliehoey/gatsby
ActionScript | 75 lines | 58 code | 17 blank | 0 comment | 8 complexity | 735b97b81fcd726c4ee3bd9997bffa9c 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. public class EnemyCrab extends EnemyWalker {
  7. override public function moveMe():void {
  8. if(frameCount >= frameDelay) {
  9. frameStarted = true;
  10. statusSet = false;
  11. var dirChange = Math.floor(Math.random() * 20);
  12. if(dirChange == 5) {
  13. velx *= -1;
  14. }
  15. this.y += vely / 2; // update our y variable
  16. this.x += velx / 2; // update our x variable
  17. if(velx > 0) {
  18. this.x = Math.ceil(this.x);
  19. } else {
  20. this.x = Math.floor(this.x);
  21. }
  22. if(vely > 0) {
  23. this.y = Math.ceil(this.y);
  24. } else {
  25. this.y = Math.floor(this.y);
  26. }
  27. notifyObservers(); // tell everybody where we are now
  28. applyPhysics(); // apply our enviromental variables
  29. updateStatus(); // update our status
  30. frameCount = 0;
  31. frameStarted = false;
  32. } else {
  33. frameCount++;
  34. }
  35. animate();
  36. }
  37. override public function setup() {
  38. collide_left = 1; // what pixel do we collide on on the left
  39. collide_right = 15; // what pixel do we collide on on the right
  40. collide_left_ground = 15;
  41. collide_right_ground = 1;
  42. myName = "EnemyCrab"; // the generic name of our enemy
  43. mySkin = "CrabSkin"; // the name of the skin for this enemy
  44. startFrame = 0; // the first frame to loop on
  45. endFrame = 1; // the final frame in the row
  46. nowFrame = 0; // current frame in row
  47. loopFrame = 0; // frame at which to loop
  48. loopType = 0; // 0 loops, 1 bounces
  49. loopRow = 0; // which row are we on
  50. loopDir = 1; // loop forward (to the right) by default
  51. speed = 10; // 5 replaced // how many frames should go by before we advance
  52. walkSpeed = 1;
  53. velx = walkSpeed;
  54. tilesWide = 2;
  55. tilesTall = 1;
  56. }
  57. }
  58. }