- HTML5 Game Development HOTSHOT
- Makzan
- 316字
- 2021-12-08 12:42:46
Showing different quests
In this task, we are going to show how to advance to the next level when the player's composition matches that of the quest compositions in the current level.
Engage thrusters
This time, we need quest-level data in the quest.js
file to be accessible from another file, so we need to attach the questLevels
and questData
methods to the game scope rather than the original local scope:
- In the
quest.js
file, we change thequestLevels
declaration fromvar questLevels
togame.questLevels
. - We apply the same to
questData
:// from var questData = questLevels[level]; // to var questData = game.questLevels[level];
- In the
scenes.js
file, we display the level with the following function:gameScene.updateLevelInfo = function(level) { document.getElementById('stage').textContent = "Stage "+ level; };
- At last, we modify the game flow in the
game.js
file to count the level:game.flow = { currentLevel: -1, maxLevel: game.questLevels.length - 1, startOver: function() { ... this.currentLevel = -1; }, nextLevel: function() { this.currentLevel+=1; if (this.currentLevel>= this.maxLevel) this.currentLevel = this.maxLevel; game.gameScene.updateLevelInfo(this.currentLevel+1); // when displaying level, we start from 1 instead of 0, so +1 here. ... }, ... }
Objective complete – mini debriefing
The level up is done by counting the current level and selecting the level from the questLevels
array. The nextLevel
method is used to increase the currentLevel
counter. Moreover, this method is called once startButton
is clicked from the menu. Therefore, it will increase the currentLevel
counter at the beginning. This is why we set the initial value of currentLevel
to -1
. This will ensure that it selects the first level once the game starts that is at index 0 of the level array. We reset currentLevel
in the startOver
method once the game is over. On the other hand, we display the current level at the top of the game inside the #stage
element. Therefore, we also update that wording every time the level is up.
- 3D Printing with RepRap Cookbook
- TestStand工業(yè)自動(dòng)化測(cè)試管理(典藏版)
- WOW!Illustrator CS6完全自學(xué)寶典
- 網(wǎng)絡(luò)綜合布線技術(shù)
- Apache Superset Quick Start Guide
- Splunk Operational Intelligence Cookbook
- 學(xué)會(huì)VBA,菜鳥也高飛!
- Machine Learning with the Elastic Stack
- DevOps Bootcamp
- 從零開始學(xué)C++
- 網(wǎng)絡(luò)服務(wù)搭建、配置與管理大全(Linux版)
- SMS 2003部署與操作深入指南
- 基于敏捷開發(fā)的數(shù)據(jù)結(jié)構(gòu)研究
- ZigBee無線通信技術(shù)應(yīng)用開發(fā)
- Cloudera Hadoop大數(shù)據(jù)平臺(tái)實(shí)戰(zhàn)指南