Compare commits
2 Commits
0f09a7b2bd
...
d7113d42fe
Author | SHA1 | Date |
---|---|---|
|
d7113d42fe | |
|
501a599336 |
|
@ -22,6 +22,7 @@ int main(void)
|
||||||
add_sprite(&assets, "testspr2", tex);
|
add_sprite(&assets, "testspr2", tex);
|
||||||
Sprite_t* spr2 = get_sprite(&assets, "testspr2");
|
Sprite_t* spr2 = get_sprite(&assets, "testspr2");
|
||||||
spr2->frame_count = 4;
|
spr2->frame_count = 4;
|
||||||
|
spr2->frame_per_row = 4;
|
||||||
spr2->origin = (Vector2){0, 0};
|
spr2->origin = (Vector2){0, 0};
|
||||||
spr2->frame_size = (Vector2){32, 32};
|
spr2->frame_size = (Vector2){32, 32};
|
||||||
spr2->speed = 15;
|
spr2->speed = 15;
|
||||||
|
|
|
@ -183,8 +183,9 @@ typedef struct _CWaterRunner {
|
||||||
typedef struct Sprite {
|
typedef struct Sprite {
|
||||||
Texture2D* texture;
|
Texture2D* texture;
|
||||||
Vector2 frame_size;
|
Vector2 frame_size;
|
||||||
Vector2 origin;
|
Vector2 origin; // TL of the frame
|
||||||
Vector2 anchor;
|
Vector2 anchor; // Where transformation anchors on
|
||||||
|
uint8_t frame_per_row;
|
||||||
int frame_count;
|
int frame_count;
|
||||||
int speed;
|
int speed;
|
||||||
char* name;
|
char* name;
|
||||||
|
|
|
@ -538,11 +538,16 @@ void draw_sprite(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, bool
|
||||||
|
|
||||||
void draw_sprite_pro(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, uint8_t flip, Vector2 scale, Color colour)
|
void draw_sprite_pro(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, uint8_t flip, Vector2 scale, Color colour)
|
||||||
{
|
{
|
||||||
if (frame_num >= spr->frame_count) frame_num = spr->frame_count - 1;
|
// Rollover behaviour
|
||||||
if (frame_num < 0) frame_num = 0;
|
if (frame_num >= spr->frame_count) frame_num %= spr->frame_count;
|
||||||
|
|
||||||
|
if (frame_num < 0) frame_num += spr->frame_count;
|
||||||
|
|
||||||
|
int r = frame_num / spr->frame_per_row;
|
||||||
|
int c = frame_num % spr->frame_per_row;
|
||||||
Rectangle rec = {
|
Rectangle rec = {
|
||||||
spr->origin.x + spr->frame_size.x * frame_num,
|
spr->origin.x + spr->frame_size.x * c,
|
||||||
spr->origin.y,
|
spr->origin.y + spr->frame_size.y * r,
|
||||||
spr->frame_size.x * ((flip & 1) ? -1 : 1),
|
spr->frame_size.x * ((flip & 1) ? -1 : 1),
|
||||||
spr->frame_size.y * ((flip & 2) ? -1 : 1),
|
spr->frame_size.y * ((flip & 2) ? -1 : 1),
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,8 +17,11 @@ typedef enum TileRotation
|
||||||
TILE_180ROT
|
TILE_180ROT
|
||||||
}TileRotation_t;
|
}TileRotation_t;
|
||||||
|
|
||||||
|
// Some of the fields are game-dependent, may have to think about doing OOP
|
||||||
|
// to separate out standard fields vs context-dependent fields
|
||||||
typedef struct Tile {
|
typedef struct Tile {
|
||||||
unsigned int tile_type;
|
unsigned int tile_type;
|
||||||
|
uint8_t connectivity;
|
||||||
SolidType_t solid;
|
SolidType_t solid;
|
||||||
TileRotation_t rotation;
|
TileRotation_t rotation;
|
||||||
uint8_t def;
|
uint8_t def;
|
||||||
|
|
|
@ -62,7 +62,8 @@ int main(void)
|
||||||
.frame_size = (Vector2){tex.width, tex.height},
|
.frame_size = (Vector2){tex.width, tex.height},
|
||||||
.origin = (Vector2){0, 0},
|
.origin = (Vector2){0, 0},
|
||||||
.anchor = (Vector2){tex.width / 2, tex.height / 2},
|
.anchor = (Vector2){tex.width / 2, tex.height / 2},
|
||||||
.frame_count = 0,
|
.frame_count = 1,
|
||||||
|
.frame_per_row = 1,
|
||||||
.speed = 0,
|
.speed = 0,
|
||||||
.name = "test_spr"
|
.name = "test_spr"
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,7 @@ typedef struct SpriteInfo
|
||||||
Vector2 frame_size;
|
Vector2 frame_size;
|
||||||
int speed;
|
int speed;
|
||||||
int frame_count;
|
int frame_count;
|
||||||
|
int frame_per_row;
|
||||||
}SpriteInfo_t;
|
}SpriteInfo_t;
|
||||||
|
|
||||||
static bool parse_sprite_info(char* sprite_info_str, SpriteInfo_t* spr_info)
|
static bool parse_sprite_info(char* sprite_info_str, SpriteInfo_t* spr_info)
|
||||||
|
@ -28,12 +29,12 @@ static bool parse_sprite_info(char* sprite_info_str, SpriteInfo_t* spr_info)
|
||||||
spr_info->tex = tex_name;
|
spr_info->tex = tex_name;
|
||||||
char* spr_data = tex_name + strlen(tex_name) + 1;
|
char* spr_data = tex_name + strlen(tex_name) + 1;
|
||||||
int data_count = sscanf(
|
int data_count = sscanf(
|
||||||
spr_data, "%f,%f,%f,%f,%d,%d",
|
spr_data, "%f,%f,%f,%f,%d,%d,%d",
|
||||||
&spr_info->origin.x, &spr_info->origin.y,
|
&spr_info->origin.x, &spr_info->origin.y,
|
||||||
&spr_info->frame_size.x, &spr_info->frame_size.y,
|
&spr_info->frame_size.x, &spr_info->frame_size.y,
|
||||||
&spr_info->frame_count, &spr_info->speed
|
&spr_info->frame_count, &spr_info->frame_per_row, &spr_info->speed
|
||||||
);
|
);
|
||||||
return data_count == 6;
|
return data_count == 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parse_emitter_info(char* emitter_info_str, EmitterConfig_t* conf)
|
static bool parse_emitter_info(char* emitter_info_str, EmitterConfig_t* conf)
|
||||||
|
@ -82,6 +83,29 @@ static inline AssetInfoType_t get_asset_type(const char* str)
|
||||||
return INVALID_INFO;
|
return INVALID_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool add_a_sprite(Assets_t* assets, const SpriteInfo_t* spr_info, char* name)
|
||||||
|
{
|
||||||
|
Texture2D* tex = get_texture(assets, spr_info->tex);
|
||||||
|
if (tex == NULL)
|
||||||
|
{
|
||||||
|
printf("Unable to get texture info %s for sprite %s\n", spr_info->tex, name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
printf("Added Sprite %s from texture %s\n", name, spr_info->tex);
|
||||||
|
Sprite_t* spr = add_sprite(assets, name, tex);
|
||||||
|
spr->origin = spr_info->origin;
|
||||||
|
spr->frame_size = spr_info->frame_size;
|
||||||
|
spr->frame_count = spr_info->frame_count;
|
||||||
|
if (spr->frame_count == 0)
|
||||||
|
{
|
||||||
|
// Cannot be zero
|
||||||
|
spr->frame_count = 1;
|
||||||
|
}
|
||||||
|
spr->frame_per_row = spr_info->frame_count;
|
||||||
|
spr->speed = spr_info->speed;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool load_from_rres(const char* file, Assets_t* assets)
|
bool load_from_rres(const char* file, Assets_t* assets)
|
||||||
{
|
{
|
||||||
RresFileInfo_t rres_file;
|
RresFileInfo_t rres_file;
|
||||||
|
@ -169,19 +193,7 @@ bool load_from_rres(const char* file, Assets_t* assets)
|
||||||
printf("Unable to parse info for sprite at line %lu\n", line_num);
|
printf("Unable to parse info for sprite at line %lu\n", line_num);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//printf("Compare %s,%s = %d\n", tmp2, spr_info.tex, strcmp(tmp2, spr_info.tex));
|
add_a_sprite(assets, &spr_info, name);
|
||||||
Texture2D* tex = get_texture(assets, spr_info.tex);
|
|
||||||
if (tex == NULL)
|
|
||||||
{
|
|
||||||
printf("Unable to get texture info %s for sprite %s\n", spr_info.tex, name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
printf("Added Sprite %s from texture %s\n", name, spr_info.tex);
|
|
||||||
Sprite_t* spr = add_sprite(assets, name, tex);
|
|
||||||
spr->origin = spr_info.origin;
|
|
||||||
spr->frame_size = spr_info.frame_size;
|
|
||||||
spr->frame_count = spr_info.frame_count;
|
|
||||||
spr->speed = spr_info.speed;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EMITTER_INFO:
|
case EMITTER_INFO:
|
||||||
|
@ -286,18 +298,7 @@ bool load_from_infofile(const char* file, Assets_t* assets)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//printf("Compare %s,%s = %d\n", tmp2, spr_info.tex, strcmp(tmp2, spr_info.tex));
|
//printf("Compare %s,%s = %d\n", tmp2, spr_info.tex, strcmp(tmp2, spr_info.tex));
|
||||||
Texture2D* tex = get_texture(assets, spr_info.tex);
|
add_a_sprite(assets, &spr_info, name);
|
||||||
if (tex == NULL)
|
|
||||||
{
|
|
||||||
printf("Unable to get texture info %s for sprite %s\n", spr_info.tex, name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
printf("Added Sprite %s from texture %s\n", name, spr_info.tex);
|
|
||||||
Sprite_t* spr = add_sprite(assets, name, tex);
|
|
||||||
spr->origin = spr_info.origin;
|
|
||||||
spr->frame_size = spr_info.frame_size;
|
|
||||||
spr->frame_count = spr_info.frame_count;
|
|
||||||
spr->speed = spr_info.speed;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EMITTER_INFO:
|
case EMITTER_INFO:
|
||||||
|
|
|
@ -479,6 +479,11 @@ static void render_editor_game_scene(Scene_t* scene)
|
||||||
// Draw water tile
|
// Draw water tile
|
||||||
DrawText(buffer, x, y, 10, BLACK);
|
DrawText(buffer, x, y, 10, BLACK);
|
||||||
}
|
}
|
||||||
|
if (tilemap.tiles[i].solid == SOLID)
|
||||||
|
{
|
||||||
|
sprintf(buffer, "%u", tilemap.tiles[i].connectivity);
|
||||||
|
DrawText(buffer, x + tilemap.tile_size / 2, y + tilemap.tile_size / 2, 12, WHITE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -223,6 +223,7 @@ void change_a_tile(TileGrid_t* tilemap, unsigned int tile_idx, TileType_t new_ty
|
||||||
}
|
}
|
||||||
|
|
||||||
tilemap->tiles[tile_idx].rotation = TILE_NOROTATE;
|
tilemap->tiles[tile_idx].rotation = TILE_NOROTATE;
|
||||||
|
|
||||||
if (new_type == SPIKES)
|
if (new_type == SPIKES)
|
||||||
{
|
{
|
||||||
// Priority: Down, Up, Left, Right
|
// Priority: Down, Up, Left, Right
|
||||||
|
@ -272,4 +273,65 @@ void change_a_tile(TileGrid_t* tilemap, unsigned int tile_idx, TileType_t new_ty
|
||||||
);
|
);
|
||||||
tilemap->tiles[tile_idx].def = (tilemap->tiles[tile_idx].tile_type == SOLID_TILE) ? 5: 2;
|
tilemap->tiles[tile_idx].def = (tilemap->tiles[tile_idx].tile_type == SOLID_TILE) ? 5: 2;
|
||||||
|
|
||||||
|
tilemap->tiles[tile_idx].connectivity = 0;
|
||||||
|
|
||||||
|
const uint8_t LEFT_BIT = 0;
|
||||||
|
const uint8_t UP_BIT = 1;
|
||||||
|
const uint8_t RIGHT_BIT = 2;
|
||||||
|
const uint8_t DOWN_BIT = 3;
|
||||||
|
{
|
||||||
|
// Priority: Left, Up, Right, Down
|
||||||
|
if (tile_idx % tilemap->width != 0)
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx].connectivity |= (tilemap->tiles[tile_idx - 1].tile_type == SOLID_TILE) ? (1 << LEFT_BIT) : 0;
|
||||||
|
if (new_type == SOLID_TILE)
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx - 1].connectivity |= (1 << RIGHT_BIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx - 1].connectivity &= ~(1 << RIGHT_BIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile_idx - tilemap->width >= 0)
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx].connectivity |= (tilemap->tiles[tile_idx - tilemap->width].tile_type == SOLID_TILE) ? (1 << UP_BIT) : 0;
|
||||||
|
if (new_type == SOLID_TILE)
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx - tilemap->width].connectivity |= (1 << DOWN_BIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx - tilemap->width].connectivity &= ~(1 << DOWN_BIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile_idx + tilemap->width < tilemap->n_tiles)
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx].connectivity |= (tilemap->tiles[tile_idx + tilemap->width].tile_type == SOLID_TILE) ? (1 << DOWN_BIT) : 0;
|
||||||
|
if (new_type == SOLID_TILE)
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx + tilemap->width].connectivity |= (1 << UP_BIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx + tilemap->width].connectivity &= ~(1 << UP_BIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((tile_idx + 1) % tilemap->width != 0)
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx].connectivity |= (tilemap->tiles[tile_idx + 1].tile_type == SOLID_TILE) ? (1 << RIGHT_BIT) : 0;
|
||||||
|
if (new_type == SOLID_TILE)
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx + 1].connectivity |= (1 << LEFT_BIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tilemap->tiles[tile_idx + 1].connectivity &= ~(1 << LEFT_BIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue