(function() {
var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
var __module = nodeEnv ? module : {exports:{}};
var __filename = 'preview-scripts/assets/Script/Board.js';
var __require = nodeEnv ? function (request) {
return cc.require(request);
} : function (request) {
return __quick_compile_project__.require(request, __filename);
};
function __define (exports, require, module) {
if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}"use strict";
cc._RF.push(module, '1c7c7LZfzlJ+KsTeDoZeUH6', 'Board');
// Script/Board.ts
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Config_1 = require("./Config");
var MapItem_1 = require("./MapItem");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var Board = /** @class */ (function (_super) {
__extends(Board, _super);
function Board() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.scoreLabel = null;
_this.tileContainer = null;
_this.hexSide = 5;
_this.tileHight = 120;
// 整体向上偏移 250
_this.posY = 250;
_this.mapItem = null;
_this.theScore = 0;
// 方便查找元素并消除
_this.hashMap = new Map();
// 存放每个节点
_this._boardFrameList = [];
return _this;
}
Object.defineProperty(Board.prototype, "boardFrameList", {
get: function () {
return this._boardFrameList;
},
set: function (boardFrameList) {
this._boardFrameList = boardFrameList;
},
enumerable: true,
configurable: true
});
Board.prototype.onLoad = function () {
this.theScore = 0;
this.updateScore();
this.setHexagonMap();
};
Board.prototype.updateScore = function () {
this.scoreLabel.string = "Score:" + this.theScore;
};
Board.prototype.setHexagonMap = function () {
this.hexSide--;
for (var q = -this.hexSide; q <= this.hexSide; q++) {
var r1 = Math.max(-this.hexSide, -q - this.hexSide);
var r2 = Math.min(this.hexSide, -q + this.hexSide);
for (var r = r1; r <= r2; r++) {
var pos = this.hex2pixel({ q: q, r: r }, this.tileHight);
var index = this.hex2index(q, r);
this.setUpMapItem(pos, index);
}
}
};
Board.prototype.hex2index = function (q, r) {
// 棋盘六角网格,坐标系转换一维 Map 下标
// 二维 q r 下标转换为 一维 Map 下标
return (q + this.hexSide) * (this.hexSide * 2 + 1) + r + this.hexSide;
};
Board.prototype.hex2pixel = function (hex, h) {
// 棋盘六角网格,坐标系转换像素方法
var size = h / 2;
var x = size * Math.sqrt(3) * (hex.q + hex.r / 2);
var y = ((size * 3) / 2) * hex.r + this.posY;
return cc.v2(x, y);
};
Board.prototype.setUpMapItem = function (pos, index) {
var node = cc.instantiate(this.mapItem);
var mapItem = node.getComponent(MapItem_1.default);
mapItem.color = Config_1.COLOR.LIGHTGRAY;
node.position = pos;
node.parent = this.node;
mapItem.isFill = false;
mapItem.position = pos;
this.boardFrameList.push(mapItem);
this.hashMap[index] = mapItem;
};
Board.prototype.resetBoard = function () {
// 恢复初始状态
for (var q = -this.hexSide; q <= this.hexSide; q++) {
var r1 = Math.max(-this.hexSide, -q - this.hexSide);
var r2 = Math.min(this.hexSide, -q + this.hexSide);
for (var r = r1; r <= r2; r++) {
var index = this.hex2index(q, r);
var tem = this.hashMap[index];
tem.color = Config_1.COLOR.LIGHTGRAY;
tem.opacity = 255;
tem.isFill = false;
}
}
};
Board.prototype.gainScore = function () {
var num = 0;
// 存放要消除的元素
var fillTiles = [];
// 按 q 遍历 左斜线
for (var q = -this.hexSide; q <= this.hexSide; q++) {
var r1 = Math.max(-this.hexSide, -q - this.hexSide);
var r2 = Math.min(this.hexSide, -q + this.hexSide);
var flag = true;
for (var r = r1; r <= r2; r++) {
var index = this.hex2index(q, r);
var tem = this.hashMap[index];
if (!tem.isFill) {
flag = false;
break;
}
}
if (flag) {
num++;
for (var r = r1; r <= r2; r++) {
var index = this.hex2index(q, r);
var tem = this.hashMap[index];
fillTiles.push(tem);
}
}
}
// 按 r 遍历 直线
for (var r = -this.hexSide; r <= this.hexSide; r++) {
var q1 = Math.max(-this.hexSide, -r - this.hexSide);
var q2 = Math.min(this.hexSide, -r + this.hexSide);
var flag = true;
for (var q = q1; q <= q2; q++) {
var index = this.hex2index(q, r);
var tem = this.hashMap[index];
if (!tem.isFill) {
flag = false;
break;
}
}
if (flag) {
num++;
for (var q = q1; q <= q2; q++) {
var index = this.hex2index(q, r);
var tem = this.hashMap[index];
fillTiles.push(tem);
}
}
}
// 按 q+r 遍历 右斜线
for (var s = -this.hexSide; s <= this.hexSide; s++) {
var q1 = 0;
var q2 = 0;
if (s > 0) {
q2 = this.hexSide;
q1 = s - q2;
}
else {
q1 = -this.hexSide;
q2 = s - q1;
}
var flag = true;
for (var q = q1; q <= q2; q++) {
var r = s - q;
var index = this.hex2index(q, r);
var tem = this.hashMap[index];
if (!tem.isFill) {
flag = false;
break;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
cocos 六边开拼图游戏代码
共224个文件
json:137个
png:28个
meta:15个
需积分: 5 0 下载量 170 浏览量
2023-12-09
18:14:43
上传
评论
收藏 880KB ZIP 举报
温馨提示
cocos 六边开拼图游戏代码,可以运行的。博客文章地址:https://blog.csdn.net/nnmmbb/article/details/134809591?spm=1001.2014.3001.5501 六边形游戏的鼻祖应该是这个 hex-frvr,原作者开发用的是 pixi 游戏引擎,本着快速开发的理念,本游戏采用 cocos creator,UI 延用 hex-frvr。学习过程中,有借鉴各路实现。此源码仅供学习使用,谢谢。 六边形游戏本质是俄罗斯方块,理解这个对接下来的开发会有很大的帮助。 本游戏实现功能如下: [x] 六边形棋盘绘制、方块随机生成 [x] 方块能否落入棋盘的判定 [x] 方块消除与游戏结束的判定 [x] 各种动画效果 [x] 游戏计分
资源推荐
资源详情
资源评论
收起资源包目录
cocos 六边开拼图游戏代码 (224个子文件)
a579b610-0aa7-4a8b-b36b-be34cc834dcc.bin 157KB
buffer.bin 157KB
83f5eff8-3385-4f95-9b76-8da0aa1d96cd.bin 48KB
14c74869-bdb4-4f57-86d8-a7875de2be30.bin 46KB
3bbdb0f6-c5f6-45de-9f33-8b5cbafb4d6d.bin 46KB
b430cea3-6ab3-4106-b073-26c698918edd.bin 7KB
a1ef2fc9-9c57-418a-8f69-6bed9a7a0e7f.bin 5KB
7a17de6e-227a-46b1-8009-e7157d4d3acf.bin 4KB
046f172c-1574-488b-bbb8-6415a9adb96d.bin 840B
e93d3fa9-8c21-4375-8a21-14ba84066c77.bin 140B
Game.fire 18KB
Game.fire 18KB
.gitignore 1KB
ecede5dca290f8dabd60b5922772672b.gltf 19KB
Board.js 34KB
TileItem.js 22KB
Config.js 11KB
1c7c72d9-7f39-49f8-ab13-783a197941fa.js 10KB
Board.js 10KB
d2eaad99-c20c-4663-8e96-d9e1508d765f.js 8KB
TileItem.js 8KB
MapItem.js 7KB
__quick_compile__.js 5KB
90c7b078-903c-48b2-9440-95b2287a2a21.js 3KB
MapItem.js 3KB
47db71eb-4b0f-44d5-b7ea-8333daeca23f.js 2KB
Config.js 2KB
__qc_index__.js 1KB
__qc_index__.js 143B
829a282c-b049-4019-bd38-5ace8d8a6417.json 87KB
e2f00085-c597-422d-9759-52c360279106.json 51KB
abc2cb62-7852-4525-a90d-d474487b88f2.json 51KB
70bbeb73-6dc2-4ee4-8faf-76b3a0e34ec4.json 35KB
2a7c0036-e0b3-4fe1-8998-89a54b8a2bec.json 27KB
d1b8be49-b0a0-435c-83b7-552bed4bbe35.json 20KB
bf0a434c-84dd-4a8e-a08a-7a36f180cc75.json 20KB
6d91e591-4ce0-465c-809f-610ec95019c6.json 19KB
a53b88f0-811e-40e4-861b-7f6039452f7e.json 18KB
uuid-to-mtime.json 16KB
ab2fdde9-10c2-44e4-bfe1-fcfcc1a86aa9.json 15KB
ca8401fe-ad6e-41a8-bd46-8e3e4e9945be.json 14KB
115286d1-2e10-49ee-aab4-341583f607e8.json 14KB
32044bd2-481f-4cf1-a656-e2b2fb1594eb.json 12KB
61aeb05b-3b32-452b-8eed-2b76deeed554.json 9KB
ed88f13d-fcad-4848-aa35-65a2cb973584.json 9KB
972b9a4d-47ee-4c74-b5c3-61d8a69bc29f.json 7KB
430eccbf-bf2c-4e6e-8c0c-884bbb487f32.json 7KB
0004d1cf-a0ad-47d8-ab17-34d3db9d35a3.json 7KB
0d784963-d024-4ea6-a7db-03be0ad63010.json 6KB
0e93aeaa-0b53-4e40-b8e0-6268b4e07bd7.json 6KB
89e4c65e-24ca-4fdf-916a-3810920973b3.json 5KB
2874f8dd-416c-4440-81b7-555975426e93.json 5KB
5965ffac-69da-4b55-bcde-9225d0613c28.json 4KB
6c5cf6e1-b044-4eac-9431-835644d57381.json 3KB
cd33edea-55f5-46c2-958d-357a01384a36.json 3KB
144c3297-af63-49e8-b8ef-1cfa29b3be28.json 3KB
954fec8b-cd16-4bb9-a3b7-7719660e7558.json 3KB
785a442c-3ceb-45be-a46e-7317f625f3b9.json 3KB
layout.editor.json 3KB
2c937608-2562-40ea-b264-7395df6f0cea.json 2KB
897ef7a1-4860-4f64-968d-f5924b18668a.json 2KB
70d7cdb0-04cd-41bb-9480-c06a4785f386.json 2KB
ddb99b39-7004-47cd-9705-751905c43c46.json 2KB
61906da3-7003-4bda-9abc-5769c76faee4.json 2KB
0cf30284-9073-46bc-9eba-e62b69dbbff3.json 2KB
f5331fd2-bf42-4ee3-a3fd-3e1657600eff.json 2KB
1f55e3be-b89b-4b79-88de-47fd31018044.json 2KB
96083d03-c332-4a3f-9386-d03e2d19e8ee.json 2KB
b5fc2cf2-7942-483d-be1f-bbeadc4714ad.json 2KB
232d2782-c4bd-4bb4-9e01-909f03d6d3b9.json 2KB
1c5e4038-953a-44c2-b620-0bbfc6170477.json 2KB
fe1417b6-fe6b-46a4-ae7c-9fd331f33a2a.json 2KB
2d9a4b85-b0ab-4c46-84c5-18f393ab2058.json 2KB
3f376125-a699-40ca-ad05-04d662eaa1f2.json 2KB
de510076-056b-484f-b94c-83bef217d0e1.json 2KB
6c9ef10d-b479-420b-bfe6-39cdda6a8ae0.json 2KB
a87cc147-01b2-43f8-8e42-a7ca90b0c757.json 2KB
4a37dd57-78cd-4cec-aad4-f11a73d12b63.json 2KB
27756ebb-3d33-44b0-9b96-e858fadd4dd4.json 2KB
17fdced1-c8f7-48a1-b126-575bdb866562.json 2KB
8c5001fd-07ee-4a4b-a8a0-63e15195e94d.json 2KB
0e42ba95-1fa1-46aa-b2cf-143cd1bcee2c.json 2KB
7de03a80-4457-438d-95a7-3e7cdffd6086.json 2KB
14c74869-bdb4-4f57-86d8-a7875de2be30.json 1KB
7a17de6e-227a-46b1-8009-e7157d4d3acf.json 1KB
3bbdb0f6-c5f6-45de-9f33-8b5cbafb4d6d.json 1KB
83f5eff8-3385-4f95-9b76-8da0aa1d96cd.json 1KB
046f172c-1574-488b-bbb8-6415a9adb96d.json 1KB
b430cea3-6ab3-4106-b073-26c698918edd.json 1KB
e93d3fa9-8c21-4375-8a21-14ba84066c77.json 1KB
a1ef2fc9-9c57-418a-8f69-6bed9a7a0e7f.json 1KB
c0040c95-c57f-49cd-9cbc-12316b73d0d4.json 1KB
432fa09c-cf03-4cff-a186-982604408a07.json 864B
project.json 684B
a5849239-3ad3-41d1-8ab4-ae9fea11f97f.json 424B
2a296057-247c-4a1c-bbeb-0548b6c98650.json 406B
tsconfig.json 386B
5fe5dcaa-b513-4dc5-a166-573627b3a159.json 379B
5c3bb932-6c3c-468f-88a9-c8c61d458641.json 376B
29158224-f8dd-4661-a796-1ffab537140e.json 372B
共 224 条
- 1
- 2
- 3
资源评论
汤米粥
- 粉丝: 251
- 资源: 37
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功