From 493b668742ceb28a4e10ca5016e652f9638429aa Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 11 Dec 2024 13:11:41 +0500 Subject: feat: texture for stars --- src/main.c | 20 +++++++++++++++++--- src/star.c | 4 ++-- src/star.h | 3 ++- 3 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index be9a05e..9a6f5a0 100644 --- a/src/main.c +++ b/src/main.c @@ -14,8 +14,17 @@ int main(int argc, char *argv[]) { Star stars[STAR_AMOUNT] = {}; + Texture2D* texture = NULL; + + if (FileExists("star.png")) { + Image image = LoadImage("star.png"); + Texture2D loadedTexture = LoadTextureFromImage(image); + texture = &loadedTexture; + UnloadImage(image); + } + for (int i = 0; i < STAR_AMOUNT; i++) { - stars[i] = StarCreate(); + stars[i] = StarCreate(texture); } while (!WindowShouldClose()) { @@ -39,8 +48,13 @@ int main(int argc, char *argv[]) { StarUpdate(star, screen_center_x, screen_center_y); - DrawRectangle(star->renderPosition.x, star->renderPosition.y, - star->size.x, star->size.y, star->color); + if (star->texture == NULL) { + DrawRectangle(star->renderPosition.x, star->renderPosition.y, + star->size.x, star->size.y, star->color); + } else { + DrawTextureEx(*star->texture, star->renderPosition, 0.0, + star->size.x / 10.0, star->color); + } } EndDrawing(); diff --git a/src/star.c b/src/star.c index 24d2dd0..4676a8f 100644 --- a/src/star.c +++ b/src/star.c @@ -22,13 +22,13 @@ Vector3 Generate3DPosition() { return v; } -Star StarCreate() { +Star StarCreate(Texture *texture) { double velocity = rand() % (STAR_MAX_VELOCITY + 1 - STAR_MIN_VELOCITY) + STAR_MIN_VELOCITY; velocity /= 100.0; - return (Star){Generate3DPosition(), {1, 1}, {0, 0}, velocity, BLACK}; + return (Star){Generate3DPosition(), {1, 1}, {0, 0}, velocity, WHITE, texture}; } void StarUpdate(Star *star, float screen_center_x, float screen_center_y) { diff --git a/src/star.h b/src/star.h index 7de8e8e..2d2774d 100644 --- a/src/star.h +++ b/src/star.h @@ -5,9 +5,10 @@ typedef struct Star { Vector2 size, renderPosition; float velocity; Color color; + Texture *texture; } Star; -Star StarCreate(); +Star StarCreate(Texture *texture); void StarUpdate(Star *star, float screen_center_x, float screen_center_y); Vector3 Generate3DPosition(); -- cgit v1.2.3