mirror of https://git.sr.ht/~kikoodx/momento
56 lines
1.5 KiB
C
56 lines
1.5 KiB
C
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
/* Copyright (C) 2021 KikooDX */
|
|
#pragma once
|
|
|
|
#include "input.h"
|
|
#include "level.h"
|
|
#include "particles.h"
|
|
|
|
#define PLAYER_WIDTH 10
|
|
#define PLAYER_HEIGHT 10
|
|
|
|
enum AirState { AirRising, AirBreaking, AirNeutral };
|
|
#define AIR_BREAKING_FACTOR 3
|
|
|
|
enum AnimState { AnimIdle, AnimBlink, AnimWalk, AnimAirborn, AnimJump };
|
|
#define BLINK_DELAY 120
|
|
|
|
struct Player {
|
|
int x;
|
|
int y;
|
|
float spd_x;
|
|
float spd_y;
|
|
float rem_x;
|
|
float rem_y;
|
|
/* jump */
|
|
int jump_buffer;
|
|
int jump_grace;
|
|
int jumps_left;
|
|
int was_in_water;
|
|
enum AirState air_state;
|
|
/* animations */
|
|
struct Particle anim;
|
|
struct Particle blink_anim;
|
|
struct Particle idle_anim;
|
|
struct Particle jump_anim;
|
|
struct Particle walk_anim;
|
|
enum AnimState anim_state;
|
|
int blink_timer;
|
|
int trail_state;
|
|
};
|
|
|
|
/* 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);
|
|
/* return 1 if exit reached, -1 on death/reset and 0 otherwise */
|
|
int player_update(struct Player *restrict player, struct Input input);
|
|
void player_collide(Tile collisions[COLLIDE_POINTS], int x, int y, int margin);
|
|
int player_collide_tile(Tile collisions[COLLIDE_POINTS], int x, int y,
|
|
Tile tile, int margin, int update);
|
|
int player_collide_solid(int x, int y);
|
|
int player_collide_sub(int x, int y, Tile sub, Tile rep, int margin);
|
|
int player_collide_water(struct Player player);
|