diff --git a/.vscode/settings.json b/.vscode/settings.json index 66e1870..ab0fa52 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,11 @@ { - "C_Cpp.errorSquiggles": "Disabled", + "C_Cpp.errorSquiggles": "Enabled", "files.associations": { "isometricrenderer.h": "c", "sprite.h": "c", "map": "c", "isometricmap.h": "c", - "animationhandler.h": "c" + "animationhandler.h": "c", + "textureids.h": "c" } } \ No newline at end of file diff --git a/Input/inputHandler.c b/Input/inputHandler.c index 0a49b35..2b5f428 100644 --- a/Input/inputHandler.c +++ b/Input/inputHandler.c @@ -66,7 +66,7 @@ void mouseInput(Game *game){ // resetting last selected Tile to grass texture if(inputHandler->selectedLayer != -1){ - IsometricMapChangeTextureIdOfTile(layers[inputHandler->selectedLayer], (int) inputHandler->cursorWorldTile.x, (int) inputHandler->cursorWorldTile.y, 0); + IsometricMapChangeTextureIdOfTile(layers, (int) inputHandler->cursorWorldTile.x, (int) inputHandler->cursorWorldTile.y, inputHandler->selectedLayer, 0); } /* TODO: n=9 no good style, Segmentation fault when n > layerAmount @@ -74,6 +74,7 @@ void mouseInput(Game *game){ -> Stash size in another variable. printf("%ld \n", sizeof(*layers) / sizeof(layers[0])); */ + // hardcoded layer amount int n = 9; for(n = 9; n >= 0 ; n--){ if(layers[n] != 0){ @@ -84,14 +85,14 @@ void mouseInput(Game *game){ IsometricMapProject(layers[n], camera, inputHandler->cursorPos.x + mouseAdjustmentX, inputHandler->cursorPos.y + mouseAdjustmentY, &inputHandler->cursorWorldPos); - Tile *selectedTile = IsometricMapGetTileFromWorldCoordinates(layers[n], inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y); + Tile *selectedTile = IsometricMapGetTileFromWorldCoordinates(layers, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y, n); if(selectedTile != 0){ inputHandler->cursorWorldTile.x = selectedTile->x; inputHandler->cursorWorldTile.y = selectedTile->y; inputHandler->selectedLayer = n; // setting currently selected tile to tower - IsometricMapChangeTextureIdOfTile(layers[n], inputHandler->cursorWorldTile.x, inputHandler->cursorWorldTile.y, 1); + IsometricMapChangeTextureIdOfTile(layers, inputHandler->cursorWorldTile.x, inputHandler->cursorWorldTile.y, n, 1); break; } } @@ -122,34 +123,33 @@ void mouseInput(Game *game){ float height = GetMousePosition().y - inputHandler->rectStart.y; // Add Sprite - if(width + height <= 1){ - ListInsertBack(sprites, SpriteCreate(game->textures, 1, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y)); + if(abs(width) + abs(height) < 20){ + int maxWidth = (game->layers[0]->width-1) * game->layers[0]->textureWidth; + int maxHeight = (game->layers[0]->height-1) * game->layers[0]->textureHeight; + if(inputHandler->cursorWorldPos.x < 0){ printf("OutOfBoundsDestination Spawn\n");} + else if(inputHandler->cursorWorldPos.y < 0){ printf("OutOfBoundsDestination Spawn\n");} + else if(inputHandler->cursorWorldPos.x > maxWidth){ printf("OutOfBoundsDestination Spawn\n");} + else if(inputHandler->cursorWorldPos.y > maxHeight){ printf("OutOfBoundsDestination Spawn\n");} + else { + ListInsertBack(sprites, SpriteCreate(game->textures, 1, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y)); + } } - // Berechnung, welche Sprites ausgewählt wurden, scuffed - // TODO: ist wirklich sehr scuffed wegen negativen koordinaten etc - // Problem: Theoretisch einfach nur schauen ob unprojected Sprite coords im Rect liegen - // Muss aber unterschieden werden ob width negativ oder so ist, aber einfach abs funktioniert nicht - // So wie es aktuell ist, funktioniert die Auswahl, aber nur solange die Kamera nicht bewegt wird + // Berechnung, welche Sprites ausgewählt wurden Vector2 rect = GetRectangle(inputHandler->rectStart); width = abs(width); height = abs(height); - //printf("Auswahl: x: %f, y: %f, w: %f, h: %f\n", rect.x, rect.y, width, height); - - // TODO: update to World Coordinates float deltaX; float deltaY; Node *current = sprites->head; while (current != 0){ - Vector2 currPos = {current->data.x, current->data.y}; - IsometricMapUnproject(layers[0], camera, currPos.x, currPos.y, &currPos); + Vector2 currPos = {current->data.x + current->data.texture->width, current->data.y + current->data.texture->height/2}; + IsometricMapUnproject(layers, camera, currPos.x, currPos.y, current->data.z, &currPos); deltaX = currPos.x - camera->target.x - (rect.x + camera->target.x); deltaY = currPos.y - camera->target.y - (rect.y + camera->target.y); - //printf("deltaX: %f, deltaY: %f\n", deltaX, deltaY); - if(deltaX > 0 && deltaX < width && deltaY > 0 && deltaY < height){ current->data.selected = 1; } @@ -169,18 +169,18 @@ void mouseInput(Game *game){ current->data.hasDestination = 1; 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; } + int maxWidth = (game->layers[0]->width-1) * game->layers[0]->textureWidth; + int maxHeight = (game->layers[0]->height-1) * game->layers[0]->textureHeight; + if(destX < 0){ printf("OutOfBoundsDestination\n"); goto skip; } + if(destY < 0){ printf("OutOfBoundsDestination\n"); goto skip; } + if(destX > maxWidth){ printf("OutOfBoundsDestination\n"); goto skip; } + if(destY > maxHeight){ printf("OutOfBoundsDestination\n"); goto skip; } current->data.destX = destX; current->data.destY = destY; } - current = current->next; + skip: current = current->next; } } } diff --git a/IsometricMap/isometricMap.c b/IsometricMap/isometricMap.c index fe8307d..254e90d 100644 --- a/IsometricMap/isometricMap.c +++ b/IsometricMap/isometricMap.c @@ -5,6 +5,7 @@ #include "raymath.h" #include "raylib.h" +// returns pointer to IsometricMap Instance IsometricMap * IsometricMapInit(int layer){ IsometricMap* map = (IsometricMap *) malloc(sizeof(IsometricMap)); @@ -15,31 +16,32 @@ IsometricMap * IsometricMapInit(int layer){ //map->tileTextures[0] = LoadTexture("assets/desert.png"); //map->tileTextures[1] = LoadTexture("assets/bigtower.png"); - map->originX = 0; - map->originY = -layer * map->tileTextures[0].width / 4; - map->width = 100 * map->tileTextures[0].width; - map->height = 100 * map->tileTextures[0].height; - map->widthBounds = 100; - map->heightBounds = 100; - map->layer = layer; - + map->width = 100; + map->height = 100; map->textureWidth = map->tileTextures[0].width; map->textureHeight = map->tileTextures[0].height; + map->worldPixelWidth = map->width * map->textureWidth; + map->worldPixelWidth = map->height * map->textureHeight; + map->layer = layer; - Tile*** tiles = (Tile***)malloc(map->widthBounds*sizeof(Tile*)); + + // mallocating the twodimensional Tiles Array + Tile*** tiles = (Tile***)malloc(map->width*sizeof(Tile*)); int n = 0; - for(n=0; n < map->widthBounds; n++){ - tiles[n] = (Tile**)malloc(map->heightBounds*sizeof(Tile*)); + for(n=0; n < map->width; n++){ + tiles[n] = (Tile**)malloc(map->height*sizeof(Tile*)); } int i = 0; int j = 0; - for(i=0; i < map->widthBounds; i++){ - for(j=0; j < map->heightBounds; j++){ + for(i=0; i < map->width; i++){ + for(j=0; j < map->height; j++){ Tile *tmp = (Tile *) malloc(sizeof(Tile)); + // initially all the Tiles are "empty" tmp->textureId = -1; tmp->x = i; tmp->y = j; + tmp->z = layer; tiles[i][j] = tmp; } } @@ -49,6 +51,8 @@ IsometricMap * IsometricMapInit(int layer){ return map; } +// For Rendering: calculates coordinate offset for a single tile at arrayPosition x y +// Only works for tiles with texture width == height (and for 22.5 degree?) Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){ Vector2* offset = (Vector2 *)malloc(sizeof(Vector2)); offset->x = x * textureSize/2 - y * textureSize/2; @@ -56,15 +60,16 @@ Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){ return offset; } +// returns Tile at x y on layer isometricMap Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *map, int x, int y){ return map->tiles[x][y]; } -// Project: Screen Coordinates -> World Coordinates +// Unproject: World Coordinates -> Screen Coordinates writes result in tmp Vector void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float y, Vector2 *tmp){ - float tileWidthHalf = isometricMap->tileTextures[0].width / 2; - float tileHeightQuarter = isometricMap->tileTextures[0].height / 4; + float tileWidthHalf = isometricMap->textureWidth / 2; + float tileHeightQuarter = isometricMap->textureHeight / 4; x += camera->target.x; y += camera->target.y; @@ -72,7 +77,6 @@ void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float xPos = (float) x; float yPos = (float) y; - float isoX = 0.5 * ( xPos / tileWidthHalf + yPos / tileHeightQuarter); float isoY = 0.5 * ( -xPos / tileWidthHalf + yPos / tileHeightQuarter); @@ -80,52 +84,70 @@ void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, tmp->y = isoY * isometricMap->tileTextures[0].height; } -// Unproject: World Coordinates -> Screen Coordinates -void IsometricMapUnproject(IsometricMap *isometricMap, Camera2D *camera, int x, int y, Vector2 *tmp){ +// Unproject: World Coordinates -> Screen Coordinates writes result in tmp Vector +void IsometricMapUnproject(IsometricMap **isometricMap, Camera2D *camera, int x, int y, float z, Vector2 *tmp){ float xPos = (float) x; float yPos = (float) y; - float worldX = (xPos - yPos) / 2; - float worldY = (xPos + yPos) / 4; + float screenX = (xPos - yPos) / 2; + float screenY = (xPos + yPos) / 4; - worldX += camera->target.x; - worldY += camera->target.y; + screenX += camera->target.x; + screenY += camera->target.y; - tmp->x = worldX; - tmp->y = worldY; + // z is currently implemented as z=1 equals 1 layer, z=2 would be two layers height (could be smoothed) + // hardcoded tile height + screenY -= z * 10; + + tmp->x = screenX; + tmp->y = screenY; } -Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap *isometricMap, float x, float y){ +// returns Tile * -> tile at coordinates x y z=layer +Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap **isometricMap, float x, float y, float z){ - x = (int)(x / isometricMap->tileTextures->width); - y = (int)(y / isometricMap->tileTextures->height); - - Tile *ptr = (Tile *) malloc(sizeof(Tile *)); - ptr->x = 0; - ptr->y = 0; + int layer = (int) z; - if( x < isometricMap->widthBounds && y < isometricMap->heightBounds && - x >= 0 && y >= 0 ){ - if(isometricMap->tiles[(int)x][(int)y]->textureId != -1){ - ptr->x = isometricMap->tiles[(int)x][(int)y]->x; - ptr->y = isometricMap->tiles[(int)x][(int)y]->y; - return ptr; + x = (int)(x / isometricMap[layer]->textureWidth); + y = (int)(y / isometricMap[layer]->textureHeight); + + if( x < isometricMap[layer]->width && y < isometricMap[layer]->height && x >= 0 && y >= 0 ){ + if(isometricMap[layer]->tiles[(int)x][(int)y]->textureId != -1){ + return (isometricMap[layer]->tiles[(int)x][(int)y]); } } - ptr = 0; + Tile *ptr = 0; return ptr; } -// IsometricMapAddTile and IsometricMapChangeTextureIdOfTile pretty much do the same by now... -void IsometricMapAddTile(IsometricMap *isometricMap, int x, int y, int textureId){ - isometricMap->tiles[x][y]->textureId = textureId; - isometricMap->tiles[x][y]->x = x; - isometricMap->tiles[x][y]->y = y; +// Gives the most upper Tile above *tile +Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile){ + Tile *ptr = (Tile *) malloc(sizeof(Tile *)); + // hardcoded layer amount + int n = 9; + for(n=9;n>=0;n--){ + if( tile->x < isometricMap[n]->width && tile->y < isometricMap[n]->height && + tile->x >= 0 && tile->y >= 0 ){ + if(isometricMap[n]->tiles[tile->x][tile->y]->textureId != -1){ + ptr->x = isometricMap[n]->tiles[tile->x][tile->y]->x; + ptr->y = isometricMap[n]->tiles[tile->x][tile->y]->y; + ptr->z = isometricMap[n]->tiles[tile->x][tile->y]->z; + return ptr; + } + } + } + ptr = 0; + return ptr; } -void IsometricMapChangeTextureIdOfTile(IsometricMap *map, int x, int y, int id){ - if( x < map->widthBounds && y < map->heightBounds && + +// changes to Texture ID of tile at x y on maplayer layer +void IsometricMapChangeTextureIdOfTile(IsometricMap **map, int x, int y, int layer, int id){ + if( x < map[layer]->width && y < map[layer]->height && x >= 0 && y >= 0 ){ - (map->tiles[x][y])->textureId = id; - } + (map[layer]->tiles[x][y])->textureId = id; + } + else{ + printf("WARNING: trying to change Texture of Tile which is out of bounds!\n"); + } } diff --git a/IsometricMap/isometricMap.h b/IsometricMap/isometricMap.h index 2a4c8fb..2a8ec2c 100644 --- a/IsometricMap/isometricMap.h +++ b/IsometricMap/isometricMap.h @@ -4,30 +4,59 @@ #include "tile.c" typedef struct IsometricMap{ + // Array with all the needed textures for this layer Texture2D tileTextures[10]; + + // twodimensional array of all the tiles in this layer Tile ***tiles; - int originX; - int originY; - // TODO: überprüfen, ob width/height und widthBounds/heightBounds überhaupt noch unterschiedlich sind. Wenn nicht eins der beiden löschen + + // amount of tiles in x-direction int width; + + // amount of tiles in y-direction int height; - int widthBounds; - int heightBounds; + + // pixel width of a single tile texture int textureWidth; + + // pixel height of a single tile texture int textureHeight; + + // pixel width of the entire map + int worldPixelWidth; + + // pixel height of the entire map + int worldPixelHeight; + + // layer of the map int layer; } IsometricMap; +// returns pointer to IsometricMap Instance IsometricMap * IsometricMapInit(int layer); + +// For Rendering: calculates coordinate offset for a single tile at arrayPosition x y +// Only works for tiles with texture width == height (and for 22.5 degree?) Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize); + +// Gives the most upper Tile above *tile +Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile); + +// returns Tile at x y on layer isometricMap Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *isometricMap, int x, int y); -// Project: Screen Coordinates -> World Coordinates + +// Project: Screen Coordinates -> World Coordinates writes result in tmp Vector +// Currently only calcing coords on layer 0 void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float y, Vector2 *tmp); -// Unproject: World Coordinates -> Screen Coordinates -void IsometricMapUnproject(IsometricMap *isometricMap, Camera2D *camera, int x, int y, Vector2 *tmp); -void IsometricMapAddTile(IsometricMap *isometricMap, int x, int y, int textureId); -void IsometricMapChangeTextureIdOfTile(IsometricMap *map, int x, int y, int id); -Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap *isometricMap, float x, float y); + +// Unproject: World Coordinates -> Screen Coordinates writes result in tmp Vector +void IsometricMapUnproject(IsometricMap **isometricMap, Camera2D *camera, int x, int y, float z, Vector2 *tmp); + +// changes to Texture ID of tile at x y on maplayer layer +void IsometricMapChangeTextureIdOfTile(IsometricMap **map, int x, int y, int layer, int id); + +// returns Tile * -> tile at coordinates x y z=layer +Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap **isometricMap, float x, float y, float layer); #endif diff --git a/IsometricMap/isometricRenderer.c b/IsometricMap/isometricRenderer.c index 3e7f706..d33e7c4 100644 --- a/IsometricMap/isometricRenderer.c +++ b/IsometricMap/isometricRenderer.c @@ -4,6 +4,7 @@ #include "../Input/inputHandler.h" #include #include +#include "../game.h" // @param deprecated void IsometricRendererDrawMap(IsometricRenderer *renderer, int height){ @@ -38,23 +39,23 @@ void IsometricRendererDrawMap(IsometricRenderer *renderer, int height){ } } -void IsometricRendererRenderIsometricMap(IsometricMap **map, InputHandler *input){ +// parameter could be changed to only IsometricMap[] +void IsometricRendererRenderIsometricMap(Game *game){ int n = 0; int i = 0; int j = 0; for(n = 0; n < 10; n++){ - 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]->textureWidth); + for(i=0; i < game->layers[n]->width; i++){ + for(j=0; j < game->layers[n]->height; j++){ + // if tile had texture id -1, it would be empty tile + if(game->layers[n]->tiles[i][j]->textureId != -1){ + Vector2 *offset = IsometricMapCalcOffsetForTileAt(i,j, game->layers[n]->textureWidth); + // the higher the layer the higher it needs to be drawed + offset->y -= n * (game->layers[n]->textureHeight/4); + + int textureId = game->layers[n]->tiles[i][j]->textureId; - int textureId = map[n]->tiles[i][j]->textureId; - - float x = map[n]->originX + offset->x; - float y = map[n]->originY + offset->y + map[n]->textureHeight - map[n]->tileTextures[textureId].height; - - - DrawTexture(map[n]->tileTextures[textureId], x, y, WHITE); + DrawTexture(game->layers[n]->tileTextures[textureId], offset->x, offset->y, WHITE); free(offset); } } diff --git a/IsometricMap/isometricRenderer.h b/IsometricMap/isometricRenderer.h index 7de86d0..d88db04 100644 --- a/IsometricMap/isometricRenderer.h +++ b/IsometricMap/isometricRenderer.h @@ -3,6 +3,7 @@ #include "raylib.h" #include "isometricMap.h" #include "../Input/inputHandler.h" +#include "../game.h" typedef struct IsometricRenderer{ Texture *texture; @@ -11,6 +12,6 @@ typedef struct IsometricRenderer{ // @param deprecated void IsometricRendererDrawMap(IsometricRenderer *renderer, int height); -void IsometricRendererRenderIsometricMap(IsometricMap **map, InputHandler *input); +void IsometricRendererRenderIsometricMap(Game *game); #endif \ No newline at end of file diff --git a/IsometricMap/tile.h b/IsometricMap/tile.h index 62c052b..9154798 100644 --- a/IsometricMap/tile.h +++ b/IsometricMap/tile.h @@ -2,10 +2,12 @@ #define TILE_H_ #include "raylib.h" +// Tile with textureid = -1 wouldn't be drawed, would just be a placeholder tile typedef struct Tile{ int textureId; int x; int y; + int z; } Tile; #endif \ No newline at end of file diff --git a/List/list.c b/List/list.c index d4ab057..1e0b6d9 100644 --- a/List/list.c +++ b/List/list.c @@ -18,7 +18,7 @@ void ListPrintForward(List *list){ printf("\n[\n"); while(current != 0){ - printf("(%f | %f),\n", current->data.x, current->data.y); + //printf("(%f | %f),\n", current->data.x, current->data.y); current = current->next; } printf("]\n"); @@ -69,7 +69,8 @@ List * ListInit(){ return newList; } -void ListDrawAllSprites(List *list, IsometricMap *map, Camera2D *camera){ +// iterates over all Sprites in the list and draws them to the world +void ListDrawAllSprites(List *list, IsometricMap **map, Camera2D *camera){ Node *current = list->head; while(current != 0){ @@ -78,6 +79,7 @@ void ListDrawAllSprites(List *list, IsometricMap *map, Camera2D *camera){ } } +// iterates over all Sprites in the list and does their acting (moving etc) void ListActAllSprites(Game *game){ // Sprites move towards their destination @@ -90,7 +92,6 @@ void ListActAllSprites(Game *game){ 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; @@ -105,7 +106,7 @@ void ListActAllSprites(Game *game){ // Change sprite according to direction Vector2 nullvektor = {0,0}; float f = Vector2Angle(movement, nullvektor); - printf("Angle: %f\n", f); + //printf("Angle: %f\n", f); f /= 3.14; f *= 3.5; f += 3.5; @@ -115,6 +116,10 @@ void ListActAllSprites(Game *game){ } SpriteUpdateAnimation(¤t->data); + // updating z-position according to the tile the sprite stands on + Tile *floorTile = IsometricMapGetTileFromWorldCoordinates(game->layers, current->data.x, current->data.y, 0); + Tile *topTile = IsometricMapGetMostUpperTile(game->layers, floorTile); + current->data.z = topTile->z; current = current->next; } diff --git a/List/list.h b/List/list.h index be3263b..a7e80f9 100644 --- a/List/list.h +++ b/List/list.h @@ -29,7 +29,7 @@ void ListPrintForward(List *list); void ListInsertFront(List *list, Sprite *data); void ListInsertBack(List *list, Sprite *data); List * ListInit(); -void ListDrawAllSprites(List *list, IsometricMap *map, Camera2D *camera); +void ListDrawAllSprites(List *list, IsometricMap **map, Camera2D *camera); void ListActAllSprites(Game *game); #endif diff --git a/README.md b/README.md index ef051c6..7a16309 100644 --- a/README.md +++ b/README.md @@ -21,15 +21,13 @@ Fantasy Welt oder Realistisch? + Sprites Animationen etc improven + 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 -+ Die Sprites brauchen evtl eine z-Koordinate, die anzeigt auf welchem Layer sie sind -+ Die Sprites müssen auch entsprechend ihrer z-Koordinaten gedrawed werden -+ Wollen wir die Möglichkeit für Höhlen haben? -> Sprites könnten automatisch das höchste Tile als z nehmen (wenn keine Höhlen) ++ Drawable Container machen, die sortiert werden können, dort kommen alle Tiles und Sprites rein, damit sie dann sortiert werden können + Maps in eigenen Dateien speichern + Parser für Map-Dateien + MapEditor -+ IsometricMap variablen auf Duplikate prüfen * Rendering Reihenfolge: layer 0, Sprites auf layer 0, layer 1, Sprites auf layer 1; Theoretisch müssen die einzelnen Layer Reihenweise gedrawed werden mit den Sprites zwischendrin -+ IsometricMap Refactoren? ++ IsometricMap struct erstellen, das den IsometricMap(+Layer) Array speichert ? + ### WiP diff --git a/animation.o b/animation.o new file mode 100644 index 0000000..d2ba2c3 Binary files /dev/null and b/animation.o differ diff --git a/animationHandler.o b/animationHandler.o new file mode 100644 index 0000000..036ae10 Binary files /dev/null and b/animationHandler.o differ diff --git a/game.c b/game.c index 9136727..fb07a95 100644 --- a/game.c +++ b/game.c @@ -8,6 +8,7 @@ #include "Textures/textureatlas.h" #include "stdio.h" +// returns pointer to new Game instance Game *GameInit() { Game *game = (Game *)malloc(sizeof(Game)); @@ -67,57 +68,57 @@ Game *GameInit() ((game->layers))[n] = IsometricMapInit(n); } - for (n = 0; n <= 10; n++) + for (n = 0; n < 10; n++) { for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { + if(i > 50 && i < 70 && j == 50){ + IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0); + } + switch (n) { case 0: - IsometricMapAddTile(((game->layers))[n], i, j, 0); + IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0); break; case 1: if (i > 35 && i < 50 && j > 45 && j < 60) { - IsometricMapAddTile(((game->layers))[n], i, j, 0); + IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0); } break; case 2: if (i > 40 && i < 44 && j > 50 && j < 54) { - IsometricMapAddTile(((game->layers))[n], i, j, 2); + IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 2); } break; } if(i == j && n == 1){ - IsometricMapAddTile(((game->layers))[n], i, j, 0); + IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0); } if(i == j && n == 2){ - IsometricMapAddTile(((game->layers))[n], i, j, 0); + IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0); } if(i == j-1 && n == 1){ - IsometricMapAddTile(((game->layers))[n], i, j, 0); + IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0); } if(i-1 == j && n == 1){ - IsometricMapAddTile(((game->layers))[n], i, j, 0); + IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0); } } } } - for (n = 0; n <= 10; n++) + for (n = 0; n < 10; n++) { for (i = 0; i < 20 - n * 2; i++) { for (j = 0; j < 20 - n * 2; j++) { - IsometricMapAddTile(((game->layers))[n], i, j, 0); - if (n == 9) - { - IsometricMapAddTile(((game->layers))[n], i, j, 2); - } + IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0); } } } diff --git a/game.h b/game.h index 190ac8e..855a416 100644 --- a/game.h +++ b/game.h @@ -3,7 +3,6 @@ #include "raylib.h" -// So kann man die includes umgehen, also keine Circular dependencies mehr :) typedef struct Game{ Texture2D worker[8]; struct TextureAtlas *textures; @@ -14,6 +13,7 @@ typedef struct Game{ struct IsometricMap **layers; } Game; +// returns pointer to new Game instance Game * GameInit(); #endif \ No newline at end of file diff --git a/game.o b/game.o new file mode 100644 index 0000000..15b4110 Binary files /dev/null and b/game.o differ diff --git a/inputHandler.o b/inputHandler.o new file mode 100644 index 0000000..25dcc7e Binary files /dev/null and b/inputHandler.o differ diff --git a/isometricMap.o b/isometricMap.o new file mode 100644 index 0000000..962bce1 Binary files /dev/null and b/isometricMap.o differ diff --git a/isometricRenderer.o b/isometricRenderer.o new file mode 100644 index 0000000..04886c9 Binary files /dev/null and b/isometricRenderer.o differ diff --git a/list.o b/list.o new file mode 100644 index 0000000..e431ea4 Binary files /dev/null and b/list.o differ diff --git a/main.c b/main.c index a4689fc..e20c9b3 100644 --- a/main.c +++ b/main.c @@ -31,9 +31,8 @@ int main(){ BeginMode2D(*(game->camera)); - IsometricRendererRenderIsometricMap(game->layers, game->inputHandler); - - ListDrawAllSprites(game->sprites, game->layers[0], game->camera); + IsometricRendererRenderIsometricMap(game); + ListDrawAllSprites(game->sprites, game->layers, game->camera); EndMode2D(); @@ -45,11 +44,7 @@ int main(){ // User Input Handling mouseInput(game); keyboardInput(game->inputHandler, game->camera); - - //cursor Positions test - //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); - + DrawFPS(GetScreenWidth() - 95, 10); EndDrawing(); diff --git a/main.o b/main.o new file mode 100644 index 0000000..4d2d6ab Binary files /dev/null and b/main.o differ diff --git a/spiel b/spiel new file mode 100755 index 0000000..dbd94bf Binary files /dev/null and b/spiel differ diff --git a/sprite.c b/sprite.c index 38845b4..dccc7a7 100644 --- a/sprite.c +++ b/sprite.c @@ -7,13 +7,19 @@ #include "Textures/animationHandler.h" #include "Textures/animation.h" #include "Textures/textureatlas.h" +#include "IsometricMap/tile.h" +// @param deprecated void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y){ + printf("WARNING: Using deprecated Function SpriteAdd!\n"); /* + + if(*spriteAmount < 100){ (sprites + *spriteAmount) -> texture = texture; (sprites + *spriteAmount) -> x = x; (sprites + *spriteAmount) -> y = y; + (sprites + *spriteAmount) -> z = 0; (sprites + *spriteAmount) -> destX = x; (sprites + *spriteAmount) -> destY = y; (sprites + *spriteAmount) -> hasDestination = 0; @@ -26,31 +32,32 @@ void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, in */ } -void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera){ +void DrawSpriteToWorld(Sprite *sprite, IsometricMap **map, Camera2D *camera){ // TODO: Nach y sortieren, bevor sie gedrawed werden // Wir müssen beachten, dass sie nach den unprojezierten Screen-Koordinaten sortiert werden müssen. // Macht es vielleicht sinn den Sprites auch einen Vector mit ihren Screen Koordinaten zu geben? - Vector2 pos = {sprite->x, sprite->y}; - IsometricMapUnproject(map, camera, pos.x, pos.y, &pos); + Vector2 pos = {sprite->x - sprite->texture->width, sprite->y - sprite->texture->height/2}; + IsometricMapUnproject(map, camera, pos.x, pos.y, sprite->z, &pos); // Also erst ab hier sortieren, mit den Werten aus dem pos Vector + // IsometricMap muss auch mit reingerechnet werden -> mögliche Container Lösung steht in der README + pos.x -= camera->target.x; pos.y -= camera->target.y; if(sprite->selected){ - DrawTexture(*sprite->texture, pos.x - sprite->texture->width/4, pos.y - sprite->texture->height/4, BLACK); + DrawTexture(*sprite->texture, pos.x, pos.y, (Color){255, 255, 255, 200}); //DrawTexture(*sprite->texture, sprite->x, sprite->y, BLACK); } else{ - DrawTexture(*sprite->texture, pos.x - sprite->texture->width/4, pos.y - sprite->texture->height/4, WHITE); + DrawTexture(*sprite->texture, pos.x, pos.y, WHITE); } - printf("%f %f \n", sprite->x, sprite->y); + //printf("%f %f \n", sprite->x, sprite->y); } void DrawSpriteToScreen(Sprite *sprite){ - if(sprite->selected){ - DrawTexture(*sprite->texture, sprite->x, sprite->y, WHITE); + DrawTexture(*sprite->texture, sprite->x, sprite->y, (Color){255, 255, 255, 200}); //DrawTexture(*sprite->texture, sprite->x, sprite->y, BLACK); } else{ diff --git a/sprite.h b/sprite.h index 1fb63de..f63f088 100644 --- a/sprite.h +++ b/sprite.h @@ -10,15 +10,17 @@ typedef struct Sprite { Texture2D *texture; float x; float y; + float z; float destX; float destY; int hasDestination; int selected; } Sprite; +// @param deprecated void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y); -void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera); +void DrawSpriteToWorld(Sprite *sprite, IsometricMap **map, Camera2D *camera); void DrawSpriteToScreen(Sprite *sprite); void SpriteUpdateAnimation(Sprite *sprite); diff --git a/sprite.o b/sprite.o new file mode 100644 index 0000000..8914cb1 Binary files /dev/null and b/sprite.o differ diff --git a/textureatlas.o b/textureatlas.o new file mode 100644 index 0000000..b318cd3 Binary files /dev/null and b/textureatlas.o differ diff --git a/tile.o b/tile.o new file mode 100644 index 0000000..ec204ad Binary files /dev/null and b/tile.o differ