diff --git a/Input/inputHandler.c b/Input/inputHandler.c index 9b1cab6..02720f3 100644 --- a/Input/inputHandler.c +++ b/Input/inputHandler.c @@ -167,8 +167,17 @@ void mouseInput(Game *game){ while (current != 0){ if(current->data.selected){ current->data.hasDestination = 1; - current->data.destX = inputHandler->cursorWorldPos.x; - current->data.destY = inputHandler->cursorWorldPos.y; + float destX = inputHandler->cursorWorldPos.x; + float destY = inputHandler->cursorWorldPos.y; + if(destX < 0){ destX = 0; } + if(destY < 0){ destY = 0; } + int maxWidth = (game->layers[0]->widthBounds-1) * game->layers[0]->textureWidth; + int maxHeight = (game->layers[0]->heightBounds-1) * game->layers[0]->textureHeight; + if(destX > maxWidth){ destX = maxWidth; } + if(destY > maxHeight){ destY = maxHeight; } + + current->data.destX = destX; + current->data.destY = destY; } current = current->next; diff --git a/IsometricMap/isometricMap.c b/IsometricMap/isometricMap.c index adddd73..302c605 100644 --- a/IsometricMap/isometricMap.c +++ b/IsometricMap/isometricMap.c @@ -19,6 +19,9 @@ IsometricMap * IsometricMapInit(int layer){ map->heightBounds = 100; map->layer = layer; + map->textureWidth = map->tileTextures[0].width; + map->textureHeight = map->tileTextures[0].height; + Tile*** tiles = (Tile***)malloc(map->widthBounds*sizeof(Tile*)); int n = 0; for(n=0; n < map->widthBounds; n++){ diff --git a/IsometricMap/isometricMap.h b/IsometricMap/isometricMap.h index 5a76f81..93ae01f 100644 --- a/IsometricMap/isometricMap.h +++ b/IsometricMap/isometricMap.h @@ -12,6 +12,8 @@ typedef struct IsometricMap{ int height; int widthBounds; int heightBounds; + int textureWidth; + int textureHeight; int layer; } IsometricMap; diff --git a/IsometricMap/isometricRenderer.c b/IsometricMap/isometricRenderer.c index 79f244a..82811f3 100644 --- a/IsometricMap/isometricRenderer.c +++ b/IsometricMap/isometricRenderer.c @@ -43,13 +43,10 @@ void IsometricRendererRenderIsometricMap(IsometricMap **map, InputHandler *input int i = 0; int j = 0; for(n = 0; n < 10; n++){ - if(map[n] == 0){ - continue; - } for(i=0; i < map[n]->widthBounds; i++){ for(j=0; j < map[n]->heightBounds; j++){ if(map[n]->tiles[i][j]->textureId != -1){ - Vector2 *offset = IsometricMapCalcOffsetForTileAt(i,j, map[n]->tileTextures[0].width); + Vector2 *offset = IsometricMapCalcOffsetForTileAt(i,j, map[n]->textureWidth); float x = map[n]->originX + offset->x; float y = map[n]->originY + offset->y; diff --git a/List/list.c b/List/list.c index 39ba93a..3e480e9 100644 --- a/List/list.c +++ b/List/list.c @@ -2,6 +2,8 @@ #include #include #include "../sprite.h" +#include "raylib.h" +#include "raymath.h" Node * ListCreateNode(Sprite *data){ Node *new = (Node *) malloc(sizeof(Node)); @@ -75,3 +77,45 @@ void ListDrawAllSprites(List *list, IsometricMap *map, Camera2D *camera){ current = current->next; } } + +void ListActAllSprites(Game *game){ + + // Sprites move towards their destination + float movementSpeed = 150.0f * GetFrameTime(); + Node *current = game->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 = game->worker + index; + } + } + + current = current->next; + } + + +} diff --git a/List/list.h b/List/list.h index 2fda7d9..be3263b 100644 --- a/List/list.h +++ b/List/list.h @@ -3,6 +3,7 @@ #include "../sprite.h" #include "../IsometricMap/isometricMap.h" #include "raylib.h" +#include "../game.h" typedef struct Node Node; typedef struct List List; @@ -29,5 +30,6 @@ void ListInsertFront(List *list, Sprite *data); void ListInsertBack(List *list, Sprite *data); List * ListInit(); void ListDrawAllSprites(List *list, IsometricMap *map, Camera2D *camera); +void ListActAllSprites(Game *game); #endif diff --git a/README.md b/README.md index 5a2cc65..a4ec636 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,16 @@ Fantasy Welt oder Realistisch? + LinkedList erweitern + Sprites Animationen etc improven -+ Die Sprites brauchen evtl eine z-Koordinate, die anzeigt auf welchem Layer sie sind, wird aber recht kompliziert. Macht es sinn das Spiel an sich auf ein Layer zu begrenzen und die höheren Layer nur für größere Gebäude zu nutzen, wie z.B. Türme? + Die Inputs sollten den Kamera Zoom beachten, aktuell geht noch alles kaputt wenn man den zoom umstellt + Funktion, um die ganzen Sprites nach ihrer y-Koordinaten sortiert zu drawen -+ Movement speed der Sprites an delta time orientieren ++ Dokumentation anfangen ### WiP + ++ Die Sprites brauchen evtl eine z-Koordinate, die anzeigt auf welchem Layer sie sind + + +### Done + ++ Movement speed der Sprites an delta time orientieren + diff --git a/game.c b/game.c index c875769..020804b 100644 --- a/game.c +++ b/game.c @@ -93,6 +93,18 @@ Game *GameInit() } break; } + if(i == j && n == 1){ + IsometricMapAddTile(((game->layers))[n], i, j, 0); + } + if(i == j && n == 2){ + IsometricMapAddTile(((game->layers))[n], i, j, 0); + } + if(i == j-1 && n == 1){ + IsometricMapAddTile(((game->layers))[n], i, j, 0); + } + if(i-1 == j && n == 1){ + IsometricMapAddTile(((game->layers))[n], i, j, 0); + } } } } diff --git a/game.o b/game.o new file mode 100644 index 0000000..8097acb Binary files /dev/null and b/game.o differ diff --git a/inputHandler.o b/inputHandler.o new file mode 100644 index 0000000..74488be Binary files /dev/null and b/inputHandler.o differ diff --git a/isometricMap.o b/isometricMap.o new file mode 100644 index 0000000..0e949a8 Binary files /dev/null and b/isometricMap.o differ diff --git a/isometricRenderer.o b/isometricRenderer.o new file mode 100644 index 0000000..fcd2c5e Binary files /dev/null and b/isometricRenderer.o differ diff --git a/list.o b/list.o new file mode 100644 index 0000000..934eed6 Binary files /dev/null and b/list.o differ diff --git a/main.c b/main.c index 5a4268f..a4689fc 100644 --- a/main.c +++ b/main.c @@ -13,23 +13,28 @@ int main(){ InitWindow(800, 450, "basic window"); - Texture2D amulet = LoadTexture("assets/amulet.png"); + //Texture2D amulet = LoadTexture("assets/amulet.png"); Game *game = GameInit(); // Hides the operating systems own cursor HideCursor(); - SetTargetFPS(60); + + //SetTargetFPS(60); + + // GAME MAIN ROUTINE while(!WindowShouldClose()){ - BeginDrawing(); + ListActAllSprites(game); ClearBackground(RAYWHITE); + BeginDrawing(); + BeginMode2D(*(game->camera)); + IsometricRendererRenderIsometricMap(game->layers, game->inputHandler); ListDrawAllSprites(game->sprites, game->layers[0], game->camera); - DrawTexture(amulet, 400, 225, WHITE); EndMode2D(); // Moving cursor Sprite to Mouse Pos and drawing it @@ -45,43 +50,6 @@ int main(){ //printf("Cursor Pos: %f %f\n", game->inputHandler->cursorPos.x, game->inputHandler.cursorPos.y)-> //printf("Cursor World Pos: %f %f\n", game->inputHandler->cursorWorldPos.x, game->inputHandler->cursorWorldPos.y); - // Sprites move towards their destination - float movementSpeed = 10.0f; - Node *current = game->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 = game->worker + index; - } - } - - current = current->next; - } - DrawFPS(GetScreenWidth() - 95, 10); EndDrawing(); diff --git a/main.o b/main.o new file mode 100644 index 0000000..5568617 Binary files /dev/null and b/main.o differ diff --git a/spiel b/spiel new file mode 100755 index 0000000..3017c34 Binary files /dev/null and b/spiel differ diff --git a/sprite.c b/sprite.c index 1c4fbad..4ff4670 100644 --- a/sprite.c +++ b/sprite.c @@ -33,6 +33,7 @@ void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera){ else{ DrawTexture(*sprite->texture, pos.x - sprite->texture->width/4, pos.y - sprite->texture->height/4, WHITE); } + printf("%f %f \n", sprite->x, sprite->y); } void DrawSpriteToScreen(Sprite *sprite){ diff --git a/sprite.o b/sprite.o new file mode 100644 index 0000000..64532a0 Binary files /dev/null and b/sprite.o differ diff --git a/tile.o b/tile.o new file mode 100644 index 0000000..ab55776 Binary files /dev/null and b/tile.o differ