1 00:00:00,110 --> 00:00:16,109 Hello, in this video tutorial we're going to use some variables. First of all, we use a variable to take account of the lives the cat is going to have, because the cat is going to die. 2 00:00:16,109 --> 00:00:24,109 and after that we will use another variable to score some points 3 00:00:24,109 --> 00:00:32,109 and even later on we will use yet another variable to increase the difficulty 4 00:00:32,109 --> 00:00:36,109 but using a countdown with a timer 5 00:00:36,109 --> 00:00:43,109 so we will have a fixed time to complete our task at the video game 6 00:00:43,109 --> 00:00:51,189 so as you may notice I've already placed the blocks for the motion here with the 7 00:00:51,189 --> 00:00:57,950 right arrow, left arrow, up arrow and down arrow as we have done so many times 8 00:00:57,950 --> 00:01:09,349 now I've placed the cat at the starting point, right there, with the 9 00:01:09,349 --> 00:01:14,530 rotation style left to right so it doesn't go upside down when going left 10 00:01:14,530 --> 00:01:28,370 and already start included the first of three backdrops I got three backdrops 11 00:01:28,370 --> 00:01:40,120 here, well, I'll remove this one, I'll make one later, one of this, first the bulwark, 12 00:01:40,120 --> 00:01:49,500 then the MIT field, and then the forest. So we'll start at the bulwark and as the 13 00:01:49,500 --> 00:01:55,799 cat moves, if it reaches an edge, the right edge, then it will go to the next 14 00:01:55,799 --> 00:02:02,579 backdrop and as it is it's exiting from the right side it will appear on the 15 00:02:02,579 --> 00:02:10,580 left side and conversely if it exits from the left edge it will appear on the 16 00:02:10,580 --> 00:02:17,340 right edge and on the previous background so change of backdrop motion and then I've 17 00:02:17,340 --> 00:02:37,340 I have already defined a block here for the cat to die in this way, playing a meow sound, and then I will rotate it, setting the rotation style all around, make it point upwards, and disappear with the ghost effect. 18 00:02:37,340 --> 00:02:40,340 Something like this. 19 00:02:40,340 --> 00:02:44,340 It's always good to check that you are doing things. 20 00:02:44,340 --> 00:02:56,340 Now, as I've included some ghost effects here, I will include also clear graphic effects at the beginning, so I got the cat not transparent from the beginning. 21 00:02:56,340 --> 00:03:06,909 Let's check if this works, so I can move the cat every way and change backdrops back and forth. 22 00:03:06,909 --> 00:03:20,819 and what am I going to do now I'm going to include another character let's say 23 00:03:21,139 --> 00:03:38,939 well let's say I got the crab and I'm going to make it smaller so set size to 24 00:03:38,939 --> 00:03:47,060 check it like 30% we click on it and check it well maybe too small let's say 25 00:03:47,060 --> 00:03:56,319 40% something like that and I want it to appear only on the second backdrop let's 26 00:03:56,319 --> 00:04:07,400 say so as the beginning we start at the first backdrop I can use for the crab 27 00:04:07,400 --> 00:04:18,769 when switching backdrop to our place the second one fill up MIT then appear 28 00:04:18,769 --> 00:04:30,839 success the 40 and show and now I'm going to duplicate this couple of times 29 00:04:30,839 --> 00:04:46,379 and say that at the war walk and at the forest it will hide so it will only 30 00:04:46,379 --> 00:04:58,740 appear there now I'm placing it somewhere let's say there so go to then I will use 31 00:04:58,740 --> 00:05:06,540 a rotation style left right and now I'm going to move it in a random way by 32 00:05:06,540 --> 00:05:18,920 bouncing with a forever move and if on edge bounce as we have already done in 33 00:05:18,920 --> 00:05:27,230 previous exercises let's check it there's no crab here we're going to the 34 00:05:27,230 --> 00:05:33,170 second backdrop there's the cat it's moving but it's pointing left and right 35 00:05:33,170 --> 00:05:43,430 let's check what happened here I have to make it point at some angle so let's put 36 00:05:43,430 --> 00:05:59,050 it here point at an angle so it will be bouncing there there it is okay now the 37 00:05:59,050 --> 00:06:11,680 is anytime the cat touches the crab it dies I mean it lose it loses a life so 38 00:06:11,680 --> 00:06:22,319 if I want the cat to have seven lives I have to create a variable so I can take 39 00:06:22,319 --> 00:06:29,339 account of the number of lives that are left so I go into variables and make a 40 00:06:29,339 --> 00:06:43,500 a variable I'm calling it lives left and now at the beginning I will set the 41 00:06:43,500 --> 00:06:55,319 lives left to 7 and as I have ticket this is ticket the lives left appear on 42 00:06:55,319 --> 00:07:06,660 screen I can move them well I can also change it make it like that right 43 00:07:06,660 --> 00:07:23,720 clicking on it I can just put it normal readout now touching the crab okay as 44 00:07:23,720 --> 00:07:32,899 have plenty of blocks here I will start a new thread and include a new forever 45 00:07:32,899 --> 00:07:41,819 and in here I will be asking with an if if the cat is touching the crab that's 46 00:07:41,819 --> 00:07:51,680 under ascension first block if touching crab touching crab what would happen 47 00:07:51,680 --> 00:08:06,439 that the lives will change how? by minus 1 so change lives by minus 1 48 00:08:06,439 --> 00:08:13,620 let's see what happens is it this one to work well not really but we'll learn 49 00:08:13,620 --> 00:08:22,899 something okay so here we got seven lives we go there now first touch okay 50 00:08:22,899 --> 00:08:31,339 we've lost nine lives in just one touch what why is this happening because all 51 00:08:31,339 --> 00:08:39,840 the time the crab is going through the cat it keeps touching it and the program 52 00:08:39,840 --> 00:08:48,179 accounts for several touches in one pass we want this to count just one so how 53 00:08:48,179 --> 00:08:57,629 can we do that we can use a weight so it leaves some time for the crab to go away 54 00:08:57,629 --> 00:09:04,629 from the cat or the cat away from the crab before counting again so let's say 55 00:09:04,629 --> 00:09:14,419 a couple of seconds and see what happens okay lives left six why this should be 56 00:09:14,419 --> 00:09:26,330 seven when clicking set lives to seven seven good now I haven't click it on the 57 00:09:26,330 --> 00:09:41,250 green flag that was now there we go and now let's say one touch six lives five 58 00:09:41,250 --> 00:09:51,970 lives. That's better. Four lives. Good. Now then, we have already defined a way to 59 00:09:51,970 --> 00:09:57,809 die, but when is the cat going to die? Well, when it loses all the lives. So we have to 60 00:09:57,809 --> 00:10:07,649 ask if lives get to zero. So if, an independent if in here, inside a forever. 61 00:10:07,649 --> 00:10:14,990 we could place it in the separate one but we can use the same forever now if 62 00:10:14,990 --> 00:10:24,639 operator equal green one zero what is going to be zero the variable lives we 63 00:10:24,639 --> 00:10:30,100 go into lives into variable and get lives left if life let's get to zero 64 00:10:30,100 --> 00:11:04,750 then die. We already got a block for that. Die. Check it. 7 lives, 6, not so difficult to avoid, 4, 3, 2, 1, and 0. 65 00:11:04,750 --> 00:11:10,580 and now the cat dies 66 00:11:10,580 --> 00:11:14,580 well, still, we might 67 00:11:14,580 --> 00:11:18,580 want to have a second chance, second 68 00:11:18,580 --> 00:11:22,580 opportunity, so how about if we make it start 69 00:11:22,580 --> 00:11:26,580 all over when it gets to zero lives 70 00:11:26,580 --> 00:11:30,580 when we did have some blocks here 71 00:11:30,580 --> 00:11:34,580 that were the setup at the 72 00:11:34,580 --> 00:11:43,480 beginning we can make a block for this setup at the beginning and call it start 73 00:11:43,480 --> 00:12:03,320 so our start is going to be this placing the lives at 7 clearing the graphic 74 00:12:03,320 --> 00:12:07,320 effects switch the back door to the first one 75 00:12:07,320 --> 00:12:17,769 sabotage in style point and go and as we are switching back to broad walk the 76 00:12:17,769 --> 00:12:21,889 crab would hide so that's good so there we go 77 00:12:21,889 --> 00:12:35,659 oops why is it check it because if I define the start I have to use the block 78 00:12:35,659 --> 00:12:44,480 here is the start I place it here when I begin I start and then after dying 79 00:12:44,480 --> 00:13:00,059 we start again here as part of the dying because if I place the start here it will 80 00:13:00,059 --> 00:13:17,399 start forever. That's all good. So, after dying it starts again. There we go. 81 00:13:17,399 --> 00:13:49,179 Six, five, four, three, two, one, zero. Dying and starting again. Good. So now, let's say we want 82 00:13:49,179 --> 00:13:55,440 to make it all more interesting and include some points for us to score 83 00:13:55,440 --> 00:14:07,750 while we try to avoid the crab so if we are going to count let's say we we score 84 00:14:07,750 --> 00:14:13,129 points by touching a different sprite 85 00:14:13,129 --> 00:14:23,740 get some apple here and well this is the apple curve 86 00:14:23,740 --> 00:14:31,309 let's say i want the apple to appear only at the same 87 00:14:31,309 --> 00:14:38,590 backdrop so when backdrop switches to i place the 88 00:14:38,590 --> 00:14:47,000 three of them and i use so for the second and 89 00:14:47,000 --> 00:14:57,230 height for the first and third well now i'm going to place the apple somewhere let's say here 90 00:14:59,389 --> 00:15:14,330 and also we'll use the rotation style left right go there point at an angle and move let's say 91 00:15:14,330 --> 00:15:25,480 point and then continuous motion with a forever move and if on its bounds we'll 92 00:15:25,480 --> 00:15:39,259 keep it simple let's check it okay so there we've got a crab and we are 93 00:15:39,259 --> 00:15:47,519 already losing lives and the apple now let's say we grab the apple how can we 94 00:15:47,519 --> 00:15:57,769 touch the apple how can we score points okay there we go so points those are 95 00:15:57,769 --> 00:16:08,100 numbers another variable so I make a variable and call it the score now at 96 00:16:08,100 --> 00:16:20,600 the beginning it's going to be zero so set again I'm here and then at the 97 00:16:20,600 --> 00:16:29,600 apple's code I could also be the cat's code because when the cat touches the 98 00:16:29,600 --> 00:16:35,279 apple the apple touches the cat. I have less blocks here so I'm going to use them here 99 00:16:35,279 --> 00:16:50,159 so at the beginning I will set score to zero and now I'm 100 00:16:50,159 --> 00:17:03,700 going to check if they are touching if touching cat which is called sprite1 101 00:17:03,700 --> 00:17:13,420 then change the score by one I'm going to variables and change not lives but 102 00:17:13,420 --> 00:17:28,579 score by one okay now we start we we got the score here we might want to hide 103 00:17:28,579 --> 00:17:40,279 later well let's see if we are scoring some points we're not why okay it's not 104 00:17:40,279 --> 00:18:01,869 working checking back to the code if touching change the score by one should 105 00:18:01,869 --> 00:18:26,420 be working it's not okay okay that's it it's actually working maybe I forgot to 106 00:18:26,420 --> 00:18:33,180 click the green flag whatever but then again remember if you don't use a weight 107 00:18:33,180 --> 00:18:40,180 you will be counting too many times so every time it's touching it's counting 108 00:18:40,180 --> 00:18:51,500 not one but plenty of points so in quite the same way as we use here a weight so 109 00:18:51,500 --> 00:18:59,680 we weren't losing the lives several at the time we go here and use a weight 110 00:18:59,680 --> 00:19:15,359 again let's say a couple of seconds okay good now as I said I want lives on the 111 00:19:15,359 --> 00:19:20,460 score to appear only on this backdrop because there's no reason for them to be 112 00:19:20,460 --> 00:19:31,150 here well maybe the likes yes but the score is not there well let's well you 113 00:19:31,150 --> 00:19:35,650 might want it to be from the beginning but if you don't you can go into 114 00:19:35,650 --> 00:19:45,019 variables and use show and hide variables so you can show variables 115 00:19:45,019 --> 00:19:58,940 score and on this backdrop and hide variables score on this other two that 116 00:19:58,940 --> 00:20:03,119 way you get the variables just on the 117 00:20:03,119 --> 00:20:09,779 background in which they are counting 118 00:20:09,779 --> 00:20:16,680 there okay now what happens if you get 119 00:20:16,680 --> 00:20:25,599 some score let's say let's say if we get 120 00:20:25,599 --> 00:20:34,579 to ten points we we win so let's create 121 00:20:34,579 --> 00:20:46,740 a final backdrop like I win first of all if we want to paint it with a packet 122 00:20:46,740 --> 00:20:53,019 it's not working here we have to convert it to bitmap first remember convert to 123 00:20:53,019 --> 00:21:00,220 bitmap now we can paint it now we can type some letters with a 124 00:21:00,220 --> 00:21:17,660 different color okay like that let's say I wait now if you use the arrow pointer 125 00:21:17,660 --> 00:21:34,369 and select it by dragging you can use a handle and make it big place then when 126 00:21:34,369 --> 00:21:44,319 you win you might want the other characters to disappear so let's get back here and say 127 00:21:45,119 --> 00:22:14,220 when but the switch is the high uh that the ios one okay so they they will disappear okay um now 128 00:22:14,220 --> 00:23:12,269 Now, checking, scoring 5, lives left 3, oops, score 7, oops, score 8, oops, lives scored, ah, oops, 9, ah, yeah, and that's just what I was, well, but, 129 00:23:12,269 --> 00:23:33,410 But you just try. Now, let's make it a little more difficult. Let's get a fixed time for us to cross through the second backdrop. Right? So, how do we count time? We count time with a timer. This is under a sensor. This is a timer. 130 00:23:33,410 --> 00:23:50,269 Timer counts up. You can restart it from zero. It gets plenty of decimals. It goes one second and decimal points of a second. Even milliseconds. Too many numbers. 131 00:23:50,269 --> 00:24:11,880 Then it's counting up. We want our time to count down. So we are going to use a variable. Well, where? There are too many blocks here. Let's go somewhere else. Like here, there, here. Let's say here. 132 00:24:11,880 --> 00:24:23,119 So, let's say we create a variable, look, we are creating a variable for all sprites. 133 00:24:23,119 --> 00:24:29,680 That's why we can create it at the graphs code or any other one, because it will work 134 00:24:29,680 --> 00:24:31,680 for all. 135 00:24:31,680 --> 00:24:35,380 So we leave this mark for all sprites. 136 00:24:35,380 --> 00:24:43,400 We will be calling it timeLeft, right. 137 00:24:43,400 --> 00:24:53,000 So now, let's say, we're going to count time from, let's say, 60 seconds, so we will make 138 00:24:53,000 --> 00:25:09,700 time, we will set the time left to 60 minus the time that counts the timer. 139 00:25:09,700 --> 00:25:16,599 we subtract because we wanted to count backwards we wanted to count down so if 140 00:25:16,599 --> 00:25:29,039 we start at 60 and we put here the timer which is under sensing the time left 141 00:25:29,039 --> 00:25:49,569 will be going down if we put this inside a forever and put it like we can put it 142 00:25:49,569 --> 00:26:00,410 in another when backdrop switches or we can put it from the beginning and say 143 00:26:00,410 --> 00:26:09,500 that the timer restart will reset the timer when we enter the backdrop 144 00:26:09,500 --> 00:26:29,740 whatever see now we got it's not showing the time here 145 00:26:29,740 --> 00:26:43,000 set time left to 60 minus timer but I guess it's not actually counting 146 00:26:43,000 --> 00:26:49,720 properly because the timer is a different number so we will round it and 147 00:26:49,720 --> 00:27:08,910 remove the decimal points we go into math operators and use round 148 00:27:08,910 --> 00:27:30,980 still not working still not working why because oh because this is life left I 149 00:27:30,980 --> 00:27:39,700 haven't changed it to time left I forgot okay that's it now at the beginning it's 150 00:27:39,700 --> 00:27:49,839 counting down right but then it will reset and start counting from 60 so what 151 00:27:49,839 --> 00:27:57,880 do we have to do? We have to remove this variable from this backdrop and only 152 00:27:57,880 --> 00:28:05,259 show it when it starts at 60 here and counting down. So we use the same trick 153 00:28:05,259 --> 00:28:12,700 we did before and use under variables, hide variable and show variable. Show 154 00:28:12,700 --> 00:28:29,019 So variable here, hide variable on the other and now we can remove the timer by unticking 155 00:28:29,019 --> 00:28:31,329 it. 156 00:28:31,329 --> 00:28:33,640 That's it. 157 00:28:33,640 --> 00:28:34,640 There. 158 00:28:34,640 --> 00:28:42,839 I have to stop it and then, okay, that's it. 159 00:28:42,839 --> 00:28:44,940 Well there we go. 160 00:28:44,940 --> 00:28:51,880 Lives left and time left but then when we hit the green arrow there's only, no there's 161 00:28:51,880 --> 00:28:55,880 three lives, not time 162 00:28:55,880 --> 00:28:59,880 ok, same thing as before, I have to change the variable number 163 00:28:59,880 --> 00:29:03,880 name here, it's time, time 164 00:29:03,880 --> 00:29:09,259 and time, and 165 00:29:09,259 --> 00:29:14,890 so time left, and we also want to show lives left 166 00:29:14,890 --> 00:29:18,890 ok, so 167 00:29:18,890 --> 00:29:22,890 so lives left in here, hide 168 00:29:22,890 --> 00:29:40,539 so let's check this again at the second backdrop we show lives and time and on 169 00:29:40,539 --> 00:29:56,599 the other backdrops we hide both of them place it no variables then time box we 170 00:29:56,599 --> 00:30:18,279 should move them so we can see all of them. Lives, score, and time. There we go. We lose 171 00:30:18,279 --> 00:30:29,400 some lives, we score some points, the time goes down, and well, now there's only one 172 00:30:29,400 --> 00:30:41,180 left for us which is if the time runs out then we die we have already used if 173 00:30:41,180 --> 00:31:00,210 lives left 0 then die we can place the if time left is 0 die in here if equal 174 00:31:00,210 --> 00:31:24,829 operator equal to zero, variables, time left, then block die, and when dying, win. 175 00:31:24,829 --> 00:31:33,349 So that should be it. There we go. We've got three variables working. The score, the time, 176 00:31:33,349 --> 00:31:47,019 Time and lives. If I get a score, I win. If not, I die and I get a try again. 177 00:31:50,819 --> 00:31:53,819 Oops. They are too close. Oops. 178 00:31:58,420 --> 00:32:03,000 Well, that's all. Thank you.