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,
......
This diff is collapsed.
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