Commit 233ea1d7 authored by haiyoucuv's avatar haiyoucuv

init

parent accfd0ff
This diff is collapsed.
[
{
"__type__": "cc.Prefab",
"_name": "福袋",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "福袋",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
},
{
"__id__": 10
}
],
"_active": true,
"_components": [
{
"__id__": 16
},
{
"__id__": 18
},
{
"__id__": 20
},
{
"__id__": 22
}
],
"_prefab": {
"__id__": 24
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "光",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
},
{
"__id__": 5
},
{
"__id__": 7
}
],
"_prefab": {
"__id__": 9
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": {
"__id__": 4
},
"_contentSize": {
"__type__": "cc.Size",
"width": 192,
"height": 191
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "66StAJqXFCaJ2ej3HlfBoS"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": {
"__id__": 6
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_spriteFrame": {
"__uuid__": "91e706a3-2b72-4aae-9409-b4ae87570f9f@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0,
"_fillType": 0,
"_sizeMode": 1,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_useGrayscale": false,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "90C/3naUdLTpUo0dap3pqi"
},
{
"__type__": "cc.Animation",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": {
"__id__": 8
},
"playOnLoad": true,
"_clips": [
{
"__uuid__": "e25622d3-ea85-4e16-8e94-1f1a839fbe1b",
"__expectedType__": "cc.AnimationClip"
}
],
"_defaultClip": {
"__uuid__": "e25622d3-ea85-4e16-8e94-1f1a839fbe1b",
"__expectedType__": "cc.AnimationClip"
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "41IFKRClFAq4STk7UDKwB9"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "64wwZ9uZZBB5gCQrFUdt98",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_name": "图",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 11
},
{
"__id__": 13
}
],
"_prefab": {
"__id__": 15
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
},
"_enabled": true,
"__prefab": {
"__id__": 12
},
"_contentSize": {
"__type__": "cc.Size",
"width": 61,
"height": 59
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "5e6yk1hnhLtZvIiPTH+S/y"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
},
"_enabled": true,
"__prefab": {
"__id__": 14
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_spriteFrame": {
"__uuid__": "986f5ef8-b353-4dd9-90bd-ed5b536ee6a2@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0,
"_fillType": 0,
"_sizeMode": 1,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_useGrayscale": false,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "87+475Oh1E5JZyBvCWovfH"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "b5udWGGdZFkr37lglnfJcy",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 17
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "bdBolABn1LK44IChBt7j2O"
},
{
"__type__": "cc.RigidBody2D",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 19
},
"enabledContactListener": true,
"bullet": false,
"awakeOnLoad": true,
"_group": 4,
"_type": 2,
"_allowSleep": true,
"_gravityScale": 1,
"_linearDamping": 0,
"_angularDamping": 0,
"_linearVelocity": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_angularVelocity": 0,
"_fixedRotation": false,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "6cxO6EcOZGIY2Mutu8PTpJ"
},
{
"__type__": "cc.CircleCollider2D",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 21
},
"tag": 0,
"_group": 4,
"_density": 1,
"_sensor": true,
"_friction": 0.2,
"_restitution": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_radius": 30,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "d4nguP1hRPj6hmP9ugayLT"
},
{
"__type__": "5da8aSqHYxAvaSUEz+0fvlM",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 23
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "3e5kK27VpPMblCs9d+jIA3"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "95QVeGhHxFHYdTtrbtkAQN",
"targetOverrides": null
}
]
\ No newline at end of file
{
"ver": "1.1.50",
"importer": "prefab",
"imported": true,
"uuid": "082dafb6-e18d-4d23-bfac-18b09cac9bc4",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "福袋"
}
}
......@@ -4,6 +4,7 @@ import { AIBehaviorParams } from "./AIBehaviorParams";
import { AISnake } from "../AISnake";
import { MainGame } from "../MainGame";
import { Global } from "../Global";
import { FoodManger } from "../Manager/FoodManger";
const { ccclass, property } = _decorator;
......@@ -100,7 +101,7 @@ export class AIPerception {
private findOptimalFood(situation: any): Vec3 | null {
const foods = MainGame.ins.fondManger.node.children;
const foods = FoodManger.ins.node.children;
let bestFood = null;
let bestScore = -Infinity;
const myPos = this.snake.head.getPosition();
......
......@@ -4,6 +4,7 @@ import { DirectionType } from "./Common/Enums";
import { Global } from "./Global";
import { MainGame } from "./MainGame";
import { aiPool } from "./Manager/CommonPool";
import { FoodManger } from "./Manager/FoodManger";
const { ccclass, property } = _decorator;
......@@ -792,7 +793,7 @@ export class AISnake extends Snake {
let nearestFood = null;
let minDistance = this.difficultyParams.viewDistance;
const foods = MainGame.ins.fondManger.node.children;
const foods = FoodManger.ins.node.children;
const boundaryBuffer = this.ESCAPE_BOUNDARY;
const mapWidth = Global.MAP_WIDTH;
const mapHeight = Global.MAP_HEIGHT;
......
......@@ -4,6 +4,7 @@ import { DirectionType } from "./Common/Enums";
import { Global } from "./Global";
import { MainGame } from "./MainGame";
import { aiPool } from "./Manager/CommonPool";
import { FoodManger } from "./Manager/FoodManger";
const { ccclass, property } = _decorator;
......@@ -796,7 +797,7 @@ export class AISnake extends Snake {
let nearestFood = null;
let minDistance = this.difficultyParams.viewDistance;
const foods = MainGame.ins.fondManger.node.children;
const foods = FoodManger.ins.node.children;
const boundaryBuffer = this.ESCAPE_BOUNDARY;
const mapWidth = Global.MAP_WIDTH;
const mapHeight = Global.MAP_HEIGHT;
......
......@@ -8,12 +8,12 @@ export const Events = {
};
// 食物类型枚举
export enum FoodType {
export enum EPropType {
FOOD = 0, // 普通食物
LUCK_BAG = 1 // 福袋
}
ccenum(FoodType);
ccenum(EPropType);
// 移动方向枚举
export enum DirectionType {
......
import { _decorator, Component, Graphics, math, misc, Node } from "cc";
import { _decorator, Component, Graphics, Label, math, misc, Node } from "cc";
const { ccclass, property, executeInEditMode } = _decorator;
......@@ -8,6 +8,10 @@ export class Target extends Component {
@property(Graphics) graphics: Graphics = null;
@property(Label) cdTxt: Label = null;
@property(Label) goalTxt: Label = null;
start() {
// this.graphics.clear();
// this.graphics.moveTo(120, 0);
......@@ -30,10 +34,7 @@ export class Target extends Component {
51,
];
const totalLength = phases.reduce((a, b, i) => {
phases[i] = a + b;
return phases[i];
}, 0);
const totalLength = phases.reduce((a, b, i) => a + b, 0);
// Tip: 注意此时phases的结果
......
......@@ -56,8 +56,6 @@ export class MainGame extends Scene {
@property(Player) player: Player = null;
@property(FoodManger) fondManger: FoodManger = null;
@property(Node) animalNode: Node = null;
@property(Camera) camera: Camera = null;
......@@ -94,7 +92,7 @@ export class MainGame extends Scene {
});
// 初始化食物和NPC
this.fondManger.init(this.maxFood);
FoodManger.ins.init(this.maxFood);
// this.fondManger.init(2000);
this.initAnimal(this.maxAnimal);
// this.initAnimal(1);
......@@ -118,7 +116,7 @@ export class MainGame extends Scene {
this.lengthTxt.string = `${length}`;
this.killTxt.string = `${killNum}名`;
this.luckyNum.string = ${luckNum}`;
this.luckyNum.string = ${luckNum + gameStore.startInfo?.accumulateLuckNum || 0}`;
}
......
......@@ -8,7 +8,7 @@ import {
Prefab,
instantiate, Vec2
} from "cc";
import { FoodType } from "db://assets/Scripts/Scenes/MainGame/Common/Enums";
import { EPropType } from "db://assets/Scripts/Scenes/MainGame/Common/Enums";
import { Global } from "db://assets/Scripts/Scenes/MainGame/Global";
import { executePreFrame, getItemGenerator } from "db://assets/Scripts/Utils/ExecutePreFrame";
import { Food } from "../Props/Food";
......@@ -22,6 +22,11 @@ const { ccclass, property } = _decorator;
@ccclass("FoodManger")
export class FoodManger extends Component {
private static _ins: FoodManger = null;
static get ins() {
return this._ins;
}
@property({ type: [SpriteFrame] })
private foods: SpriteFrame[] = [];
......@@ -31,6 +36,11 @@ export class FoodManger extends Component {
maxFood: number = 100;
onLoad() {
FoodManger._ins = this;
}
onDestroy() {
FoodManger._ins = null;
}
/**
......@@ -63,13 +73,16 @@ export class FoodManger extends Component {
*/
addFood(x?: number, y?: number, energy: number = 1) {
const maxW = Global.MAP_HEIGHT / 2 - 100;
const maxH = Global.MAP_HEIGHT / 2 - 100;
// 如果没有指定位置,随机生成位置
if (!x) {
x = math.randomRangeInt(-(Global.MAP_WIDTH / 2 - 50), Global.MAP_WIDTH / 2 - 50);
x = math.randomRange(-maxW, maxW);
}
if (!y) {
y = math.randomRangeInt(-(Global.MAP_HEIGHT / 2 - 50), Global.MAP_HEIGHT / 2 - 50);
y = math.randomRange(-maxH, maxH);
}
const food = foodPool.get() || instantiate(this.foodPrefab);
......@@ -87,7 +100,7 @@ export class FoodManger extends Component {
// 设置碰撞类型
const collider = food.getComponent(Collider2D);
if (collider) {
collider.tag = FoodType.FOOD;
collider.tag = EPropType.FOOD;
}
food.active = true;
......@@ -97,11 +110,7 @@ export class FoodManger extends Component {
* 初始化单个食物
*/
initItem = (_: number) => {
// 随机生成位置
const x = math.randomRangeInt(-(Global.MAP_WIDTH / 2 - 50), Global.MAP_WIDTH / 2 - 50);
const y = math.randomRangeInt(-(Global.MAP_HEIGHT / 2 - 50), Global.MAP_HEIGHT / 2 - 50);
this.addFood(x, y);
this.addFood();
};
async initFoods(infoArr: { x: number, y: number, energy: number }[]) {
......
......@@ -6,9 +6,9 @@ import {
Prefab,
instantiate,
} from "cc";
import { FoodType } from "db://assets/Scripts/Scenes/MainGame/Common/Enums";
import { EPropType } from "db://assets/Scripts/Scenes/MainGame/Common/Enums";
import { Global } from "db://assets/Scripts/Scenes/MainGame/Global";
import { executePreFrame, getItemGenerator } from "db://assets/Scripts/Utils/ExecutePreFrame";
import gameStore from "../../../store/gameStore";
const { ccclass, property } = _decorator;
......@@ -18,61 +18,55 @@ const { ccclass, property } = _decorator;
@ccclass("LuckyBagManager")
export class LuckyBagManager extends Component {
@property(Prefab)
fuDaiPrefab: Prefab = null;
private static _ins: LuckyBagManager = null;
static get ins() {
return this._ins;
}
maxFood: number = 5;
@property(Prefab)
luckyBagPrefab: Prefab = null;
onLoad() {
LuckyBagManager._ins = this;
}
onDestroy() {
LuckyBagManager._ins = null;
}
/**
* 初始化食物
*/
async init(maxFood: number = 100) {
this.maxFood = maxFood;
await executePreFrame(getItemGenerator(maxFood, this.initItem), 1, this);
start() {
this.flushItems();
}
/**
* 设置食物
*/
add(x?: number, y?: number) {
flushItems() {
const { luckNum } = gameStore.gameInfo || {};
const { currentAcquireNum } = gameStore.startInfo || {};
// 如果没有指定位置,随机生成位置
if (!x) {
x = math.randomRangeInt(-(Global.MAP_WIDTH / 2 - 50), Global.MAP_WIDTH / 2 - 50);
}
const flushNum = Math.min(currentAcquireNum - luckNum, 3);
if (!y) {
y = math.randomRangeInt(-(Global.MAP_HEIGHT / 2 - 50), Global.MAP_HEIGHT / 2 - 50);
this.add(flushNum);
}
const food = instantiate(this.fuDaiPrefab);
add(num: number = 1) {
const maxW = Global.MAP_HEIGHT / 2 - 100;
const maxH = (Global.MAP_HEIGHT / 2 - 100);
for (let i = 1; i <= num; i++) {
const x = math.randomRange(-maxW, maxW);
const y = math.randomRange(-maxH, maxH);
const node = instantiate(this.luckyBagPrefab);
// 设置食物属性
food.setPosition(x, y);
this.node.addChild(food);
node.setPosition(x, y);
this.node.addChild(node);
// 设置碰撞类型
const collider = food.getComponent(Collider2D);
const collider = node.getComponent(Collider2D);
if (collider) {
collider.tag = FoodType.LUCK_BAG;
collider.tag = EPropType.LUCK_BAG;
}
}
food.active = true;
}
/**
* 初始化单个食物
*/
initItem = (_: number) => {
// 随机生成位置
const x = math.randomRangeInt(-(Global.MAP_WIDTH / 2 - 50), Global.MAP_WIDTH / 2 - 50);
const y = math.randomRangeInt(-(Global.MAP_HEIGHT / 2 - 50), Global.MAP_HEIGHT / 2 - 50);
this.add(x, y);
};
}
import { _decorator } from "cc";
import { propPool } from "../Manager/CommonPool";
import { PropBase } from "./PropBase";
import { Snake } from "../Snake";
......@@ -14,7 +13,8 @@ export class LuckyBag extends PropBase {
recycle() {
this.node.removeFromParent();
propPool.put(this.node);
this.node.destroy();
// propPool.put(this.node);
}
}
\ No newline at end of file
......@@ -15,9 +15,9 @@ import {
} from "cc";
import { Global } from "./Global";
import { isIntersect, loadSkin } from "./utils/uitl";
import { MainGame } from "./MainGame";
import { bodyPool } from "./Manager/CommonPool";
import { PropBase } from "./Props/PropBase";
import { FoodManger } from "./Manager/FoodManger";
const { ccclass, property } = _decorator;
......@@ -382,7 +382,7 @@ export class Snake extends Component {
};
});
MainGame.ins.fondManger.initFoods(foodArr);
FoodManger.ins.initFoods(foodArr);
}
protected getNewPos(angle: number, dt: number, currentPos: Vec3, speed: number = this.speed): Vec3 {
......
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