player spawn tile
This commit is contained in:
parent
a1858119be
commit
e03464995b
|
@ -1,4 +1,6 @@
|
|||
#pragma once
|
||||
#include "tile.h"
|
||||
#include "vec.h"
|
||||
#include "visual_data.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -26,3 +28,4 @@ void level_draw(void);
|
|||
|
||||
int level_get(int x, int y);
|
||||
int level_get_px(int x, int y);
|
||||
struct Vec level_find(enum Tile);
|
||||
|
|
|
@ -10,7 +10,7 @@ struct Player {
|
|||
int jump_buffer, jump_grace;
|
||||
};
|
||||
|
||||
void player_init(struct Player *);
|
||||
void player_spawn(struct Player *);
|
||||
void player_update(struct Player *);
|
||||
void player_draw(struct Player *);
|
||||
void player_move(struct Player *, struct Vec);
|
||||
|
|
|
@ -3,5 +3,7 @@
|
|||
enum Tile {
|
||||
TILE_AIR,
|
||||
TILE_SOLID,
|
||||
TILE_SPAWN,
|
||||
TILE_EXIT,
|
||||
TILE_OOB,
|
||||
};
|
||||
|
|
BIN
res/test.kble
BIN
res/test.kble
Binary file not shown.
BIN
res/tileset.png
BIN
res/tileset.png
Binary file not shown.
Before Width: | Height: | Size: 119 B After Width: | Height: | Size: 205 B |
10
src/level.c
10
src/level.c
|
@ -1,6 +1,7 @@
|
|||
#include "level.h"
|
||||
#include "conf.h"
|
||||
#include "tile.h"
|
||||
#include "vec.h"
|
||||
#include "visual_data.h"
|
||||
#include <gint/display.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -92,6 +93,15 @@ level_get_px(int x, int y)
|
|||
return level_get(x / TILE_SIZE, y / TILE_SIZE);
|
||||
}
|
||||
|
||||
struct Vec
|
||||
level_find(enum Tile t)
|
||||
{
|
||||
int i = level.size;
|
||||
while (i-- > 0 && level.data[i] != t)
|
||||
;
|
||||
return (struct Vec){i % level.width, i / level.width};
|
||||
}
|
||||
|
||||
static void
|
||||
level_free(void)
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ main(void)
|
|||
|
||||
init();
|
||||
level_load(&kble_test);
|
||||
player_spawn(&player);
|
||||
|
||||
do {
|
||||
int i;
|
||||
|
@ -51,7 +52,6 @@ init(void)
|
|||
|
||||
input_init();
|
||||
level_init();
|
||||
player_init(&player);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -13,10 +13,11 @@ static int collide(int x, int y, int tile);
|
|||
static int collide_solid(int x, int y);
|
||||
|
||||
void
|
||||
player_init(struct Player *p)
|
||||
player_spawn(struct Player *p)
|
||||
{
|
||||
p->pos.x = TILE_SIZE;
|
||||
p->pos.y = TILE_SIZE;
|
||||
struct Vec pos = level_find(TILE_SPAWN);
|
||||
p->pos.x = pos.x * TILE_SIZE + (TILE_SIZE - PLAYER_WIDTH) / 2;
|
||||
p->pos.y = pos.y * TILE_SIZE + TILE_SIZE - PLAYER_HEIGHT;
|
||||
reset_speed(p, 1, 1);
|
||||
p->air_state = AS_NEUTRAL;
|
||||
p->jump_buffer = 0;
|
||||
|
|
Loading…
Reference in New Issue