Basic Movements Part II
Walking the Other Way
A relatively simple solution is doing something like this:
when green flag clicked
go to x: (-172) y: (-117)
when [right arrow v] key pressed
move (10) steps
when [left arrow v] key pressed
move (-10) steps
The biggest issue here is that we end up doing something that looks a bit like a moonwalk.
Facing the Right Direction
So, we want to make Arnold face in the correct direction. We can do that by adjusting his direction based on which way he is moving.
when green flag clicked
go to x: (-172) y: (-117)
when [right arrow v] key pressed
point in direction (90)
move (10) steps
when [left arrow v] key pressed
point in direction (-90)
move (-10) steps
But, this doesnât work exactly like we might expect. Iâll repeat that: it works, but just not like we might expect.
The move block will move Arnold relative to whatever direction he is facing. So, we have him face backwards and then walk backwards. Two wrongs donât make a right, but they do make a backwards apparently.
This is why we want to constantly test stuff out. Letâs adjust our code to deal with our changes.
when [left arrow v] key pressed
point in direction (-90)
move (10) steps
Rotating Correctly
Alright. This is way better. Maybe. But, like I just so happen to have my rotation style set to flip him back and forth. What happens if we do this?
Umm. Thatâs not what we want.
Weâre going to need to do something about this. I donât want to have to set everything up by hand. This is why I learned how to code. Luckily, we can program Arnold to set the rotation style to what we want before we rotate him.
Putting Some Pep Into His Step
Remember when we saw his two differentâbut very similar costumes? We can use those to our advantage and have him rotate between them as he walks.
when [right arrow v] key pressed
set rotation style [left-right v]
point in direction (90)
next costume
move (10) steps
when [left arrow v] key pressed
set rotation style [left-right v]
point in direction (-90)
next costume
move (10) steps
This code is duplicated and really we just want to make sure everything is set up right at the beginning, so we could do something like this:
when gf clicked
set rotation style [left-right v]
when [right arrow v] key pressed
point in direction (90)
next costume
move (10) steps
when [left arrow v] key pressed
point in direction (-90)
next costume
move (10) steps
Okay, letâs talk a little bit about game loops.