This commit is contained in:
Martin
2022-11-03 16:55:49 +01:00
commit f250c24f90
28 changed files with 10923 additions and 0 deletions

12
assets/Media.meta Normal file
View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "fae64031-d2c9-4dfe-b230-aa8b831c487b",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "28f1b0a2-fc2d-4d13-b2a4-1a63eff3374f",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "e0f63227-3d3c-4059-bd11-cc0ca8fe2cf9",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,203 @@
[
{
"__type__": "cc.AnimationClip",
"_name": "WeaponSwing",
"_objFlags": 0,
"__editorExtras__": {
"embeddedPlayerGroups": []
},
"_native": "",
"sample": 60,
"speed": 1,
"wrapMode": 1,
"enableTrsBlending": false,
"_duration": 0.31666666666666665,
"_hash": 500763545,
"_tracks": [
{
"__id__": 1
}
],
"_exoticAnimation": null,
"_events": [],
"_embeddedPlayers": []
},
{
"__type__": "cc.animation.VectorTrack",
"_binding": {
"__type__": "cc.animation.TrackBinding",
"path": {
"__id__": 2
}
},
"_channels": [
{
"__id__": 3
},
{
"__id__": 5
},
{
"__id__": 7
},
{
"__id__": 9
}
],
"_nComponents": 3
},
{
"__type__": "cc.animation.TrackPath",
"_paths": [
"eulerAngles"
]
},
{
"__type__": "cc.animation.Channel",
"_curve": {
"__id__": 4
}
},
{
"__type__": "cc.RealCurve",
"_times": [
0,
0.31666666666666665
],
"_values": [
{
"__type__": "cc.RealKeyframeValue",
"interpolationMode": 0,
"tangentWeightMode": 0,
"value": 0,
"rightTangent": 0,
"rightTangentWeight": 1,
"leftTangent": 0,
"leftTangentWeight": 1,
"easingMethod": 0,
"__editorExtras__": {
"tangentMode": 0
}
},
{
"__type__": "cc.RealKeyframeValue",
"interpolationMode": 0,
"tangentWeightMode": 0,
"value": 0,
"rightTangent": 0,
"rightTangentWeight": 1,
"leftTangent": 0,
"leftTangentWeight": 1,
"easingMethod": 0,
"__editorExtras__": {
"tangentMode": 0
}
}
],
"preExtrapolation": 1,
"postExtrapolation": 1
},
{
"__type__": "cc.animation.Channel",
"_curve": {
"__id__": 6
}
},
{
"__type__": "cc.RealCurve",
"_times": [
0,
0.31666666666666665
],
"_values": [
{
"__type__": "cc.RealKeyframeValue",
"interpolationMode": 0,
"tangentWeightMode": 0,
"value": 0,
"rightTangent": 0,
"rightTangentWeight": 1,
"leftTangent": 0,
"leftTangentWeight": 1,
"easingMethod": 0,
"__editorExtras__": {
"tangentMode": 0
}
},
{
"__type__": "cc.RealKeyframeValue",
"interpolationMode": 0,
"tangentWeightMode": 0,
"value": 0,
"rightTangent": 0,
"rightTangentWeight": 1,
"leftTangent": 0,
"leftTangentWeight": 1,
"easingMethod": 0,
"__editorExtras__": {
"tangentMode": 0
}
}
],
"preExtrapolation": 1,
"postExtrapolation": 1
},
{
"__type__": "cc.animation.Channel",
"_curve": {
"__id__": 8
}
},
{
"__type__": "cc.RealCurve",
"_times": [
0,
0.31666666666666665
],
"_values": [
{
"__type__": "cc.RealKeyframeValue",
"interpolationMode": 0,
"tangentWeightMode": 0,
"value": 0,
"rightTangent": 0,
"rightTangentWeight": 1,
"leftTangent": 0,
"leftTangentWeight": 1,
"easingMethod": 0,
"__editorExtras__": {
"tangentMode": 0
}
},
{
"__type__": "cc.RealKeyframeValue",
"interpolationMode": 0,
"tangentWeightMode": 0,
"value": 90,
"rightTangent": 0,
"rightTangentWeight": 1,
"leftTangent": 0,
"leftTangentWeight": 1,
"easingMethod": 0,
"__editorExtras__": {
"tangentMode": 0
}
}
],
"preExtrapolation": 1,
"postExtrapolation": 1
},
{
"__type__": "cc.animation.Channel",
"_curve": {
"__id__": 10
}
},
{
"__type__": "cc.RealCurve",
"_times": [],
"_values": [],
"preExtrapolation": 1,
"postExtrapolation": 1
}
]

View File

@@ -0,0 +1,13 @@
{
"ver": "2.0.3",
"importer": "animation-clip",
"imported": true,
"uuid": "5022a9c8-7d40-4759-a10c-ce914b4b3fec",
"files": [
".cconb"
],
"subMetas": {},
"userData": {
"name": "WeaponSwing"
}
}

12
assets/Scenes.meta Normal file
View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "633f1a26-e6a5-47bf-a5aa-0d4d35202468",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

