first commit
This commit is contained in:
125
assets/seripts/scenes/GameSceneControl.ts
Normal file
125
assets/seripts/scenes/GameSceneControl.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import { _decorator, Component, google, Label, Node } from "cc";
|
||||
import { GlobalData } from "../config/GlobalData";
|
||||
import { EventDispatcher } from "../libs/EventDispatcher";
|
||||
import { GameState } from "../config/Config";
|
||||
import { MusicManager } from "../managers/MusicManager";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("GameSceneControl")
|
||||
export class GameSceneControl extends Component {
|
||||
// 当前这一局得分label
|
||||
@property(Label)
|
||||
curRoundScoreLabel: Label = null;
|
||||
|
||||
// 当前这句剩余生命值label
|
||||
@property(Label)
|
||||
lifeNumLabel: Label = null;
|
||||
|
||||
// ui 节点
|
||||
@property(Node)
|
||||
uiNode: Node = null;
|
||||
|
||||
// 音频管理器
|
||||
musicManager: MusicManager = null;
|
||||
|
||||
onLoad() {
|
||||
// 获取音频管理器
|
||||
this.musicManager = this.node.getComponent(MusicManager);
|
||||
|
||||
// 监听小恐龙吃到音符事件
|
||||
EventDispatcher.getTarget().on(
|
||||
EventDispatcher.DINO_EAT_NOTE,
|
||||
this.updateCurRoundScoreLabel,
|
||||
this,
|
||||
);
|
||||
// 监听音符碰到线事件
|
||||
EventDispatcher.getTarget().on(
|
||||
EventDispatcher.UPDATE_LIFE,
|
||||
this.updateLifeNumLabel,
|
||||
this,
|
||||
);
|
||||
// 监听游戏结束事件
|
||||
EventDispatcher.getTarget().on(
|
||||
EventDispatcher.GAME_OVER,
|
||||
this.handleEndGame,
|
||||
this,
|
||||
);
|
||||
// 监听过关事件
|
||||
EventDispatcher.getTarget().on(
|
||||
EventDispatcher.PASS_LEVLE,
|
||||
this.handlePassLevel,
|
||||
this,
|
||||
);
|
||||
}
|
||||
|
||||
start() {
|
||||
// 重置游戏数据
|
||||
GlobalData.resetGameData();
|
||||
this.startGame();
|
||||
}
|
||||
|
||||
startGame() {
|
||||
// 开始游戏
|
||||
this.uiNode.active = true;
|
||||
// 更新 ui 节点相关数据
|
||||
this.updateUi();
|
||||
// 设置游戏状态为进行中
|
||||
GlobalData.gameState = GameState.PLAYING;
|
||||
// 开始游戏提示动画
|
||||
|
||||
// 1 s 后正式开始游戏
|
||||
this.scheduleOnce(() => {
|
||||
// 开始播放背景音乐
|
||||
this.playMusic();
|
||||
// 发送开始游戏事件
|
||||
EventDispatcher.getTarget().emit(EventDispatcher.GAME_STAET);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
// 更新 ui
|
||||
updateUi() {
|
||||
// 更新本局总得分
|
||||
this.updateCurRoundScoreLabel();
|
||||
// 更新生命值
|
||||
this.updateLifeNumLabel();
|
||||
// 更新当前速度的显示
|
||||
this.updateSpeed();
|
||||
}
|
||||
|
||||
// 更新当前这一局得分
|
||||
updateCurRoundScoreLabel() {
|
||||
this.curRoundScoreLabel.string = GlobalData.curRoundTotalScore.toString();
|
||||
}
|
||||
|
||||
// 更新当前这句剩余生命值
|
||||
updateLifeNumLabel() {
|
||||
this.lifeNumLabel.string = "x" + GlobalData.lifeNumPerRound.toString();
|
||||
}
|
||||
|
||||
// 更新速度显示
|
||||
updateSpeed() {}
|
||||
|
||||
// 暂停游戏
|
||||
pauseGame() {
|
||||
EventDispatcher.getTarget().emit(EventDispatcher.SHOW_PAUSE_MODAL);
|
||||
}
|
||||
|
||||
// 处理游戏结束时
|
||||
handleEndGame() {
|
||||
// 游戏结束,弹出游戏界面
|
||||
this.uiNode.active = false;
|
||||
}
|
||||
|
||||
// 闯过当前关卡时 重新开始下一轮
|
||||
handlePassLevel() {
|
||||
// 增加速率
|
||||
GlobalData.speedRate += GlobalData.speedRateAdd;
|
||||
// 继续开始游戏
|
||||
this.startGame();
|
||||
}
|
||||
|
||||
// 播放音乐
|
||||
playMusic() {
|
||||
this.musicManager.play();
|
||||
}
|
||||
}
|
||||
9
assets/seripts/scenes/GameSceneControl.ts.meta
Normal file
9
assets/seripts/scenes/GameSceneControl.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "60d28f0e-e562-4a8a-9321-551fa0e9ab1c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
48
assets/seripts/scenes/HomeSceneControl.ts
Normal file
48
assets/seripts/scenes/HomeSceneControl.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { _decorator, Component, director, Node } from "cc";
|
||||
import AudioEffect from "../libs/AudioEffect";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("HomeSceneCon")
|
||||
export class HomeSceneCon extends Component {
|
||||
// 滑动区域节点
|
||||
@property(Node)
|
||||
swipeNode: Node = null;
|
||||
|
||||
start() {
|
||||
// 监听滑动区域事件
|
||||
this.swipeNode.on(Node.EventType.TOUCH_START, this.goToGameScene, this);
|
||||
}
|
||||
|
||||
// 跳转到游戏场景
|
||||
goToGameScene() {
|
||||
director.preloadScene("game", () => {
|
||||
director.loadScene("game");
|
||||
});
|
||||
}
|
||||
|
||||
// 跳转到 love-story 场景
|
||||
goToLoveStoryScene() {
|
||||
AudioEffect.playClickAudio();
|
||||
director.preloadScene("love-story", () => {
|
||||
director.loadScene("love-story");
|
||||
});
|
||||
}
|
||||
|
||||
// 跳转到 mood 场景
|
||||
goToMoodScene() {
|
||||
AudioEffect.playClickAudio();
|
||||
director.preloadScene("mood", () => {
|
||||
director.loadScene("mood");
|
||||
});
|
||||
}
|
||||
|
||||
// 跳转到作者场景
|
||||
goToAuthorScene() {
|
||||
AudioEffect.playClickAudio();
|
||||
director.preloadScene("author", () => {
|
||||
director.loadScene("author");
|
||||
});
|
||||
}
|
||||
|
||||
update(deltaTime: number) {}
|
||||
}
|
||||
9
assets/seripts/scenes/HomeSceneControl.ts.meta
Normal file
9
assets/seripts/scenes/HomeSceneControl.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "fd8f17a5-c483-4f69-8a79-bdeca9aa1946",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user