Activa JavaScript para disfrutar de los vídeos de la Mediateca.
Platformer02 - Contenido educativo
Ajuste de pantallaEl ajuste de pantalla se aprecia al ver el vídeo en pantalla completa. Elige la presentación que más te guste:
hello in this video tutorial I'm going to show you how to make the vertical motion and I will
00:00:00
do it for a kind of platformer game so it's going to be some jumping well we have already made a
00:00:08
horizontal motion with acceleration and inertia so we start from here and I'm going to explain
00:00:17
how to jump now and a platform again but former kind of game the cat will be jumping up only when
00:00:28
on the ground or on a platform so we have to draw some ground and platforms so let's go into the
00:00:38
backdrop here and let's draw let's say a rectangle filled with some color and that's going to be our
00:00:46
ground and let's say we draw a platformer line here and let's say another platformer line there
00:00:56
so let's make this a little thicker
00:01:13
okay now we got some grounds and platforms so as I was saying the cat is only going to
00:01:15
jump up if it's on standing on a platform or a ground that means touching the green color so
00:01:31
we're going to control and use an if touching the color but then instead of using just if touching
00:01:38
the color I'm going to use the if-else because I want something to happen if it is not touching
00:01:46
the color right what's going to happen if it's not touching the color that mean it's midway in a
00:01:52
jump so it will fall down so here I'm going to place what happens when it's falling down and
00:02:01
here I will place what happens when it can jump so first thing if touching color so the sensing
00:02:09
touching color pick the right color
00:02:20
and then so if it is touching the color it will jump and if it is not touching else here it will
00:02:30
fall down falling down is an accelerated kind of motion because you fall faster and faster the
00:02:40
higher you fall from the faster you get to the ground so we're going to use the same approach
00:02:48
as we use for the accelerated horizontal motion so the motion will be accomplished by changing
00:02:54
the vertical coordinate here so we're going to motion and change the vertical coordinate by as
00:03:06
it's going to be accelerated this is going to be a number that change so we need a variable we're
00:03:15
going to variables make a variable that's going to be called the y speed and we're going to change
00:03:22
the vertical position by the value of this vertical speed and at the beginning it's going to be zero
00:03:33
so now quite the same as we did with a horizontal acceleration we will use the
00:03:46
vertical acceleration here for the falling down so we change the vertical speed
00:03:54
and as it's going down we have to use a negative number here instead of using this minus two I've
00:04:05
found out that the smaller number works better so we'll use 0.5 so you can change this number
00:04:15
to make it fall down faster or slower so we have taken account of falling down so let's check it
00:04:23
so if it's there and if we place this inside our forever and
00:04:32
from the beginning then if it is not touching it will fall down so it's falling down at an
00:04:47
accelerating rate if it falls from higher it will go faster if it's falling from lower place it will
00:05:00
fall now first of all we want the fall to stop when it gets to the ground or to a platform so
00:05:11
it can stand on top of it so how can we do so well we know when it's touching the color so
00:05:25
first thing will be to stop the downwards motion we can stop that downwards motion by setting the
00:05:34
vertical speed to zero so if touching the color it should stop so let's check it so I have to
00:05:46
hit the green flag and now if it falls now it will stop because if touching green color then
00:05:58
vertical variable will be zero and now stops now
00:06:09
it stops there good so we have taken care of the downwards motion the falling now we have to take
00:06:20
care of the upwards motion the jumping for us to make the cat jump we will use the arrow key
00:06:31
up arrow key so if
00:06:40
under sensing key press
00:06:49
meaning up arrow key press then what then go up but we don't want it to be
00:06:56
accelerating up so we don't use change the vertical speed we will set a fixed value so it
00:07:06
jumps up at a fixed speed so we use set instead of change so we will make it go up at some speed
00:07:16
let's say 10 right so if the arrow keys press the vertical speed will be 10 now when only if
00:07:28
it is touching the ground or a platform right because we don't want it to be able to fly in
00:07:43
middle air so now let's check it now I hit the up arrow and it's not going up why because I haven't
00:07:54
change it here my variable to now if touching color it is speed to zero stop and then I hit
00:08:12
the right arrow and it goes up like that now when I release it it falls down automatically if I keep
00:08:26
hitting the arrow it doesn't go anywhere because it is not touching the green color it's in me
00:08:38
there so this doesn't work so this will only work if touching color if not touching color it just
00:08:46
falls down and now I can jump on top of the platforms but then there's something which is
00:08:56
standing on the platforms but there's something which is quite wrong here look if I go up from
00:09:07
here I'm touching the green and I can go up to the platform I'm going through the platform and
00:09:16
that's not good so I have to prevent the cat from going through the platform somehow how can I do
00:09:22
it well one simple way would be to use a different color for the underside of the platform so I'm
00:09:31
going to use a red color here and draw a rectangle underneath the platform
00:09:37
like that and then if I touch that color I will make the cat go down like bouncing back
00:09:52
so I use if
00:10:06
and I put this inside the same forever here now touching color
00:10:14
now this other color I will pick it
00:10:22
then what then something fall down so this is the falling down block so duplicated but
00:10:27
now if I want to make the bouncing back different from falling down I can just make this faster so
00:10:43
I can use let's say minus five so let's have a look at it now I move under the platform I go up
00:10:56
and it will bounce back faster than falling look this is falling and this is bouncing back now you
00:11:05
have to pick the right angle for you to be able to jump into that
00:11:16
okay well so let's recollect we are making the upwards motion using change vertical value
00:11:27
coordinate with a variable speed here vertical speed this is zero at the beginning only if you
00:11:39
touch in the ground or a platform color then you can make it go up by setting the vertical value
00:11:50
to 10 if touching color it will make it zero so when it falls down it will stop there and
00:12:02
if not touching the color it will automatically accelerate downwards now to prevent the cat
00:12:15
from going through the underside of the platform we use a different color and if
00:12:28
touching that color we make it fall down even faster than when in midair and what with this
00:12:33
you can make a jumping kind of game you can of course include more sprites so if you get them
00:12:44
you can get points you can put some kind of lava floor so if you jump into it you
00:12:51
you die and so on okay thank you
00:13:00
- Valoración:
- Eres el primero. Inicia sesión para valorar el vídeo.
- 1
- 2
- 3
- 4
- 5
- Idioma/s:
- Autor/es:
- Juan Carlos Alonso de Mena
- Subido por:
- Juan Carlos A.
- Licencia:
- Reconocimiento - No comercial
- Visualizaciones:
- 55
- Fecha:
- 5 de noviembre de 2023 - 11:07
- Visibilidad:
- Público
- Centro:
- IES ALPEDRETE
- Duración:
- 13′ 06″
- 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:
- 41.23 MBytes