更新代码

This commit is contained in:
Leo
2022-01-11 21:50:28 +08:00
parent 1fb74bf28f
commit 204075a272
17 changed files with 32723 additions and 39 deletions

View File

@@ -0,0 +1,113 @@
import { _decorator, Component, Node, Vec2, v2, CCObject } from 'cc';
import { Movement } from './Movement';
const { ccclass, property } = _decorator;
export enum PathType {
line,
circle
}
export class Path {
}
export class PathInfo {
type: PathType
/**速度 */
speed: number;
/**半径 */
radius: number;
/**中心点 */
center: Vec2;
// startAngle: number;
/**角度 */
angle: number;
/**长度 */
distance: number
/**起点 */
startPos: Vec2;
}
@ccclass('MovePath')
export class MovePath extends Component {
@property({
type: Movement,
displayName: "移动组件"
})
private movement: Movement = null;
private pathList: PathInfo[] = [];
private curPath: PathInfo = null;
private curDistance: number;
private curIndex: number = 0;
start() {
let p1 = new PathInfo();
p1.type = PathType.line;
p1.speed = 50;
p1.angle = -Math.PI / 2;
p1.startPos = v2(200, 200);
p1.distance = 400;
this.pathList.push(p1);
p1 = new PathInfo();
p1.type = PathType.line;
p1.speed = 50;
p1.angle = Math.PI
p1.startPos = v2(200, -200);
p1.distance = 400;
this.pathList.push(p1);
p1 = new PathInfo();
p1.type = PathType.line;
p1.speed = 50;
p1.angle = Math.PI / 2
p1.startPos = v2(-200, -200);
p1.distance = 400;
this.pathList.push(p1);
p1 = new PathInfo();
p1.type = PathType.line;
p1.speed = 50;
p1.angle = 0;
p1.startPos = v2(-200, 200);
p1.distance = 400;
this.pathList.push(p1);
this.curPath = this.getPathInfo();
}
addIndex() {
this.curIndex++;
}
getPathInfo() {
return this.pathList[this.curIndex];
}
initMovement() {
this.movement.angle = this.curPath.angle;
this.movement.speed = this.curPath.speed;
this.movement.radius = this.curPath.radius;
this.movement.center = this.curPath.center;
}
update(deltaTime: number) {
if (null != this.curPath) {
this.curDistance < this.curPath.distance;
}
}
}
/**
* [1] Class member could be defined like this.
* [2] Use `property` decorator if your want the member to be serializable.
* [3] Your initialization goes here.
* [4] Your update function goes here.
*
* Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
* Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/ccclass.html
* Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
*/

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "6535b322-d44e-41a8-99bd-cfc0e6469cc2",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -2,43 +2,43 @@
import { _decorator, Component, Node, Vec3, Enum, CCObject, Vec2, v2 } from 'cc';
const { ccclass, property } = _decorator;
export enum MovementState {
idle,
run,
stop,
}
@ccclass('Movement')
export class Movement extends Component {
@property({ displayName: "运动速度" })
/**运动速度 */
speed = 0;
@property({ displayName: "运动角速度" })
angleSpeed = 0;
@property({ displayName: "运动半径" })
/**运动半径 */
radius = 0;
@property({ displayName: "运动角度(单位为弧度)" })
/**运动角度(单位为弧度) */
angle = 0;
@property({ displayName: "运动加速度" })
accelerate = 1;
@property({ type: Enum(MovementState), displayName: "运动状态" })
state: MovementState = MovementState.idle;
/**圆周运动中心点 */
center: Vec2 = new Vec2();
start() {
// this.state=MovementState.run;
/**
* 距离增量
* @param time
* @returns
*/
deltaDistance(time: number) {
return this.speed * time;
}
move(r, angle) {
let x = r * Math.cos(angle);
let y = r * Math.sin(angle);
this.node.translate(new Vec3(x, y));
/**
* 角度增量
* @param time
* @returns
*/
deltaAngle(time: number) {
let distance = this.deltaDistance(time);
return distance / this.radius;
}
/**
* 圆周运动
* @param dt
* @param center
*/
circle(dt: number, center: Vec2 = v2(0, 0)) {
let delta = this.angleSpeed * dt;
let delta = this.deltaAngle(dt);
this.angle += delta;
if (this.angle > Math.PI * 2) {
this.angle -= Math.PI * 2;
@@ -48,8 +48,12 @@ export class Movement extends Component {
this.node.position = new Vec3(x, y, this.node.position.z);
}
/**
* 直线运动
* @param dt
*/
line(dt: number) {
let r = this.speed * dt;
let r = this.deltaDistance(dt);
let x = r * Math.cos(this.angle);
let y = r * Math.sin(this.angle);
let pos = this.node.position;
@@ -57,14 +61,3 @@ export class Movement extends Component {
this.node.position = pos;
}
}
/**
* [1] Class member could be defined like this.
* [2] Use `property` decorator if your want the member to be serializable.
* [3] Your initialization goes here.
* [4] Your update function goes here.
*
* Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
* Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/ccclass.html
* Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
*/

View File

@@ -21,8 +21,14 @@ export class Rule extends Component {
@property({ type: Movement, displayName: "移动组件" })
moveComponent: Movement = null;
onLoad() {
this.moveComponent.speed = 50;
this.moveComponent.radius = 100;
}
start() {
// [3]
}
onEnable() {
@@ -57,7 +63,7 @@ export class Rule extends Component {
}
update(deltaTime: number) {
// this.moveCircel(deltaTime);
this.moveCircel(deltaTime);
// this.moveComponent.line(deltaTime);
}
}

53
npmPlugin/.gitignore vendored Normal file
View File

@@ -0,0 +1,53 @@
#/////////////////////////////////////////////////////////////////////////////
# Fireball Projects
#/////////////////////////////////////////////////////////////////////////////
/library/
/temp/
/local/
/build/
native
#/////////////////////////////////////////////////////////////////////////////
# npm files
#/////////////////////////////////////////////////////////////////////////////
npm-debug.log
node_modules/
#/////////////////////////////////////////////////////////////////////////////
# Logs and databases
#/////////////////////////////////////////////////////////////////////////////
*.log
*.sql
*.sqlite
#/////////////////////////////////////////////////////////////////////////////
# files for debugger
#/////////////////////////////////////////////////////////////////////////////
*.sln
*.csproj
*.pidb
*.unityproj
*.suo
#/////////////////////////////////////////////////////////////////////////////
# OS generated files
#/////////////////////////////////////////////////////////////////////////////
.DS_Store
ehthumbs.db
Thumbs.db
#/////////////////////////////////////////////////////////////////////////////
# WebStorm files
#/////////////////////////////////////////////////////////////////////////////
.idea/
#//////////////////////////
# VS Code files
#//////////////////////////
.vscode/

23
npmPlugin/README.md Normal file
View File

@@ -0,0 +1,23 @@
# 使用Npm库
## 常用库
* crypto-js
* zlib
## 步骤
### 下载库到工程目录中
在工程目录打开終端
~~~
npm install crypto-js
~~~
### 代码中使用
通过编辑器新建js脚本
~~~
const SHA1 = require('crypto-js').SHA1;
~~~

287
npmPlugin/assets/Game.fire Normal file
View File

@@ -0,0 +1,287 @@
[
{
"__type__": "cc.SceneAsset",
"_name": "",
"_objFlags": 0,
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_is3DNode": true,
"_groupIndex": 0,
"groupIndex": 0,
"autoReleaseAssets": false,
"_id": "71e6b85c-3502-4597-bdf3-99dc67169745"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
}
],
"_active": true,
"_components": [
{
"__id__": 5
},
{
"__id__": 6
},
{
"__id__": 7
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
480,
320,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "a5esZu+45LA5mBpvttspPD"
},
{
"__type__": "cc.Node",
"_name": "Main Camera",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "e1WoFrQ79G7r4ZuQE3HlNb"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 3
},
"_enabled": true,
"_cullingMask": 4294967295,
"_clearFlags": 7,
"_backgroundColor": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": -1,
"_zoomRatio": 1,
"_targetTexture": null,
"_fov": 60,
"_orthoSize": 10,
"_nearClip": 1,
"_farClip": 4096,
"_ortho": true,
"_rect": {
"__type__": "cc.Rect",
"x": 0,
"y": 0,
"width": 1,
"height": 1
},
"_renderStages": 1,
"_alignWithScreen": true,
"_id": "81GN3uXINKVLeW4+iKSlim"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width": 960,
"height": 640
},
"_fitWidth": false,
"_fitHeight": true,
"_id": "59Cd0ovbdF4byw5sbjJDx7"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_id": "29zXboiXFBKoIV4PQ2liTe"
},
{
"__type__": "17c42o0HGBBZaR33B2wvW8a",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_id": "a7jbclT/pCLbuKJ04Ax+TP"
}
]

View File

@@ -0,0 +1,7 @@
{
"ver": "1.2.9",
"uuid": "71e6b85c-3502-4597-bdf3-99dc67169745",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}

View File

@@ -0,0 +1,46 @@
// Learn cc.Class:
// - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const SHA1 = require('crypto-js').SHA1;
const zlib = require('zlib');
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// // ATTRIBUTES:
// default: null, // The default value will be used only when the component attaching
// // to a node for the first time
// type: cc.SpriteFrame, // optional, default is typeof default
// serializable: true, // optional, default is true
// },
// bar: {
// get () {
// return this._bar;
// },
// set (value) {
// this._bar = value;
// }
// },
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start() {
let str = SHA1("aaaaaa").toString(); // 计算SHA1值并返回字符串内容
console.log('str=', str);
const content = JSON.stringify({ a: 1, b: "1" });
let result = zlib.gzipSync(content);
},
// update (dt) {},
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.8",
"uuid": "17c42a34-1c60-4165-a477-dc1db0bd6f1a",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

32073
npmPlugin/creator.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

15
npmPlugin/jsconfig.json Normal file
View File

@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"experimentalDecorators": true
},
"exclude": [
"node_modules",
".vscode",
"library",
"local",
"settings",
"temp"
]
}

16
npmPlugin/package-lock.json generated Normal file
View File

@@ -0,0 +1,16 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"crypto-js": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz",
"integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw=="
},
"zlib": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/zlib/-/zlib-1.0.5.tgz",
"integrity": "sha1-bnyXL8NxxkWmr7A6sUdp3vEU/MA="
}
}
}

8
npmPlugin/project.json Normal file
View File

@@ -0,0 +1,8 @@
{
"engine": "cocos-creator-js",
"packages": "packages",
"name": "npmPlugin",
"id": "a5d78104-575f-45ec-9f34-1650d99e24e6",
"version": "2.4.5",
"isNew": false
}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,6 @@
{
"game": {
"name": "未知游戏",
"appid": "UNKNOW"
}
}

19
npmPlugin/tsconfig.json Normal file
View File

@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [ "es2015", "es2017", "dom" ],
"target": "es5",
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "temp/vscode-dist",
"forceConsistentCasingInFileNames": true
},
"exclude": [
"node_modules",
"library",
"local",
"temp",
"build",
"settings"
]
}