Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make platforms?
- kotilo
-
Scratcher
11 posts
How to make platforms?
Yeah, I wanna know how to make platforms in scratch. Can you tell me how? I've tried many times, but I haven't devise how to make it. If someone can tell me it, I'll use it in my game and I'll write your username to the credit box of my game.
- Braeden5454
-
Scratcher
500+ posts
How to make platforms?
Platforms like IN a game, or the game type? If you answer I will be glad to help. 

- Mister_Guacamole
-
Scratcher
26 posts
How to make platforms?
Platforms are a concept, the same way the button of your main menu is. The simplest platform you could do would be a rectangle. As you surely know, a rectangle has a width and a height, but it also (speaking in terms of Scratch) has a (x, y) position on the screen, (0, 0) being the center of the view. So let's say we have a red rectangle you made with the editor that has these properties set in the code:
It will come handy after. Now we need a player, because what would be a game without a player? For simplicity's sake, our player will be a rectangle, a plain good ol' rectangle just like our platform:
…But our poor player, he can't move! We need to implement a basic movement system for our rectangle. Let's write down what we want to player to be able to do:
In code it could look like this:
Alright, now we need a collision between our player and the platform, else what kind of platform is this?! ‘Collision’ here doesn't mean something dangerous or bad, it's simply detecting if two things - player/platform - are touching. Since we are dealing with two rectangle the collision detection is pretty forward (but if you are interested in more check out the SAT algorithm and start from there). Two rectangles are touching when they are overlapping. Overlapping in term of rectangles means that… well it'd be better explained in code
(note that this is only for X overlapping; you need to figure out how to do it for the Y axis on your own)
Then you can update your player movement code to something like this: (to restrict movement when colliding)
Tell me if this wasn't clear!
set [platform x v] to [0]
set [platform y v] to [0]
set [platform width v] to [100]
set [platform height v] to [50]
It will come handy after. Now we need a player, because what would be a game without a player? For simplicity's sake, our player will be a rectangle, a plain good ol' rectangle just like our platform:
set [player x v] to [0]
set [player y v] to [0]
set [player width v] to [10]
set [player height v] to [10]
…But our poor player, he can't move! We need to implement a basic movement system for our rectangle. Let's write down what we want to player to be able to do:
- Move to the left/right when the user presses the associated keys on the keyboard
- Float up when the user has pressed the up arrow
- Float down when the user has pressed the down arrow
In code it could look like this:
forever
if <key [left v] pressed?> then
change [player x v] by (-1)
end
if <key [right v] pressed?> then
change [player x v] by (1)
end
if <key [up v] pressed?> then
change [player y v] by (1)
end
if <key [down v] pressed?> then
change [player y v] by (-1)
end
end
Alright, now we need a collision between our player and the platform, else what kind of platform is this?! ‘Collision’ here doesn't mean something dangerous or bad, it's simply detecting if two things - player/platform - are touching. Since we are dealing with two rectangle the collision detection is pretty forward (but if you are interested in more check out the SAT algorithm and start from there). Two rectangles are touching when they are overlapping. Overlapping in term of rectangles means that… well it'd be better explained in code
(note that this is only for X overlapping; you need to figure out how to do it for the Y axis on your own)if <((player x) - ((player width) / (2))) < ((platform x) + ((platform width) / (2)))> then
if <((player x) + ((player width) / (2))) > ((platform x) - ((platform width) / (2)))> then
set [collision with platform v] to [true]
end
else
set [collision with platform v] to [false]
end
Then you can update your player movement code to something like this: (to restrict movement when colliding)
forever
if <(collision with platform) = [false]>
if <key [left v] pressed?> then
change [player x v] by (-1)
end
if <key [right v] pressed?> then
change [player x v] by (1)
end
if <key [up v] pressed?> then
change [player y v] by (1)
end
if <key [down v] pressed?> then
change [player y v] by (-1)
end
end
end
Tell me if this wasn't clear!
Last edited by Mister_Guacamole (May 26, 2014 17:02:24)
- kotilo
-
Scratcher
11 posts
How to make platforms?
thank you!!! You have spent much time with this. I use that in my games, is it alright? I'll write your name to the credit box.
And braeden I meant IN a game. Thanks for you too.

And braeden I meant IN a game. Thanks for you too.
Last edited by kotilo (May 26, 2014 18:10:35)
- Mister_Guacamole
-
Scratcher
26 posts
How to make platforms?
You're welcome!
You can use it, I made it for that, even thought the code will certainly not work properly without adaptation from your part.
You can use it, I made it for that, even thought the code will certainly not work properly without adaptation from your part.- GCGCGC
-
Scratcher
100+ posts
How to make platforms?
I guess you're not making a regular platformer game?
Sounds more like a maze type game.
Interesting code. Also works as a wall, I suppose.
Sounds more like a maze type game.
Interesting code. Also works as a wall, I suppose.
- boomerang455
-
Scratcher
2 posts
How to make platforms?
How do you make obstacles?
when green flag clicked
forever
if <> then
then what do you do?
- boomerang455
-
Scratcher
2 posts
How to make platforms?
I'm trying to make a game. How do you
make something teleport you
when green flag clicked
define unrelyable to sprite 3<touching [ v] ?>
go to x: () y: (0)
- WhiteWolf100
-
Scratcher
28 posts
How to make platforms?
i need how to make a platform, btw if you want to know any of the basics, comment my profile . i think you have to make a variable and choose set to one if touching? then move 10 steps if you want to set a platform? 

set [ whateveruwantv] to [1 ]
if <touching [sprite1 v] ?> then
move (10) steps
end
- WhiteWolf100
-
Scratcher
28 posts
How to make platforms?
it takes a long time :p
first you get a chanractar and put codes to make it move then to make it jump thn desigh an start button blah blah blah thn desight anll the levls and backgrounds blah te blah blah blah and thn add sound blah blah blah.
to sum it all up, a good game it hard to make.
first you get a chanractar and put codes to make it move then to make it jump thn desigh an start button blah blah blah thn desight anll the levls and backgrounds blah te blah blah blah and thn add sound blah blah blah.
to sum it all up, a good game it hard to make.
Last edited by WhiteWolf100 (May 11, 2015 14:13:14)
- Discussion Forums
- » Help with Scripts
-
» How to make platforms?