1391
assets/Scenes/scene.scene Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
{
"ver": "1.1.40",
"importer": "scene",
"imported": true,
"uuid": "cffa5b19-2043-4cef-8221-1a10ab7a2c1f",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

12
assets/Scripts.meta Normal file
View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "f5d8d5db-417b-40f1-b7d8-86bd1cb1369c",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,20 @@
import { Component, _decorator } from "cc";
import { Player } from "./Player";
import { VirtualJoystic } from "./VirtualJoystic";
const { ccclass, property } = _decorator;
@ccclass("GameBootstrapper")
export class GameBootstrapper extends Component {
@property(VirtualJoystic) private virtualJoystic: VirtualJoystic;
@property(Player) private player: Player;
@property(Number) private strikeDelay = 0;
public start(): void {
this.virtualJoystic.init();
this.player.init(this.virtualJoystic, this.strikeDelay);
}
public update(deltaTime: number): void {
this.player.gameTick(deltaTime);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5faa9913-e167-4014-92de-7061e103e557",
"files": [],
"subMetas": {},
"userData": {}
}

31
assets/Scripts/Player.ts Normal file
View File

@@ -0,0 +1,31 @@
import { Component, Vec2, Vec3, _decorator } from "cc";
import { VirtualJoystic } from "./VirtualJoystic";
import { Weapon } from "./Weapon";
const { ccclass, property } = _decorator;
@ccclass("Player")
export class Player extends Component {
private virtualJoystic: VirtualJoystic;
@property private speed = 0;
@property(Weapon) private weapon: Weapon;
public init(virtualJoystic: VirtualJoystic, strikeDelay: number): void {
this.virtualJoystic = virtualJoystic;
this.weapon.init(strikeDelay);
}
public gameTick(deltaTime: number): void {
const movement: Vec2 = this.virtualJoystic.getAxis();
movement.x *= deltaTime * this.speed;
movement.y *= deltaTime * this.speed;
const newPosition: Vec3 = this.node.worldPosition;
newPosition.x += movement.x;
newPosition.y += movement.y;
this.node.setWorldPosition(newPosition);
this.weapon.gameTick(deltaTime, movement);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b570abb8-1bcd-4ef0-85e8-4d783531001d",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,79 @@
import { _decorator, Component, Node, Vec3, input, Input, EventMouse, Vec2, EventTouch } from "cc";
const { ccclass, property } = _decorator;
@ccclass("VirtualJoystic")
export class VirtualJoystic extends Component {
@property(Number) private maxDistance = 10;
@property(Node) private knob: Node;
#isUsingJoystic = false;
#defaultPosition: Vec2 = new Vec2();
public init(): void {
input.on(Input.EventType.MOUSE_DOWN, this.activateMouseJoystic, this);
input.on(Input.EventType.MOUSE_UP, this.deactivateJoystic, this);
input.on(Input.EventType.MOUSE_MOVE, this.moveKnobMouse, this);
input.on(Input.EventType.TOUCH_START, this.activateTouchJoystic, this);
input.on(Input.EventType.TOUCH_END, this.deactivateJoystic, this);
input.on(Input.EventType.TOUCH_MOVE, this.moveKnobTouch, this);
this.deactivateJoystic();
}
public getAxis(): Vec2 {
if (this.#isUsingJoystic) {
return new Vec2(this.knob.position.x / this.maxDistance, this.knob.position.y / this.maxDistance);
} else {
return new Vec2();
}
}
private activateTouchJoystic(e: EventTouch): void {
this.activateJoystic(e.getUILocation());
}
private activateMouseJoystic(e: EventMouse): void {
this.activateJoystic(e.getUILocation());
}
private activateJoystic(location: Vec2): void {
this.#isUsingJoystic = true;
this.node.active = true;
this.#defaultPosition = location;
this.node.setWorldPosition(new Vec3(this.#defaultPosition.x, this.#defaultPosition.y, 0));
this.knob.position = new Vec3();
}
private deactivateJoystic(): void {
this.#isUsingJoystic = false;
this.node.active = false;
}
private moveKnobTouch(e: EventTouch): void {
this.moveKnob(e.getUILocation());
}
private moveKnobMouse(e: EventMouse): void {
this.moveKnob(e.getUILocation());
}
private moveKnob(location: Vec2): void {
if (!this.#isUsingJoystic) return;
const posDelta: Vec2 = location.subtract(this.#defaultPosition);
let x: number = posDelta.x;
let y: number = posDelta.y;
const length: number = Math.sqrt(posDelta.x ** 2 + posDelta.y ** 2);
if (this.maxDistance < length) {
const multiplier: number = this.maxDistance / length;
x *= multiplier;
y *= multiplier;
}
this.knob.position = new Vec3(x, y, 0);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "a51b28bc-4ef0-4324-97fc-44f964ce087a",
"files": [],
"subMetas": {},
"userData": {}
}

35
assets/Scripts/Weapon.ts Normal file
View File

@@ -0,0 +1,35 @@
import { Animation, BoxCollider2D, Component, Contact2DType, Vec2, Vec3, _decorator } from "cc";
const { ccclass, property } = _decorator;
@ccclass("Weapon")
export class Weapon extends Component {
@property(Animation) private weaponAnimation: Animation;
@property(BoxCollider2D) private weaponCollider: BoxCollider2D;
private strikeDelay: number;
private currentDelay = 0;
public init(strikeDelay: number): void {
this.strikeDelay = strikeDelay;
this.weaponCollider.on(Contact2DType.BEGIN_CONTACT, () => {
console.log("Begin Contact!");
});
}
public gameTick(deltaTime: number, movement: Vec2): void {
this.currentDelay += deltaTime;
if (this.strikeDelay <= this.currentDelay) {
this.currentDelay = 0;
this.strike(movement);
}
}
private strike(movement: Vec2): void {
const direction: Vec2 = movement.normalize();
const angle: number = (Math.atan2(direction.y, direction.x) * 180) / Math.PI;
this.node.eulerAngles = new Vec3(0, 0, angle);
this.weaponAnimation.play("WeaponSwing");
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "2391b8b7-f9fa-42a8-b046-55ff57b07d02",
"files": [],
"subMetas": {},
"userData": {}
}