- Scratch 2.0 Game Development HOTSHOT
- Sergio van Pul Jessica Chiang
- 473字
- 2021-07-19 18:16:59
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:
- First create a new variable called
funds
. This will count your credit pool. - Then click on the Sounds tab to add a sound effect.
- Click on the choose sound from library icon and select the pop sound.
- Click on OK to add it to the available sounds for the project.
- 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. - Go the the first platform's Scripts tab. We will make some additions to the script.
- Get an if … else … block.
- Get a > operator for the condition slot.
- Place the funds variable on the left of the > operator.
- 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. - Inside if, add a change <funds> by -
20
block. - Also drag the clone block inside the if block.
- 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.
- Copy the whole script to the second platform.
- Click on Delete to delete the original script from the second platform. A platform script should look like the following screenshot:
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:
- Click on the red enemy.
- In the enemy clone script that checks for cannonball hits, add a change <funds> by
2
block just before the clone is destroyed. - 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 player4
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.