Add bounding box info in tiles
Changelog: - Use more memory, but should help out in implementing spikesscene_man
parent
a719c73c50
commit
81da536e8e
|
@ -430,7 +430,7 @@ void init_level_scene(LevelScene_t* scene)
|
||||||
sc_array_add(&scene->scene.systems, &tile_collision_system);
|
sc_array_add(&scene->scene.systems, &tile_collision_system);
|
||||||
sc_array_add(&scene->scene.systems, &update_tilemap_system);
|
sc_array_add(&scene->scene.systems, &update_tilemap_system);
|
||||||
sc_array_add(&scene->scene.systems, &hitbox_update_system);
|
sc_array_add(&scene->scene.systems, &hitbox_update_system);
|
||||||
sc_array_add(&scene->scene.systems, &player_crushing_system);
|
//sc_array_add(&scene->scene.systems, &player_crushing_system);
|
||||||
sc_array_add(&scene->scene.systems, &state_transition_update_system);
|
sc_array_add(&scene->scene.systems, &state_transition_update_system);
|
||||||
sc_array_add(&scene->scene.systems, &player_ground_air_transition_system);
|
sc_array_add(&scene->scene.systems, &player_ground_air_transition_system);
|
||||||
sc_array_add(&scene->scene.systems, &sprite_animation_system);
|
sc_array_add(&scene->scene.systems, &sprite_animation_system);
|
||||||
|
@ -462,6 +462,7 @@ void init_level_scene(LevelScene_t* scene)
|
||||||
all_tiles[i].solid = NOT_SOLID;
|
all_tiles[i].solid = NOT_SOLID;
|
||||||
all_tiles[i].tile_type = EMPTY_TILE;
|
all_tiles[i].tile_type = EMPTY_TILE;
|
||||||
sc_map_init_64v(&all_tiles[i].entities_set, 16, 0);
|
sc_map_init_64v(&all_tiles[i].entities_set, 16, 0);
|
||||||
|
all_tiles[i].size = (Vector2){TILE_SIZE, TILE_SIZE};
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < scene->data.tilemap.width; ++i)
|
for (size_t i = 0; i < scene->data.tilemap.width; ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const Vector2 TILE_SZ = {TILE_SIZE, TILE_SIZE};
|
|
||||||
static const Vector2 GRAVITY = {0, GRAV_ACCEL};
|
static const Vector2 GRAVITY = {0, GRAV_ACCEL};
|
||||||
static const Vector2 UPTHRUST = {0, -GRAV_ACCEL * 1.1};
|
static const Vector2 UPTHRUST = {0, -GRAV_ACCEL * 1.1};
|
||||||
typedef enum AnchorPoint {
|
typedef enum AnchorPoint {
|
||||||
|
@ -60,7 +59,9 @@ static uint8_t check_collision(const CollideEntity_t* ent, TileGrid_t* grid, boo
|
||||||
find_AABB_overlap(
|
find_AABB_overlap(
|
||||||
(Vector2){ent->bbox.x, ent->bbox.y},
|
(Vector2){ent->bbox.x, ent->bbox.y},
|
||||||
(Vector2){ent->bbox.width, ent->bbox.height},
|
(Vector2){ent->bbox.width, ent->bbox.height},
|
||||||
(Vector2){tile_x * TILE_SIZE, tile_y * TILE_SIZE}, TILE_SZ, &overlap
|
(Vector2){tile_x * TILE_SIZE + grid->tiles[tile_idx].offset.x, tile_y * TILE_SIZE + grid->tiles[tile_idx].offset.y},
|
||||||
|
grid->tiles[tile_idx].size,
|
||||||
|
&overlap
|
||||||
);
|
);
|
||||||
|
|
||||||
//For one-way platform, check for vectical collision, only return true for up direction
|
//For one-way platform, check for vectical collision, only return true for up direction
|
||||||
|
@ -704,12 +705,12 @@ void tile_collision_system(Scene_t* scene)
|
||||||
if(tilemap.tiles[tile_idx].tile_type != EMPTY_TILE)
|
if(tilemap.tiles[tile_idx].tile_type != EMPTY_TILE)
|
||||||
{
|
{
|
||||||
Vector2 other;
|
Vector2 other;
|
||||||
other.x = (tile_idx % tilemap.width) * TILE_SIZE;
|
other.x = (tile_idx % tilemap.width) * TILE_SIZE + tilemap.tiles[tile_idx].offset.x;
|
||||||
other.y = (tile_idx / tilemap.width) * TILE_SIZE; // Precision loss is intentional
|
other.y = (tile_idx / tilemap.width) * TILE_SIZE + tilemap.tiles[tile_idx].offset.y; // Precision loss is intentional
|
||||||
|
|
||||||
check_collision_and_move(
|
check_collision_and_move(
|
||||||
&tilemap, p_ent,
|
&tilemap, p_ent,
|
||||||
&other, TILE_SZ, tilemap.tiles[tile_idx].solid
|
&other, tilemap.tiles[tile_idx].size, tilemap.tiles[tile_idx].solid
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ typedef struct Tile {
|
||||||
SolidType_t solid;
|
SolidType_t solid;
|
||||||
unsigned int water_level;
|
unsigned int water_level;
|
||||||
struct sc_map_64v entities_set;
|
struct sc_map_64v entities_set;
|
||||||
|
Vector2 offset;
|
||||||
|
Vector2 size;
|
||||||
}Tile_t;
|
}Tile_t;
|
||||||
|
|
||||||
typedef struct TileGrid {
|
typedef struct TileGrid {
|
||||||
|
|
Loading…
Reference in New Issue