Whether a baseball is thrown or hit, one thing is certain: someone is trying to catch it. To represent this, build a simple game where the goal is to catch the baseballs that fly across the screen.
Start the project, and create a mitt for the player to control.
- Create a new project in @boardname@
- Create a new sprite representing a mitt
- Change the variable name from
||variables:mySprite||
to||variables:mitt||
, and the||sprites:kind||
fromPlayer
toMitt
- Make
||variables:mitt||
move based off the direction keys using||controller:move sprite with buttons||
- Make
||variables:mitt||
stay in screen using||sprites:set mySprite stay in screen on||
Add balls for the player to attempt to collect.
- Get an
||game:on game update every 500 ms||
event - Create a
||sprites:projectile from side||
representing a baseball inside the||game:on game update every||
event and change the variable name from||variables:projectile||
to||variables:baseball||
- Make
||variables:baseball||
move randomly in thex
andy
directions using||math:pick random 0 to 10||
for the initial||sprites:vx||
and||sprites:vy||
: make the range from-50
and50
- Set
||variables:baseball||
to||sprites:kind||
Baseball
Add gameplay elements that make the game interesting to play.
- Add a
||info:countdown||
of 20 seconds in the||loops:on start||
- Create an
||sprites:on overlap||
event between sprites of||sprites:kind||
Mitt
and sprites of||sprites:kind||
Baseball
- Inside the
||sprites:on overlap||
event,||sprites:destroy||
theBaseball
, and add1
to the score - Make the
Mitt
'bounce' when in the overlap event, by- changing
Mitt
'sy
by -5 ||loops:pause||
for 100 ms- changing
Mitt
'sy
by 5
- changing
Extend the material from this review by completing the following challenges!
- When a ball is caught, use
||music:play sound power up||
to play music - Add another projectile that is created every 15 seconds, of
||sprites:kind||
||sprites:TimeBonus||
. Create an overlap event so that when the||variables:Mitt||
overlaps with the||sprites:TimeBonus||
, the||info:countdown||
is reset to 20 seconds