Guest User

Untitled

a guest
Jun 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. package spaceShip
  2. {
  3. import flash.display.Sprite;
  4. import flash.display.*;
  5. import flash.events.Event;
  6. import flash.events.MouseEvent;
  7. import flash.filters.*;
  8. import flash.events.KeyboardEvent;
  9. import flash.ui.Keyboard;
  10. import net.flashpunk.Entity;
  11. import net.flashpunk.FP;
  12. import net.flashpunk.graphics.Emitter;
  13. import net.flashpunk.graphics.Graphiclist;
  14. import net.flashpunk.graphics.Image;
  15.  
  16. /**
  17. * ...
  18. * @author Joe Newbry
  19. */
  20. public class ShipView extends Entity
  21. {
  22. // Object that contains the player model
  23. private var _model:ShipModel;
  24.  
  25. //Object that contains the player controller
  26. private var _controller:ShipController;
  27.  
  28. [Embed(source='../../assets/images/Ship2.png')]
  29. private static const SHOT:Class;
  30. private var myShip:Image = new Image(SHOT);
  31.  
  32. [Embed(source = '../../assets/images/ShipTrail.png')]
  33. private static const TRAIL:Class;
  34. private var shipEmitter:Emitter = new Emitter(TRAIL, 4, 4);
  35. private static const EMITTER:String = "myEmitter";
  36.  
  37.  
  38. public function ShipView(model:ShipModel, controller:ShipController)
  39. {
  40. _model = model;
  41. _controller = controller;
  42. shipEmitter.newType(EMITTER, [0, 1,0,1,0,1,2,3,2,1,3,2,1,0]);
  43. shipEmitter.setAlpha(EMITTER, 1,1) // could add an easing funciton
  44. myShip.angle = _model.angle;
  45. shipEmitter.setMotion(EMITTER, 45, 10,1);
  46. shipEmitter.emit(EMITTER, 0, 0);
  47. //Listens for changes on the model
  48. //The event handler that reacts to changes
  49. //in the doel's value is below
  50. _model.addEventListener(Event.CHANGE, changeHandler);
  51. draw();
  52. }
  53.  
  54. private function draw():void
  55. {
  56. graphic = new Graphiclist(myShip,shipEmitter);
  57. myShip.centerOO();
  58. }
  59. private function changeHandler(event:Event):void
  60. {
  61. myShip.x = _model.xPos;
  62. myShip.y = _model.yPos;
  63. shipEmitter.emit(EMITTER, -2, -2);
  64. shipEmitter.emit(EMITTER, 3, -2);
  65. shipEmitter.emit(EMITTER, -7, -2);
  66. }
  67. }
  68. }
Add Comment
Please, Sign In to add comment