diff --git a/assets/Menu.fire b/assets/Menu.fire index 877184a..6123396 100644 --- a/assets/Menu.fire +++ b/assets/Menu.fire @@ -73,6 +73,9 @@ }, { "__id__": 15 + }, + { + "__id__": 16 } ], "_prefab": null, @@ -156,7 +159,7 @@ "__type__": "cc.Vec3", "x": 0, "y": 0, - "z": 539.5338265577053 + "z": 779.4228634059948 }, "_scale": { "__type__": "cc.Vec3", @@ -629,5 +632,15 @@ "__uuid__": "9c3d7d56-f77a-4e1f-a64c-865e00c80cff" }, "_id": "0erRnoKLBJhIFfRGuNB7Qo" + }, + { + "__type__": "1e5d46Ai89Cn4miJXf2Ka71", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "_id": "8akbMFRTxMJoUZES0nQNaf" } ] \ No newline at end of file diff --git a/assets/Scripts/EnemyShip.ts b/assets/Scripts/EnemyShip.ts index 5a55b4a..3a1d03d 100644 --- a/assets/Scripts/EnemyShip.ts +++ b/assets/Scripts/EnemyShip.ts @@ -9,6 +9,7 @@ // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html import GameData from "./GameData"; +import SoundManager from "./SoundsManager"; const {ccclass, property} = cc._decorator; @@ -47,6 +48,7 @@ export default class NewClass extends cc.Component { var bullet = cc.instantiate(this.yellowBullet); bullet.setPosition(this.node.position.x, this.node.position.y - 60); this.node.parent.addChild(bullet); + SoundManager.instance.playEffect('gun2'); } // LIFE-CYCLE CALLBACKS: @@ -64,6 +66,7 @@ export default class NewClass extends cc.Component { if(otherCollider.name === 'greenbullet') { this.enemyLife--; if(this.enemyLife <= 0 && this.playAnimation) { + SoundManager.instance.playEffect('explosion'); this.node.getComponent(cc.Collider).enabled = false; this.node.stopAllActions(); this.playAnimation = false; @@ -72,6 +75,7 @@ export default class NewClass extends cc.Component { } } if(otherCollider.name === 'player') { + SoundManager.instance.stopMusic(); this.node.destroy(); cc.director.loadScene('Menu'); } @@ -97,6 +101,7 @@ export default class NewClass extends cc.Component { update (dt) { if(this.node.position.y <= -(this.node.parent.getContentSize().height)) { + SoundManager.instance.stopMusic(); this.node.destroy(); cc.director.loadScene('Menu'); } diff --git a/assets/Scripts/Game.ts b/assets/Scripts/Game.ts index 90e343a..3157bb3 100644 --- a/assets/Scripts/Game.ts +++ b/assets/Scripts/Game.ts @@ -9,6 +9,7 @@ // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html import GameData from "./GameData"; +import SoundManager from "./SoundsManager"; const {ccclass, property} = cc._decorator; @@ -66,6 +67,8 @@ export default class NewClass extends cc.Component { onLoad () { var manager = cc.director.getCollisionManager(); manager.enabled = true; + + SoundManager.instance.playMusic('Dududum', true); } start () { diff --git a/assets/Scripts/MoveJet.ts b/assets/Scripts/MoveJet.ts index eb12e15..9964750 100644 --- a/assets/Scripts/MoveJet.ts +++ b/assets/Scripts/MoveJet.ts @@ -8,6 +8,8 @@ // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html +import SoundManager from "./SoundsManager"; + const {ccclass, property} = cc._decorator; @ccclass @@ -29,9 +31,11 @@ export default class NewClass extends cc.Component { onCollisionEnter(otherCollider, selfCollider) { if(otherCollider.name === 'Bullet') { this.playerLifes--; + SoundManager.instance.playEffect('healthaddon'); this.setLifes(this.playerLifes); otherCollider.node.destroy(); if(this.playerLifes <= 0) { + SoundManager.instance.stopMusic(); this.node.destroy(); cc.director.loadScene('Menu'); } @@ -39,10 +43,12 @@ export default class NewClass extends cc.Component { else if(otherCollider.name === 'health') { this.playerLifes = 8; this.setLifes(this.playerLifes); + SoundManager.instance.playEffect('gunaddon'); otherCollider.node.destroy(); } else if(otherCollider.name === 'rocket') { this.shootingInterval = Math.min(this.shootingInterval + 1, 5); + SoundManager.instance.playEffect('gunaddon'); otherCollider.node.destroy(); } } @@ -54,6 +60,7 @@ export default class NewClass extends cc.Component { } shootBullets() { + SoundManager.instance.playEffect('gun'); switch (this.shootingInterval) { case 1: this.spawnBullet(0, 40); diff --git a/assets/Scripts/Root.ts b/assets/Scripts/Root.ts new file mode 100644 index 0000000..a57352d --- /dev/null +++ b/assets/Scripts/Root.ts @@ -0,0 +1,20 @@ +// Learn TypeScript: +// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html +// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html +// Learn Attribute: +// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html +// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html +// Learn life-cycle callbacks: +// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html +// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html + +const {ccclass, property} = cc._decorator; +import SoundManager from "./SoundsManager"; + +@ccclass +export default class NewClass extends cc.Component { + + onLoad() { + SoundManager.instance.preloadSounds(); + } +} diff --git a/assets/Scripts/Root.ts.meta b/assets/Scripts/Root.ts.meta new file mode 100644 index 0000000..428b155 --- /dev/null +++ b/assets/Scripts/Root.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.5", + "uuid": "1e5d4e80-8bcf-429f-89a2-2577f629aef5", + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/assets/Scripts/SoundsManager.ts b/assets/Scripts/SoundsManager.ts new file mode 100644 index 0000000..b74dc5f --- /dev/null +++ b/assets/Scripts/SoundsManager.ts @@ -0,0 +1,75 @@ +// Learn TypeScript: +// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html +// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html +// Learn Attribute: +// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html +// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html +// Learn life-cycle callbacks: +// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html +// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html + +const {ccclass, property} = cc._decorator; + +@ccclass +export default class SoundManager extends cc.Component { + private static _instance: SoundManager = null; + + private sounds: { [key: string]: cc.AudioClip } = {}; + private musicId: number = -1; + + public static get instance(): SoundManager { + if (!this._instance) { + const node = new cc.Node("SoundManager"); + cc.game.addPersistRootNode(node); // stays across scenes + this._instance = node.addComponent(SoundManager); + } + return this._instance; + } + + // ✅ Preload all your sounds at startup + preloadSounds() { + cc.loader.loadResDir("sounds", cc.AudioClip, (err, clips, urls) => { + if (err) { + cc.error("Error loading sounds:", err); + return; + } + + for (let i = 0; i < clips.length; i++) { + const key = urls[i].split("/").pop(); // file name without path + this.sounds[key] = clips[i]; + } + + cc.audioEngine.setMusicVolume(0.1); + }); + } + + // ✅ Play short effects (clicks, shots, explosions) + playEffect(name: string, loop: boolean = false) { + const clip = this.sounds[name]; + if (clip) { + cc.audioEngine.setEffectsVolume(name === 'explosion' ? 0.1 : 0.2); + cc.audioEngine.playEffect(clip, loop); + } else { + cc.warn(`Sound '${name}' not found. Make sure it's preloaded.`); + } + } + + // ✅ Play/Stop background music + playMusic(name: string, loop: boolean = true) { + const clip = this.sounds[name]; + if (clip) { + if (this.musicId !== -1) { + cc.audioEngine.stop(this.musicId); + } + this.musicId = cc.audioEngine.playMusic(clip, loop); + } else { + cc.warn(`Music '${name}' not found. Make sure it's preloaded.`); + } + } + + stopMusic() { + cc.audioEngine.stopMusic(); + this.musicId = -1; + } + +} diff --git a/assets/Scripts/SoundsManager.ts.meta b/assets/Scripts/SoundsManager.ts.meta new file mode 100644 index 0000000..b60ec6b --- /dev/null +++ b/assets/Scripts/SoundsManager.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.5", + "uuid": "37d707d8-0ba1-44a6-9ba3-398124444f75", + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/assets/Scripts/SwitchScreens.ts b/assets/Scripts/SwitchScreens.ts index 5b5e87a..55b9fce 100644 --- a/assets/Scripts/SwitchScreens.ts +++ b/assets/Scripts/SwitchScreens.ts @@ -9,21 +9,34 @@ // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html import GameData from "./GameData"; +import SoundManager from "./SoundsManager"; const {ccclass, property} = cc._decorator; @ccclass -export default class NewClass extends cc.Component { +export default class MenuScreen extends cc.Component { + + onLoad() { + const scene = cc.director.getScene().name; + if(scene === 'Menu') { + this.scheduleOnce(() => { + SoundManager.instance.playMusic('Judgement', true); + }, 0.1); + } + } loadLevelsScene() { + SoundManager.instance.playEffect('click'); cc.director.preloadScene('Level', () => { cc.director.loadScene('Level'); }); } loadGameScene(event, customData) { + SoundManager.instance.playEffect('click'); const selectedLevel = Number(customData); GameData.instance.selectedLevel = selectedLevel; + SoundManager.instance.stopMusic(); cc.director.preloadScene('Game', () => { cc.director.loadScene('Game'); }); diff --git a/assets/resources.meta b/assets/resources.meta new file mode 100644 index 0000000..feca4bc --- /dev/null +++ b/assets/resources.meta @@ -0,0 +1,7 @@ +{ + "ver": "1.0.1", + "uuid": "1c8ac613-25f0-4b91-9b77-dd606628cb4f", + "isSubpackage": false, + "subpackageName": "", + "subMetas": {} +} \ No newline at end of file diff --git a/assets/sounds.meta b/assets/resources/sounds.meta similarity index 100% rename from assets/sounds.meta rename to assets/resources/sounds.meta diff --git a/assets/sounds/Dududum.mp3 b/assets/resources/sounds/Dududum.mp3 similarity index 100% rename from assets/sounds/Dududum.mp3 rename to assets/resources/sounds/Dududum.mp3 diff --git a/assets/sounds/Dududum.mp3.meta b/assets/resources/sounds/Dududum.mp3.meta similarity index 100% rename from assets/sounds/Dududum.mp3.meta rename to assets/resources/sounds/Dududum.mp3.meta diff --git a/assets/sounds/Judgement.mp3 b/assets/resources/sounds/Judgement.mp3 similarity index 100% rename from assets/sounds/Judgement.mp3 rename to assets/resources/sounds/Judgement.mp3 diff --git a/assets/sounds/Judgement.mp3.meta b/assets/resources/sounds/Judgement.mp3.meta similarity index 100% rename from assets/sounds/Judgement.mp3.meta rename to assets/resources/sounds/Judgement.mp3.meta diff --git a/assets/sounds/click.mp3 b/assets/resources/sounds/click.mp3 similarity index 100% rename from assets/sounds/click.mp3 rename to assets/resources/sounds/click.mp3 diff --git a/assets/sounds/click.mp3.meta b/assets/resources/sounds/click.mp3.meta similarity index 100% rename from assets/sounds/click.mp3.meta rename to assets/resources/sounds/click.mp3.meta diff --git a/assets/sounds/explosion.mp3 b/assets/resources/sounds/explosion.mp3 similarity index 100% rename from assets/sounds/explosion.mp3 rename to assets/resources/sounds/explosion.mp3 diff --git a/assets/sounds/explosion.mp3.meta b/assets/resources/sounds/explosion.mp3.meta similarity index 100% rename from assets/sounds/explosion.mp3.meta rename to assets/resources/sounds/explosion.mp3.meta diff --git a/assets/sounds/gun.mp3 b/assets/resources/sounds/gun.mp3 similarity index 100% rename from assets/sounds/gun.mp3 rename to assets/resources/sounds/gun.mp3 diff --git a/assets/sounds/gun.mp3.meta b/assets/resources/sounds/gun.mp3.meta similarity index 100% rename from assets/sounds/gun.mp3.meta rename to assets/resources/sounds/gun.mp3.meta diff --git a/assets/sounds/gun2.mp3 b/assets/resources/sounds/gun2.mp3 similarity index 100% rename from assets/sounds/gun2.mp3 rename to assets/resources/sounds/gun2.mp3 diff --git a/assets/sounds/gun2.mp3.meta b/assets/resources/sounds/gun2.mp3.meta similarity index 100% rename from assets/sounds/gun2.mp3.meta rename to assets/resources/sounds/gun2.mp3.meta diff --git a/assets/resources/sounds/gunaddon.wav b/assets/resources/sounds/gunaddon.wav new file mode 100644 index 0000000..28692d6 Binary files /dev/null and b/assets/resources/sounds/gunaddon.wav differ diff --git a/assets/resources/sounds/gunaddon.wav.meta b/assets/resources/sounds/gunaddon.wav.meta new file mode 100644 index 0000000..533bca3 --- /dev/null +++ b/assets/resources/sounds/gunaddon.wav.meta @@ -0,0 +1,6 @@ +{ + "ver": "2.0.0", + "uuid": "fd59f682-d897-45c3-9371-9049b65e8cd8", + "downloadMode": 0, + "subMetas": {} +} \ No newline at end of file diff --git a/assets/resources/sounds/healthaddon.wav b/assets/resources/sounds/healthaddon.wav new file mode 100644 index 0000000..f98799b Binary files /dev/null and b/assets/resources/sounds/healthaddon.wav differ diff --git a/assets/resources/sounds/healthaddon.wav.meta b/assets/resources/sounds/healthaddon.wav.meta new file mode 100644 index 0000000..39b765d --- /dev/null +++ b/assets/resources/sounds/healthaddon.wav.meta @@ -0,0 +1,6 @@ +{ + "ver": "2.0.0", + "uuid": "93bb95b4-42bb-4364-95e0-fe263f6ce2bd", + "downloadMode": 0, + "subMetas": {} +} \ No newline at end of file diff --git a/settings/project.json b/settings/project.json index 77281bf..20a06b3 100644 --- a/settings/project.json +++ b/settings/project.json @@ -72,5 +72,6 @@ "width": 960 }, "use-customize-simulator": true, - "use-project-simulator-setting": false + "use-project-simulator-setting": false, + "start-scene": "current" } \ No newline at end of file