Compare commits

...

2 Commits

Author SHA1 Message Date
daf7317c08 Enemy is a rollerskate 2025-03-04 21:02:55 -05:00
d0c6b363b8 Draw player image with sprite offset 2025-03-04 20:49:52 -05:00
4 changed files with 11 additions and 2 deletions

11
enemy.c
View File

@ -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) {

BIN
img/enemy.aseprite Normal file

Binary file not shown.

BIN
img/enemy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

View File

@ -34,7 +34,7 @@ void handle_player_input(Player *p) {
}
void draw_player(Player *p) {
DrawTextureRec(p->spritesheet, (Rectangle) { 128, 128, 128, 128 }, p->position, WHITE);
DrawTextureRec(p->spritesheet, (Rectangle) { 128, 128, 128, 128 }, (Vector2) { p->position.x - 64, p->position.y - 29 }, WHITE);
}
void move_player(Player *p) {