mirror of
https://github.com/Cola-Echo/memory-manager-concurrent.git
synced 2026-06-07 07:05:49 +00:00
Update memory-manager-concurrent
This commit is contained in:
40
games/laya-snakes/js/Bean.js
Normal file
40
games/laya-snakes/js/Bean.js
Normal file
@@ -0,0 +1,40 @@
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
/**
|
||||
* Bean extends laya.display.Sprite
|
||||
*/
|
||||
var Bean = (function (_super) {
|
||||
__extends(Bean, _super);
|
||||
function Bean(x, y, colorNum) {
|
||||
if (x === void 0) { x = Math.random() * game.gameMainUI.map.width; }
|
||||
if (y === void 0) { y = Math.random() * game.gameMainUI.map.height; }
|
||||
if (colorNum === void 0) { colorNum = Math.floor(Math.random() * (6 - 1 + 1) + 1); }
|
||||
_super.call(this);
|
||||
this.haveEaten = false;
|
||||
this.speed = 2;
|
||||
this.eatenTargetPos = { x: 0, y: 0 };
|
||||
this.haveEatenDis = 4;
|
||||
this.eatenPos = { x: 0, y: 0 };
|
||||
this.eatenInitPos = { x: 0, y: 0 };
|
||||
this.colorNum = colorNum;
|
||||
this.zOrder = 0;
|
||||
this.visible = false;
|
||||
this.eatenInitPos["x"] = x;
|
||||
this.eatenInitPos["y"] = y;
|
||||
this.init(x, y);
|
||||
}
|
||||
Bean.prototype.init = function (x, y) {
|
||||
this.loadImage("images/bean" + this.colorNum + ".png", 0, 0, 0, 0, new Handler(this, this.loaded, [x, y]));
|
||||
};
|
||||
Bean.prototype.loaded = function (x, y) {
|
||||
this.zOrder = 0;
|
||||
this.pivot(this.width / 2, this.height / 2);
|
||||
this.pos(x, y);
|
||||
this.visible = true;
|
||||
};
|
||||
return Bean;
|
||||
}(laya.display.Sprite));
|
||||
//# sourceMappingURL=Bean.js.map
|
||||
1
games/laya-snakes/js/Bean.js.map
Normal file
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AAJ,UAAK,CAAS,EAAE,CAAS;QACrB,IAAI,CAAC,SAAS,CAAC,aAAa,GAAG,IAAI,CAAC,QAAQ,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9G,CAAC;IAED,qBAAM,GAAN,UAAO,CAAS,EAAE,CAAS;QACvB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;QACf,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAC3C,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;IACvB,CAAC;IACL,WAAC;AAAD,CAAC,AApCD,CAAmB,IAAI,CAAC,OAAO,CAAC,MAAM,GAoCrC"}
|
||||
287
games/laya-snakes/js/Game.js
Normal file
287
games/laya-snakes/js/Game.js
Normal file
@@ -0,0 +1,287 @@
|
||||
var Sprite = laya.display.Sprite;
|
||||
var Loader = laya.net.Loader;
|
||||
var Texture = laya.resource.Texture;
|
||||
var Handler = laya.utils.Handler;
|
||||
var Browser = laya.utils.Browser;
|
||||
var TiledMap = laya.map.TiledMap;
|
||||
var Rectangle = laya.maths.Rectangle;
|
||||
var Stat = laya.utils.Stat;
|
||||
var TextFiled = laya.display.Text;
|
||||
var LocalStorage = laya.net.LocalStorage;
|
||||
/**
|
||||
* Game
|
||||
* 游戏入口类
|
||||
*/
|
||||
var Game = (function () {
|
||||
function Game() {
|
||||
this.stageW = Browser.onQQBrowser ? Browser.width / Browser.pixelRatio : Browser.clientWidth;
|
||||
this.stageH = Browser.onQQBrowser ? Browser.height / Browser.pixelRatio : Browser.clientHeight;
|
||||
this.beanSingleNumInit = 300;
|
||||
this.beanMaxNum = 600;
|
||||
this.beanNum = 0;
|
||||
this.beanOrder = 0;
|
||||
this.beans = {};
|
||||
this.SnakeAINum = 5;
|
||||
this.snakeAIArr = [];
|
||||
this._init();
|
||||
Stat.show(200, 10);
|
||||
}
|
||||
//屏幕适配、初始化舞台
|
||||
Game.prototype._init = function () {
|
||||
this.stageW = 600;
|
||||
this.stageH = Browser.height / Browser.width * this.stageW;
|
||||
Laya.init(this.stageW, this.stageH, Laya.WebGL);
|
||||
Laya.stage.scaleMode = Laya.Stage.SCALE_SHOWALL;
|
||||
Laya.stage.alignH = Laya.Stage.ALIGN_CENTER;
|
||||
Laya.stage.alignV = Laya.Stage.ALIGN_MIDDLE;
|
||||
Laya.stage.screenMode = Laya.Stage.SCREEN_HORIZONTAL;
|
||||
Laya.stage.bgColor = "#555555";
|
||||
//加载资源
|
||||
this._load();
|
||||
//对屏幕改小改变进行监听
|
||||
Browser.window.onresize = onWindowResize;
|
||||
};
|
||||
Game.prototype._onresizeAction = function () {
|
||||
this.loading && this.loading.pos(this.stageW / 2, this.stageH / 2);
|
||||
this.gameStartUI && this.gameStartUI.pos(this.stageW / 2, this.stageH / 2);
|
||||
this.gameMainUI && (this.gameMainUI.mask_rank.x = (this.stageW - this.gameMainUI.mask_rank.width - 10));
|
||||
this.gameMainUI && this.gameMainUI.ctrl_flash.pos(this.stageW - this.gameMainUI.ctrl_flash.width, this.stageH - this.gameMainUI.ctrl_flash.height);
|
||||
this.gameMainUI && this.gameMainUI.ctrl_back.pos(this.gameMainUI.ctrl_back.width, this.stageH - this.gameMainUI.ctrl_back.height);
|
||||
};
|
||||
//加载资源
|
||||
Game.prototype._load = function () {
|
||||
var _this = this;
|
||||
this.loading = new TextFiled();
|
||||
this.loading.text = "正在加载资源,请稍后...";
|
||||
this.loading.color = "#000000";
|
||||
this.loading.font = "Microsoft YaHei";
|
||||
this.loading.pos(this.stageW / 2, this.stageH / 2);
|
||||
this.loading.pivot(this.loading.width / 2, this.loading.height / 2);
|
||||
Laya.stage.addChild(this.loading);
|
||||
//加载资源
|
||||
Laya.loader.load("res/atlas/images.json", Laya.Handler.create(this, function () {
|
||||
//资源加载完成则进入开始界面
|
||||
// this.gameStartSence()
|
||||
_this.gameMain();
|
||||
}), null, Laya.Loader.ATLAS);
|
||||
Laya.loader.load("map/tile_map.png");
|
||||
Laya.loader.load("images/head1.png");
|
||||
Laya.loader.load("images/head2.png");
|
||||
Laya.loader.load("images/head3.png");
|
||||
Laya.loader.load("images/head4.png");
|
||||
Laya.loader.load("images/head5.png");
|
||||
};
|
||||
//开始界面
|
||||
Game.prototype.gameStartSence = function () {
|
||||
this.gameStartUI = new GameStart();
|
||||
this.gameStartUI.pos(this.stageW / 2, this.stageH / 2);
|
||||
this.gameStartUI.btn_single.on("click", this, this.gameStart, [0]);
|
||||
this.gameStartUI.btn_net.on("click", this, this.gameStart, [1]);
|
||||
Laya.stage.addChild(this.gameStartUI);
|
||||
Laya.stage.removeChild(this.loading);
|
||||
this.loading.destroy();
|
||||
};
|
||||
//开始游戏,进入GameMain
|
||||
Game.prototype.gameStart = function (gameMode) {
|
||||
this.nickname = this.gameStartUI.nickname.label;
|
||||
this.neturl = this.gameStartUI.neturl.label;
|
||||
this.skin = this.gameStartUI.skinRadio.selectedIndex;
|
||||
this.gameMode = gameMode;
|
||||
Laya.stage.removeChild(this.gameStartUI);
|
||||
this.gameMain();
|
||||
};
|
||||
//进行游戏
|
||||
Game.prototype.gameMain = function () {
|
||||
this.gameMainUI = new GameMain();
|
||||
this.gameMainUI.map.pos(this.stageW / 2, this.stageH / 2);
|
||||
this.gameMainUI.mask_rank.x = this.stageW - this.gameMainUI.mask_rank.width - 10;
|
||||
this.gameMainUI.ctrl_flash.pos(this.stageW - this.gameMainUI.ctrl_flash.width - 30, this.stageH - this.gameMainUI.ctrl_flash.height);
|
||||
this.gameMainUI.ctrl_back.pos(this.gameMainUI.ctrl_back.width + 30, this.stageH - this.gameMainUI.ctrl_back.height);
|
||||
Laya.stage.addChild(this.gameMainUI);
|
||||
for (var _bean_i = 0; _bean_i < this.beanSingleNumInit; _bean_i++) {
|
||||
this.beanOrder++;
|
||||
this.addBean(this.beanOrder);
|
||||
}
|
||||
this.addBeanRandom();
|
||||
this.snakeSelf = new Snake();
|
||||
this.gameMainUI.map.addChild(this.snakeSelf);
|
||||
for (var index = 0; index < this.SnakeAINum; index++) {
|
||||
var snakeAI = new Snake(Math.floor(Math.random() * (5 - 1 + 1) + 1), this.gameMainUI.map.width * Math.random(), this.gameMainUI.map.height * Math.random());
|
||||
snakeAI.AI = true;
|
||||
this.snakeAIArr.push(snakeAI);
|
||||
this.gameMainUI.map.addChild(snakeAI);
|
||||
}
|
||||
this.snakeAIRotation();
|
||||
Laya.timer.frameLoop(1, this, this.gameLoop);
|
||||
};
|
||||
//游戏主循环
|
||||
Game.prototype.gameLoop = function () {
|
||||
this.snakeSelf.move();
|
||||
this.snakeAIMove();
|
||||
this.mapMove();
|
||||
this.eateBean();
|
||||
this.gameMainUI.text_length.text = this.snakeSelf.snakeLength + "";
|
||||
// this.gameMainUI.text_kill.text = this.snakeSelf.snakeSize + ""
|
||||
// this.gameMainUI.text_kill.text = Browser.width + " " + Browser.clientWidth + " " + Browser.pixelRatio
|
||||
};
|
||||
Game.prototype.eateBean = function () {
|
||||
for (var key in this.beans) {
|
||||
var bean = this.beans[key];
|
||||
// if (bean.haveEaten) {//确定了有被吃对象
|
||||
// let x = (bean.speed) * Math.cos(Math.atan2(bean.eatenInitPos["y"] - bean.y, bean.eatenInitPos["x"] - bean.x))
|
||||
// let y = (bean.speed) * Math.sin(Math.atan2(bean.eatenInitPos["y"] - bean.y, bean.eatenInitPos["x"] - bean.x))
|
||||
// bean.x += x
|
||||
// bean.y += y
|
||||
// bean.eatenPos["x"] += x
|
||||
// bean.eatenPos["x"] += y
|
||||
// // console.log(distance(bean.eatenPos["x"], bean.eatenPos["y"], bean.eatenInitPos["x"], bean.eatenInitPos["x"]))
|
||||
// if (distance(bean.x, bean.y, bean.eatenInitPos["x"], bean.eatenInitPos["y"]) < bean.haveEatenDis) {
|
||||
// bean.destroy()
|
||||
// this.beans[key] = undefined
|
||||
// delete this.beans[key]
|
||||
// this.snakeSelf.snakeLength++
|
||||
// this.snakeSelf.eatBean++
|
||||
// this.beanNum--
|
||||
// }
|
||||
// } else if (distance(bean.x, bean.y, this.snakeSelf.x, this.snakeSelf.y) <= (this.snakeSelf.width / 2) + 20) {
|
||||
// bean.eatenTarget = this.snakeSelf
|
||||
// bean.eatenInitPos["x"] = this.snakeSelf.x + this.snakeSelf.speed * 10 * Math.cos(this.snakeSelf.rotation * Math.PI / 180)
|
||||
// bean.eatenInitPos["y"] = this.snakeSelf.y + this.snakeSelf.speed * 10 * Math.sin(this.snakeSelf.rotation * Math.PI / 180)
|
||||
// bean.haveEaten = true
|
||||
// }
|
||||
if (distance(bean.x, bean.y, this.snakeSelf.x, this.snakeSelf.y) <= this.snakeSelf.width / 2) {
|
||||
bean.destroy();
|
||||
this.beans[key] = undefined;
|
||||
delete this.beans[key];
|
||||
this.snakeSelf.snakeLength++;
|
||||
this.snakeSelf.eatBean++;
|
||||
this.beanNum--;
|
||||
}
|
||||
else if (distance(bean.x, bean.y, this.snakeSelf.x, this.snakeSelf.y) <= (this.snakeSelf.width / 2) + 20) {
|
||||
bean.x += (this.snakeSelf.speed + 0.1) * Math.cos(Math.atan2(this.snakeSelf.y - bean.y, this.snakeSelf.x - bean.x));
|
||||
bean.y += (this.snakeSelf.speed + 0.1) * Math.sin(Math.atan2(this.snakeSelf.y - bean.y, this.snakeSelf.x - bean.x));
|
||||
}
|
||||
for (var index = 0; index < this.snakeAIArr.length; index++) {
|
||||
var element = this.snakeAIArr[index];
|
||||
if (distance(bean.x, bean.y, element.x, element.y) <= element.width / 2) {
|
||||
bean.destroy();
|
||||
this.beans[key] = undefined;
|
||||
delete this.beans[key];
|
||||
element.snakeLength++;
|
||||
element.eatBean++;
|
||||
this.beanNum--;
|
||||
}
|
||||
else if (distance(bean.x, bean.y, element.x, element.y) <= (element.width / 2) + 20) {
|
||||
bean.x += (bean.speed) * Math.cos(Math.atan2(element.y - bean.y, element.x - bean.x));
|
||||
bean.y += (bean.speed) * Math.sin(Math.atan2(element.y - bean.y, element.x - bean.x));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
//做地图相对移动,以便能让玩家的蛇始终居中
|
||||
Game.prototype.mapMove = function () {
|
||||
var mapScale = this.snakeSelf.snakeInitSize / this.snakeSelf.snakeSize < 0.7 ? 0.7 : this.snakeSelf.snakeInitSize / this.snakeSelf.snakeSize;
|
||||
// this.gameMainUI.map.x = -1 * (this.snakeSelf.x - this.stageW / 2 + this.snakeSelf.width / 2 - this.gameMainUI.map.width / 2) * mapScale
|
||||
// this.gameMainUI.map.y = -1 * (this.snakeSelf.y - this.stageH / 2 + this.snakeSelf.height / 2 - this.gameMainUI.map.height / 2) * mapScale
|
||||
this.gameMainUI.map.x = -1 * (this.snakeSelf.x + this.snakeSelf.width / 2 - this.gameMainUI.map.width / 2) * mapScale + this.stageW / 2;
|
||||
this.gameMainUI.map.y = -1 * (this.snakeSelf.y + this.snakeSelf.height / 2 - this.gameMainUI.map.height / 2) * mapScale + this.stageH / 2;
|
||||
this.gameMainUI.map.scale(mapScale, mapScale);
|
||||
};
|
||||
Game.prototype.addBean = function (beanOrder, x, y, colorNum) {
|
||||
var bean = new Bean(x, y, colorNum);
|
||||
bean.orderNum = beanOrder;
|
||||
this.beans[beanOrder] = bean;
|
||||
this.gameMainUI.map.addChild(bean);
|
||||
this.beanNum++;
|
||||
};
|
||||
Game.prototype.addBeanRandom = function () {
|
||||
var _this = this;
|
||||
this.beanRandomTimer = setInterval(function () {
|
||||
if (_this.beanNum < _this.beanMaxNum) {
|
||||
for (var index = 0; index < 20; index++) {
|
||||
_this.beanOrder++;
|
||||
_this.addBean(_this.beanOrder);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
};
|
||||
Game.prototype.snakeAIMove = function () {
|
||||
for (var index = 0; index < this.snakeAIArr.length; index++) {
|
||||
var snakeAI = this.snakeAIArr[index];
|
||||
snakeAI.move();
|
||||
var hitDis = 90 / snakeAI.speedObj["rotation"] * snakeAI.speed + snakeAI.width / 2;
|
||||
var hitPos = { x: 0, y: 0 };
|
||||
hitPos["x"] = hitDis * Math.cos(snakeAI.rotation * Math.PI / 180) + snakeAI.x;
|
||||
hitPos["y"] = hitDis * Math.sin(snakeAI.rotation * Math.PI / 180) + snakeAI.y;
|
||||
var hiten = false;
|
||||
//判断是否快碰撞到边界
|
||||
if (hitPos["x"] >= this.gameMainUI.map.width - snakeAI.width / 2 || hitPos["x"] <= snakeAI.width / 2
|
||||
|| hitPos["y"] >= this.gameMainUI.map.height - snakeAI.width / 2 || hitPos["y"] <= snakeAI.width / 2) {
|
||||
snakeAI.reverseRotation();
|
||||
}
|
||||
//判断是否撞倒玩家蛇
|
||||
if (distance(hitPos["x"], hitPos["y"], this.snakeSelf.x, this.snakeSelf.y) <= this.snakeSelf.width) {
|
||||
snakeAI.reverseRotation();
|
||||
hiten = true;
|
||||
}
|
||||
for (var index_1 = 0; index_1 < this.snakeSelf.bodyArr.length; index_1++) {
|
||||
if (hiten)
|
||||
break;
|
||||
var element = this.snakeSelf.bodyArr[index_1];
|
||||
if (distance(hitPos["x"], hitPos["y"], element.x, element.y) <= element.width) {
|
||||
snakeAI.reverseRotation();
|
||||
hiten = true;
|
||||
}
|
||||
}
|
||||
//判断AI之间是否自己碰撞
|
||||
for (var i = 0; i < this.snakeAIArr.length; i++) {
|
||||
if (hiten)
|
||||
break;
|
||||
var elementSnakeAI = this.snakeAIArr[i];
|
||||
if (index == i)
|
||||
continue;
|
||||
if (distance(hitPos["x"], hitPos["y"], elementSnakeAI.x, elementSnakeAI.y) <= elementSnakeAI.width) {
|
||||
snakeAI.reverseRotation();
|
||||
hiten = true;
|
||||
}
|
||||
for (var index_2 = 0; index_2 < elementSnakeAI.bodyArr.length; index_2++) {
|
||||
if (hiten)
|
||||
break;
|
||||
var element = elementSnakeAI.bodyArr[index_2];
|
||||
if (distance(hitPos["x"], hitPos["y"], element.x, element.y) <= element.width) {
|
||||
snakeAI.reverseRotation();
|
||||
hiten = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Game.prototype.snakeAIRotation = function () {
|
||||
var _this = this;
|
||||
for (var index = 0; index < this.snakeAIArr.length; index++) {
|
||||
this.snakeAIArr[index].targetR = 180 - Math.random() * 360;
|
||||
this.snakeAIArr[index].speedNow = Math.random() > 0.9 ? "fast" : "slow";
|
||||
}
|
||||
setInterval(function () {
|
||||
for (var index = 0; index < _this.snakeAIArr.length; index++) {
|
||||
_this.snakeAIArr[index].targetR = 180 - Math.random() * 360;
|
||||
_this.snakeAIArr[index].speedNow = Math.random() > 0.9 ? "fast" : "slow";
|
||||
}
|
||||
}, 3000);
|
||||
};
|
||||
return Game;
|
||||
}());
|
||||
//当屏幕大小改变时回调
|
||||
function onWindowResize() {
|
||||
game.stageW = Browser.onQQBrowser ? Browser.width / Browser.pixelRatio : Browser.width / Browser.pixelRatio;
|
||||
game.stageH = Browser.onQQBrowser ? Browser.height / Browser.pixelRatio : Browser.height / Browser.pixelRatio;
|
||||
Laya.stage.size(game.stageW, game.stageH);
|
||||
//屏幕大小改变时发生的改变
|
||||
game._onresizeAction();
|
||||
}
|
||||
//计算距离
|
||||
function distance(x1, y1, x2, y2) {
|
||||
return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
|
||||
}
|
||||
var game = new Game();
|
||||
//# sourceMappingURL=Game.js.map
|
||||
1
games/laya-snakes/js/Game.js.map
Normal file
1
games/laya-snakes/js/Game.js.map
Normal file
File diff suppressed because one or more lines are too long
61
games/laya-snakes/js/GameMain.js
Normal file
61
games/laya-snakes/js/GameMain.js
Normal file
@@ -0,0 +1,61 @@
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
/**
|
||||
* GameMain extends ui.GameMainUI
|
||||
*/
|
||||
var GameMain = (function (_super) {
|
||||
__extends(GameMain, _super);
|
||||
function GameMain() {
|
||||
_super.call(this);
|
||||
this.keySpaceDown = false;
|
||||
this.init();
|
||||
}
|
||||
GameMain.prototype.init = function () {
|
||||
this.ctrl_flash.on("mousedown", this.ctrl_flash, this.ctrlFlashDown);
|
||||
this.ctrl_flash.on("mouseup", this.ctrl_flash, this.ctrlFlashUp);
|
||||
Laya.stage.on("mouseup", this, this.ctrlRockerUp);
|
||||
Laya.stage.on("mousemove", this, this.ctrlRockerDown);
|
||||
Laya.stage.on("keydown", this, this.keyDown);
|
||||
Laya.stage.on("keyup", this, this.keyUp);
|
||||
};
|
||||
GameMain.prototype.keyUp = function (e) {
|
||||
if (e.keyCode == 32) {
|
||||
this.ctrlFlashUp();
|
||||
}
|
||||
};
|
||||
GameMain.prototype.keyDown = function (e) {
|
||||
if (e.keyCode == 32) {
|
||||
this.ctrlFlashDown();
|
||||
}
|
||||
};
|
||||
GameMain.prototype.ctrlFlashDown = function () {
|
||||
game.snakeSelf.speedNow = "fast";
|
||||
};
|
||||
GameMain.prototype.ctrlFlashUp = function () {
|
||||
game.snakeSelf.speedNow = "slow";
|
||||
};
|
||||
GameMain.prototype.ctrlRockerUp = function () {
|
||||
if (Laya.stage.mouseX <= game.stageW / 1.5) {
|
||||
this.ctrl_rocker.visible = true;
|
||||
this.ctrl_rocker_move.visible = false;
|
||||
}
|
||||
};
|
||||
GameMain.prototype.ctrlRockerDown = function () {
|
||||
if (Laya.stage.mouseX <= game.stageW / 1.5) {
|
||||
this.ctrl_rocker.visible = false;
|
||||
this.ctrl_rocker_move.visible = true;
|
||||
if (distance(Laya.stage.mouseX, Laya.stage.mouseY, this.ctrl_back.x, this.ctrl_back.y) <= (this.ctrl_back.width / 2 - this.ctrl_rocker.width / 2)) {
|
||||
this.ctrl_rocker_move.pos(Laya.stage.mouseX, Laya.stage.mouseY);
|
||||
}
|
||||
else {
|
||||
this.ctrl_rocker_move.pos(this.ctrl_back.x + (this.ctrl_back.width / 2 - this.ctrl_rocker.width / 2) * Math.cos(Math.atan2(Laya.stage.mouseY - this.ctrl_back.y, Laya.stage.mouseX - this.ctrl_back.x)), this.ctrl_back.y + (this.ctrl_back.width / 2 - this.ctrl_rocker.width / 2) * Math.sin(Math.atan2(Laya.stage.mouseY - this.ctrl_back.y, Laya.stage.mouseX - this.ctrl_back.x)));
|
||||
}
|
||||
game.snakeSelf.targetR = Math.atan2(Laya.stage.mouseY - this.ctrl_back.y, Laya.stage.mouseX - this.ctrl_back.x) * 180 / Math.PI;
|
||||
}
|
||||
};
|
||||
return GameMain;
|
||||
}(ui.GameMainUI));
|
||||
//# sourceMappingURL=GameMain.js.map
|
||||
1
games/laya-snakes/js/GameMain.js.map
Normal file
1
games/laya-snakes/js/GameMain.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GameMain.js","sourceRoot":"","sources":["../../src/GameMain.ts"],"names":[],"mappings":";;;;;AAAA;;GAEG;AACH;IAAuB,4BAAa;IAIhC;QACI,iBAAO,CAAA;QAHX,iBAAY,GAAY,KAAK,CAAA;QAIzB,IAAI,CAAC,IAAI,EAAE,CAAA;IACf,CAAC;IAED,uBAAI,GAAJ;QACI,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;QACpE,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;QAChE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;QACjD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,WAAW,EAAC,I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;YACD,IAAI,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,CAAA;QACnI,CAAC;IACL,CAAC;IAGL,eAAC;AAAD,CAAC,AA5DD,CAAuB,EAAE,CAAC,UAAU,GA4DnC"}
|
||||
49
games/laya-snakes/js/GameStart.js
Normal file
49
games/laya-snakes/js/GameStart.js
Normal file
@@ -0,0 +1,49 @@
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
/**
|
||||
* GameStart extends ui.GameStartUI
|
||||
*/
|
||||
var GameStart = (function (_super) {
|
||||
__extends(GameStart, _super);
|
||||
function GameStart() {
|
||||
_super.call(this);
|
||||
this.init();
|
||||
}
|
||||
GameStart.prototype.init = function () {
|
||||
this.nickname.label = "游客" + Math.floor(Math.random() * (9999 - 1 + 1) + 1);
|
||||
this.skinRadio.selectedIndex = Math.floor(Math.random() * (4 - 0 + 1) + 0);
|
||||
this.neturl.label = "192.168.1.60";
|
||||
LocalStorage.getItem("nickname") && (this.nickname.label = LocalStorage.getItem("nickname"));
|
||||
LocalStorage.getItem("neturl") && (this.neturl.label = LocalStorage.getItem("neturl"));
|
||||
LocalStorage.getItem("skin") && (this.skinRadio.selectedIndex = parseInt(LocalStorage.getItem("skin")));
|
||||
this.nickname.on("click", this, this.changeNickName);
|
||||
this.neturl.on("click", this, this.changeNetUrl);
|
||||
this.skinRadio.on("click", this, this.onSelectSkin);
|
||||
};
|
||||
GameStart.prototype.changeNickName = function () {
|
||||
var nickname = window.prompt("请输入您的昵称!", this.nickname.label);
|
||||
if (nickname != null && nickname != "") {
|
||||
this.nickname.label = nickname;
|
||||
}
|
||||
else {
|
||||
Browser.window.alert("请输入昵称!");
|
||||
}
|
||||
};
|
||||
GameStart.prototype.changeNetUrl = function () {
|
||||
var neturl = window.prompt("请输入服务器地址!", this.neturl.label);
|
||||
if (neturl != null && neturl != "") {
|
||||
this.neturl.label = neturl;
|
||||
}
|
||||
else {
|
||||
Browser.window.alert("请输入服务器地址!");
|
||||
}
|
||||
};
|
||||
GameStart.prototype.onSelectSkin = function () {
|
||||
// Browser.window.alert(this.skinRadio.selectedIndex)
|
||||
};
|
||||
return GameStart;
|
||||
}(ui.GameStartUI));
|
||||
//# sourceMappingURL=GameStart.js.map
|
||||
1
games/laya-snakes/js/GameStart.js.map
Normal file
1
games/laya-snakes/js/GameStart.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GameStart.js","sourceRoot":"","sources":["../../src/GameStart.ts"],"names":[],"mappings":";;;;;AAAA;;GAEG;AACH;IAAwB,6BAAc;IAClC;QACI,iBAAO,CAAA;QACP,IAAI,CAAC,IAAI,EAAE,CAAA;IACf,CAAC;IAED,wBAAI,GAAJ;QACI,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QAC3E,IAAI,CAAC,SAAS,CAAC,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QAC1E,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,cAAc,CAAA;QAClC,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,GAA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C,CAAC,CAAC;YACjC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,MAAM,CAAA;QAC9B,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QACrC,CAAC;IACL,CAAC;IAED,gCAAY,GAAZ;QACI,qDAAqD;IACzD,CAAC;IACL,gBAAC;AAAD,CAAC,AAzCD,CAAwB,EAAE,CAAC,WAAW,GAyCrC"}
|
||||
187
games/laya-snakes/js/Snake.js
Normal file
187
games/laya-snakes/js/Snake.js
Normal file
@@ -0,0 +1,187 @@
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
/**
|
||||
* Snake extends laya.display.Sprite
|
||||
*/
|
||||
var Snake = (function (_super) {
|
||||
__extends(Snake, _super);
|
||||
function Snake(colorNum, x, y) {
|
||||
if (colorNum === void 0) { colorNum = Math.floor(Math.random() * (5 - 1 + 1) + 1); }
|
||||
if (x === void 0) { x = game.gameMainUI.map.width / 2; }
|
||||
if (y === void 0) { y = game.gameMainUI.map.height / 2; }
|
||||
_super.call(this);
|
||||
this.speedObj = { "slow": 2, "fast": 4, "rotation": 10 };
|
||||
this.speedNow = "slow";
|
||||
this.snakeInitSize = 0.45;
|
||||
this.snakeLength = 24;
|
||||
this.kill = 0;
|
||||
this.bodyArr = [];
|
||||
this.pathArr = [];
|
||||
this.eatBean = 0;
|
||||
this.bodyBeanNum = 6; //吃几颗豆增加一节身体
|
||||
this.bodyMaxNum = 500;
|
||||
this.initWidth = 40;
|
||||
this.AI = false;
|
||||
this.speed = this.speedObj[this.speedNow];
|
||||
this.targetR = this.rotation;
|
||||
this.colorNum = colorNum;
|
||||
this.visible = false;
|
||||
this.snakeSize = this.snakeInitSize;
|
||||
this.loadImage("images/head" + this.colorNum + ".png", 0, 0, 0, 0, new Handler(this, this.loaded, [x, y]));
|
||||
}
|
||||
Snake.prototype.loaded = function (x, y) {
|
||||
this.zOrder = 11000;
|
||||
this.initWidth = this.width;
|
||||
this.rotationTemp = this.rotation;
|
||||
this.snakeScale(this);
|
||||
this.pivot(this.width / 2, this.height / 2);
|
||||
this.pos(x, y);
|
||||
this.visible = true;
|
||||
this.bodySpace = Math.floor(this.width / 10 * 8);
|
||||
for (var index = 1; index <= this.getBodyNum(); index++) {
|
||||
this.addBody(this.x - index * this.bodySpace, this.y, this.rotation);
|
||||
}
|
||||
for (var index = 0; index < this.bodySpace * this.getBodyNum(); index++) {
|
||||
this.pathArr.push({
|
||||
x: this.x - index,
|
||||
y: this.y
|
||||
});
|
||||
}
|
||||
};
|
||||
Snake.prototype.move = function () {
|
||||
this.bodySpace = Math.floor(this.width / 10 * 8);
|
||||
this.headMove();
|
||||
this.bodyMove();
|
||||
this.speedChange();
|
||||
this.rotationChange();
|
||||
this.bodyCheck();
|
||||
};
|
||||
Snake.prototype.moveOut = function () {
|
||||
//碰到边界了
|
||||
};
|
||||
Snake.prototype.headMove = function () {
|
||||
var x = this.speed * Math.cos(this.rotation * Math.PI / 180);
|
||||
var y = this.speed * Math.sin(this.rotation * Math.PI / 180);
|
||||
this.rotation = this.rotationTemp;
|
||||
var pos = { x: this.x, y: this.y };
|
||||
var posBefore = { x: this.x, y: this.y };
|
||||
if (!(this.x + x >= game.gameMainUI.map.width - this.width / 2 || this.x + x <= this.width / 2)) {
|
||||
this.x += x;
|
||||
pos.x = this.x;
|
||||
}
|
||||
else {
|
||||
this.moveOut();
|
||||
}
|
||||
if (!(this.y + y >= game.gameMainUI.map.height - this.width / 2 || this.y + y <= this.width / 2)) {
|
||||
this.y += y;
|
||||
pos.y = this.y;
|
||||
}
|
||||
else {
|
||||
this.moveOut();
|
||||
}
|
||||
for (var index = 1; index <= this.speed; index++) {
|
||||
this.pathArr.unshift({
|
||||
x: index * Math.cos(Math.atan2(pos.y - posBefore.y, pos.x - posBefore.x)) + posBefore.x,
|
||||
y: index * Math.sin(Math.atan2(pos.y - posBefore.y, pos.x - posBefore.x)) + posBefore.y
|
||||
});
|
||||
}
|
||||
};
|
||||
Snake.prototype.bodyMove = function () {
|
||||
for (var index = 0; index < this.bodyArr.length; index++) {
|
||||
var element = this.bodyArr[index];
|
||||
if (this.pathArr[(index + 1) * this.bodySpace]) {
|
||||
element.rotation = Math.atan2(this.pathArr[(index + 1) * this.bodySpace]["y"] - element.y, this.pathArr[(index + 1) * this.bodySpace]["x"] - element.x) / Math.PI * 180;
|
||||
element.pos(this.pathArr[(index + 1) * this.bodySpace]["x"], this.pathArr[(index + 1) * this.bodySpace]["y"]);
|
||||
}
|
||||
if (this.pathArr.length > this.bodyArr.length * (1 + this.bodySpace)) {
|
||||
this.pathArr.pop();
|
||||
}
|
||||
}
|
||||
};
|
||||
Snake.prototype.snakeScale = function (ele, eleType) {
|
||||
if (eleType === void 0) { eleType = "head"; }
|
||||
var x = ele.x, y = ele.y, zOrder = ele.zOrder;
|
||||
ele.pivot(ele.width / 2, ele.height / 2);
|
||||
ele.graphics.clear();
|
||||
ele.loadImage("images/" + eleType + this.colorNum + ".png", 0, 0, this.initWidth * this.snakeSize, this.initWidth * this.snakeSize);
|
||||
ele.pivot(ele.width / 2, ele.height / 2);
|
||||
ele.pos(x, y);
|
||||
this.speedObj["rotation"] = 4 / this.snakeSize;
|
||||
};
|
||||
Snake.prototype.speedChange = function () {
|
||||
this.speed = this.speedNow == 'slow' ?
|
||||
(this.speed > this.speedObj[this.speedNow] ? this.speed - 1 : this.speedObj[this.speedNow])
|
||||
: (this.speed < this.speedObj[this.speedNow] ? this.speed + 1 : this.speedObj[this.speedNow]);
|
||||
};
|
||||
Snake.prototype.rotationChange = function () {
|
||||
var perRotation = Math.abs(this.targetR - this.rotationTemp) < this.speedObj['rotation'] ? Math.abs(this.targetR - this.rotationTemp) : this.speedObj['rotation'];
|
||||
if (this.targetR < -0 && this.rotationTemp > 0 && Math.abs(this.targetR) + this.rotationTemp > 180) {
|
||||
perRotation = (180 - this.rotationTemp) + (180 + this.targetR) < this.speedObj['rotation'] ? (180 - this.rotationTemp) + (180 + this.targetR) : this.speedObj['rotation'];
|
||||
this.rotationTemp += perRotation;
|
||||
}
|
||||
else {
|
||||
this.rotationTemp += this.targetR > this.rotationTemp && Math.abs(this.targetR - this.rotationTemp) <= 180 ? perRotation : -perRotation;
|
||||
}
|
||||
this.rotationTemp = Math.abs(this.rotationTemp) > 180 ? (this.rotationTemp > 0 ? this.rotationTemp - 360 : this.rotationTemp + 360) : this.rotationTemp;
|
||||
};
|
||||
Snake.prototype.addBody = function (x, y, r) {
|
||||
var _this = this;
|
||||
var body = new Sprite();
|
||||
var zOrder = this.zOrder - this.bodyArr.length - 1;
|
||||
body.visible = false;
|
||||
body.alpha = 0;
|
||||
body.zOrder = zOrder;
|
||||
body.loadImage("images/body" + this.colorNum + ".png", 0, 0, 0, 0, new Handler(this, function () {
|
||||
_this.snakeScale(body, "body");
|
||||
body.pos(x, y);
|
||||
body.rotation = r;
|
||||
game.gameMainUI.map.addChild(body);
|
||||
body.visible = true;
|
||||
body.alpha = 1;
|
||||
}));
|
||||
this.bodyArr.push(body);
|
||||
};
|
||||
Snake.prototype.bodyCheck = function () {
|
||||
var _this = this;
|
||||
if (this.eatBean >= this.bodyBeanNum && this.bodyArr.length < this.bodyMaxNum) {
|
||||
var addBodyNum = Math.floor(this.eatBean / this.bodyBeanNum);
|
||||
var x = this.bodyArr[this.bodyArr.length - 1].x;
|
||||
var y = this.bodyArr[this.bodyArr.length - 1].y;
|
||||
var r = this.bodyArr[this.bodyArr.length - 1].rotation;
|
||||
for (var index = 0; index < addBodyNum; index++) {
|
||||
this.addBody(this.bodySpace * Math.cos(r * Math.PI / 180), this.bodySpace * Math.sin(r * Math.PI / 180), r);
|
||||
}
|
||||
for (var index = 0; index < this.bodySpace * addBodyNum; index++) {
|
||||
this.pathArr.push({
|
||||
x: this.x - index * Math.cos(r * Math.PI / 180),
|
||||
y: this.y - index * Math.sin(r * Math.PI / 180)
|
||||
});
|
||||
}
|
||||
this.eatBean = this.eatBean % this.bodyBeanNum;
|
||||
if (this.snakeSize < 1) {
|
||||
this.snakeSize = this.snakeInitSize + (1 - this.snakeInitSize) / this.bodyMaxNum * this.bodyArr.length;
|
||||
this.bodyArr.forEach(function (element) {
|
||||
_this.snakeScale(element, "body");
|
||||
});
|
||||
// for (let index = this.bodyArr.length - 1; index >= 0; index--) {
|
||||
// this.snakeScale(this.bodyArr[index], "body")
|
||||
// }
|
||||
this.snakeScale(this);
|
||||
}
|
||||
else {
|
||||
this.snakeSize = 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
Snake.prototype.getBodyNum = function () {
|
||||
return Math.floor(this.snakeLength / this.bodyBeanNum);
|
||||
};
|
||||
Snake.prototype.reverseRotation = function () {
|
||||
this.targetR = this.rotation > 0 ? this.rotation - 180 : this.rotation + 180;
|
||||
};
|
||||
return Snake;
|
||||
}(laya.display.Sprite));
|
||||
//# sourceMappingURL=Snake.js.map
|
||||
1
games/laya-snakes/js/Snake.js.map
Normal file
1
games/laya-snakes/js/Snake.js.map
Normal file
File diff suppressed because one or more lines are too long
40
games/laya-snakes/js/ui/layaUI.max.all.js
Normal file
40
games/laya-snakes/js/ui/layaUI.max.all.js
Normal file
@@ -0,0 +1,40 @@
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
var View = laya.ui.View;
|
||||
var Dialog = laya.ui.Dialog;
|
||||
var ui;
|
||||
(function (ui) {
|
||||
var GameMainUI = (function (_super) {
|
||||
__extends(GameMainUI, _super);
|
||||
function GameMainUI() {
|
||||
_super.call(this);
|
||||
}
|
||||
GameMainUI.prototype.createChildren = function () {
|
||||
_super.prototype.createChildren.call(this);
|
||||
this.createView(ui.GameMainUI.uiView);
|
||||
};
|
||||
GameMainUI.uiView = { "type": "View", "props": {}, "child": [{ "type": "Image", "props": { "var": "map", "skin": "map/tile_map.png", "pivotY": 750, "pivotX": 1500 } }, { "type": "Label", "props": { "y": 10, "x": 10, "text": "长度:" } }, { "type": "Label", "props": { "y": 10, "x": 44, "var": "text_length", "text": "0" } }, { "type": "Label", "props": { "y": 26, "x": 10, "text": "击杀:" } }, { "type": "Label", "props": { "y": 26, "x": 44, "var": "text_kill", "text": "0" } }, { "type": "Image", "props": { "y": 10, "x": 489, "width": 102, "var": "mask_rank", "skin": "images/mask.png", "height": 133 } }, { "type": "Button", "props": { "y": 321, "x": 511, "var": "ctrl_flash", "stateNum": "2", "skin": "images/control-flash.png", "pivotY": 40, "pivotX": 40 } }, { "type": "Image", "props": { "y": 329, "x": 85, "var": "ctrl_back", "skin": "images/control-back.png", "pivotY": 40, "pivotX": 40 }, "child": [{ "type": "Image", "props": { "y": 40, "x": 40, "var": "ctrl_rocker", "skin": "images/control-rocker.png", "pivotY": 17.5, "pivotX": 17.5 } }] }, { "type": "Image", "props": { "y": 357, "x": -32, "visible": false, "var": "ctrl_rocker_move", "skin": "images/control-rocker.png", "pivotY": 17.5, "pivotX": 17.5 } }] };
|
||||
return GameMainUI;
|
||||
}(View));
|
||||
ui.GameMainUI = GameMainUI;
|
||||
})(ui || (ui = {}));
|
||||
var ui;
|
||||
(function (ui) {
|
||||
var GameStartUI = (function (_super) {
|
||||
__extends(GameStartUI, _super);
|
||||
function GameStartUI() {
|
||||
_super.call(this);
|
||||
}
|
||||
GameStartUI.prototype.createChildren = function () {
|
||||
_super.prototype.createChildren.call(this);
|
||||
this.createView(ui.GameStartUI.uiView);
|
||||
};
|
||||
GameStartUI.uiView = { "type": "View", "props": { "skin": "images/head2.png" }, "child": [{ "type": "Image", "props": { "var": "background", "skin": "images/s1-background.jpg", "pivotY": 297, "pivotX": 594, "name": "background" }, "child": [{ "type": "Image", "props": { "y": 204.5, "x": 394.5, "width": 399, "skin": "images/s1-option-background.png", "name": "option_background", "height": 211 }, "child": [{ "type": "RadioGroup", "props": { "y": 50, "x": 51, "var": "skinRadio", "space": -3, "skin": "images/s1-radio.png", "selectedIndex": 0, "labels": " 红色, 蓝色, 绿色, 紫色, 棕色", "labelPadding": "4", "direction": "vertical" } }, { "type": "Image", "props": { "y": 54, "x": 133, "width": 12, "skin": "images/head1.png", "rotation": 90, "height": 12 } }, { "type": "Image", "props": { "y": 75, "x": 133, "width": 12, "skin": "images/head2.png", "rotation": 90, "height": 12 } }, { "type": "Image", "props": { "y": 97, "x": 133, "width": 12, "skin": "images/head3.png", "rotation": 90, "height": 12 } }, { "type": "Image", "props": { "y": 118, "x": 133, "width": 12, "skin": "images/head4.png", "rotation": 90, "height": 12 } }, { "type": "Image", "props": { "y": 139, "x": 133, "width": 12, "skin": "images/head5.png", "rotation": 90, "height": 12 } }, { "type": "Button", "props": { "y": 14, "x": 234, "var": "btn_single", "stateNum": "1", "skin": "images/s1-btn1.png", "labelPadding": "-20", "labelBold": true, "label": "单人模式" } }, { "type": "Button", "props": { "y": 113, "x": 234, "var": "btn_net", "stateNum": "1", "skin": "images/s1-btn2.png", "labelPadding": "-20", "labelBold": true, "label": "多人模式" } }, { "type": "Button", "props": { "y": 13, "x": 46, "width": 126, "var": "nickname", "stateNum": "1", "skin": "images/s1-input.png", "label": "昵称", "height": 24 } }, { "type": "Button", "props": { "y": 166, "x": 46, "width": 126, "var": "neturl", "stateNum": "1", "skin": "images/s1-input.png", "label": "192.168.1.60", "height": 24 } }, { "type": "Label", "props": { "y": -31, "x": 139.5, "text": "贪吃蛇小作战", "fontSize": 20, "font": "Microsoft Yahei", "color": "#226eaa", "bold": true } }, { "type": "TextInput", "props": { "y": 190.5, "x": 161.5, "text": "TextInput", "skin": "comp/textinput.png" } }] }] }] };
|
||||
return GameStartUI;
|
||||
}(View));
|
||||
ui.GameStartUI = GameStartUI;
|
||||
})(ui || (ui = {}));
|
||||
//# sourceMappingURL=layaUI.max.all.js.map
|
||||
1
games/laya-snakes/js/ui/layaUI.max.all.js.map
Normal file
1
games/laya-snakes/js/ui/layaUI.max.all.js.map
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user