Coding Fire Mario (part 2) | SMB in Scratch E19.2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello fellow scratchers i'm griff batch and we're back for the second part of episode 19 of the mario tile scrolling series we have made great progress adding fire flowers to this game we've got the power-up collectible via mario costumes we can power up we can fire the projectiles only well they appear more like fireball cannons at present so our next step is clear let's get scratching right so they are supposed to be bouncing right so they need gravity we've certainly covered this enough times before to know what to do first check that the fireballs are not falling at their maximum speed already if speed y is greater than minus 12 then we can apply gravity to them by changing speed y by negative 1.5 feel free to play with these numbers to get a good feel to the bounce of the projectiles then we use our handcrafted move sprite y block to do the job okay wow we've created something special here they certainly like to hug the floor don't they what we need here is some bounce now we could look for speed y being zero like we did with the speed x but we need to watch out for bounces off the ceiling too so instead we'll use an if falling equals zero as this is only set to zero when we are physically on the floor and not a ceiling then to bounce back up we set speed y to 11. where do i get these numbers from they are just trial and error nothing scientific or complex just playing around with them like i encourage you to do too smash the green flag and bask in the wonder of our fantastic bouncing fireballs oh yeah fire mario is turning out great what do you think so far have you noticed anything missing yes a few things perhaps but right off what about mario's throw animation it looks like he's just popping fireballs out of his head take a look in our mario costumes scrolling down into the bottom costumes 29 and 30 are the special throwing costumes i was talking about we can certainly use these come back into the mario code and we'll make a new variable named throw for this sprite only we will use this to keep track of when to play back the throwing animation find the define handle keys fire script now after changing fireballs by one we can also set throw to two this is because we have two costumes to animate over when we throw a fireball next up find the define paint sprite script this is where we do all the costume switching we'll try adding this right near the top as it overrides most of the other actions so if throw is greater than zero then well change throw by negative um i'm gonna say negative 0.25 that would take four frames to move on to the next throwing costume right put a switch costume to block before the change throw block and borrow the same join as we always do here but because we want the costume frame number add another join on the right hand side and write throw with a capital t on the left and on the right we want the number one or two for that we'll use the ceiling of throw the ceiling operator rounds numbers up to the nearest whole number so 1.1 would still round up to 2. nearly forgot pop in a stop this script at the end so we don't continue on and set the costume to something else testing the throwing animation now it works yes and it looks great hoorah right i wonder who of you has spotted one other issue we have been having that the projectiles can actually sometimes double register a hit you can hear it sometimes as the collision sound gets played multiple times this has actually been an issue for some time where a flipped enemy is able to be flipped over and over especially using koopa shells this is such a quick fix why don't we squish that now we just need to prevent already flipping enemies from being flipped again click into the enemy sprite and find the when i receive move player after enemy script this is where we check for collisions that will cause an enemy to be flipped so slip a new if at the top of the script and check if type equals flip this is true when the sprite is already flipping so simply stop this script to prevent us from even checking for a flip again against this sprite i want to try to give that a test the trick is hitting the same enemy twice okay that looked good just a few more tests i'm not sure i hit on that time yeah that was a direct hit and it looked good bug squashed so next bug and that's if enemies drop off the bottom of the level they don't despawn this is not the end of the world but it does now cause a problem if one of our fireballs falls off the bottom can you guess why yes because our fireballs count we'll never go back down we need to despawn these fireballs in the enemy sprite find the define move enemy script then after the initial check for a type of flip we'll add in a new if checking if y is less than negative 32 that should be just enough off the bottom of the screen for most situations and we use our new delete clone custom block that ensures it counts down the fireballs do you know while we are here let's replace these other two usages of delete this sprite with our new delete clone custom block phew good catch there and lastly since we are talking about sprites going out of range let's find the define tick fireball script our fireballs should not keep on flying across the level once they move off the left or right side of the screen either after moving in the x direction down here let's check if the abs the absolute value of x subtract camera x is greater than 240 that means it's gone off the left or right side of the screen then also delete clone using the new custom block that's easy to test we just need to fire rapidly off the edge of the screen like so and if we can keep firing then yay it has worked [Music] splendid are you feeling as good about this as me well then is now a good time for me to share with you a potential spanner in the works perhaps you've also been noticing one other flaw in our fireball implementation and that is that a single fireball can kill a whole screen of enemies if you fire it off in just the right place a cool perk perhaps but not how mario's fireballs are supposed to work these ones are supposed to destroy one enemy but also be destroyed themselves in the impact so how do we pull that one off well i tried a number of different ways of doing this before i settled on my favorite solution it was especially difficult to get the projectiles to detect they had collided with an enemy but not trigger when two projectiles hit each other wiping each other out but this is a similar issue to our deadly enemy problem from the cooper shell episode and so you may not be surprised that i have a similar solution if you can't remember how we did that i advise you to go re-watch that episode here are the position tiles and move player after enemy event receivers that we set up to hide the non-deadly enemies while keeping the deadly koopa shells visible all time to explain my thinking let's click into the mario sprite and find the highest the define game loop script at present all sprites are visible after the move player event has run but then in the move enemy event all non-deadly enemy sprites are hidden next up the move player after enemy event runs and this is also used in the enemy's sprite to detect when a deadly enemy touches a non-deadly one killing the enemy this is now including fireballs hitting enemies and lastly in the position tile script all the sprites are made fully visible again end of game tick and good job but we now want to detect when an enemy fireball collides with a non-deadly enemy for that we need to hide all the fireballs but show all the other enemy sprites we'll broadcast a new event for this naming it hide fireballs then we'll broadcast another new event naming it check fireballs in which we can check for collisions so drop both of these before the broadcast position tiles excellent now we just need to make this work click back into the enemy sprite we start with the when i receive hide fireballs if type equals fireball then we hide it of course then stop this script because there's a little more to do if this is any other visible enemy then we actually want to show it just borrow that script from the position tiles event receiver it should say if visible is greater than zero then show this sets us up to detect collisions between the fireballs and any other enemy if you need a refresher as to why then do re-watch the previous episode want to give that a quick test just to ensure things are working as before great but to delete the fireballs correctly on impact we need to code the when i receive check viable script again if type equals fireball and now we can borrow the scripts from the move player after enemy event show the single fireball check if it touches any other visible enemy do something and then hide it again ready for the next fireball to be checked this showing and re-hiding is what stops the two fireballs from destroying each other as you will never have more than one visible at a time but we don't want to cause a fireball enemy to flip so remove that instead we want to use our delete clone custom block right that felt both simple and complex at the same time i guess it's not much coding but you have to get things set up just right in order for it to work let's give it a test are you ready for this one fireball one enemy test coming up boom that is what i'm talking about so let's test a bit more [Music] this sure is fun but it's hard to test whether two fireballs can collide with each other so let's temporarily up the maximum number of fireballs that's in the mario sprite under handle keys fire i'll just up the fireballs to 20 and look at this this is crazy satisfying why doesn't mario have a 20 fireball limit anyway certainly overlapping fireballs is not a problem here yeah well that brings a whole new dimension to the game doesn't it now although that was far too much fun i'm going to pop the maximum fireballs back down to 2. so there's not a lot left to do here the final remaining tweak is to simply fix what happens when mario gets hurt as fire mario at present we shrink back to classic mario size but in reality at least in smb3 we should only downgrade as far as the main super mario player state we have an event receiver for this in the main mario sprite find that when i receive mario hurt script the top script is handling invulnerability and losing a life if you are mini mario so scroll down and here we set invulnerability to 70. we now check for which mario we currently are using if else and check for mario equals fire so the existing loop transformations can go in the else but pop the broadcast to continue the game loop to after the if as we'll want this in both cases right to downgrade from fire mario to super mario we set the mario variable to mario with the capital m and then force them to update their costume using a paint sprite now i want to pause the game and flash the player to indicate the change of state that's easy we use repeat 30 and keep the broadcast position tiles the flashing is already accounted for by the invulnerability available that we set and here we go so as fire mario we just need to touch oh hey come back oh man never trust a gumba to do what you want fine let's face off with a piranha plant brilliant that was just what i was hoping it would look like just what i needed [Music] ah another bug oh the purple square when we downgrade while still throwing a fireball no quickly back to the mario hurt receiver we can prevent this easily by adding a set throw to zero after setting the invulnerability to zero but before the animation plays phew [Music] and that is such good news because my fellow scratchers this is most definitely the end of today's episode i feel like we've had to do such a lot of scripting and i hope i didn't lose you the end result though is so satisfying and i think we are ever closer to having covered almost everything that you will need to make the most incredible games of your own be it mario or any other tile-based platformer if you have enjoyed this episode then please do smash click and wiggle that like button and don't forget to subscribe to the channel to catch all the latest episodes the moment they come out do let me know how your projects are coming along in the comments below the video or just say hi and tell me what your favorite video has been so far thank you though so much for watching and have a great week ahead and scratch on guys
Info
Channel: griffpatch
Views: 28,827
Rating: undefined out of 5
Keywords: scratch coding, scratch programming, scratch game, scratch 3, griffpatch, griffpatcho, super mario maker 2, super mario maker, mario, mario scratch, scratch coding games, coding for kids, scratch
Id: uHyGfBBf4Oo
Channel Id: undefined
Length: 16min 22sec (982 seconds)
Published: Wed Nov 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.