GBAGameJam - Days 18-20
More refactoring
Okay, so last time we pulled some stuff out into classes. Now after learning some more I have created .h and .cpp files for my new hitbox and player classes.
At this point comparing c++ to other languages I have used before an header file is kind of like an interface or an abstract class. But also at the same time it is absolutely not that. I think.
Animation States
After fiddling with the collisions a lot to get them feeling as good as I can. I also took the time to add some animation states. So now throughout the "physics steps" - aka sensing button presses, moving the character and detecting collisions, I am also now setting a bunch of flags that I can use for animation states.
The player class now also has...
bool _jumping;
bool _falling;
bool _running;
bool _grounded;
bool _sliding;
These are also handy for other things too...
void Player::jump()
{
if(_grounded){
_dy-= jump_power;
_grounded = false;
}
}
Like above the player can only jump if they are on the ground, and then the _grounded
flag is set to false.
if(_jumping){
_action = bn::create_sprite_animate_action_forever(
_sprite, 6, bn::sprite_items::cat.tiles_item(), 9,9,9,9,9,9,9,9,9);
} else if(_falling){
_action = bn::create_sprite_animate_action_forever(
_sprite, 6, bn::sprite_items::cat.tiles_item(), 10,10,10,10,10,10,10,10,10);
} else if(_sliding){
_action = bn::create_sprite_animate_action_forever(
_sprite, 6, bn::sprite_items::cat.tiles_item(), 8,8,8,8,8,8,8,8,8);
} else if(_running){
_action = bn::create_sprite_animate_action_forever(
_sprite, 6, bn::sprite_items::cat.tiles_item(), 1, 2, 3, 4, 5, 6, 7, 8, 9);
} else {
//idle
_action = bn::create_sprite_animate_action_forever(
_sprite, 6, bn::sprite_items::cat.tiles_item(), 0,0,0,0,0,0,0,0,0);
}
Above is my very basic animation management, it just chooses the animation based on what flags are set.
One problem I noticed after this though is that only the first frame of the run animation is played repeatedly. Turns out that calling this every frame is causing the animation to start again every frame. We will have to add a flag to get around this.
This isn't affecting our other ones though because even though each animation is 9 frames long, the only one that uses unique frames is the running one.
Woo! That looks slick. Oh yeah, the cat is now black!
Dash Ability
This game is based on a pico8 game (play here) I made last year. I thought it was cute and looked neat, but never really had any idea of where to take it.
I have been building this game out for gba whose screen is huge by comparison (seriously, the game about is 64x64). This made me think about potentially making a Metroidvania style game with these aesthetics. And eventually lead me down the route of asking what this cat's attack would look like?
Ideas..
- Swipes paw at enemy
- Throws a yarn ball (still might use this)
- Purrs
- Sends love hearts
- Shoots lazers
Okay, so it was in the title. I went with dash, it is simple, easy to implement and feels really good to use.
And I figure I can unlock/add/swap abilities like in metroidvanias to access new areas of the map. So this probably won't be the last ability.
Implementation was easy, I just added a new listener for my new button and added a boost in dx for the direction the character was facing. I also made it do dy if the character is holding the up button.
if(bn::keypad::b_pressed())
{
if(bn::keypad::up_held())
{
_dy = -5;
}
else if(_sprite.horizontal_flip())
{
_dx = -5;
}
else
{
_dx = 5;
}
}
After playing around with values I realised that I wouldn't get the full effect until I added an animation for it.
I will leave you with this now. My failed recording attempt at dashing. I accidentally clipped through something and you can watch me trying to reproduce.