banner



how to make a platformer on scratch

DocumentInQuestion.png This page or section is in question every bit to whether it is useful or not. You can discuss whether y'all desire it deleted or not on its talk page. (March 2022)
Reason: Indistinguishable of How to Make a Basic Platformer?

A advanced platformer is a game where the role player has to jump on platforms and go to the stop to win. This tutorial shows how to make a static platformer, where the player has to get to a green square to move on to the adjacent level. This features wall jumping, wall detection, ceiling detection, lava detection, trampoline detection, and real-life gravity.

Training

Variables

Make these variables:

(x velocity) (y velocity)        

Sprites

These sprites are needed:

  • A player sprite (a small just visible shape)
  • A level sprite

My Blocks

Brand the blocks:

define platform define initialize        

in the role player sprite.

Making the Game

Levels

To brand levels, make costumes in the level sprite. Employ the tools in the costume editor to make platforms for the histrion to jump on. To brand lava, which resets the player, describe carmine areas. To make trampolines, just draw areas that are in the preferred color except red. Remember that trampolines push the player directly up. Make a small greenish square in each level in the preferred area, which the player has to bear upon to move to the next level. If it is preferred, write text in each level that says what level the actor is on. Once finished making plenty levels, brand a final costume that says The game is complete (or other preferred text). Brand sure to call the last costume win so that it is known when the player won.

Code

Player

Nether the initialize cake in the player sprite, add the post-obit lawmaking:

define initialize get to x: (-220) y: (-50) //Or whatever other position that is preferred. set [x velocity v] to (0) set [y velocity 5] to (0)        

Nether the platform cake in the player sprite, add the following lawmaking:

ascertain platform point in management (90) if <key (right arrow v) pressed> then change [10 velocity v] past (1) //Motility right. cease if <key (left arrow v) pressed> and so change [x velocity v] by (-1) //Move left. stop set [x velocity v] to ((ten velocity)*(0.9)) //Gradually tiresome down the player. change 10 by (x velocity) //Really move. if <touching (level five)> so //Gradient detection. The more nested ifs, the smoother slopes are to run on. Make sure that the number of if thens is correct. modify y by (i) if <touching (level five)> and then change y by (1) if <touching (level v)> and then change y by (1) if <touching (level v)> then change y by (1) if <touching (level v)> and then change y by (1) if <touching (level v)> then change y by (1) if <touching (level v)> and so change y by (1) if <touching (level v)> and then change y by (1) if <touching (level 5)> then change y by (i) if <touching (level five)> and so change y past (1) if <touching (level five)> then modify 10 by ((0)-(ten velocity)) change y past (-10) if <key (upwardly arrow v) pressed> then if <(x velocity) > (0)> so set up [x velocity 5] to (-7) else set [10 velocity v] to (seven) end fix [y velocity 5] to (xiv) //14 is the leap speed. else set [x velocity v] to (0) //Do naught if the histrion isn't jumping. finish end terminate end end stop end end end finish end end change [y velocity five] by (-ane) //Gravity. change y past (y velocity) //Really motion (up/down). if <touching (level 5)> then  change y by ((0)-(y velocity)) //Makes certain the role player doesn't sink into the ground. set [y velocity 5] to (0) //End moving downward. end alter y by (-ane) //Go down a bit to sense the ground. if <<touching (level v)> and <central (up arrow five) pressed>> then //leap if touching the ground set [y velocity v] to (12) //12 is the jump speed, which slowly gets smaller considering of the gravity 2 blocks earlier the previous if. cease change y by (1) //Move support that chip the player moved down. if on border, bounce //Brand sure the role player doesn't go off the screen. if <touching color (#00FF00)?> then //Set the colour to the color of the light-green foursquare. initialize::custom //If the histrion touches the green square, the role player passed the level, then the player goes back to the beginning. broadcast (next level 5) //This will be received in the level sprite. end if <touching color (#FF0000)?> then //Restart if the player touches lava; make sure this cerise is the same shade of red that is used for the lava. initialize::custom  end if <touching color (#FFA500)?> then //Brand it any color the trampolines are. set up [y velocity v] to (22) //It has to spring college than the normal jump speed. end        

Finally, add this last office in and so that the sprite volition proceed running the platform cake.

when gf clicked testify forever platform::custom ...//As well add together this next office to sense when the thespian wins. if <([costume proper noun v] of (level v)) = [win]> then //This is why the final costume is chosen "win". hide terminate [this script 5] end finish        

Level

The level sprite has much less code than the histrion sprite. Insert this code in:

when gf clicked switch costume to (costume1 v) //Or whatever the showtime costume is called.  when I receive [next level v] //Broadcasted by the role player sprite. adjacent costume        

Stage

This is optional, only to make the platformer accept music when the player wins, backpack it from here or download it. Make sure the site where the music is beingness downloaded is safety. For the sound effect, take it from the Scratch library. "Win" or "Triumph" are examples. Insert the music and sound result into the stage, and and so insert the post-obit code:

when gf clicked forever play sound (music v) until done //Whatever the music is called. finish  when gf clicked await until <([costume name v] of (level v)) = [win]> //This is some other. stop [other scripts in sprite v] //Stop the music. offset sound (win five) //Or Triumph, if that was called.        

The platformer is done.

Cookies aid us deliver our services. By using our services, you agree to our use of cookies.

The Wiki is working on a night theme, and you're seeing it! Got feedback? Post on the Wiki Forum Topic.

Source: https://en.scratch-wiki.info/wiki/Advanced_Platformer_Tutorial

Posted by: smithplagne.blogspot.com

0 Response to "how to make a platformer on scratch"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel