Commit c2d02291 authored by Nguyễn Quang Sáng's avatar Nguyễn Quang Sáng

09/10/23 commit

parent 8b846837
{
"__type__": "cc.AnimationClip",
"_name": "TapToPlay",
"_objFlags": 0,
"_native": "",
"_duration": 0.25,
"sample": 60,
"speed": 0.1,
"wrapMode": 2,
"curveData": {
"props": {
"scale": [
{
"frame": 0,
"value": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
}
},
{
"frame": 0.11666666666666667,
"value": {
"__type__": "cc.Vec3",
"x": 1.3,
"y": 1.3,
"z": 1
}
},
{
"frame": 0.25,
"value": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
}
}
]
}
},
"events": []
}
\ No newline at end of file
{
"ver": "2.1.2",
"uuid": "6bdaace5-4f0a-4fd2-922a-714f27be16a4",
"importer": "animation-clip",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.7",
"uuid": "3e5732c0-46c8-433b-813b-005de92eb2ab",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 175,
"height": 115,
"platformSettings": {},
"subMetas": {
"barGreen": {
"ver": "1.0.6",
"uuid": "4f2ea4de-c652-4ecf-82e2-d7cb3b344f08",
"importer": "sprite-frame",
"rawTextureUuid": "3e5732c0-46c8-433b-813b-005de92eb2ab",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": -1,
"trimX": 9,
"trimY": 11,
"width": 157,
"height": 95,
"rawWidth": 175,
"rawHeight": 115,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 45,
"borderRight": 47,
"subMetas": {}
}
}
}
\ No newline at end of file
{ {
"ver": "2.3.7", "ver": "2.3.7",
"uuid": "f8ad0a65-5ebe-4bf0-8b42-a831bb2020e2", "uuid": "218e4d7b-57d0-46de-89dc-13024c58f088",
"importer": "texture", "importer": "texture",
"type": "sprite", "type": "sprite",
"wrapMode": "clamp", "wrapMode": "clamp",
...@@ -8,15 +8,15 @@ ...@@ -8,15 +8,15 @@
"premultiplyAlpha": false, "premultiplyAlpha": false,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 54, "width": 129,
"height": 38, "height": 68,
"platformSettings": {}, "platformSettings": {},
"subMetas": { "subMetas": {
"startPoint": { "barRed": {
"ver": "1.0.6", "ver": "1.0.6",
"uuid": "198639e5-9950-4d01-b8c5-732441df6eab", "uuid": "275cde9d-9690-4a29-888f-a7afc78f5a09",
"importer": "sprite-frame", "importer": "sprite-frame",
"rawTextureUuid": "f8ad0a65-5ebe-4bf0-8b42-a831bb2020e2", "rawTextureUuid": "218e4d7b-57d0-46de-89dc-13024c58f088",
"trimType": "auto", "trimType": "auto",
"trimThreshold": 1, "trimThreshold": 1,
"rotated": false, "rotated": false,
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
"offsetY": 0, "offsetY": 0,
"trimX": 0, "trimX": 0,
"trimY": 0, "trimY": 0,
"width": 54, "width": 129,
"height": 38, "height": 68,
"rawWidth": 54, "rawWidth": 129,
"rawHeight": 38, "rawHeight": 68,
"borderTop": 0, "borderTop": 0,
"borderBottom": 0, "borderBottom": 0,
"borderLeft": 0, "borderLeft": 0,
......
{
"ver": "2.3.7",
"uuid": "e163aae5-6ef4-4807-921f-14e6bcfa3590",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 76,
"height": 76,
"platformSettings": {},
"subMetas": {
"circleRed": {
"ver": "1.0.6",
"uuid": "54a46da2-0226-4624-b0b2-646221c8bbfd",
"importer": "sprite-frame",
"rawTextureUuid": "e163aae5-6ef4-4807-921f-14e6bcfa3590",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 76,
"height": 76,
"rawWidth": 76,
"rawHeight": 76,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{ {
"ver": "2.3.7", "ver": "2.3.7",
"uuid": "278f55a6-a5ac-4eaa-af71-235a558a7a3a", "uuid": "85d64a28-9537-4577-922d-f764ed0ac74f",
"importer": "texture", "importer": "texture",
"type": "sprite", "type": "sprite",
"wrapMode": "clamp", "wrapMode": "clamp",
...@@ -8,15 +8,15 @@ ...@@ -8,15 +8,15 @@
"premultiplyAlpha": false, "premultiplyAlpha": false,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 33, "width": 70,
"height": 33, "height": 74,
"platformSettings": {}, "platformSettings": {},
"subMetas": { "subMetas": {
"plus": { "hammer": {
"ver": "1.0.6", "ver": "1.0.6",
"uuid": "a7b930b1-c853-41c8-99b7-7dc0ae10aa48", "uuid": "c8bfcc19-3ef5-473d-87ae-815666e2a409",
"importer": "sprite-frame", "importer": "sprite-frame",
"rawTextureUuid": "278f55a6-a5ac-4eaa-af71-235a558a7a3a", "rawTextureUuid": "85d64a28-9537-4577-922d-f764ed0ac74f",
"trimType": "auto", "trimType": "auto",
"trimThreshold": 1, "trimThreshold": 1,
"rotated": false, "rotated": false,
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
"offsetY": 0, "offsetY": 0,
"trimX": 0, "trimX": 0,
"trimY": 0, "trimY": 0,
"width": 33, "width": 70,
"height": 33, "height": 74,
"rawWidth": 33, "rawWidth": 70,
"rawHeight": 33, "rawHeight": 74,
"borderTop": 0, "borderTop": 0,
"borderBottom": 0, "borderBottom": 0,
"borderLeft": 0, "borderLeft": 0,
......
{
"ver": "2.3.7",
"uuid": "e5993cc3-8c4b-45f6-b2c3-4e189071369a",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 70,
"height": 70,
"platformSettings": {},
"subMetas": {
"nextBlock": {
"ver": "1.0.6",
"uuid": "3e63b730-46cd-4cda-950c-45a8033248d1",
"importer": "sprite-frame",
"rawTextureUuid": "e5993cc3-8c4b-45f6-b2c3-4e189071369a",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 70,
"height": 70,
"rawWidth": 70,
"rawHeight": 70,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.7",
"uuid": "dfe2d310-9bd5-4071-98d1-8d05155e83dc",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 55,
"height": 67,
"platformSettings": {},
"subMetas": {
"restart": {
"ver": "1.0.6",
"uuid": "f974169d-33c4-41e0-a354-2d4573ba8e41",
"importer": "sprite-frame",
"rawTextureUuid": "dfe2d310-9bd5-4071-98d1-8d05155e83dc",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 55,
"height": 67,
"rawWidth": 55,
"rawHeight": 67,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.7",
"uuid": "4af2df70-8616-4f52-ba51-e375be5237a3",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 57,
"height": 57,
"platformSettings": {},
"subMetas": {
"soundOFF": {
"ver": "1.0.6",
"uuid": "2fcf078b-37c9-4a22-9509-4602ff630f35",
"importer": "sprite-frame",
"rawTextureUuid": "4af2df70-8616-4f52-ba51-e375be5237a3",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 57,
"height": 57,
"rawWidth": 57,
"rawHeight": 57,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
This diff is collapsed.
import LocalStorage from "../Data/LocalStorage";
import GameController from "./GameController";
const { ccclass, property } = cc._decorator;
@ccclass
export default class ButtonsController extends cc.Component {
@property(cc.Button) pauseBtn: cc.Button = null;
@property(cc.Node) shadow: cc.Node = null;
@property(cc.Node) pauseScreen: cc.Node = null;
@property(cc.SpriteFrame) soundOffSpf: cc.SpriteFrame = null;
@property(cc.SpriteFrame) soundOnSpf: cc.SpriteFrame = null;
@property(cc.Node) soundBtn: cc.Node = null;
soundMode: boolean = true;
currentSoundSpf: cc.SpriteFrame = null;
protected onLoad(): void {
this.currentSoundSpf = this.soundBtn
.getChildByName("Icon")
.getComponent(cc.Sprite).spriteFrame;
if (LocalStorage.getMusic()) {
this.currentSoundSpf = this.soundOnSpf;
this.soundMode = true;
} else {
this.currentSoundSpf = this.soundOffSpf;
this.soundMode = false;
}
}
onClickPause() {
if (GameController.instance.isGamePaused) {
GameController.instance.isGamePaused = false;
this.shadow.active = false;
this.pauseScreen.active = false;
} else {
GameController.instance.isGamePaused = true;
this.shadow.active = true;
this.pauseScreen.active = true;
}
}
onClickRestart() {
cc.director.loadScene("gameplay");
}
onClickSound() {
console.log(this.currentSoundSpf);
if (this.soundMode) {
this.currentSoundSpf = this.soundOffSpf;
LocalStorage.setMusic(false);
this.soundMode = false;
} else {
this.currentSoundSpf = this.soundOnSpf;
LocalStorage.setMusic(true);
this.soundMode = true;
}
}
}
{
"ver": "1.1.0",
"uuid": "88a0c485-291a-492b-b469-a0ee0074f1f1",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import BlockData from "../Data/BlockData"; import BlockData from "../Data/BlockData";
import Score from "../Data/Score";
import Block from "../Objects/Block"; import Block from "../Objects/Block";
import Utils from "../Tools/Utils"; import Utils from "../Tools/Utils";
...@@ -10,6 +11,7 @@ export default class GameController extends cc.Component { ...@@ -10,6 +11,7 @@ export default class GameController extends cc.Component {
@property(cc.Node) board: cc.Node = null; @property(cc.Node) board: cc.Node = null;
@property(cc.Node) spawnBar: cc.Node = null; @property(cc.Node) spawnBar: cc.Node = null;
@property(BlockData) blocksData: BlockData = null; @property(BlockData) blocksData: BlockData = null;
@property(Score) scoreLbl: Score = null;
static instance: GameController; static instance: GameController;
...@@ -21,9 +23,12 @@ export default class GameController extends cc.Component { ...@@ -21,9 +23,12 @@ export default class GameController extends cc.Component {
dropColumn: number = 0; dropColumn: number = 0;
cellTarget: cc.Node = null; cellTarget: cc.Node = null;
spawnColumn: number = Utils.random(0, 4); spawnColumn: number = Utils.random(0, 4);
cachedBlocksToMerge: Array<cc.Node> = null; cachedBlocksToMove: Array<cc.Node> = null;
currentBlockRow: number = 0; currentBlockRow: number = 0;
currentBlockCol: number = 0; currentBlockCol: number = 0;
cacheBlockToMerge = [];
isGamePaused: boolean = false;
protected onLoad(): void { protected onLoad(): void {
GameController.instance = this; GameController.instance = this;
...@@ -66,6 +71,8 @@ export default class GameController extends cc.Component { ...@@ -66,6 +71,8 @@ export default class GameController extends cc.Component {
} }
onTouchDown(event: cc.Event.EventTouch) { onTouchDown(event: cc.Event.EventTouch) {
if (this.isGamePaused) return;
let touchTarget = event.currentTarget; let touchTarget = event.currentTarget;
this.dropPosX = touchTarget.x; this.dropPosX = touchTarget.x;
...@@ -81,7 +88,7 @@ export default class GameController extends cc.Component { ...@@ -81,7 +88,7 @@ export default class GameController extends cc.Component {
} }
onTouchMove(event: cc.Event.EventTouch) { onTouchMove(event: cc.Event.EventTouch) {
if (this.currentBlock == null || !this.isHolding) { if (this.currentBlock == null || !this.isHolding || this.isGamePaused) {
return; return;
} }
...@@ -101,7 +108,7 @@ export default class GameController extends cc.Component { ...@@ -101,7 +108,7 @@ export default class GameController extends cc.Component {
} }
onTouchEnd(event: cc.Event.EventTouch) { onTouchEnd(event: cc.Event.EventTouch) {
if (!this.currentBlock || !this.isHolding) return; if (!this.currentBlock || !this.isHolding || this.isGamePaused) return;
this.dropColumn = Math.floor(this.dropPosX / BlockData.BLOCK_SIZE) + 2; this.dropColumn = Math.floor(this.dropPosX / BlockData.BLOCK_SIZE) + 2;
this.spawnColumn = this.dropColumn; this.spawnColumn = this.dropColumn;
...@@ -199,6 +206,7 @@ export default class GameController extends cc.Component { ...@@ -199,6 +206,7 @@ export default class GameController extends cc.Component {
this.currentBlock.getComponent(Block).isPlace = true; this.currentBlock.getComponent(Block).isPlace = true;
this.touched = false; this.touched = false;
this.currentBlock = null;
this.spawnBlock(this.blocksData.generateNumber()); this.spawnBlock(this.blocksData.generateNumber());
} }
} }
...@@ -241,12 +249,12 @@ export default class GameController extends cc.Component { ...@@ -241,12 +249,12 @@ export default class GameController extends cc.Component {
} }
} }
this.cachedBlocksToMerge = blocksToMerge; this.cachedBlocksToMove = blocksToMerge;
this.mergeBlock(nodeIndex); this.mergeBlock(nodeIndex);
} }
mergeBlock(nodeIndex: number) { mergeBlock(nodeIndex: number) {
let blocksToMergeCount = this.cachedBlocksToMerge.length + 1; let blocksToMergeCount = this.cachedBlocksToMove.length + 1;
const cellToMerge = this.board.children[nodeIndex]; const cellToMerge = this.board.children[nodeIndex];
this.currentBlockRow = Math.floor(nodeIndex / 5); this.currentBlockRow = Math.floor(nodeIndex / 5);
this.currentBlockCol = nodeIndex % 5; this.currentBlockCol = nodeIndex % 5;
...@@ -263,8 +271,8 @@ export default class GameController extends cc.Component { ...@@ -263,8 +271,8 @@ export default class GameController extends cc.Component {
let index = Math.log(newValue) / Math.log(2) - 1; let index = Math.log(newValue) / Math.log(2) - 1;
for (let i = 0; i < this.cachedBlocksToMerge.length; i++) { for (let i = 0; i < this.cachedBlocksToMove.length; i++) {
this.cachedBlocksToMerge[i].destroy(); this.cachedBlocksToMove[i].destroy();
} }
if (this.currentBlock.parent) { if (this.currentBlock.parent) {
this.currentBlock.parent.removeChild(this.currentBlock); this.currentBlock.parent.removeChild(this.currentBlock);
...@@ -290,8 +298,8 @@ export default class GameController extends cc.Component { ...@@ -290,8 +298,8 @@ export default class GameController extends cc.Component {
mergeAction(cellToMerge: cc.Node, value: number, index: number) { mergeAction(cellToMerge: cc.Node, value: number, index: number) {
let hasCheckedEmptyCell = false; let hasCheckedEmptyCell = false;
for (let i = 0; i < this.cachedBlocksToMerge.length; i++) { for (let i = 0; i < this.cachedBlocksToMove.length; i++) {
const block = this.cachedBlocksToMerge[i]; const block = this.cachedBlocksToMove[i];
const nodeClone = new cc.Node(); const nodeClone = new cc.Node();
...@@ -311,8 +319,10 @@ export default class GameController extends cc.Component { ...@@ -311,8 +319,10 @@ export default class GameController extends cc.Component {
nodeClone.destroy(); nodeClone.destroy();
nodeClone.parent.removeAllChildren(); nodeClone.parent.removeAllChildren();
this.scoreLbl.setScore(Math.pow(2, index + 1));
cellToMerge.children[0].getComponent(Block).setSpriteBlock(index); cellToMerge.children[0].getComponent(Block).setSpriteBlock(index);
this.cachedBlocksToMerge.length = 0; this.cachedBlocksToMove.length = 0;
if (!hasCheckedEmptyCell) { if (!hasCheckedEmptyCell) {
this.checkEmptyCell(); this.checkEmptyCell();
...@@ -367,8 +377,6 @@ export default class GameController extends cc.Component { ...@@ -367,8 +377,6 @@ export default class GameController extends cc.Component {
nodeToMove.setPosition(cc.Vec2.ZERO); nodeToMove.setPosition(cc.Vec2.ZERO);
if (!hasCheckMerge) { if (!hasCheckMerge) {
console.log(row, col);
this.checkMergeability(row, col); this.checkMergeability(row, col);
hasCheckMerge = true; hasCheckMerge = true;
} }
...@@ -385,4 +393,45 @@ export default class GameController extends cc.Component { ...@@ -385,4 +393,45 @@ export default class GameController extends cc.Component {
this.checkMergeability(this.currentBlockRow, this.currentBlockCol); this.checkMergeability(this.currentBlockRow, this.currentBlockCol);
} }
} }
onFindBlocksToMerge() {
const data = this.blocksData.blockData;
const blocksToMerge = [];
for (let row = 0; row < data.length; row++) {
for (let col = 0; col < data[row].length; col++) {
const currentValue = data[row][col];
if (currentValue !== 0) {
const neighbors = [
{ row: row - 1, col },
{ row: row + 1, col },
{ row, col: col - 1 },
{ row, col: col + 1 },
];
let hasDifferentValue = false;
for (const neighbor of neighbors) {
const { row: neighborRow, col: neighborCol } = neighbor;
if (
neighborRow >= 0 &&
neighborRow < data.length &&
neighborCol >= 0 &&
neighborCol < data[neighborRow].length &&
data[neighborRow][neighborCol] !== currentValue
) {
hasDifferentValue = true;
break;
}
}
if (hasDifferentValue) {
blocksToMerge.push({ row, col });
}
}
}
}
return blocksToMerge;
}
} }
const { ccclass, property } = cc._decorator;
@ccclass
export default class LocalStorage extends cc.Component {
public static setHighestScore(value: number) {
cc.sys.localStorage.setItem("DropAndMergeTheNumber - HighestScore", value);
}
public static getHighestScore(): number {
if (cc.sys.localStorage.getItem("DropAndMergeTheNumber - HighestScore") == null) {
cc.sys.localStorage.setItem("DropAndMergeTheNumber - HighestScore", 0);
return 0;
} else
return JSON.parse(
cc.sys.localStorage.getItem("DropAndMergeTheNumber - HighestScore")
);
}
public static setMusic(value: boolean) {
cc.sys.localStorage.setItem("DropAndMergeTheNumber - Music", value);
}
public static getMusic(): boolean {
if (cc.sys.localStorage.getItem("DropAndMergeTheNumber - Music") == null) {
cc.sys.localStorage.setItem("DropAndMergeTheNumber - Music", true);
return true;
} else
return JSON.parse(cc.sys.localStorage.getItem("DropAndMergeTheNumber - Music"));
}
}
{
"ver": "1.1.0",
"uuid": "a8d37964-b0da-4e9b-969b-997e11f46e10",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import LocalStorage from "./LocalStorage";
const { ccclass, property } = cc._decorator;
@ccclass
export default class Score extends cc.Component {
@property(cc.Node) highScoreLbl: cc.Node = null;
currentScore: number = 0;
highestScore: number = LocalStorage.getHighestScore();
protected onLoad(): void {
this.highScoreLbl.getComponent(cc.Label).string =
this.highestScore.toString();
}
setScore(score: number) {
this.currentScore += score;
this.node.getComponent(cc.Label).string = this.currentScore.toString();
if (this.currentScore > this.highestScore) {
LocalStorage.setHighestScore(this.currentScore);
this.highScoreLbl.getComponent(cc.Label).string =
this.currentScore.toString();
}
}
}
{
"ver": "1.1.0",
"uuid": "f49e7478-16c4-4ece-9adb-267dc091e28f",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
...@@ -19,6 +19,9 @@ export default class Block extends cc.Component { ...@@ -19,6 +19,9 @@ export default class Block extends cc.Component {
protected update(dt: number): void { protected update(dt: number): void {
if (this.isPlace) return; if (this.isPlace) return;
if (!GameController.instance.isGamePaused) {
this.node.y -= dt * 100;
}
if (this.isAtEndOfColumn()) { if (this.isAtEndOfColumn()) {
this.isPlace = true; this.isPlace = true;
...@@ -28,7 +31,6 @@ export default class Block extends cc.Component { ...@@ -28,7 +31,6 @@ export default class Block extends cc.Component {
this.currentBlockColumn this.currentBlockColumn
); );
} }
this.node.y -= dt * 100;
} }
setSpriteBlock(index: number) { setSpriteBlock(index: number) {
......
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