📄 trickmanager.as
字号:
/**
* Paperskated3d - simple skateboard simulator in Papervision3d
*
* @author Bartek Drozdz
* @version 1.0
*
* Released under Creative Commons Attribution-Non-Commercial-Share Alike 3.0 License.
*/
package com.paperskate3d.tricks {
import com.paperskate3d.skate.SkateBoard;
import com.paperskate3d.SkatingEvent;
import flash.display.DisplayObject;
import flash.events.EventDispatcher;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import com.carlcalderon.arthropod.Debug;
public class TrickManager extends EventDispatcher {
private var skate:SkateBoard;
public static var ROLLING:int = 1;
public static var OLLIE:int = 2;
public static var SHOVEIT:int = 3;
// For future use
public static var GRIND:int = 5;
public static var TAIL_SLIDE:int = 6;
public static var NOSE_SLIDE:int = 7;
public static var SLIDE:int = 8;
private var state:int = ROLLING;
private var currentOllie:Ollie;
private var currentWheelie:Wheelie;
private var trickStack:TrickStack;
private var orientation:Number = 1;
// Do not change those
public var baseRotationX:Number = -90;
public var terrainLevel:Number = 0;
public function TrickManager(skate:SkateBoard):void {
this.skate = skate;
trickStack = new TrickStack();
}
public function trickInProgress():Boolean {
return !(state == ROLLING && currentWheelie == null);
}
public function hasWheelie():Boolean {
return currentWheelie != null;
}
public function abortWheelie():void {
if (hasWheelie()) {
currentWheelie.abort();
currentWheelie = null;
}
}
public function abort():void {
state = ROLLING;
currentWheelie = null;
}
public function lowSpeed():void {
if (currentWheelie != null) {
currentWheelie.abort();
currentWheelie = null;
}
}
public function perform(ke:KeyboardEvent, speed:Number, playbackSpeed:Number):Boolean {
var t:BasicTrick;
switch(ke.keyCode) {
case Keyboard.SPACE:
if (state != ROLLING ||
(currentWheelie != null && currentWheelie.nose == true) ||
trickStack.hasTrick("ollie")) return false;
t = new Ollie();
trickStack.addTrick(t);
t.init(skate, this);
abortWheelie();
t.start(speed, playbackSpeed);
dispatchEvent(new SkatingEvent(SkatingEvent.TRICK_STARTED));
state = OLLIE;
currentOllie = t as Ollie;
break;
case 78: // Keyboard.N:
if (state != ROLLING ||
(currentWheelie != null && currentWheelie.nose == false) ||
trickStack.hasTrick("ollie")) return false;
abortWheelie();
t = new Ollie(true);
trickStack.addTrick(t);
t.init(skate, this);
t.start(speed, playbackSpeed);
dispatchEvent(new SkatingEvent(SkatingEvent.TRICK_STARTED));
state = OLLIE;
currentOllie = t as Ollie;
break;
case 75: // Keyboard.K
if (!(state == OLLIE || state == SHOVEIT) || trickStack.hasTrick("kickflip")) return false;
if (ke.shiftKey) t = new KickFlip(true, state == SHOVEIT);
else t = new KickFlip(false, state == SHOVEIT);
trickStack.addTrick(t);
t.init(skate, this, currentOllie.phase);
t.start(speed, playbackSpeed);
break;
case 81: // Keyboard.Q:
if (state != OLLIE || trickStack.hasTrick("spin")) return false;
if (!ke.shiftKey) t = new Spin(180);
else t = new Spin(360);
trickStack.addTrick(t);
t.init(skate, this, currentOllie.phase);
t.start(speed, playbackSpeed);
break;
case 87: // Keyboard.W:
if (state != OLLIE || trickStack.hasTrick("spin")) return false;
if (!ke.shiftKey) t = new Spin(180, true);
else t = new Spin(360, true);
trickStack.addTrick(t);
t.init(skate, this, currentOllie.phase);
t.start(speed, playbackSpeed);
break;
case 65: // Keyboard.A:
if (state != ROLLING) return false;
if (!ke.shiftKey) t = new Spin(180, false, true);
else t = new Spin(360, false, true);
trickStack.addTrick(t);
t.init(skate, this);
t.start(speed, playbackSpeed);
abortWheelie();
dispatchEvent(new SkatingEvent(SkatingEvent.TRICK_STARTED));
state = SHOVEIT;
break;
case 83: // Keyboard.S:
if (state != ROLLING) return false;
if (!ke.shiftKey) t = new Spin(180, true, true);
else t = new Spin(360, true, true);
trickStack.addTrick(t);
t.init(skate, this);
t.start(speed, playbackSpeed);
abortWheelie();
dispatchEvent(new SkatingEvent(SkatingEvent.TRICK_STARTED));
state = SHOVEIT;
break;
case 73: // Keyboard.I
if (state != OLLIE || trickStack.hasTrick("impossible")) return false;
if (!ke.shiftKey) t = new Impossible(true);
else t = new Impossible();
trickStack.addTrick(t);
t.init(skate, this, currentOllie.phase);
t.start(speed, playbackSpeed);
break;
case 84: // Keyboard.T
if (state == OLLIE) {
if (currentOllie.phase == Ollie.DROP || currentOllie.phase == Ollie.BOUNCE) return false;
currentWheelie = new Wheelie();
currentWheelie.init(skate, this);
currentOllie.setWheelieTarget(currentWheelie);
} else if(state != SHOVEIT) {
if (currentWheelie == null) {
currentWheelie = new Wheelie();
currentWheelie.init(skate, this);
currentWheelie.start(speed, playbackSpeed);
} else {
abortWheelie();
}
}
break;
case 89: // Keyboard.Y
if (state == OLLIE) {
if (currentOllie.phase == Ollie.DROP || currentOllie.phase == Ollie.BOUNCE) return false;
currentWheelie = new Wheelie(true);
currentWheelie.init(skate, this);
currentOllie.setWheelieTarget(currentWheelie);
} else if(state != SHOVEIT) {
if (currentWheelie == null) {
currentWheelie = new Wheelie(true);
currentWheelie.init(skate, this);
currentWheelie.start(speed, playbackSpeed);
} else {
abortWheelie();
}
}
break;
default:
return false;
}
return true;
}
public function switchOrientation():void {
orientation *= -1;
}
public function onTrickFinished(t:BasicTrick):void {
if ((t is Ollie && state == OLLIE) || (t is Spin && state == SHOVEIT)) {
dispatchEvent(new SkatingEvent(SkatingEvent.TRICK_FINISHED));
state = ROLLING;
trickStack.reset();
}
}
public function getWheelSituation():Object {
var situation:Object = new Object();
if (currentWheelie != null && currentWheelie.nose == false) {
if(orientation == 1) {
situation.fl = situation.fr = orientation;
situation.bl = situation.br = 0;
} else {
situation.fl = situation.fr = 0;
situation.bl = situation.br = orientation;
}
} else if (currentWheelie != null && currentWheelie.nose == true) {
if(orientation == 1) {
situation.fl = situation.fr = 0;
situation.bl = situation.br = orientation;
} else {
situation.fl = situation.fr = orientation;
situation.bl = situation.br = 0;
}
} else if((state == OLLIE && !currentOllie.landed) || state == SHOVEIT) {
situation.fl = situation.fr = situation.bl = situation.br = 0;
} else {
situation.fl = situation.fr = situation.bl = situation.br = orientation;
}
return situation;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -