Commit 0dd09263 authored by haiyoucuv's avatar haiyoucuv

init

parent 842d0321
This diff is collapsed.
[
{
"__type__": "cc.Prefab",
"_name": "卡A",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "卡A",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [],
"_active": true,
"_components": [
{
"__id__": 2
},
{
"__id__": 4
},
{
"__id__": 6
},
{
"__id__": 8
},
{
"__id__": 10
}
],
"_prefab": {
"__id__": 12
},
"_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__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 3
},
"_contentSize": {
"__type__": "cc.Size",
"width": 32,
"height": 42
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "f36Gjr/cxA5bosiEnf90lC"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 5
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_spriteFrame": {
"__uuid__": "04c4c3c6-c6a2-4ffb-98af-169280fb26f6@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": "79U2Z8PihDCKpj25KchRMz"
},
{
"__type__": "cc.RigidBody2D",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 7
},
"enabledContactListener": true,
"bullet": false,
"awakeOnLoad": true,
"_group": 4,
"_type": 1,
"_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": "97wTw+gGFFXqhX9+0L8n3z"
},
{
"__type__": "cc.BoxCollider2D",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 9
},
"tag": 0,
"_group": 4,
"_density": 1,
"_sensor": true,
"_friction": 0.2,
"_restitution": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_size": {
"__type__": "cc.Size",
"width": 32,
"height": 42
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "03SReFoi1MyblTtnOqjaHw"
},
{
"__type__": "ff08cSpRqFAubppBaJ7tYho",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 11
},
"tag": 2,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "96Vnnh5RpGZ52WY8R4AzOS"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "cbAXFUcl9AyYAN+i9Mo+C6",
"instance": null,
"targetOverrides": null
}
]
\ No newline at end of file
{
"ver": "1.1.50",
"importer": "prefab",
"imported": true,
"uuid": "efbb3e39-0a47-481d-a9a2-27f449ab881d",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "卡A"
}
}
[
{
"__type__": "cc.Prefab",
"_name": "卡B",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "卡B",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [],
"_active": true,
"_components": [
{
"__id__": 2
},
{
"__id__": 4
},
{
"__id__": 6
},
{
"__id__": 8
},
{
"__id__": 10
}
],
"_prefab": {
"__id__": 12
},
"_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__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 3
},
"_contentSize": {
"__type__": "cc.Size",
"width": 32,
"height": 42
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "f36Gjr/cxA5bosiEnf90lC"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 5
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_spriteFrame": {
"__uuid__": "e37fb195-9aa5-43ba-9720-93366607f675@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": "79U2Z8PihDCKpj25KchRMz"
},
{
"__type__": "cc.RigidBody2D",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 7
},
"enabledContactListener": true,
"bullet": false,
"awakeOnLoad": true,
"_group": 4,
"_type": 1,
"_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": "97wTw+gGFFXqhX9+0L8n3z"
},
{
"__type__": "cc.BoxCollider2D",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 9
},
"tag": 0,
"_group": 4,
"_density": 1,
"_sensor": true,
"_friction": 0.2,
"_restitution": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_size": {
"__type__": "cc.Size",
"width": 32,
"height": 42
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "03SReFoi1MyblTtnOqjaHw"
},
{
"__type__": "ff08cSpRqFAubppBaJ7tYho",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 11
},
"tag": 3,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "6d2fdXQtZG5oyCopoKcs1R"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "cbAXFUcl9AyYAN+i9Mo+C6",
"instance": null,
"targetOverrides": null
}
]
\ No newline at end of file
{
"ver": "1.1.50",
"importer": "prefab",
"imported": true,
"uuid": "5b9810de-f810-45a7-8d79-b3fc1152bfc9",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "卡B"
}
}
[
{
"__type__": "cc.Prefab",
"_name": "卡C",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "卡C",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [],
"_active": true,
"_components": [
{
"__id__": 2
},
{
"__id__": 4
},
{
"__id__": 6
},
{
"__id__": 8
},
{
"__id__": 10
}
],
"_prefab": {
"__id__": 12
},
"_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__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 3
},
"_contentSize": {
"__type__": "cc.Size",
"width": 32,
"height": 42
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "f36Gjr/cxA5bosiEnf90lC"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 5
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_spriteFrame": {
"__uuid__": "af6adb06-7b7a-4c99-9a3a-93f00d63e5c7@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": "79U2Z8PihDCKpj25KchRMz"
},
{
"__type__": "cc.RigidBody2D",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 7
},
"enabledContactListener": true,
"bullet": false,
"awakeOnLoad": true,
"_group": 4,
"_type": 1,
"_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": "97wTw+gGFFXqhX9+0L8n3z"
},
{
"__type__": "cc.BoxCollider2D",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 9
},
"tag": 0,
"_group": 4,
"_density": 1,
"_sensor": true,
"_friction": 0.2,
"_restitution": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_size": {
"__type__": "cc.Size",
"width": 32,
"height": 42
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "03SReFoi1MyblTtnOqjaHw"
},
{
"__type__": "ff08cSpRqFAubppBaJ7tYho",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 11
},
"tag": 4,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "6d2fdXQtZG5oyCopoKcs1R"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "cbAXFUcl9AyYAN+i9Mo+C6",
"instance": null,
"targetOverrides": null
}
]
\ No newline at end of file
{
"ver": "1.1.50",
"importer": "prefab",
"imported": true,
"uuid": "e47a3402-261d-4da0-942c-c672159c078b",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "卡C"
}
}
......@@ -10,7 +10,10 @@ export const Events = {
// 食物类型枚举
export enum EPropType {
FOOD = 0, // 普通食物
LUCK_BAG = 1 // 福袋
LUCK_BAG = 1, // 福袋
CARD_A = 2,
CARD_B = 3,
CARD_C = 4,
}
ccenum(EPropType);
......
import { _decorator, View } from 'cc';
import { _decorator, IVec2Like, math, View } from "cc";
const { ccclass } = _decorator;
/**
* 全局配置类
*/
@ccclass('Global')
@ccclass("Global")
export class Global {
/** 地图宽度 */
public static MAP_WIDTH: number = 6000;
/** 地图宽度 */
static MAP_WIDTH: number = 6000;
/** 地图高度 */
static MAP_HEIGHT: number = 4200;
static getRandomPosition(padding: number = 0): IVec2Like {
const maxW = Global.MAP_WIDTH / 2 - padding;
const maxH = Global.MAP_HEIGHT / 2 - padding;
const x = math.randomRange(-maxW, maxW);
const y = math.randomRange(-maxH, maxH);
/** 地图高度 */
public static MAP_HEIGHT: number = 4200;
return { x, y };
}
}
\ No newline at end of file
import {
_decorator,
math,
Component,
Prefab,
instantiate,
} from "cc";
import { Global } from "db://assets/Scripts/Scenes/MainGame/Global";
import { executePreFrame, getItemGenerator } from "db://assets/Scripts/Utils/ExecutePreFrame";
const { ccclass, property } = _decorator;
/**
* 食物管理器
*/
@ccclass("CardManager")
export class CardManager extends Component {
private static _ins: CardManager = null;
static get ins() {
return this._ins;
}
@property({ type: [Prefab] })
private cardPrefabs: Prefab[] = [];
maxCard: number = 10;
onLoad() {
CardManager._ins = this;
}
onDestroy() {
CardManager._ins = null;
}
start() {
this.init(10);
}
/**
* 获取当前食物数量
*/
getCardSum() {
return this.node.children.length || 0;
}
/**
* 初始化食物
*/
async init(maxCard: number = 10) {
this.maxCard = maxCard;
await executePreFrame(getItemGenerator(maxCard, this.initItem), 1, this);
}
/**
* 检查食物
*/
checkCard() {
for (let i = this.getCardSum(); i < this.maxCard; i++) {
this.addCard();
}
}
/**
* 设置食物
*/
addCard(x?: number, y?: number) {
// 如果没有指定位置,随机生成位置
if (!x) {
const { x: _x, y: _y } = Global.getRandomPosition(100);
x = _x;
y = _y;
}
const index = math.randomRangeInt(0, this.cardPrefabs.length);
const card = instantiate(this.cardPrefabs[index]);
// 设置食物属性
card.setPosition(x, y);
this.node.addChild(card);
card.active = true;
}
/**
* 初始化单个食物
*/
initItem = (_: number) => {
this.checkCard();
};
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "aad38637-15a2-4fcb-b087-b702d39b404f",
"files": [],
"subMetas": {},
"userData": {}
}
......@@ -28,7 +28,7 @@ export class FoodManger extends Component {
}
@property({ type: [SpriteFrame] })
private foods: SpriteFrame[] = [];
foods: SpriteFrame[] = [];
@property(Prefab)
private foodPrefab: Prefab = null;
......@@ -73,16 +73,11 @@ export class FoodManger extends Component {
*/
addFood(x?: number, y?: number, energy: number = 1) {
const maxW = Global.MAP_WIDTH / 2 - 100;
const maxH = Global.MAP_HEIGHT / 2 - 100;
// 如果没有指定位置,随机生成位置
if (!x) {
x = math.randomRange(-maxW, maxW);
}
if (!y) {
y = math.randomRange(-maxH, maxH);
const { x: _x, y: _y } = Global.getRandomPosition(100);
x = _x;
y = _y;
}
const food = foodPool.get() || instantiate(this.foodPrefab);
......
import { _decorator } from "cc";
import { PropBase } from "./PropBase";
import { Snake } from "db://assets/Scripts/Scenes/MainGame/Snake";
import { EPropType } from "../Common/Enums";
import { CardManager } from "../Manager/CardManager";
const { ccclass, property } = _decorator;
@ccclass("Card")
export class Card extends PropBase {
@property({ type: EPropType })
tag: EPropType = EPropType.CARD_A;
onLoad() {
}
beEaten = (target: Snake) => {
};
recycle() {
CardManager.ins.checkCard();
this.node.removeFromParent();
this.node.destroy();
// propPool.put(this.node);
}
}
\ No newline at end of file
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "ff08c4a9-46a1-40b9-ba69-05a27bb58868",
"files": [],
"subMetas": {},
"userData": {}
}
import { Vec2, Vec3, Size, assetManager, SpriteFrame, SpriteAtlas } from "cc";
import { Vec2, Vec3, Size, assetManager, SpriteFrame, SpriteAtlas, math, IVec2Like } from "cc";
import { Global } from "../Global";
/**
* 判断两点是否在指定范围内相交
......@@ -9,7 +10,7 @@ import { Vec2, Vec3, Size, assetManager, SpriteFrame, SpriteAtlas } from "cc";
* @returns 是否相交
*/
export function isIntersect(pos1: Vec3, pos2: Vec3, rangeW: number, rangeH: number): boolean {
return rangeW > Math.abs(pos1.x - pos2.x) && rangeH > Math.abs(pos1.y - pos2.y);
return rangeW > Math.abs(pos1.x - pos2.x) && rangeH > Math.abs(pos1.y - pos2.y);
}
/**
......@@ -19,33 +20,13 @@ export function isIntersect(pos1: Vec3, pos2: Vec3, rangeW: number, rangeH: numb
* @returns 随机浮点数
*/
export function getRandomFloat(min: number, max: number): number {
return Math.random() * (max - min) + min;
return Math.random() * (max - min) + min;
}
/**
* 获取随机位置
* @param viewSize 视图大小
* @param padding 边距
* @returns 随机位置
*/
export function getRandomPosition(viewSize: Size, padding: number = 0): Vec2 {
const x = getRandomFloat(
-viewSize.width / 2 + padding,
viewSize.width / 2 - padding
);
const y = getRandomFloat(
-viewSize.height / 2 + padding,
viewSize.height / 2 - padding
);
return new Vec2(x, y);
}
export function formatTime(seconds: number): string {
const mins = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
return `${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
const mins = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
return `${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
}
export function loadSkin(skinName: string, bundleName: string = "MainGame"): Promise<SpriteAtlas> {
......
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