PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/game/engine/actors/weapons/BaseballWeapon.as

https://bitbucket.org/charliehoey/gatsby
ActionScript | 81 lines | 69 code | 12 blank | 0 comment | 7 complexity | c0595e553c20bfed37c026089b3a7c3a 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 BaseballWeapon extends Weapon implements IObserver {
  9. private var throwDistance:int = 60;
  10. private var velx:Number = 0;
  11. private var vely:Number = 0;
  12. private const MAX_VEL_X = 5;
  13. public function BaseballWeapon(owner) {
  14. super(owner);
  15. goingLeft = owner.goingLeft;
  16. }
  17. override public function setup() {
  18. flySpeed = 2;
  19. damage = 1;
  20. myName = "BaseballWeapon";
  21. mySkin = "BaseballWeaponSkin";
  22. tilesWide = 1;
  23. tilesTall = 1;
  24. collide_left = 4; // what pixel do we collide on on the left
  25. collide_right = 12; // what pixel do we collide on on the right
  26. startFrame = 0; // the first frame to loop on
  27. endFrame = 1; // the final frame in the row
  28. nowFrame = 0; // current frame in row
  29. loopFrame = 0; // frame at which to loop
  30. loopType = 0; // 0 loops, 1 bounces
  31. loopRow = 0; // which row are we on
  32. loopDir = 1; // loop forward (to the right) by default
  33. speed = 3; // how many frames should go by before we advance
  34. flySpeed = 3;
  35. if(goingLeft) {
  36. velx = -flySpeed;
  37. } else {
  38. velx = flySpeed;
  39. }
  40. animate();
  41. }
  42. override public function notify(subject):void {
  43. if(subject is Hero) {
  44. if(checkCollision(subject)) {
  45. subject.receiveDamage(this);
  46. frameCount = frameDelay;
  47. }
  48. }
  49. }
  50. public function fireBullet(goingLeft) {
  51. frameCount = 0;
  52. frameDelay = throwDistance;
  53. }
  54. override public function update():void {
  55. if(frameCount >= throwDistance) {
  56. frameCount = 0;
  57. myMap.removeFromMap(this);
  58. } else {
  59. frameCount++;
  60. }
  61. if(velx > MAX_VEL_X) {
  62. velx = MAX_VEL_X;
  63. }
  64. this.x += velx;
  65. notifyObservers();
  66. animate();
  67. }
  68. }
  69. }