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

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.

主站蜘蛛池模板: 琼结县| 蓬溪县| 灯塔市| 保德县| 靖安县| 容城县| 休宁县| 左云县| 易门县| 武义县| 湟中县| 莲花县| 锡林郭勒盟| 牙克石市| 隆昌县| 甘泉县| 武宁县| 五河县| 咸丰县| 定西市| 云阳县| 云龙县| 晋城| 武川县| 绩溪县| 开阳县| 金平| 调兵山市| 曲周县| 龙泉市| 虎林市| 穆棱市| 玛纳斯县| 鄄城县| 峡江县| 于田县| 潜江市| 普洱| 绥德县| 浦县| 乌海市|