background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Базовый курс С++ Часть #89. Смена уровней"

input logo icon
"videoThumbnail Базовый курс С++ Часть #89. Смена уровней
Table of contents
|

Table of contents

0:00
Смена уровней
0:31
Стираем уровень под шваброй
2:22
Добавим метод Clear_Area()
5:09
Добавим новое игровое состояние Mop_Level
8:35
Добавим в уровень метод Mop_Level()
11:05
Добавим в уровень метод Is_Level_Mopping_Done()
12:19
Добавим перечисление EMop_State
16:02
Учитываем состояния швабры в методе анимации Act()
19:29
Добавим геттер Get_Mop_State()
21:54
Добавим метод Show_Level()
23:11
Сведём методы Erase_Level() и Show_Level() в Activate()
25:51
Добавим состояния швабры для подъёма и опускания
27:20
Исправим использование состояний швабры
28:45
Задаём стартовую позицию сложенной швабры
32:25
Добавим метод Get_Cylinders_Height()
34:03
Делаем анимацию подъёма швабры
39:12
Переводим анимацию в расширение после подъёма
40:44
Переводим анимацию в спуск после опускания
45:02
Рефакторим машину состояний анимации швабры
48:30
Вынесем код в Act_Lifting()
55:26
Оптимизация машины состояний для стирания и показа уровня
59:52
Финальный рефакторинг машины состояний
1:01:48
Popcorn_part_89.zip: пишем код
Video tags
|

Video tags

C++
c++ visual studio
Popcorn
visual studio 2019
делаем игровой движок на C++
игры на С++
изучение С++
как научиться программировать с нуля
кодим игры
курсы С++
основы c++
пишем игры
попкорн
Программирование в Windows
Программирование
С++ для начинающих
С++ за час
С++ игры
С++ лекции
С++ обучение
С++ с нуля
С++ уроки
С++
Создание игры на С++
арканоид
смена уровней
уровни игры
переход на новый уровень
очистка уровня
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:00
[music]
00:00:16
we continue to make our game and now
00:00:19
when we have this mop displayed on the screen,
00:00:23
let’s make it so that it
00:00:25
can erase the old level and display a
00:00:28
new one, since first there is an
00:00:32
upward movement, that means we need to start
00:00:35
erasing what is already displayed on the screen, the
00:00:38
thing is the fact that in the original game we
00:00:41
can notice that at the level there are
00:00:43
bricks that do not break, we
00:00:46
now also have them in the first 10 levels, but
00:00:48
we already have bricks; teleportation does not
00:00:50
break it; bricks
00:00:51
that should disappear if
00:00:54
we break all the bricks and go to the
00:00:56
next level, so when moving
00:00:59
this mop,
00:01:01
we will need to erase everything that
00:01:05
is below it before each next
00:01:09
frame of drawing this mop,
00:01:12
I think that here in the level in the
00:01:18
drawing method from our level there are no these drops for
00:01:22
us here before we draw
00:01:25
the mop we will need erase everything that
00:01:29
is under it, but I think that you can
00:01:31
do this, for example, here inside
00:01:34
that condition because the bricks are
00:01:36
not displayed on the entire screen,
00:01:38
but inside the rector, so here if the
00:01:43
current drawing area intersects the entire
00:01:46
set of our bricks, then we
00:01:48
will erase
00:01:50
the level well, only if it was going about moving
00:01:53
up to this here it is to call us with an
00:01:57
object from a method that we don’t have yet
00:02:02
nuclear just clean the area under not
00:02:04
here I would clean the area
00:02:10
under all this mop I do
00:02:12
n’t think but here that’s enough and I think it’s
00:02:16
necessary even like- then sign the comments
00:02:20
like this
00:02:22
and then we need to implement such a
00:02:25
method already in our mop since it
00:02:30
will be a public method
00:02:31
then we will put it
00:02:52
here if we now have
00:02:56
abra in an active state
00:03:00
then we will do something, otherwise not
00:03:02
here either I will fill with the background the entire area
00:03:08
that is located below the top edge of
00:03:11
the mop, and the top edge has a coordinate
00:03:16
that is stored here in this
00:03:20
rect bean structure, that is, I can use the
00:03:22
rect methods
00:03:29
without our set of tools to fill the
00:03:34
specified rectangle with the background color,
00:03:37
well, if I were a fruit I’ll take this to extract
00:03:41
all the background color, it’s just a narrow strip over the summer,
00:03:47
corresponding to this
00:03:50
erasing part, and I need to fill everything
00:03:54
to the end of the screen, so I’ll create
00:03:58
another cancer, which I’ll immediately remember with
00:04:03
the values ​​​​from our project,
00:04:06
but it’s better to do it like this and the bottom
00:04:14
edge I will forcefully set the maximum
00:04:18
position that is possible for us, this is max
00:04:26
y paz, and multiply all this by the
00:04:29
global scale,
00:04:33
now this rectangle will
00:04:36
describe the entire area under the mops and we
00:04:39
will fill here too,
00:04:40
let's see what happens. I did
00:04:50
n’t fill this method is called, but
00:04:57
yes, we need to put it this
00:05:02
effect is here so we can fill it in,
00:05:08
but perfectly
00:05:10
the level is erased and we can make a
00:05:12
reverse movement, but here now
00:05:16
we have a platform rolling out,
00:05:20
the gate opens and all this should not
00:05:22
happen at that moment while we are erasing
00:05:25
and bringing out a new level in this way
00:05:28
for here this special game situation,
00:05:30
when we switch to a new level,
00:05:34
we need a special state of our engine
00:05:37
in which nothing will interfere with us
00:05:40
entering this image, so
00:05:42
before we move this mop down and display a
00:05:45
new level,
00:05:46
let's first add a
00:05:49
new state to our engine here, listing the game
00:05:55
state I I think this state should exist
00:05:57
before we start playing
00:05:59
the level and I call it could for lips could
00:06:05
this is a mop but husband and the English language
00:06:08
is that any word can
00:06:11
be an entity action or a sign of
00:06:14
this if I put the words could and then
00:06:17
level to in this construction could
00:06:20
already be an action from the point of view of the
00:06:22
English language, it would be like going to
00:06:24
shave the level, well in our case this is
00:06:27
exactly what our era does
00:06:29
and let's go straight from this state and
00:06:31
start now in our engine we
00:06:35
start in the state of losing the ball and when
00:06:39
we are in such a state there and according to the
00:06:41
timer we will wait until
00:06:45
the platform disappears, initially it is not there and we
00:06:47
launch a restart of the entire game, but I think
00:06:50
it is better to immediately install the MOP for you and
00:06:53
then at the start our mop will go
00:06:57
up, then it will go down, it will bring us a new
00:06:59
level and then only we will go to
00:07:02
restart left,
00:07:03
and in order for us to have a new level
00:07:05
displayed after the mop,
00:07:06
I think we don’t need to
00:07:09
force the first level now,
00:07:12
instead, we need to
00:07:15
order the output of this first level after we are all set up on the mop,
00:07:24
but since the mop
00:07:28
us that is not available I think that we should
00:07:31
instruct our level to get wet level this
00:07:36
will start an
00:07:37
animation of the movement of the mop and in our
00:07:41
method it is a timer here I will be
00:07:49
in the mutuzil state
00:07:51
and while we are in this
00:07:53
state we need to wait until
00:07:56
the mop moves up and down and update
00:07:59
our level and after that we need to
00:08:01
restart the
00:08:02
level so I would wait here until
00:08:05
our level is finished with this move pink well
00:08:08
here you can do it just hear and if
00:08:12
our level is finished could pink like this is there a
00:08:21
pink level done then
00:08:25
I I did a restart of the level, well, in theory,
00:08:32
this should now work in the correct
00:08:34
sequence, then let’s
00:08:37
add a new method to our level 0
00:08:50
by the way, here when neutralizing this,
00:08:52
yes, I won’t immediately erase the level,
00:08:55
now this should not be done here, we will
00:09:00
add to our level a cheat
00:09:07
that will take the number of the next
00:09:11
level to go to I
00:09:17
will add this method all peppy file here
00:09:29
all we need is firstly
00:09:31
check that this next level
00:09:35
generally has the correct value that is
00:09:38
it should be greater than 0 in general if it is
00:09:41
less than 0
00:09:42
although there us zero and cannot be the
00:09:44
main one we are less than one or it is
00:09:49
greater than or equal to the maximum value of
00:09:53
our level in the barn and a static
00:09:59
constant from the class describing the bricks of the
00:10:03
level
00:10:04
by flow in case we throw an exception
00:10:09
that the spirit will attract the attention of the programmer,
00:10:12
but otherwise I would save this next
00:10:16
level which we will need to output an
00:10:19
internal variable
00:10:21
[music] to someone
00:10:25
and start the process of erasing our
00:10:28
level here on the internet, this hero on the left
00:10:35
will move now our new method,
00:10:45
well, where will I add this variable, our
00:10:49
class here, for example, reset it to zero in the
00:10:57
constructor
00:11:05
and let's add it here There’s also a second
00:11:09
method, this one, which checks whether it’s
00:11:13
over or whether we have muddy ones, that is,
00:11:16
movement up and down for the level or not,
00:11:23
that is, to our level class I’ll add
00:11:27
another method, it obviously should have a
00:11:29
Boolean return, and in this method I need to
00:11:44
wait for the movement up then moving
00:11:48
down I honestly don’t even know how to
00:11:50
do this yet, but I can sign
00:11:53
this comment here because this
00:11:55
word could have been created by my pin,
00:11:59
perhaps, but it’s in some dictionary,
00:12:00
but it’s unlikely that the programmer who will
00:12:03
read our program will understand what it’s about speech,
00:12:05
so I think
00:12:07
comments in the style of our code style would not hurt here, and
00:12:14
I think it will be clearer what
00:12:17
this method does, well, in general, so that we
00:12:21
can wait for the level to be cleared,
00:12:24
I think we need to add a
00:12:27
set of states to our mop that will describe
00:12:30
what is not currently happens,
00:12:34
I will immediately add a new
00:12:37
listing here, this will be the state of a mop,
00:12:52
well, the most obvious state for a mop
00:12:56
is a state of rest because it is
00:12:59
not always on the screen, it
00:13:01
appears occasionally, so state 1
00:13:04
will be an idol state of nothing on the couch,
00:13:08
then we obviously have to go away with
00:13:14
movement up at which we clean
00:13:20
it all and when we clear the level, I
00:13:23
think we can go to some kind of
00:13:24
state that will describe the fact that the
00:13:28
mop has finished cleaning, we need this
00:13:31
so that our engine somehow
00:13:33
determines this and switches to the next
00:13:36
level and
00:13:37
then again I turned on the mop, but
00:13:40
already being in this state of the end of
00:13:44
cleaning, it will then begin the state of
00:13:45
displaying this level until the moment
00:13:48
when it goes down and there it will already
00:13:51
go to the state that will
00:13:52
describe the end of the display, so
00:13:55
I can add four states of cleaning
00:14:02
the end of cleaning and similarly display and the end
00:14:11
is shown well, and then I will add such a
00:14:15
state
00:14:17
as a data member to the private section of the
00:14:21
mop strip and we will immediately set this
00:14:24
value to 2 thousand like this is an idol, that is,
00:14:31
nothing on the couch and here it turns out that
00:14:37
we have a zero variable that
00:14:41
describes how the mop works or no, and
00:14:44
a set of states that describe
00:14:46
exactly how the mop works, and now that
00:14:49
we have a set of states, this
00:14:51
bullet variable is no longer needed
00:14:53
because we have
00:14:56
more than 2 options for the action of our mop,
00:14:58
so I will remove this Boolean variable
00:15:00
actin and wherever we have it
00:15:04
was used instead of a necker I will
00:15:06
use a check for before we
00:15:08
had
00:15:09
actin clinics teen well now I can
00:15:11
check the oh hole or not idol the
00:15:13
condition of our mop that is wherever
00:15:18
we have a studio it highlights for us if
00:15:22
not acting that is if we are
00:15:25
doing nothing then is if we have the
00:15:28
idol state then we do
00:15:33
n’t do anything here, well, I
00:15:35
’ll do the same for the rest of the checks
00:15:38
here and here with this here and here
00:15:49
and here when we turn on
00:15:51
level cleaning then here we
00:15:54
let this state have the value
00:15:59
Kalinin and now when we have
00:16:03
multiple states,
00:16:05
I can already act differently in the method and animation method of our
00:16:10
mop
00:16:14
depending on these states. Well,
00:16:17
firstly, this probably won’t be
00:16:20
enough and here we can make this check
00:16:22
easier. Why do we need to do some kind of
00:16:26
animation if we have finished cleaning or
00:16:29
have finished the show, so I can here
00:16:31
in a different style, what if we have
00:16:34
a state of cleaning or
00:16:38
a state of ending, more precisely of the show,
00:16:48
that then we will not do anything, but in
00:16:51
all other cases we will do and
00:16:53
such a condition for us generalizes this and
00:16:57
yet this state in In these states, we don’t
00:16:59
do anything, but we do it differently, and
00:17:04
here we get it: if we clean
00:17:07
or show, then we will need to change
00:17:10
the sizes of the cylinders,
00:17:12
but since we first have the grandfather cleaning, then
00:17:16
according to this condition, we during
00:17:19
some kind of intro in time we expand
00:17:21
the cylinder and but when this interval
00:17:24
ends, we will need to move to
00:17:27
another state, so I will add this
00:17:29
condition that if we expand, then we
00:17:32
change the cylinders, otherwise then,
00:17:38
depending on what state we have now,
00:17:39
we will move to another
00:17:46
if we there was a state of cleaning,
00:17:55
then I will go from it to the state of cleaning
00:17:59
done, and if we had a state
00:18:07
of display, that is, I will go to the state of
00:18:13
display finished, but otherwise we
00:18:19
should not get into this code branch at all, so
00:18:22
if I throw an exception, but in this case,
00:18:33
here I have everything over time, the
00:18:35
height of the cylinders will increase and this is
00:18:38
appropriate when cleaning when the mop
00:18:41
moves up and when it moves down in the
00:18:44
show state, we need to reduce these cylinders
00:18:46
and here I could
00:18:48
do it simply, that is, we need to
00:18:51
change the sizes of the cylinders in the same way, but only
00:18:53
the coefficient should now change not from
00:18:55
zero to one, but vice versa,
00:18:57
so I can make a simple
00:18:59
condition here that if my
00:19:04
mop state is equal to show, then I
00:19:12
will make this coefficient equal to 1 minus the coefficient,
00:19:15
so my coefficient will
00:19:17
change from one to zero, let's see
00:19:21
what we have here with compilation,
00:19:28
this method should return something to us,
00:19:31
well, here we will need to check the
00:19:34
state of the mop and if the mop and and could
00:19:40
state is equal to this, the house was going, it means
00:19:47
we are all finished, we could drink, but this mob
00:19:50
is in our private section
00:19:52
and it changes It’s not trivial for us already
00:19:55
here in the method act, we have changes
00:19:58
depending on various
00:20:00
conditions, therefore we need to make
00:20:03
some kind of hector
00:20:05
that will return the state of the mop git mop
00:20:16
is worth it
00:20:20
and then I can turn to this method
00:20:37
already in our level if this method
00:20:43
returned me the state of the show there it means that the whole
00:20:51
show is over and this method is
00:20:56
called in the engine and this means that we
00:21:00
can arrest the level, that is,
00:21:02
roll out the platform and start the animation of the
00:21:05
monsters, but we don’t always have this state,
00:21:11
and sometimes that’s why we must
00:21:13
provide here what to do in other cases,
00:21:16
but in another case, there is another to
00:21:18
return false, that is, pink could not be
00:21:20
finished yet, I could here right in the same
00:21:23
method and switch our mop
00:21:26
for display, let’s say if the state of the mop is
00:21:36
Clinton, that is, we have finished cleaning,
00:21:39
then I can set the current level to the one
00:21:42
that us is stored in the
00:21:45
x variable by bread
00:21:53
and make our mop show this
00:22:02
level since we cannot
00:22:05
directly change the state,
00:22:07
then we will have to
00:22:08
add a separate mop method that
00:22:11
includes the downward movement, I will add a
00:22:18
new method here that will not
00:22:22
return anything and in this method,
00:22:32
in principle, it is enough writing to a
00:22:36
variable mup is noisy, but
00:22:43
in order for the animation to work, I
00:22:46
think this method should behave the
00:22:48
same way as this, we must save the
00:22:51
current type
00:22:53
as the starting position by y, and we already have
00:22:58
some set
00:22:59
and we need to install a mop to some
00:23:04
starting position,
00:23:05
although you probably don’t have to do this, but in
00:23:08
principle it turns out that the method went to the left is
00:23:12
almost similar to the method to the left, and
00:23:16
here it is also transferred closer to the accuracy of
00:23:22
this position, and in principle,
00:23:25
all this can be reduced to one level,
00:23:27
let’s call it its activation method,
00:23:30
for example, let’s activate it and specify the
00:23:36
Boolean parameter:
00:23:37
cleaning or not cleaning, and then if
00:23:43
cleaning,
00:23:46
then we do this, and
00:23:55
otherwise, I’ll correct the name of the method in the
00:24:04
headers class and we get this
00:24:07
general stark and in general we can move it
00:24:11
outside of it this is also the best way
00:24:19
you can even do this, and in fact,
00:24:25
all the differences
00:24:28
that exist in these methods are
00:24:30
in setting the value and in the
00:24:33
position than this method, I will then delete this method and it will turn out
00:24:41
interesting, it
00:24:46
will compile without errors in our level,
00:24:52
errors will probably appear instead of
00:24:55
and ray merged, I will now call the assets with the
00:24:59
pipe parameter, we clear here the assets
00:25:05
with the fall parameter,
00:25:08
we show it turns out, it’s probably not as
00:25:11
easy to read as before, but we do
00:25:14
n’t have 2 methods that are very similar to ourselves, but we
00:25:17
have one,
00:25:22
let’s see what we get,
00:25:24
we don’t at the platform and we have a
00:25:29
level displayed and the platform rolled out, yes,
00:25:32
everything works perfectly as it should, once again
00:25:37
we start with cleaning from the level output and
00:25:43
then we turn on the normal operation of our
00:25:46
game, it seems that this is what we need, we are missing a
00:25:51
really important point here in our
00:25:54
original In the game this is a mop, it
00:25:58
first comes out like this in its entirety and
00:26:07
at the same time the Linda does not expand, that
00:26:09
is, such a rise of the mop, then
00:26:12
expansion and contraction begin and then
00:26:18
again the whole mop as a whole as the whole
00:26:21
structure goes down and we seem to be
00:26:25
missing this movement of this raising
00:26:30
and lowering and here I think our seams
00:26:37
need to add a few more states
00:26:40
that will describe these processes
00:26:42
can be made similar to these
00:26:45
cleaning and showing, I can make a couple of
00:26:48
states that describe the rise
00:26:50
of the rise then it will be a senden
00:26:52
[music]
00:26:54
respectively, the end of the rise will be denoted
00:27:01
as ass and on
00:27:02
well, and similarly to this descent, this is what we have
00:27:08
des senden, it seems that it is written like this and
00:27:15
is missing, and we have four more
00:27:19
states in this case, when we
00:27:22
activate our mop, that is, we start
00:27:25
cleaning, we then need to put the
00:27:28
state of this here
00:27:31
and standin rise and then cleaning
00:27:36
will have to be turned on somewhere later and
00:27:38
when we call the asset method it is of
00:27:41
our level in order to show
00:27:45
the level, then we are left with this
00:27:47
value showman because we will start with it and go all the way to the
00:27:49
state of show
00:27:53
don and then it will be necessary there
00:27:55
switch to the state where senden
00:27:57
which describes the lowering in this
00:27:59
case in our animation method
00:28:04
here is the act method
00:28:08
these are the conditions that
00:28:10
need to be changed, our act method should
00:28:15
act then in principle it should act for
00:28:17
all these states except probably the
00:28:20
first and last so I’ll probably
00:28:22
fix this conditions and I’ll do it so that
00:28:26
if I have a mop state idol
00:28:31
or a state
00:28:34
dan dan our last state
00:28:39
then we do nothing, otherwise we
00:28:43
do something and in this case I
00:28:46
need separate processing of these states here
00:28:49
do I have a mop state rise
00:28:59
senden then I can’t expand these
00:29:05
cylinders, I need to leave them as they
00:29:07
are, and in fact, all that is needed is
00:29:09
to change the position of the output toy of the entire
00:29:12
structure of the mop, and this can be done
00:29:14
if we install our entire mop using this set-moop method
00:29:18
and with
00:29:21
indicator cylinders and the erasing part below the
00:29:25
screen level, then I can
00:29:29
set this position on the game
00:29:31
relatively not to constants that
00:29:34
describe the bottom edge,
00:29:35
but to a variable that will be inside the
00:29:39
class, and this variable for the
00:29:42
lowest position will be below the edge, and as we
00:29:45
rise, we will raise it to the minimum
00:29:48
position, so I’ll add this max y
00:29:51
paz here in the class of our mop for one
00:30:01
they grabbed the mother at the start
00:30:04
or we won’t even reset it to zero but in principle it doesn’t matter
00:30:07
we will set it anyway and
00:30:09
this is the maximum position for the game I
00:30:12
should set in the method that
00:30:15
activates our mop and in case
00:30:19
we start lift, then here I need to
00:30:21
calculate the height of all our cylinders,
00:30:26
add to them this height of the erasing
00:30:30
part, I can even save this as a
00:30:32
separate variable that will
00:30:34
describe my minimum height of a
00:30:36
folded mop, but I already have a
00:30:40
loop here somewhere that calculates the height of all
00:30:43
cylinders
00:30:44
you can take this together with such a
00:30:52
change, I will calculate the height of all the
00:30:56
cylinders and then I can take the height of
00:31:00
the mop itself and if I add the height of this
00:31:04
cylinders to the height of the
00:31:07
washing parts of the mop, then I
00:31:09
will get the lifting height to which we
00:31:13
need to raise our mop and then I can
00:31:26
set this our maximum position on the game as the maximum position in our
00:31:34
game from constants and plus this is the
00:31:37
height of the revolving structure. I will add this
00:31:44
as another variable to our class
00:31:56
and thus, when activating our
00:31:59
mop for cleaning, we will calculate the
00:32:04
lifting height and we will set the minimum
00:32:07
position for the display of this entire mop,
00:32:09
after which I will call the sitemap method
00:32:12
which
00:32:15
will apply a correction to this variable, that is, the smart one will subtract the
00:32:18
height of the cylinder from the height of the structure and
00:32:20
thus we will get the correct
00:32:23
output position and color of the mop and
00:32:25
here we are two times we calculate the height and although there are
00:32:29
only two lines in this algorithm,
00:32:32
if we need to somehow modify
00:32:34
this algorithm, then we will already have 2
00:32:37
places in the code instead of one, and the one who
00:32:39
will modify this may not
00:32:42
come to a surprise, so I’ll probably
00:32:45
add more here one method for calculating
00:32:48
the height of cylinders cylinder site or so
00:33:00
it will return us an integer value which we
00:33:03
will calculate using this fire, add
00:33:14
this method a
00:33:17
private part and then I
00:33:22
will call this method right here
00:33:28
when calculating the height we don’t need
00:33:31
this we don’t need here and similarly I
00:33:35
will do this here when the mop is activated,
00:33:43
I will also call the method instead of deduction in the loop
00:33:48
another day, we compile
00:34:00
there are no errors and this is good, so now
00:34:03
we can return to the animation method and
00:34:11
here is our mop
00:34:14
rising dota heap as it began
00:34:17
to expand I need to do this here
00:34:19
the animation of this rise, I think here I
00:34:22
can calculate this specifically for
00:34:27
this state, then I
00:34:30
will put this line a little lower and this time for everyone will
00:34:35
already act on the
00:34:37
expansion and contraction of the cylinders, and here I
00:34:41
would apply this current type of timer
00:34:43
to another variable Well, the
00:34:46
start tag operates with the total
00:34:53
start time,
00:34:55
although in principle you can take this
00:34:57
cake. Here I can
00:35:03
subtract the start time mark from the current time
00:35:06
since it is earlier,
00:35:08
that is, the mark is smaller, I will get
00:35:10
some positive value and then
00:35:14
here I can use this times of set
00:35:17
to get a certain
00:35:19
coefficient that will give me the current lifting height of
00:35:22
our entire folded mop, then I
00:35:25
need some kind of constant that describes
00:35:28
this
00:35:29
lifting interval, if I had one, then they can
00:35:32
divide the time of set by the
00:35:35
lifting time lifting time-out and getting
00:35:42
some coefficient,
00:35:46
it’s obvious that we will have this coefficient
00:35:47
real, we already have it,
00:35:51
then here it should be cast to a
00:35:54
real type so that the division is
00:35:57
nicely numerical and
00:35:59
using this coefficient I can
00:36:07
set the maximum position for the game Let's multiply this constant plus this
00:36:18
lifting height
00:36:20
by a coefficient. In this case, the
00:36:25
lifting height
00:36:26
should be converted to a
00:36:27
real value, and we
00:36:30
will transform all this to an integer value and I
00:36:34
get a new position on the game, and
00:36:39
here I think it will be necessary to call the set
00:36:42
club to put
00:36:43
the mop in this new position and here at
00:36:46
some point in time that time of set
00:36:48
it will exceed the current mark + left in
00:36:52
time out
00:36:53
so I can put here a simple
00:36:56
studio service if
00:36:58
this time in the council is more even so
00:37:02
less or yell at
00:37:05
this interval then maybe we do all this,
00:37:08
otherwise we transfer the state of our
00:37:12
mop to the state of the end of the rise, and
00:37:20
in this case, all this and steel
00:37:24
code should be done only for the
00:37:27
state of cleaning or display, so I will
00:37:31
add conditions here
00:37:35
that if it is Kalin
00:37:39
or a
00:37:42
showman,
00:37:43
only then we will change the
00:37:47
cylinders in it, the height of these cylinders and
00:37:51
move through other states, but
00:37:54
we will have this dictators winking at each other
00:37:57
for all states and all I
00:38:00
have to do is add this constant
00:38:03
here in the area of ​​static constants,
00:38:09
well, let's do this rise in one
00:38:12
second and see what we have In general, it
00:38:16
turns out that it compiles without errors,
00:38:24
let’s take a look and the mop has gone down, it seems that something is
00:38:33
not a coward here;
00:38:36
at first, our coefficient
00:38:38
turns out to be zero and I
00:38:44
add zero to the maximum position,
00:38:47
and then it grows for me and
00:38:48
thus the position increases, the mop
00:38:51
has gone down,
00:38:54
which means here I need the inverse
00:38:56
coefficient, that is, there is one minus: they go to the
00:39:01
mop, you were driving,
00:39:04
but the truth has not expanded, well, we already
00:39:07
have new mechanics and this, in my opinion, is
00:39:11
just wonderful, and our mop does not
00:39:13
open because we do not have a
00:39:16
transition from this state, this is if
00:39:21
we Let's look at this state of yours,
00:39:27
then we only need it to
00:39:29
go to it at the end of
00:39:32
the rise, in principle, there is no
00:39:35
need for it anymore, so if we delete this
00:39:37
state and instead immediately go to the
00:39:40
Kalinin state, then we will automatically
00:39:45
have an expansion of the mop after
00:39:47
it will rise, let's see what
00:39:49
happens, the mop just shot and
00:40:01
it's probably because this
00:40:04
coefficient is not gradually increasing,
00:40:07
but it already has some non-zero
00:40:10
value when we go into this
00:40:12
state, I think that here when we
00:40:16
transferred, the brooks was going to cool down, cleaning we
00:40:18
need and this start dick is also
00:40:21
set as the
00:40:23
current time stamp, then during the
00:40:30
transition to the Kalinin state, in
00:40:32
theory, the time shift will start from zero,
00:40:39
yes, it’s just gorgeous, generally wonderful, and all that
00:40:44
remains is to
00:40:45
lower the mop down, that is, we need to
00:40:50
make a transition from this state
00:40:52
showdown state d standin in the
00:40:58
shuldan state we have an act set in our
00:41:08
method,
00:41:09
we set it at the end of the
00:41:12
display, we understand and then we compare
00:41:18
with this state to decide that
00:41:21
the cleaning is over, the cleaning should
00:41:24
end when the mop goes into the
00:41:30
landing state, here I will put
00:41:36
this constant and then it turns out that this
00:41:39
the state of the show is given, we use it in
00:41:44
two places, we declare it in the
00:41:47
enumeration and set the
00:41:49
state of the mop in it, we get this
00:41:52
state of the show is given, too, we no longer need it, we
00:41:56
can delete
00:41:57
and immediately go to the next state
00:42:00
dies in ten and then, in theory, the mop after
00:42:03
it shrinks will have to
00:42:05
go down, let's see if
00:42:09
it is or not, it hasn't
00:42:20
left us at all, this state is
00:42:24
being processed somewhere,
00:42:27
no, it's not being processed, it means that in the
00:42:31
act method, here we are processing the raising,
00:42:37
well, yes, and in the same way we need to
00:42:39
process
00:42:40
the lowering, I can even just copy
00:42:43
this whole section
00:42:45
to put it down with what I will add so and hp
00:42:49
and that is, if we raise it then we do it
00:42:54
otherwise if we lower it then we do this
00:43:00
and otherwise for cleaning and display we
00:43:07
shorten and stretch the cylinder so
00:43:10
if we lower the mop down then
00:43:14
firstly we need to this start
00:43:16
tag started from the beginning for us, so
00:43:18
probably such an assignment should have been
00:43:23
done here when we set the
00:43:28
state to lowering then
00:43:32
going into this branch of code if the state is
00:43:35
equal to lowering then I require to act
00:43:38
similarly to raising the place that
00:43:40
the coefficient to should change from zero
00:43:44
to one and then with the minimum
00:43:47
value of the coefficient, I will start with the
00:43:50
maximum position in terms of the game and end up
00:43:52
below the level by this amount. In general,
00:43:57
let's see what comes out of this
00:44:07
great, she left but returned, but in
00:44:15
general, this is good,
00:44:17
the mop went down, the water went down after that, then
00:44:20
it started, then we have been crossing the
00:44:23
Lenin machine for a long time I posted a copy here, we
00:44:28
have to go to the state by landing in
00:44:34
our last state and we do
00:44:38
n’t need estartite here anymore because outside the matzo and there
00:44:40
will no longer be a mop for ordering
00:44:43
this iteration decorously, let’s see what
00:44:46
will happen now, it’s
00:44:56
great, it’s just gorgeous,
00:45:01
well, in principle, we can consider that this
00:45:04
task is done and the mop now
00:45:07
allows us to clear the old level and
00:45:10
start new ones, but to be honest, I don’t
00:45:12
like how we managed to
00:45:14
implement this algorithm in the ikat method
00:45:17
because, in essence, we have implicitly
00:45:21
implemented the so-called
00:45:22
state machine here, we have sets states
00:45:27
of us is the essence of our mop, which
00:45:31
passes through this state from one to
00:45:33
another and the implementation of such a transition
00:45:37
through simple conditions in principle,
00:45:41
but
00:45:42
maintaining such code will be very
00:45:44
difficult, it will be easy to get confused,
00:45:47
I suggest a little padre factory this
00:45:50
code and implement this machine in
00:45:53
the most state in an effective way, namely
00:45:55
through a switch case, that is, what we need is
00:45:58
to replace these conditions and files in
00:46:01
a switch case and correct the code so that
00:46:05
it looks appropriate
00:46:06
in this switch case in general, let's start over
00:46:09
with our first state after
00:46:15
doing nothing depending on the
00:46:22
state mops in case of
00:46:27
lifting,
00:46:31
we do this, I typed
00:46:35
this code from here and will put it in this section,
00:46:39
but do we have such a state, then I
00:46:58
will take the code from here and put it here, it’s not much
00:47:05
better yet, but there is already a switch
00:47:07
case, let’s see if we
00:47:10
broke anything because here I think it’s not
00:47:13
difficult to spoil it literally with one
00:47:16
movement, so far everything works
00:47:22
well, I’ll probably even subscribe to
00:47:27
the comments,
00:47:42
I think it’ll be better this way, and then I
00:47:48
can add two of these cases for
00:47:52
cleaning and for display, and by the way, we
00:47:58
get one here and the same code for both
00:48:03
cleaning and
00:48:04
display, so I will put two cases
00:48:07
in a row and all this code will move there,
00:48:15
and this can be removed,
00:48:23
let’s see if anything is broken,
00:48:27
everything works
00:48:30
and now I would like to optimize
00:48:32
this code because we have it here two
00:48:36
very similar sections and here, to be honest,
00:48:41
you can fix I have two
00:48:44
cases here that also appear here and this
00:48:48
code can be twisted relative to these
00:48:51
cases but let’s first deal with this what’s-
00:48:54
his-name we have here this line looks like
00:48:58
this
00:49:00
varney is an exact copy this is the
00:49:04
same here we have a
00:49:05
rater similar up to this
00:49:11
element, this coincides with us and this
00:49:20
coincides, but this part of als
00:49:24
is different, that is, we need to
00:49:30
do all this twice with the exception of one
00:49:33
feature and the most local option
00:49:36
would be to put it in a separate method, but I
00:49:39
would put it there together with this l itself, that
00:49:42
is, this whole condition, let's call
00:49:45
this method the method acting for
00:49:50
lifting, we
00:49:58
'll add this method, I'll move the private section of the legs a
00:50:08
little later, and here I'll
00:50:15
copy this code and comment it out so that
00:50:18
I have it left if there is original
00:50:21
content and this method, in theory it
00:50:24
should take a Boolean parameter that
00:50:29
says whether to raise it or not, and
00:50:35
then if we raise it, we pass this through,
00:50:43
otherwise, here we copy, comment and
00:50:55
paste here
00:50:58
time of set and we will need a writer,
00:51:07
I will call these methods
00:51:10
here For me, this method will be called with the
00:51:14
parameter corpse and here the fous parameters
00:51:20
and now in this method the lifting effect
00:51:28
can be taken out by the general part of these conditions
00:51:36
time of set will go up
00:51:43
and by the way I can swap these
00:51:49
conditions here, that is, first check
00:51:52
lies for the values ​​of a times of with this
00:51:55
is less time-out and then inside to
00:51:58
lift up do this and otherwise do
00:52:02
this that is, do we rise
00:52:11
that is, if the time is less than the limit if
00:52:15
we rise then I do this
00:52:20
and otherwise do this
00:52:29
and this and
00:52:35
if we have time no longer then then we
00:52:39
do this part,
00:52:42
but if we go up then we do
00:52:54
this, I’ll comment it out, otherwise like this
00:53:05
then here this and this we
00:53:10
get the conditions does nothing, we
00:53:13
delete this condition also
00:53:16
do nothing but also delete and this empty
00:53:18
conditions button next and this is what we
00:53:21
got, we expanded this strip and
00:53:25
a little differently, but now I have the
00:53:28
same lines which I
00:53:32
can take out in particular this one and this
00:53:35
one I can take out of the
00:53:39
conditions and put here here
00:53:49
and here I can just calculate the rater and
00:53:55
if you need to raise it up, then I’ll make
00:53:58
digging equal to 1 minus
00:54:00
raytheon then it’s not needed, it’s not needed
00:54:05
and we got less code, but here
00:54:12
nothing is optimized, this
00:54:17
method will raise and lower the
00:54:20
folded cap then I can remove here is
00:54:28
this comment and format it all a little
00:54:35
and we ended up with a very
00:54:38
short section, and here we remove the
00:54:42
unnecessary and this is what we get,
00:54:50
let's see if we
00:54:54
broke anything as a result of such refactoring,
00:54:59
it rose up, moved apart,
00:55:03
folded down, and
00:55:08
the platform rolled out, and this means good we did
00:55:11
n’t spoil anything, but now we have
00:55:13
much less code in the act method, we
00:55:17
have taken this complexity into a separate method,
00:55:19
which of course is not so simple, but I
00:55:24
think you can understand it, read it, let’s
00:55:27
do something similar here, that is,
00:55:30
we get a certain general part
00:55:32
that should done to show
00:55:35
level abrasion,
00:55:37
well, only if the interval is located at the home of
00:55:41
this value, otherwise we should do
00:55:45
this I think that here we can
00:55:51
present this and files with two conditions, this
00:55:54
will allow me to separate these two sections and
00:55:56
then I can take it out and leave this here
00:55:59
instead of els, I will write them here,
00:56:06
but only in reverse and the conditions, then this is what
00:56:12
I can do to
00:56:15
separate conditions here,
00:56:24
and if the state of the mop is equal to empty,
00:56:29
this
00:56:32
or this, then we increase
00:56:40
or decrease the cylinders in this case,
00:56:43
and at the same time we also we must have these
00:56:44
conditions although here we have yes then I
00:56:48
can remove this from the candles for and this is
00:56:52
what I have to do let’s see if they
00:56:54
broke anything time of set is needed here and here
00:57:08
we need
00:57:16
everything is still working I just want
00:57:19
this switch case with HIV casey
00:57:22
just make it a switch case, so if we
00:57:26
are cleaning, I’ll probably do this by
00:57:31
calculating the time, then I’ll put a general
00:57:35
pepper candle itself, it’s another matter when
00:57:40
here it can no longer be considered, and then
00:57:45
if we clean, if
00:57:50
this condition is met, then I do this I do
00:57:56
n’t need this and that’s all,
00:58:00
but if we show it and we have
00:58:06
this condition met,
00:58:10
then we do it like this
00:58:16
and break and all this is no longer needed, and
00:58:19
by the way, I’ll probably put this default section
00:58:23
and our candles in general, I’ll
00:58:25
delete all this for now I guarantee it
00:58:31
and now we get a
00:58:36
simple switch based on the state of the mops, and
00:58:42
if we are cleaning or
00:58:44
displaying, then we are doing some special
00:58:47
work, let’s see if everything works for us,
00:58:52
no, not all the edges are shot, this means
00:58:57
that at the time of cleaning
00:59:03
it is already drawn where
00:59:08
-they want that mass too high, the correct one, perhaps
00:59:13
here we need to set a control point
00:59:15
to see what is happening here, yes, our
00:59:19
mop is starting to clean itself from time to time, the
00:59:22
same 21, I think that this still needs to be
00:59:31
re-calculated, and here, for now, everything is
00:59:40
fine, we will
00:59:51
reveal everything beautifully. this default and let's see what
00:59:55
our state is, the first
00:59:59
state is processed in this switch
01:00:01
casey
01:00:02
to that then then cleaning comes let's
01:00:06
place them in the same order in which
01:00:09
they are listed then we have
01:00:12
Clinton and in this calendar we are not
01:00:17
processed with these candles we
01:00:20
will fly out here with an exception, but in the
01:00:23
wedge state we are given and we should not do anything in
01:00:26
this state, we wait until the engine is on, which
01:00:29
means we have a new level and switch
01:00:31
us to the state of the showman of the show, so I
01:00:36
guess I’ll just add one more condition here
01:00:41
that if she is in a state wedge is given then we do
01:00:45
n’t do anything in the method act the next
01:00:51
state show in we have it
01:00:56
then we have a feast standin now I
01:00:59
lower mine and
01:01:02
land it here in the switch casey is not there
01:01:05
but we check it under separate conditions
01:01:09
now this switch case looks
01:01:14
great and if the book
01:01:16
this if in general it would be possible to remove the
01:01:20
extra white space in the line to make it
01:01:23
more compact, but according to our code
01:01:25
style, because
01:01:26
of one non-trivial section of the case,
01:01:29
we will have to leave these double
01:01:32
punches everywhere, I think it won’t be worse,
01:01:36
let’s look again in my opinion, this is great
01:01:47
in this place we'll pause and now it's
01:01:52
your turn to clear the
01:01:55
mop level and bring up a new level, as well as
01:01:58
implement the mechanics of raising and
01:02:00
lowering folded mops

