Code a Fun Space Shooter Game ๐Ÿš€ | 1. Move & Shoot | Scratch Tutorial

griffpatch ยท Beginner ยท๐Ÿง’ Coding for Kids ยท5y ago

Key Takeaways

Creates a simple space shooter game with player movement and shooting mechanics using Scratch

Full Transcript

[Music] hello fellow lemons welcome to another mix it up Monday tutorial I'm Griff patch and today we are going to start a little project based Loosely around the classic game asteroids but well far more over the top as you can see lemons have achieved Interstellar capability and are attempting to take over the universe to tackle such a scenario we obviously need to fight back with rapid fire lemon bursting lasers so what's the coolest thing we're going to learn while making this game that would be how to handle loads of rapidly moving projectile clones and enemies and how to robustly handle the collisions between them as a bonus we'll also tack on some cool special effects including damage and explosion flashes and the much sought after camera Shake today we're going to cover the basic player design movement and shooting of laser projectiles towards the mouse I'm also so interested to know how many times I can say the word lemon in one episode lemon lemon lemon were you counting okay let's get scratching we'll begin with the player spaceship Sprite I'll politely discard My Pal scratch cat and create a new Sprite in its place we'll need to draw a ship that faces to the right that's the direction we almost always need to make our sprite's face I often forget and end up drawing it facing up so we can use a rectangle holding the shift as we draw it to perfectly keep it as a square then switching to the shape tool select one corner node and click delete to make a perfect triangle Now using the selection tool again I can rotate the triangle but again holding the shift key while dragging it so as to rotate by exactly 45ยฐ okay next trick grab the top resize node and hold down the alt as you drag down this resize of the object around the middle very useful next I drag the triangle until it snaps to the center of the canvas it's important to do this so that the ship will rotate beautifully around its middle point but then once centered I then drag it to the right a little bit again while holding the shift key this lets it move without it allowing to go up and down so it stays snapped to the middle in the vertical okay and there's more tricks yet hold down the alt ke key again and then left click and drag the triangle to create a perfect duplicate ah but while still dragging hold down the shift key and power the shape is snapping to stay lined up with the previous shape I'll color it lemon yellow this ship is already looking cool I think I'll drop the Border thickness down a touch right I didn't name the Sprite so let's name it now player next we can make the background nice and dark by switching to the stage I'll convert it to a bit map and fill the entire screen with a color that's almost but not quite black okay back to the player Sprite and let's fill in some code it's going to be a basic game Loop this time we'll set it up with a when green flag clicked bring the player to the front of all the other Sprites and go to the center of the screen we'll want our ship to have smooth movement so we'll keep track of its momentum that is its speed make two new variables named speed X for this Sprite only and speed y also for this Sprite only and we'll be very good and set them both to zero before the game gets going always good to reset your variables like this at the start of the game now for the game Loop bring in a forever Loop so what shall we do first how about left and right movement we can do this in so many ways but the pattern is always very similar I'm going to make a new custom block naming it move X and adding in a numeric input of joystick X now people ask why do I use so many of these custom blocks the truth is we don't always need to but one huge Advantage is that they break up your code into nice chunks and they give each chunk a rather nice name that can be a lifesaver when you come back to a project later and want to find something it's just so much more readable we'll use the move X block right away and I'm going to use the same key press trick we did in some other tutorials of putting the key press blocks inside a subtract operator like this either we can have right arrow press subtract left Arrow pressed or as I'm going to do now key D pressed subtract key a pressed that's the was keys this beautiful little trick gives us a minus one for left a zero for no movement and a one for right that's really useful okay so the joystick X input here will now as we just said B minus one for left or one for right let's use this to change the player's speed X variable specifically by 0.9 multiplied by joystick X now the 0.9 here is the player's acceleration feel free to create a variable to hold the value if you prefer but I'm just being quick today next up we set speed X yeah not change this time set set speed X to 0.9 multiplied by speed X this is not the same 0.9 as the one above this one is for air resistance to slow the player back down with a speed variable now updated we can change X by the speed X to get the player moving on the stage let's give it a quick test run the project and press the left and right Keys whichever you assigned there that's a nice feel cool we can do the same now for up and down make a new custom block move y with an input of joystick y this code will be just the same as for the left and right change speed y by 0.9 multipli by joystick Y and set speed y to 0.9 times by speed y and finally change y by speed y we can pop the new move Y block into the forever Loop and pass in a key W or up subtract key s or down let's test that again to check we have full movement now yeah beautiful all all we need now is to rotate to point towards the mouse cursor this is going to be quite a fast-paced game so I'm not going to limit the speed of turning so it's really easy just drop in a point towards Mouse pointer and we're done yeah I like that a lot now we are facing the right direction we need to be able to fire those lemon bursting lasers make make a new Sprite naming it laser we can start by zooming in and drawing a long rectangle remembering to snap it to the center of the canvas again I think a fill color of white but with a lemon yellow outline looks neat next I'll round the ends of the laser beam with a shape tool just click to create new nodes on the top bottom and midr edges like this now we can click on the corner nodes and press the delete key to remove them leaving a not half bad rounded end do the same for the Left End to finish it off I'm making the Border a bit thicker size two and now to ensure the laser is correctly drawn I'm going to draw a completely transparent rectangle around the entire shape this is not crucial but it helps to ensure the Laser's edges are nice and crisp and don't get cut off weirdly I'm sure the scratch bug will get fixed one day okay let's put some scripts together beginning with the initializing scripts when green flag clicked hide the laser only wants to be visible when cloned the original Sprite should be hidden and in fact will never be used as a laser Sprite at all this is common practice in scratch in fact if you do try to use the main Sprite you can get into trouble because unlike all the Clone Sprites the delete clone will not work on the main Sprite that can lead to bugs where one bullet suddenly appears on the screen and won't disappear like the others so yeah hide the main laser Sprite we're going to hang all our game Loops off of when I start as clone hat block this is very convenient for Less complex games like this one as soon as the laser is cloned position it at the player's Sprite location we are going to want to send it flying out in the direction the player is facing to match the player's direction we use a point in Direction block yeah don't use the point towards player that won't work we could have used the point towards mouse that would surely work as we are at present always facing towards the mouse but that may not be the case in the future so point in Direction and then find the of block in the sensing category and switch the Sprite name to be player now you can select the direction of player neat okay we need to show the cloned laser Sprite and then we'll begin a repeat until Loop repeating until the laser is touching the edge of the stage within the repeat drop in a move block and I'll change it to be 11 steps the bigger the number the faster the laser will travel so have a play with that this Loop will fit finish when we hit the edge of the stage so then delete this clone to remove it from the game that all sounds good we just need a way to trigger the laser to fire now we may be tempted to use a when space key pressed h block then we simply can create a clone of self now which of you knows why this is not such a great idea let's give it a test I can press space and a single laser fires out on first inspection this is working very nicely so the cloning and Laser movement scripts are great but because I have scratch add-ons installed I can see how many clones are being used as I launch each laser and look at that how is it possible that I'm using all three hundred clones at once with so few lasers showing up on screen any ideas okay let me explain this is a super common bug for scratchers who are new to using Clones look back at where we added the create clone block here it is whenever the space key is pressed we create a clone of ourselves seems harmless until you consider that this is being triggered on the laser Sprite now tell me how many laser Sprites are there at once well there's one Sprite to begin with but as soon as I press the space we clone the Sprite and then there are two laser Sprites so when I then press the space again to fire the next bullet not just one laser Sprite will trigger a space press script but two and both Sprites the original and the Clone will both create new bullet clones of their own of course because the Clone creating script places the new bullets at the player all these new bullets appear on top of each other so we only see one even though there are two so that makes four bullet Sprites even though we've only pressed space twice so now can you guess what happens if I press space a third time you guessed it four bullets becomes eight bullets and then 16 32 64 128 256 and pow we've exceeded the 300 clone limit it doesn't take long before all the Clones are used up disaster because we'll need to keep all these clones available for all those lemons so the mistake we made was to have a key pressed on a Sprite that is being cloned always remember if a Sprite is cloned that all the Clones will be receiving the key press event okay much easier to trigger the Clone event from the player Sprite instead make sure to delete this when space key pressed hat block click into the player Sprite we'll make a new custom block named shoot and we'll use it right after pointing towards the mouse pointer down here now I don't want to trigger off the when key pressed because I don't fancy the player having to mash the space key that much instead I want a steady stream of lasers to five out as soon as the key is held down so add in an if space key pressed or Mouse down we might as well allow the mouse to fire too and then we'll use the crate clone of and switch it to clone the laser Sprite great should we give that another test mash the green flag oh man yes look at that that's insane Firepower lemons don't stand a chance against that yeah so I think we need to re that back in a touch limit the rate of fire make a new variable to keep track of this naming it fire rate for this Sprite only we need an if else block and check if the fire rate variable is larger than zero oh move the key press check into the lside we only want to allow firing of the laser when fire rate has decreased to zero so yeah if the fire rate is greater than zero then change the fire rate by NE 1 then after creating a new laser set fire rate to um 10 this will now not allow the laser to fire again until it has decreased back down to zero let's give that a test oh gosh that feels slow now a regular pulse of just three laser blasts per second that could work for early levels perhaps but it's not going to be a match for the number of lemons I have in mind no I'm counting on there being quite a lot of lemons indeed so perhaps let's try a setting 58 to one okay that's nice it's perhaps a little quick but I kind of like it it's a nice compromise and I'm feeling it will give us perhaps some chance of warding off even a somewhat excitable lemon Invasion right guys this is the end of part one of this tutorial if you want any game assets then I've included a link to a scratch project in the info under this video I think you should take the time though to have fun and make the spaceship costumes yourself but there's also some cool sound effects in there for you to grab so have fun the next episode we'll build on this tutorial and we'll finally get those lemons into the game lots and lots of lemons yeah and that is where the fun really will begin but I hope you've enjoyed this video thus far please do smash the like button and don't forget to subscribe to the channel to avoid missing my next exciting video thank you so much to my new channel members joining the membership is a huge deal because simply put more supporters translate to me being able to make more videos it's that simple that's right you can help make this channel awesome oh and there are some fantastic perks up for grabs too so check that out and that's it thanks for watching and scratch on guys [Music]

Original Description

How to build a simple, fast paced space shooter in Scratch based on the classic arcade game Asteroids, but with Lemons! In the first of this three part Scratch coding tutorial we cover player movement and the firing of lasers. This will then set us up for the really exciting part two where we can look at enemy Lemons, collisions, and splitting of the lemons. Part 3 will venture into the awesome explosion flashes, screen shake and more! Wondering why Lemons? Well, Lemons were the first fruit to have achieved interstellar capability and are thus attempting to take over the universe. To tackle such a scenario we obviously need to fight back with rapid fire lemon busting lasers! ๐Ÿš€ *Boost Your Creativity with Griffpatch* The Griffpatch Academy will take you from "Gamer to Game Creator" Learn more at ๐Ÿ‘‰ https://griffpatch.academy ๐Ÿ‘ˆ ๐Ÿ˜บ Scratch was developed by the Lifelong Kindergarten Group at the MIT Media Lab. See http://scratch.mit.edu ๐Ÿฑ Scratch Starter Project Game Assets https://scratch.mit.edu/projects/548866331/ ๐Ÿ‘€ Simple Space Shooter Part 1 - https://youtu.be/sqsNb0s7Oq4 Part 2 - https://youtu.be/okhIwJUOalM Part 3 - https://youtu.be/RKdXM3x-jEo Bonus - Scores - https://youtu.be/atMwy3UKc14 Bonus - Health Bars - https://youtu.be/rTKDzz_d6X4 Part 4 - https://youtu.be/eJf42cpqY-w โค๏ธ Enhanced Scratch Developer Tools https://scratchaddons.com/ --------------Video Chapters-------------- 0:00 Intro 01:06 The Player Sprite 03:04 Player Movement 07:17 The Laser Sprite 08:35 Laser Code 10:34 Firing the laser 13:09 Triggering lasers the right way 15:25 Outro scratch coding, scratch programming, scratch game, scratch 3
Watch on YouTube โ†— (saves to browser)
Sign in to unlock AI tutor explanation ยท โšก30

Playlist

Uploads from griffpatch ยท griffpatch ยท 54 of 60

1 Burrow Blitz - A game by Griffpatch
Burrow Blitz - A game by Griffpatch
griffpatch
2 Burrow Blitz Level 1 Speed Run!
Burrow Blitz Level 1 Speed Run!
griffpatch
3 Scratch Messaging Extension (for chrome & firefox)
Scratch Messaging Extension (for chrome & firefox)
griffpatch
4 Scrolling Platformer Tutorial | Part 1 | Get Scrolling
Scrolling Platformer Tutorial | Part 1 | Get Scrolling
griffpatch
5 Scrolling Platformer Tutorial | Part 2 | Gravity
Scrolling Platformer Tutorial | Part 2 | Gravity
griffpatch
6 Scrolling Platformer Tutorial | Part 3 | Platform Detection
Scrolling Platformer Tutorial | Part 3 | Platform Detection
griffpatch
7 Scrolling Platformer Tutorial | Part 4 | Off Screen Sprites and Player Death
Scrolling Platformer Tutorial | Part 4 | Off Screen Sprites and Player Death
griffpatch
8 Scrolling Platformer Tutorial | Part 5 | Collectables
Scrolling Platformer Tutorial | Part 5 | Collectables
griffpatch
9 Scrolling Platformer Tutorial | Part 6 | Danger Sprites (Bug fix)
Scrolling Platformer Tutorial | Part 6 | Danger Sprites (Bug fix)
griffpatch
10 Scrolling Platformer Tutorial | Part 7 | Exit Portal
Scrolling Platformer Tutorial | Part 7 | Exit Portal
griffpatch
11 Scratch 3 | Box2d |  Physics Extension
Scratch 3 | Box2d | Physics Extension
griffpatch
12 Scrolling Platformer Tutorial | Part 8 | Vertical Scrolling
Scrolling Platformer Tutorial | Part 8 | Vertical Scrolling
griffpatch
13 Zombie Cube | Speedrun challenge
Zombie Cube | Speedrun challenge
griffpatch
14 Scratch 3 | Physics Extension | Version 2
Scratch 3 | Physics Extension | Version 2
griffpatch
15 Top Down Scroller | E1 - Scrolling | Scratch Tutorial
Top Down Scroller | E1 - Scrolling | Scratch Tutorial
griffpatch
16 Top Down Scroller | Part 2 | Enemy AI
Top Down Scroller | Part 2 | Enemy AI
griffpatch
17 Top Down Scroller | Part 3 | Enemy Clones & List
Top Down Scroller | Part 3 | Enemy Clones & List
griffpatch
18 Top Down Scroller | Part 4 | Live Die Repeat (Game Over)
Top Down Scroller | Part 4 | Live Die Repeat (Game Over)
griffpatch
19 Top Down Scroller | Part 5 | You've Won!
Top Down Scroller | Part 5 | You've Won!
griffpatch
20 Cloud Game Tutorial | Part 1 | The Basics
Cloud Game Tutorial | Part 1 | The Basics
griffpatch
21 Cloud Game Tutorial | Part 2 | Encoding and Decoding
Cloud Game Tutorial | Part 2 | Encoding and Decoding
griffpatch
22 Scratch 3 Dev Tools Browser Extension by griffpatch
Scratch 3 Dev Tools Browser Extension by griffpatch
griffpatch
23 Cloud Game Tutorial | Part 3 | Multiplayer
Cloud Game Tutorial | Part 3 | Multiplayer
griffpatch
24 Scrolling Platformer Tutorial | Part 9 | Momentum
Scrolling Platformer Tutorial | Part 9 | Momentum
griffpatch
25 Scrolling Platformer Tutorial | Part 10 | Wall Jumping
Scrolling Platformer Tutorial | Part 10 | Wall Jumping
griffpatch
26 Cloud Game Tutorial | Part 4 | Auto Game Joining
Cloud Game Tutorial | Part 4 | Auto Game Joining
griffpatch
27 Game Preview - "Getting Over It" with Griffpatch - A fan recreation in Scratch
Game Preview - "Getting Over It" with Griffpatch - A fan recreation in Scratch
griffpatch
28 Speed Run with Outtakes | Getting Over It | 4 minutes 30 seconds
Speed Run with Outtakes | Getting Over It | 4 minutes 30 seconds
griffpatch
29 Griffpatch's Live Stream
Griffpatch's Live Stream
griffpatch
30 MMO Platformer Speedrun Challenge
MMO Platformer Speedrun Challenge
griffpatch
31 Appel Platformer | Scratch Game Blog
Appel Platformer | Scratch Game Blog
griffpatch
32 Cloud Game Tutorial | Part 5 | Smooth Movement
Cloud Game Tutorial | Part 5 | Smooth Movement
griffpatch
33 How to Design a Level for Appel
How to Design a Level for Appel
griffpatch
34 Fastest Appel Speedruns | Jan 2021
Fastest Appel Speedruns | Jan 2021
griffpatch
35 Tile Scrolling Platformer (Mario) | 1. Setup
Tile Scrolling Platformer (Mario) | 1. Setup
griffpatch
36 Tile Scrolling Platformer | 2. Grid List
Tile Scrolling Platformer | 2. Grid List
griffpatch
37 Tile Scrolling Platformer | 3. Tile Collisions
Tile Scrolling Platformer | 3. Tile Collisions
griffpatch
38 Tile Scrolling Platformer | 4. Platforming Scripts
Tile Scrolling Platformer | 4. Platforming Scripts
griffpatch
39 Tile Scrolling Platformer | 5. The Level Editor
Tile Scrolling Platformer | 5. The Level Editor
griffpatch
40 Tile Scrolling Platformer | 6. Level Codes
Tile Scrolling Platformer | 6. Level Codes
griffpatch
41 Tile Scrolling Platformer | 7. Drop Through Platforms
Tile Scrolling Platformer | 7. Drop Through Platforms
griffpatch
42 How to make Physics in Scratch | Full Tutorial
How to make Physics in Scratch | Full Tutorial
griffpatch
43 Tile Scrolling Platformer | 8. Enemy Clones
Tile Scrolling Platformer | 8. Enemy Clones
griffpatch
44 Simple Pathfinding Tutorial
Simple Pathfinding Tutorial
griffpatch
45 Tile Scrolling Platformer | 9. Enemies in Level Editor
Tile Scrolling Platformer | 9. Enemies in Level Editor
griffpatch
46 Simple Maze Generation | Scratch Tutorial
Simple Maze Generation | Scratch Tutorial
griffpatch
47 Tile Scrolling Platformer | 10. Mystery Blocks
Tile Scrolling Platformer | 10. Mystery Blocks
griffpatch
48 Simple Car Steering Simulation | Scratch Tutorial
Simple Car Steering Simulation | Scratch Tutorial
griffpatch
49 Simple Background Scrolling Tutorial
Simple Background Scrolling Tutorial
griffpatch
50 Tile Scrolling Platformer | 11. Death, Background & Sound
Tile Scrolling Platformer | 11. Death, Background & Sound
griffpatch
51 Mid Week Update & Channel Membership
Mid Week Update & Channel Membership
griffpatch
52 Simple Grid List Tutorial with Image Scanning
Simple Grid List Tutorial with Image Scanning
griffpatch
53 Tile Scrolling Platformer | 12. Auto Arranging Tiles
Tile Scrolling Platformer | 12. Auto Arranging Tiles
griffpatch
โ–ถ Code a Fun Space Shooter Game ๐Ÿš€ | 1. Move & Shoot | Scratch Tutorial
Code a Fun Space Shooter Game ๐Ÿš€ | 1. Move & Shoot | Scratch Tutorial
griffpatch
55 Space Shooter 2 - Enemy Collisions
Space Shooter 2 - Enemy Collisions
griffpatch
56 Tile Scrolling Platformer | 13. Level Progression & Editor Improvements
Tile Scrolling Platformer | 13. Level Progression & Editor Improvements
griffpatch
57 Space Shooter 3 - Camera Shake & FX
Space Shooter 3 - Camera Shake & FX
griffpatch
58 Tile Scrolling Platformer | 14. Sloping Tiles
Tile Scrolling Platformer | 14. Sloping Tiles
griffpatch
59 Pathfinding a Maze using Lists
Pathfinding a Maze using Lists
griffpatch
60 Tile Scrolling Platformer | 15. Crouch & Slide
Tile Scrolling Platformer | 15. Crouch & Slide
griffpatch

Related Reads

Chapters (8)

Intro
1:06 The Player Sprite
3:04 Player Movement
7:17 The Laser Sprite
8:35 Laser Code
10:34 Firing the laser
13:09 Triggering lasers the right way
15:25 Outro
Up next
Man Builds a Backyard Tiny House and Turns It into a Home Office | Start to Finish by @Elseweyr
AKLA GELEN
Watch โ†’