Cloud Game Tutorial | Part 4 | Auto Game Joining
Skills:
AI Productivity Tools80%
Key Takeaways
The video demonstrates how to create a multiplayer cloud game in Scratch 3, focusing on auto game joining scripts and reworking the cloud project to separate player and opponent scripts.
Full Transcript
hello fellow scratches I'm Griff patch and welcome to episode 4 of my series on creating multiplayer cloud games in scratch today's episode is entitled automatic game joining and to achieve this we will split the job into four parts but don't worry all four covered in this single episode but just make sure you keep with me until the end where we should achieve something very satisfying indeed if you missed parts one two three then I advise you go back and complete these first as we're going to continue from where we left off so stage one requires us to do some rather drastic script reshuffling so try to follow carefully rather than staying with a single sprite approach we are going to now draw a distinction between your player sprite and your opponent sprites the benefit of this is that the main player requires all the scripts for creating your game whereas the opponent's most likely only need to move around and change their costumes also there are there no clones used in the player sprite as there's just one for you so coding the main player becomes easier to handle let's start by duplicating the player sprite and we'll name it opponents click back to the first sprite and ensure it's named player we now want to remove anything that isn't to do with the main player scripts form this sprite where we used to have the setup players custom block bring in a board cast and wait for the message set up opponents will move up the broadcast begin and delete the setup players custom block altogether from this sprite under the begin receiver block stack completely remove everything below the first if statement this player sprite does not need to get its position from the cloud any longer let's change the if condition to be my player is greater than 0 this will allow our player sprite to send cloud data as whichever player number we get allocated we wrap up the cloud writing scripts by creating a new custom block send cloud data run without screen refresh and we'll move the setting coded block stack in there this makes things tidier now drag the new custom block out and place it back inside the if statement now because this player sprite is only bothered with positioning our main player we can simplify the positioning scripts to just use a go-to mouse pointer block as the first block in our forever loop from now on we will be adding any player positioning code in there this change also requires us to modify our send Cloud Data custom block to use expedition and y position in place of their mouse X and Mouse Y blocks we also need to switch to play a hash variable here with my player hash now let's switch over to the opponent sprite we don't want to be triggering on the green flag any longer but instead we will use the new when I receive set up opponents event in fact all we need in here is the setup players custom block so remove the rest let's drag in a set color effect 90 so we can distinguish between the player sprite and all the opponent clone sprites we could alternatively change the costumes themselves in the costume editor now that we have a player sprite as well as the four opponent sprite clones we will need to ensure we hide any opponent that is set to use the player ID that the player sprite is using within the begin receiver replace the if with an if/else block when this opponent player has the same player ID as my player ID set ghost to 100 to hide it otherwise we do the decoding and positioning as before note that we can delete the encoding scripts from this opponent sprite now let's just tidy this up a little bit more by adding a new custom block called tick and move the decoding and positioning scripts in there as always then move the tick custom block to where the scripts were taken from and now let's test I'll open up two windows side by side and in the left window I press the 1 key now see how you can tell which player is me by the color at this point did you notice that my player one sprite has been fading out while I am not moving the mouse remember this because we will come back to it shortly but before we look into that let's just tidy away some our new scripts the playa sprite no longer needs to be able to read or decode cloud data so we can delete the following custom blocks value equals cloud hash player and the begin decode of and finally the value equals read from encoded blocks and now let's move to the opponent sprite we can remove anything to do with setting cloud variables so delete the set cloud hash to value custom block the right value to encoded and while we're at it all the when key pressed hat blocks to join the game as these are also in the player sprite okay we've made it state two of this video where we're gonna fix the fading out of non moving players to visualize what is happening here let me make all the cloud variables visible now when a player does not move their mouse deposition doesn't change and therefore their cloud variable does not change either this is leading to the player fading away on other player screens as if we were no longer playing to fix this we need to ensure that we are always changing are encoded cloud variable even when we are not moving well something that it's always changing is the time so how about we encode this to send along with our data within the player sprite in the send cloud data custom block we'll arrange it to first write the user name and then we'll write the round of time at times ten timer is in seconds and cloud variables can only update ten times a second so if we multiply by ten and then round it then this number should increase by one every time the cloud variable is transmitted lastly we write the x and y position as before we're in a mirror these changes in the opponent sprite within the tick custom block after the begin decode we first read from encoded the value of the player name we therefore move the say block up here then read in the time value we don't do anything with this yet so decode the next value which is the x position and then finally the y position and now let's test again now when I join the game with the one key and still you will see that my players clown variable is constantly changing and the player no longer fades away great let's move on so we have this fading out effect but the names of the offline players are still visible which brings us to stage three of this tutorial we're gonna fix that and we're gonna completely hide the player names too in the opponent sprite add a new variable named offline and make it for this sprite only under the setup players receiver set offline to 100 this will signify the player is offline and hide the sprite in the beginning receiver when my player equals player hash set offline to 100 and hide now let's make a few changes to the tick custom block as follows when the cloud variable has not changed rather than fading out we now change the offline veil ball by one if the offline veil reaches a hundred then we hide the entire sprite this will also hide the name of the sprite in the speech bubble else if the cloud verbal has changed then rather than removing the ghost effect we now check whether offline is greater than 99 and if it was then the sprite must have been hidden and we show it again then after the if still within the else block we set offline back to zero to say that we are not offline ok let's give this a quick test notice as the project starts up the offline players no longer fade out but once they disappear so do their usernames great that's what we wanted to achieve and now hold on to your scratch blocks because this is stage 4 and we are going to script the auto game join in code itself the aim is to choose which player number we can be and therefore which cloud variable we will use how we are going to do this is when the project starts we take a look at all the cloud variables wait for a few seconds and then we take another look if a cloud variable has changed in that time then someone is already playing using that variable but if one of them is the same after that 3 seconds well then the game slot is my lightly free to use and we should claim it let's start by clicking into the stage backdrop to create some feedback messages for the user joining our game first rename the costume as blank now add a new backdrop named joining add a text message letting the player know we are trying to find them a place in the game next add a costume named full and this is to let them know that sadly the game is full and finally one more costume named joined this is to say that we have successfully joined the game right back to the player sprite now please under the setup opponents broadcast add a switch backdrop to joining immediately after this we will broadcast and wait a new message called join game next added an if/else block and check for my player is greater than zero this will be true if we have successfully joined the game so set backdrop to joined otherwise change the backdrop to full while we're in the player sprite we can remove all these when key pressed stacks as I'm happy to say that we're not gonna need them any longer and let's also delete the unrequired player hash variable and last value variable too as they are only used in the opponent sprite now lastly click into the opponent's sprite let's create that new receiver for join game this will trigger on all the opponent clones when the game is starting drag in our custom block value equals cloud hash with an input of player hash this gives us the current cloud variable for this opponent now to keep a record of the value of this cloud variable we set last value to the join of a and the variable value we wait three seconds before then getting the cloud variables value again using the same custom block finally compare the last value with the current value if they are the same then we can hope that this cloud veil ball is not in use by anyone else and we set our my player hash to the player number of this opponent clone as I said previously this script is run for all the opponent clones as they all will share the join game script therefore if any of them are not in use then one of those will succeed in setting the my player however if we go back and look at the player sprite you can see that if there were no free slots then my player would have remained as zero and we will get the message that the game is full right time to test is out first off fire up the project in my to scratch accounts the one on the right is my main grief match one on the left is my grief match shooter and you can see here that my grief patch account got in there with player 1 and with patch shooter has been assigned player 2 this is excellent so how about a more thorough test I'm going to ask some of my scratcher friends to join who will join me first then ah Thank You Lou ends p22 great to have you on this player - oh yes here is player three like a bow a nine this part is really getting going and Wow cool who is that Luke mania Studios grabbing the player for slot we have success we've maxed out all four player slots if we wait around now let's watch people leave now waiting for other players to join hello sir give 4 1 2 I know nice to see you again crystal keeper 7 and finally Ren's - brilliant I think this has been a great success so that's where we will leave this episode we've made a lot of changes today and I hope that you've been able to follow along I can't wait to hear from you how are you doing if you enjoyed this tutorial so far then please like this video subscribe to my channel and I'll be back soon with another episode thank you for watching bye guys
Original Description
This is part 4 of how to create a multiplayer cloud game in Scratch 3. In this episode we add auto game joining scripts, but before that we also rework the cloud project to split the player and opponent scripts apart. This will make coding games upon this base project far easier going forward!
Part 1 - The Basics - https://www.youtube.com/watch?v=-KoHaz7ZPvo
Part 2 - Encoding and Decoding - https://www.youtube.com/watch?v=nNv9iehpGRQ
Part 3 - Multiplayer - https://youtu.be/4acaa5y_jSU
Part 4 - Auto Game Joining - https://youtu.be/kzp-xr2f3Kw
Part 5 - Smooth Movement - https://youtu.be/2oNTn9ijWIw
In further videos we will look at many other ideas including how to smooth player movement out!
Some multiplayer cloud games I have recreated in scratch are slither.io, agar.io, diep.io, Terraria, bomberman, and a few off my own including multiplayer platformer fun, and fireflies, and tanks.
🚀 *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
Hi, I'm griffpatch from #Scratch (https://scratch.mit.edu/users/griffpatch/). I create and program games in the online Scratch coding website / language often used in schools to teach the basics of learning to code. In this #tutorial series I will be teaching the basics of how to create #multiplayer #games in Scratch using #cloud variables. In this episode we will create a small project that communicates the mouse position from one web browser to another. We also see the immediate limitations of how cloud variables which we will then learn how to overcome in subsequent videos.
Playlist
Uploads from griffpatch · griffpatch · 26 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
▶
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Burrow Blitz - A game by Griffpatch
griffpatch
Burrow Blitz Level 1 Speed Run!
griffpatch
Scratch Messaging Extension (for chrome & firefox)
griffpatch
Scrolling Platformer Tutorial | Part 1 | Get Scrolling
griffpatch
Scrolling Platformer Tutorial | Part 2 | Gravity
griffpatch
Scrolling Platformer Tutorial | Part 3 | Platform Detection
griffpatch
Scrolling Platformer Tutorial | Part 4 | Off Screen Sprites and Player Death
griffpatch
Scrolling Platformer Tutorial | Part 5 | Collectables
griffpatch
Scrolling Platformer Tutorial | Part 6 | Danger Sprites (Bug fix)
griffpatch
Scrolling Platformer Tutorial | Part 7 | Exit Portal
griffpatch
Scratch 3 | Box2d | Physics Extension
griffpatch
Scrolling Platformer Tutorial | Part 8 | Vertical Scrolling
griffpatch
Zombie Cube | Speedrun challenge
griffpatch
Scratch 3 | Physics Extension | Version 2
griffpatch
Top Down Scroller | E1 - Scrolling | Scratch Tutorial
griffpatch
Top Down Scroller | Part 2 | Enemy AI
griffpatch
Top Down Scroller | Part 3 | Enemy Clones & List
griffpatch
Top Down Scroller | Part 4 | Live Die Repeat (Game Over)
griffpatch
Top Down Scroller | Part 5 | You've Won!
griffpatch
Cloud Game Tutorial | Part 1 | The Basics
griffpatch
Cloud Game Tutorial | Part 2 | Encoding and Decoding
griffpatch
Scratch 3 Dev Tools Browser Extension by griffpatch
griffpatch
Cloud Game Tutorial | Part 3 | Multiplayer
griffpatch
Scrolling Platformer Tutorial | Part 9 | Momentum
griffpatch
Scrolling Platformer Tutorial | Part 10 | Wall Jumping
griffpatch
Cloud Game Tutorial | Part 4 | Auto Game Joining
griffpatch
Game Preview - "Getting Over It" with Griffpatch - A fan recreation in Scratch
griffpatch
Speed Run with Outtakes | Getting Over It | 4 minutes 30 seconds
griffpatch
Griffpatch's Live Stream
griffpatch
MMO Platformer Speedrun Challenge
griffpatch
Appel Platformer | Scratch Game Blog
griffpatch
Cloud Game Tutorial | Part 5 | Smooth Movement
griffpatch
How to Design a Level for Appel
griffpatch
Fastest Appel Speedruns | Jan 2021
griffpatch
Tile Scrolling Platformer (Mario) | 1. Setup
griffpatch
Tile Scrolling Platformer | 2. Grid List
griffpatch
Tile Scrolling Platformer | 3. Tile Collisions
griffpatch
Tile Scrolling Platformer | 4. Platforming Scripts
griffpatch
Tile Scrolling Platformer | 5. The Level Editor
griffpatch
Tile Scrolling Platformer | 6. Level Codes
griffpatch
Tile Scrolling Platformer | 7. Drop Through Platforms
griffpatch
How to make Physics in Scratch | Full Tutorial
griffpatch
Tile Scrolling Platformer | 8. Enemy Clones
griffpatch
Simple Pathfinding Tutorial
griffpatch
Tile Scrolling Platformer | 9. Enemies in Level Editor
griffpatch
Simple Maze Generation | Scratch Tutorial
griffpatch
Tile Scrolling Platformer | 10. Mystery Blocks
griffpatch
Simple Car Steering Simulation | Scratch Tutorial
griffpatch
Simple Background Scrolling Tutorial
griffpatch
Tile Scrolling Platformer | 11. Death, Background & Sound
griffpatch
Mid Week Update & Channel Membership
griffpatch
Simple Grid List Tutorial with Image Scanning
griffpatch
Tile Scrolling Platformer | 12. Auto Arranging Tiles
griffpatch
Code a Fun Space Shooter Game 🚀 | 1. Move & Shoot | Scratch Tutorial
griffpatch
Space Shooter 2 - Enemy Collisions
griffpatch
Tile Scrolling Platformer | 13. Level Progression & Editor Improvements
griffpatch
Space Shooter 3 - Camera Shake & FX
griffpatch
Tile Scrolling Platformer | 14. Sloping Tiles
griffpatch
Pathfinding a Maze using Lists
griffpatch
Tile Scrolling Platformer | 15. Crouch & Slide
griffpatch
More on: AI Productivity Tools
View skill →
🎓
Tutor Explanation
DeepCamp AI