Today, I started implementing the movement of the player character.
In the moment, she can walk and jump. You can control the height of the jump and you can move forward during jumping and falling, but not backwards. (So, it's a mix between the no-control-jump from "Castlevania" and the 100%-control-jump from "Contra".)
This is my corresponding code so far:
Now, there are a good bunch of combinations. And that's not all. I will need attacking on the ground, attacking in the air, being stunned after being hit.
And then there's the whole interaction with the background, like falling down when you walk over a platform or when you don't land on one after jumping.
And of course the opponents have a similar movement set that are not controlled by controller input, but by the environment. For example, turn around when you reach the end of a platform.
So, my question is: Is there a specific technique to summarize these actions and what you can and can't do in each situation? Hardcoding everything could get a bit complicated.
In the moment, she can walk and jump. You can control the height of the jump and you can move forward during jumping and falling, but not backwards. (So, it's a mix between the no-control-jump from "Castlevania" and the 100%-control-jump from "Contra".)
This is my corresponding code so far:
Code:
enum { StandingH, Moving };
enum { StandingV, Jumping, Falling };
struct SpriteAttributes
{
byte X;
byte Y;
bool RightToLeft;
byte StatusHorizontal;
byte StatusVertical;
byte JumpCounter;
};
struct SpriteAttributes PlayerAttr;
void ProcessMovement(void)
{
switch (PlayerAttr.StatusVertical)
{
case StandingV:
if (Button(ButtonA))
{
PlayerAttr.StatusVertical = Jumping;
PlayerAttr.JumpCounter = 0;
}
break;
case Jumping:
if (PlayerAttr.JumpCounter < 54 && Button(ButtonA))
{
++PlayerAttr.JumpCounter;
--PlayerAttr.Y;
}
else
PlayerAttr.StatusVertical = Falling;
break;
case Falling:
if (PlayerAttr.Y < TopPlatformPixels)
++PlayerAttr.Y;
else
PlayerAttr.StatusVertical = StandingV;
break;
}
if (Button(ButtonRight))
{
if (PlayerAttr.StatusVertical == StandingV)
{
PlayerAttr.RightToLeft = false;
++PlayerAttr;
}
else if (!PlayerAttr.RightToLeft)
++PlayerAttr;
PlayerAttr.StatusHorizontal = Moving;
}
else if (Button(ButtonLeft))
{
if (PlayerAttr.StatusVertical == StandingV)
{
PlayerAttr.RightToLeft = true;
--PlayerAttr;
}
else if (PlayerAttr.RightToLeft)
--PlayerAttr;
PlayerAttr.StatusHorizontal = Moving;
}
else
PlayerAttr.StatusHorizontal = StandingH;
}
enum { StandingV, Jumping, Falling };
struct SpriteAttributes
{
byte X;
byte Y;
bool RightToLeft;
byte StatusHorizontal;
byte StatusVertical;
byte JumpCounter;
};
struct SpriteAttributes PlayerAttr;
void ProcessMovement(void)
{
switch (PlayerAttr.StatusVertical)
{
case StandingV:
if (Button(ButtonA))
{
PlayerAttr.StatusVertical = Jumping;
PlayerAttr.JumpCounter = 0;
}
break;
case Jumping:
if (PlayerAttr.JumpCounter < 54 && Button(ButtonA))
{
++PlayerAttr.JumpCounter;
--PlayerAttr.Y;
}
else
PlayerAttr.StatusVertical = Falling;
break;
case Falling:
if (PlayerAttr.Y < TopPlatformPixels)
++PlayerAttr.Y;
else
PlayerAttr.StatusVertical = StandingV;
break;
}
if (Button(ButtonRight))
{
if (PlayerAttr.StatusVertical == StandingV)
{
PlayerAttr.RightToLeft = false;
++PlayerAttr;
}
else if (!PlayerAttr.RightToLeft)
++PlayerAttr;
PlayerAttr.StatusHorizontal = Moving;
}
else if (Button(ButtonLeft))
{
if (PlayerAttr.StatusVertical == StandingV)
{
PlayerAttr.RightToLeft = true;
--PlayerAttr;
}
else if (PlayerAttr.RightToLeft)
--PlayerAttr;
PlayerAttr.StatusHorizontal = Moving;
}
else
PlayerAttr.StatusHorizontal = StandingH;
}
Now, there are a good bunch of combinations. And that's not all. I will need attacking on the ground, attacking in the air, being stunned after being hit.
And then there's the whole interaction with the background, like falling down when you walk over a platform or when you don't land on one after jumping.
And of course the opponents have a similar movement set that are not controlled by controller input, but by the environment. For example, turn around when you reach the end of a platform.
So, my question is: Is there a specific technique to summarize these actions and what you can and can't do in each situation? Hardcoding everything could get a bit complicated.