#include "raylib.h" #include #include #include "sprite.h" #include "Input/inputHandler.h" #include "raymath.h" #include "List/list.h" #include "IsometricMap/isometricRenderer.h" #include "IsometricMap/isometricMap.h" int main(){ InitWindow(800, 450, "basic window"); 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 = {&(cursorTextures[0]), 450, 225}; InputHandler inputHandler; inputHandler.pressed = 0; inputHandler.rectStart.x = 0; inputHandler.rectStart.y = 0; inputHandler.cursorPos.x = 0; inputHandler.cursorPos.y = 0; inputHandler.cursorWorldPos.x = 0; inputHandler.cursorWorldPos.y = 0; inputHandler.cursorWorldTile.x = 0; inputHandler.cursorWorldTile.y = 0; inputHandler.selectedLayer = -1; inputHandler.cursorTextures = cursorTextures; inputHandler.cursorSprite = &cursorSprite; Camera2D camera = { 0 }; camera.target = (Vector2){0, 0}; camera.rotation = 0.0f; camera.zoom = 1.0f; IsometricMap **layers = (IsometricMap **) malloc(10*sizeof(IsometricMap *)); // Test Layers --- int n = 0; int i = 0; int j = 0; for(n = 0; n < 10; n++){ layers[n] = IsometricMapInit(n); } for(n = 0; n <= 10; n++){ for(i = 0; i < 100; i++){ for(j = 0; j < 100; j++){ switch(n){ case 0: IsometricMapAddTile(layers[n], i, j, 0); break; case 1: if(i > 35 && i < 50 && j > 45 && j < 60){ IsometricMapAddTile(layers[n], i, j, 0); } break; case 2: if(i > 40 && i < 44 && j > 50 && j < 54){ IsometricMapAddTile(layers[n], i, j, 1); } break; } } } } for(n = 0; n <= 10; n++){ for(i = 0; i < 20-n*2; i++){ for(j = 0; j < 20-n*2; j++){ IsometricMapAddTile(layers[n], i, j, 0); if(n == 9){ IsometricMapAddTile(layers[n], i, j, 1); } } } } // ------- // Test of the IsometricMapUnproject Function //Vector2 asdf = {500, 600}; //printf("unprojected %f %f\n",asdf.x, asdf.y); //IsometricMapProject(layers[0], &camera, asdf.x, asdf.y, &asdf); //printf("projected %f %f\n",asdf.x, asdf.y); //IsometricMapUnproject(layers[0], &camera, asdf.x, asdf.y, &asdf); //printf("unprojected %f %f\n",asdf.x, asdf.y); // Hides the operating systems own cursor HideCursor(); SetTargetFPS(60); while(!WindowShouldClose()){ BeginDrawing(); ClearBackground(RAYWHITE); BeginMode2D(camera); IsometricRendererRenderIsometricMap(layers, &inputHandler); ListDrawAllSprites(sprites, layers[0], &camera); EndMode2D(); // Moving cursor Sprite to Mouse Pos and drawing it cursorSprite.x = inputHandler.cursorPos.x; cursorSprite.y = inputHandler.cursorPos.y; DrawSpriteToScreen(&cursorSprite); // User Input Handling mouseInput(&inputHandler, sprites, worker+4, &camera, layers); keyboardInput(&inputHandler, &camera); //cursor Positions test //printf("Cursor Pos: %f %f\n", inputHandler.cursorPos.x, inputHandler.cursorPos.y); //printf("Cursor World Pos: %f %f\n", inputHandler.cursorWorldPos.x, inputHandler.cursorWorldPos.y); // Sprites move towards their destination float movementSpeed = 10.0f; Node *current = sprites->head; while (current != 0){ if(current->data.hasDestination == 1){ Vector2 movement = { current->data.destX - current->data.x, current->data.destY - current->data.y }; if(Vector2Length(movement) < movementSpeed){ current->data.hasDestination = 0; current->data.x = current->data.destX; current->data.y = current->data.destY; } else{ movement = Vector2Normalize(movement); 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(); } CloseWindow(); return 0; }