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

10
.eslintrc.json Normal file
View File

@ -0,0 +1,10 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"rules": {
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/explicit-member-accessibility": "warn"
}
}

25
.gitignore vendored Normal file
View File

@ -0,0 +1,25 @@
#///////////////////////////
# Cocos Creator 3D Project
#///////////////////////////
.creator
library/
temp/
local/
build/
profiles/
native
#//////////////////////////
# NPM
#//////////////////////////
node_modules/
#//////////////////////////
# VSCode
#//////////////////////////
.vscode/
#//////////////////////////
# WebStorm
#//////////////////////////
.idea/

7
.prettierrc.json Normal file
View File

@ -0,0 +1,7 @@
{
"printWidth": 150,
"singleQuote": false,
"tabWidth": 4,
"trailingComma": "none",
"endOfLine": "auto"
}

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": {}
}

5
jest.config.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = {
verbose: true,
preset: "ts-jest",
testEnvironment: "node"
};

8770
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

26
package.json Normal file
View File

@ -0,0 +1,26 @@
{
"name": "VampSu",
"uuid": "44d41970-47e0-4ec4-84a9-e2884a9f7957",
"version": "3.6.1",
"creator": {
"version": "3.6.1"
},
"scripts": {
"prettier-format": "prettier --config .prettierrc.json assets/Scripts/*.ts --write",
"test": "jest"
},
"dependencies": {
"eslint": "^8.25.0",
"jest": "^29.2.2",
"ts-jest": "^29.0.3"
},
"devDependencies": {
"@types/node": "^18.11.6",
"@types/jest": "^29.2.0",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.10",
"prettier": "^2.7.1"
}
}

View File

@ -0,0 +1,22 @@
{
"game": {
"name": "UNKNOW GAME",
"app_id": "UNKNOW",
"c_id": "0"
},
"appConfigMaps": [
{
"app_id": "UNKNOW",
"config_id": "e32858"
}
],
"configs": [
{
"app_id": "UNKNOW",
"config_id": "e32858",
"config_name": "Default",
"config_remarks": "",
"services": []
}
]
}

View File

@ -0,0 +1,144 @@
{
"__version__": "1.0.6",
"modules": {
"cache": {
"base": {
"_value": true
},
"graphcis": {
"_value": true
},
"gfx-webgl": {
"_value": true
},
"gfx-webgl2": {
"_value": true
},
"animation": {
"_value": true
},
"skeletal-animation": {
"_value": true
},
"3d": {
"_value": false
},
"2d": {
"_value": true
},
"xr": {
"_value": true
},
"ui": {
"_value": true
},
"particle": {
"_value": false
},
"physics": {
"_value": false,
"_option": "physics-ammo"
},
"physics-ammo": {
"_value": false
},
"physics-cannon": {
"_value": false
},
"physics-physx": {
"_value": false
},
"physics-builtin": {
"_value": false
},
"physics-2d": {
"_value": true,
"_option": "physics-2d-builtin"
},
"physics-2d-box2d": {
"_value": false
},
"physics-2d-builtin": {
"_value": false
},
"intersection-2d": {
"_value": true
},
"primitive": {
"_value": false
},
"profiler": {
"_value": true
},
"occlusion-query": {
"_value": false
},
"geometry-renderer": {
"_value": false
},
"debug-renderer": {
"_value": false
},
"particle-2d": {
"_value": true
},
"audio": {
"_value": true
},
"video": {
"_value": true
},
"webview": {
"_value": true
},
"tween": {
"_value": true
},
"terrain": {
"_value": false
},
"tiled-map": {
"_value": true
},
"spine": {
"_value": true
},
"dragon-bones": {
"_value": true
},
"marionette": {
"_value": true
},
"custom-pipeline": {
"_value": false
}
},
"includeModules": [
"2d",
"animation",
"audio",
"base",
"dragon-bones",
"gfx-webgl",
"gfx-webgl2",
"intersection-2d",
"marionette",
"particle-2d",
"physics-2d-builtin",
"profiler",
"skeletal-animation",
"spine",
"tiled-map",
"tween",
"ui",
"video",
"webview",
"xr"
],
"noDeprecatedFeatures": {
"value": false,
"version": ""
},
"flags": {}
}
}

13
tests/virt.test.ts Normal file
View File

@ -0,0 +1,13 @@
test("try ", () => {
const x = 200;
const y = -100;
const atan = Math.atan(Math.abs(y) / Math.abs(x));
console.log(Math.sin(atan) * y);
console.log(Math.cos(atan) * x);
expect(true).toBeTruthy();
});
export {};

9
tests/virt.test.ts.meta Normal file
View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "62fcbd59-7ce1-4582-91c1-e502763b791b",
"files": [],
"subMetas": {},
"userData": {}
}

13
tsconfig.json Normal file
View File

@ -0,0 +1,13 @@
{
/* Base configuration. Do not edit this field. */
"extends": "./temp/tsconfig.cocos.json",
/* Add your custom configuration here. */
"compilerOptions": {
"target": "ES2015",
"module": "CommonJS",
"allowSyntheticDefaultImports": true,
"types": ["jest", "node"],
"strictNullChecks": false
}
}