diff --git a/Makefile b/Makefile index 2450243..0f0d972 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,11 @@ -spiel: main.o - gcc -o spiel main.o -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 +spiel: main.o sprite.o + gcc -o spiel main.o sprite.o -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 main.o: main.c gcc -c main.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 +sprite.o: sprite.c + gcc -c sprite.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 + clean: - rm *.o + rm *.o spiel diff --git a/main.c b/main.c index e7ba166..a8f8f3d 100644 --- a/main.c +++ b/main.c @@ -9,13 +9,17 @@ int main(){ InitWindow(800, 450, "basic window"); Texture2D texture; - struct Sprite sprites[100]; + Sprite sprites[100]; texture = LoadTexture("assets/amulet.png"); int spriteAmount = 0; struct Sprite cursorSprite = {&texture, 450, 225}; + texture = LoadTexture("amulet.png"); + + int j = 0; + Sprite cursor = {&texture, 450, 225}; struct InputHandler inputHandler; Camera2D camera = { 0 }; @@ -23,7 +27,7 @@ int main(){ camera.rotation = 0.0f; camera.zoom = 1.0f; - addSprite(sprites, &spriteAmount, &texture, 400, 225); + SpriteAdd(sprites, &j, &texture, cursor.x + camera.target.x, cursor.y + camera.target.y); SetTargetFPS(60); while(!WindowShouldClose()){ @@ -34,9 +38,9 @@ int main(){ BeginMode2D(camera); int i; - int length = sizeof(sprites)/sizeof(sprites[0]); - for(i=0; i < spriteAmount; i++){ - DrawSprite(&sprites[i]); + //int length = sizeof(sprites)/sizeof(sprites[0]); + for(i=0; i < j; i++){ + DrawTexture(*sprites[i].texture, sprites[i].x, sprites[i].y, WHITE); } EndMode2D(); @@ -49,6 +53,12 @@ int main(){ mouseInput(&inputHandler, sprites, &spriteAmount, &texture, &camera); keyboardInput(&inputHandler, &camera); +/* + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)){ + printf("Klick\n"); + SpriteAdd(sprites, &j, &texture, cursor.x + camera.target.x, cursor.y + camera.target.y); + } + */ // Sprites move towards their destination float movementSpeed = 10.0f; diff --git a/main.o b/main.o deleted file mode 100644 index 3b35452..0000000 Binary files a/main.o and /dev/null differ diff --git a/spiel b/spiel deleted file mode 100755 index 73ce6ab..0000000 Binary files a/spiel and /dev/null differ diff --git a/sprite.c b/sprite.c new file mode 100644 index 0000000..894a25f --- /dev/null +++ b/sprite.c @@ -0,0 +1,14 @@ +#include "sprite.h" +#include "raylib.h" + +void SpriteAdd(struct Sprite *cursors, int *j, Texture2D *texture, int x, int y){ + if(*j < 100){ + (cursors + *j) -> texture = texture; + (cursors + *j) -> x = x; + (cursors + *j) -> y = y; + (*j)++; + } + else{ + printf("Voll\n"); + } +} diff --git a/sprite.h b/sprite.h index 280f887..44e32ad 100644 --- a/sprite.h +++ b/sprite.h @@ -1,4 +1,8 @@ -struct Sprite{ +#ifndef SPRITE_H_ +#define SPRITE_H_ +#include "raylib.h" + +typedef struct Sprite { Texture2D *texture; float x; float y; @@ -7,19 +11,6 @@ struct Sprite{ int hasDestination; } Sprite; -void addSprite(struct Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y){ - if(*spriteAmount < 100){ - (sprites + *spriteAmount) -> texture = texture; - (sprites + *spriteAmount) -> x = x; - (sprites + *spriteAmount) -> y = y; - (*spriteAmount)++; - //printf("SPRITE\n"); - } - else{ - printf("Sprites Voll\n"); - } -} +void SpriteAdd(struct Sprite *cursors, int *j, Texture2D *texture, int x, int y); -void DrawSprite(struct Sprite *sprite){ - DrawTexture(*sprite->texture, sprite->x, sprite->y, WHITE); -} \ No newline at end of file +#endif diff --git a/sprite.o b/sprite.o new file mode 100644 index 0000000..459c435 Binary files /dev/null and b/sprite.o differ