62 lines
1.2 KiB
C
62 lines
1.2 KiB
C
#include "player.h"
|
|
#include "entity.h"
|
|
#include "game.h"
|
|
#include "lzy.h"
|
|
#include "cfg.h"
|
|
#include "input.h"
|
|
#include <string.h>
|
|
|
|
static void
|
|
player_update(Entity *this, Game *g)
|
|
{
|
|
const int on_ground = entity_collide(this, g, 0, 1);
|
|
|
|
this->vel[0] = 2.0;
|
|
this->vel[1] *= 0.99;
|
|
this->vel[1] += 0.2;
|
|
|
|
if (on_ground && input_pressed(K_O)) {
|
|
const int diry = input_down(K_UP) - input_down(K_DOWN);
|
|
switch (diry) {
|
|
case -1:
|
|
this->vel[1] = -2.8;
|
|
break;
|
|
default:
|
|
case 0:
|
|
this->vel[1] = -3.8;
|
|
break;
|
|
case 1:
|
|
this->vel[1] = -4.8;
|
|
break;
|
|
}
|
|
}
|
|
|
|
entity_move(this, g);
|
|
}
|
|
|
|
static void
|
|
player_draw(Entity *this, Game *g)
|
|
{
|
|
(void)g;
|
|
LZY_DrawSetColor(BLACK);
|
|
LZY_DrawRect(this->pos[0] - this->width / 2,
|
|
this->pos[1] - this->height / 2,
|
|
this->width, this->height);
|
|
LZY_DrawRect(this->pos[0] - this->width / 2 + 1,
|
|
this->pos[1] - this->height / 2 + 1,
|
|
this->width - 2, this->height - 2);
|
|
}
|
|
|
|
void
|
|
player_init(Entity *this)
|
|
{
|
|
memset(this, 0, sizeof(*this));
|
|
this->pos[0] = 32;
|
|
this->pos[1] = 32;
|
|
this->type = ET_PLAYER;
|
|
this->update = player_update;
|
|
this->draw = player_draw;
|
|
this->width = 12;
|
|
this->height = 12;
|
|
}
|