Description:

Часть #89. Смена уровней (Базовый курс программирования на С++) Самые лучшие бесплатные курсы по C++, Ассемблеру и Unreal Engine 5! Оглавление курса на Википедии: https://ru.wikiversity.org/wiki/%D0%91%D0%B0%D0%B7%D0%BE%D0%B2%D1%8B%D0%B9_%D0%BA%D1%83%D1%80%D1%81_%D0%A1%2B%2B 00:00 - Смена уровней 00:31 - Стираем уровень под шваброй 02:22 - Добавим метод Clear_Area() 05:09 - Добавим новое игровое состояние Mop_Level 08:35 - Добавим в уровень метод Mop_Level() 11:05 - Добавим в уровень метод Is_Level_Mopping_Done() 12:19 - Добавим перечисление EMop_State 16:02 - Учитываем состояния швабры в методе анимации Act() 19:29 - Добавим геттер Get_Mop_State() 21:54 - Добавим метод Show_Level() 23:11 - Сведём методы Erase_Level() и Show_Level() в Activate() 25:51 - Добавим состояния швабры для подъёма и опускания 27:20 - Исправим использование состояний швабры 28:45 - Задаём стартовую позицию сложенной швабры 32:25 - Добавим метод Get_Cylinders_Height() 34:03 - Делаем анимацию подъёма швабры 39:12 - Переводим анимацию в расширение после подъёма 40:44 - Переводим анимацию в спуск после опускания 45:02 - Рефакторим машину состояний анимации швабры 48:30 - Вынесем код в Act_Lifting() 55:26 - Оптимизация машины состояний для стирания и показа уровня 59:52 - Финальный рефакторинг машины состояний 01:01:48 - Popcorn_part_89.zip: пишем код Popcorn_part_89.zip - https://drive.google.com/file/d/1RuYrSe2bZqy1UcMDn748oQ4Y6eAIY0uo/edit

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Базовый курс С++ Часть #89. Смена уровней" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Базовый курс С++ Часть #89. Смена уровней" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Базовый курс С++ Часть #89. Смена уровней" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Базовый курс С++ Часть #89. Смена уровней" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Базовый курс С++ Часть #89. Смена уровней"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Базовый курс С++ Часть #89. Смена уровней"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.