mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 08:36:14 +00:00
added temp enemy mover
This commit is contained in:
5
assets/Scripts/Game/Input/IInput.ts
Normal file
5
assets/Scripts/Game/Input/IInput.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Vec2 } from "cc";
|
||||
|
||||
export interface IInput {
|
||||
getAxis: () => Vec2;
|
||||
}
|
9
assets/Scripts/Game/Input/IInput.ts.meta
Normal file
9
assets/Scripts/Game/Input/IInput.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b82ab67e-d720-4feb-ada9-07b6704a2b88",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
60
assets/Scripts/Game/Input/KeyboardInput.ts
Normal file
60
assets/Scripts/Game/Input/KeyboardInput.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
9
assets/Scripts/Game/Input/KeyboardInput.ts.meta
Normal file
9
assets/Scripts/Game/Input/KeyboardInput.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "14d4988b-08bc-4a0e-97e7-b06b78b1a180",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
20
assets/Scripts/Game/Input/MultiInput.ts
Normal file
20
assets/Scripts/Game/Input/MultiInput.ts
Normal 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();
|
||||
}
|
||||
}
|
9
assets/Scripts/Game/Input/MultiInput.ts.meta
Normal file
9
assets/Scripts/Game/Input/MultiInput.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "679d7c05-dfb4-43e8-8115-9af235222733",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user