您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

215 行
4.6 KiB

  1. -- 游戏逻辑相关的全局函数
  2. local BGMusicPlayer = require("luaScript.Tools.MusicPlayer")();
  3. --背景音乐的通用接口
  4. function playBGMusic(key, musicFileName)
  5. playConfig =
  6. {
  7. -- 唯一的名字,如果正在播的是这个名字,就忽略
  8. Name = key;
  9. -- 需要播放的声音列表,会从中随机一首
  10. Files = {musicFileName};
  11. -- 播放几率,[0-100]
  12. Rate = 100;
  13. -- 每批的间隔
  14. IntervalMin = 0;
  15. IntervalMax = 0;
  16. -- 一批播放多少次
  17. PlayCountMin = 1;
  18. PlayCountMax = 1;
  19. -- 循环多少批,0表示无限循环
  20. LoopCount = 0;
  21. -- 延迟几秒才开始播放
  22. DelayTime = 0;
  23. -- 声音停止时的淡出时间(秒)
  24. FadeOut = 0;
  25. }
  26. BGMusicPlayer.playBGMusic(playConfig);
  27. end
  28. function stopBGMusic()
  29. return BGMusicPlayer.stopBGMusic();
  30. end
  31. --音效的通用接口
  32. function playVoice(voiceFileName)
  33. local soundVolume = app.systemSetting.info.soundVolume
  34. local sound = cc.AudioController:getInstance():playSound(voiceFileName, false);
  35. if sound then
  36. sound:setGain(soundVolume)
  37. end
  38. return sound
  39. end
  40. function stopVoice(sound)
  41. if sound then
  42. cc.AudioController:getInstance():stopSound(sound)
  43. end
  44. end
  45. -------------------- MUSIC ---------------------------
  46. function playMusicLogin()
  47. playBGMusic("BG_Login", "res/sound/bg_login.ogg")
  48. end
  49. function playMusicHall()
  50. playBGMusic("BG_Hall", "res/sound/bg_hall.ogg")
  51. end
  52. function playMusicRoom(index)
  53. if index == 0 then
  54. playBGMusic("BG_Room", "res/sound/room/bgmusic.ogg")
  55. else
  56. playBGMusic("BG_Room", "res/sound/room/bgm.ogg")
  57. end
  58. end
  59. -------------------- SOUND ---------------------------
  60. -- 播放发牌的音效
  61. function playVoiceGiveCard()
  62. playVoice("res/sound/g_flop.ogg")
  63. end
  64. --播放行为操作音效
  65. function playVoiceNiuX(NiuX,nUserId)
  66. if not NiuX then
  67. return
  68. end
  69. local memberInfo = app.room.roomInfo.memberList[nUserId]
  70. if memberInfo then
  71. local userInfo = json.decode(memberInfo.userInfo)
  72. if not userInfo then
  73. return
  74. end
  75. --男1女2,默认是男生
  76. local sexNum = userInfo.sex or 1
  77. --因为女生用的资源是0
  78. if tonumber(sexNum) == 2 then
  79. sexNum = 0
  80. end
  81. local sex = tostring(sexNum)
  82. local voiceName = ""
  83. if tonumber(sexNum) == 1 then
  84. voiceName = string.format("res/sound/room/gg_ogg/f0_nn%d.ogg", NiuX)
  85. else
  86. --女生或者人妖(可能性别保密)进这里播放
  87. voiceName = string.format("res/sound/room/mm_ogg/f1_nn%d.ogg", NiuX)
  88. end
  89. playVoice(voiceName)
  90. end
  91. end
  92. --播放不抢庄操作音效
  93. function playVoiceBuQiang(nUserId)
  94. local memberInfo = app.room.roomInfo.memberList[nUserId]
  95. if memberInfo then
  96. local userInfo = json.decode(memberInfo.userInfo)
  97. if not userInfo then
  98. return
  99. end
  100. --男1女2,默认是男生
  101. local sexNum = userInfo.sex or 1
  102. --因为女生用的资源是0
  103. if tonumber(sexNum) == 2 then
  104. sexNum = 0
  105. end
  106. local sex = tostring(sexNum)
  107. local voiceName = ""
  108. if tonumber(sexNum) == 1 then
  109. voiceName = "res/sound/room/buqiang_0.ogg"
  110. else
  111. --女生或者其他
  112. voiceName = "res/sound/room/buqiang_1.ogg"
  113. end
  114. playVoice(voiceName)
  115. end
  116. end
  117. --播放抢庄操作音效
  118. function playVoiceQiang(nUserId)
  119. local memberInfo = app.room.roomInfo.memberList[nUserId]
  120. if memberInfo then
  121. local userInfo = json.decode(memberInfo.userInfo)
  122. if not userInfo then
  123. return
  124. end
  125. --男1女2,默认是男生
  126. local sexNum = userInfo.sex or 1
  127. --因为女生用的资源是0
  128. if tonumber(sexNum) == 2 then
  129. sexNum = 0
  130. end
  131. local sex = tostring(sexNum)
  132. local voiceName = ""
  133. if tonumber(sexNum) == 1 then
  134. voiceName = "res/sound/room/qiangzhuang_0.ogg"
  135. else
  136. --女生或者其他
  137. voiceName = "res/sound/room/qiangzhuang_1.ogg"
  138. end
  139. playVoice(voiceName)
  140. end
  141. end
  142. --播放按钮点击音效
  143. function playBtnEffect()
  144. playVoice("res/sound/click.ogg")
  145. end
  146. --播放按钮关闭音效
  147. function playBtnCloseEffect()
  148. playVoice("res/sound/effect_return.ogg")
  149. end
  150. --播放标签页点击音效
  151. function playBtnTagEffect()
  152. playVoice("res/sound/effect_biaoqian.ogg")
  153. end
  154. --播放金币飞
  155. function playOneCoinEffect()
  156. playVoice("res/sound/room/coin_big.ogg")
  157. end
  158. --播放下注
  159. function playCoinsEffect()
  160. playVoice("res/sound/room/chips_to_table.ogg")
  161. end
  162. --播放下注
  163. function playCoinsFlyEffect()
  164. playVoice("res/sound/room/coins_fly.ogg")
  165. end
  166. --播放抢庄家音效
  167. function playVoiceRootBanker()
  168. playVoice("res/sound/room/random_banker_lianxu.ogg")
  169. end
  170. --播放成功失败音效
  171. function playEndVoice(cardFileName)
  172. local voiceName = string.format("res/sound/room/%s.ogg", cardFileName)
  173. playVoice(voiceName)
  174. end
  175. --播放闹钟
  176. function playClockVoice()
  177. local voiceName = "res/sound/time_over.ogg"
  178. playVoice(voiceName)
  179. end