PageRenderTime 131ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/game/engine/actors/weapons/Projectile.as

https://bitbucket.org/charliehoey/gatsby
ActionScript | 94 lines | 76 code | 17 blank | 1 comment | 3 complexity | 3110f2a25fd2eb837893fe6fcc233b03 MD5 | raw file
  1. package engine.actors.weapons{
  2. import engine.actors.Animatable;
  3. import engine.actors.Actor;
  4. import engine.actors.enemies.*;
  5. import flash.utils.Timer;
  6. import flash.events.Event;
  7. import flash.events.TimerEvent;
  8. import flash.geom.Point;
  9. public class Projectile extends Animatable {
  10. public var owner:Actor;
  11. public var damage:Number = 1;
  12. public var lifeSpan:Number = 2000;
  13. public var isDead:Boolean = false;
  14. protected var lifeTimer:Timer;
  15. public var mySpeed = 4;
  16. public var vecx = 1;
  17. public var vecy = 1;
  18. public var velx = 1;
  19. public var vely = 1;
  20. public function Projectile(owner) {
  21. super();
  22. this.owner = owner;
  23. }
  24. override public function setup() {
  25. myName = "BaseballWeapon";
  26. mySkin = "BaseballWeaponSkin";
  27. tilesWide = 1;
  28. tilesTall = 1;
  29. collide_left = 4; // what pixel do we collide on on the left
  30. collide_right = 12; // what pixel do we collide on on the right
  31. startFrame = 0; // the first frame to loop on
  32. endFrame = 1; // the final frame in the row
  33. nowFrame = 0; // current frame in row
  34. loopFrame = 0; // frame at which to loop
  35. loopType = 0; // 0 loops, 1 bounces
  36. loopRow = 0; // which row are we on
  37. loopDir = 1; // loop forward (to the right) by default
  38. speed = 3; // how many frames should go by before we advance
  39. startLifeTimer();
  40. animate();
  41. }
  42. public function startLifeTimer() {
  43. lifeTimer = new Timer(lifeSpan,1);
  44. lifeTimer.addEventListener(TimerEvent.TIMER, this.killMe);
  45. lifeTimer.start();
  46. }
  47. public function setOwner(owner) {
  48. this.owner = owner;
  49. }
  50. public function killMe(e) {
  51. HP = 0;
  52. isDead = true;
  53. lifeTimer.stop();
  54. lifeTimer.removeEventListener(TimerEvent.TIMER, this.killMe);
  55. }
  56. override public function notify(subject):void {
  57. if(subject is Enemy || subject is EnemyWalker) {
  58. if(checkCollision(subject)) {
  59. subject.receiveDamage(this);
  60. frameCount = frameDelay;
  61. }
  62. }
  63. }
  64. public function moveMe() {
  65. // this will get overwritten later, if necessary
  66. }
  67. override public function update():void {
  68. moveMe();
  69. velx = mySpeed * vecx;
  70. vely = mySpeed * vecy;
  71. this.x += velx;
  72. this.y += vely;
  73. notifyObservers();
  74. animate();
  75. }
  76. }//end class
  77. }//end package