Commit a1a04361 authored by haiyoucuv's avatar haiyoucuv

init

parent 1b520c6e
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
\ No newline at end of file
...@@ -35,10 +35,13 @@ ...@@ -35,10 +35,13 @@
}, },
{ {
"__id__": 20 "__id__": 20
},
{
"__id__": 22
} }
], ],
"_prefab": { "_prefab": {
"__id__": 22 "__id__": 24
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
...@@ -416,7 +419,7 @@ ...@@ -416,7 +419,7 @@
"enabledContactListener": true, "enabledContactListener": true,
"bullet": false, "bullet": false,
"awakeOnLoad": true, "awakeOnLoad": true,
"_group": 32, "_group": 4,
"_type": 2, "_type": 2,
"_allowSleep": true, "_allowSleep": true,
"_gravityScale": 1, "_gravityScale": 1,
...@@ -448,7 +451,7 @@ ...@@ -448,7 +451,7 @@
"__id__": 21 "__id__": 21
}, },
"tag": 0, "tag": 0,
"_group": 32, "_group": 4,
"_density": 1, "_density": 1,
"_sensor": true, "_sensor": true,
"_friction": 0.2, "_friction": 0.2,
...@@ -465,6 +468,24 @@ ...@@ -465,6 +468,24 @@
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "d4nguP1hRPj6hmP9ugayLT" "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", "__type__": "cc.PrefabInfo",
"root": { "root": {
......
...@@ -3,10 +3,12 @@ import { NodePool } from "cc"; ...@@ -3,10 +3,12 @@ import { NodePool } from "cc";
export const foodPool = new NodePool(); export const foodPool = new NodePool();
export const bodyPool = new NodePool(); export const bodyPool = new NodePool();
export const aiPool = new NodePool(); export const aiPool = new NodePool();
export const propPool = new NodePool();
export function clearAllPool() { export function clearAllPool() {
foodPool.clear(); foodPool.clear();
bodyPool.clear(); bodyPool.clear();
aiPool.clear(); aiPool.clear();
propPool.clear();
} }
\ No newline at end of file
import { _decorator, Component } from "cc"; import { _decorator } from "cc";
import { foodPool } from "../Manager/CommonPool"; import { foodPool } from "../Manager/CommonPool";
import { PropBase } from "./PropBase";
import { Snake } from "../Snake";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass("Food") @ccclass("Food")
export class Food extends Component { export class Food extends PropBase {
_energy: number = 1; _energy: number = 1;
...@@ -23,8 +26,8 @@ export class Food extends Component { ...@@ -23,8 +26,8 @@ export class Food extends Component {
this.energy = energy; this.energy = energy;
} }
protected start() { beEaten=(target: Snake) => {
target.addEnergy(this.energy);
} }
recycle() { recycle() {
......
import { _decorator } from "cc";
import { propPool } from "../Manager/CommonPool";
import { PropBase } from "./PropBase";
import { Snake } from "../Snake";
const { ccclass, property } = _decorator;
@ccclass("LuckyBag")
export class LuckyBag extends PropBase {
beEaten = (target: Snake) => {
};
recycle() {
this.node.removeFromParent();
propPool.put(this.node);
}
}
\ No newline at end of file
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "5da8a4aa-1d8c-40bd-a494-133fb47ef94c",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, Component } from "cc";
import { Snake } from "../Snake";
const { ccclass, property } = _decorator;
@ccclass("PropBase")
export class PropBase extends Component {
beEaten(target: Snake) {
};
recycle() {
};
}
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "343401ae-5e08-4311-8747-216116496283",
"files": [],
"subMetas": {},
"userData": {}
}
...@@ -2,8 +2,7 @@ import { ...@@ -2,8 +2,7 @@ import {
_decorator, _decorator,
Collider2D, Collider2D,
Component, Component,
Contact2DType, instantiate, IVec2Like, Contact2DType, instantiate,
math,
Node, Node,
PhysicsGroup, PhysicsGroup,
Prefab, Prefab,
...@@ -11,15 +10,15 @@ import { ...@@ -11,15 +10,15 @@ import {
SpriteFrame, SpriteFrame,
tween, UITransform, tween, UITransform,
v2, v2,
v3, Vec2, v3,
Vec3, Vec3,
} from "cc"; } from "cc";
import { FoodType } from "./Common/Enums";
import { Global } from "./Global"; import { Global } from "./Global";
import { isIntersect, loadSkin } from "./utils/uitl"; import { isIntersect, loadSkin } from "./utils/uitl";
import { MainGame } from "./MainGame"; import { MainGame } from "./MainGame";
import { bodyPool } from "./Manager/CommonPool"; import { bodyPool } from "./Manager/CommonPool";
import { Food } from "./Props/Food"; import { Food } from "./Props/Food";
import { PropBase } from "./Props/PropBase";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
...@@ -173,8 +172,7 @@ export class Snake extends Component { ...@@ -173,8 +172,7 @@ export class Snake extends Component {
} }
onBeginEye(selfCollider: Collider2D, otherCollider: Collider2D) { onBeginEye(selfCollider: Collider2D, otherCollider: Collider2D) {
if (otherCollider.group === PhysicsGroup["Food"]) { if (otherCollider.group === PhysicsGroup["Prop"]) {
const foodType = otherCollider.tag;
// 食物吃掉的动画 // 食物吃掉的动画
tween(otherCollider.node) tween(otherCollider.node)
...@@ -184,17 +182,19 @@ export class Snake extends Component { ...@@ -184,17 +182,19 @@ export class Snake extends Component {
}) })
.call(() => { .call(() => {
if (!this.isLife) return; if (!this.isLife) return;
const foodTs = otherCollider.getComponent(Food);
this.addEnergy(foodTs.energy); const propTs = otherCollider.getComponent(PropBase);
foodTs.recycle(); propTs.beEaten(this);
propTs.recycle();
}) })
.start(); .start();
} }
} }
// 能量与成长 // 能量与成长
lastRemaining = 0; private lastRemaining = 0;
private addEnergy(value: number) {
addEnergy(value: number) {
this.energy += value; this.energy += value;
const growthThreshold = Math.floor(4 * this.scale); const growthThreshold = Math.floor(4 * this.scale);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
}, },
{ {
"index": 2, "index": 2,
"name": "Food" "name": "Prop"
}, },
{ {
"index": 3, "index": 3,
...@@ -28,10 +28,6 @@ ...@@ -28,10 +28,6 @@
{ {
"index": 4, "index": 4,
"name": "Body" "name": "Body"
},
{
"index": 5,
"name": "Prop"
} }
], ],
"collisionMatrix": { "collisionMatrix": {
...@@ -39,8 +35,8 @@ ...@@ -39,8 +35,8 @@
"1": 52, "1": 52,
"2": 10, "2": 10,
"3": 116, "3": 116,
"4": 42, "4": 10,
"5": 90, "5": 74,
"6": 40 "6": 40
}, },
"maxSubSteps": 1, "maxSubSteps": 1,
......
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