Advertisement
Guest User

Untitled

a guest
Sep 5th, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package project.game.players.controllers {
  2.  
  3.     import project.game.players.myPlayer;
  4.     import flash.events.*;
  5.     import flash.ui.Keyboard;
  6.  
  7.     public class myPlayerController {
  8.  
  9.         public var player: myPlayer;
  10.         public var myStage;
  11.         public var clicked: Array;
  12.  
  13.         public function myPlayerController(param1) {
  14.             this.myStage = param1;
  15.             init();
  16.         }
  17.         public function init() {
  18.             this.player = new myPlayer(myStage);
  19.             startEngine();
  20.         }
  21.         public function startEngine() {
  22.             myStage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
  23.             myStage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
  24.             myStage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
  25.         }
  26.         public function onEnterFrame(e: Event) {
  27.             if (this.clicked["UP"]) {
  28.                 this.player.mySprite.x += 1;
  29.             }
  30.             if (this.clicked["DOWN"]) {
  31.                 this.player.mySprite.x - 1;
  32.             }
  33.             if (this.clicked["RIGHT"]) {
  34.                 this.player.mySprite.y += 1;
  35.             }
  36.             if (this.clicked["LEFT"]) {
  37.                 this.player.mySprite.y -= 1;
  38.             }
  39.         }
  40.         public function onKeyUp(e: KeyboardEvent) {
  41.             if (e.keyCode == Keyboard.UP) {
  42.                 this.clicked["UP"] = false;
  43.             }
  44.             if (e.keyCode == Keyboard.DOWN) {
  45.                 this.clicked["DOWN"] = false;
  46.             }
  47.             if (e.keyCode == Keyboard.RIGHT) {
  48.                 this.clicked["RIGHT"] = false;
  49.             }
  50.             if (e.keyCode == Keyboard.LEFT) {
  51.                 this.clicked["LEFT"] = false;
  52.             }
  53.         }
  54.         public function onKeyDown(e: KeyboardEvent) {
  55.             if (e.keyCode == Keyboard.UP) {
  56.                 this.clicked["UP"] = true;
  57.             }
  58.             if (e.keyCode == Keyboard.DOWN) {
  59.                 this.clicked["DOWN"] = true;
  60.             }
  61.             if (e.keyCode == Keyboard.RIGHT) {
  62.                 this.clicked["RIGHT"] = true;
  63.             }
  64.             if (e.keyCode == Keyboard.LEFT) {
  65.                 this.clicked["LEFT"] = true;
  66.             }
  67.         }
  68.  
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement