官术网_书友最值得收藏!

Limiting resources

We now have a decent horde of enemies threatening our base. There is still one problem though. The player can place cannons at their leisure. So they can quickly build up an impenetrable barrage of artillery. No horde could survive that onslaught.

Engage thrusters

To really make a challenging game, we have to limit the player's options a little. To do that, we will script a resource system. The player will start the game with some "credits" to build a few cannons with. When the funds are depleted, they can't build anymore. Killing enemies will gain the player some more credits and allow them to increase their artillery battery. The following are the steps to create the credits:

  1. First create a new variable called funds. This will count your credit pool.
  2. Then click on the Sounds tab to add a sound effect.
  3. Click on the choose sound from library icon and select the pop sound.
  4. Click on OK to add it to the available sounds for the project.
  5. In the stage sprite script, after emptying the lists, set funds value to 40 by using the set < funds> to block. This will be the starting amount of credits.
  6. Go the the first platform's Scripts tab. We will make some additions to the script.
  7. Get an if … else … block.
  8. Get a > operator for the condition slot.
  9. Place the funds variable on the left of the > operator.
  10. Type in 19 on the right of the > operator. We will make the price of cannons 20 credits, so you need to have at least that amount in your funds.
  11. Inside if, add a change <funds> by -20 block.
  12. Also drag the clone block inside the if block.
  13. Inside the else block, place a play sound <pop> block. When there aren't enough funds to create a cannon, this will make a sound to let the player know about it.
  14. Copy the whole script to the second platform.
  15. Click on Delete to delete the original script from the second platform. A platform script should look like the following screenshot:
    Engage thrusters

The player can now spend funds. Next, let's create a way to gain funds so the player can keep building as the game progresses. The following are the steps given to do it:

  1. Click on the red enemy.
  2. In the enemy clone script that checks for cannonball hits, add a change <funds> by 2 block just before the clone is destroyed.
  3. Do the same for the blue and the yellow enemy but with different values. Killing a blue enemy will reward 3 credits. Killing a yellow one will give the player 4 credits.

Objective complete – mini debriefing

These additions put a nice limit on the amount of resistance a player can build up. It builds tension as the player's offensive power will increase as the horde does.

主站蜘蛛池模板: 大城县| 淮安市| 隆德县| 开封县| 黎城县| 襄垣县| 江孜县| 博兴县| 石景山区| 会泽县| 郸城县| 山阴县| 宿州市| 昭苏县| 德庆县| 通州区| 渝中区| 全椒县| 峨山| 天气| 安丘市| 吴堡县| 乌恰县| 屯门区| 虎林市| 安远县| 济宁市| 衡东县| 彩票| 绥滨县| 舞钢市| 华亭县| 鄂伦春自治旗| 宁强县| 克东县| 通道| 奇台县| 西畴县| 吐鲁番市| 桑日县| 亚东县|