Spit Ball

advertisement
SPIT BALL!
simple shooter tutorial
ROOK 10
There are SO MANY shooter games in the world today. Remember to use good taste. Be a
responsible “shooter”. Do not promote any activity which goes beyond good clean fun!
Everyone loves a good clean water balloon fight. Some simple rules to follow are: NO GUNS!
NO GUTS! NO SHOOTING PEOPLE!
Start a new SCRATCH project.
Right click on the SCRATCH kitty and delete this SPRITE.
Click on the PAINT NEW SPRITE button.
This opens up the PAINT EDITOR
Use the circle tool to create a simple spit ball graphic in the center of the screen.
Click OK.
Now use the CHOOSE NEW SPRITE FROM FILE button and pick a target object. Here we will be
using a “slug bug”.
SCROLLING OBJECT
First we need to get the target object (slug bug) moving across the screen.
Click on the slug bug – SPRITE 2. This opens up the SCRIPTS TAB for this sprite.
From the yellow CONTROL menu grab the WHEN THE GREEN FLAG IS CLICKED tile and drop it
on the SCRIPTS window for SPRITE 2. This will start the script running at the beginning of the
game when the player clicks the green flag.
Now let’s size the SPRITE.
From the purple LOOKS menu grab a purple SET SIZE TO 100% tile and attach it to the stack.
Set the percentage value to size the target SPRITE (the slug bug). Here we are using 50%.
SCRATCH MOVEMENT
SCRATCH uses an X:Y COORDINATE PLANE to define the game playing field.
At the center of the SCRATCH game screen X=0 and Y=0.
We move up and down on the screen by increasing or decreasing the Y value.
We move left and right on the screen by increasing or decreasing the X value.
In this case we want the slug bug to move from left to right on the screen. Thus, we simply
need to increase – or add to – its X value. Take a look at the blue MOTION menu. There is a
blue tile made just for this task.
Grab the blue CHANGE X BY 10 tile and add it to the stack.
Try it out by clicking the green flag. Notice the bug “lurches” forward. If we can “loop” a
number of these lurches together, we will be getting somewhere.
Grab the yellow FOREVER tile in the CONTROL menu. Use it to wrap around the blue CHANGE X
BY 10 tile. A FOREVER tile is used to create LOOP of events to do over and over again.
Click the green flag to give it a test drive. Notice the bug runs off the side of the screen and
crashes into the right edge. In order to produce a scroll effect, let’s find some tiles that will
sense when the bug is off the right side of the screen and start it back at the left edge.
Go to the blue SENSING menu and grab the X POSITION OF SPRITE 1 tile. Place it on the scripts
workplace. Use the dropdown menu and choose SPRITE 2 (our slug bug).
Grab a yellow IF loop from the yellow CONTROL menu. Place it on the workplace.
In the green OPERATORS menu grab a green GREATER THAN (the tile that looks like __>__ )
Remember the right edge of the screen X=240. The left edge has an X value of -240. Thus, if we
react when the X value for the bug is greater than 240, we can then move it back to the left side
of the screen. In other words, the X value of the bug increases until it is greater than 240 at
that point we reset the X value of the bug to -240. Here’s how.
Grab the yellow IF tile and place it in the stack.
Put the green GREATHER THAN tile in the hole of the IF tile
Now place the blue X POSITION OF SPRITE 2 tile in the first hole of the green tile.
Now type in 240 in the remaining place - our right side of the screen X value.
The stack now says; “ IF the X value of the bug is greater than 240 we are going to do
something”. What we are going to do is a bit “sleight of hand”. We are going to HIDE the bug,
move it back to the left edge, and then make it reappear – SHOW.
From the purple LOOKS menu grab a purple HIDE tile and place it in the stack.
From the blue MOTION menu, grab a blue SET X TO 0 tile and add it to the stack. Type in -240
for the new X value.
From the purple LOOKS menu grab a purple SHOW tile and place it in the stack.
Click the green flag and give it a try.
How can we slow down the speeding slug bug? How might we speed it up?
By decreasing the amount that the bug “lurches” forward each loop we can slow down and
smooth out its travel.
Type in 4 for the value in the blue CHANGE X BY 10 tile.
If grandma is driving, try typing in a 2 for this value. A 22 for this value will get you up to
NASCAR slug bug speed!
SIMPLE SHOOTER MOVEMENT
Now we are ready to get the spitballs flying.
First let’s SIZE our spit ball. We will want to do this when the game begins, thus we will use the
WHEN GREEN FLAG CLICKED tile.
Grab the yellow WHEN GREEN FLAG CLICKED tile from the CONTROL menu and drop it on the
SCRIPTS workplace for SPRITE 1.
Attach a purple SET SIZE TO 100% tile. Type in a size for your spit ball. Here we will use 30%.
The spitball will start at the bottom edge and travel up. Set its beginning position here. At the
bottom of the screen Y= -180. A Y value of -180 and an X value of 0 will start the spitball off in
the center of the screen at the bottom.
We want our spitball to be fired by the space bar, thus, we will be creating a new stack of tiles
to be triggered by a space bar event.
Grab the yellow WHEN SPACE KEY IS PRESSED tile. Drop it on the SCRIPTS workplace.
Now when the space bar is pushed we simply need to increase the Y value of SPRITE 1 to have it
go flying towards the top of the screen.
Grab a blue CHANGE X BY 10 tile and attach it to the new stack.
Give it a try by pressing the space bar. Again, as with the slug bug, the spitball goes lurching
forward. We need a loop. However, this time we don’t want the spitball go on forever. We
simply need a one-way trip. The idea is we need it to go lurching forward UNTIL it reaches the
top edge of the screen. Remember, at the top edge of the screen Y=180. Here we are going to
use a REPEAT UNTIL loop. We will use this loop to say “repeat the lurch forward until you reach
the top of the screen then do something else”.
Grab a yellow REPEAT UNTIL tile and attach it to the stack. Have the REPEAT UNTIL loop
enclose the blue CHANGE Y BY 10 tile.
Now we will fill the hole next to UNTILL with our conditions – that is when the spitball reaches
the top of the screen.
Grab a green GREATHER THAN tile from the green OPERATORS menu.
Grab a blue X POSITION OF SPRITE 1 tile from the blue SENSING menu. Change the first value of
this tile to Y POSITION.
Now put the pieces together.
Grab the green GREATER THAN tile and place it in the hole in the REPEAT UNTIL tile.
Grab the blue Y POSITION OF SPRITE 1 tile and place it in the first value of the GREATER THAN
tile.
Type in 179 (we need a value just less than the top of the screen) for the second value.
Give it a try. Pushing the space bar will send the spitball off, however we have to click the
green flag to reset it. Let’s add some tiles to auto return the spitball to the bottom of the
screen. Like we did with the slug bug we will use sleight of hand to hide the spitball, move it
and make it reappear.
From the purple LOOKS menu grab a purple HIDE tile and place it in the stack.
From the blue MOTION menu, grab a blue SET Y TO 0 tile and add it to the stack. Type in -180
for the new Y value.
From the purple LOOKS menu grab a purple SHOW tile and place it in the stack.
Now give it a try. The spitballs are flying now.
As with SPRITE 2 (the slug bug) we can change the speed of the spitball by changing the value in
the blue CHANGE Y BY 10 tile.
LEFT AND RIGHT AIMING
Now we need to add a simple left and right aiming system for our spitball. Here we simply
want to move the spitball left and right at the bottom of the screen. Left and right is controlled
by the X value of the SPRITE. When the RIGHT ARROW key is pressed we add 10 to the X value.
When the LEFT ARROW key is pressed we subtract 10.
Add these tiles to the SCRIPTS for SPRITE 1.
Give it a try. See if you can aim and shoot your spitball.
COLLISIONS
Ok now it’s time to create what happens when the spitball hits the target! There are any
number of things that could happen. The spitball could cause the car to change direction,
change color, or explode. We could find a nice “SPLAT!” sound to go with the collision, or a
“TWHUMP!”. Once we create the structure for a spitball hit, you can go back later and create
your own outcomes. For now we are going to do a simple distortion effect for the car and a
nice juicy “SPLAT!” sound for the spitball.
The tiles for a spitball hit are simple. We simply need to SENSE when the spitball is touching
the target. There is a nice blue TOUCHING? tile in the SENSING menu just for this purpose.
With SPRITE 1 (spitball) SCRIPTS selected:
First grab a yellow IF tile from the yellow CONTROL menu. Put this tile on the WHEN SPACEBAR
KEY PRESSED stack just below the blue CHANGE Y BY 10 tile.
Grab a blue TOUCHING __? tile from the blue SENSING menu. Drop it into the yellow IF tile.
In the dropdown menu of this tile choose SPRITE 2.
There is our COLLISION. If the spitball and the slug bug are touching? then whatever we put
inside this loop will happen. Let’s put in our “SPLAT!” sound.
Go to the SOUNDS tab. Click on the IMPORT button and look for the sound of a spitball hit.
Here we are using the sound “Plunge”
Now back to the SCRIPTS tab.
From the pink SOUNDS menu grab the pink PLAY SOUND __ tile and put it in the yellow IF tile.
From the drop down menu choose “Plunge”
Click the GREEN FLAG and give it a try.
Obviously, when the spitball hits, it doesn’t keep going. We need to HIDE the spitball once it
hits the car.
From the purple LOOKS menu grab a purple HIDE tile. Place it in the stack just under our
SOUNDS tile.
Now for the impact of the spitball hit on the SPRITE 2 – the slug bug. At this point the SCRIPTS
for the spitball and the slug bug are completely separate. How does the car know that it’s been
hit? One way would be to put a second TOUCHING? loop in the slug bug SCRIPT. A better way
is for us to announce an event. Right here where the spitball hits the bug we can announce or
BROADCAST to all the other parts of the game that something happened. “We have a HIT!”.
The other parts of the game can listen for this event and react when they hear that there has
been a “HIT!”.
Grab a yellow BROADCAST __ tile from the yellow CONTROL menu. In the dropdown menu
choose new and type in “hit”.
Now we have announced to the game “We have a hit!”. Let’s create a reaction for the slug bug
SPRITE.
Go to the SCRIPTS TAB for SPRITE 2 (the slug bug)
Grab a yellow WHEN I RECEIVE <__> tile. Choose “hit” from the dropdown menu. Drop it in the
SCRIPTS window for SPRITE 2
SCRATCH has a number of graphic effects. One of them is FISHEYE. The FISHEYE effect bulges
the SPRITE at the center.
Add these tiles to the stack to create a momentary “bulge” in the slug bug as it is hit by the spit
ball.
Now give the game a try.
EXPAND THE DESIGN
There are SO MANY ways in which this simple shooter game can be expanded. Take a look at
the DRAGON HUNTER game to get some ideas.
There are SO MANY shooter games in the world today. Remember to use good taste. Be a
responsible “shooter”. Do not promote any activity which goes beyond the decorum of good
clean fun! Some good rules to follow are: NO GUNS! NO GUTS! NO SHOOTING PEOPLE!
dr vic 3/10
Download