PageRenderTime 889ms CodeModel.GetById 50ms RepoModel.GetById 45ms app.codeStats 0ms

/game/engine/actors/weapons/LaserWeapon.as

https://bitbucket.org/charliehoey/gatsby
ActionScript | 86 lines | 67 code | 17 blank | 2 comment | 5 complexity | 70fa56e70757f2d85727b4fd9306a4af MD5 | raw file
  1. package engine.actors.weapons {
  2. import engine.IObserver;
  3. import engine.actors.player.Hero;
  4. import engine.actors.enemies.Enemy;
  5. import engine.actors.geoms.*;
  6. import flash.events.Event;
  7. import engine.actors.Animatable;
  8. public class LaserWeapon extends Weapon implements IObserver {
  9. private const laserSpeed:Number = 5;
  10. private var shootDistance:int = 100;
  11. private var loopSet = false;
  12. private var velx:Number = 0;
  13. private var vely:Number = 0;
  14. private var vecX:Number = 1;
  15. private var vecY:Number = 1;
  16. public function LaserWeapon(owner, vecx, vecy) {
  17. this.vecX = vecx; // normalized x vector
  18. this.vecY = vecy; // normalized y vector
  19. super(owner);
  20. }
  21. override public function setup() {
  22. damage = 1;
  23. myName = "LaserWeapon";
  24. mySkin = "LaserWeaponSkin";
  25. tile = 8;
  26. tilesWide = 1;
  27. tilesTall = 4;
  28. collide_left = 4; // what pixel do we collide on on the left
  29. collide_right = 12; // what pixel do we collide on on the right
  30. startFrame = 0; // the first frame to loop on
  31. endFrame = 1; // the final frame in the row
  32. nowFrame = 0; // current frame in row
  33. loopFrame = 0; // frame at which to loop
  34. loopType = 0; // 0 loops, 1 bounces
  35. loopRow = 0; // which row are we on
  36. loopDir = 1; // loop forward (to the right) by default
  37. speed = 1; // how many frames should go by before we advance (maybe this should be animationSpeed)
  38. //this.velx = laserSpeed * vecX;
  39. //this.vely = laserSpeed * vecY;
  40. this.velx = 0;
  41. this.vely = laserSpeed;
  42. animate();
  43. }
  44. override public function notify(subject):void {
  45. if(subject is Hero) {
  46. if(checkCollision(subject)) {
  47. subject.receiveDamage(this);
  48. frameCount = frameDelay;
  49. }
  50. }
  51. }
  52. override public function update():void {
  53. if(!loopSet) {
  54. setLoop(0, 0, 1, 0, 0, 0);
  55. loopSet = true;
  56. }
  57. if(frameCount >= shootDistance) {
  58. frameCount = 0;
  59. myMap.removeFromMap(this);
  60. } else {
  61. frameCount++;
  62. }
  63. this.x += velx;
  64. this.y += vely;
  65. notifyObservers();
  66. animate();
  67. }
  68. }
  69. }