added temp enemy mover

This commit is contained in:
Martin
2022-11-14 16:35:47 +01:00
parent 279218b4c3
commit 3dd10f13ef
16 changed files with 212 additions and 23 deletions

View File

@@ -0,0 +1,5 @@
import { Vec2 } from "cc";
export interface IInput {
getAxis: () => Vec2;
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b82ab67e-d720-4feb-ada9-07b6704a2b88",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,60 @@
import { EventKeyboard, Input, input, KeyCode, Vec2 } from "cc";
import { IInput } from "./IInput";
export class KeyboardInput implements IInput {
private xAxis = 0;
private yAxis = 0;
private up: KeyCode;
private down: KeyCode;
private left: KeyCode;
private right: KeyCode;
public constructor(up: KeyCode, down: KeyCode, left: KeyCode, right: KeyCode) {
this.up = up;
this.down = down;
this.left = left;
this.right = right;
input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
input.on(Input.EventType.KEY_UP, this.onKeyUp, this);
}
public getAxis(): Vec2 {
return new Vec2(this.xAxis, this.yAxis).normalize();
}
private onKeyDown(event: EventKeyboard): void {
switch (event.keyCode) {
case this.up:
this.yAxis += 1;
break;
case this.down:
this.yAxis += -1;
break;
case this.left:
this.xAxis += -1;
break;
case this.right:
this.xAxis += 1;
break;
}
}
private onKeyUp(event: EventKeyboard): void {
switch (event.keyCode) {
case this.up:
this.yAxis -= 1;
break;
case this.down:
this.yAxis -= -1;
break;
case this.left:
this.xAxis -= -1;
break;
case this.right:
this.xAxis -= 1;
break;
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "14d4988b-08bc-4a0e-97e7-b06b78b1a180",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,20 @@
import { Vec2 } from "cc";
import { IInput } from "./IInput";
export class MultiInput implements IInput {
private inputs: IInput[];
public constructor(inputs: IInput[]) {
this.inputs = inputs;
}
public getAxis(): Vec2 {
for (let i = 0; i < this.inputs.length; i++) {
if (!this.inputs[i].getAxis().equals(Vec2.ZERO)) {
return this.inputs[i].getAxis();
}
}
return new Vec2();
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "679d7c05-dfb4-43e8-8115-9af235222733",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,8 +1,9 @@
import { _decorator, Component, Node, Vec3, input, Input, EventMouse, Vec2, EventTouch } from "cc";
import { IInput } from "./IInput";
const { ccclass, property } = _decorator;
@ccclass("VirtualJoystic")
export class VirtualJoystic extends Component {
export class VirtualJoystic extends Component implements IInput {
@property(Number) private maxDistance = 10;
@property(Node) private knob: Node;