This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-06-09 10:13:16

Mattkrewe
New Scratcher
Registered: 2012-06-09
Posts: 8

I need some help

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

 

#2 2012-06-09 10:30:41

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: I need some help


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#3 2012-06-09 10:36:35

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: I need some help

For music, I like to go here, and here.

Last edited by sonicfan12p (2012-06-09 10:37:16)


Why are the secret organizations getting all the attention?  mad

Offline

 

#4 2012-06-09 10:48:59

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: I need some help

I'll just write them out for him  wink
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 here
you 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


http://i46.tinypic.com/ao03lk.png

Offline

 

#5 2012-06-09 13:35:24

JH1010
Scratcher
Registered: 2012-05-31
Posts: 1000+

Re: I need some help

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
end
For 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

 

#6 2012-06-09 14:16:04

Mattkrewe
New Scratcher
Registered: 2012-06-09
Posts: 8

Re: I need some help

Thanks phirrup! Your scripts will help me a lot!  smile

Offline

 

#7 2012-06-09 14:36:44

Mattkrewe
New Scratcher
Registered: 2012-06-09
Posts: 8

Re: I need some help

Wait, the scripts aren't working correctly. The gravity is working, except the character wont stay on the platforms. Phirrip, can you explain this please?  sad

Offline

 

#8 2012-06-09 16:32:10

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: I need some help

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:
•Colour of ground in script is not the same as the actuall colour of platform
•That block mentioned above is missing
•You've double-scripted it meaning that something is going wrong. Usually this involves wait until, repeat until or wait 1 secs blocks (As I said, I tested my jumping script and it works for me...)
•The platforms are too thin

Doubl-check the script. You could upload a test project so that we can see exactly what's wrong.


http://i46.tinypic.com/ao03lk.png

Offline

 

#9 2012-06-09 18:36:05

Mattkrewe
New Scratcher
Registered: 2012-06-09
Posts: 8

Re: I need some help

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

 

#10 2012-06-10 03:08:08

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: I need some help

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 script
There 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.

1 more thing: Delete the scripts which start "when a pressed", "when d pressed" and add this instead:
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
end
Insert this script and you'll see the results!

Last edited by PhirripSyrrip (2012-06-10 03:09:00)


http://i46.tinypic.com/ao03lk.png

Offline

 

#11 2012-06-10 09:47:43

Mattkrewe
New Scratcher
Registered: 2012-06-09
Posts: 8

Re: I need some help

Okay, but do I leave the old script and add in the new one?

Offline

 

#12 2012-06-10 09:56:43

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: I need some help

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".


http://i46.tinypic.com/ao03lk.png

Offline

 

#13 2012-06-10 10:11:51

Mattkrewe
New Scratcher
Registered: 2012-06-09
Posts: 8

Re: I need some help

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

 

#14 2012-06-10 10:26:30

Mattkrewe
New Scratcher
Registered: 2012-06-09
Posts: 8

Re: I need some help

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

Offline

 

#15 2012-06-19 22:29:14

wahoo77
New Scratcher
Registered: 2012-06-17
Posts: 27

Re: I need some help

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

 

#16 2012-06-20 09:30:25

skippito
Scratcher
Registered: 2012-03-17
Posts: 100+

Re: I need some help

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

 

#17 2012-06-22 09:26:41

wahoo77
New Scratcher
Registered: 2012-06-17
Posts: 27

Re: I need some help

instead of


    if <y position <-180> 
use
if <y position <-179>

Offline

 

#18 2012-06-22 09:31:52

wahoo77
New Scratcher
Registered: 2012-06-17
Posts: 27

Re: I need some help

instead of


    if <(y position) < [-180]> 
    lose life
use
if <(y position) < [-179]>
lose life
sorry for the first version    I couldn't preveiw it  sad

Offline

 

Board footer