盖楼游戏
一个基于 Canvas 的盖楼游戏
Demo 预览
在线预览地址 (Demo Link) https://github.com/bmqb/tower_game
github
https://github.com/bmqb/tower_game 喜欢的朋友 给个 star 支持一下哦
Game Rule 游戏规则
以下为默认游戏规则, 也可参照下节自定义游戏参数
每局游戏生命值为 3, 掉落一块楼层生命值减 1, 掉落 3 块后游戏结束, 单局游戏无时间限制
成功盖楼加 25 分, 完美盖楼加 50 分, 连续完美盖楼额外加 25 分, 楼层掉落扣除生命值 1, 单局游戏共有 3 次掉落机会
栗子: 第一块完美盖楼加 50 分, 第二块连续完美盖楼加 75 分, 第三块连续完美盖楼加 100 分, 依此类推
Customise 自定义
- git clone https://github.com/bmqb/tower_game.git
- cd tower_game
- npm install
- npm start
打开
http://localhost:8082
图片音频资源可以直接替换 assets 目录下对应的资源文件
游戏规则可以修改 index.html 文件 L480 的 option 对象
Option 自定义选项
可以使用以下 option 表格里的参数, 完成游戏自定义, 所有参数都是非必填项
Option | Type | Description |
---|---|---|
width | number | 游戏主画面宽度 |
height | number | 游戏主画面高度 |
canvasId | string | Canvas 的 DOM ID |
soundOn | boolean | 是否开启声音 |
successScore | number | 成功盖楼分数 |
perfectScore | number | 完美盖楼额外奖励分数 |
hookSpeed | function | 钩子平移速度 |
hookAngle | function | 钩子摆动角度 |
landBlockSpeed | function | 下方楼房横向速度 |
setGameScore | function | 当前游戏分数 hook |
setGameSuccess | function | 当前游戏成功次数 hook |
setGameFailed | function | 当前游戏失败次数 hook |
hookSpeed
钩子平移速度
函数接收两个参数, 当前成功楼层和当前分数, 返回速度数值
- function(currentFloor, currentScore) {
- return number
- }
- hookAngle
钩子摆动角度
函数接收两个参数, 当前成功楼层和当前分数, 返回角度数值
- function(currentFloor, currentScore) {
- return number
- }
- landBlockSpeed
下方楼房平移速度
函数接收两个参数, 当前成功楼层和当前分数, 返回速度数值
- function(currentFloor, currentScore) {
- return number
- }
- setGameScore
当前游戏分数 hook
函数接收一个参数, 当前游戏分数
- function(score) {
- // your logic
- }
- setGameSuccess
当前游戏成功次数 hook
函数接收一个参数, 当前游戏成功次数
- function(successCount) {
- // your logic
- }
- setGameFailed
当前游戏失败次数 hook
函数接收一个参数, 当前游戏失败次数
- function(failedCount) {
- // your logic
- }
- License
- MIT license.
来源: https://www.cnblogs.com/iamkun/p/8616104.html