Saltar navegación

Activa JavaScript para disfrutar de los vídeos de la Mediateca.

Scratch variables - Contenido educativo

Ajuste de pantalla

El ajuste de pantalla se aprecia al ver el vídeo en pantalla completa. Elige la presentación que más te guste:

Subido el 10 de noviembre de 2024 por Juan Carlos A.

28 visualizaciones

Descargar la transcripción

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. 00:00:00
and after that we will use another variable to score some points 00:00:16
and even later on we will use yet another variable to increase the difficulty 00:00:24
but using a countdown with a timer 00:00:32
so we will have a fixed time to complete our task at the video game 00:00:36
so as you may notice I've already placed the blocks for the motion here with the 00:00:43
right arrow, left arrow, up arrow and down arrow as we have done so many times 00:00:51
now I've placed the cat at the starting point, right there, with the 00:00:57
rotation style left to right so it doesn't go upside down when going left 00:01:09
and already start included the first of three backdrops I got three backdrops 00:01:14
here, well, I'll remove this one, I'll make one later, one of this, first the bulwark, 00:01:28
then the MIT field, and then the forest. So we'll start at the bulwark and as the 00:01:40
cat moves, if it reaches an edge, the right edge, then it will go to the next 00:01:49
backdrop and as it is it's exiting from the right side it will appear on the 00:01:55
left side and conversely if it exits from the left edge it will appear on the 00:02:02
right edge and on the previous background so change of backdrop motion and then I've 00:02:10
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. 00:02:17
Something like this. 00:02:37
It's always good to check that you are doing things. 00:02:40
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. 00:02:44
Let's check if this works, so I can move the cat every way and change backdrops back and forth. 00:02:56
and what am I going to do now I'm going to include another character let's say 00:03:06
well let's say I got the crab and I'm going to make it smaller so set size to 00:03:21
check it like 30% we click on it and check it well maybe too small let's say 00:03:38
40% something like that and I want it to appear only on the second backdrop let's 00:03:47
say so as the beginning we start at the first backdrop I can use for the crab 00:03:56
when switching backdrop to our place the second one fill up MIT then appear 00:04:07
success the 40 and show and now I'm going to duplicate this couple of times 00:04:18
and say that at the war walk and at the forest it will hide so it will only 00:04:30
appear there now I'm placing it somewhere let's say there so go to then I will use 00:04:46
a rotation style left right and now I'm going to move it in a random way by 00:04:58
bouncing with a forever move and if on edge bounce as we have already done in 00:05:06
previous exercises let's check it there's no crab here we're going to the 00:05:18
second backdrop there's the cat it's moving but it's pointing left and right 00:05:27
let's check what happened here I have to make it point at some angle so let's put 00:05:33
it here point at an angle so it will be bouncing there there it is okay now the 00:05:43
is anytime the cat touches the crab it dies I mean it lose it loses a life so 00:05:59
if I want the cat to have seven lives I have to create a variable so I can take 00:06:11
account of the number of lives that are left so I go into variables and make a 00:06:22
a variable I'm calling it lives left and now at the beginning I will set the 00:06:29
lives left to 7 and as I have ticket this is ticket the lives left appear on 00:06:43
screen I can move them well I can also change it make it like that right 00:06:55
clicking on it I can just put it normal readout now touching the crab okay as 00:07:06
have plenty of blocks here I will start a new thread and include a new forever 00:07:23
and in here I will be asking with an if if the cat is touching the crab that's 00:07:32
under ascension first block if touching crab touching crab what would happen 00:07:41
that the lives will change how? by minus 1 so change lives by minus 1 00:07:51
let's see what happens is it this one to work well not really but we'll learn 00:08:06
something okay so here we got seven lives we go there now first touch okay 00:08:13
we've lost nine lives in just one touch what why is this happening because all 00:08:22
the time the crab is going through the cat it keeps touching it and the program 00:08:31
accounts for several touches in one pass we want this to count just one so how 00:08:39
can we do that we can use a weight so it leaves some time for the crab to go away 00:08:48
from the cat or the cat away from the crab before counting again so let's say 00:08:57
a couple of seconds and see what happens okay lives left six why this should be 00:09:04
seven when clicking set lives to seven seven good now I haven't click it on the 00:09:14
green flag that was now there we go and now let's say one touch six lives five 00:09:26
lives. That's better. Four lives. Good. Now then, we have already defined a way to 00:09:41
die, but when is the cat going to die? Well, when it loses all the lives. So we have to 00:09:51
ask if lives get to zero. So if, an independent if in here, inside a forever. 00:09:57
we could place it in the separate one but we can use the same forever now if 00:10:07
operator equal green one zero what is going to be zero the variable lives we 00:10:14
go into lives into variable and get lives left if life let's get to zero 00:10:24
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. 00:10:30
and now the cat dies 00:11:04
well, still, we might 00:11:10
want to have a second chance, second 00:11:14
opportunity, so how about if we make it start 00:11:18
all over when it gets to zero lives 00:11:22
when we did have some blocks here 00:11:26
that were the setup at the 00:11:30
beginning we can make a block for this setup at the beginning and call it start 00:11:34
so our start is going to be this placing the lives at 7 clearing the graphic 00:11:43
effects switch the back door to the first one 00:12:03
sabotage in style point and go and as we are switching back to broad walk the 00:12:07
crab would hide so that's good so there we go 00:12:17
oops why is it check it because if I define the start I have to use the block 00:12:21
here is the start I place it here when I begin I start and then after dying 00:12:35
we start again here as part of the dying because if I place the start here it will 00:12:44
start forever. That's all good. So, after dying it starts again. There we go. 00:13:00
Six, five, four, three, two, one, zero. Dying and starting again. Good. So now, let's say we want 00:13:17
to make it all more interesting and include some points for us to score 00:13:49
while we try to avoid the crab so if we are going to count let's say we we score 00:13:55
points by touching a different sprite 00:14:07
get some apple here and well this is the apple curve 00:14:13
let's say i want the apple to appear only at the same 00:14:23
backdrop so when backdrop switches to i place the 00:14:31
three of them and i use so for the second and 00:14:38
height for the first and third well now i'm going to place the apple somewhere let's say here 00:14:47
and also we'll use the rotation style left right go there point at an angle and move let's say 00:14:59
point and then continuous motion with a forever move and if on its bounds we'll 00:15:14
keep it simple let's check it okay so there we've got a crab and we are 00:15:25
already losing lives and the apple now let's say we grab the apple how can we 00:15:39
touch the apple how can we score points okay there we go so points those are 00:15:47
numbers another variable so I make a variable and call it the score now at 00:15:57
the beginning it's going to be zero so set again I'm here and then at the 00:16:08
apple's code I could also be the cat's code because when the cat touches the 00:16:20
apple the apple touches the cat. I have less blocks here so I'm going to use them here 00:16:29
so at the beginning I will set score to zero and now I'm 00:16:35
going to check if they are touching if touching cat which is called sprite1 00:16:50
then change the score by one I'm going to variables and change not lives but 00:17:03
score by one okay now we start we we got the score here we might want to hide 00:17:13
later well let's see if we are scoring some points we're not why okay it's not 00:17:28
working checking back to the code if touching change the score by one should 00:17:40
be working it's not okay okay that's it it's actually working maybe I forgot to 00:18:01
click the green flag whatever but then again remember if you don't use a weight 00:18:26
you will be counting too many times so every time it's touching it's counting 00:18:33
not one but plenty of points so in quite the same way as we use here a weight so 00:18:40
we weren't losing the lives several at the time we go here and use a weight 00:18:51
again let's say a couple of seconds okay good now as I said I want lives on the 00:18:59
score to appear only on this backdrop because there's no reason for them to be 00:19:15
here well maybe the likes yes but the score is not there well let's well you 00:19:20
might want it to be from the beginning but if you don't you can go into 00:19:31
variables and use show and hide variables so you can show variables 00:19:35
score and on this backdrop and hide variables score on this other two that 00:19:45
way you get the variables just on the 00:19:58
background in which they are counting 00:20:03
there okay now what happens if you get 00:20:09
some score let's say let's say if we get 00:20:16
to ten points we we win so let's create 00:20:25
a final backdrop like I win first of all if we want to paint it with a packet 00:20:34
it's not working here we have to convert it to bitmap first remember convert to 00:20:46
bitmap now we can paint it now we can type some letters with a 00:20:53
different color okay like that let's say I wait now if you use the arrow pointer 00:21:00
and select it by dragging you can use a handle and make it big place then when 00:21:17
you win you might want the other characters to disappear so let's get back here and say 00:21:34
when but the switch is the high uh that the ios one okay so they they will disappear okay um now 00:21:45
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, 00:22:14
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. 00:23:12
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. 00:23:33
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. 00:23:50
So, let's say we create a variable, look, we are creating a variable for all sprites. 00:24:11
That's why we can create it at the graphs code or any other one, because it will work 00:24:23
for all. 00:24:29
So we leave this mark for all sprites. 00:24:31
We will be calling it timeLeft, right. 00:24:35
So now, let's say, we're going to count time from, let's say, 60 seconds, so we will make 00:24:43
time, we will set the time left to 60 minus the time that counts the timer. 00:24:53
we subtract because we wanted to count backwards we wanted to count down so if 00:25:09
we start at 60 and we put here the timer which is under sensing the time left 00:25:16
will be going down if we put this inside a forever and put it like we can put it 00:25:29
in another when backdrop switches or we can put it from the beginning and say 00:25:49
that the timer restart will reset the timer when we enter the backdrop 00:26:00
whatever see now we got it's not showing the time here 00:26:09
set time left to 60 minus timer but I guess it's not actually counting 00:26:29
properly because the timer is a different number so we will round it and 00:26:43
remove the decimal points we go into math operators and use round 00:26:49
still not working still not working why because oh because this is life left I 00:27:08
haven't changed it to time left I forgot okay that's it now at the beginning it's 00:27:30
counting down right but then it will reset and start counting from 60 so what 00:27:39
do we have to do? We have to remove this variable from this backdrop and only 00:27:49
show it when it starts at 60 here and counting down. So we use the same trick 00:27:57
we did before and use under variables, hide variable and show variable. Show 00:28:05
So variable here, hide variable on the other and now we can remove the timer by unticking 00:28:12
it. 00:28:29
That's it. 00:28:31
There. 00:28:33
I have to stop it and then, okay, that's it. 00:28:34
Well there we go. 00:28:42
Lives left and time left but then when we hit the green arrow there's only, no there's 00:28:44
three lives, not time 00:28:51
ok, same thing as before, I have to change the variable number 00:28:55
name here, it's time, time 00:28:59
and time, and 00:29:03
so time left, and we also want to show lives left 00:29:09
ok, so 00:29:14
so lives left in here, hide 00:29:18
so let's check this again at the second backdrop we show lives and time and on 00:29:22
the other backdrops we hide both of them place it no variables then time box we 00:29:40
should move them so we can see all of them. Lives, score, and time. There we go. We lose 00:29:56
some lives, we score some points, the time goes down, and well, now there's only one 00:30:18
left for us which is if the time runs out then we die we have already used if 00:30:29
lives left 0 then die we can place the if time left is 0 die in here if equal 00:30:41
operator equal to zero, variables, time left, then block die, and when dying, win. 00:31:00
So that should be it. There we go. We've got three variables working. The score, the time, 00:31:24
Time and lives. If I get a score, I win. If not, I die and I get a try again. 00:31:33
Oops. They are too close. Oops. 00:31:50
Well, that's all. Thank you. 00:31:58
Materias:
Tecnología
Niveles educativos:
▼ Mostrar / ocultar niveles
  • Educación Secundaria Obligatoria
    • Ordinaria
      • Primer Ciclo
        • Primer Curso
        • Segundo Curso
      • Segundo Ciclo
        • Tercer Curso
        • Cuarto Curso
        • Diversificacion Curricular 1
        • Diversificacion Curricular 2
    • Compensatoria
Autor/es:
Juan Carlos Alonso de mena
Subido por:
Juan Carlos A.
Licencia:
Reconocimiento
Visualizaciones:
28
Fecha:
10 de noviembre de 2024 - 20:57
Visibilidad:
Público
Centro:
IES ALPEDRETE
Duración:
32′ 04″
Relación de aspecto:
16:10 El estándar usado por los portátiles de 15,4" y algunos otros, es ancho como el 16:9.
Resolución:
1920x1200 píxeles
Tamaño:
182.63 MBytes

Del mismo autor…

Ver más del mismo autor


EducaMadrid, Plataforma Educativa de la Comunidad de Madrid

Plataforma Educativa EducaMadrid