Compare commits
4 Commits
754d380221
...
1094e13c0a
Author | SHA1 | Date |
---|---|---|
|
1094e13c0a | |
|
54acd365d4 | |
|
2bda67e917 | |
|
42c4572066 |
|
@ -32,6 +32,7 @@ int main(void)
|
||||||
Font* fnt = get_font(&assets, "testfont");
|
Font* fnt = get_font(&assets, "testfont");
|
||||||
|
|
||||||
int current_frame = 0;
|
int current_frame = 0;
|
||||||
|
int elapsed = 0;
|
||||||
while(!WindowShouldClose())
|
while(!WindowShouldClose())
|
||||||
{
|
{
|
||||||
if (IsKeyReleased(KEY_C))
|
if (IsKeyReleased(KEY_C))
|
||||||
|
@ -49,12 +50,12 @@ int main(void)
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
// Update the animated Sprite
|
// Update the animated Sprite
|
||||||
spr2->elapsed++;
|
elapsed++;
|
||||||
if (spr2->elapsed == spr2->speed)
|
if (elapsed == spr2->speed)
|
||||||
{
|
{
|
||||||
current_frame++;
|
current_frame++;
|
||||||
current_frame %= spr2->frame_count;
|
current_frame %= spr2->frame_count;
|
||||||
spr2->elapsed = 0;
|
elapsed = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
term_assets(&assets);
|
term_assets(&assets);
|
||||||
|
|
|
@ -186,7 +186,6 @@ typedef struct Sprite {
|
||||||
Vector2 origin;
|
Vector2 origin;
|
||||||
Vector2 anchor;
|
Vector2 anchor;
|
||||||
int frame_count;
|
int frame_count;
|
||||||
int elapsed;
|
|
||||||
int speed;
|
int speed;
|
||||||
char* name;
|
char* name;
|
||||||
} Sprite_t;
|
} Sprite_t;
|
||||||
|
@ -207,6 +206,11 @@ typedef struct _CSprite_t {
|
||||||
bool pause;
|
bool pause;
|
||||||
int current_frame;
|
int current_frame;
|
||||||
float fractional;
|
float fractional;
|
||||||
|
float rotation; // Degree
|
||||||
|
float rotation_speed; // Degree / s
|
||||||
|
int elapsed;
|
||||||
|
Vector2 offset;
|
||||||
|
Color colour;
|
||||||
} CSprite_t;
|
} CSprite_t;
|
||||||
|
|
||||||
typedef struct _CMoveable_t {
|
typedef struct _CMoveable_t {
|
||||||
|
|
|
@ -530,24 +530,36 @@ LevelPack_t* get_level_pack(Assets_t* assets, const char* name)
|
||||||
|
|
||||||
void draw_sprite(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, bool flip_x)
|
void draw_sprite(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, bool flip_x)
|
||||||
{
|
{
|
||||||
|
draw_sprite_pro(
|
||||||
|
spr, frame_num, pos, rotation, flip_x ? 1: 0,
|
||||||
|
(Vector2){1, 1}, WHITE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
if (frame_num < 0) frame_num = 0;
|
||||||
Rectangle rec = {
|
Rectangle rec = {
|
||||||
spr->origin.x + spr->frame_size.x * frame_num,
|
spr->origin.x + spr->frame_size.x * frame_num,
|
||||||
spr->origin.y,
|
spr->origin.y,
|
||||||
spr->frame_size.x * (flip_x ? -1:1),
|
spr->frame_size.x * ((flip & 1) ? -1 : 1),
|
||||||
spr->frame_size.y
|
spr->frame_size.y * ((flip & 2) ? -1 : 1),
|
||||||
};
|
};
|
||||||
//DrawTextureRec(*spr->texture, rec, pos, WHITE);
|
|
||||||
Rectangle dest = {
|
Rectangle dest = {
|
||||||
.x = pos.x - spr->anchor.x,
|
.x = pos.x,
|
||||||
.y = pos.y - spr->anchor.y,
|
.y = pos.y,
|
||||||
.width = spr->frame_size.x,
|
.width = spr->frame_size.x * scale.x,
|
||||||
.height = spr->frame_size.y
|
.height = spr->frame_size.y * scale.y
|
||||||
};
|
};
|
||||||
|
Vector2 anchor = spr->anchor;
|
||||||
|
anchor.x *= scale.x;
|
||||||
|
anchor.y *= scale.y;
|
||||||
DrawTexturePro(
|
DrawTexturePro(
|
||||||
*spr->texture,
|
*spr->texture,
|
||||||
rec,
|
rec,
|
||||||
dest,
|
dest,
|
||||||
spr->anchor,
|
anchor,
|
||||||
rotation, WHITE
|
rotation, colour
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,7 @@ Font* get_font(Assets_t* assets, const char* name);
|
||||||
LevelPack_t* get_level_pack(Assets_t* assets, const char* name);
|
LevelPack_t* get_level_pack(Assets_t* assets, const char* name);
|
||||||
|
|
||||||
void draw_sprite(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, bool flip_x);
|
void draw_sprite(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, bool flip_x);
|
||||||
|
void draw_sprite_pro(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, uint8_t flip, Vector2 scale, Color colour);
|
||||||
|
|
||||||
typedef struct SFX
|
typedef struct SFX
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,7 +63,6 @@ int main(void)
|
||||||
.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 = 0,
|
||||||
.elapsed = 0,
|
|
||||||
.speed = 0,
|
.speed = 0,
|
||||||
.name = "test_spr"
|
.name = "test_spr"
|
||||||
};
|
};
|
||||||
|
|
2
run.sh
2
run.sh
|
@ -1,3 +1,3 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
LSAN_OPTIONS=suppressions=./lsan_supp.txt ./build/$1
|
./build.sh && LSAN_OPTIONS=suppressions=./lsan_supp.txt ./build/$1
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
#define MOVE_ACCEL 1300
|
#define MOVE_ACCEL 1300
|
||||||
|
|
||||||
#ifndef TILE16_SIZE
|
#ifndef TILE16_SIZE
|
||||||
#define PLAYER_WIDTH 30
|
#define PLAYER_WIDTH 28
|
||||||
#define PLAYER_HEIGHT 42
|
#define PLAYER_HEIGHT 42
|
||||||
#define PLAYER_C_WIDTH 30
|
#define PLAYER_C_WIDTH 28
|
||||||
#define PLAYER_C_HEIGHT 26
|
#define PLAYER_C_HEIGHT 26
|
||||||
#else
|
#else
|
||||||
#define PLAYER_WIDTH 14
|
#define PLAYER_WIDTH 14
|
||||||
|
|
|
@ -240,12 +240,18 @@ static Vector2 shift_bbox(Vector2 bbox, Vector2 new_bbox, AnchorPoint_t anchor)
|
||||||
|
|
||||||
void destroy_entity(Scene_t* scene, TileGrid_t* tilemap, Entity_t* p_ent)
|
void destroy_entity(Scene_t* scene, TileGrid_t* tilemap, Entity_t* p_ent)
|
||||||
{
|
{
|
||||||
|
Vector2 half_size = {0,0};
|
||||||
|
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
|
||||||
|
if (p_bbox != NULL)
|
||||||
|
{
|
||||||
|
half_size = p_bbox->half_size;
|
||||||
|
}
|
||||||
if (p_ent->m_tag == BOULDER_ENT_TAG)
|
if (p_ent->m_tag == BOULDER_ENT_TAG)
|
||||||
{
|
{
|
||||||
ParticleEmitter_t emitter = {
|
ParticleEmitter_t emitter = {
|
||||||
.spr = get_sprite(&scene->engine->assets, "p_rock"),
|
.spr = get_sprite(&scene->engine->assets, "p_rock"),
|
||||||
.config = get_emitter_conf(&scene->engine->assets, "pe_burst"),
|
.config = get_emitter_conf(&scene->engine->assets, "pe_burst"),
|
||||||
.position = p_ent->position,
|
.position = Vector2Add(p_ent->position, half_size),
|
||||||
.n_particles = 5,
|
.n_particles = 5,
|
||||||
.user_data = CONTAINER_OF(scene, LevelScene_t, scene),
|
.user_data = CONTAINER_OF(scene, LevelScene_t, scene),
|
||||||
.update_func = &simple_particle_system_update,
|
.update_func = &simple_particle_system_update,
|
||||||
|
@ -259,7 +265,7 @@ void destroy_entity(Scene_t* scene, TileGrid_t* tilemap, Entity_t* p_ent)
|
||||||
ParticleEmitter_t emitter = {
|
ParticleEmitter_t emitter = {
|
||||||
.spr = get_sprite(&scene->engine->assets, (p_container->material == WOODEN_CONTAINER) ? "p_wood" : "p_metal"),
|
.spr = get_sprite(&scene->engine->assets, (p_container->material == WOODEN_CONTAINER) ? "p_wood" : "p_metal"),
|
||||||
.config = get_emitter_conf(&scene->engine->assets, "pe_burst"),
|
.config = get_emitter_conf(&scene->engine->assets, "pe_burst"),
|
||||||
.position = p_ent->position,
|
.position = Vector2Add(p_ent->position, half_size),
|
||||||
.n_particles = 5,
|
.n_particles = 5,
|
||||||
.user_data = CONTAINER_OF(scene, LevelScene_t, scene),
|
.user_data = CONTAINER_OF(scene, LevelScene_t, scene),
|
||||||
.update_func = &simple_particle_system_update,
|
.update_func = &simple_particle_system_update,
|
||||||
|
@ -272,7 +278,7 @@ void destroy_entity(Scene_t* scene, TileGrid_t* tilemap, Entity_t* p_ent)
|
||||||
ParticleEmitter_t emitter = {
|
ParticleEmitter_t emitter = {
|
||||||
.spr = get_sprite(&scene->engine->assets, "p_wood"),
|
.spr = get_sprite(&scene->engine->assets, "p_wood"),
|
||||||
.config = get_emitter_conf(&scene->engine->assets, "pe_burst"),
|
.config = get_emitter_conf(&scene->engine->assets, "pe_burst"),
|
||||||
.position = p_ent->position,
|
.position = Vector2Add(p_ent->position, half_size),
|
||||||
.n_particles = 5,
|
.n_particles = 5,
|
||||||
.user_data = CONTAINER_OF(scene, LevelScene_t, scene),
|
.user_data = CONTAINER_OF(scene, LevelScene_t, scene),
|
||||||
.update_func = &simple_particle_system_update,
|
.update_func = &simple_particle_system_update,
|
||||||
|
@ -283,7 +289,7 @@ void destroy_entity(Scene_t* scene, TileGrid_t* tilemap, Entity_t* p_ent)
|
||||||
ParticleEmitter_t emitter2 = {
|
ParticleEmitter_t emitter2 = {
|
||||||
.spr = get_sprite(&scene->engine->assets, "p_coin"),
|
.spr = get_sprite(&scene->engine->assets, "p_coin"),
|
||||||
.config = get_emitter_conf(&scene->engine->assets, "pe_single"),
|
.config = get_emitter_conf(&scene->engine->assets, "pe_single"),
|
||||||
.position = p_ent->position,
|
.position = Vector2Add(p_ent->position, half_size),
|
||||||
.n_particles = 1,
|
.n_particles = 1,
|
||||||
.user_data = CONTAINER_OF(scene, LevelScene_t, scene),
|
.user_data = CONTAINER_OF(scene, LevelScene_t, scene),
|
||||||
.update_func = &simple_particle_system_update,
|
.update_func = &simple_particle_system_update,
|
||||||
|
@ -298,7 +304,7 @@ void destroy_entity(Scene_t* scene, TileGrid_t* tilemap, Entity_t* p_ent)
|
||||||
ParticleEmitter_t emitter = {
|
ParticleEmitter_t emitter = {
|
||||||
.spr = get_sprite(&scene->engine->assets, "p_arrow"),
|
.spr = get_sprite(&scene->engine->assets, "p_arrow"),
|
||||||
.config = get_emitter_conf(&scene->engine->assets, "pe_burst"),
|
.config = get_emitter_conf(&scene->engine->assets, "pe_burst"),
|
||||||
.position = p_ent->position,
|
.position = Vector2Add(p_ent->position, half_size),
|
||||||
.n_particles = 2,
|
.n_particles = 2,
|
||||||
.user_data = CONTAINER_OF(scene, LevelScene_t, scene),
|
.user_data = CONTAINER_OF(scene, LevelScene_t, scene),
|
||||||
.update_func = &simple_particle_system_update,
|
.update_func = &simple_particle_system_update,
|
||||||
|
@ -1486,7 +1492,7 @@ void state_transition_update_system(Scene_t* scene)
|
||||||
ParticleEmitter_t emitter = {
|
ParticleEmitter_t emitter = {
|
||||||
.spr = get_sprite(&scene->engine->assets, "p_water"),
|
.spr = get_sprite(&scene->engine->assets, "p_water"),
|
||||||
.config = get_emitter_conf(&scene->engine->assets, "pe_burst"),
|
.config = get_emitter_conf(&scene->engine->assets, "pe_burst"),
|
||||||
.position = p_ent->position,
|
.position = Vector2Add(p_ent->position, p_bbox->half_size),
|
||||||
.n_particles = 5,
|
.n_particles = 5,
|
||||||
.user_data = (CONTAINER_OF(scene, LevelScene_t, scene)),
|
.user_data = (CONTAINER_OF(scene, LevelScene_t, scene)),
|
||||||
.update_func = &simple_particle_system_update,
|
.update_func = &simple_particle_system_update,
|
||||||
|
@ -2002,7 +2008,6 @@ void sprite_animation_system(Scene_t* scene)
|
||||||
{
|
{
|
||||||
next_idx = p_cspr->transition_func(p_ent);
|
next_idx = p_cspr->transition_func(p_ent);
|
||||||
}
|
}
|
||||||
if (p_cspr->pause) return;
|
|
||||||
|
|
||||||
bool reset = p_cspr->current_idx != next_idx;
|
bool reset = p_cspr->current_idx != next_idx;
|
||||||
p_cspr->current_idx = next_idx;
|
p_cspr->current_idx = next_idx;
|
||||||
|
@ -2010,7 +2015,14 @@ void sprite_animation_system(Scene_t* scene)
|
||||||
SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
||||||
if (spr.sprite == NULL) continue;
|
if (spr.sprite == NULL) continue;
|
||||||
|
|
||||||
if (reset) p_cspr->current_frame = 0;
|
if (reset)
|
||||||
|
{
|
||||||
|
p_cspr->fractional = 0;
|
||||||
|
p_cspr->elapsed = 0;
|
||||||
|
p_cspr->current_frame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spr.sprite->speed == 0) continue;
|
||||||
|
|
||||||
// Animate it (handle frame count)
|
// Animate it (handle frame count)
|
||||||
p_cspr->fractional += scene->delta_time;
|
p_cspr->fractional += scene->delta_time;
|
||||||
|
@ -2018,12 +2030,15 @@ void sprite_animation_system(Scene_t* scene)
|
||||||
if (p_cspr->fractional > ANIM_FRAME_RATE)
|
if (p_cspr->fractional > ANIM_FRAME_RATE)
|
||||||
{
|
{
|
||||||
p_cspr->fractional -= ANIM_FRAME_RATE;
|
p_cspr->fractional -= ANIM_FRAME_RATE;
|
||||||
spr.sprite->elapsed++;
|
p_cspr->elapsed++;
|
||||||
if (spr.sprite->elapsed == spr.sprite->speed)
|
if (p_cspr->elapsed == spr.sprite->speed)
|
||||||
{
|
{
|
||||||
p_cspr->current_frame++;
|
p_cspr->elapsed = 0;
|
||||||
p_cspr->current_frame %= spr.sprite->frame_count;
|
if (!p_cspr->pause)
|
||||||
spr.sprite->elapsed = 0;
|
{
|
||||||
|
p_cspr->current_frame++;
|
||||||
|
p_cspr->current_frame %= spr.sprite->frame_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue