I've started Scratch recently and am having trouble with scripting. So far I know how to move left and right, have made a background, and have some music. Any help with jumping, goals and things such as spikes. Thanks
Offline
Okay, let's say the spikes causes the sprite to die or lose a life. Have this script for the main sprite:
When green flag clicked
set life to 3
if touching spike, change life to -1
Or life could be health, but you get the main jist of it. Now, for gravity, there are tons of ways scripting works with gravity. My way, well, is different from others, and this script allows the sprite to not go through platforms and has a goof gravity engine.
Here it is below (tell me if you don't understand something in here):
Hit right test shall be a variable.
Xvelocity will be set as x.
Hit test left will also be a variable.
Gravity set as y.
The sensor sprite will have four lines at each corner like a rectangle but an empty middle. Each line will have a different color.
Sensore sprite- When green flag clicked
go to main sprite
set ghost effect to 100
forever if color green (this will be platform color bottom) touching color yellow
broadcast hit test left
if color green touching color blue
broadcast hit test right
etc
etc
The main sprite will then have the script as this:
When green flag clicked
hit right test =1, change xvelocity by -4, set hit test left to 0
hit test left=1, change xvelocity by 4, set hit test leeft to 0.
Forever
<if else touching color <whatever color platform bottom> set gravity to .2 <if touching whatever color platform top>set gravity to -1
change gravity by -0.2
if <key up arrow pressed and touching color <whatever color platform bottom>
set gravity to 4.3
change y by Gravity
if else key right arrow presssed
move five steps right
set xVelocity to 5
if else key left arrow pressed
move five steps left
set xVelocity to -2.5
set xVelocity to 0
change x by xVelocity
Again, sorry if I coded some things wrong; it's hard to explain if not looking at scripts of somebody's gravity game. Other scripting of Other Scratchers would be different though. Hope this helps, and good luck! If you need more help, look at Scratch Wiki. THey have alot of articles.
Last edited by kingofdallamas (2011-03-16 22:55:10)
Offline