Discuss Scratch

lambodhar
Scratcher
42 posts

How to make a Platformer || Platformer Tutorial

Hey There! Welcome to a Platformer Tutorial
I will be showing you how to make a Platformer with a ton of features including Enemy AI, Water, smooth movement and more!
If you use this tutorial please do credit me @lambodhar. Also, it would be great if you followed me too since I worked hard on making this tutorial
Additionally, you can have fun playing this game below:
Just click on the image to play and have fun!



whenclickedplaysounddrumrolluntildonesayLet get started!

Let's first start off by drawing the player!
Make a new sprite and then, draw the player as a square as depicted below



Let's now code the player
Just follow all the coding below :)

defineRunEnginewithspeed:speedjumpheight:jumpheightFriction:frictionsetrotationstyleleft-rightgravityifkeyright arrowpressed?thenchangeSpeed xbyspeedpointindirection90ifkeyleft arrowpressed?thenchangeSpeed xby-speedpointindirection-90setSpeed xtoSpeedx*frictionchangexbySpeedxiftouchinglevel?thenchangeyby1iftouchinglevel?thenchangeyby1iftouchinglevel?thenchangeyby1iftouchinglevel?thenchangeyby1iftouchinglevel?thenchangeyby1iftouchinglevel?thenchangexbySpeedx*-1changeyby-5ifkeyup arrowpressed?orkeywpressed?thenifSpeedx<0thensetSpeed xto8elsesetSpeed xto-8setspeed Yto10elsesetSpeed xto0changeybyspeedYiftouchinglevel?thenchangeybyspeedY*-1setspeed Yto0changeyby-1iftouchingwater?thenifkeyup arrowpressed?orkeywpressed?thensetspeed Yto3elseiftouchinglevel?thenifkeyup arrowpressed?orkeywpressed?thensetspeed Ytojumpheightchangeyby1if237<xpositionthenbroadcastnext levelbroadcastlevel resetbroadcastsetup enemiesbroadcastsetup trampolinesifyposition<-174thenbroadcastlevel resetbroadcastsetup enemiesbroadcastsetup trampolinesiftouchingenemy?thensetspeed Yto10whenclickedsetlevelto1broadcastlevel resetbroadcastsetup enemiesbroadcastsetup trampolinesforeverRunEnginewithspeed:1jumpheight:15Friction:0.9whenIreceivelevel resetgotox:-192y:47setSpeed xto0setspeed Yto0whenIreceivenext levelchangelevelby1definegravityiftouchingwater?thenchangespeed Yby-0.3elsechangespeed Yby-1

We are now done with the coding the player!

Now, let's code the level.

Make a new sprite called level.
Then make multiple costumes of different level as shown in the below picture
Each costume is a one level


Then, code the level as shown below
whenclickedforeverswitchcostumetolevel

Now, let's make enemy AI
For this, duplicate the player sprite and then edit the enemy codes as shown below.
You can additionally, make the enemy red colour


defineRunEnginewithspeed:speedjumpheight:jumpheightFriction:frictionshowchangespeed Yby-1ifxposition<x positionofPlayerthenchangeSpeed xbyspeedifx positionofPlayer<xpositionthenchangeSpeed xby-speedsetSpeed xtoSpeedx*frictionchangexbySpeedxiftouchinglevel?thenchangeyby1iftouchinglevel?thenchangeyby1iftouchinglevel?thenchangeyby1iftouchinglevel?thenchangeyby1iftouchinglevel?thenchangeyby1iftouchinglevel?thenchangexbySpeedx*-1changeyby-5if15+yposition<y positionofPlayerthenifSpeedx<0thensetSpeed xto8elsesetSpeed xto-8setspeed Yto10elsesetSpeed xto0changeybyspeedYiftouchinglevel?thenchangeybyspeedY*-1setspeed Yto0changeyby-1iftouchinglevel?thenifyposition+15<y positionofPlayerthensetspeed Ytojumpheightchangeyby1ifyposition<-173thendeletethiscloneiftouchingPlayer?thenifyposition<y positionofPlayer+7thendeletethiscloneelsebroadcastlevel resetbroadcastsetup enemieswhenIreceivelevel resetgotox:167y:47setSpeed xto0setspeed Yto0whenIstartasaclonesetSpeed xto0setspeed Yto0foreverRunEnginewithspeed:.7jumpheight:15Friction:0.9defineCloneatX:xy:Ygotox:xy:YcreatecloneofmyselfThiscustomblockhelpsustoplaceenemies.Toplaceyourenemy,typeintheXcoordinateinthefirstblankandYcoordinateitthesecondblank.SeebelowcodeforexampleonhowtousetheblockwhenIreceivesetup enemiesiflevel=2thenCloneatX:184y:88iflevel=3thenCloneatX:180y:-9whenIreceivelevel resetdeletethisclone

Now, we are done with coding the enemy AI!


Now, let's code the water!
For this, make a new sprite called water and make the water level the same way you made the ground levels!
Each costume will be one level
Preferably, make the colour “blue”
Then, code the water as shown below:
whenclickedforeverswitchcostumetolevel




AND….. You are now done!!!!
CONGRATS ON MAKING AN ADVANCED PLATFORMER!
IF YOU HAVE ANY DOUBTS, BE SURE TO COMMENT ON MY PROFILE OR YOU CAN ASK IN THIS FORUM TOPIC ITSELF!

THANKS AND BE SURE TO CREDIT ME @lambodhar IF YOU USE THIS TUTORIAL
ALSO, CONSIDER FOLLOWING ME TOO!
BYE…


Last edited by lambodhar (Sept. 30, 2020 03:00:46)

Cat_Dusty
Scratcher
500+ posts

How to make a Platformer || Platformer Tutorial

This isn't the right place to post this…
lambodhar
Scratcher
42 posts

How to make a Platformer || Platformer Tutorial

Cat_Dusty wrote:

This isn't the right place to post this…
Then where should this be posted?

Powered by DjangoBB