I'm currently making and game called Platformer Boy, and as the name says, its a platformer game. I need to know how the character can jump, then fall down(Gravity?), and stand on platforms, as well as if the character falls off a platform, they lose a life and have to restart. I also need to know how to make it so when you run out of lives, you lose the game. Can someone post some scripts to help me out with my problem? Thanks for your time.
-Mattkrewe
P.S: Does anyone have any decent music I could use in my game, other then the music Scratch already has? Thanks!
Offline
http://wiki.scratch.mit.edu/wiki/Platformer
Hope it helped!
Offline
Offline
I'll just write them out for him
To jump (with gravity)
when gf clicked forever if <<key [up arrow v] pressed?> and <touching color [#000000] ?>>//colour of platform set [yVel v] to [14] wait until <not <touching color [#000000] ?>> end repeat until <touching color [#000000] ?> change [yVel v] by [-1] end if <touching color [#000000] ?> set [yVel v] to [0] when gf clicked forever change y by (yVel)For the loosing lives if falling off platforms:
when gf clicked go to x: (0) y: (0) forever if <(y position) < [-180] >//-180 is the bottom of screen change [lives v] by [-1] go to x: (0) y: (0)x:0 y:0 is the spawning point unless it's a scrolling platformer where you'd have to use
set [scroll v] to [0]Game Over Script:
forever if <(lives) > [0]> every script you use hereyou would have to put this script around all the scripts you use so that movement is disabled if it's game over. Then you could add a game over screen which would be a seperate sprite:
when gf clicked hide forever if <(lives) = [0]> show
Offline
To jump:
when gf clicked forever if <<touching colour [#000000] and <key [up arrow] is pressed>> change y by (10) // too high? end if <not<touching colour [#000000]>> change y by (-3) // too strong/weak? end endFor the lives thing you would need to create a variable called lives and use this script.
when gf is clicked forever if <<lives v>=(0)> broadcast [game over] end
Offline
Weird, I've used my scripts in the program and it works fine. 1 thing I forgot to mention is that you should probably include this block:
set [yVel v] to [0]RIGHT AT THE TOP of the script, immediately below the when flag clicked block. Other things that might make it glitch:
Offline
I have uploaded the current version of my game Phirrip. Please check it out and download it, and see what is wrong with it. However, I have an idea of what the problem might be, but I could be wrong.
*Please note that I haven't added in the losing lives if you fall off a platform script yet.
-Mattkrewe
Offline
Fixed.
Basically the problem was that "Level 1-1" was broadcasted while the "Level 1-1" screen was showing, not when the level actually starts so the player was playing without the screen showing. Also, the player wasn't starting on the platform. To fix this, I changed the script for W1 to this:
when I receive [Level 1-1 v] go to x: (-176) y: (-2) set [yVel v] to [0] wait (5) secs forever rest of scriptThere was another problem with the jumping. Instead of
change [yVel v] by [-1]you included;
set [yVel v] to [-1]You should just replace this and the jumping works much better.
when I receive [Level 1-1 v] forever if <key [a v] pressed?> point in direction (-90) move (5) steps end if <key [d v] pressed?> point in direction (90) move (5) steps endInsert this script and you'll see the results!
Last edited by PhirripSyrrip (2012-06-10 03:09:00)
Offline
Which script are you talking about? For the jumping script, keep your current one except change "set yvel to -1" to "change yvel to -1". Add the "go to" block I added immediately under "when I receive level 1-1" and the "wait 5 secs" block where I put it. so change those 3 things about the script, you don't need another one.
For the moving script, add the script I added but delete the two scripts that start "when a key pressed" and "when d key pressed".
Offline
Never mind my last post. I put in all the scripts and it's working fine, however the losing lives script isn't working correctly. When the character falls off a platform, it stays there and doesn't lose a life. I might be able to fix it though.
-Mattkrewe
Offline
Mattkrewe wrote:
I have uploaded the newest version of Platformer Boy, I couldn't tell what was wrong with the losing lives script, so maybe you could figure it out please?
-Mattkrewe
Try using this script.
put a thin line at the bottom in a color you haven't used yet (color x)
when gf clicked forever if <touching color (color x)> change [life] by[-1] end end
Offline
Here is a gravity script. The color in the script can be changed to whatever color your platform is. The value gravity is set to if the up arrow is pressed can also be changed. It will affect the distance jumped.
when gf clicked set [Gravity v] to [0] forever if <touching color [color of ground]> set [Gravity v] to [0] change y by [1] if <key [up arrow v] pressed?> set [Gravity v] to [the larger this number is, the higher your sprite will jump] end else change [Gravity v] by [-1] change y by (Gravity) end end
Last edited by skippito (2012-06-20 17:23:29)
Offline