新增虚拟输入类 VirtualInput

This commit is contained in:
yhh
2020-08-27 18:48:20 +08:00
parent e81f98ff17
commit d07912d610
47 changed files with 3428 additions and 1615 deletions
+260 -139
View File
@@ -285,7 +285,6 @@ declare module es {
update(): void;
setEnabled(isEnabled: boolean): this;
setUpdateOrder(updateOrder: number): this;
clone(): Component;
}
}
declare module es {
@@ -334,7 +333,6 @@ declare module es {
destroy(): void;
detachFromScene(): void;
attachToScene(newScene: Scene): void;
clone(position?: Vector2): Entity;
onAddedToScene(): void;
onRemovedFromScene(): void;
update(): void;
@@ -349,7 +347,6 @@ declare module es {
removeAllComponents(): void;
compareTo(other: Entity): number;
toString(): string;
protected copyFrom(entity: Entity): void;
}
}
declare module es {
@@ -691,7 +688,7 @@ declare module es {
class SpriteAnimation {
readonly sprites: Sprite[];
readonly frameRate: number;
constructor(sprites: Sprite[], frameRate: number);
constructor(sprites: Sprite[], frameRate?: number);
}
}
declare module es {
@@ -759,7 +756,7 @@ declare module es {
declare module es {
class TiledMapRenderer extends RenderableComponent {
tiledMap: TmxMap;
physicsLayer: number;
physicsLayer: Ref<number>;
layerIndicesToRender: number[];
private toContainer;
readonly width: number;
@@ -808,11 +805,10 @@ declare module es {
}
declare module es {
abstract class Collider extends Component {
debug: any;
shape: Shape;
isTrigger: boolean;
physicsLayer: number;
collidesWithLayers: number;
physicsLayer: Ref<number>;
collidesWithLayers: Ref<number>;
shouldColliderScaleAndRotateWithTransform: boolean;
registeredPhysicsBounds: Rectangle;
_localOffsetLength: number;
@@ -837,7 +833,6 @@ declare module es {
unregisterColliderWithPhysicsSystem(): void;
overlaps(other: Collider): boolean;
collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean;
clone(): Component;
}
}
declare module es {
@@ -846,10 +841,9 @@ declare module es {
polygonShape: egret.Shape;
pixelShape1: egret.Shape;
pixelShape2: egret.Shape;
constructor();
constructor(x?: number, y?: number, width?: number, height?: number);
width: number;
height: number;
createBoxRect(x: number, y: number, width: number, height: number): BoxCollider;
setSize(width: number, height: number): this;
setWidth(width: number): BoxCollider;
setHeight(height: number): void;
@@ -1303,10 +1297,10 @@ declare module es {
class Flags {
static isFlagSet(self: number, flag: number): boolean;
static isUnshiftedFlagSet(self: number, flag: number): boolean;
static setFlagExclusive(self: number, flag: number): number;
static setFlag(self: number, flag: number): number;
static unsetFlag(self: number, flag: number): number;
static invertFlags(self: number): number;
static setFlagExclusive(self: Ref<number>, flag: number): void;
static setFlag(self: Ref<number>, flag: number): void;
static unsetFlag(self: Ref<number>, flag: number): void;
static invertFlags(self: Ref<number>): void;
}
}
declare module es {
@@ -1422,12 +1416,12 @@ declare module es {
static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean;
static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2;
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean;
static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean;
static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean;
static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean;
static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean;
static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean;
static circleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean;
static circleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean;
static circleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean;
static rectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean;
static rectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean;
static rectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean;
static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors;
}
}
@@ -1486,7 +1480,6 @@ declare module es {
abstract collidesWithLine(start: Vector2, end: Vector2, hit: RaycastHit): boolean;
abstract containsPoint(point: Vector2): any;
abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
clone(): Shape;
}
}
declare module es {
@@ -1508,7 +1501,7 @@ declare module es {
static findPolygonCenter(points: Vector2[]): Vector2;
static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2;
static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: Ref<number>, edgeNormal: Vector2): Vector2;
static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: any): void;
static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: Vector2[]): void;
recalculateBounds(collider: Collider): void;
overlaps(other: Shape): any;
collidesWithShape(other: Shape, result: CollisionResult): boolean;
@@ -2051,122 +2044,6 @@ declare module es {
update(): void;
}
}
declare module es {
class TouchState {
x: number;
y: number;
touchPoint: number;
touchDown: boolean;
readonly position: Vector2;
reset(): void;
}
class Input {
private static _init;
private static _previousTouchState;
private static _resolutionOffset;
private static _touchIndex;
private static _gameTouchs;
static readonly gameTouchs: TouchState[];
private static _resolutionScale;
static readonly resolutionScale: Vector2;
private static _totalTouchCount;
static readonly totalTouchCount: number;
static readonly touchPosition: Vector2;
static maxSupportedTouch: number;
static readonly touchPositionDelta: Vector2;
static initialize(): void;
static scaledPosition(position: Vector2): Vector2;
private static initTouchCache;
private static touchBegin;
private static touchMove;
private static touchEnd;
private static setpreviousTouchState;
}
}
declare class KeyboardUtils {
static TYPE_KEY_DOWN: number;
static TYPE_KEY_UP: number;
static A: string;
static B: string;
static C: string;
static D: string;
static E: string;
static F: string;
static G: string;
static H: string;
static I: string;
static J: string;
static K: string;
static L: string;
static M: string;
static N: string;
static O: string;
static P: string;
static Q: string;
static R: string;
static S: string;
static T: string;
static U: string;
static V: string;
static W: string;
static X: string;
static Y: string;
static Z: string;
static ESC: string;
static F1: string;
static F2: string;
static F3: string;
static F4: string;
static F5: string;
static F6: string;
static F7: string;
static F8: string;
static F9: string;
static F10: string;
static F11: string;
static F12: string;
static NUM_1: string;
static NUM_2: string;
static NUM_3: string;
static NUM_4: string;
static NUM_5: string;
static NUM_6: string;
static NUM_7: string;
static NUM_8: string;
static NUM_9: string;
static NUM_0: string;
static TAB: string;
static CTRL: string;
static ALT: string;
static SHIFT: string;
static CAPS_LOCK: string;
static ENTER: string;
static SPACE: string;
static BACK_SPACE: string;
static INSERT: string;
static DELETE: string;
static HOME: string;
static END: string;
static PAGE_UP: string;
static PAGE_DOWN: string;
static LEFT: string;
static RIGHT: string;
static UP: string;
static DOWN: string;
static PAUSE_BREAK: string;
static NUM_LOCK: string;
static SCROLL_LOCK: string;
static WINDOWS: string;
private static keyDownDict;
private static keyUpDict;
static init(): void;
static registerKey(key: string, fun: Function, thisObj: any, type?: number, ...args: any[]): void;
static unregisterKey(key: string, type?: number): void;
static destroy(): void;
private static onKeyDonwHander;
private static onKeyUpHander;
private static keyCodeToString;
}
declare module es {
class ListPool {
private static readonly _objectQueue;
@@ -2386,6 +2263,250 @@ declare module es {
initialized: boolean;
}
}
declare module es {
class TouchState {
x: number;
y: number;
touchPoint: number;
touchDown: boolean;
readonly position: Vector2;
reset(): void;
}
class Input {
private static _init;
private static _previousTouchState;
private static _resolutionOffset;
private static _touchIndex;
private static _gameTouchs;
static readonly gameTouchs: TouchState[];
private static _resolutionScale;
static readonly resolutionScale: Vector2;
private static _totalTouchCount;
static readonly totalTouchCount: number;
static readonly touchPosition: Vector2;
static _virtualInputs: VirtualInput[];
static maxSupportedTouch: number;
static readonly touchPositionDelta: Vector2;
static initialize(): void;
static update(): void;
static scaledPosition(position: Vector2): Vector2;
static isKeyPressed(key: Keys): boolean;
static isKeyPressedBoth(keyA: Keys, keyB: Keys): boolean;
static isKeyDown(key: Keys): boolean;
static isKeyDownBoth(keyA: Keys, keyB: Keys): boolean;
static isKeyReleased(key: Keys): boolean;
static isKeyReleasedBoth(keyA: Keys, keyB: Keys): boolean;
private static initTouchCache;
private static touchBegin;
private static touchMove;
private static touchEnd;
private static setpreviousTouchState;
}
}
import Keys = es.Keys;
declare class KeyboardUtils {
static currentKeys: Keys[];
static previousKeys: Keys[];
private static keyStatusKeys;
static init(): void;
static update(): void;
static destroy(): void;
private static onKeyDownHandler;
private static onKeyUpHandler;
}
declare module es {
enum Keys {
none = 0,
back = 8,
tab = 9,
enter = 13,
capsLock = 20,
escape = 27,
space = 32,
pageUp = 33,
pageDown = 34,
end = 35,
home = 36,
left = 37,
up = 38,
right = 39,
down = 40,
select = 41,
print = 42,
execute = 43,
printScreen = 44,
insert = 45,
delete = 46,
help = 47,
d0 = 48,
d1 = 49,
d2 = 50,
d3 = 51,
d4 = 52,
d5 = 53,
d6 = 54,
d7 = 55,
d8 = 56,
d9 = 57,
a = 65,
b = 66,
c = 67,
d = 68,
e = 69,
f = 70,
g = 71,
h = 72,
i = 73,
j = 74,
k = 75,
l = 76,
m = 77,
n = 78,
o = 79,
p = 80,
q = 81,
r = 82,
s = 83,
t = 84,
u = 85,
v = 86,
w = 87,
x = 88,
y = 89,
z = 90,
leftWindows = 91,
rightWindows = 92,
apps = 93,
sleep = 95,
numPad0 = 96,
numPad1 = 97,
numPad2 = 98,
numPad3 = 99,
numPad4 = 100,
numPad5 = 101,
numPad6 = 102,
numPad7 = 103,
numPad8 = 104,
numPad9 = 105,
multiply = 106,
add = 107,
seperator = 108,
subtract = 109,
decimal = 110,
divide = 111,
f1 = 112,
f2 = 113,
f3 = 114,
f4 = 115,
f5 = 116,
f6 = 117,
f7 = 118,
f8 = 119,
f9 = 120,
f10 = 121,
f11 = 122,
f12 = 123,
f13 = 124,
f14 = 125,
f15 = 126,
f16 = 127,
f17 = 128,
f18 = 129,
f19 = 130,
f20 = 131,
f21 = 132,
f22 = 133,
f23 = 134,
f24 = 135,
numLock = 144,
scroll = 145,
leftShift = 160,
rightShift = 161,
leftControl = 162,
rightControl = 163,
leftAlt = 164,
rightAlt = 165,
browserBack = 166,
browserForward = 167
}
}
declare module es {
enum OverlapBehavior {
cancelOut = 0,
takeOlder = 1,
takeNewer = 2
}
abstract class VirtualInput {
protected constructor();
deregister(): void;
abstract update(): any;
}
abstract class VirtualInputNode {
update(): void;
}
}
declare module es {
class VirtualIntegerAxis extends VirtualInput {
nodes: VirtualAxisNode[];
readonly value: number;
constructor(...nodes: VirtualAxisNode[]);
update(): void;
addKeyboardKeys(overlapBehavior: OverlapBehavior, negative: Keys, positive: Keys): this;
}
abstract class VirtualAxisNode extends VirtualInputNode {
abstract value: number;
}
}
declare module es {
class VirtualAxis extends VirtualInput {
nodes: VirtualAxisNode[];
readonly value: number;
constructor(...nodes: VirtualAxisNode[]);
update(): void;
}
class KeyboardKeys extends VirtualAxisNode {
overlapBehavior: OverlapBehavior;
positive: Keys;
negative: Keys;
_value: number;
_turned: boolean;
constructor(overlapBehavior: OverlapBehavior, negative: Keys, positive: Keys);
update(): void;
readonly value: number;
}
}
declare module es {
class VirtualButton extends VirtualInput {
nodes: Node[];
bufferTime: number;
firstRepeatTime: number;
mutiRepeatTime: number;
isRepeating: boolean;
_bufferCounter: number;
_repeatCounter: number;
_willRepeat: boolean;
constructor(bufferTime?: number, ...nodes: Node[]);
setRepeat(firstRepeatTime: number, mutiRepeatTime?: number): void;
update(): void;
readonly isDown: boolean;
readonly isPressed: boolean;
readonly isReleased: boolean;
consumeBuffer(): void;
addKeyboardKey(key: Keys): VirtualButton;
}
abstract class Node extends VirtualInputNode {
abstract isDown: boolean;
abstract isPressed: boolean;
abstract isReleased: boolean;
}
class KeyboardKey extends Node {
key: Keys;
constructor(key: Keys);
readonly isDown: boolean;
readonly isPressed: boolean;
readonly isReleased: boolean;
}
}
declare module es {
class AssetPacker {
protected itemsToRaster: TextureToPack[];
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+3 -1
View File
@@ -17,7 +17,7 @@
"bin-debug/SampleHelpers/SampleScene.js",
"bin-debug/Scenes/Ninja Adventure/ProjectileHitDetector.js",
"bin-debug/UI/loading/LoadingView.js",
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
"bin-debug/Scenes/Ninja Adventure/CameraBounds.js",
"bin-debug/Fgui/loading/loadingBinder.js",
"bin-debug/Fgui/loading/UI_View_loading.js",
"bin-debug/Fgui/sc/scBinder.js",
@@ -28,7 +28,9 @@
"bin-debug/Scenes/Animated Tiles/AnimatedTilesScene.js",
"bin-debug/Scenes/Empty Scene/BasicScene.js",
"bin-debug/Scenes/LineCasting/LineCaster.js",
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
"bin-debug/Main.js",
"bin-debug/Scenes/Ninja Adventure/FireballProjectileController.js",
"bin-debug/Scenes/Ninja Adventure/Ninja.js",
"bin-debug/Scenes/Ninja Adventure/NinjaAdventureScene.js",
"bin-debug/ThemeAdapter.js",
+21 -6
View File
@@ -1,7 +1,7 @@
{
"groups": [
{
"keys": "bg_png,bgNorm_png,moon_png,orange_png,moonNorm_png,orangeNorm_png,orthogonal-outside_json",
"keys": "bg_png,bgNorm_png,moon_png,orange_png,moonNorm_png,orangeNorm_png,tiledMap_json,orthogonal-outside_json,tilemap_json,plume_png",
"name": "preload"
},
{
@@ -52,11 +52,6 @@
"type": "image",
"name": "orangeNorm_png"
},
{
"url": "preload/orthogonal-outside.json",
"type": "json",
"name": "orthogonal-outside_json"
},
{
"url": "characters/1.png",
"type": "image",
@@ -101,6 +96,26 @@
"url": "fgui/loading.zip",
"type": "bin",
"name": "loading"
},
{
"url": "preload/caveman/tiledMap.json",
"type": "json",
"name": "tiledMap_json"
},
{
"url": "preload/orthogonal/orthogonal-outside.json",
"type": "json",
"name": "orthogonal-outside_json"
},
{
"url": "preload/ninja/tilemap.json",
"type": "json",
"name": "tilemap_json"
},
{
"url": "preload/plume.png",
"type": "image",
"name": "plume_png"
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+193
View File
@@ -0,0 +1,193 @@
{ "height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0, 0, 0, 0, 0, 0, 2147483652, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2147483652, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2147483652, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 2147483652, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
"height":30,
"id":1,
"name":"main",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":40,
"x":0,
"y":0
},
{
"draworder":"topdown",
"id":2,
"name":"objects",
"objects":[
{
"height":14.8796,
"id":6,
"name":"spawn",
"rotation":0,
"type":"",
"visible":true,
"width":14.8796,
"x":48.4346,
"y":240.503
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":3,
"nextobjectid":7,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.2.1",
"tileheight":16,
"tilesets":[
{
"columns":2,
"firstgid":1,
"image":"tileset.png",
"imageheight":32,
"imagewidth":32,
"margin":0,
"name":"tileset",
"spacing":0,
"tilecount":4,
"tileheight":16,
"tiles":[
{
"id":0,
"objectgroup":
{
"draworder":"index",
"name":"",
"objects":[
{
"height":16,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":16,
"x":0,
"y":0
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}
},
{
"id":2,
"objectgroup":
{
"draworder":"index",
"name":"",
"objects":[
{
"height":3,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":16,
"x":0,
"y":0
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"filewtf",
"type":"file",
"value":""
},
{
"name":"floaty",
"type":"float",
"value":0
},
{
"name":"inty",
"type":"int",
"value":0
},
{
"name":"nez:isOneWayPlatform",
"type":"bool",
"value":true
},
{
"name":"poop",
"type":"color",
"value":""
}]
},
{
"id":3,
"objectgroup":
{
"draworder":"index",
"name":"",
"objects":[
{
"height":0,
"id":1,
"name":"",
"polygon":[
{
"x":0,
"y":0
},
{
"x":0,
"y":16
},
{
"x":16,
"y":16
}],
"rotation":0,
"type":"",
"visible":true,
"width":0,
"x":0,
"y":0
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
},
"properties":[
{
"name":"nez:isSlope",
"type":"bool",
"value":true
},
{
"name":"nez:slopeTopLeft",
"type":"int",
"value":0
},
{
"name":"nez:slopeTopRight",
"type":"int",
"value":15
}]
}],
"tilewidth":16
}],
"tilewidth":16,
"type":"map",
"version":1.2,
"width":40
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

File diff suppressed because one or more lines are too long
Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

-16
View File
@@ -38,22 +38,6 @@ module samples {
displayContainer.addChild(this._lineShape);
}
public onAddedToEntity(): void {
KeyboardUtils.registerKey(KeyboardUtils.SPACE, this.spaceDown, this, KeyboardUtils.TYPE_KEY_DOWN);
}
public onRemovedFromEntity(): void {
KeyboardUtils.unregisterKey(KeyboardUtils.SPACE, KeyboardUtils.TYPE_KEY_DOWN);
}
private spaceDown(){
let hit = Physics.linecast(this._lastPosition, this.transform.position);
if (hit.collider){
this._collisionPosition = hit.point;
}
}
public render(camera: es.Camera): any {
this._pixelShape1.graphics.clear();
this._pixelShape1.graphics.beginFill(0xffff00);
@@ -0,0 +1,37 @@
module samples {
import Component = es.Component;
import Vector2 = es.Vector2;
export class CameraBounds extends Component {
public min: Vector2;
public max: Vector2;
constructor(min: Vector2 = Vector2.zero, max: Vector2 = Vector2.zero){
super();
this.min = min;
this.max = max;
this.setUpdateOrder(Number.MAX_VALUE);
}
public onAddedToEntity(): void {
this.entity.updateOrder = Number.MAX_VALUE;
}
public update(): void {
let cameraBounds = this.entity.scene.camera.bounds;
if (cameraBounds.top < this.min.y)
this.entity.scene.camera.position.add(new Vector2(0, this.min.y - cameraBounds.top));
if (cameraBounds.left < this.min.x)
this.entity.scene.camera.position.add(new Vector2(this.min.x - cameraBounds.left, 0));
if (cameraBounds.bottom > this.max.y)
this.entity.scene.camera.position.add(new Vector2(0, this.max.y - cameraBounds.bottom));
if (cameraBounds.right > this.max.x)
this.entity.scene.camera.position.add(new Vector2(this.max.x - cameraBounds.right, 0));
}
}
}
@@ -0,0 +1,28 @@
module samples {
import Component = es.Component;
import Vector2 = es.Vector2;
import ProjectileMover = es.ProjectileMover;
import Time = es.Time;
/**
* 西
*/
export class FireballProjectileController extends Component {
public velocity: Vector2;
public _mover: ProjectileMover;
constructor(velocity: Vector2){
super();
this.velocity = velocity;
}
public onAddedToEntity(): void {
this._mover = this.entity.getComponent<ProjectileMover>(ProjectileMover);
}
public update(): void {
if (this._mover.move(Vector2.multiply(this.velocity, new Vector2(Time.deltaTime))))
this.entity.destroy();
}
}
}
+126 -31
View File
@@ -1,50 +1,145 @@
module samples {
import SpriteAnimator = es.SpriteAnimator;
import Mover = es.Mover;
import VirtualButton = es.VirtualButton;
import VirtualIntegerAxis = es.VirtualIntegerAxis;
import KeyboardKey = es.KeyboardKey;
import KeyboardKeys = es.KeyboardKeys;
import OverlapBehavior = es.OverlapBehavior;
import Vector2 = es.Vector2;
import Time = es.Time;
import Keys = es.Keys;
import CollisionResult = es.CollisionResult;
import SubpixelVector2 = es.SubpixelVector2;
import ITriggerListener = es.ITriggerListener;
export class Ninja extends es.Component {
export class Ninja extends es.Component implements ITriggerListener{
public _animator: SpriteAnimator;
public _subpixelV2: SubpixelVector2 = new SubpixelVector2();
public _mover: Mover;
public _moveSpeed = 100;
public _projectileVelocity: Vector2 = new Vector2(175);
public _fireInput: VirtualButton;
public _xAxisInput: VirtualIntegerAxis;
public _yAxisInput: VirtualIntegerAxis;
public onAddedToEntity(): void {
let characterPng = RandomUtils.randint(1, 6);
this.entity.scene.content.loadRes(`${characterPng}_png`).then(texture => {
let sprites = es.Sprite.spritesFromAtlas(texture, 16, 16);
let texture = RES.getRes(`${characterPng}_png`);
let sprites = es.Sprite.spritesFromAtlas(texture, 16, 16);
this._mover = this.entity.addComponent(new Mover());
this._animator = this.entity.addComponent(new SpriteAnimator());
this._mover = this.entity.addComponent(new Mover());
this._animator = this.entity.addComponent(new SpriteAnimator());
this._animator.addAnimation("walkLeft", new es.SpriteAnimation([
sprites[2],
sprites[6],
sprites[10],
sprites[14]
], 4));
this._animator.addAnimation("walkLeft", new es.SpriteAnimation([
sprites[2],
sprites[6],
sprites[10],
sprites[14]
], 4));
this._animator.addAnimation("walkRight", new es.SpriteAnimation([
sprites[3],
sprites[7],
sprites[11],
sprites[15]
], 4));
this._animator.addAnimation("walkRight", new es.SpriteAnimation([
sprites[3],
sprites[7],
sprites[11],
sprites[15]
], 4));
this._animator.addAnimation("walkDown", new es.SpriteAnimation([
sprites[0],
sprites[4],
sprites[8],
sprites[12]
], 4));
this._animator.addAnimation("walkDown", new es.SpriteAnimation([
sprites[0],
sprites[4],
sprites[8],
sprites[12]
], 4));
this._animator.addAnimation("walkUp", new es.SpriteAnimation([
sprites[1],
sprites[5],
sprites[9],
sprites[13]
], 4));
this._animator.addAnimation("walkUp", new es.SpriteAnimation([
sprites[1],
sprites[5],
sprites[9],
sprites[13]
], 4));
this._animator.play("walkDown");
});
this.setupInput();
}
public onRemovedFromEntity(): void {
this._fireInput.deregister();
}
public setupInput(){
// 设置输入射击一个火球。我们允许在键盘z上使用
this._fireInput = new VirtualButton();
this._fireInput.nodes.push(new KeyboardKey(Keys.z));
this._xAxisInput = new VirtualIntegerAxis();
this._xAxisInput.nodes.push(new KeyboardKeys(OverlapBehavior.takeNewer, Keys.left, Keys.right));
this._yAxisInput = new VirtualIntegerAxis();
this._yAxisInput.nodes.push(new KeyboardKeys(OverlapBehavior.takeNewer, Keys.up, Keys.down));
}
public update(): void {
let moveDir = new Vector2(this._xAxisInput.value, this._yAxisInput.value);
let animation = "walkDown";
if (moveDir.x < 0)
animation = "walkLeft";
else if(moveDir.x > 0)
animation = "walkRight";
if (moveDir.y < 0)
animation = "walkUp";
else if(moveDir.y > 0)
animation = "walkDown";
if (!moveDir.equals(Vector2.zero)){
if (!this._animator.isAnimationActive(animation))
this._animator.play(animation);
else
this._animator.unPause();
let movement = Vector2.multiply(moveDir, new Vector2(this._moveSpeed * Time.deltaTime));
let res: CollisionResult = new CollisionResult();
this._mover.calculateMovement(movement, res);
this._subpixelV2.update(movement);
this._mover.applyMovement(movement);
}else{
this._animator.pause();
}
if (this._fireInput.isPressed){
let dir = Vector2.zero;
switch (this._animator.currentAnimationName) {
case "walkUp":
dir.y = -1;
break;
case "walkDown":
dir.y = 1;
break;
case "walkRight":
dir.x = 1;
break;
case "walkLeft":
dir.x = -1;
break;
default:
dir = new Vector2(1, 0);
break;
}
let ninjaScene = this.entity.scene as NinjaAdventureScene;
ninjaScene.createProjectiles(this.entity.transform.position, Vector2.multiply(this._projectileVelocity, dir));
}
}
public onTriggerEnter(other: es.Collider, local: es.Collider): any {
console.log(`triggerEnter: ${other.entity.name}`);
}
public onTriggerExit(other: es.Collider, local: es.Collider): any {
console.log(`triggerExit: ${other.entity.name}`);
}
}
}
@@ -4,13 +4,38 @@ module samples {
import SpriteRenderer = es.SpriteRenderer;
import ProjectileHitDetector = es.ProjectileHitDetector;
import FollowCamera = es.FollowCamera;
import TiledMapLoader = es.TiledMapLoader;
import TiledMapRenderer = es.TiledMapRenderer;
import Vector2 = es.Vector2;
import ProjectileMover = es.ProjectileMover;
import Sprite = es.Sprite;
import SpriteAnimator = es.SpriteAnimator;
import SpriteAnimation = es.SpriteAnimation;
export class NinjaAdventureScene extends SampleScene {
public async onStart() {
super.onStart();
let tiledEntity = this.createEntity("tiled-map-entity");
TiledMapLoader.loadTmxMap(new es.TmxMap(), "tilemap_json").then(map => {
let tiledMapRenderer = tiledEntity.addComponent(new TiledMapRenderer(map, "collision"));
tiledMapRenderer.setLayersToRender("tiles", "terrain", "details");
tiledMapRenderer.renderLayer = 10;
let tiledMapDetailsComp = tiledEntity.addComponent(new TiledMapRenderer(map));
tiledMapRenderer.setLayerToRender("above-details");
tiledMapRenderer.renderLayer = -1;
let topLeft = new Vector2(map.tileWidth, map.tileWidth);
let bottomRight = new Vector2(map.tileWidth * (map.width - 1),
map.tileWidth * (map.height - 1));
tiledEntity.addComponent(new CameraBounds(topLeft, bottomRight));
});
let playerEntity = this.createEntity("player");
playerEntity.position = new es.Vector2(256, 224);
playerEntity.position = new es.Vector2(256 / 2, 224 / 2);
playerEntity.addComponent(new Ninja());
let collider = playerEntity.addComponent(new CircleCollider());
@@ -21,20 +46,39 @@ module samples {
this.camera.entity.addComponent(new FollowCamera(playerEntity));
this.content.loadRes("moon_png").then(moonTexture => {
let moonEntity = this.createEntity("moon");
moonEntity.position = new es.Vector2(412, 460);
moonEntity.addComponent(new SpriteRenderer(moonTexture));
moonEntity.addComponent(new ProjectileHitDetector());
moonEntity.addComponent(new CircleCollider());
});
let moonTexture = RES.getRes("moon_png");
let moonEntity = this.createEntity("moon");
moonEntity.position = new es.Vector2(412, 460);
moonEntity.addComponent(new SpriteRenderer(moonTexture));
moonEntity.addComponent(new ProjectileHitDetector());
moonEntity.addComponent(new CircleCollider());
}
public update(){
super.update();
/**
* 使
* @param position
* @param velocity
*/
public createProjectiles(position: Vector2, velocity: Vector2) {
// 创建一个实体来存放投射程序及其逻辑
let entity = this.createEntity("projectile");
entity.position = position;
entity.addComponent(new ProjectileMover());
entity.addComponent(new FireballProjectileController(velocity));
this.findEntity("player").position.x -= es.Time.deltaTime * 10;
this.findEntity("player").position.y -= es.Time.deltaTime * 10;
let collider = entity.addComponent(new CircleCollider());
Flags.setFlagExclusive(collider.collidesWithLayers, 0);
Flags.setFlagExclusive(collider.physicsLayer, 1);
let texture = RES.getRes("plume_png");
let sprites = Sprite.spritesFromAtlas(texture, 16, 16);
let animator = entity.addComponent(new SpriteAnimator());
animator.renderLayer = 1;
animator.addAnimation("default", new SpriteAnimation(sprites));
animator.play("default");
return entity;
}
}
}