补充关卡功能

This commit is contained in:
2025-05-13 14:17:33 +08:00
parent 941dd170b5
commit dcb12db40d
16 changed files with 382 additions and 7 deletions

Binary file not shown.

View File

@@ -0,0 +1,3 @@
{
"uuid": "3ff6c374-5ecd-4de1-b271-a3280f87f9d9"
}

View File

@@ -0,0 +1,48 @@
{
"_$type": "Animator",
"enabled": true,
"path": "",
"cullingMode": 2,
"controllerLayers": [
{
"name": "Base Layer",
"states": [
{
"x": 108,
"y": 105,
"id": "-1",
"name": "进入",
"nexts": [],
"soloTransitions": [
{
"id": "1"
}
]
},
{
"y": 112,
"id": "-2",
"name": "任何状态",
"x": 447
},
{
"x": 285.5874536260055,
"y": 220.0965316887919,
"_isLooping": 0,
"id": "1",
"name": "score_up",
"speed": 1,
"clipEnd": 1,
"clip": {
"_$uuid": "3ff6c374-5ecd-4de1-b271-a3280f87f9d9"
},
"loop": -1
}
],
"playOnWake": true,
"blendingMode": 0,
"defaultWeight": 1
}
],
"layerW": 150
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "96c849ea-9704-40bc-8bb5-c00a4f341d30"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 686 B

View File

@@ -0,0 +1,6 @@
{
"uuid": "06a9c4a8-d664-4f3a-9c35-25b610195ced",
"importer": {
"textureType": 2
}
}

View File

@@ -0,0 +1,75 @@
{
"_$ver": 1,
"_$id": "ze5gx82a",
"_$type": "Box",
"name": "ScoreAdd",
"x": -17,
"y": 28,
"width": 150,
"height": 60,
"centerX": 0,
"centerY": 0,
"_$comp": [
{
"_$type": "Animator2D",
"controller": {
"_$uuid": "96c849ea-9704-40bc-8bb5-c00a4f341d30",
"_$type": "AnimationController2D"
},
"controllerLayers": [
{
"_$type": "AnimatorControllerLayer2D",
"name": "Base Layer",
"states": [
{
"_$type": "AnimatorState2D",
"name": "score_up",
"clipStart": 0,
"clip": {
"_$uuid": "3ff6c374-5ecd-4de1-b271-a3280f87f9d9",
"_$type": "AnimationClip2D"
},
"soloTransitions": []
}
],
"defaultStateName": "score_up"
}
]
},
{
"_$type": "bdb0e671-99fa-47a5-9101-7ec008b1d25d",
"scriptPath": "../src/views/AutoDestroy.ts",
"lifeTime": 1
}
],
"_$child": [
{
"_$id": "mqksqekt",
"_$type": "Box",
"name": "offset",
"y": -150,
"width": 150,
"height": 60,
"_$child": [
{
"_$id": "muzcdy3q",
"_$type": "Label",
"name": "Label",
"x": 0,
"y": 0,
"width": 150,
"height": 60,
"scaleX": 1,
"scaleY": 1,
"text": "+150",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 60,
"color": "rgba(29, 92, 220, 1)",
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
}
]
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "324b6a80-ccee-46d2-bbbd-5a7bf92067b3"
}

View File

@@ -14,6 +14,21 @@
{
"_$type": "692a672b-2457-456c-8093-321ea7a10e1b",
"scriptPath": "../src/views/Stage.ts",
"label_stage_name": {
"_$ref": "w8r3l8ie"
},
"label_score": {
"_$ref": "zgzyqyoc"
},
"label_mistake": {
"_$ref": "azfx9pw2"
},
"label_diff": {
"_$ref": "qxei5ih3"
},
"label_time": {
"_$ref": "m5cdq70n"
},
"obj_blocks": {
"_$ref": "mv2d4o7d"
},
@@ -75,6 +90,49 @@
"skin": "res://63e88ec0-8898-4190-9f70-a4df67200ce3",
"color": "#ffffff"
},
{
"_$id": "xllpjjqz",
"_$type": "Box",
"name": "back",
"x": 60,
"y": 60,
"width": 400,
"height": 64,
"_mouseState": 2,
"left": 60,
"top": 60,
"_$child": [
{
"_$id": "l1ebdt6a",
"_$type": "Button",
"name": "btn_back",
"width": 92,
"height": 64,
"_mouseState": 2,
"stateNum": 1,
"skin": "res://06a9c4a8-d664-4f3a-9c35-25b610195ced",
"label": "",
"labelSize": 20,
"labelAlign": "center",
"labelVAlign": "middle"
},
{
"_$id": "w8r3l8ie",
"_$type": "Text",
"name": "label_stage_name",
"x": 116,
"width": 200,
"height": 64,
"text": "[color=#000000]关卡 [/color][color=#1d5cdc]20[/color]",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 60,
"color": "#FFFFFF",
"ubb": true,
"valign": "middle",
"leading": 2
}
]
},
{
"_$id": "jtbep2gl",
"_$type": "Box",
@@ -87,6 +145,77 @@
"centerX": 0,
"centerY": -128,
"_$child": [
{
"_$id": "zgzyqyoc",
"_$type": "Label",
"name": "label_score",
"x": 372,
"y": -122,
"width": 300,
"height": 60,
"centerX": 0,
"centerY": -614,
"text": "分数999",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 50,
"color": "rgba(29, 92, 220, 1)",
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "azfx9pw2",
"_$type": "Label",
"name": "label_mistake",
"x": 4,
"y": -58,
"width": 300,
"height": 60,
"centerX": -368,
"centerY": -550,
"text": "错误3/3",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 30,
"color": "rgba(123, 129, 140, 1)",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "qxei5ih3",
"_$type": "Label",
"name": "label_diff",
"x": 372,
"y": -58,
"width": 300,
"height": 60,
"centerX": 0,
"centerY": -550,
"text": "难度",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 30,
"color": "rgba(123, 129, 140, 1)",
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "m5cdq70n",
"_$type": "Label",
"name": "label_time",
"x": 741,
"y": -58,
"width": 300,
"height": 60,
"centerX": 369,
"centerY": -550,
"text": "99:99:99",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 30,
"color": "rgba(123, 129, 140, 1)",
"align": "right",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "mv2d4o7d",
"_$type": "HBox",

View File

@@ -3,5 +3,7 @@
export const respath = {
home_ui_res: "resources/Home.lh",
stage_ui_res: "resources/Stage.lh",
score_add_ui_res: "resources/ScoreAdd.lh",
}

View File

@@ -1,3 +1,5 @@
import { G_ShowScoreTips } from "../views/GUITips";
const { regClass, property } = Laya;
@regClass()
@@ -14,10 +16,12 @@ export class Block extends Laya.Script {
public YGroup: number = 0;
private selected: boolean = false
private newSelect: boolean = false
private preset: boolean = false//预设格子
private checked: boolean = false//正确格子
private showNumber: number = 0;
private correctNumber: number = 0;
private score: number = 0
private note_numbers: Array<number> = new Array()
private label_show: Laya.Label;
@@ -46,6 +50,8 @@ export class Block extends Laya.Script {
public setSelected(selected: boolean): void {
this.selected = selected
if (selected)
this.newSelect = true
this.updateBlock()
}
@@ -67,6 +73,7 @@ export class Block extends Laya.Script {
this.checked = preset;
this.showNumber = showNumber;
this.correctNumber = correctNumber;
this.score = 0
this.updateBlock();
}
@@ -82,22 +89,35 @@ export class Block extends Laya.Script {
return this.showNumber;
}
public getCorrectNumber(): number {
return this.correctNumber;
}
public setShowNumber(showNumber: number): boolean {
if (this.checked == false) {
if (showNumber == this.correctNumber)
this.checked = true;
this.showNumber = showNumber;
if (this.checked || showNumber == 0)//正确或者擦除
if (this.checked || showNumber == 0) {//正确或者擦除
this.note_numbers = new Array()
}
this.score = 0
if (this.newSelect) {
this.newSelect = false
if (this.checked) {
this.score = 150
G_ShowScoreTips(this.score.toString(), this.owner)
}
}
this.updateBlock();
}
return this.checked
}
public getCorrectNumber(): number {
return this.correctNumber;
}
public getScore(): number {
return this.score
}
public addNoteNumber(noteNumber: number): void {
if (this.note_numbers.indexOf(noteNumber) < 0) {
this.note_numbers.push(noteNumber)

19
src/views/AutoDestroy.ts Normal file
View File

@@ -0,0 +1,19 @@
const { regClass, property } = Laya;
@regClass()
export class AutoDestroy extends Laya.Script {
declare owner : Laya.Box;
@property(Number)
public lifeTime: number = 1;
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
if (this.lifeTime < 1) {
this.lifeTime = 1
}
Laya.timer.once(this.lifeTime*1000, this, ()=>{
this.owner.destroy()
})
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "bdb0e671-99fa-47a5-9101-7ec008b1d25d"
}

9
src/views/GUITips.ts Normal file
View File

@@ -0,0 +1,9 @@
import { respath } from "../constants/respath";
export function G_ShowScoreTips(text: string, parent: any): void {
Laya.loader.load(respath.score_add_ui_res).then((go)=>{
var prefab = go.create()
var label = parent.addChild(prefab).getChildByName("offset").getChildByName("Label") as Laya.Label
label.text = text
})
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "0a00337c-1c20-470f-930f-2b47f0294e23"
}

View File

@@ -11,6 +11,20 @@ export class Stage extends Laya.Script {
private letterToNumber: any;
private numberToLetter: any;
@property(Laya.Text)
public label_stage_name: Laya.Text;
@property(Laya.Label)
public label_score: Laya.Label;
@property(Laya.Label)
public label_mistake: Laya.Label;
private mistake_now = 0
private mistake_all = 3
@property(Laya.Label)
public label_diff: Laya.Label;
@property(Laya.Label)
public label_time: Laya.Label;
private stage_last: number
@property(Laya.Box)
public obj_blocks: Laya.Box;
@property(Laya.Box)
@@ -120,6 +134,7 @@ export class Stage extends Laya.Script {
public onLoadStage(levelStr: string): void {
this.mistake_now = 0
this.selectedBlock = null;
if (levelStr.length == 81 && this.blocks.length == 81) {
@@ -155,6 +170,35 @@ export class Stage extends Laya.Script {
else {
console.log("onLoadStage error", levelStr.length, this.blocks.length)
}
this.onUpdateScore()
this.onUpdateMistake()
this.stage_last = 0
var begin = Date.now()
Laya.timer.loop(1000, this, ()=>{
var now = Date.now()
this.stage_last += Math.floor((now-begin)/1000)
begin = now
var last = this.stage_last
var hour = Math.floor(last/3600)
last = last - hour * 3600
var minite = Math.floor(last/60)
last = last - minite * 60
var second = Math.floor(last)
this.label_time.text = `${hour>=10?hour:("0"+hour)}:${minite>=10?minite:("0"+minite)}:${second>10?second:("0"+second)}`
})
}
onUpdateScore(): void {
var score = 0
for (var i=0; i<this.blocks.length; i++) {
score += this.blocks[i].getScore()
}
this.label_score.text = `分数: ${score}`
}
onUpdateMistake(): void {
this.label_mistake.text = `${this.mistake_now}/${this.mistake_all}`
}
onSetBlock(block: Block): void {
@@ -206,6 +250,7 @@ export class Stage extends Laya.Script {
onClickErase(evt: Laya.Event): void {
if (this.selectedBlock && this.selectedBlock.getIsChecked() == false) {
this.selectedBlock.setShowNumber(0)
this.onUpdateScore()
this.onSetBlock(this.selectedBlock)
}
}
@@ -230,8 +275,9 @@ export class Stage extends Laya.Script {
index = list.length -1
var block = list[index]
block.setShowNumber(block.getCorrectNumber())
this.selectedBlock = block
this.onUpdateScore()
this.onSetBlock(block)
this.selectedBlock = block
}
}
@@ -261,6 +307,7 @@ export class Stage extends Laya.Script {
}
else {
var b = this.selectedBlock.setShowNumber(showNumber);
this.onUpdateScore()
this.onSetBlock(this.selectedBlock)
if (b) {
var left = candy.getLeft();
@@ -269,7 +316,12 @@ export class Stage extends Laya.Script {
console.log("完成关卡")
}
}
else {
else {//失败
this.mistake_now ++
this.onUpdateMistake()
if (this.mistake_now >= this.mistake_all) {
//关卡失败
}
}
}
}