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

10/10/23 commit

parent c2d02291
{
"__type__": "cc.AnimationClip",
"_name": "PopDown",
"_objFlags": 0,
"_native": "",
"_duration": 0.5,
"sample": 60,
"speed": 1,
"wrapMode": 1,
"curveData": {
"props": {
"y": [
{
"frame": 0,
"value": 681.759
},
{
"frame": 0.5,
"value": 490
}
]
}
},
"events": []
}
\ No newline at end of file
{
"ver": "2.1.2",
"uuid": "498f3067-72ca-41ad-abec-bf9bfb770af9",
"importer": "animation-clip",
"subMetas": {}
}
\ No newline at end of file
{
"__type__": "cc.AnimationClip",
"_name": "PopUp",
"_objFlags": 0,
"_native": "",
"_duration": 0.5,
"sample": 60,
"speed": 0.3,
"wrapMode": 1,
"curveData": {
"props": {
"y": [
{
"frame": 0,
"value": -693.105
},
{
"frame": 0.16666666666666666,
"value": -491.234
},
{
"frame": 0.3333333333333333,
"value": -491.234
},
{
"frame": 0.5,
"value": -691.718
}
]
}
},
"events": []
}
\ No newline at end of file
{
"ver": "2.1.2",
"uuid": "3b2264fe-97b8-4d90-8f9d-55c821678b65",
"importer": "animation-clip",
"subMetas": {}
}
\ No newline at end of file
{
"__type__": "cc.AnimationClip",
"_name": "PullUp",
"_objFlags": 0,
"_native": "",
"_duration": 0.5,
"sample": 60,
"speed": 1,
"wrapMode": 1,
"curveData": {
"props": {
"y": [
{
"frame": 0,
"value": 490
},
{
"frame": 0.5,
"value": 681.759
}
]
}
},
"events": []
}
\ No newline at end of file
{
"ver": "2.1.2",
"uuid": "7b4591ef-2c81-4f85-bb92-09bff861b0b2",
"importer": "animation-clip",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.7",
"uuid": "9e2decdc-8554-4ff8-8af4-5e30b59162c7",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 623,
"height": 220,
"platformSettings": {},
"subMetas": {
"barBoostItem": {
"ver": "1.0.6",
"uuid": "ca03b522-6c02-4453-81ec-15dc2ea4bfe9",
"importer": "sprite-frame",
"rawTextureUuid": "9e2decdc-8554-4ff8-8af4-5e30b59162c7",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 623,
"height": 220,
"rawWidth": 623,
"rawHeight": 220,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.7",
"uuid": "b569bf88-22e6-49bd-97f5-2beea1e7bef6",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 175,
"height": 115,
"platformSettings": {},
"subMetas": {
"button": {
"ver": "1.0.6",
"uuid": "3bf0f14a-74c4-45dc-a3d4-d1c1f6cabdfb",
"importer": "sprite-frame",
"rawTextureUuid": "b569bf88-22e6-49bd-97f5-2beea1e7bef6",
"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": 46,
"borderRight": 44,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.7",
"uuid": "b7c74ea3-fba5-42ff-82fb-8ee6cb066a2a",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 407,
"height": 217,
"platformSettings": {},
"subMetas": {
"buttonStart": {
"ver": "1.0.6",
"uuid": "7da626ca-3b1e-4896-953d-d4e4e44f19ea",
"importer": "sprite-frame",
"rawTextureUuid": "b7c74ea3-fba5-42ff-82fb-8ee6cb066a2a",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 407,
"height": 217,
"rawWidth": 407,
"rawHeight": 217,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.7",
"uuid": "42e44b0c-6ff2-4a01-80fc-a54a97a47373",
"uuid": "9c6ac572-6919-445d-b4e5-7350869ca4f8",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
......@@ -12,11 +12,11 @@
"height": 121,
"platformSettings": {},
"subMetas": {
"header": {
"popdown": {
"ver": "1.0.6",
"uuid": "f06e40bc-cc5a-4ced-a739-503a3d09363f",
"uuid": "1323014d-b880-46be-b7e4-60a434777c03",
"importer": "sprite-frame",
"rawTextureUuid": "42e44b0c-6ff2-4a01-80fc-a54a97a47373",
"rawTextureUuid": "9c6ac572-6919-445d-b4e5-7350869ca4f8",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
......@@ -29,9 +29,9 @@
"rawWidth": 208,
"rawHeight": 121,
"borderTop": 0,
"borderBottom": 60,
"borderLeft": 55,
"borderRight": 55,
"borderBottom": 61,
"borderLeft": 47,
"borderRight": 48,
"subMetas": {}
}
}
......
{
"ver": "2.3.7",
"uuid": "4fc908d6-74bc-4eb9-afd5-4d55d8fbd547",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 208,
"height": 121,
"platformSettings": {},
"subMetas": {
"popup": {
"ver": "1.0.6",
"uuid": "34b7aaaa-54e0-499a-9fdf-18977ff89de6",
"importer": "sprite-frame",
"rawTextureUuid": "4fc908d6-74bc-4eb9-afd5-4d55d8fbd547",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 208,
"height": 121,
"rawWidth": 208,
"rawHeight": 121,
"borderTop": 60,
"borderBottom": 0,
"borderLeft": 49,
"borderRight": 54,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.7",
"uuid": "593f2aea-6f48-4534-a2a5-6f5cfaec84eb",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 61,
"height": 54,
"platformSettings": {},
"subMetas": {
"ads": {
"ver": "1.0.6",
"uuid": "5b2c4cea-6c15-4f45-9296-76285a5e9ba7",
"importer": "sprite-frame",
"rawTextureUuid": "593f2aea-6f48-4534-a2a5-6f5cfaec84eb",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 61,
"height": 54,
"rawWidth": 61,
"rawHeight": 54,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.7",
"uuid": "7c1724b5-912e-48dc-b74d-25336b8a37a2",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 79,
"height": 93,
"platformSettings": {},
"subMetas": {
"check": {
"ver": "1.0.6",
"uuid": "4ae598e3-8c6d-4e74-a878-493c3fcdf030",
"importer": "sprite-frame",
"rawTextureUuid": "7c1724b5-912e-48dc-b74d-25336b8a37a2",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 79,
"height": 93,
"rawWidth": 79,
"rawHeight": 93,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
This diff is collapsed.
import BlockData from "../Data/BlockData";
import LocalStorage from "../Data/LocalStorage";
import GameController from "./GameController";
......@@ -5,39 +6,45 @@ 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.Node) startScreen: cc.Node = null;
@property(cc.Node) shadow: cc.Node = null;
@property(cc.SpriteFrame) soundOffSpf: cc.SpriteFrame = null;
@property(cc.SpriteFrame) soundOnSpf: cc.SpriteFrame = null;
@property(cc.Node) soundBtn: cc.Node = null;
@property(cc.Node) popup: cc.Node = null;
@property(cc.Node) destroyBlockPopUp: cc.Node = null;
soundMode: boolean = true;
currentSoundSpf: cc.SpriteFrame = null;
currentSoundSpf: cc.SpriteFrame;
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;
cc.audioEngine.setMusicVolume(0);
cc.audioEngine.setEffectsVolume(0);
}
this.updateSoundBtnSpf();
}
onClickStart() {
GameController.instance.isGameStart = true;
this.startScreen.active = false;
this.shadow.active = false;
GameController.instance.node.emit("startGame");
}
onClickPause() {
if (!GameController.instance.isGameStart) return;
if (GameController.instance.isGamePaused) {
GameController.instance.isGamePaused = false;
this.shadow.active = false;
this.pauseScreen.active = false;
this.shadow.active = false;
} else {
GameController.instance.isGamePaused = true;
this.shadow.active = true;
this.pauseScreen.active = true;
this.shadow.active = true;
}
}
......@@ -46,16 +53,110 @@ export default class ButtonsController extends cc.Component {
}
onClickSound() {
console.log(this.currentSoundSpf);
if (this.soundMode) {
if (this.currentSoundSpf === this.soundOnSpf) {
this.currentSoundSpf = this.soundOffSpf;
LocalStorage.setMusic(false);
this.soundMode = false;
} else {
this.currentSoundSpf = this.soundOnSpf;
LocalStorage.setMusic(true);
this.soundMode = true;
}
this.updateSoundBtnSpf();
}
updateSoundBtnSpf() {
const sprite = this.soundBtn.getChildByName("Icon").getComponent(cc.Sprite);
sprite.spriteFrame = this.currentSoundSpf;
}
onClickBuy512Block() {
if (LocalStorage.getAllCoin() < 100) {
return this.popup.getComponent(cc.Animation).play("PopUp");
}
const item = this.startScreen.getChildByName("Item1");
item.getChildByName("Check").active = true;
item.getChildByName("BuyBtn").active = false;
item.getChildByName("WatchAdsBtn").active = false;
item.getChildByName("Label").y = 0;
LocalStorage.setAllCoin(LocalStorage.getAllCoin() - 100);
this.startScreen
.getChildByName("CoinBar")
.getChildByName("Label")
.getComponent(cc.Label).string = LocalStorage.getAllCoin().toString();
GameController.instance.isGet512Block = true;
}
onClickBuyNextBlock() {
if (LocalStorage.getAllCoin() < 100) {
return this.popup.getComponent(cc.Animation).play("PopUp");
}
const item = this.startScreen.getChildByName("Item2");
item.getChildByName("Check").active = true;
item.getChildByName("BuyBtn").active = false;
item.getChildByName("WatchAdsBtn").active = false;
item.getChildByName("Label").y = 0;
LocalStorage.setAllCoin(LocalStorage.getAllCoin() - 100);
this.startScreen
.getChildByName("CoinBar")
.getChildByName("Label")
.getComponent(cc.Label).string = LocalStorage.getAllCoin().toString();
GameController.instance.isPreviewNextBlock = true;
}
onClickDestroyBlock() {
const data = BlockData.instance.blockData;
let hasNonZeroValue = false;
for (let i = 0; i < data.length; i++) {
for (let j = 0; j < data[i].length; j++) {
if (data[i][j] !== 0) {
hasNonZeroValue = true;
break;
}
}
if (hasNonZeroValue) {
break;
}
}
if (!hasNonZeroValue) return;
GameController.instance.isGamePaused = true;
this.regEvents();
this.destroyBlockPopUp.getComponent(cc.Animation).play("PopDown");
}
regEvents() {
let childrens = GameController.instance.board.children;
childrens.forEach((child) => {
if (child.children.length > 0) {
child.on(cc.Node.EventType.TOUCH_START, this.onTouchDown, this);
}
});
}
onTouchDown(event: cc.Event.EventTouch) {
const data = BlockData.instance.blockData;
const childrens = GameController.instance.board.children;
const cell = event.currentTarget;
const cellIndex = cell.parent.children.indexOf(cell);
const row = Math.floor(cellIndex / 5);
const col = cellIndex % 5;
const value = BlockData.instance.getBlockValue(row, col);
for (let i = 0; i < data.length; i++) {
for (let j = 0; j < data[i].length; j++) {
if (data[i][j] == value) {
let cell = childrens[i * 5 + j];
BlockData.instance.setBlockValue(i, j, 0);
cell.children[0].destroy();
}
}
}
GameController.instance.checkEmptyCell();
this.destroyBlockPopUp.getComponent(cc.Animation).play("PullUp");
GameController.instance.isGamePaused = false;
}
}
import BlockData from "../Data/BlockData";
import LocalStorage from "../Data/LocalStorage";
import Score from "../Data/Score";
import Block from "../Objects/Block";
import Utils from "../Tools/Utils";
......@@ -12,6 +13,8 @@ export default class GameController extends cc.Component {
@property(cc.Node) spawnBar: cc.Node = null;
@property(BlockData) blocksData: BlockData = null;
@property(Score) scoreLbl: Score = null;
@property(cc.Label) coinLbl: cc.Label = null;
@property(cc.Node) nextBlockSpf: cc.Node = null;
static instance: GameController;
......@@ -29,11 +32,24 @@ export default class GameController extends cc.Component {
cacheBlockToMerge = [];
isGamePaused: boolean = false;
isGameStart: boolean = false;
isGet512Block: boolean = false;
isPreviewNextBlock: boolean = false;
nextBlock: number = 0;
protected onLoad(): void {
GameController.instance = this;
this.spawnBlock(this.blocksData.generateNumber());
this.coinLbl.string = LocalStorage.getAllCoin().toString();
this.node.on("startGame", () => {
if (this.isGameStart) {
if (this.isGet512Block) {
this.spawnBlock(8);
} else {
this.spawnBlock(this.blocksData.generateNumber());
}
}
});
}
regEvents() {
......@@ -58,9 +74,18 @@ export default class GameController extends cc.Component {
spawnBlock(index: number) {
if (this.blocksData.blockData.length > 0) {
const hasNonZero = this.blocksData.blockData[0].some((e) => e !== 0);
if (hasNonZero) return;
const isFull = this.blocksData.blockData[0].some((e) => e !== 0);
if (isFull) return;
}
if (this.isPreviewNextBlock) {
this.nextBlock = this.blocksData.generateNumber();
this.nextBlockSpf.getComponent(cc.Sprite).spriteFrame =
this.blockPrefab.data.getComponent(Block).listSpriteBlocks[
this.nextBlock
];
}
this.currentBlock = cc.instantiate(this.blockPrefab);
this.currentBlock.parent = this.spawnBar.children[this.spawnColumn];
this.currentBlock.getComponent(Block).setSpriteBlock(index);
......@@ -71,7 +96,7 @@ export default class GameController extends cc.Component {
}
onTouchDown(event: cc.Event.EventTouch) {
if (this.isGamePaused) return;
if (this.isGamePaused || !this.isGameStart) return;
let touchTarget = event.currentTarget;
this.dropPosX = touchTarget.x;
......@@ -88,7 +113,12 @@ export default class GameController extends cc.Component {
}
onTouchMove(event: cc.Event.EventTouch) {
if (this.currentBlock == null || !this.isHolding || this.isGamePaused) {
if (
this.currentBlock == null ||
!this.isHolding ||
this.isGamePaused ||
!this.isGameStart
) {
return;
}
......@@ -108,7 +138,13 @@ export default class GameController extends cc.Component {
}
onTouchEnd(event: cc.Event.EventTouch) {
if (!this.currentBlock || !this.isHolding || this.isGamePaused) return;
if (
!this.currentBlock ||
!this.isHolding ||
this.isGamePaused ||
!this.isGameStart
)
return;
this.dropColumn = Math.floor(this.dropPosX / BlockData.BLOCK_SIZE) + 2;
this.spawnColumn = this.dropColumn;
......@@ -207,7 +243,12 @@ export default class GameController extends cc.Component {
this.currentBlock.getComponent(Block).isPlace = true;
this.touched = false;
this.currentBlock = null;
this.spawnBlock(this.blocksData.generateNumber());
if (this.isPreviewNextBlock) {
this.spawnBlock(this.nextBlock);
} else {
this.spawnBlock(this.blocksData.generateNumber());
}
}
}
......
......@@ -27,4 +27,16 @@ export default class LocalStorage extends cc.Component {
} else
return JSON.parse(cc.sys.localStorage.getItem("DropAndMergeTheNumber - Music"));
}
public static setAllCoin(value: number) {
cc.sys.localStorage.setItem("DropAndMergeTheNumber - AllCoin", value);
}
public static getAllCoin(): number {
if (cc.sys.localStorage.getItem("DropAndMergeTheNumber - AllCoin") == null) {
cc.sys.localStorage.setItem("DropAndMergeTheNumber - AllCoin", 0);
return 0;
} else
return JSON.parse(cc.sys.localStorage.getItem("DropAndMergeTheNumber - AllCoin"));
}
}
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