Commit aa7315ad authored by haiyoucuv's avatar haiyoucuv

init

parent 29f47b46
This diff is collapsed.
......@@ -365,7 +365,7 @@ export class Animal extends Component {
);
const halfWidth = Global.MAP_WIDTH / 2;
const halfHeight = Global.MAP_HIGHT / 2;
const halfHeight = Global.MAP_HEIGHT / 2;
// 如果要超出地图边界,则转向
if (this.v.x <= -halfWidth || this.v.x >= halfWidth ||
......@@ -418,8 +418,8 @@ export class Animal extends Component {
Global.MAP_WIDTH / 2 - 50
);
const y = math.randomRangeInt(
-(Global.MAP_HIGHT / 2 - 50),
Global.MAP_HIGHT / 2 - 50
-(Global.MAP_HEIGHT / 2 - 50),
Global.MAP_HEIGHT / 2 - 50
);
this.reInit(x, y);
});
......
......@@ -70,7 +70,7 @@ export class FondManger extends Component {
}
if (!y) {
y = math.randomRangeInt(-(Global.MAP_HIGHT / 2 - 50), Global.MAP_HIGHT / 2 - 50);
y = math.randomRangeInt(-(Global.MAP_HEIGHT / 2 - 50), Global.MAP_HEIGHT / 2 - 50);
}
// 从对象池获取食物节点
......@@ -101,7 +101,7 @@ export class FondManger extends Component {
initItem = (_: number) => {
// 随机生成位置
const x = math.randomRangeInt(-(Global.MAP_WIDTH / 2 - 50), Global.MAP_WIDTH / 2 - 50);
const y = math.randomRangeInt(-(Global.MAP_HIGHT / 2 - 50), Global.MAP_HIGHT / 2 - 50);
const y = math.randomRangeInt(-(Global.MAP_HEIGHT / 2 - 50), Global.MAP_HEIGHT / 2 - 50);
this.addFood(x, y);
};
......
......@@ -22,7 +22,7 @@ export class Global {
public static MAP_WIDTH: number = 5000;
/** 地图高度 */
public static MAP_HIGHT: number = 4000;
public static MAP_HEIGHT: number = 4000;
/** 当前皮肤ID */
public static skinId: number = 0;
......
......@@ -95,24 +95,24 @@ export class MainGame extends Scene {
// EPhysics2DDrawFlags.Shape;
Global.MAP_WIDTH = this.uiBg.contentSize.x;
Global.MAP_HIGHT = this.uiBg.contentSize.y;
Global.MAP_HEIGHT = this.uiBg.contentSize.y;
// 初始化墙壁
const wallTop = this.uiBg.node.getChildByName("WALL_TOP");
wallTop.setPosition(0, Global.MAP_HIGHT / 2);
wallTop.setPosition(0, Global.MAP_HEIGHT / 2);
wallTop.getComponent(UITransform).width = Global.MAP_WIDTH;
const wallBottom = this.uiBg.node.getChildByName("WALL_BOTTOM");
wallBottom.setPosition(0, -Global.MAP_HIGHT / 2);
wallBottom.setPosition(0, -Global.MAP_HEIGHT / 2);
wallBottom.getComponent(UITransform).width = Global.MAP_WIDTH;
const wallLeft = this.uiBg.node.getChildByName("WALL_LEFT");
wallLeft.setPosition(-Global.MAP_WIDTH / 2, 0);
wallLeft.getComponent(UITransform).height = Global.MAP_HIGHT;
wallLeft.getComponent(UITransform).height = Global.MAP_HEIGHT;
const wallRight = this.uiBg.node.getChildByName("WALL_RIGHT");
wallRight.setPosition(Global.MAP_WIDTH / 2, 0);
wallRight.getComponent(UITransform).height = Global.MAP_HIGHT;
wallRight.getComponent(UITransform).height = Global.MAP_HEIGHT;
this.player.init();
......@@ -190,7 +190,7 @@ export class MainGame extends Scene {
initItem = (index: number) => {
const node = PoolManager.instance.getNode(this.animalPrefab);
const x = math.randomRangeInt(-(Global.MAP_WIDTH / 2 - 50), Global.MAP_WIDTH / 2 - 50);
const y = math.randomRangeInt(-(Global.MAP_HIGHT / 2 - 50), Global.MAP_HIGHT / 2 - 50);
const y = math.randomRangeInt(-(Global.MAP_HEIGHT / 2 - 50), Global.MAP_HEIGHT / 2 - 50);
node.getComponent(AISnake)?.init({
x, y,
......
......@@ -46,15 +46,15 @@ export class Snake extends Component {
@property(Prefab) bodyPrefab: Prefab = null;
// 私有成员变量
private bodyArr: Node[] = [];
bodyArr: Node[] = [];
private imgHead: SpriteFrame = null;
private imgBody1: SpriteFrame = null;
private imgBody2: SpriteFrame = null;
// 蛇的状态
protected isLife: boolean = false;
isLife: boolean = false;
private scale: number = 0.2;
protected speed: number = 600;
speed: number = 600;
private energy: number = 0;
private tag: number = 0;
......@@ -63,6 +63,10 @@ export class Snake extends Component {
private vh: number = Global.visibleSize.height / 2 + 100;
private ready: boolean = false;
get radius() {
return this.scale * 50;
}
// 初始化方法
public async init(config: IInitConfig = {}) {
......@@ -280,7 +284,7 @@ export class Snake extends Component {
// 边界检查
const mapHalfWidth = Global.MAP_WIDTH / 2;
const mapHalfHeight = Global.MAP_HIGHT / 2;
const mapHalfHeight = Global.MAP_HEIGHT / 2;
if (
newHeadPos.x <= -mapHalfWidth || newHeadPos.x >= mapHalfWidth ||
newHeadPos.y <= -mapHalfHeight || newHeadPos.y >= mapHalfHeight
......
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