Power Up Super Mario | Tile Scrolling Platformer e18

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello fellow scratchers i'm griff patch and welcome back to part 18 of our tile scrolling series probably soon to be rebranded as our how to code super mario advance 4 in scratch series today we finally will be adding mario what do you think we added them a long time back well kinda yeah but there's a difference between mario and super mario super mario is of course the big mario player while mario well he's the little tiny guy we start out with so today we add mini mario yay long time coming right in doing so we will introduce the power mechanic for mushrooms for this epic transformation into super mario and of course his power down when he gets caught by an enemy this is really fun to have and makes the game so cool for this we will of course need some new costumes so do head over to the starter asset project linked under this video take a look in the mario sprite costumes and scroll down there costumes 11 and onwards are the new mini mario costumes if i zoom in yeah there he is just open your backpack and drop the entire mario sprite in there great okay so open your tile scrolling projects from part 17. to prevent us losing any work make sure to save it as a copy and once scratch has stopped whirring we can name it part 18. yay guys let's get scratching we'll begin by bringing in those new costumes open your backpack again and drag the mario sprite into this project now we have the mario 2 sprite we want to find the mini walk 1 costume number 11 and then one by one we'll drag them into the official mario sprite like this all the way up to costume 19. super before we delete the mario 2 sprite just click into the mario and ensure we have all 19 costumes in there yep so delete mario 2. before we make use of any of these costumes let me just explain how they are set up it's important to realize i don't just chuck these costumes into scratch they are very purposefully positioned and aligned to work just right here is the big super mario costume if i leave a copy on the screen so that you can see how things line up then i'll switch to the mini mario now see how his feet are perfectly aligned with super mario this ensures as we switch between costumes we still have his feet on the floor now we could have done this a very different way by centering mario vertically and changing the height variable but as you will see this way turns out a lot less complicated now the walk animation of mini mario is just two frames rather than super mario's four to simplify our code i have therefore duplicated up the two mini mario walking costumes to make it a four frame walk cycle two now did you notice the names of these costumes is very specific all the super mario costumes begin with mario and the mini mario ones begin with mini other than that what follows is the same walk one turn jump this will make coding up the animations much easier you'll see in a moment oh and then there's this last costume mario transform this one is a mid-height mario between the mini and the super mario we'll use this to add a little pizzazz to our power up and down animations so are you ready our coding begins in the super mario sprite find with me the define paint sprite custom block now i'm using scratch add-ons quite heavily in this tutorial to find my way around when the project gets as big and complicated as this one it becomes a lifesaver so this script sets mario's costume based on their current action you can see all the switch costume names are mario this and mario that well that's useful because now we have a new set of mini mario costumes that all start mini this and mini that let's make it so that we can quickly switch between the two costume sets start by making a new variable naming it mario for all sprites now set it to mario oh dear scratch is still only showing half my block as i drag it around i hope that gets fixed soon duplicate that and this time set it to mini that's our new costume set name so bring in a join so where we are switching costume here to mario crouch we can join our mario variable with the word crouch to give us the full name mario crouch we just need to make absolutely sure we have written this without any typos and even the capital letters must be the same otherwise this will not work once we are sure we can drop it into the switch costume like so now we work our way down each of these switch costume blocks duplicating the join block and entering the corresponding costume action mario death mario jump mario walk three mario turn ah now this walk animation is not quite so straightforward we don't use a name here but the number one no problem though start by adding a new switch costume above it and oh yeah this is where we start with mario walk one now we replace this like the others with a join mario with walk one then when we had a one here below we replaced that with the current costume number block since that will now be the number of the first walk costume great it's time to give that a test assuming that mario variable is still set to mario with a capital m our costumes should look like they have for the last 16 episodes or so okay not so exciting but very cool that it is indeed looking correct but now for some fun click the set mario to mini block and pow did you see that we instantly switched over to the mini mario costume set that's awesome oh it's so refreshing to see him looking like this and there's his original losing live costume yes and of course we can just click on the blocks to switch back and forward between mario and super mario how cool is that and so easy to do just by being careful with how we named the costumes do you see how this could be extended to add even more types of mario later on if we wanted yeah i bet you did so tell me since mini mario is so small what happens when we crouch oh no what's this oh the dreaded purple square invasion has begun it's been a long time since we had one of these if you remember this occurs when we try to set mario to a costume that does not exist and in this case it's the mini mario crouch costume yeah mini mario can not in fact crouch and that is why there is no costume for this we need to prevent crouching from mini mario then so find the define handle keys jump crouch script here is where we are handling the key down for crouching add in an and and a mario is not equal mario is not equal to mini if i run the project now i can confirm that i'm smashing the down key and mario is not crouching and yeah there's no more purple square thank goodness for that i didn't like that purple square one bit but talking of crouching let me find those set mario blocks where'd they go uh here they are now clicking back into mario we can test that we are still able to crouch and yep we can still crouch and slide brilliant but that does pose the question [Music] switch back to mini mario and if i try to walk under this block i should be able to fit but ah no we are blocked by an invisible force and of course we are because for all the costume switching we have done we have not addressed the actual height of mario in the game engine where he is treated as full height still so back in the code find with me the define fix collision in direction dxdy script this is where we are looking at six possible collision points on mario notice how when mario crouches we are already excluding the top two points this reduces his height to just one block high well that sounds perfect for mini mario right so add an ore inside this knot and we'll only check these two upper collision points when we are not crouching or when mario equals mini nice let's give that a test shall we i'll try running under the platform yes that's no problem at all so what about the mystery blocks just check i can still trigger them yep that's brilliant and it means we have a mushroom to collect and you all know what that means yes now we need to add the power up feature to make mario transform into super mario for this we need to click into the enemy sprite since this is where the mushroom sprite lives find the defined tick life script this takes care of the mushroom sprite and scrolling down a bit here is where we detect mario picking it up let's broadcast a new message naming it collect one up we can use this to trigger the action on the mario sprite in a moment but first we need some new sounds do you still have the sound sprite in your project if not you'll find it in the asset project still sound number 19 is named power up listen to this and power down okay copy these two sounds into the mario sprite and then click back into the mario sprite confirm they are there and then to the code so this power-up action works very much like the mario lou's life script here in that while the action is taking place the entire game needs to pause this is to stop the enemies walking around and killing you while you upgrade begin by making a new when i receive collect one up block now this doesn't want to do anything if we are already super mario so if not mario equals mini just stop this script otherwise great we start the iconic power up sound and for starters just set mario to mario make sure to use the correct capital letters there for it to work and we can run the project here we go are you ready for this i'm excited [Music] we have upgraded this is so cool okay perhaps i'm overplaying this we still need to pause the game and show the actual transition animation firstly to pause the game loop bring in a stop other scripts in this sprite and do that right after the first if now we won't set mario to super mario right away so move that down here for later okay next up we need to wait for zero seconds now why is that well although we used a stopple script in sprite we have to wait one more game tick to allow all the other queued up event receivers scripts in the other sprites to finish running otherwise things will get out of order and all sorts of badness will creep in try without it if you wish and you'll see what i mean so we switch our costume to the transitional costume mario transform so we want to show this costume for two game frames now while the game is paused we still want the main game tiles to animate so add a repeat to and broadcast position tiles this won't allow any enemies to move but it will keep the tile costumes animating now to switch to the next costume duplicate the blocks above and switch to mario walk one that's the big mario costume i think we'll do this for three frames rather than two though but see what you prefer right before we can test this we need to set mario back to mini that is mini mario click that to set the variables and then click the event to see the animation oh wow that was short we got a little bob out of him but nothing more we need to loop this around a few times repeat three times and pop the two set costume scripts in here then return the whole thing back under the weight zero block set us back to the mini mario and click the event receiver again to test it right so this is just half the animation we currently switch between middle size and super mario we also need to do the same for mini to middle size mario in which case let's make a new custom block naming it loop transformation but make sure not to tick the run without screen refresh why because we want to play an animation in here that lasts more than one game frame put the entire repeat loop in there and as normal we'll then use this block where we took the scripts from then once the first animation is complete we finally set mario to mario that is big mario and use the loop transformation block once more all we need to change is which costume we are switching to of course we can use a join block with the walk one on the right and put the variable mario on the left this should now toggle between mini mario and transforming mario then full size mario and transforming mario let me just set mario back to mini before we can test it and here we go oh yeah i am liking that we have a very pleasant transformation there so what's left to do ah since we stopped the main game loop before playing this animation we need to way to kick it off again broadcast a new message of level continue game loop we can't use any existing receivers as they tend to initiate enemies etcetera and we don't want any of that if we scroll to our main game loop script you can introduce the new when i receive level continue game loop just here just like the other scripts we kick off the game loop custom block now hold on see how we are setting coins to zero when the game loop begins well that's no good anymore as it would happen when we collect a power up so take it out and we'll move it into the level start game loop but not our continue game loop but also there's another one where is it here we are level start game loop respawn this one also needs a set coins to zero before the game loop begins great now just one more change before we test this baby out find the define reset player script and we need to set mario to mini down at the bottom yeah and with that we are ready to test once more here we go now i'm even more excited to see the full classic transformation take place are you [Music] and oh yes now that's what i'm talking about if you got this far then i bet you are celebrating too because this is just too cool well then they say what comes up must come down so look when we now contact an enemy we are still launching into the lose life animation but when in super mario mode this is no longer how things should work by being super mario we should get a second chance that is we should shrink back to mini mario and continue from there now this is a little bit more tricky because it's not always the case for example dropping off the bottom of the screen is fatal no matter how big you are [Music] so we need to differentiate between different ways you can get hurt click into the enemy sprite we need to locate all the places where we broadcast mario lou's life if you have my dev tools extension or scratch add-ons installed then that comes in really useful here i'm looking up the lose life event okay here is one it's in the tick goomba script we're going to change it to a new event naming it mario hurt okay the next one is tick piranha change it to mario hurt tick shell again change it to mario hurt and that looks like it good so back into the mario sprite we go and look for the when i receive mario lou's life script well saying that we aren't actually going to do anything with that but we are going to make a new when i receive mario hurt script to work alongside it firstly if we are hurt and we are mini mario that is mario equals mini then we can simply defer to the lose live script by broadcasting mario lou's life and then stop this script but otherwise we want to play a new power down animation so as before we stop other scripts in this sprite and then wait for zero seconds again for the other broadcast to end loop transformation to play the first half of the animation and then set mario back to mini capital m loop transformation again to play the second half of the animation and broadcast level continue game loop [Music] smash that green flag i think first we should test we can still lose a life as mini mario yes we can no problems there although i still rather like seeing the correct little mario sprite when that happens but now as big mario let's go to our doom yes we shrink but oh no what happened we still died even so but of course since the game starts up again we are still touching the goomba so goomba gets to kill us all over again and that's it for mini mario okay so this is a little bit more complicated than it first looked the secret success here is that when mario gets hurt we should become invulnerable for a short amount of time that is he should flash a lot and not be able to be hurt just for a moment while and after he shrinks down again oh man but before we move away i forgot to play the power down sound just before we wait here start the power down sound right let's make a new variable yay call it invulnerable if you can spell it and make it for this sprite only then just after the wait set it to around 70 frames should do the trick that should end up giving us around a second and a half of time so now when this mario hurt event is triggered we can add in a new if check and say if invulnerable is greater than zero just stop this script you can't be hurt right now notice this doesn't stop us losing a life just not being hurt now if we look in the loop transformation script notice we always broadcast position tiles even if we are transforming this is the only receiver that is always broadcast at all times during the game we can make use of this to make our player flash when i receive position tiles if invulnerable is greater than zero then change invulnerable by minus one so that will count it back down to zero with each tick of the game now we want to flash mario every other frame we'll use a mod two for that so if in vulnerable mod 2 is less than 1 we can set ghost effect to 0. now a ghost effect of 0 means that the sprite is fully visible so when invulnerable is an even number and that includes 0 of course the sprite will be fully visible but when it's an odd number we set ghost effect to 99 that's pretty much invisible coolio let's test this [Music] just powering up and wait for it yes now that was very successful did you notice how we began flashing throughout the shrinking animation too that was exactly as planned and then the flashing stops and we should be here very vulnerable once more superb oh man goomba how dare you and not to worry all good testing right [Music] here i come gumbers actually i've changed my mind we should go all the way across the level and when we get to the yeah so we're gonna try dropping to our death as big mario [Music] okay nice we still come to our demise right away as it should be i wonder if it was supposed to switch to the small mario death sprite there drop me a comment if you know right we should make sure this invulnerable variable gets reset at the start of the game find the reset player script and we'll set invulnerable to zero after setting mario to mini so we are drawing to a close now but before we do let's just address one more thing that mini mario should not be able to jump quite as high as super mario around one block less i believe find the define handle keys jump and crouch script there's all sorts of ways we could fix this but the simplest right off the bat is to locate the start sound jump block here this is where we launch a new jump stick in an if right afterwards checking whether mario equals mini then if it is quickly set jumping to 3. this skips the first frames of the jump limiting the maximum height we can reach when in mini mario mode let's just test this out if i come over here to these mystery blocks and now test how high i can jump okay good so i could headbutt them but i can't jump high enough to get on top but then if i collect the mushroom and then come back to the same point look i can now jump right up above the mystery blocks brilliant and on that bombshell this episode has drawn to an end can i ask how your tile based scrolling games are coming along are you building a mario like me or making it all your own drop me a comment below and let me know what you're up to if you enjoyed this video then smash the like button and don't forget to subscribe to the channel so you get notified of the next video as it comes around if you want to support the channel further then you can become one of my paid members then you not only get those cool custom channel emojis but you also get priority replies and comments early access to videos and even the scratch projects themselves wow thank you so much for watching and until next time scratch on guys [Music] you
Info
Channel: griffpatch
Views: 97,425
Rating: undefined out of 5
Keywords: scratch coding, scratch programming, scratch game, scratch 3, griffpatch, griffpatcho
Id: zAHY5F-hkQI
Channel Id: undefined
Length: 26min 39sec (1599 seconds)
Published: Sun Oct 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.