diff --git a/enemy.c b/enemy.c index 4af65a2..971ecbe 100644 --- a/enemy.c +++ b/enemy.c @@ -14,7 +14,15 @@ #include "enemy.h" #include "entity.h" +Texture2D *enemy_sprite = NULL; + Entity *spawn_enemy(void) { + if (enemy_sprite == NULL) { + enemy_sprite = malloc(sizeof(Texture2D)); + Image sprite_img = LoadImage("img/enemy.png"); + *enemy_sprite = LoadTextureFromImage(sprite_img); + UnloadImage(sprite_img); + } Entity *e = malloc(sizeof(Entity)); e->name = "Enemy"; e->properties = malloc(sizeof(Entity)); @@ -35,7 +43,8 @@ Entity *spawn_enemy(void) { void draw_enemy(Entity *e) { EnemyProperties *props = e->properties; - DrawRectangleRec(props->position, RED); + // DrawRectangleRec(props->position, RED); + DrawTextureRec(*enemy_sprite, (Rectangle) { props->velocity.x > 0 ? 32 : 0, 0, 32, 32 }, (Vector2) { props->position.x, props->position.y }, WHITE); } void update_position_enemy(Entity *e, float dt) { diff --git a/img/enemy.aseprite b/img/enemy.aseprite new file mode 100644 index 0000000..266b5a9 Binary files /dev/null and b/img/enemy.aseprite differ diff --git a/img/enemy.png b/img/enemy.png new file mode 100644 index 0000000..f546e2b Binary files /dev/null and b/img/enemy.png differ