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 @@
},
{
"__id__": 20
},
{
"__id__": 22
}
],
"_prefab": {
"__id__": 22
"__id__": 24
},
"_lpos": {
"__type__": "cc.Vec3",
......@@ -416,7 +419,7 @@
"enabledContactListener": true,
"bullet": false,
"awakeOnLoad": true,
"_group": 32,
"_group": 4,
"_type": 2,
"_allowSleep": true,
"_gravityScale": 1,
......@@ -448,7 +451,7 @@
"__id__": 21
},
"tag": 0,
"_group": 32,
"_group": 4,
"_density": 1,
"_sensor": true,
"_friction": 0.2,
......@@ -465,6 +468,24 @@
"__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": {
......
......@@ -3,10 +3,12 @@ import { NodePool } from "cc";
export const foodPool = new NodePool();
export const bodyPool = new NodePool();
export const aiPool = new NodePool();
export const propPool = new NodePool();
export function clearAllPool() {
foodPool.clear();
bodyPool.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 { PropBase } from "./PropBase";
import { Snake } from "../Snake";
const { ccclass, property } = _decorator;
@ccclass("Food")
export class Food extends Component {
export class Food extends PropBase {
_energy: number = 1;
......@@ -23,8 +26,8 @@ export class Food extends Component {
this.energy = energy;
}
protected start() {
beEaten=(target: Snake) => {
target.addEnergy(this.energy);
}
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 {
_decorator,
Collider2D,
Component,
Contact2DType, instantiate, IVec2Like,
math,
Contact2DType, instantiate,
Node,
PhysicsGroup,
Prefab,
......@@ -11,15 +10,15 @@ import {
SpriteFrame,
tween, UITransform,
v2,
v3, Vec2,
v3,
Vec3,
} from "cc";
import { FoodType } from "./Common/Enums";
import { Global } from "./Global";
import { isIntersect, loadSkin } from "./utils/uitl";
import { MainGame } from "./MainGame";
import { bodyPool } from "./Manager/CommonPool";
import { Food } from "./Props/Food";
import { PropBase } from "./Props/PropBase";
const { ccclass, property } = _decorator;
......@@ -173,8 +172,7 @@ export class Snake extends Component {
}
onBeginEye(selfCollider: Collider2D, otherCollider: Collider2D) {
if (otherCollider.group === PhysicsGroup["Food"]) {
const foodType = otherCollider.tag;
if (otherCollider.group === PhysicsGroup["Prop"]) {
// 食物吃掉的动画
tween(otherCollider.node)
......@@ -184,17 +182,19 @@ export class Snake extends Component {
})
.call(() => {
if (!this.isLife) return;
const foodTs = otherCollider.getComponent(Food);
this.addEnergy(foodTs.energy);
foodTs.recycle();
const propTs = otherCollider.getComponent(PropBase);
propTs.beEaten(this);
propTs.recycle();
})
.start();
}
}
// 能量与成长
lastRemaining = 0;
private addEnergy(value: number) {
private lastRemaining = 0;
addEnergy(value: number) {
this.energy += value;
const growthThreshold = Math.floor(4 * this.scale);
......
......@@ -19,7 +19,7 @@
},
{
"index": 2,
"name": "Food"
"name": "Prop"
},
{
"index": 3,
......@@ -28,10 +28,6 @@
{
"index": 4,
"name": "Body"
},
{
"index": 5,
"name": "Prop"
}
],
"collisionMatrix": {
......@@ -39,8 +35,8 @@
"1": 52,
"2": 10,
"3": 116,
"4": 42,
"5": 90,
"4": 10,
"5": 74,
"6": 40
},
"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