mirror of https://git.sr.ht/~kikoodx/crystal-tower
thy death
This commit is contained in:
parent
a51212acc7
commit
5f14f2394a
|
@ -14,4 +14,4 @@
|
|||
#define FRICTION_BREAK (0.6f / MAX_WALK_SPEED)
|
||||
#define JUMP_GRACE 1
|
||||
#define JUMP_BUFFER 12
|
||||
#define JUMP_SPD -5.0
|
||||
#define JUMP_SPD -4.4
|
||||
|
|
|
@ -15,9 +15,11 @@ struct Level {
|
|||
int height;
|
||||
int size;
|
||||
char *data;
|
||||
struct LevelBin *source;
|
||||
};
|
||||
|
||||
void level_load(struct LevelBin *);
|
||||
void level_reload(void);
|
||||
void level_free(void);
|
||||
void level_draw(void);
|
||||
struct Vec level_find(enum Tile);
|
||||
|
@ -25,3 +27,4 @@ enum Tile level_get(int x, int y);
|
|||
enum Tile level_get_px(int x, int y);
|
||||
void level_set(int x, int y, enum Tile v);
|
||||
void level_set_px(int x, int y, enum Tile v);
|
||||
int level_oob(int x, int y);
|
||||
|
|
18
src/level.c
18
src/level.c
|
@ -1,6 +1,8 @@
|
|||
#include "level.h"
|
||||
#include "camera.h"
|
||||
#include "conf.h"
|
||||
#include "particles.h"
|
||||
#include "player.h"
|
||||
#include "tile.h"
|
||||
#include "vec.h"
|
||||
#include <gint/display.h>
|
||||
|
@ -16,11 +18,20 @@ level_load(struct LevelBin *s)
|
|||
self.height = s->height;
|
||||
self.size = i;
|
||||
self.data = malloc(i);
|
||||
self.source = s;
|
||||
while (i-- > 0) {
|
||||
self.data[i] = s->data[i];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
level_reload(void)
|
||||
{
|
||||
level_load(self.source);
|
||||
player_init(level_find(TILE_PLAYER));
|
||||
particles_init();
|
||||
}
|
||||
|
||||
void
|
||||
level_free(void)
|
||||
{
|
||||
|
@ -95,3 +106,10 @@ level_set_px(int x, int y, enum Tile v)
|
|||
{
|
||||
level_set(x / TILE_SIZE, y / TILE_SIZE, v);
|
||||
}
|
||||
|
||||
int
|
||||
level_oob(int x, int y)
|
||||
{
|
||||
return x < 0 || x >= self.width * TILE_SIZE || y < 0 ||
|
||||
y >= self.height * TILE_SIZE;
|
||||
}
|
||||
|
|
|
@ -26,9 +26,7 @@ main(void)
|
|||
GINT_CALL(callback, &has_ticked));
|
||||
timer_start(timer);
|
||||
input_init();
|
||||
particles_init();
|
||||
level_load(&lvl_test);
|
||||
player_init(level_find(TILE_PLAYER));
|
||||
camera_init(player_pos());
|
||||
|
||||
while (!input_down(K_EXIT)) {
|
||||
|
|
21
src/player.c
21
src/player.c
|
@ -12,6 +12,8 @@ static struct Player self;
|
|||
|
||||
static int jump(int on_ground);
|
||||
static void walljump(void);
|
||||
static void death(void);
|
||||
static int oob(int x, int y);
|
||||
static int collide_solid(int x, int y);
|
||||
|
||||
void
|
||||
|
@ -63,6 +65,11 @@ player_update(void)
|
|||
if (self.lock_direction && abs(self.spd.x) < MAX_WALK_SPEED / 2)
|
||||
self.lock_direction = 0;
|
||||
|
||||
/* death */
|
||||
if (oob(self.pos.x, self.pos.y)) {
|
||||
death();
|
||||
}
|
||||
|
||||
player_move(player_update_rem());
|
||||
}
|
||||
|
||||
|
@ -108,6 +115,12 @@ walljump(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
death(void)
|
||||
{
|
||||
level_reload();
|
||||
}
|
||||
|
||||
void
|
||||
player_draw(void)
|
||||
{
|
||||
|
@ -168,6 +181,14 @@ collide_solid(int x, int y)
|
|||
level_get_px(x2, y2) == TILE_SOLID;
|
||||
}
|
||||
|
||||
static int
|
||||
oob(int x, int y)
|
||||
{
|
||||
const int x2 = x + PLAYER_WIDTH - 1;
|
||||
const int y2 = y + PLAYER_HEIGHT - 1;
|
||||
return level_oob(x, y) && level_oob(x2, y2);
|
||||
}
|
||||
|
||||
struct Vec *
|
||||
player_pos(void)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue