Sprites updated

main
Jonathan Hager 3 years ago
parent e836ba2510
commit d4fe236bda
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -71,6 +71,9 @@ void mouseInput(InputHandler *inputHandler, List *sprites, Texture2D *texture, C
inputHandler->rectStart.x = GetMousePosition().x;
inputHandler->rectStart.y = GetMousePosition().y;
inputHandler->pressed = 1;
// Cursorsprite is changed to "down"
inputHandler->cursorSprite->texture = (inputHandler->cursorTextures) + 1;
}
}
@ -81,6 +84,8 @@ void mouseInput(InputHandler *inputHandler, List *sprites, Texture2D *texture, C
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)){
inputHandler->pressed = 0;
// Cursorsprite is rechanged to normal
inputHandler->cursorSprite->texture = (inputHandler->cursorTextures);
float width = GetMousePosition().x - inputHandler->rectStart.x;
float height = GetMousePosition().y - inputHandler->rectStart.y;

@ -11,6 +11,8 @@ typedef struct InputHandler{
Vector2 cursorPos;
Vector2 selectedTile;
int selectedLayer;
Texture2D *cursorTextures;
Sprite *cursorSprite;
} InputHandler;
void mouseInput(InputHandler *inputHandler, List *sprites, Texture2D *texture, Camera2D *camera, IsometricMap *map);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 710 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 764 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 805 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 845 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 795 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 848 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 848 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 729 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
list.o

Binary file not shown.

@ -11,15 +11,34 @@
int main(){
InitWindow(800, 450, "basic window");
Texture2D texture;
texture = LoadTexture("assets/amulet.png");
Texture2D amulet;
amulet = LoadTexture("assets/amulet.png");
Image worker1flip = LoadImage("assets/worker/worker-1.png");
ImageFlipHorizontal(&worker1flip);
Image worker2flip = LoadImage("assets/worker/worker-2.png");
ImageFlipHorizontal(&worker2flip);
Image worker3flip = LoadImage("assets/worker/worker-3.png");
ImageFlipHorizontal(&worker3flip);
Texture2D worker[8];
worker[6] = LoadTexture("assets/worker/worker-0.png");
worker[5] = LoadTexture("assets/worker/worker-1.png");
worker[7] = LoadTextureFromImage(worker1flip);
worker[4] = LoadTexture("assets/worker/worker-2.png");
worker[0] = LoadTextureFromImage(worker2flip);
worker[3] = LoadTexture("assets/worker/worker-3.png");
worker[1] = LoadTextureFromImage(worker3flip);
worker[2] = LoadTexture("assets/worker/worker-4.png");
Texture2D cursorTextures[2];
cursorTextures[0] = LoadTexture("assets/cursor.gif");
cursorTextures[1] = LoadTexture("assets/cursor_down.gif");
List *sprites = ListInit();
//ListPrintForward(sprites);
Sprite cursorSprite = {&texture, 450, 225};
Sprite cursorSprite = {&(cursorTextures[0]), 450, 225};
InputHandler inputHandler;
inputHandler.pressed = 0;
@ -30,6 +49,8 @@ int main(){
inputHandler.selectedTile.x = 0;
inputHandler.selectedTile.y = 0;
inputHandler.selectedLayer = 0;
inputHandler.cursorTextures = cursorTextures;
inputHandler.cursorSprite = &cursorSprite;
Camera2D camera = { 0 };
camera.target = (Vector2){0, 0};
@ -47,6 +68,8 @@ int main(){
IsometricMapAddTile(Layer4, 2, 2, 1);
// Hides the operating systems own cursor
HideCursor();
SetTargetFPS(60);
while(!WindowShouldClose()){
@ -67,12 +90,12 @@ int main(){
EndMode2D();
// Moving cursor Sprite to Mouse Pos and drawing it
cursorSprite.x = inputHandler.cursorPos.x - texture.width / 2;
cursorSprite.y = inputHandler.cursorPos.y - texture.height / 2;
cursorSprite.x = inputHandler.cursorPos.x;
cursorSprite.y = inputHandler.cursorPos.y;
DrawSprite(&cursorSprite);
// User Input Handling
mouseInput(&inputHandler, sprites, &texture, &camera, map);
mouseInput(&inputHandler, sprites, worker+4, &camera, map);
keyboardInput(&inputHandler, &camera);
// Sprites move towards their destination
@ -96,12 +119,24 @@ int main(){
movement = Vector2Scale(movement, movementSpeed);
current->data.x += movement.x;
current->data.y += movement.y;
// Change sprite according to direction
Vector2 nullvektor = {0,0};
float f = Vector2Angle(movement, nullvektor);
printf("Angle: %f\n", f);
f /= 3.14;
f *= 3.5;
f += 3.5;
int index = (int) f;
current->data.texture = worker + index;
}
}
current = current->next;
}
DrawFPS(GetScreenWidth() - 95, 10);
EndDrawing();
}

BIN
main.o

Binary file not shown.

BIN
spiel

Binary file not shown.

@ -22,7 +22,8 @@ void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, in
void DrawSprite(Sprite *sprite){
if(sprite->selected){
DrawTexture(*sprite->texture, sprite->x, sprite->y, BLACK);
DrawTexture(*sprite->texture, sprite->x, sprite->y, WHITE);
//DrawTexture(*sprite->texture, sprite->x, sprite->y, BLACK);
}
else{
DrawTexture(*sprite->texture, sprite->x, sprite->y, WHITE);

Binary file not shown.

BIN
tile.o

Binary file not shown.
Loading…
Cancel
Save