Commit d1c2985b authored by haiyoucuv's avatar haiyoucuv

init

parent 09c26ebe
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "3e292ad8-0faa-4a0c-ada1-a504d2566351",
"files": [],
"subMetas": {},
"userData": {
"isBundle": true
}
}
This diff is collapsed.
{"ver":"1.1.50","importer":"scene","imported":true,"uuid":"39e51b58-ec32-4016-8c51-4d37d8db5e0f","files":[".json"],"subMetas":{},"userData":{}}
......@@ -7849,7 +7849,7 @@
"__id__": 165
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 212
......
......@@ -77,9 +77,7 @@ export class AISnake extends Snake {
death() {
super.death();
this.node.removeFromParent();
aiPool.put(this.node);
this.node.destroy();
MainGame.ins.initAiSnake(this.nickName, this.tag);
}
......
......@@ -2,9 +2,7 @@
import { ccenum } from "cc";
export const Events = {
changeSkinId: "changeSkinId", // 更换皮肤事件
setGameState: "setGameState", // 设置游戏状态事件
showGOver: "showGOver" // 显示游戏结束界面事件
Death: "Death", // 设置游戏状态事件
};
// 食物类型枚举
......@@ -32,7 +30,6 @@ export enum DirectionType {
export enum GameState {
READY = 0, // 准备状态
PLAY = 1, // 游戏中
PAUSE = 2, // 暂停
OVER = 3, // 游戏结束
}
......
......@@ -23,7 +23,9 @@ export class PreCd extends Component {
}
protected onDestroy() {
PreCd._ins = null;
if (PreCd._ins == this) {
PreCd._ins = null;
}
}
async startCd() {
......
......@@ -15,6 +15,7 @@ export class Rank extends Component {
nodeMap = new Map<number, Node>();
start() {
this.nodeMap.clear();
this.nodeMap.set(MainGame.ins.player.tag, this.selfNode);
this.schedule(() => {
......
......@@ -39,7 +39,9 @@ export class Target extends Component {
}
onDestroy() {
Target._ins = null;
if (Target._ins == this) {
Target._ins = null;
}
}
start() {
......
import {
_decorator,
AssetManager,
assetManager,
Label, lerp,
ProgressBar,
resources,
} from "cc";
import Scene from "../../../Module/Scene";
const { ccclass, property } = _decorator;
@ccclass("GameLoading")
export class GameLoading extends Scene{
static bundle = "GameLoading";
static skin = "GameLoading";
@property(ProgressBar)
progressBar: ProgressBar;
@property(Label)
progressTxt: Label = null;
onLoad() {
}
onDestroy() {
}
setProgress(progress: number) {
this.progressBar.progress = progress;
// this.progressTxt.string = `游戏加载中 ${Math.round(progress * 100)}%`;
}
async start() {
this.setProgress(0.1);
const pkg = [
{
path: "MainGame",
type: "bundle"
},
];
const list = await this.getPreLoadList(pkg);
await this.preload(list, 0.1, 1);
this.data?.callBack();
}
getPreLoadList = async (pkg) => {
const pathArr: {
path: string;
bundle: AssetManager.Bundle;
}[] = [];
const ps = [];
pkg.forEach((asset) => {
if (typeof asset == "string") {
return pathArr.push({
path: asset,
bundle: resources,
});
}
switch (asset.type) {
case "dir":
resources.getDirWithPath(asset.path)
.forEach((v) => {
pathArr.push({
path: v.path,
bundle: resources
});
});
break;
case "bundle":
ps.push(
new Promise<void>((resolve) => {
assetManager.loadBundle(asset.path, (err, bundle) => {
if (err) console.error(err);
bundle.getDirWithPath("").forEach((assets) => {
pathArr.push({
path: assets.path,
bundle: bundle
});
});
resolve();
});
})
);
break;
default:
pathArr.push({
bundle: resources,
path: asset.path
});
}
});
await Promise.all(ps);
return pathArr;
};
preload = async (
pkg: {
path: string;
bundle: AssetManager.Bundle
}[],
from = 0,
to = 1
) => {
const total = pkg.length;
let loaded = 0;
const ps = pkg.map((asset) => {
return new Promise<void>((resolve) => {
asset.bundle.load(asset.path, () => {
loaded++;
const progress = lerp(from, to, loaded / total);
this.setProgress(progress);
resolve();
});
});
});
await Promise.all(ps);
};
}
{"ver":"4.0.24","importer":"typescript","imported":true,"uuid":"908be645-cc0a-4164-b695-a3010328883b","files":[],"subMetas":{},"userData":{}}
......@@ -12,7 +12,7 @@ import {
import { FoodManger } from "./Manager/FoodManger";
import { Global, SkinName } from "./Global";
import { Events, GameState } from "./Common/Enums";
import { showToast } from "../../../Module/UIFast";
import { changeScene, showPanel, showToast } from "../../../Module/UIFast";
import Scene from "../../../Module/Scene";
import { executePreFrame, getItemGenerator } from "../../Utils/ExecutePreFrame";
import { Player } from "./Player";
......@@ -26,6 +26,8 @@ import { Target } from "./Components/Target";
import { PropManager } from "./Manager/PropManager";
import { CardManager } from "./Manager/CardManager";
import { LuckyBagManager } from "./Manager/LuckyBagManager";
import GameFailPanel from "../../Panels/GameFailPanel";
import { GameLoading } from "./GameLoading";
const { ccclass, property } = _decorator;
......@@ -62,7 +64,8 @@ export class MainGame extends Scene {
@property({ type: Label, group: "UI" }) lengthTxt: Label = null;
@property({ type: Label, group: "UI" }) luckyNum: Label = null;
private state: GameState = GameState.READY;
private isStart: boolean = false;
private isOver: boolean = false;
async onLoad() {
......@@ -78,24 +81,69 @@ export class MainGame extends Scene {
.setContentSize(Global.MAP_WIDTH, Global.MAP_HEIGHT);
// 注册事件
director.on(Events.showGOver, this.showGOver, this);
director.on(Events.setGameState, this.setGameState, this);
director.on(Events.Death, this.playerDeath, this);
}
async start() {
await this.initStage();
// 设置游戏状态
this.setGameState(GameState.PLAY);
this.isStart = true;
}
onDestroy() {
MainGame._ins = null;
if (MainGame._ins == this) {
MainGame._ins = null;
}
director.off(Events.Death, this.playerDeath, this);
clearAllPool();
}
playerDeath = async () => {
if (this.isOver) return;
this.isOver = true;
const { currentStage } = gameStore.startInfo;
if (currentStage == 1) {
showPanel(GameFailPanel);
} else if (currentStage == 2) {
} else {
this.gameOver();
}
showToast("你已死亡!");
};
cdOver = async () => {
if (this.isOver) return;
this.isOver = true;
const { currentStage } = gameStore.startInfo;
if (currentStage == 1) {
const submitSuc = await gameStore.submitOne(this.player.length);
const gameSuc = await gameStore.startGame();
if (gameSuc) {
// await changeScene(GameLoading, {
// callBack: async () => {
await changeScene(MainGame);
// }
// });
}
} else if (currentStage == 2) {
} else {
}
};
gameOver() {
}
@render
render() {
const {length, killNum, luckNum} = gameStore.gameInfo || {};
......@@ -111,6 +159,7 @@ export class MainGame extends Scene {
// 初始化玩家
this.player.init({
// initEnergy: 10000
tag: this.player.tag,
nickName: "我",
skinName: SkinName.sp_skin_snake_year,
});
......@@ -137,20 +186,20 @@ export class MainGame extends Scene {
Target.ins.totalCd = Target.ins.cd = 60;
await Target.ins.showBanner2();
await PreCd.ins.startCd();
Target.ins.startCd(60);
Target.ins.startCd(60, this.cdOver);
} else if (currentStage == 1) {
Target.ins.totalCd = Target.ins.cd = 10;
await Target.ins.showBanner1();
await PreCd.ins.startCd();
Target.ins.startCd(10);
Target.ins.startCd(10, this.cdOver);
}
}
update(dt: number) {
if (this.state == GameState.READY) return;
if (!this.isStart) return;
this.player.onUpdate(dt);
......@@ -163,30 +212,11 @@ export class MainGame extends Scene {
});
}
setGameState(state: GameState) {
this.state = Number(state);
switch (this.state) {
case GameState.READY:
break;
case GameState.PLAY:
break;
case GameState.OVER:
this.showGOver();
showToast("你已死亡!");
break;
default:
console.log("err");
}
}
initAiSnake(nickName?: string, tag?: number) {
const node = instantiate(this.animalPrefab);
showGOver() {
console.log("showGOver", this.player.getSnakeLen());
}
const { x, y } = Global.getRandomPosition(100);
initAiSnake(nickName?: string, tag?: number) {
const node = aiPool.get() || instantiate(this.animalPrefab);
const x = math.randomRange(-(Global.MAP_WIDTH / 2 - 50), Global.MAP_WIDTH / 2 - 50);
const y = math.randomRange(-(Global.MAP_HEIGHT / 2 - 50), Global.MAP_HEIGHT / 2 - 50);
node.getComponent(AISnake)?.init({
nickName: nickName,
tag: tag,
......@@ -204,6 +234,7 @@ export class MainGame extends Scene {
const nickArr = useNick(count);
const initItem = (index: number) => {
if (!this.isValid) return;
this.initAiSnake(nickArr[index]);
};
......
......@@ -20,7 +20,9 @@ export class CardManager extends ItemMgrBase {
}
onDestroy() {
CardManager._ins = null;
if (CardManager._ins == this) {
CardManager._ins = null;
}
}
}
......@@ -31,7 +31,9 @@ export class FoodManger extends Component {
}
onDestroy() {
FoodManger._ins = null;
if (FoodManger._ins == this) {
FoodManger._ins = null;
}
}
......
......@@ -29,7 +29,9 @@ export class LuckyBagManager extends Component {
}
onDestroy() {
LuckyBagManager._ins = null;
if (LuckyBagManager._ins == this) {
LuckyBagManager._ins = null;
}
}
@property(Prefab)
......
......@@ -22,7 +22,9 @@ export class PropManager extends ItemMgrBase {
}
onDestroy() {
PropManager._ins = null;
if (PropManager._ins == this) {
PropManager._ins = null;
}
}
}
......@@ -32,7 +32,6 @@ export class Player extends Snake {
this.camera.orthoHeight = lerp(275, 612, value);
}
get length() {
return gameStore.gameInfo.length;
}
......@@ -52,6 +51,7 @@ export class Player extends Snake {
onLoad() {
super.onLoad();
this.tag = Snake.getTag();
input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
input.on(Input.EventType.KEY_UP, this.onKeyUp, this);
this.fastBtn.node.on("fast", this.onFast, this);
......@@ -76,7 +76,7 @@ export class Player extends Snake {
this.length = 0;
// 发送游戏结束事件
director.emit(Events.setGameState, GameState.OVER);
director.emit(Events.Death);
}
keyArr: number[] = [];
......
......@@ -93,16 +93,28 @@ export class Snake extends Component {
set length(value: number) {
this._length = value;
this.node.emit("updateLength", value);
this?.node?.emit("updateLength", value);
}
get radius() {
return this.scale * 29;
}
onLoad() {
}
onDestroy() {
}
// 初始化方法
public async init(config: IInitConfig) {
this.bodyArr.forEach((body) => {
body.removeFromParent();
bodyPool.put(body);
});
const {
nickName,
x = 0, y = 0, angle = 0, scale = 0.5,
......@@ -250,6 +262,8 @@ export class Snake extends Component {
// 蛇身体生长
private grow() {
if (!this.isValid) return;
this.length += 1;
let len = this.bodyArr.length;
......@@ -390,10 +404,16 @@ export class Snake extends Component {
if (!this.isLife) return;
this.isLife = false;
this.node.active = false;
this.node.removeFromParent();
this.cardMap.clear();
this.clearInvincible();
const foodArr = this.recycleBody();
FoodManger.ins.initFoods(foodArr);
}
recycleBody() {
const len = this.bodyArr.length;
const foodArr = this.bodyArr.map((body) => {
body.removeFromParent();
......@@ -405,8 +425,8 @@ export class Snake extends Component {
energy: ~~(this.energy / len),
};
});
FoodManger.ins.initFoods(foodArr);
this.bodyArr.length = 0;
return foodArr;
}
protected getNewPos(angle: number, dt: number, currentPos: Vec3): IVec2Like {
......@@ -439,9 +459,6 @@ export class Snake extends Component {
this._invincibleTime = 0;
}
onLoad() {
}
}
\ No newline at end of file
......@@ -184,7 +184,7 @@
"_priority": 65535,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 835.0173228346456,
"_orthoHeight": 647.4188034188035,
"_near": 1,
"_far": 2000,
"_color": {
......
......@@ -24,7 +24,7 @@ const { ccclass, property } = _decorator;
const _FPS = 61;
@ccclass("Start")
export class Start extends Component {
export class Start extends Component{
@property(Prefab)
uiPrefab: Prefab;
......
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "5a166f1b-96fa-41ae-b030-170f446922f5",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "5a166f1b-96fa-41ae-b030-170f446922f5@6c48a",
"displayName": "loadingBar",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "5a166f1b-96fa-41ae-b030-170f446922f5",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "5a166f1b-96fa-41ae-b030-170f446922f5@f9941",
"displayName": "loadingBar",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 640,
"height": 47,
"rawWidth": 640,
"rawHeight": 47,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-320,
-23.5,
0,
320,
-23.5,
0,
-320,
23.5,
0,
320,
23.5,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
47,
640,
47,
0,
0,
640,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-320,
-23.5,
0
],
"maxPos": [
320,
23.5,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "5a166f1b-96fa-41ae-b030-170f446922f5@6c48a",
"atlasUuid": ""
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"hasAlpha": true,
"fixAlphaTransparencyArtifacts": false,
"redirect": "5a166f1b-96fa-41ae-b030-170f446922f5@6c48a"
}
}
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "2cf82299-125d-4874-a996-83c5c3e3f142",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "2cf82299-125d-4874-a996-83c5c3e3f142@6c48a",
"displayName": "loadingEffect",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "2cf82299-125d-4874-a996-83c5c3e3f142",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "2cf82299-125d-4874-a996-83c5c3e3f142@f9941",
"displayName": "loadingEffect",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 99,
"height": 99,
"rawWidth": 99,
"rawHeight": 99,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-49.5,
-49.5,
0,
49.5,
-49.5,
0,
-49.5,
49.5,
0,
49.5,
49.5,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
99,
99,
99,
0,
0,
99,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-49.5,
-49.5,
0
],
"maxPos": [
49.5,
49.5,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "2cf82299-125d-4874-a996-83c5c3e3f142@6c48a",
"atlasUuid": ""
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"hasAlpha": true,
"fixAlphaTransparencyArtifacts": false,
"redirect": "2cf82299-125d-4874-a996-83c5c3e3f142@6c48a"
}
}
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "ff1c8d83-5e65-4e47-b85e-334eded02be1",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "ff1c8d83-5e65-4e47-b85e-334eded02be1@6c48a",
"displayName": "loadingFill",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "ff1c8d83-5e65-4e47-b85e-334eded02be1",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "ff1c8d83-5e65-4e47-b85e-334eded02be1@f9941",
"displayName": "loadingFill",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 634,
"height": 41,
"rawWidth": 634,
"rawHeight": 41,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-317,
-20.5,
0,
317,
-20.5,
0,
-317,
20.5,
0,
317,
20.5,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
41,
634,
41,
0,
0,
634,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-317,
-20.5,
0
],
"maxPos": [
317,
20.5,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "ff1c8d83-5e65-4e47-b85e-334eded02be1@6c48a",
"atlasUuid": ""
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"hasAlpha": true,
"fixAlphaTransparencyArtifacts": false,
"redirect": "ff1c8d83-5e65-4e47-b85e-334eded02be1@6c48a"
}
}
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "547630f4-a0e0-4134-8427-9c3c53863e68",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "547630f4-a0e0-4134-8427-9c3c53863e68@6c48a",
"displayName": "图片底",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "547630f4-a0e0-4134-8427-9c3c53863e68",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "547630f4-a0e0-4134-8427-9c3c53863e68@f9941",
"displayName": "图片底",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 220,
"height": 220,
"rawWidth": 220,
"rawHeight": 220,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-110,
-110,
0,
110,
-110,
0,
-110,
110,
0,
110,
110,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
220,
220,
220,
0,
0,
220,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-110,
-110,
0
],
"maxPos": [
110,
110,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "547630f4-a0e0-4134-8427-9c3c53863e68@6c48a",
"atlasUuid": ""
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"hasAlpha": true,
"fixAlphaTransparencyArtifacts": false,
"redirect": "547630f4-a0e0-4134-8427-9c3c53863e68@6c48a"
}
}
{
"success": true,
"code": "",
"message": "",
"data": {}
}
\ No newline at end of file
{
"success": true,
"code": "",
"message": "",
"data": {}
}
\ No newline at end of file
{
"__version__": "3.0.5",
"__version__": "3.0.7",
"game": {
"name": "未知游戏",
"app_id": "UNKNOW",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment