Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package project.game.players.controllers {
- import project.game.players.myPlayer;
- import flash.events.*;
- import flash.ui.Keyboard;
- public class myPlayerController {
- public var player: myPlayer;
- public var myStage;
- public var clicked: Array;
- public function myPlayerController(param1) {
- this.myStage = param1;
- init();
- }
- public function init() {
- this.player = new myPlayer(myStage);
- startEngine();
- }
- public function startEngine() {
- myStage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
- myStage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
- myStage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
- }
- public function onEnterFrame(e: Event) {
- if (this.clicked["UP"]) {
- this.player.mySprite.x += 1;
- }
- if (this.clicked["DOWN"]) {
- this.player.mySprite.x - 1;
- }
- if (this.clicked["RIGHT"]) {
- this.player.mySprite.y += 1;
- }
- if (this.clicked["LEFT"]) {
- this.player.mySprite.y -= 1;
- }
- }
- public function onKeyUp(e: KeyboardEvent) {
- if (e.keyCode == Keyboard.UP) {
- this.clicked["UP"] = false;
- }
- if (e.keyCode == Keyboard.DOWN) {
- this.clicked["DOWN"] = false;
- }
- if (e.keyCode == Keyboard.RIGHT) {
- this.clicked["RIGHT"] = false;
- }
- if (e.keyCode == Keyboard.LEFT) {
- this.clicked["LEFT"] = false;
- }
- }
- public function onKeyDown(e: KeyboardEvent) {
- if (e.keyCode == Keyboard.UP) {
- this.clicked["UP"] = true;
- }
- if (e.keyCode == Keyboard.DOWN) {
- this.clicked["DOWN"] = true;
- }
- if (e.keyCode == Keyboard.RIGHT) {
- this.clicked["RIGHT"] = true;
- }
- if (e.keyCode == Keyboard.LEFT) {
- this.clicked["LEFT"] = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement