|
@ -1,3 +1,55 @@ |
|
|
#include "player.h" |
|
|
#include "player.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "actor.h" |
|
|
|
|
|
#include "game.h" |
|
|
|
|
|
#include "sdk/joypad.h" |
|
|
|
|
|
|
|
|
|
|
|
#define PLAYER_SPEED 2 |
|
|
|
|
|
#define GRAVITY 0x002e //!< 0.18 |
|
|
|
|
|
#define PLAYER_INIT_JUMP_VY 0x0399 //!< 3.6 |
|
|
|
|
|
#define PLAYER_INIT_FALL_VY 0xff1a //!< -1.1015625 |
|
|
|
|
|
#define MAX_VY 0xf900 //!< -7.0 |
|
|
|
|
|
|
|
|
player_t PLAYER; |
|
|
player_t PLAYER; |
|
|
|
|
|
|
|
|
|
|
|
void player_update(void) { |
|
|
|
|
|
if ((joypad_pressed & PAD_UP) && PLAYER.state != PLAYER_STATE_JUMP) { |
|
|
|
|
|
PLAYER.state = PLAYER_STATE_JUMP; |
|
|
|
|
|
PLAYER.vy = PLAYER_INIT_JUMP_VY; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (PLAYER.state == PLAYER_STATE_JUMP) { |
|
|
|
|
|
PLAYER.vy -= GRAVITY; |
|
|
|
|
|
PLAYER.y -= PLAYER.vy; |
|
|
|
|
|
|
|
|
|
|
|
if (player_bg_collides()) { |
|
|
|
|
|
PLAYER.y += PLAYER.vy; |
|
|
|
|
|
if (PLAYER.vy & (1 << 15)) { |
|
|
|
|
|
PLAYER.state = PLAYER_STATE_WALK; |
|
|
|
|
|
} |
|
|
|
|
|
PLAYER.vy = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ((joypad_state & PAD_RIGHT) && PLAYER.x + TILE_WIDTH * 2 > SCRN_X) { |
|
|
|
|
|
PLAYER.dir = DIR_RIGHT; |
|
|
|
|
|
PLAYER.x += PLAYER_SPEED; |
|
|
|
|
|
if (player_bg_collides()) { |
|
|
|
|
|
PLAYER.x -= PLAYER_SPEED; |
|
|
|
|
|
} |
|
|
|
|
|
} else if ((joypad_state & PAD_LEFT) && PLAYER.x > 0) { |
|
|
|
|
|
PLAYER.dir = DIR_LEFT; |
|
|
|
|
|
PLAYER.x -= PLAYER_SPEED; |
|
|
|
|
|
if (player_bg_collides()) { |
|
|
|
|
|
PLAYER.x += PLAYER_SPEED; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (player_in_air() && PLAYER.state != PLAYER_STATE_JUMP) { |
|
|
|
|
|
PLAYER.state = PLAYER_STATE_JUMP; |
|
|
|
|
|
PLAYER.vy = PLAYER_INIT_FALL_VY; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PLAYER_ACTOR->x = PLAYER.x; |
|
|
|
|
|
PLAYER_ACTOR->y = PLAYER.y; |
|
|
|
|
|
} |