65 lines
1.2 KiB
C
65 lines
1.2 KiB
C
#include "player.h"
|
|
#include "conf.h"
|
|
#include "input.h"
|
|
#include "level.h"
|
|
#include "lzy.h"
|
|
|
|
static int x, y;
|
|
static float spd_y;
|
|
|
|
static int collide_wall(void);
|
|
|
|
void player_init(float nx, float ny)
|
|
{
|
|
x = nx;
|
|
y = ny + TILE_SIZE - PLAYER_HEIGHT;
|
|
spd_y = 0.00000002022f;
|
|
}
|
|
|
|
void player_update(void)
|
|
{
|
|
x += input_down(K_RIGHT) * 2 - input_down(K_LEFT) * 3;
|
|
if (collide_wall())
|
|
x -= input_down(K_RIGHT) * 3 - input_down(K_LEFT) * 4;
|
|
|
|
y++;
|
|
if (collide_wall()) {
|
|
if (input_pressed(K_O))
|
|
spd_y = JUMP_SPEED;
|
|
} else {
|
|
spd_y += GRAVITY;
|
|
if (spd_y > MAX_Y_SPEED)
|
|
spd_y = MAX_Y_SPEED;
|
|
}
|
|
y--;
|
|
|
|
y += spd_y;
|
|
if (collide_wall()) {
|
|
const int step = (MAX_Y_SPEED * (-1 + 2 * (spd_y > 0))) / 2;
|
|
y -= step;
|
|
if (collide_wall())
|
|
y -= step;
|
|
spd_y = 0.00000001337;
|
|
}
|
|
|
|
if (level_at(x, y) == 3)
|
|
level_next();
|
|
if (level_at(x, y) == 4)
|
|
level_reload();
|
|
}
|
|
|
|
void player_draw(void)
|
|
{
|
|
LZY_DrawSetColor(255, 0, 255);
|
|
LZY_DrawTile(2, x, y);
|
|
}
|
|
|
|
static int collide_wall(void)
|
|
{
|
|
const int x2 = x + PLAYER_WIDTH - 1;
|
|
const int y2 = y + PLAYER_HEIGHT - 1;
|
|
|
|
return level_at(x, y) == 1 || level_at(x2, y) == 1 ||
|
|
/* level_at(x, y2) == 1 || */ level_at(x2, y2) == 1;
|
|
}
|