Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package spaceShip
- {
- import flash.display.Sprite;
- import flash.display.*;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.filters.*;
- import flash.events.KeyboardEvent;
- import flash.ui.Keyboard;
- import net.flashpunk.Entity;
- import net.flashpunk.FP;
- import net.flashpunk.graphics.Emitter;
- import net.flashpunk.graphics.Graphiclist;
- import net.flashpunk.graphics.Image;
- /**
- * ...
- * @author Joe Newbry
- */
- public class ShipView extends Entity
- {
- // Object that contains the player model
- private var _model:ShipModel;
- //Object that contains the player controller
- private var _controller:ShipController;
- [Embed(source='../../assets/images/Ship2.png')]
- private static const SHOT:Class;
- private var myShip:Image = new Image(SHOT);
- [Embed(source = '../../assets/images/ShipTrail.png')]
- private static const TRAIL:Class;
- private var shipEmitter:Emitter = new Emitter(TRAIL, 4, 4);
- private static const EMITTER:String = "myEmitter";
- public function ShipView(model:ShipModel, controller:ShipController)
- {
- _model = model;
- _controller = controller;
- shipEmitter.newType(EMITTER, [0, 1,0,1,0,1,2,3,2,1,3,2,1,0]);
- shipEmitter.setAlpha(EMITTER, 1,1) // could add an easing funciton
- myShip.angle = _model.angle;
- shipEmitter.setMotion(EMITTER, 45, 10,1);
- shipEmitter.emit(EMITTER, 0, 0);
- //Listens for changes on the model
- //The event handler that reacts to changes
- //in the doel's value is below
- _model.addEventListener(Event.CHANGE, changeHandler);
- draw();
- }
- private function draw():void
- {
- graphic = new Graphiclist(myShip,shipEmitter);
- myShip.centerOO();
- }
- private function changeHandler(event:Event):void
- {
- myShip.x = _model.xPos;
- myShip.y = _model.yPos;
- shipEmitter.emit(EMITTER, -2, -2);
- shipEmitter.emit(EMITTER, 3, -2);
- shipEmitter.emit(EMITTER, -7, -2);
- }
- }
- }
Add Comment
Please, Sign In to add comment