Discuss Scratch

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:

setplatform xto0setplatform yto0setplatform widthto100setplatform heightto50

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:

setplayer xto0setplayer yto0setplayer widthto10setplayer heightto10

…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:

foreverifkeyleftpressed?thenchangeplayer xby-1ifkeyrightpressed?thenchangeplayer xby1ifkeyuppressed?thenchangeplayer yby1ifkeydownpressed?thenchangeplayer yby-1

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)

ifplayerx-playerwidth/2<platformx+platformwidth/2thenifplayerx+playerwidth/2>platformx-platformwidth/2thensetcollision with platformtotrueelsesetcollision with platformtofalse

Then you can update your player movement code to something like this: (to restrict movement when colliding)

foreverifcollisionwithplatform=falseifkeyleftpressed?thenchangeplayer xby-1ifkeyrightpressed?thenchangeplayer xby1ifkeyuppressed?thenchangeplayer yby1ifkeydownpressed?thenchangeplayer yby-1

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.

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.
kotilo
Scratcher
11 posts

How to make platforms?

Thanks. You're awsome.
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.
boomerang455
Scratcher
2 posts

How to make platforms?

How do you make obstacles?
whenclickedforeverifthenthenwhatdoyoudo?
boomerang455
Scratcher
2 posts

How to make platforms?

I'm trying to make a game. How do you
makesomethingteleportyouwhenclickeddefineunrelyabletosprite3touching?gotox: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 whateveruwantvto1 iftouchingsprite1?thenmove10steps
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.

Last edited by WhiteWolf100 (May 11, 2015 14:13:14)

SiberianLIGER
Scratcher
1 post

How to make platforms?

hello

Powered by DjangoBB