Coding

Scratch Tutorial for Beginners – Make a Flappy Bird Game

  • 00:00:00 hello everyone in this video I will be
  • 00:00:02 showing you how to make a flappy bird
  • 00:00:03 type game in scratch for those of you
  • 00:00:06 who don't know what scratch is scratch
  • 00:00:08 is a block based programming language
  • 00:00:10 where you can drag and drop blocks to
  • 00:00:11 create projects it's more of an
  • 00:00:14 educational type of visual programming
  • 00:00:16 language to teach children how to code
  • 00:00:18 there's also a online community where
  • 00:00:21 you can view other people's projects and
  • 00:00:22 share your own anyways to get started go
  • 00:00:25 to scratch.mit.edu which is the scratch
  • 00:00:27 website once you're there you can either
  • 00:00:29 create a new account by clicking the
  • 00:00:31 join scratch button over here or scroll
  • 00:00:34 down and download the offline editor
  • 00:00:36 which is the same thing if you're using
  • 00:00:39 the online version once you have created
  • 00:00:41 an account you can click the create
  • 00:00:43 button over here to start a new project
  • 00:00:46 so let's start by creating the bird so
  • 00:00:49 I'm gonna go to the costumes of this
  • 00:00:52 scratch cat and I'm gonna delete the
  • 00:00:54 second one and I'm going to clear this
  • 00:00:58 one and I'll draw my own bird so I'll
  • 00:01:02 start by creating a circle let's see
  • 00:01:06 about this size I think now I'm going to
  • 00:01:09 add a black outline to it right here –
  • 00:01:15 maybe a I think size 5 is good I'll
  • 00:01:19 decrease the circle a little bit though
  • 00:01:21 maybe – this big all right and since I'm
  • 00:01:28 making a bird I'll make it yellow on the
  • 00:01:31 inside so about this color alright so
  • 00:01:36 let's see now I'll draw the eye so I'm
  • 00:01:40 drawing an another circle I'll make it
  • 00:01:45 this big and I'll position this right
  • 00:01:50 over here okay
  • 00:01:56 I'll actually make this fill black and
  • 00:01:59 I'll keep that outline so yeah now I'm
  • 00:02:02 going to draw a beak so I'll draw two
  • 00:02:05 lines like this
  • 00:02:10 and I'll make the fill yellow actually
  • 00:02:15 the same color as the bird so this and
  • 00:02:19 then I got to make sure the beak is
  • 00:02:22 under the bird so I'm going to shift it
  • 00:02:25 backwards like that and I think I'm
  • 00:02:30 going to add some legs so I'll just draw
  • 00:02:33 some quick lines like this and there so
  • 00:02:41 yeah this is a really quick drawing I
  • 00:02:43 don't want to spend too much time
  • 00:02:45 drawing so that's why I quickly created
  • 00:02:48 a bird so yeah anyways now I am done and
  • 00:02:51 I'm going to go back to the code and now
  • 00:02:55 let's start coding the bird so I want
  • 00:02:59 the bird to be able to jump when I press
  • 00:03:01 the mouse button so to do that let's go
  • 00:03:04 to the event and then drag this wind fly
  • 00:03:08 clicked onto here and now let's go to
  • 00:03:11 control and then grab a forever loop and
  • 00:03:16 I'm going to drag an if-then statement
  • 00:03:19 and then I'm going to go to sensing
  • 00:03:22 that's where the mouse down stuff is
  • 00:03:24 then I'll drag the mouse down into the
  • 00:03:27 if-then so pretty much what happens is
  • 00:03:30 that when I press the green flag
  • 00:03:31 then this keeps checking if the mouse is
  • 00:03:35 down so now we want to actually do stuff
  • 00:03:38 when the mouse is down so first of all
  • 00:03:41 we want the bird to be affected by
  • 00:03:43 gravity so pretty much when the bird
  • 00:03:45 falls it falls faster and faster over
  • 00:03:48 time so to do that we actually have to
  • 00:03:50 create a variable so let's go to
  • 00:03:52 variables and let's create one let's
  • 00:03:55 call this Y velocity and let's select
  • 00:04:04 for the sprite only so pretty much this
  • 00:04:08 variable is only or actually can only be
  • 00:04:11 used by the bird so now let's click OK
  • 00:04:13 and what our Y philosophy variable is
  • 00:04:18 going to do is that it's going to be the
  • 00:04:21 speed of the bird in the Y position
  • 00:04:23 which is up and down so pretty much if
  • 00:04:26 our Y velocity is going to be three then
  • 00:04:29 the bird is going to move upwards
  • 00:04:31 constantly at three units and if our Y
  • 00:04:35 velocity is let's say negative ten
  • 00:04:38 then our bird is going to move downwards
  • 00:04:40 constantly by ten units however we want
  • 00:04:44 the bird to move downwards faster and
  • 00:04:48 faster right we want the bird to fall
  • 00:04:49 faster and faster over time so we're
  • 00:04:51 going to actually be changing the Y
  • 00:04:53 velocity which means that we're going to
  • 00:04:55 be changing the speed in which the bird
  • 00:04:57 moves down over time so it's like
  • 00:04:59 gravity
  • 00:05:00 so let's first set the Y velocity to
  • 00:05:04 zero when the flag is clicked and okay
  • 00:05:08 let's make the bird start over here so
  • 00:05:10 that's like let's go to motion so
  • 00:05:14 negative one seventy two and zero in the
  • 00:05:17 Y position and then let's see so what we
  • 00:05:22 want is that we want the Y position of
  • 00:05:25 the bird to be always changing
  • 00:05:27 by the Y velocity variable or the speed
  • 00:05:31 so I'm actually to make this more clear
  • 00:05:33 I'm going to rename the Y velocity
  • 00:05:35 variable to change in Y so I think
  • 00:05:42 that's easier to understand but anyways
  • 00:05:44 let's go back to the motion blocks and
  • 00:05:46 what I'm gonna do is drag a change Y
  • 00:05:49 block drag it inside of the forever loop
  • 00:05:52 and then I'll go to variables and drag
  • 00:05:56 the change in Y variable inside of the
  • 00:05:59 change Y by block so what this is is
  • 00:06:03 that the Y position of the bird is
  • 00:06:05 always going to change by the change in
  • 00:06:07 Y so now we have to set the values for
  • 00:06:10 the change in Y so if we press the mouse
  • 00:06:14 button we want to set the change in Y by
  • 00:06:19 let's say nine so pretty much what
  • 00:06:23 happens is that when we click then the
  • 00:06:27 speed of the bird will be going upwards
  • 00:06:29 by nine and it would keep going up so
  • 00:06:33 let's try it out when we press then it
  • 00:06:36 keeps going up like that
  • 00:06:37 so yeah but now of course we want the
  • 00:06:40 bird to fall so what we can do is
  • 00:06:43 actually just drag a change change in Y
  • 00:06:47 by block and put it in the forever loop
  • 00:06:50 and let's change it by let's say
  • 00:06:53 negative 0.8 sorry negative 0.8 so since
  • 00:07:00 there is gravity we always want the bird
  • 00:07:02 to be going downwards so now let's try
  • 00:07:05 it out
  • 00:07:07 now as you can see it works there's
  • 00:07:11 gravity because the bird keeps going
  • 00:07:14 down by negative 0.8 and then when we
  • 00:07:17 press the mouse button then the speed of
  • 00:07:20 the bird changes to 9 so um yeah that's
  • 00:07:25 a really simple jumping script we have
  • 00:07:27 right here and anyways that will do it
  • 00:07:30 for right now for the bird so now let's
  • 00:07:33 create our pipes where the birds going
  • 00:07:36 to go through so let's click the button
  • 00:07:38 over here and let's create a new sprite
  • 00:07:42 so I'm just gonna draw some simple pipes
  • 00:07:46 let's see I'm going to draw a rectangle
  • 00:07:50 like this and I'm going to make the
  • 00:07:55 pipes green and all right and now I'm
  • 00:08:02 going to add another rectangle put it
  • 00:08:05 right here like this okay I'll make the
  • 00:08:12 pipes a bit thicker all right okay
  • 00:08:26 cool all right so this is going to be
  • 00:08:28 the top pipe and now we want the bottom
  • 00:08:31 pipe so let's create a new costume
  • 00:08:35 actually um let's duplicate this one and
  • 00:08:38 then I'm gonna flip it so let's select
  • 00:08:41 the entire thing and then let's flip
  • 00:08:45 vertically and now we have the bottom
  • 00:08:48 pipe alright so we have to the top and
  • 00:08:51 the bottom pipe so let's first name
  • 00:08:53 these I'll name this top pipe and this
  • 00:08:57 one bottom pipe and alright let's go
  • 00:09:02 back to the code so of course we want a
  • 00:09:06 win site clicked and what we want is
  • 00:09:11 that we want this sprite to be creating
  • 00:09:13 copies of the top and bottom pipe
  • 00:09:15 because we're gonna have more than one
  • 00:09:17 pipe on the screen at any given time so
  • 00:09:20 just to make it easier to manage we
  • 00:09:22 don't want the actual sprite to show so
  • 00:09:25 let's go to looks and then hide the
  • 00:09:27 sprite when the flag is clicked and now
  • 00:09:32 we we want the sprite to keep creating
  • 00:09:34 clones so let's go to control and then
  • 00:09:37 drag a forever loop and let's go to
  • 00:09:41 events oops sorry not events of control
  • 00:09:46 and let's drag a crepe clone of myself
  • 00:09:48 and put it inside of the forever loop so
  • 00:09:51 it's gonna keep creating clones of the
  • 00:09:53 pipe and we actually wanted to create
  • 00:09:56 two clones of the pipe because we have a
  • 00:09:59 top and the bottom pipe so if we try it
  • 00:10:03 right now then it's only gonna create
  • 00:10:04 clones of the bottom pipe
  • 00:10:07 so of course the pipes aren't shown but
  • 00:10:09 anyways if we do show the pipes
  • 00:10:11 let's just drag it when they start as a
  • 00:10:13 clone and also a show then the pipes are
  • 00:10:18 there's like tons of clones of the pipes
  • 00:10:20 like that but we want this sprite to
  • 00:10:24 simultaneously create the top and bottom
  • 00:10:26 pipes
  • 00:10:26 so let's actually first create a
  • 00:10:30 variable and let's name this
  • 00:10:38 or top pipe I guess and make sure to
  • 00:10:43 select for this right only this is very
  • 00:10:45 important otherwise it won't work so
  • 00:10:47 select for this fight only and then
  • 00:10:49 click OK
  • 00:10:50 and now what we want to do is to set
  • 00:10:55 bottom or top pipe and then drag it to
  • 00:10:58 the forever loop right before it creates
  • 00:11:00 a clone of itself and let's set it to
  • 00:11:03 top and then let's duplicate this and
  • 00:11:08 then put it under here and then we want
  • 00:11:12 to set bottom or top pipe to bottom
  • 00:11:15 and then in create clone of itself again
  • 00:11:19 so I'll explain to you later what this
  • 00:11:21 does but pretty much the clone is going
  • 00:11:24 to use this variable to know whether it
  • 00:11:26 is the top or the bottom pipe so anyways
  • 00:11:29 let's add a weight in here so let's go
  • 00:11:33 to events actually a control and then
  • 00:11:36 let's drag a way to 1 seconds and I'll
  • 00:11:39 change this to maybe 3 seconds alright
  • 00:11:41 and now in the when I start as a clone
  • 00:11:44 we will want to show it and now we want
  • 00:11:47 to add a if else statement so let's drag
  • 00:11:50 that and we want to check if it's the
  • 00:11:54 top pipe then it switches its costume to
  • 00:11:57 the top pipe costume and if it's the
  • 00:12:00 bottom pipe then it's going to switch
  • 00:12:02 costume to the bottom pipe costume so
  • 00:12:04 that's why we use this variable so let's
  • 00:12:07 do that so let's go to operators grab an
  • 00:12:11 equals operator drag inside of here and
  • 00:12:14 let's go to variables grab the bottom or
  • 00:12:17 top pipe variable put inside here and if
  • 00:12:20 the bottom or top pipe variable is equal
  • 00:12:22 to bottom make sure it's spelled the
  • 00:12:26 same as how you spelled it here but if
  • 00:12:30 it's bottom then we wanted to switch
  • 00:12:33 costume to bottom pipe and else if it is
  • 00:12:38 top then we switch costume to top pipe
  • 00:12:41 so it's as simple as that now let's try
  • 00:12:46 this out it's not gonna work but let's
  • 00:12:48 just see how it is so far so as you can
  • 00:12:50 see
  • 00:12:51 actually spawns the top and bottom pipe
  • 00:12:53 like that all right so now we want the
  • 00:12:57 top and bottom pipes to actually be
  • 00:13:00 positioned correctly we want the top
  • 00:13:03 pipe right here and bottom pipe right
  • 00:13:05 here so to do that for now let's just go
  • 00:13:10 to motion and grab a go to put it after
  • 00:13:13 the switch costume to bottom pipe and
  • 00:13:16 for the bottom pipe let's let's see
  • 00:13:22 let's make it go like right here for now
  • 00:13:27 so we want to spawn at the edge of the
  • 00:13:30 screen right because the pipes are going
  • 00:13:32 to move from the right to the left
  • 00:13:33 so exposition to 5/9 and y position
  • 00:13:40 negative two one two all right
  • 00:13:43 and for the top pipe let's see let's
  • 00:13:49 make it spawn let's say right here so 2
  • 00:13:54 5 9 and y position 54 all right so let's
  • 00:13:59 try that for now so as you can see the
  • 00:14:02 top and bottom pipes spawn like this and
  • 00:14:04 now we want the top and bottom pipes to
  • 00:14:07 move to the left side of the screen
  • 00:14:09 right so to do this is to go to control
  • 00:14:12 and grab a repeat until block let's put
  • 00:14:16 that after the if-else statement so what
  • 00:14:19 the repeat until block does is that it
  • 00:14:21 keeps doing something as long as the
  • 00:14:24 thing in here is true and then after the
  • 00:14:27 thing in here is false then it runs the
  • 00:14:30 code after so of course since we want
  • 00:14:33 the blocks to disappear after reaching
  • 00:14:36 the left side of the screen we want to
  • 00:14:39 grab a operator let's grab a lesser than
  • 00:14:42 operator then inside here and let's go
  • 00:14:45 to motion grab the exposition block
  • 00:14:50 right here drag it inside of the repeat
  • 00:14:52 until operator and we want to check if
  • 00:14:55 the exposition is less than a certain
  • 00:14:58 number then the clones delete itself so
  • 00:15:02 let's see let's first show the initial
  • 00:15:03 sprite
  • 00:15:05 and let's see right here so if the
  • 00:15:08 exposition is less than negative 237
  • 00:15:12 then the Clones should delete themselves
  • 00:15:14 so let's go to a control and let's grab
  • 00:15:18 a delete this clone and drag it after
  • 00:15:20 the repeat into so of course we want the
  • 00:15:24 pipes to be moving to the left until the
  • 00:15:27 exposition is less than negative 237 so
  • 00:15:30 let's go to a motion and let's grab a
  • 00:15:33 change X by block and put it inside of
  • 00:15:36 the repeat into and let's change it by
  • 00:15:40 let's say negative 5 so we want the
  • 00:15:45 pipes to move towards the left by 5
  • 00:15:48 units until it reaches the edge here and
  • 00:15:51 then it hides so yeah let's try it out
  • 00:15:54 and as you can see the pipes work like
  • 00:15:58 that and we can like increase or
  • 00:16:01 decrease the spawn rate so maybe you can
  • 00:16:03 wait like one second and we can see
  • 00:16:06 there's the pipes like this and they
  • 00:16:09 also disappear once they touch it left
  • 00:16:12 to edge of the screen and they appear
  • 00:16:14 from the right so yeah the pipes seem to
  • 00:16:17 be working
  • 00:16:18 however we want spawning in the Y
  • 00:16:21 position so to do that we actually have
  • 00:16:24 to create a new variable so let's create
  • 00:16:26 a new variable let's call it random Y
  • 00:16:36 spawn I guess random Y spawn position
  • 00:16:41 and let's select for the spy only and
  • 00:16:46 then click OK so what we want to do is
  • 00:16:50 to set a random Y position for the
  • 00:16:54 blocks to spawn from so to do that let's
  • 00:16:57 first drag this into this forever loop
  • 00:17:00 before it creates clones of the pipes
  • 00:17:03 and let's go to operators to grab the
  • 00:17:08 pick random and put it inside of the set
  • 00:17:11 random y spawn position and um let's see
  • 00:17:16 let's maybe okay let's deal with this
  • 00:17:19 but let's see the range in which the
  • 00:17:22 pipes can spawn so I'm going to show the
  • 00:17:24 original sprite and I'm gonna do some
  • 00:17:28 testing so let's see I think the top
  • 00:17:32 pipe should be right here around this
  • 00:17:36 would be the highest point it can spawn
  • 00:17:38 so that's why position 153 and the
  • 00:17:44 lowest position for the bottom pipe is
  • 00:17:46 gonna be let's say right here so
  • 00:17:50 negative 284 so for now let's just put
  • 00:17:54 in 1 what was it again
  • 00:17:57 153 I think yeah 153 to negative 284 I
  • 00:18:04 think let's just double-check yeah
  • 00:18:12 something like that
  • 00:18:13 all right so this is going to be the
  • 00:18:15 range in which the pipes can spawn but
  • 00:18:17 oh yeah one important thing I think to
  • 00:18:20 make this easier let's go to the
  • 00:18:22 costumes and make sure that the pipes
  • 00:18:24 are actually positioned where we want
  • 00:18:27 them so let's say let's copy this bottom
  • 00:18:32 pipe and put it into the top pipe for
  • 00:18:34 now and let's say we want our space to
  • 00:18:38 be this big right then we want to make
  • 00:18:42 sure that the top pipe and bottom pipe
  • 00:18:45 are positioned like this in each of
  • 00:18:48 their costumes so I'm gonna move this to
  • 00:18:50 the middle right here okay I think this
  • 00:18:54 is the middle alright so right here so
  • 00:18:59 now I'm gonna delete the bottom pipe or
  • 00:19:04 actually not yet I'm gonna first
  • 00:19:06 duplicate this and then I'm gonna delete
  • 00:19:10 the bottom pipe and now I'm gonna go to
  • 00:19:13 my duplicate and then I'm gonna delete
  • 00:19:17 the top pipe and now we don't need this
  • 00:19:21 extra bottom pipe costume so yeah
  • 00:19:25 anyways now we have the top pipe and
  • 00:19:28 bottom pipe where we want them and I'm
  • 00:19:32 gonna first rename this to bottom five
  • 00:19:33 all right cool so of course you can
  • 00:19:37 change the space in which is between the
  • 00:19:40 top and bottom pipe so that's up to you
  • 00:19:42 but yeah let's go back to the code now
  • 00:19:45 and let's see let's find our range in Y
  • 00:19:50 positions again now so let's see for the
  • 00:19:55 top pipe I'd say Y position 79 and for
  • 00:20:01 the bottom pipe
  • 00:20:02 I'd say Y position negative 79 all right
  • 00:20:06 that works well so now because I
  • 00:20:10 repositioned these two pipes to where
  • 00:20:13 want them it's now super easy so all you
  • 00:20:16 have to do is to go to variables and
  • 00:20:19 then drag the random Y spawnposition
  • 00:20:21 into the go to X Y and in the Y so let's
  • 00:20:26 drag that into here for both the top and
  • 00:20:29 the bottom pipe and now let's try it out
  • 00:20:34 so as you can see it works however the
  • 00:20:38 pipes are entirely on the screen like
  • 00:20:43 there's some empty space but of course
  • 00:20:46 we can go to the costumes and change
  • 00:20:47 that but at least the random Y position
  • 00:20:51 works so as you can see they're spawned
  • 00:20:54 randomly so to change or actually to fix
  • 00:20:58 the problem let's go to costumes and all
  • 00:21:02 we needed to do is to increase this
  • 00:21:05 length of the rectangle so let's drag
  • 00:21:08 this entire rectangle down here
  • 00:21:10 and I'm going to drag this rectangle
  • 00:21:16 upwards like this all right now I'm
  • 00:21:19 gonna select the entire thing and then
  • 00:21:21 drag it back up I think it was right
  • 00:21:25 around here okay maybe a bit more
  • 00:21:30 downwards yeah about right all right and
  • 00:21:35 now let's do the same for the bottom
  • 00:21:36 pipe move it up here drag the rectangle
  • 00:21:41 down here and then drag the entire thing
  • 00:21:44 back down
  • 00:21:46 right around here I think so yeah all
  • 00:21:51 right looks good okay I think this one's
  • 00:21:54 positioned a bit to the left so I'll
  • 00:21:57 move it back maybe this one a bit to the
  • 00:22:02 left
  • 00:22:05 all right cool so now let's run it and
  • 00:22:10 as you can see the pipes now spawn like
  • 00:22:13 this they're in a random Y position and
  • 00:22:15 the entire pipe covers like both the top
  • 00:22:20 and the bottom edges of the screen so
  • 00:22:23 awesome I think I'm going to increase
  • 00:22:27 the gap a bit because I don't think the
  • 00:22:29 bird can go through like very easily or
  • 00:22:32 if it's possible at all so let's
  • 00:22:36 increase the gap and to do that it's
  • 00:22:38 really simple you just move the top and
  • 00:22:40 the bottom pipe upwards and downwards so
  • 00:22:43 the top pipe upwards like this and the
  • 00:22:46 bottom pipe downwards like this all
  • 00:22:51 right and make sure your gap is equal on
  • 00:22:53 both the top and the bottom compared to
  • 00:22:56 the middle like over here versus over
  • 00:22:58 here so yeah it looks about right now
  • 00:23:01 let's try it
  • 00:23:01 and now the gap is much larger so
  • 00:23:05 awesome I'll make the bird a bit smaller
  • 00:23:09 I think so I'll go back to the bird I'm
  • 00:23:12 gonna go to looks and change the size or
  • 00:23:15 set the size to maybe 80 okay I think
  • 00:23:20 that's better so yeah now I think for
  • 00:23:24 the bird it looks a bit like two still
  • 00:23:28 when it jumps so I think I'm gonna
  • 00:23:31 rotate it when it jumps so it looks like
  • 00:23:33 it's actually flapping so to do that
  • 00:23:35 let's just go to motion and drag a point
  • 00:23:39 in direction and drag it under the if
  • 00:23:42 Mouse down and I'm going to change it to
  • 00:23:46 let's say 45 degrees and what this does
  • 00:23:51 is that it's gonna change it to like
  • 00:23:53 this when it jumps but of course we want
  • 00:23:56 the bird to rotate back to its original
  • 00:23:59 position which
  • 00:24:00 90 degrees so let's just grab it if
  • 00:24:03 statement and then put it inside of the
  • 00:24:07 forever loop and let's go to operators
  • 00:24:10 grab a lesser than operator and we want
  • 00:24:15 to check if the direction which is in
  • 00:24:18 the motions is less than 90 which was
  • 00:24:23 its starting direction then we want it
  • 00:24:25 to turn clockwise let's say three
  • 00:24:29 degrees so pretty much if the bird is
  • 00:24:34 like this then it's gonna keep rotating
  • 00:24:37 until it faces the right so let's try it
  • 00:24:39 out now as you can see there is some
  • 00:24:42 motion with the bird so when it flaps it
  • 00:24:44 sort of moves back like that so I think
  • 00:24:48 it looks better like this and I might
  • 00:24:50 change it to maybe turn four degrees so
  • 00:24:54 let's try it all right I think that
  • 00:24:57 looks much better
  • 00:24:59 so yeah now let's make a simple lose
  • 00:25:04 state so when the bird touches the pipes
  • 00:25:07 then let's just stop the game for right
  • 00:25:09 now so let's see let's drag a if
  • 00:25:14 statement inside of the forever loop and
  • 00:25:18 let's go to sensing and it's detect if
  • 00:25:22 touching sprite – or the pipes then it's
  • 00:25:27 gonna stalk all so let's go to control
  • 00:25:29 and let's stop everything so let's try
  • 00:25:34 it out and yeah when it touched a pipe
  • 00:25:39 then the entire game stopped all right
  • 00:25:41 so okay I'm gonna first hide all of my
  • 00:25:44 variables all right so then I'll try it
  • 00:25:49 again okay and when it touch the pipe
  • 00:25:54 then the entire game stopped all right
  • 00:25:56 cool okay and it's like this
  • 00:26:05 okay um I think I'm going to add a
  • 00:26:08 simple background so I'll go to
  • 00:26:10 backdrops here go to costumes or
  • 00:26:11 backdrops and then I'm going to fill it
  • 00:26:15 or actually I'll convert to bitmap and
  • 00:26:18 then I'll fill this maybe to light blue
  • 00:26:23 let's see like this and all right now we
  • 00:26:32 have some simple backdrop so um yeah
  • 00:26:36 this is our completed game or actually
  • 00:26:40 not completed but a completed working
  • 00:26:42 game so all right cool let's see yeah
  • 00:26:47 this is a bit hard right now but you
  • 00:26:49 know you can tweak it to change the
  • 00:26:51 difficulty to make it easier maybe so
  • 00:26:54 yeah
  • 00:27:01 this is part 2 on how to make a flappy
  • 00:27:03 bird game in scratch in this tutorial I
  • 00:27:06 will be creating an infinite scrolling
  • 00:27:08 background and a scoring system so the
  • 00:27:11 first thing I wanted to add that I
  • 00:27:12 didn't do in the last video was to make
  • 00:27:15 the bird be able to lose when it reaches
  • 00:27:18 the bottom of the screen over here so to
  • 00:27:21 do that it's actually really simple
  • 00:27:23 let's go to operators and then grab and
  • 00:27:25 or statement and let's put it over here
  • 00:27:29 so if the bird is touching sprite to
  • 00:27:33 which are the pipes or if the birds Y
  • 00:27:36 position is less than a certain value
  • 00:27:41 let's see if it's less than negative 171
  • 00:27:49 then we want to stop the game so let's
  • 00:27:52 try it out if the bird goes to the
  • 00:27:54 bottom here then the game stops all
  • 00:27:56 right so now that we're done with that
  • 00:27:59 I'm going to start creating the
  • 00:28:01 scrolling background so I was thinking
  • 00:28:03 of maybe adding some hills in the
  • 00:28:05 background and then making the moving
  • 00:28:08 slowly to the left to make it look like
  • 00:28:10 the bird is you know moving so let's do
  • 00:28:13 that
  • 00:28:14 so let's first create a new sprite and
  • 00:28:17 now I'm going to draw my hills
  • 00:28:24 all right so I'm done with my Hill and
  • 00:28:28 what I did was that I just made a
  • 00:28:30 rectangle across the entire drawing area
  • 00:28:32 and then I use this v-shaped tool to you
  • 00:28:36 know add a few points and then I just
  • 00:28:38 moved these points around to make it
  • 00:28:41 curvy all right so make sure that the
  • 00:28:45 width of your hill is exactly the same
  • 00:28:48 width as the drawing area no more or
  • 00:28:51 less as you can see I made this very
  • 00:28:53 exact so yeah and also make sure that
  • 00:28:57 the height of the left edge over here is
  • 00:29:00 the exact same height as the height of
  • 00:29:03 the right edge over here anyways this
  • 00:29:06 will do for now and let me go back to
  • 00:29:08 the code so first off I'm going to grab
  • 00:29:13 a win flag clicked in the events and
  • 00:29:15 then I'm going to make the hills go to
  • 00:29:19 zero zero so now to the center of the
  • 00:29:23 screen and what I want is that I want
  • 00:29:25 this hill to constantly move towards the
  • 00:29:28 left so to do that let's go to control
  • 00:29:31 grab a forever loop and then let's go to
  • 00:29:35 motion grab the change X by block put it
  • 00:29:39 inside of the for loop and let's say
  • 00:29:42 let's change X by negative three alright
  • 00:29:47 so we try it right now then the hill as
  • 00:29:50 you can see always moves towards the
  • 00:29:52 left by three units all right so since
  • 00:29:56 I'm going to be testing this Hill a lot
  • 00:29:58 I'm going to disconnect the code from
  • 00:30:01 the chicken and the pipes so you know
  • 00:30:06 it's only the hill and I'm also going to
  • 00:30:09 hide the chicken all right so now this
  • 00:30:13 is just the hill
  • 00:30:14 so yeah alright cool so now that the
  • 00:30:18 Hill moves now we want the hill to go
  • 00:30:21 from the left edge of the screen to the
  • 00:30:23 right edge of the screen once it reaches
  • 00:30:26 the end over here so to do that let's
  • 00:30:28 grab and if statement
  • 00:30:30 and let's put this inside of the far
  • 00:30:33 loop and we want to check if the
  • 00:30:36 exposition of the
  • 00:30:37 are less than a certain value so let's
  • 00:30:41 go to operators grab a less than
  • 00:30:43 operator go to motion grab an exposition
  • 00:30:47 and let's check if the exposition is
  • 00:30:50 less than negative 464 so what it did
  • 00:30:58 was that I found the smallest possible
  • 00:30:59 value for this right which is negative
  • 00:31:03 465 and then I just added one so yeah
  • 00:31:06 so once the exposition of the hills is
  • 00:31:09 less than negative 464 then we wanted to
  • 00:31:13 move to the right side of the screen so
  • 00:31:16 since I made this hill the exact width
  • 00:31:19 of the screen which is 480 pixels or
  • 00:31:23 units then what I can do is just simply
  • 00:31:26 set X to its current x position over
  • 00:31:31 here multiplied by a negative one so
  • 00:31:34 let's go to operators grab the negative
  • 00:31:36 1 operator drag it inside of the set X 2
  • 00:31:39 and then go to motion grab the
  • 00:31:42 exposition and type in negative 1 all
  • 00:31:46 right so let's try it out once the hill
  • 00:31:49 reaches the left side of the screen then
  • 00:31:53 it teleports to the right side all right
  • 00:31:56 so it works it's infinite like this
  • 00:32:00 let's see it again
  • 00:32:02 and all right it works so oh yeah one
  • 00:32:06 thing I noticed was that it's not very
  • 00:32:08 smooth as you can see here you can see
  • 00:32:12 that it sort of gets cut off early
  • 00:32:14 before it it teleports to the right side
  • 00:32:17 so I don't really want that to happen
  • 00:32:19 let's say it again as you can see it
  • 00:32:23 doesn't completely go off the screen so
  • 00:32:26 that's sort of something that scratch
  • 00:32:28 has and to actually fix the issue
  • 00:32:30 I'm just going to go to looks and grab a
  • 00:32:34 set size to block and the right before
  • 00:32:37 it changes X by negative 3 and checks if
  • 00:32:41 the x position is less than negative 4
  • 00:32:43 64 I'm going to set size to 150 percent
  • 00:32:50 and right – after the hill moves and
  • 00:32:53 checks for all the stuff then I'm gonna
  • 00:32:56 set the size back to a hundred percent
  • 00:32:58 so like this before all of your code put
  • 00:33:01 in set size to 1 to 50% and then right
  • 00:33:04 after put set size to 100% so this is
  • 00:33:09 sort of complicated to explain but
  • 00:33:11 pretty much what this does is that the
  • 00:33:14 set size makes the hills bigger then
  • 00:33:17 it's actually supposed to be which is
  • 00:33:19 100 percent so right before it moves it
  • 00:33:23 can technically go off screen but then
  • 00:33:26 right after it moves it changes back to
  • 00:33:28 its original size so you wouldn't even
  • 00:33:31 notice that it's 150 percent of its
  • 00:33:34 normal size so let's try it out and
  • 00:33:38 let's see now
  • 00:33:43 Oh oops okay I forgot to change this to
  • 00:33:46 if the exposition is less than negative
  • 00:33:48 480 or actually a negative 479 so since
  • 00:33:54 the left edge of the screen is negative
  • 00:33:56 240 and the entire size of this costume
  • 00:33:59 is 480 then half of the costume size is
  • 00:34:03 going to be 240 and then once you
  • 00:34:06 subtract 240 from negative 240 then that
  • 00:34:10 is the rightmost edge of the sprite at
  • 00:34:14 the leftmost edge so yeah that was again
  • 00:34:17 sort of confusing uh sorry but it should
  • 00:34:20 make sense visually so now let's try it
  • 00:34:22 out again and as you can see now the
  • 00:34:29 hill smoothly goes from the left side to
  • 00:34:33 the right side so let's see it again and
  • 00:34:37 all right so it works cool and I'm
  • 00:34:41 actually gonna quickly add a dark green
  • 00:34:44 outline because I think the light green
  • 00:34:46 is sort of too close to the light blue
  • 00:34:50 color of the sky so yeah I'm gonna
  • 00:34:52 quickly add a line over here
  • 00:34:58 all right so I'm done with my outline I
  • 00:35:01 just pretty much added a line and then I
  • 00:35:03 just reshaped it using this tool to fit
  • 00:35:06 the hill all right so now I think it
  • 00:35:09 looks better let's try it again
  • 00:35:11 and as you can see there's the hill and
  • 00:35:14 then teleports back so now we need to
  • 00:35:18 add the second Hill because once the
  • 00:35:21 hill is moving then there's a lot of
  • 00:35:23 empty space and we don't want that so to
  • 00:35:26 add a second Hill all we need to do is
  • 00:35:28 to go to control and then create clone
  • 00:35:31 of myself all right and we want to make
  • 00:35:37 the clone do the exact same thing as the
  • 00:35:40 original sprite however the only
  • 00:35:42 difference will be that the clone is
  • 00:35:44 shifted to the right of the sprite so
  • 00:35:46 let's grab a when I star as a clone then
  • 00:35:50 let's go to motion and then let's drag
  • 00:35:53 this go to X 480 and then y 0 and to
  • 00:35:57 make sure to go to looks grab the set
  • 00:36:00 size to 150 put it before the go to X Y
  • 00:36:03 and then grab the set size 100 and then
  • 00:36:05 put it after since we want the clone to
  • 00:36:09 go completely off screen so yeah anyway
  • 00:36:12 since the clone is going to have exactly
  • 00:36:15 the same code as the original sprite
  • 00:36:17 we're gonna create a block so let's go
  • 00:36:20 to my blocks and then make a block let's
  • 00:36:22 call this move then let's click OK all
  • 00:36:28 right now we have move and now we want
  • 00:36:31 to drag this set size to 150 and stuff
  • 00:36:36 like that into the move and now we can
  • 00:36:39 drag our move block inside of the
  • 00:36:41 forever loop and okay so my move block
  • 00:36:45 did not appear um that sometimes happens
  • 00:36:48 so I'm just gonna refresh the page there
  • 00:36:52 we go so now there is the move block and
  • 00:36:54 let's put this inside of the forever
  • 00:36:57 loop and for the clone let's just
  • 00:37:00 duplicate this for loop and then put it
  • 00:37:03 under the stuff over here
  • 00:37:05 alright so now the original sprite and
  • 00:37:07 the clone both follow the same
  • 00:37:09 code in the move block so it's sort of
  • 00:37:12 simpler because if I want to change
  • 00:37:14 something all I need to do is change
  • 00:37:16 this one move block instead of you know
  • 00:37:18 changing two separate blocks like this
  • 00:37:21 so all right now let's see how it looks
  • 00:37:26 so as you can see there is now a
  • 00:37:28 infinite scrolling hill background and
  • 00:37:31 it looks very smooth and yeah alright so
  • 00:37:37 I think there's a tiny difference in the
  • 00:37:41 line I just drew so I'm gonna fix it
  • 00:37:44 real quick let's see it's over here okay
  • 00:37:52 let's try it again
  • 00:37:54 yeah you can barely tell that I have two
  • 00:37:58 Hills so yeah alright so now that we're
  • 00:38:03 done with the hill background we can't
  • 00:38:05 add the chicken and the pipes back so
  • 00:38:07 let's show the chicken then reconnect
  • 00:38:12 the blocks then go to the pipes
  • 00:38:15 reconnect the blocks also and now you
  • 00:38:19 try it out and okay the hills are in
  • 00:38:23 front of both the chicken and the pipes
  • 00:38:25 so we want them to go back so let's go
  • 00:38:28 to looks and grab a go backwards let's
  • 00:38:35 say ten layers to make sure that it
  • 00:38:37 actually goes back and I'll let's drag
  • 00:38:40 this um in the wind flag clicked before
  • 00:38:42 it creates a clone of itself and now it
  • 00:38:46 works like this alright cool now we have
  • 00:38:50 sort of some parallax going on which is
  • 00:38:53 pretty much on the hill moves to the
  • 00:38:55 left slower than the pipes do so yeah
  • 00:39:02 now we have our infinite background and
  • 00:39:05 now we're going to make a simple scoring
  • 00:39:08 system so let's go to the pipes and
  • 00:39:12 let's see we want to first create a
  • 00:39:16 score variable so let's go to variables
  • 00:39:18 then create a variable let's call this
  • 00:39:21 score
  • 00:39:23 then for all sprites and they click okay
  • 00:39:25 all right so what we want to do is that
  • 00:39:28 if the bird goes past the middle of the
  • 00:39:32 pipes that we want the score to
  • 00:39:34 increased by one so to do that we have
  • 00:39:39 to go into pipes and then we want to
  • 00:39:42 check if the exposition of the bird is
  • 00:39:46 greater than the exposition of the pipes
  • 00:39:49 so let's go to operators and grab a
  • 00:39:53 greater than operator and let's go to
  • 00:39:56 sensing grab the BACtrack number of
  • 00:40:00 stage block and change the stage to
  • 00:40:03 sprite one which is the bird and now we
  • 00:40:08 have our exposition of sprite one so if
  • 00:40:11 the exposition of the bird is greater
  • 00:40:14 than the pipe exposition so motion and
  • 00:40:18 then exposition then we want to go to
  • 00:40:21 variables and then change score by one
  • 00:40:25 all right now we want to put this inside
  • 00:40:28 of the repeat until and now as the pipes
  • 00:40:32 are moving to the left it's going to
  • 00:40:34 constantly check so now there's a one
  • 00:40:39 problem though whenever the bird is
  • 00:40:41 passed the pipes the score goes up by a
  • 00:40:44 lot because it keeps checking and the
  • 00:40:46 score keeps going up but we only want
  • 00:40:48 the score to go up once so to fix that
  • 00:40:53 we can just simply create a variable
  • 00:40:55 let's name this already scored so
  • 00:41:00 already scored and we want to select for
  • 00:41:06 this sprite only this is a very
  • 00:41:08 important for the sprite only Dennis
  • 00:41:11 cook okay and let's see where is my
  • 00:41:15 variable hmm all right so there it is
  • 00:41:21 already scored so what we're gonna do is
  • 00:41:25 the first set already scored to no
  • 00:41:28 because when the pipes spawn then the
  • 00:41:32 bird hasn't gone through them yet so of
  • 00:41:35 course the bird has not
  • 00:41:36 scored so let's set this to no put it on
  • 00:41:39 before everything in the if and repeat
  • 00:41:43 until loops and now we want to check if
  • 00:41:46 the bird has not yet already scored then
  • 00:41:49 we want to change score by one so let's
  • 00:41:52 go to operators grab an and and its grab
  • 00:41:56 to equal and it's go to variables grab
  • 00:41:59 already scored and it's check if already
  • 00:42:02 scored is equals to no now let's drag
  • 00:42:07 this over here into the left side and
  • 00:42:10 let's put it back so of course it also
  • 00:42:14 checks if the bird has already scored
  • 00:42:17 and if it's no then it changes score by
  • 00:42:20 one but of course once it changes the
  • 00:42:23 score by one then it has scored so we
  • 00:42:26 don't want this to call again so we just
  • 00:42:29 set already scored to yes
  • 00:42:34 so now it's only going to call once so
  • 00:42:37 let's try it out all right and it
  • 00:42:43 doesn't quite work the score goes up by
  • 00:42:46 two so let's see I think to fix this I'm
  • 00:42:51 going to make this set before the score
  • 00:42:54 changes by one now let's try it again
  • 00:42:59 okay still does not work let's see oh
  • 00:43:07 yeah that is because we have both the
  • 00:43:10 top and the bottom pipe so it acts as
  • 00:43:13 two clones and it both check so what we
  • 00:43:15 want to do is either only make the top
  • 00:43:18 or the bottom pipe check so let's only
  • 00:43:21 make the top pipe check so do that let's
  • 00:43:24 grab another operator grab an and grab
  • 00:43:27 an equals and let's see check if the
  • 00:43:32 bottom or top pipe is equal to top now
  • 00:43:37 let's drag this into the left side and
  • 00:43:40 I'll check the entire thing back in let
  • 00:43:45 me zoom out a bit alright
  • 00:43:48 and now it should work so first it
  • 00:43:52 checks if the exposition of the bird is
  • 00:43:55 greater than the current pipe exposition
  • 00:43:57 which means that the bird went past it
  • 00:44:00 it also checks if the bird already
  • 00:44:02 scored and also checks if the bottom or
  • 00:44:06 top pipe is equal to top then if all of
  • 00:44:09 these are true then it sets already
  • 00:44:12 scored – yes and then it train a score
  • 00:44:15 by one now let's try it out first of all
  • 00:44:18 I'm going to set the score to zero
  • 00:44:22 whenever the flag is clicked and now it
  • 00:44:24 should be good so as you can see the
  • 00:44:29 score changes by one every time so yeah
  • 00:44:33 all right it works cool let me try it
  • 00:44:38 again
  • 00:44:41 and yeah now I have both my scrolling
  • 00:44:47 background and the score counter the
  • 00:44:50 game also ends when the bird touches the
  • 00:44:52 bottom of the screen like this
  • 00:44:58 this is part three on how to make a
  • 00:45:00 flappy bird game in scratch in this
  • 00:45:02 video I will be making the pipe skill on
  • 00:45:04 screen and off screen more smoothly add
  • 00:45:05 a number counter for the score and add a
  • 00:45:08 simple Luo screen anyways let's get
  • 00:45:11 started with the pipes so if you see the
  • 00:45:14 pipes right now they sort of suddenly
  • 00:45:16 appear at the edge of the screen and
  • 00:45:18 they don't really smoothly appear and
  • 00:45:21 they also disappear before they can
  • 00:45:23 completely go off screen like that so
  • 00:45:26 I'm gonna fix that
  • 00:45:28 so let's first go to the pipes and then
  • 00:45:30 let's do the same thing we did for the
  • 00:45:32 background so in the last video I made
  • 00:45:35 the background be able to go on screen
  • 00:45:37 and off screen smoothly by first setting
  • 00:45:40 its size to a larger size than the
  • 00:45:42 actual size we want and then we position
  • 00:45:45 the background to where we want it and
  • 00:45:47 then we set the size back to its
  • 00:45:49 original size so let's do the same thing
  • 00:45:52 for the pipes so let's go to the pipes
  • 00:45:54 and then right before it spawns let's go
  • 00:46:00 to looks and then grab a set size too
  • 00:46:03 and let's change this to like 150% and
  • 00:46:07 then drag it right before go to XY and
  • 00:46:10 then let's drag a set size to 100% right
  • 00:46:15 after the go to XY and now let's change
  • 00:46:19 the X to like maybe 270 to completely
  • 00:46:23 make sure that the pipe is starting off
  • 00:46:26 screen and before the top pipe let's do
  • 00:46:29 the same thing so set size to 150% but
  • 00:46:33 it before and then set size to a hundred
  • 00:46:36 percent put it after so let's try it out
  • 00:46:40 and they still don't entirely start off
  • 00:46:46 screen so okay I think it should work
  • 00:46:50 after we also set size to 150 percent
  • 00:46:53 and a hundred percent before and after
  • 00:46:57 it changes X by negative five so let's
  • 00:47:00 try it out so let's drag this before we
  • 00:47:02 change X by negative five and then drag
  • 00:47:05 this after the change X by negative five
  • 00:47:07 so now let's try it again
  • 00:47:10 yeah I think that works the pipes as you
  • 00:47:13 can see spawn from the right side of the
  • 00:47:16 screen smoothly they don't you know sort
  • 00:47:19 of randomly appear from the edge so yeah
  • 00:47:22 and now let's fix the pipes leaving this
  • 00:47:27 screen so right now it's still a bit
  • 00:47:29 choppy when they leave the screen like
  • 00:47:31 that let's see it again
  • 00:47:34 yep so still a bit choppy so to fix that
  • 00:47:38 all we need to do is to change this x
  • 00:47:41 position to a smaller number so maybe
  • 00:47:45 let's say if X position is less than 200
  • 00:47:47 and I mean negative 260 now let's try it
  • 00:47:53 out
  • 00:47:54 oops okay let's try it again
  • 00:47:58 let me first reattach this and all right
  • 00:48:01 so let's see and cool they also leave
  • 00:48:07 the screen smoothly so yeah I think we
  • 00:48:10 fix the pipes and all right now that we
  • 00:48:16 have the pipes fixed now I'm going to
  • 00:48:18 make a number counter for the score so
  • 00:48:21 instead of using this variable I'm going
  • 00:48:23 to use actual numbers and that just
  • 00:48:26 makes the game look a bit better so yeah
  • 00:48:28 let's first create a new sprite and just
  • 00:48:32 paint 10 costumes with the number 0
  • 00:48:35 through 9 so yeah
  • 00:48:37 [Music]
  • 00:48:40 and yeah so now I have the numbers 1 2 3
  • 00:48:44 4 5 6 7 8 9 and then 0 so the costume
  • 00:48:49 names don't matter but the order matters
  • 00:48:51 so make sure it's 1 through 9 and then 0
  • 00:48:53 at the end so all right now let's go
  • 00:48:55 back to the code and let's first grab a
  • 00:48:58 win flag clicked then let's hide the
  • 00:49:02 original sprite because we're gonna be
  • 00:49:04 using clones for this and then let's
  • 00:49:07 create a variable let's name this I
  • 00:49:10 guess digits and then select for the
  • 00:49:14 sprite only remember this is very
  • 00:49:16 important for this part only because
  • 00:49:18 each clone is going to have a different
  • 00:49:21 value for the variable so if you do for
  • 00:49:23 all sprites then it's not gonna work
  • 00:49:25 because whenever the variable changes in
  • 00:49:28 value then all of the clones are going
  • 00:49:30 to have the same value for that variable
  • 00:49:33 so we want the clones to have separate
  • 00:49:35 values for the digits variable so select
  • 00:49:38 for this part only and then click OK
  • 00:49:41 all right by the way if your variable
  • 00:49:45 doesn't show up immediately after you
  • 00:49:47 created it then you can just refresh the
  • 00:49:49 page and it should show up but anyways
  • 00:49:52 let's grab a set digits to block and
  • 00:49:55 let's set the digits to 1 and let's drag
  • 00:50:00 this after Bhide now let's go to control
  • 00:50:04 grab a repeat loop and then let's grab a
  • 00:50:09 crate cloning myself and then go to
  • 00:50:12 variables and let's grab a change digits
  • 00:50:15 by one and this just creates 10 clones
  • 00:50:18 each with a different value of the
  • 00:50:20 digits so anyways now we want the clones
  • 00:50:23 to do stuff right so let's go to events
  • 00:50:26 I'll show your control sorry and then
  • 00:50:29 let's drag a when I start as a clone
  • 00:50:32 then we want the clone to show or
  • 00:50:39 actually not show yet but yeah so let's
  • 00:50:43 go to control grab a forever loop put it
  • 00:50:47 under the when I star as a clone and
  • 00:50:49 then we want the clones to go to a
  • 00:50:52 specific
  • 00:50:54 based on its digits favorable so let's
  • 00:50:57 go to a motion and then drag a go to Y
  • 00:51:01 position sorry a go to XY position and
  • 00:51:03 then let's go to variables grab the
  • 00:51:07 digits variable and then go to operators
  • 00:51:10 grab the multiplication operator let's
  • 00:51:13 drag the digits variable inside of the
  • 00:51:15 left side of the operator and let's say
  • 00:51:19 let's multiply this by 10 now let's drag
  • 00:51:25 this inside of the exposition of the go
  • 00:51:28 to X Y and let's place this inside of
  • 00:51:32 the forever loop so if I just run this
  • 00:51:36 what this does is that poops okay I need
  • 00:51:39 to show the clones for now so yep all
  • 00:51:43 right so if I run this then what this
  • 00:51:45 does is that it creates ten clones and
  • 00:51:48 they are all spaced apart by 10 pixels
  • 00:51:51 and this is because each clone has a
  • 00:51:54 different digits value because when I
  • 00:51:56 first set digits to one and then created
  • 00:51:59 a clone the clone I created the first
  • 00:52:01 time had the digits value set to one but
  • 00:52:04 then since I changed digits by one the
  • 00:52:06 next clone I created has the value of
  • 00:52:09 digits to two now and if I change it
  • 00:52:13 again and then create another clone then
  • 00:52:15 the third clone I created has the value
  • 00:52:17 of digits to three so that's how it
  • 00:52:19 works
  • 00:52:19 each clone I create has a different
  • 00:52:22 value of digits but yeah anyways now we
  • 00:52:26 want the clones to show or hide based on
  • 00:52:30 the score so let's say right now the
  • 00:52:32 score is two then we only want the ones
  • 00:52:36 place clone to show or this one and then
  • 00:52:41 we want all the other ones to hide so do
  • 00:52:44 that let's grab an if-else statement to
  • 00:52:46 any control drag that in the forever
  • 00:52:49 loop and then we want to check if the
  • 00:52:53 length of the score is less than its own
  • 00:52:57 variable of digits so let's grab a
  • 00:53:00 lesser than operator and then let's grab
  • 00:53:04 a length of
  • 00:53:07 and let's go to variables and then drag
  • 00:53:11 the score variable inside of the length
  • 00:53:13 of drag this into the left side and
  • 00:53:17 check if the length of score is less
  • 00:53:19 than digits so if it is that means we
  • 00:53:24 don't need that number and then we just
  • 00:53:27 hide it otherwise we want it to show
  • 00:53:31 so now as you can see since the score
  • 00:53:35 was 2 now only one of the digits to show
  • 00:53:38 so let's say the score was maybe like
  • 00:53:44 270 now all three of them show so yeah
  • 00:53:49 now we want these clones to show the
  • 00:53:52 correct number so to do that let's go to
  • 00:53:55 looks and if you want them to switch
  • 00:53:59 costume based on their digit in the
  • 00:54:03 score so to do that lets go to operators
  • 00:54:06 grab the letter operator or actually
  • 00:54:11 letter 1 of Apple and then let's replace
  • 00:54:14 the one with digits and then Apple with
  • 00:54:18 score now let's drag this inside of the
  • 00:54:22 switch costume – then let's drag this
  • 00:54:24 under the show so based on their own
  • 00:54:29 digits 1 2 & 3 they're going to show the
  • 00:54:32 letter of the score so 1 2 & 3 so yeah
  • 00:54:36 as you can see this shows the correct
  • 00:54:39 score now let's reposition this to the
  • 00:54:42 top so I'm just change this Y value to
  • 00:54:44 maybe 150 mm maybe 155 and I think
  • 00:54:52 that's fine and now we can hide the
  • 00:54:54 score variable now I think I'm going to
  • 00:54:58 want my score to be in the middle but
  • 00:55:00 however there is a problem so since the
  • 00:55:03 scores in the middle when the length of
  • 00:55:06 the score increases I still want my
  • 00:55:08 score to stay in the middle so right now
  • 00:55:10 it's not gonna work let's say I set the
  • 00:55:13 score to a really high number let's say
  • 00:55:18 like this and this score
  • 00:55:21 has one two three four seven digits so
  • 00:55:24 let's set it and as you can see this
  • 00:55:27 number is not in the middle because it's
  • 00:55:29 still in the same x position so um I
  • 00:55:33 want to fix that so that this number is
  • 00:55:35 in the middle no matter how many digits
  • 00:55:38 the score is so to do that let's grab a
  • 00:55:41 length of score so length of and then
  • 00:55:45 score and we want this to move back
  • 00:55:49 based on the length of the score right
  • 00:55:51 so now let's go to operators grab a
  • 00:55:55 multiplication operator drag this on the
  • 00:55:58 left side and make sure to multiply this
  • 00:56:00 by the same number you multiplied the
  • 00:56:03 digits by so in my case it would be ten
  • 00:56:05 and now we want to subtract this from
  • 00:56:10 the original exposition so let's grab a
  • 00:56:13 minus operator
  • 00:56:14 drag this on the left side drag this on
  • 00:56:17 the right side and oh yeah one more
  • 00:56:19 thing since we want the score to stay in
  • 00:56:22 the middle we want to divide this by two
  • 00:56:26 so let's put this on the left side and
  • 00:56:29 then divide by two
  • 00:56:32 all right now let's drag this inside of
  • 00:56:35 the minus operator and drag this back so
  • 00:56:40 as you can see the number is now in the
  • 00:56:42 middle let's try it out so let's say the
  • 00:56:46 score is zero
  • 00:56:48 then into the middle now let's try 100
  • 00:56:53 still in the middle let's try a thousand
  • 00:56:56 and it's still in the middle all right
  • 00:56:58 and just to make this more clear like
  • 00:57:01 these numbers here I'm gonna create a
  • 00:57:04 variable and all those name this space
  • 00:57:08 between digits I guess that'll click
  • 00:57:13 okay and I'll just set this to 10
  • 00:57:23 and then drag this to replace the tent
  • 00:57:26 all right now it's more clear and it's
  • 00:57:29 also easier to change because I can just
  • 00:57:31 change this variable to increase or
  • 00:57:34 decrease the space so I think I'm going
  • 00:57:36 to increase it to maybe 12 and all right
  • 00:57:40 I think that looks good so yeah now
  • 00:57:42 let's try it out and let's see how the
  • 00:57:46 score variable works all right it looks
  • 00:57:49 pretty good
  • 00:57:50 so I'm gonna try to get to 10 oops okay
  • 00:57:55 let me try again
  • 00:57:56 so we have zero right now one two three
  • 00:58:00 four
  • 00:58:01 dang it okay let me try again okay I
  • 00:58:07 don't think I'm gonna get to ten but
  • 00:58:10 let's just assume that the score miracle
  • 00:58:13 works based on my testing so yeah now
  • 00:58:16 that we fix the pipes and added a number
  • 00:58:19 counter now I'm going to add a loose
  • 00:58:22 screen so right now when the bird
  • 00:58:25 touches the pipes then the game stops
  • 00:58:27 and that's sort of boring I want the
  • 00:58:31 player to be able to maybe have an
  • 00:58:33 option to restart the game so to do that
  • 00:58:36 let's create a new sprite and I am just
  • 00:58:42 going to create a simple Luo screen
  • 00:58:50 so now I have my loose screen and this
  • 00:58:53 is gonna show up when the game ends so
  • 00:58:56 let's go to the code and I actually want
  • 00:58:59 this to be transparent so um let's just
  • 00:59:03 grab a win flag clicked then let's go to
  • 00:59:06 looks grab this set color effect to zero
  • 00:59:10 and change this to ghosts
  • 00:59:13 and let's change this to maybe 50 okay
  • 00:59:17 maybe less so 20 and all right maybe a
  • 00:59:21 15 actually and now this loose screen is
  • 00:59:25 sort of transparent so now I'm going to
  • 00:59:28 create another sprite and this is going
  • 00:59:32 to be for the retry button
  • 00:59:34 [Music]
  • 00:59:39 all right so now I am done with the
  • 00:59:41 retry button and I also changed the lose
  • 00:59:44 screen by adding a crying bird so yeah
  • 00:59:48 anyways um let's start with the blue
  • 00:59:51 screen or actually oh yeah for the retry
  • 00:59:54 button I want it to be transparent too
  • 00:59:56 so let's also grab a set ghost effect
  • 01:00:02 2:15 let me change that to maybe 25 or
  • 01:00:07 30 all right so let's go to the loo
  • 01:00:11 screen so um we want to first hide this
  • 01:00:15 when the flag is clicked however we want
  • 01:00:18 this to show when the bird loses so
  • 01:00:22 let's go to the bird and right here in
  • 01:00:27 the if touching sprite – or Y position
  • 01:00:29 is less than negative 171 we want to
  • 01:00:33 broadcast a message to tell the loose
  • 01:00:35 screen that the bird lost so let's go to
  • 01:00:38 control or actually uh event and then
  • 01:00:43 broadcast a new message let's just call
  • 01:00:47 this lose and let's put this in the if
  • 01:00:54 touching sprite – or Y position is less
  • 01:00:57 than negative 171 and instead of stop
  • 01:01:01 all let's just stop this script so the
  • 01:01:05 bird would just stop all of this and
  • 01:01:07 stop moving so yeah all right now in our
  • 01:01:11 loose screen we want to grab a when I
  • 01:01:14 receive lose then we want the loose
  • 01:01:16 screen to show so we just grab a show
  • 01:01:19 and this should be good let's also do
  • 01:01:24 the same thing for the retry button so
  • 01:01:27 when I receive lose then show otherwise
  • 01:01:32 when the flag is clicked then hide so
  • 01:01:35 yeah let's try it out right now so when
  • 01:01:38 the bird crashes into the pipe then
  • 01:01:42 there so you lose and we see that the
  • 01:01:45 bird stopped moving
  • 01:01:46 however the pipes are still moving so to
  • 01:01:49 fix that let's just go to the pipes and
  • 01:01:51 then
  • 01:01:53 at a when I received lose then let's
  • 01:01:57 stop all and change this to stop other
  • 01:02:02 scripts in sprite so by doing that it
  • 01:02:05 just stops this block over here and this
  • 01:02:07 block over here so now let's try it
  • 01:02:10 again when the bird Falls let's say then
  • 01:02:13 everything stops
  • 01:02:14 oh yeah except for the background so
  • 01:02:16 let's go to the background and drag a
  • 01:02:20 when I receive lose then stop other
  • 01:02:24 scripts in the sprite all right let's
  • 01:02:26 try now and now as you can see
  • 01:02:29 everything stops now we want the
  • 01:02:31 sweetheart button to actually work
  • 01:02:33 because right now this doesn't do
  • 01:02:35 anything so let's go to the retry button
  • 01:02:37 and then let's see inside of the when I
  • 01:02:43 receive lose we want to drag in a farver
  • 01:02:45 loop and let's drag in if-else statement
  • 01:02:50 and then let's go to sensing let's
  • 01:02:54 detect if mouse is down then let's say
  • 01:02:59 let's make the retry button a bit darker
  • 01:03:02 so let's go to looks and then grab the
  • 01:03:07 set color effect 2-0 drag this inside of
  • 01:03:10 the if Mouse down let's change this to
  • 01:03:12 brightness and let's set this to maybe
  • 01:03:18 negative 10 so this makes it darker
  • 01:03:22 let's try it out oh yeah sorry I meant
  • 01:03:25 if touching mouse pointer not if Mouse
  • 01:03:28 down
  • 01:03:28 so let's actually change that let's go
  • 01:03:31 to sensing grab a touching mouse pointer
  • 01:03:34 and let's replace the mouse down and now
  • 01:03:38 let's try it out so as you can see it's
  • 01:03:41 now darker however if the mouse pointer
  • 01:03:44 is not touching the budget anymore we
  • 01:03:48 want it to go back to its original
  • 01:03:50 brightness so let's go to looks grab the
  • 01:03:54 set brightness Effect 2 and let's change
  • 01:03:59 it back to zero all right now let's try
  • 01:04:02 it out and as you can see there is a bit
  • 01:04:05 of a
  • 01:04:06 but in touching effect all right so now
  • 01:04:09 we want it to detect if the mouse
  • 01:04:12 pointer is down and then we want to
  • 01:04:14 restart the entire game so let's go to
  • 01:04:17 control grab an if statement put this
  • 01:04:21 inside of the if touching mouse pointer
  • 01:04:23 and now we drag the mouse down inside
  • 01:04:27 with the if statement and if the mouse
  • 01:04:30 is down then we want to let's say
  • 01:04:33 broadcast a new message so let's go to
  • 01:04:37 events and broadcast a new message let's
  • 01:04:41 just say play now let's drag this inside
  • 01:04:47 of the if Mouse down let's also stop
  • 01:04:50 this entire script after it broadcasts
  • 01:04:54 play so that it doesn't keep on
  • 01:04:56 broadcasting play so let's just drag a
  • 01:05:00 stop all and change this to solve the
  • 01:05:03 sprite or stop the script so right now
  • 01:05:06 it's not gonna do anything and that's
  • 01:05:09 because we need the sprites to restart
  • 01:05:11 to all of their actions when the play is
  • 01:05:14 broadcasted
  • 01:05:15 so let's first go to the chicken and
  • 01:05:19 instead of the ones I clicked let's
  • 01:05:22 replace that with the when I receive
  • 01:05:25 play like this all right let's do the
  • 01:05:30 same for the pipes so instead of the
  • 01:05:33 ones I clicked we want the winner
  • 01:05:35 receive play then it does all that and
  • 01:05:40 for the background let's replace the win
  • 01:05:43 flag clicked and for the number counter
  • 01:05:50 replace the wind flag clicked and then
  • 01:05:57 for the you lose replace the one for I
  • 01:06:02 clicked and also for the retry button
  • 01:06:10 alright so now that we replaced all of
  • 01:06:13 the wind fly clicked with plays that
  • 01:06:16 means that now all this is replayable
  • 01:06:20 as long as we call the play message then
  • 01:06:23 all of this is going to restart however
  • 01:06:26 when we click the flag we still want to
  • 01:06:30 broadcast play right because we want to
  • 01:06:32 start the game when we click the flag so
  • 01:06:35 yeah I'm just gonna put this inside of
  • 01:06:36 the chicken and now it should work so it
  • 01:06:41 starts the game everything works as
  • 01:06:43 normal until we lose and then we start
  • 01:06:46 and everything restarts however as you
  • 01:06:51 can see there are some problems so let's
  • 01:06:53 go to the pipes and I think the problem
  • 01:06:57 is because the clones don't get deleted
  • 01:07:00 when the lose message is broadcasted so
  • 01:07:04 let's grab a delete this clone after I
  • 01:07:08 receive lose so all of the clones from
  • 01:07:10 the previous game should get deleted now
  • 01:07:13 let's try it again so when the bird
  • 01:07:16 crashes to the pipe and then restarts
  • 01:07:19 then it works all right cool and one
  • 01:07:23 thing for the number counter it's
  • 01:07:27 actually better to probably add a win
  • 01:07:29 flag clicked then do all this stuff
  • 01:07:33 because we only need to do this once
  • 01:07:36 when the green flag is clicked so yeah
  • 01:07:39 now this should be good so oh yeah since
  • 01:07:45 there's also a clone for the background
  • 01:07:47 to make sure there aren't any extra
  • 01:07:50 clones on the screen when I restart then
  • 01:07:53 we want to delete the clone so yeah now
  • 01:08:01 I think this should be good oh yeah okay
  • 01:08:05 I forgot to stop other scripts in this
  • 01:08:07 sprite for the number counter so let's
  • 01:08:10 just do that just in case so when I
  • 01:08:13 receive lose then stop other scripts in
  • 01:08:17 this sprite all right and we don't want
  • 01:08:20 to delete these clones because we're
  • 01:08:22 only creating them once when the flag is
  • 01:08:24 clicked so yeah now let's try it again
  • 01:08:28 so everything works as normal then when
  • 01:08:32 we lose
  • 01:08:33 then there's a loose screen and then if
  • 01:08:35 we retry then everything works as normal
  • 01:08:40 oops okay except for the number counter
  • 01:08:43 so let's see okay actually let me just
  • 01:08:48 still add a delete this clone after
  • 01:08:50 loose and then let's replace the ones I
  • 01:08:54 clicked with when I receive play all
  • 01:09:00 right now I think this should work let's
  • 01:09:03 try it out so everything works as normal
  • 01:09:07 then we retry and it works all right
  • 01:09:13 cool
  • 01:09:14 so now we have a replayable game and
  • 01:09:21 okay what happened here that's weird oh
  • 01:09:24 yeah that was because my mouse pointer
  • 01:09:26 was on the retry button so yeah but yeah
  • 01:09:33 this works alright let's see and you
  • 01:09:42 lose and then we try and then it
  • 01:09:45 restarts all right cool
  • 01:09:52 this is part 4 on how to make a flappy
  • 01:09:54 bird game in scratch in this tutorial I
  • 01:09:57 will be making some improvements to the
  • 01:09:58 loose screen adding a countdown text and
  • 01:10:01 adding a menu screen so first off our
  • 01:10:04 clones of the pipe and the hills don't
  • 01:10:07 show up when the game is over and that's
  • 01:10:10 because we delete the clones when the
  • 01:10:12 game is over since we don't want the
  • 01:10:14 clones to reappear when the game
  • 01:10:15 restarts however we still want them to
  • 01:10:18 show when the ulugh screen pops up but
  • 01:10:21 we can't really put the delete this
  • 01:10:23 clone after the when I receive play
  • 01:10:26 because it wouldn't really work so let's
  • 01:10:29 just say for the pipes for example I
  • 01:10:31 moved the jelly disk loan from the when
  • 01:10:34 they received lose to when I receive
  • 01:10:36 play then if you try it then we lose and
  • 01:10:41 then restart then there's these clones
  • 01:10:44 of these pipes and this still doesn't
  • 01:10:46 work so to fix this we need to broadcast
  • 01:10:49 a message after the win and receive lose
  • 01:10:52 but before the when I receive play and
  • 01:10:55 this way we can safely delete our clones
  • 01:10:58 in between the losing and the play so
  • 01:11:01 I'm going to first put this back and
  • 01:11:04 alright this also ties in perfectly with
  • 01:11:07 making the countdown text because the
  • 01:11:10 countdown is going to happen after the
  • 01:11:13 you lose but before the game starts so
  • 01:11:16 what I was thinking for the countdown is
  • 01:11:18 that when the game starts it's going to
  • 01:11:20 show up like a 3 2 1 start and then the
  • 01:11:23 game's gonna actually start like this so
  • 01:11:25 when the countdown is happening the
  • 01:11:27 games gonna actually be paused but yeah
  • 01:11:30 so let's make the countdown text let's
  • 01:11:34 first create a new sprite and I'm just
  • 01:11:37 gonna type in the number 3 alright I'll
  • 01:11:44 make this a bit larger like this and
  • 01:11:47 then I'll duplicate this I'll type in to
  • 01:11:51 do create this again type in 1 and then
  • 01:11:55 duplicate this is again then I'll type
  • 01:11:58 go then I'll make sure to Center this in
  • 01:12:04 the middle
  • 01:12:05 all right so on the screen over here
  • 01:12:08 it's gonna be three two one go so this
  • 01:12:12 is gonna be our countdown text all right
  • 01:12:15 so currently when the green flag is
  • 01:12:17 clicked we broadcast play however we
  • 01:12:21 don't want to do that because we want to
  • 01:12:23 broadcast our countdown text to start
  • 01:12:25 instead so let's create a new message
  • 01:12:28 and I'll just call this start countdown
  • 01:12:33 all right
  • 01:12:34 click OK and then when the green flag is
  • 01:12:37 clicked we want to actually broadcast
  • 01:12:39 start countdown so let's go to our
  • 01:12:42 countdown sprite in their countdown
  • 01:12:45 sprite we want to receive the start
  • 01:12:48 countdown and then when it receives it
  • 01:12:51 we want to first show it and then let's
  • 01:12:57 go to motion make sure it goes to X Y
  • 01:13:00 zero zero so it's in the center like
  • 01:13:03 this and then we want to go to looks and
  • 01:13:08 then switch costume to costume 1 which
  • 01:13:10 is the number 3 and then go to control
  • 01:13:15 let's wait maybe 0.5 seconds and then
  • 01:13:20 let's actually duplicate this switch
  • 01:13:23 costume and wait so duplicate this and
  • 01:13:27 then put it under then we want to switch
  • 01:13:31 costume to costume 2 which is the number
  • 01:13:34 2 and then weigh 0.5 seconds and then
  • 01:13:38 duplicate this again switch costume to
  • 01:13:41 costume 1 or actually 3 sorry and then
  • 01:13:45 switch costume to costume 4 which is the
  • 01:13:49 go so it's gonna be like this 3 2 1 go
  • 01:13:53 and then at the end we actually want to
  • 01:13:55 hide this so go to looks and then hide
  • 01:13:59 it so it's like this 3 2 1 go and then
  • 01:14:03 hide all right so if we try it right now
  • 01:14:06 then we have our countdown but we
  • 01:14:09 actually want the countdown to start the
  • 01:14:12 game after it's finished so at the end
  • 01:14:14 over here let's go to events and then
  • 01:14:18 broadcast
  • 01:14:19 play after it finished counting down so
  • 01:14:23 let's try it again three two one go and
  • 01:14:27 then the game starts alright cool
  • 01:14:30 however we still want the game to
  • 01:14:32 initialize when the green flag is
  • 01:14:34 clicked because right now there's like
  • 01:14:36 nothing right and then when the game
  • 01:14:38 starts then everything is put into place
  • 01:14:40 but we want everything to be ready when
  • 01:14:43 the countdown is counting down like this
  • 01:14:45 so to do that it's actually pretty easy
  • 01:14:47 we have to just go to every sprite and
  • 01:14:49 then make sure it's in the correct place
  • 01:14:52 when it receives the countdown message
  • 01:14:54 so for example in the chicken we want it
  • 01:14:57 to set it's change in Y to zero so
  • 01:15:00 that's not moving and then go to this
  • 01:15:03 position and then set size to eighty and
  • 01:15:05 that's going to be under when I receive
  • 01:15:08 start tamp down so just change that and
  • 01:15:11 then for the rest of the actual moving
  • 01:15:14 script let's just drag a when I receive
  • 01:15:16 play so by doing this the chickens
  • 01:15:20 actually in its starting position when
  • 01:15:23 the countdown happens like this all
  • 01:15:26 right cool so now time to do the pipes
  • 01:15:29 so let's see I think for the pipes it's
  • 01:15:35 fine
  • 01:15:36 because when the countdown is happening
  • 01:15:37 we don't want any pipes of spawn so the
  • 01:15:40 pipes are okay but let's see the hills
  • 01:15:43 so of course when it receives the
  • 01:15:46 countdown we want the hill to be in the
  • 01:15:50 middle so go to zero zero and then go
  • 01:15:54 backwards ten layers so in the very back
  • 01:15:56 and I think this is fine and then we can
  • 01:16:01 just drag this back inside of the win
  • 01:16:03 and receive play and let's see how it
  • 01:16:06 looks so the hills in the correct
  • 01:16:09 position alright and now I think the
  • 01:16:13 only thing missing is the number counter
  • 01:16:15 or the score counter so let's go to the
  • 01:16:18 score counter and let's see let's change
  • 01:16:23 the win and receive plate two when they
  • 01:16:25 receive start countdown so pretty much
  • 01:16:28 the score counter creates all of its
  • 01:16:30 clones and then the clones show and
  • 01:16:31 stuff like that
  • 01:16:32 when the score starts counting down or
  • 01:16:35 the count down sprite starts counting
  • 01:16:36 down sorry
  • 01:16:37 so yeah let's try it out now oh yeah and
  • 01:16:41 we also need to hide our you lose screen
  • 01:16:44 and retry button when the countdown
  • 01:16:46 starts so let's go to our you lose
  • 01:16:48 sprite and change the play to start
  • 01:16:53 countdown and do the same thing for a
  • 01:16:55 retry button change the win and receive
  • 01:16:58 play – when I receive start countdown
  • 01:17:01 alright let's try to get now there's the
  • 01:17:04 countdown and then the game starts
  • 01:17:06 alright cool
  • 01:17:08 let's try it again there's the countdown
  • 01:17:11 and then the game starts alright so the
  • 01:17:16 countdown now works when the green flag
  • 01:17:19 is clicked however the countdown does
  • 01:17:21 not work yet when the retied button is
  • 01:17:23 clicked and that is because for the
  • 01:17:26 retry button when the button is clicked
  • 01:17:28 it broadcasts play but we need to change
  • 01:17:31 that to count down or start countdown so
  • 01:17:34 when the mouse is down then broadcast
  • 01:17:37 start countdown alright let's try it
  • 01:17:39 again
  • 01:17:40 so countdown and then let's just say we
  • 01:17:43 lose the game then we try and then
  • 01:17:46 there's the countdown alright cool so we
  • 01:17:48 added the countdown and the countdown
  • 01:17:52 seems to work alright but however we
  • 01:17:55 still need to fix the problem with the
  • 01:17:57 loose screen because the clones are
  • 01:17:59 disappearing so to prevent the clones
  • 01:18:01 from deleting when the loose screen
  • 01:18:03 starts up
  • 01:18:03 let's move the delete this clone into
  • 01:18:06 the when I receive start countdown not
  • 01:18:09 after when I receive loose so let's
  • 01:18:12 first go to our pipes and then where it
  • 01:18:16 says delete this clone inside of the
  • 01:18:18 when I receive loose let's change this
  • 01:18:20 to when I receive start countdown and
  • 01:18:24 then delete this clone and the same
  • 01:18:27 thing for the hills so instead of the
  • 01:18:31 delete this clone inside of the winner
  • 01:18:33 received loose we drag a rash in here
  • 01:18:37 when I receive start countdown then
  • 01:18:39 delete this clone alright let's try it
  • 01:18:42 now so there's a countdown
  • 01:18:45 then let's lose the game and now as you
  • 01:18:48 can see the pipes show up and the hill
  • 01:18:50 shows up and for some reason our retry
  • 01:18:53 button is in the back over here so I'm
  • 01:18:56 just going to make it go to the front
  • 01:18:59 layer when the lose is received all
  • 01:19:05 right let's try it again count down and
  • 01:19:08 then lose this game and then there we go
  • 01:19:11 now we have a fully functioning loo
  • 01:19:13 screen cool so I'm just try it out it's
  • 01:19:18 like this and then when the game is lost
  • 01:19:21 then essentially everything pauses and
  • 01:19:24 it's all good all right so now I sort of
  • 01:19:27 wanted to add a bird knock-back
  • 01:19:29 animation when the game loses for
  • 01:19:32 example when the bird crashes into the
  • 01:19:34 pipe the bird sort of jumps backwards
  • 01:19:36 like that so I'm going to add that let's
  • 01:19:39 go to the bird sprite and then since we
  • 01:19:43 want the bird to do its animation when
  • 01:19:46 the game is lost let's grab a when I
  • 01:19:48 receive lose then let's make the bird
  • 01:19:53 sort of jump so we want to of course
  • 01:19:56 change the or actually set the change in
  • 01:20:00 Y to let's say 7 now we want to go to
  • 01:20:06 control and then grab a repeat until
  • 01:20:08 block put it after the change in Y to 7
  • 01:20:12 and then let's repeat until the bird is
  • 01:20:16 lower than the bottom edge of the screen
  • 01:20:18 so our P until the Y position is less
  • 01:20:23 than what is it I think I have it over
  • 01:20:26 here
  • 01:20:26 oh yeah negative 171 all right
  • 01:20:31 drag this inside of the repeat until and
  • 01:20:35 then after the bird is lower than
  • 01:20:38 negative 171 in the Y position then it's
  • 01:20:41 going to hide so Jack B hide after the
  • 01:20:43 repeat until and then while it's still
  • 01:20:47 greater than negative 171 then we want
  • 01:20:50 it to just duplicate this so change Y by
  • 01:20:54 changing Y drag inside of the repeat
  • 01:20:58 until
  • 01:20:59 and then we want to also make sure the
  • 01:21:02 change in Y is decreasing so also copy
  • 01:21:05 this one change change in Y by negative
  • 01:21:08 0.8 and then drag this inside of there
  • 01:21:12 repeat until all right so let's try it
  • 01:21:15 out so when the bird crashes into the
  • 01:21:18 pipe then it sort of jumps like that all
  • 01:21:23 right I think I'm gonna make the bird
  • 01:21:24 also go backwards a bit so let's go to
  • 01:21:28 motion and that drag a change X by let's
  • 01:21:33 say negative 1 that's dragon in there
  • 01:21:38 and let's try it out
  • 01:21:40 oops okay and our bird is hidden that is
  • 01:21:43 because I hit it over here but then I do
  • 01:21:47 not show it again when the game starts
  • 01:21:49 so let's go to looks and then grab a
  • 01:21:51 show drag it after the when I receive
  • 01:21:55 start countdown all right let's try it
  • 01:21:57 again there's the bird when it hits the
  • 01:22:01 pipe then it does that all right cool
  • 01:22:05 let's see it again the bird when it hits
  • 01:22:11 the pipe let's say here it sort of jumps
  • 01:22:13 backwards all right and I'm also going
  • 01:22:16 to make sure that the bird points in
  • 01:22:19 direction of 90 degrees when the game
  • 01:22:21 starts all right and I think it works so
  • 01:22:29 let's see oh yeah I realized that the
  • 01:22:32 score does not reset until the start
  • 01:22:35 countdown finishes but we want the score
  • 01:22:37 to reset when you start countdown begins
  • 01:22:39 so let's see where the score is set over
  • 01:22:42 right here all right and let's actually
  • 01:22:45 set the score when I receive start
  • 01:22:49 countdown all right now the score resets
  • 01:22:52 to zero when the start countdown begins
  • 01:22:54 and it should be fine all right cool
  • 01:22:58 like this okay
  • 01:23:04 and now I sort of remember seeing some
  • 01:23:08 bugs when I was play testing this game
  • 01:23:10 so let me just try to find them
  • 01:23:13 let's see oh yeah right there
  • 01:23:21 when you press retry before the bird is
  • 01:23:24 finished falling it sort of doesn't work
  • 01:23:27 like that because the bird is still
  • 01:23:28 falling so let's go to our bird and
  • 01:23:32 let's see it stops all other scripts in
  • 01:23:37 the sprite so let's put it before
  • 01:23:39 everything over here and that is because
  • 01:23:41 when the game restarts while the bird is
  • 01:23:44 still falling then the bird is going to
  • 01:23:47 keep on falling so we need to make sure
  • 01:23:49 that we stop the falling bird sprite or
  • 01:23:51 script and then it should work all right
  • 01:23:54 let's try it again so when the bird is
  • 01:23:58 falling and then it clicked we try then
  • 01:24:01 it works let's see I remember seeing
  • 01:24:07 something else that was a problem I
  • 01:24:09 think it was the pipes so let's see okay
  • 01:24:22 I don't see anything right now
  • 01:24:34 okay that's a problem so I think when
  • 01:24:37 you press me try right after the bird
  • 01:24:39 dies then it doesn't work so let's try
  • 01:24:42 it
  • 01:24:43 oops okay it's right here so I'm just
  • 01:24:46 gonna spam click this and then yeah the
  • 01:24:50 game doesn't really work so let's see
  • 01:24:52 how I can fix this
  • 01:24:55 hmm let's see it again
  • 01:24:59 all right so that just stops working so
  • 01:25:05 I think the best way to fix this is to
  • 01:25:08 just go to the retry button and then
  • 01:25:12 adding a wait let's say 0.1 seconds
  • 01:25:16 before it runs the code about the
  • 01:25:20 touching the mouse pointer and stuff
  • 01:25:21 like that so I think they should fix it
  • 01:25:24 I'm gonna try it again alright that
  • 01:25:30 fixes it so when I click it super
  • 01:25:32 rapidly there's no more weird pipe
  • 01:25:36 issues so that's fine
  • 01:25:39 alright cool so I think I fixed all of
  • 01:25:42 the bugs for now now I'm going to create
  • 01:25:46 a simple menu screen so first of all I
  • 01:25:49 need to create a menu button so let's
  • 01:25:51 just duplicate this retry button and
  • 01:25:56 then let's go to costumes and I'm gonna
  • 01:26:01 change this to menu and yeah that should
  • 01:26:05 be fun
  • 01:26:06 alright so now I'm going to position
  • 01:26:09 this downwards a bit maybe right here
  • 01:26:18 alright so I'm just gonna drag this go
  • 01:26:22 to X Y let's say after the when I
  • 01:26:26 receive lose and fourthly you retry
  • 01:26:29 button I'm gonna do the same so go to 0
  • 01:26:34 0 alright so now I have the retry and
  • 01:26:39 menu button so when I click the menu
  • 01:26:42 button I want it to broadcast a new
  • 01:26:45 message and let's just name this menu
  • 01:26:49 when we click the menu button you want
  • 01:26:51 it to actually go to the menu so let's
  • 01:26:55 go to stage and then I'm going to create
  • 01:26:58 a new backdrop and this is gonna be my
  • 01:27:04 menu backdrop and for now I'm just gonna
  • 01:27:07 create a rectangle that's the color
  • 01:27:11 white or actually a light blue works too
  • 01:27:16 so like this all right bit wider okay
  • 01:27:26 and then I'm just gonna add some text
  • 01:27:30 saying menu and this should be fine for
  • 01:27:40 now alright so now in our stage we want
  • 01:27:46 to make sure that when it receives menu
  • 01:27:49 so an event when I receive menu then we
  • 01:27:53 want to switch backdrop to backdrop –
  • 01:27:56 which is the menu backdrop and then when
  • 01:28:00 I receive start countdown which is the
  • 01:28:06 game starting with the countdown text
  • 01:28:08 then we want to switch backdrop to
  • 01:28:10 backdrop 1 which is our game background
  • 01:28:13 so yeah right now it should work with
  • 01:28:16 just the background change alright and
  • 01:28:21 then menu and like that the menu changes
  • 01:28:24 however if we go to the menu we want
  • 01:28:27 everything else to disappear so let's go
  • 01:28:30 to the sprites one by one and then make
  • 01:28:32 sure the high when they receive menu so
  • 01:28:35 let's first go to the bird alright so
  • 01:28:39 let's go to events when I receive menu
  • 01:28:44 then we want to hide and then go to
  • 01:28:49 control Raschi events or sorry control
  • 01:28:52 and then stop other scripts in sprite
  • 01:28:56 alright so this ensures that nothing
  • 01:28:59 else in the chicken sprite is going to
  • 01:29:01 run
  • 01:29:02 and that should be fine now let's drag
  • 01:29:05 this into also our pipe sprite and let's
  • 01:29:11 add a delete this clone at the end to
  • 01:29:14 make sure all the clones are gone and
  • 01:29:16 then drag this into our Hill sprite
  • 01:29:20 alright drag this into our number
  • 01:29:23 counter sprite also our loose screen
  • 01:29:28 however we don't need this delete this
  • 01:29:31 clone since there are no clones in this
  • 01:29:33 blue screen and we also don't need this
  • 01:29:37 stop other scripts in sprite since there
  • 01:29:40 are no loops in here so it's fine and
  • 01:29:43 let's go to let's say our number counter
  • 01:29:47 and then drag this into our retry button
  • 01:29:49 sprite let's take out the delete this
  • 01:29:53 clone because there are no clones in
  • 01:29:54 this sprite and I think there should be
  • 01:29:59 fine oh yeah also the menu button
  • 01:30:02 alright and it should be good let's try
  • 01:30:06 it out countdown and then lose the game
  • 01:30:09 then menu oh yeah this is another bug
  • 01:30:12 when you lose the game right win a pipe
  • 01:30:15 is spawned then the pipe still moves
  • 01:30:19 because the stock other scripts in
  • 01:30:22 sprite is called right before the pipe
  • 01:30:25 starts moving so yeah I am going to fix
  • 01:30:30 this in the next part of the series
  • 01:30:31 though but anyways let's go back to
  • 01:30:34 looking at the menu so let's try it
  • 01:30:37 again when the bird loses then menu then
  • 01:30:42 as you can see everything hides and we
  • 01:30:44 are at the menu so now on the menu
  • 01:30:46 screen we want a play button so to do
  • 01:30:49 that let's just copy the menu button and
  • 01:30:52 that's go to costumes change this to
  • 01:30:56 play or actually start and then let's go
  • 01:31:03 to the code and let's see in the window
  • 01:31:07 receive menu we want the button to show
  • 01:31:10 and actually do all this stuff
  • 01:31:14 so we
  • 01:31:15 take this out and then change the loose
  • 01:31:18 to menu and this should be fine and then
  • 01:31:22 when the mouse is down we want a start
  • 01:31:25 button to broadcast play or actually
  • 01:31:28 start countdown and then that should be
  • 01:31:31 fine let's see alright and when I
  • 01:31:36 receive start countdown we want the
  • 01:31:38 start button to hide and also to stop
  • 01:31:45 other scripts in the sprite oh actually
  • 01:31:49 oh we already have it here so it's fine
  • 01:31:51 yep that's good and I think we should be
  • 01:31:55 good so let's try it out
  • 01:31:59 oops okay everything is gone or actually
  • 01:32:02 the hills and that's because I need to
  • 01:32:05 make sure I show the hills when the
  • 01:32:09 start countdown is received like that
  • 01:32:12 alright let's try it out
  • 01:32:14 okay then when the bird crashed the pipe
  • 01:32:19 and then menu then there's our start
  • 01:32:23 button alright and then when we press
  • 01:32:25 Start then there is our countdown okay
  • 01:32:29 everything seems normal and everything
  • 01:32:34 seems to work now I'm just going to
  • 01:32:36 reposition the start button to maybe the
  • 01:32:39 middle over here so right here
  • 01:32:43 that is why position 23 all right and
  • 01:32:50 there should be good menu and then menu
  • 01:32:55 alright now since we have a menu when
  • 01:32:59 the green flag is clicked we don't want
  • 01:33:01 it to start the game but we want it to
  • 01:33:03 go to the menu so instead of
  • 01:33:05 broadcasting start countdown we wanted
  • 01:33:07 to broadcast menu and now it should be
  • 01:33:11 fine
  • 01:33:12 so when the green flag is clicked it
  • 01:33:14 shows the menu and then we can start
  • 01:33:17 alright and our game works like normal
  • 01:33:21 and then when the bird crashes it shows
  • 01:33:26 the animation
  • 01:33:27 and then we can retry and we can also go
  • 01:33:32 to the menu alright so there we have it
  • 01:33:35 we have our basic menu we have a working
  • 01:33:38 retry button and LU screen and we also
  • 01:33:41 added some countdown text
  • 01:33:46 this is part 5
  • 01:33:48 how to make a flappy bird game in
  • 01:33:50 scratch and in this video I am going to
  • 01:33:52 make the menu look better add some
  • 01:33:54 sound-effects fix some bugs and we
  • 01:33:56 explain all the code in the project
  • 01:33:58 anyways let's get started so the first
  • 01:34:01 thing I want to fix before I do anything
  • 01:34:03 else is that I forgot to make it so that
  • 01:34:05 you can't hold the mouse button because
  • 01:34:08 right now when you hold the mouse button
  • 01:34:10 the bird sort of floats up and we don't
  • 01:34:14 want that because we only want the bird
  • 01:34:16 to jump once when you tap the button and
  • 01:34:19 if you hold the button the bird still
  • 01:34:21 only jumps once so that's what we want
  • 01:34:23 so to do that we just actually have to
  • 01:34:25 go to control and then grab a wait until
  • 01:34:29 block go to operators grab a knot and
  • 01:34:32 then go to sensing and then grab a mouse
  • 01:34:37 down and let's drag this after the set
  • 01:34:40 change in Y and point in direction
  • 01:34:42 inside of the if Mouse down and now what
  • 01:34:45 this does is that after you hold the
  • 01:34:48 mouse button down it runs the set
  • 01:34:50 changed Y and point in direction and
  • 01:34:52 then you have to release the mouse
  • 01:34:54 pointer before running this again so now
  • 01:34:57 this prevents the player from holding
  • 01:34:59 down the mouse button however we can't
  • 01:35:01 put this if Mouse down inside of this
  • 01:35:03 forever loop anymore because while it's
  • 01:35:05 waiting for knob Mouse down then nothing
  • 01:35:08 else would run so we want to separate
  • 01:35:10 this if Mouse down from the forever loop
  • 01:35:12 and then let's just go to events grab a
  • 01:35:17 separate when I receive play and then
  • 01:35:20 grab a forever loop from the control and
  • 01:35:22 then drag this if Mouse down stuff
  • 01:35:25 inside of the forever loop all right now
  • 01:35:29 let's try it out
  • 01:35:31 all right and then if I try holding then
  • 01:35:36 the bird still jumps like normal let me
  • 01:35:39 try it again like this if I hold then
  • 01:35:44 the bird still only jumps once all right
  • 01:35:47 cool so we fix that problem and
  • 01:35:51 something else that may happen when you
  • 01:35:54 play the game is that when you lose the
  • 01:35:56 game right when another clone of the
  • 01:35:59 pipe spawns the cloned pipe keeps
  • 01:36:02 moving normally across the screen
  • 01:36:03 instead of freezing so let's go to the
  • 01:36:07 pipes to see what's wrong
  • 01:36:11 let's see what can we fix in here okay
  • 01:36:16 let me first try to recreate the bug so
  • 01:36:19 I have to crash into the pipe right when
  • 01:36:22 a new pipe spawns okay that was a bit
  • 01:36:25 too late let me try it again
  • 01:36:29 okay a bit too early now let me see
  • 01:36:36 okay still a bit too early okay a bit
  • 01:36:44 too late now all right so I managed to
  • 01:36:51 get the bug and as you can see the newly
  • 01:36:55 spawned pipe keeps scrolling through the
  • 01:36:57 screen and we don't want that so let's
  • 01:36:59 go to our pipes now and I think what
  • 01:37:03 happens is that the pipe creates a clone
  • 01:37:09 at the exact same time that the bird
  • 01:37:12 loses and then it's supposed to stop all
  • 01:37:15 other scripts in this bite but it
  • 01:37:17 doesn't stop the Krait clone of myself
  • 01:37:20 because it's the exact same time and
  • 01:37:22 then that ends up the newly created
  • 01:37:25 clone not stopping all of its scripts
  • 01:37:27 and then keep on going so that's the
  • 01:37:31 problem I think so to fix that we have
  • 01:37:34 to create a new variable and then I'll
  • 01:37:38 just call this lost and then yep click
  • 01:37:46 OK and when the flag is clicked or
  • 01:37:52 actually when I receive a play or
  • 01:37:59 actually start countdown let's set lost
  • 01:38:02 to no and then once the bird crashes
  • 01:38:07 into the pipe then we want to set lost
  • 01:38:10 to yes so let's go to the bird
  • 01:38:15 and then right here in the if touching
  • 01:38:18 sprite to which is the pipe then we want
  • 01:38:21 to set lost to yes and then do all this
  • 01:38:26 all right now let's go back to our pipe
  • 01:38:29 and in the clone over pipe we want to
  • 01:38:33 make sure that the pipe only moves if
  • 01:38:35 lost is equal to no otherwise we want
  • 01:38:38 the pipe to pause so let's go to control
  • 01:38:41 grab an if statement and then go to
  • 01:38:44 operators we have an equals and then go
  • 01:38:47 to variables grab a lost and then check
  • 01:38:50 if lost is equal to no then do all of
  • 01:38:54 this stuff inside of the repeat until
  • 01:38:57 oops I'm gonna make sure that I also get
  • 01:38:59 the set size to 150 percent in there all
  • 01:39:04 right so let's try it out I'm gonna try
  • 01:39:08 to make sure that bird loses right when
  • 01:39:10 the pipe spawns to see if the problem is
  • 01:39:11 fixed all right I'm gonna go to a
  • 01:39:15 project view so it's a bit easier and
  • 01:39:17 let's try it so let me make sure that
  • 01:39:22 the pipe just spawns okay that was a bit
  • 01:39:25 too late I think okay but too early now
  • 01:39:35 okay a bit too early again I think I
  • 01:39:39 need to be like one frame later okay
  • 01:39:42 that's too late okay so I can't recreate
  • 01:39:49 the exact problem that we used to have
  • 01:39:51 but I'm pretty sure the problem is fixed
  • 01:39:53 so let's go back inside it of the
  • 01:39:56 project and okay hmm let me first
  • 01:40:00 reposition the you loose screen I think
  • 01:40:03 it accidentally dragged it so I'll just
  • 01:40:05 drag it go to zero zero after the when I
  • 01:40:09 received lose all right and now that I
  • 01:40:14 think all of the bugs are fixed I'm
  • 01:40:16 going to create a better looking menu
  • 01:40:21 [Music]
  • 01:40:32 all right so I am done with the menu and
  • 01:40:36 I separated the title into a new sprite
  • 01:40:40 so instead of putting it inside of the
  • 01:40:43 backdrop I made it its own separate
  • 01:40:45 sprite and that's because I want the
  • 01:40:47 title to maybe move around a bit so yeah
  • 01:40:50 and I also added some sun rays and I
  • 01:40:55 made these a separate sprite also
  • 01:40:57 because I'm gonna add some ghost effect
  • 01:40:59 because I want the Rays to be
  • 01:41:01 transparent so yeah anyways I made the
  • 01:41:04 button look a bit better and added some
  • 01:41:07 hills in the background and yeah
  • 01:41:09 alright so I'm gonna first go to the
  • 01:41:11 Sunbeam sprite and then I'm going to go
  • 01:41:15 to a control or actually events and then
  • 01:41:17 drag a when I receive menu then I'm
  • 01:41:21 gonna go to looks and then I'm going to
  • 01:41:24 set the ghost effect to maybe let's try
  • 01:41:28 50 all right um let's try 40 maybe 30
  • 01:41:37 and I like 40 better all right and then
  • 01:41:40 I'm also gonna make them go to the back
  • 01:41:44 so go to back layer alright and I think
  • 01:41:49 they look better
  • 01:41:50 and now for the title I am also going to
  • 01:41:54 drag a when I receive menu then I think
  • 01:42:00 I'm gonna make the title go up and down
  • 01:42:02 by a tiny bit so I'm going to my guess
  • 01:42:07 grab a repeat and then I'm going to
  • 01:42:10 repeat maybe 10 times and I'm going to
  • 01:42:14 change Y by let's say 0.5 and then I'm
  • 01:42:22 going to duplicate this and then change
  • 01:42:25 Y by negative 0.5 and let's see how this
  • 01:42:29 looks
  • 01:42:30 alright so it goes up and down like that
  • 01:42:34 okay so I think we can repeat this so
  • 01:42:38 let's go to control and then grab a for
  • 01:42:40 loop and put this around the two repeats
  • 01:42:44 in the sea and it jumps up and down like
  • 01:42:48 that all right
  • 01:42:50 also I'm going to grab a win I receive
  • 01:42:56 start town town then I am going to hide
  • 01:43:03 the sprite and then stop all other
  • 01:43:06 scripts in the sprite so in control and
  • 01:43:09 then stop other scripts in sprite and
  • 01:43:13 also for my sunbeams I'm gonna do the
  • 01:43:17 same thing so when I receive start
  • 01:43:19 countdown then hide and we don't need
  • 01:43:24 the stop other scripts in the sprite
  • 01:43:26 because there are no loops in here so
  • 01:43:28 we're fine all right let's see
  • 01:43:31 and okay our title is gone and we have
  • 01:43:35 to reshow it so let's drag a show after
  • 01:43:38 the when I received menu and also a show
  • 01:43:42 for the sunbeams and that should be good
  • 01:43:46 all right let's try it out so there's
  • 01:43:49 the bouncing title and when we press
  • 01:43:52 Start then the game starts as normal
  • 01:43:55 all right cool so I think this is going
  • 01:44:01 to be our title screen now and let's see
  • 01:44:06 okay and now I'm going to make some
  • 01:44:09 changes to the you lose screen
  • 01:44:14 [Music]
  • 01:44:23 all right so this is going to be our you
  • 01:44:26 loose screen and for the retry and many
  • 01:44:29 buttons I am going to take out the ghost
  • 01:44:32 effect so I'm going to set it back to
  • 01:44:34 zero so it's fully visible all right and
  • 01:44:38 that should look better okay so now we
  • 01:44:43 have our updated loose screen so let's
  • 01:44:47 see it again and our loose screen right
  • 01:44:53 here and lastly I am going to now add
  • 01:44:57 some sound effects so let's see of
  • 01:45:00 course we want a flapping sound effect
  • 01:45:02 for our bird so let's go to our bird and
  • 01:45:05 then let's go to sounds and now let's
  • 01:45:08 create a new sound we can actually
  • 01:45:11 choose a sound so the scratch 2.0 editor
  • 01:45:14 has a great selection of sounds you can
  • 01:45:16 choose from like all these so I'm gonna
  • 01:45:19 try to find some maybe flapping sound
  • 01:45:22 let me search it up flap
  • 01:45:24 okay nothing let me go to effects
  • 01:45:27 alright so low whoosh sounds pretty good
  • 01:45:31 it sounds like this so let's select this
  • 01:45:36 and I'm going to first trim this so
  • 01:45:40 let's click this trim tool over here and
  • 01:45:42 I'm just going to trim this much of it
  • 01:45:45 and then click Save and now let's see I
  • 01:45:51 might make it slower
  • 01:45:54 okay bit slower okay I think that's fine
  • 01:46:01 for now so let's go back to our code and
  • 01:46:04 to add the sound it's really easy all we
  • 01:46:07 need to do is in our if Mouse down we
  • 01:46:11 just want to go to sound and then add a
  • 01:46:14 play sound low whoosh so let's put this
  • 01:46:17 right after and that should be fine so
  • 01:46:20 let's try it out now when the bird flaps
  • 01:46:25 there's the low whoosh sound all right
  • 01:46:31 cool so I think that sounds pretty good
  • 01:46:34 and oh yeah we don't want the sound to
  • 01:46:37 play when we're selecting a button
  • 01:46:39 though like if we click retry then the
  • 01:46:45 sound still plays and we don't want that
  • 01:46:47 so let's see I think in our when I
  • 01:46:55 receive lose we can go to control and
  • 01:46:59 then grab a stop other scripts in the
  • 01:47:03 sprite and let's put it right after it
  • 01:47:05 receives lose so this is where the bird
  • 01:47:08 sort of jumps back when it like hits a
  • 01:47:11 pipe or something so yeah now let's try
  • 01:47:14 it out okay and then when the lose is
  • 01:47:20 there is no more sound and all right it
  • 01:47:24 works
  • 01:47:26 so our flapping sound works for the bird
  • 01:47:29 oops and that should be fine all right
  • 01:47:33 so I think I also want a button sound so
  • 01:47:37 when we hover over it there's the sort
  • 01:47:39 of button click sound effect or
  • 01:47:41 something like that so let's see let's
  • 01:47:44 go to sounds again and let's try to find
  • 01:47:48 the sound all right so I found a good
  • 01:47:50 sound
  • 01:47:51 it's called would tap sounds like this
  • 01:47:56 so I think this is gonna be when we
  • 01:47:59 hover over the button let's see I might
  • 01:48:03 make it slower
  • 01:48:09 actually this was fine so yeah
  • 01:48:12 let's leave it like that okay this is
  • 01:48:13 fine now let's go back to the code and
  • 01:48:17 in all of our buttons we want to add
  • 01:48:20 that would tap sound and okay I think it
  • 01:48:23 accidentally added that to the loose
  • 01:48:25 screen
  • 01:48:26 so oops but we can just drop this sound
  • 01:48:28 into our buttons like that so let's do
  • 01:48:32 that and in our buttons
  • 01:48:36 we can now add this when it's touching
  • 01:48:39 the mouse pointer so let's go to sound
  • 01:48:42 and then add the start sound would tap
  • 01:48:47 let's place this after the if touching
  • 01:48:50 mouse pointer or actually let's not do
  • 01:48:53 that because it won't work because sense
  • 01:48:55 this if statement is constantly checking
  • 01:48:58 if it's touching the mouse pointer the
  • 01:48:59 sound would constantly play so we don't
  • 01:49:02 want that we only want the sound to play
  • 01:49:04 once when the mouse enters the button
  • 01:49:06 area so let's grab a separate event when
  • 01:49:10 I receive lose and then let's grab a
  • 01:49:14 forever loop and we can just grab an if
  • 01:49:18 statement and then check if it's
  • 01:49:21 touching the mouse pointer then we want
  • 01:49:24 to start the sound would tap and then
  • 01:49:27 let's go to control and wait until it's
  • 01:49:31 not touching the mouse pointer and now
  • 01:49:36 that should be fine so this ensures that
  • 01:49:37 the sound only plays once when the mouse
  • 01:49:39 pointer enters so let's try it out that
  • 01:49:43 is for the retry button so let's go to
  • 01:49:45 the retry button and then as you can see
  • 01:49:51 the button sound plays all right so
  • 01:49:59 let's do the same thing for the menu
  • 01:50:01 button let's just drag this inside of
  • 01:50:04 the menu sprite or menu button sprite
  • 01:50:06 and then that should be fine because the
  • 01:50:10 menu button sprite has almost the same
  • 01:50:12 code as the retry button sprite so we're
  • 01:50:14 good now let's drag this into our start
  • 01:50:17 button ok and then instead of when I
  • 01:50:21 receive lose we want this to be when I
  • 01:50:24 receive menu now let's try it out
  • 01:50:28 ok there's he start button sprite and ok
  • 01:50:35 so this works fine like that however
  • 01:50:43 first thing I noticed was that the
  • 01:50:46 countdown sprite showed on the menu so
  • 01:50:50 we want to
  • 01:50:51 go to events drag a when I receive menu
  • 01:50:54 then we want to hide the countdown
  • 01:50:56 sprite alright and a second thing kind
  • 01:51:01 of noticed was that when the game starts
  • 01:51:03 you can still hover over the menu button
  • 01:51:06 sprite because it's still there so let's
  • 01:51:10 go to our Start button in our menu and
  • 01:51:14 let's see oh yeah we have to make sure
  • 01:51:19 that when the start button is clicked we
  • 01:51:22 want to also stop other scripts in the
  • 01:51:26 sprite including the button sound effect
  • 01:51:29 so yeah that's why this was playing
  • 01:51:32 because this Farva loop was still going
  • 01:51:35 so now that we added the stop other
  • 01:51:38 strips in sprite it stops everything in
  • 01:51:40 the start button sprite alright let's
  • 01:51:43 try it again
  • 01:51:44 so there's our sound effect and okay
  • 01:51:48 let's see oh yeah okay so the stop other
  • 01:51:54 scripts in sprite also stopped this so
  • 01:51:57 let's just drag this hide inside of the
  • 01:51:59 if Mouse down and that should be fine
  • 01:52:02 alright and there we go okay oh and I
  • 01:52:14 think the same thing for the menu button
  • 01:52:16 so we want to stop other scripts in the
  • 01:52:19 sprite for the menu button and let's
  • 01:52:23 also drag the hide inside of the if
  • 01:52:26 Mouse down instead of the start
  • 01:52:28 countdown and let's check the retry
  • 01:52:32 button okay same thing so drag a stop
  • 01:52:37 other scripts in sprite and that should
  • 01:52:41 be fine oh yeah let's drag the hide
  • 01:52:44 inside of the if Mouse down and let's
  • 01:52:47 write again okay
  • 01:52:53 all right okay our many button is still
  • 01:52:58 there so let's see oh yeah we still have
  • 01:53:02 to include the one I receive start
  • 01:53:04 countdown because when we restart the
  • 01:53:07 game we still have to hide the mini
  • 01:53:09 button so yeah my bad let's drag this
  • 01:53:12 back let's also drag this inside of the
  • 01:53:15 retry button sprite just in case yeah
  • 01:53:19 that should be fine all right okay the
  • 01:53:29 money button is still running okay to
  • 01:53:33 fix this we have to go to control and
  • 01:53:38 then stop other scripts in the sprite
  • 01:53:41 wind star countdown is received and that
  • 01:53:46 should be fine let's do the same thing
  • 01:53:48 for the retry button so stop other
  • 01:53:50 scripts in sprite when start countdown
  • 01:53:53 who's received and now let's try it
  • 01:53:55 again okay all right
  • 01:54:02 no more button tapping sound effects in
  • 01:54:05 the game I mean when the game starts
  • 01:54:14 alright
  • 01:54:23 and I think that works okay cool
  • 01:54:26 so we have the button sound effect down
  • 01:54:30 and now I think I'm going to add a sound
  • 01:54:33 effect to when the bird passes a pipe
  • 01:54:37 maybe some like high-pitched ding sound
  • 01:54:40 effect or maybe a bell or something so
  • 01:54:42 let's try to find that let's see let's
  • 01:54:46 go to our pipe let's see yep so let's go
  • 01:54:56 to sounds now and I'm going to find the
  • 01:54:59 sound okay I found the sound effect and
  • 01:55:02 it's this sort of coin sound effect like
  • 01:55:05 that so let's add this and I'm gonna
  • 01:55:11 trim this to here and I might make this
  • 01:55:16 higher pitched let's see okay yeah I
  • 01:55:23 think a higher pitch sounds better okay
  • 01:55:30 and now this is gonna be our score
  • 01:55:33 increase sound effect so let's go to our
  • 01:55:36 code and right in here when the bird
  • 01:55:40 passes the position of the pipes then we
  • 01:55:43 want to go to sounds and then start the
  • 01:55:46 sound of the coin all rights try it out
  • 01:55:56 alright there it is okay that seems
  • 01:56:04 pretty good let's try it again
  • 01:56:10 alright
  • 01:56:11 and one more sound effect and I think I
  • 01:56:14 will add is when the bird crashes into
  • 01:56:18 the pipe we sort of need some bump sound
  • 01:56:21 effect so let's go to our bird sprite
  • 01:56:24 and then I will find a sound alright so
  • 01:56:29 there weren't any small bumping sound
  • 01:56:31 effects but I think beatbox one will do
  • 01:56:34 so it's like this
  • 01:56:39 so I think I'm gonna only use the first
  • 01:56:42 part of the sound effect so when it does
  • 01:56:46 this ok so right around here so I'm
  • 01:56:51 gonna trim about this much of it let's
  • 01:56:53 try it pip it more or hear all right so
  • 01:57:12 I think this much is fine I'm gonna save
  • 01:57:14 this alright and let's drag the sound
  • 01:57:20 into when the bird crashes into the pipe
  • 01:57:24 so right here let's drag the start sound
  • 01:57:30 of beatbox one inside of the if touching
  • 01:57:34 sprite to which is the pipe or if the Y
  • 01:57:37 position is less than negative 171
  • 01:57:40 alright let's try it out okay that
  • 01:57:49 sounds pretty good let's try it again
  • 01:57:51 when it falls off okay I think that's
  • 01:57:56 good and of course you can record your
  • 01:57:58 own sound effects if you want you can
  • 01:58:00 also find them online there's some good
  • 01:58:02 sites where you can download some free
  • 01:58:04 sound effects but anyways that's pretty
  • 01:58:07 much it so I'm just gonna do some more
  • 01:58:10 playthroughs of the game so this is the
  • 01:58:13 menu okay I'm gonna go to the project
  • 01:58:17 page alright so this is the menu we have
  • 01:58:22 our start this is our gameplay
  • 01:58:44 let's crash into the pipe okay let me
  • 01:58:53 try okay let's go back and let's start
  • 01:59:03 again of course you can make the game
  • 01:59:15 harder by decreasing the space between
  • 01:59:17 the pipes all right
  • 01:59:25 oops got some lag right there but yeah
  • 01:59:32 anyways that's the entire game anyways
  • 01:59:34 that's over this video and that's it for
  • 01:59:36 this entire series