I know when I started Scratch, it seemed really confusing. It's not. I'll be posting a simple game here. Lets make it a shooting games with enemies, a stationed gun in the center, and bullets. This first posts will break down and show you the gun script.
Make a new sprite (under the white stage area there is a button to bring up the paint editor). Make your gun and hit OK. Now add this script to it:
<when green flag clicked>
<forever>
<point towards( mouse pointer
<if><key[ space ]pressed?>
<broadcast[ shoot
<end>
<end>
This will make your gun aim at the mouse pointer (or perpendicular if you drew your gun facing up not to the right). Whenever you press space, you will shoot (once you add the bullet scripts). Now the breakdown:
<when green flag clicked>
<forever>
<end>
So what does that do? Well, that starts your game.
<when green flag clicked> is when your game is fully loaded in the Java player, or
when you click the green flag in the Scratch program. You need it to start your game/animation
<forever>
<end> What this is is a forever loop. It is kinda self explanatory. Forever, this will
happen. In this case, it will always point towards your mouse pointer.
<if><key[ space ]pressed?>
<broadcast[ shoot
<end> In a forever loop, this will keep checking whether this is true or
not. If it is true (you press space) you will shoot. What is that broadcast thing there though? Well, think of it like an intercom. When someone talks in an intercom at school, each classroom can hear. In this case, each classroom is a sprite, so you send a message to each sprite. I'll talk about how to hear that message over the intercom later.
Last edited by Bluestribute (2008-08-22 21:18:06)
Offline
O.K., time for ammo. Put these scripts on a new sprite called ammo (after you draw it in the paint editor):
<when green flag clicked>
<hide>
<when I receive[ shoot
<go to[ gun
<point in direction( direction of gun
<show>
<repeat until><< <touching[ edge <or> <touching[ enemy >>
<move( 10 )steps>
<end>
<hide>
Now for the breakdown of some new blocks:
<when I receive[ shoot Remember when we broadcasted shoot, and I used the intercom analogy? Well, you can't hear the intercom without it being on, and this is how. With this block, you have now turned on the intercom so you can say "Oh, time to shoot".
<repeat until> Repeat until that condition is true. In this case, touching the edge or enemy
Those are really the blocks you will need to know- the control blocks. The others are self explanatory
Offline
Now for a hitTest on the enemy (not movement, just to see whether it got shot):
<when green flag clicked>
<show>
<forever>
<wait( <pick random( 1 )to( 5 )secsc>
<show>
<if><touching[ bullet
<hide>
<wait( <pick random( 1 )to( 5 )secsc>
<show>
<end>
<end>
See, very simple
Offline
Thanks for posting this guide I made something out of this guide! SEE IT: http://scratch.mit.edu/projects/matthewjose/248855 Thanks for always being a helpful scratcher!
Offline
matthewjose wrote:
Thanks for posting this guide I made something out of this guide! SEE IT: http://scratch.mit.edu/projects/matthewjose/248855 Thanks for always being a helpful scratcher!
Cool! I'll look at it later, cause I can't right now. Anyways, I'll post enemy moving later
Offline
OK, enemy movement time! This is the most basic of AI's cause I am really bad at them (artificial intelligence or Computer Player), but anyways, I used this method for my Turret game:
<when green flag clicked>
<hide>
<forever>
<wait( <pick random( 1 )to( 5 )secsc>
<go to x Where you want )y Where you want
<point towards( player
<show>
<move( 10 )steps>
<end>
That should be the movement script, though I'll need to see if it is correct…
Later I'll show you how to add this script to your hitTest
Last edited by Bluestribute (2008-08-24 13:17:39)
Offline
Ok, to add the above script to your hitTest, do this:
<when green flag clicked>
<hide>
<forever>
<wait( <pick random( 1 )to( 5 )secsc>
<go to x starting X )y starting Y
<point towards( player
<show>
<move( 10 )steps>
<if><touching[ bullet
<hide>
<go to x starting X )y:(starting Y
<wait( <pick random( 1 )to( 5 )secsc>
<show>
<end>
<end>
That should work. And theres your first game- a shoot 'um up
Offline