momento/include/player.h

56 lines
1.5 KiB
C
Raw Permalink Normal View History

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2021 KikooDX */
#pragma once
#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
#define PLAYER_WIDTH 10
#define PLAYER_HEIGHT 10
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
struct Player {
int x;
int y;
2021-03-30 22:57:49 +02:00
float spd_x;
float spd_y;
float rem_x;
float rem_y;
/* jump */
int jump_buffer;
int jump_grace;
int jumps_left;
2021-05-27 16:53:40 +02:00
int was_in_water;
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-30 01:42:11 +02:00
/* used for collisions */
enum { UP_LEFT, UP_RIGHT, DOWN_LEFT, DOWN_RIGHT };
#define COLLIDE_POINTS 4
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);
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,
Tile tile, int margin, int update);
2021-03-30 22:57:49 +02:00
int player_collide_solid(int x, int y);
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);