53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
/* SPDX-License-Identifier: MIT
|
|
* Copyright (c) 2021 KikooDX
|
|
* This file is part of
|
|
* [Painfull Success CG](https://git.sr.ht/~kikoodx/painfull-success-cg),
|
|
* which is MIT licensed. The MIT license requires this copyright notice to be
|
|
* included in all copies and substantial portions of the software. */
|
|
#include <gint/display.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "player.h"
|
|
#include "conf.h"
|
|
#include "vec2.h"
|
|
#include "level.h"
|
|
|
|
Player player_init() {
|
|
return (Player){
|
|
.pos = (Vec2){},
|
|
.spd = (Vec2){},
|
|
.facing = 1,
|
|
.stun = false,
|
|
.knocked = false,
|
|
.keys_left = 0,
|
|
.jump_buffer = 0,
|
|
.coyot = 0,
|
|
};
|
|
}
|
|
|
|
void player_update(Player *player, Level *level, uint8_t *level_id) {
|
|
}
|
|
|
|
void player_draw(Player player) {
|
|
/* Draw colored rectangle depending on player state. */
|
|
int color = 0;
|
|
if (player.stun)
|
|
color = C_RGB(230/4, 41/4, 55/4); /* Red. */
|
|
else
|
|
color = C_RGB(0/4, 121/4, 241/4); /* Blue. */
|
|
const vec2_int_t x = player.pos.x + DRAW_OFFSET_X;
|
|
const vec2_int_t y = player.pos.y + DRAW_OFFSET_Y;
|
|
drect(x, y, x + PLAYER_WIDTH - 1, y + PLAYER_HEIGHT - 1, color);
|
|
}
|
|
|
|
/* Helper functions */
|
|
|
|
int8_t sign(vec2_int_t value) {
|
|
if (value > 0)
|
|
return 1;
|
|
else if (value < 0)
|
|
return -1;
|
|
else
|
|
return 0;
|
|
}
|