bouncy bouncing

This commit is contained in:
KikooDX 2021-12-18 10:05:52 +01:00
parent 05ac1bba00
commit 21e2a088dc
10 changed files with 25 additions and 4 deletions

View File

@ -22,6 +22,7 @@ set(ASSETS
res/tileset.png
res/test.kble
res/burn.kble
res/bounce.kble
)
set(FLAGS -std=c99 -Os -Wall -Wextra -Wshadow)

View File

@ -9,10 +9,11 @@
#define GROUND_ACCELERATION 0.4f
#define AIR_FRICTION (AIR_ACCELERATION / MAX_WALK_SPEED)
#define GROUND_FRICTION (GROUND_ACCELERATION / MAX_WALK_SPEED)
#define AIR_RESISTANCE 0.02f
#define AIR_RESISTANCE 0.01f
#define GRAVITY 0.3f
#define JUMP_SPEED -6.0f
#define JUMP_BREAK 3
#define JUMP_BUFFER 12
#define JUMP_GRACE 6
#define BURN_DEATH 3
#define BOUNCE_SPEED -2.0f

View File

@ -7,7 +7,7 @@ struct Player {
struct Vec pos;
struct VecF spd, rem;
enum AirState air_state;
int jump_buffer, jump_grace, burn;
int jump_buffer, jump_grace, burn, bouncing;
};
void player_spawn(struct Player *);

View File

@ -6,5 +6,6 @@ enum Tile {
TILE_SPAWN,
TILE_EXIT,
TILE_BURN,
TILE_BOUNCER,
TILE_OOB,
};

View File

@ -1,3 +1,4 @@
#pragma once
int sign(int);
float absf(float);

BIN
res/bounce.kble Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@ -10,8 +10,9 @@
static struct Level level;
extern bopti_image_t bimg_tileset;
extern struct LevelBin kble_test, kble_burn;
static const struct LevelBin *levels[] = {&kble_test, &kble_burn, NULL};
extern struct LevelBin kble_test, kble_burn, kble_bounce;
static const struct LevelBin *levels[] = {&kble_test, &kble_burn, &kble_bounce,
NULL};
static void level_free(void);

View File

@ -79,6 +79,16 @@ player_update(struct Player *p)
p->jump_grace = 0;
}
/* bounce */
if (collide(p->pos.x, p->pos.y, TILE_BOUNCER)) {
if (!p->bouncing) {
p->spd.y = -absf(p->spd.y) + BOUNCE_SPEED;
p->bouncing = 1;
}
} else {
p->bouncing = 0;
}
/* burn and death */
if (collide(p->pos.x, p->pos.y, TILE_BURN)) {
if (++p->burn >= BURN_DEATH) level_reload();

View File

@ -5,3 +5,9 @@ sign(int x)
{
return (x > 0) - (x < 0);
}
float
absf(float x)
{
return x * (-1 + 2 * (x > 0));
}