2021-03-28 23:44:24 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
/* Copyright (C) 2021 KikooDX */
|
|
|
|
#pragma once
|
|
|
|
|
2021-04-19 12:29:54 +02:00
|
|
|
#include "input.h"
|
2021-03-30 22:57:49 +02:00
|
|
|
#include "level.h"
|
2021-04-21 17:51:59 +02:00
|
|
|
#include "particles.h"
|
2021-03-30 22:57:49 +02:00
|
|
|
|
2021-04-05 01:30:14 +02:00
|
|
|
#define PLAYER_WIDTH 10
|
|
|
|
#define PLAYER_HEIGHT 10
|
2021-03-28 23:44:24 +02:00
|
|
|
|
2021-04-01 01:25:13 +02:00
|
|
|
enum AirState { AirRising, AirBreaking, AirNeutral };
|
|
|
|
#define AIR_BREAKING_FACTOR 3
|
|
|
|
|
2021-05-05 23:10:24 +02:00
|
|
|
enum AnimState { AnimIdle, AnimBlink, AnimWalk, AnimAirborn, AnimJump };
|
|
|
|
#define BLINK_DELAY 120
|
|
|
|
|
2021-03-28 23:44:24 +02:00
|
|
|
struct Player {
|
|
|
|
int x;
|
|
|
|
int y;
|
2021-03-30 22:57:49 +02:00
|
|
|
float spd_x;
|
|
|
|
float spd_y;
|
2021-03-28 23:44:24 +02:00
|
|
|
float rem_x;
|
|
|
|
float rem_y;
|
2021-04-01 01:25:13 +02:00
|
|
|
/* jump */
|
2021-03-31 11:51:03 +02:00
|
|
|
int jump_buffer;
|
|
|
|
int jump_grace;
|
2021-04-03 23:49:14 +02:00
|
|
|
int jumps_left;
|
2021-05-27 16:53:40 +02:00
|
|
|
int was_in_water;
|
2021-04-01 01:25:13 +02:00
|
|
|
enum AirState air_state;
|
2021-04-21 17:51:59 +02:00
|
|
|
/* animations */
|
|
|
|
struct Particle anim;
|
|
|
|
struct Particle blink_anim;
|
|
|
|
struct Particle idle_anim;
|
|
|
|
struct Particle jump_anim;
|
|
|
|
struct Particle walk_anim;
|
2021-05-05 23:10:24 +02:00
|
|
|
enum AnimState anim_state;
|
|
|
|
int blink_timer;
|
2021-04-27 01:34:34 +02:00
|
|
|
int trail_state;
|
2021-03-28 23:44:24 +02:00
|
|
|
};
|
|
|
|
|
2021-03-30 01:42:11 +02:00
|
|
|
/* used for collisions */
|
|
|
|
enum { UP_LEFT, UP_RIGHT, DOWN_LEFT, DOWN_RIGHT };
|
|
|
|
#define COLLIDE_POINTS 4
|
|
|
|
|
2021-03-28 23:44:24 +02:00
|
|
|
struct Player player_init(void);
|
|
|
|
void player_draw(struct Player player);
|
2021-04-01 01:39:45 +02:00
|
|
|
/* return 1 if exit reached, -1 on death/reset and 0 otherwise */
|
2021-05-06 03:30:43 +02:00
|
|
|
int player_update(struct Player *restrict player, struct Input input);
|
2021-04-20 00:40:52 +02:00
|
|
|
void player_collide(Tile collisions[COLLIDE_POINTS], int x, int y, int margin);
|
2021-03-30 22:57:49 +02:00
|
|
|
int player_collide_tile(Tile collisions[COLLIDE_POINTS], int x, int y,
|
2021-04-05 01:30:14 +02:00
|
|
|
Tile tile, int margin, int update);
|
2021-03-30 22:57:49 +02:00
|
|
|
int player_collide_solid(int x, int y);
|
2021-04-05 01:30:14 +02:00
|
|
|
int player_collide_sub(int x, int y, Tile sub, Tile rep, int margin);
|
2021-05-27 16:20:47 +02:00
|
|
|
int player_collide_water(struct Player player);
|