diff --git a/Input/inputHandler.c b/Input/inputHandler.c index 7bf8d95..579ceb3 100644 --- a/Input/inputHandler.c +++ b/Input/inputHandler.c @@ -129,15 +129,15 @@ void mouseInput(InputHandler *inputHandler, List *sprites, Texture2D *texture, C void keyboardInput(InputHandler *inputHandler, Camera2D *camera){ if(IsKeyDown(KEY_W)){ - (*camera).target.y -= 100.0f * GetFrameTime(); + (*camera).target.y -= 1000.0f * GetFrameTime(); } if(IsKeyDown(KEY_S)){ - (*camera).target.y += 100.0f * GetFrameTime(); + (*camera).target.y += 1000.0f * GetFrameTime(); } if(IsKeyDown(KEY_D)){ - (*camera).target.x += 100.0f * GetFrameTime(); + (*camera).target.x += 1000.0f * GetFrameTime(); } if(IsKeyDown(KEY_A)){ - (*camera).target.x -= 100.0f * GetFrameTime(); + (*camera).target.x -= 1000.0f * GetFrameTime(); } } \ No newline at end of file diff --git a/IsometricMap/isometricMap.c b/IsometricMap/isometricMap.c index 957ab94..1b2069f 100644 --- a/IsometricMap/isometricMap.c +++ b/IsometricMap/isometricMap.c @@ -5,20 +5,20 @@ #include "raymath.h" #include "raylib.h" -IsometricMap * IsometricMapInit(int x, int y){ +IsometricMap * IsometricMapInit(int x, int y, int layer){ IsometricMap* map = (IsometricMap *) malloc(sizeof(IsometricMap)); map->tileTextures[0] = LoadTexture("assets/grass.png"); map->tileTextures[1] = LoadTexture("assets/tower.png"); map->originX = 0; - map->originY = 0; + map->originY = -layer * map->tileTextures[0].width / 4; map->width = x * map->tileTextures[0].width; map->height = y * map->tileTextures[0].height; - Tile* tiles[x]; + Tile*** tiles = (Tile***)malloc(x*sizeof(Tile*)); int n = 0; for(n=0; nsizeX = x; @@ -29,14 +29,11 @@ IsometricMap * IsometricMapInit(int x, int y){ for(i=0; i < x; i++){ for(j=0; j < y; j++){ - if(i != j){ - Tile tmp = {0, i, j}; - tiles[i][j] = tmp; - } - else{ - Tile tmp = {1, i, j}; - tiles[i][j] = tmp; - } + Tile *tmp = (Tile *) malloc(sizeof(Tile)); + tmp->textureId = 0; + tmp->x = i; + tmp->y = j; + tiles[i][j] = tmp; } } map->tiles = tiles; @@ -59,7 +56,7 @@ Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){ } Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *map, int x, int y){ - return &(map->tiles[x][y]); + return map->tiles[x][y]; } void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, int x, int y, Vector2 *tmp){ @@ -90,6 +87,21 @@ void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, int x, in } +void IsometricMapAddTile(IsometricMap *isometricMap, int x, int y, int textureId){ + + //if(x < isometricMap->sizeX && y < isometricMap->sizeY){ + + Tile *tile = (Tile *) malloc(sizeof(Tile)); + tile->textureId = textureId; + tile->x = x; + tile->y = y; + + //Tile tile = {textureId, x, y}; + isometricMap->tiles[x][y] = tile; + + //} + +} diff --git a/IsometricMap/isometricMap.h b/IsometricMap/isometricMap.h index 50d0661..7d31680 100644 --- a/IsometricMap/isometricMap.h +++ b/IsometricMap/isometricMap.h @@ -5,7 +5,7 @@ typedef struct IsometricMap{ Texture2D tileTextures[10]; - Tile **tiles; + Tile ***tiles; int sizeX; int sizeY; int originX; @@ -15,17 +15,17 @@ typedef struct IsometricMap{ } IsometricMap; // TODO: -void IsometricMapAddTile(IsometricMap *isometricMap, int x, int y, int textureId); Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap *isometricMap, float x, float y); // World Coordinates -> Screen Coordinates Vector2 IsometricMapUnproject(IsometricMap *isometricMap, Camera2D *camera, int x, int y); // Working -IsometricMap * IsometricMapInit(int x, int y); +IsometricMap * IsometricMapInit(int x, int y, int layer); Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize); Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *isometricMap, int x, int y); // Screen Coordinates -> World Coordinates void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, int x, int y, Vector2 *tmp); +void IsometricMapAddTile(IsometricMap *isometricMap, int x, int y, int textureId); #endif \ No newline at end of file diff --git a/IsometricMap/isometricRenderer.c b/IsometricMap/isometricRenderer.c index 7a88c64..c961894 100644 --- a/IsometricMap/isometricRenderer.c +++ b/IsometricMap/isometricRenderer.c @@ -47,11 +47,13 @@ void IsometricRendererRenderIsometricMap(IsometricMap *map, InputHandler *input) float y = map->originY + offset->y; // TODO -> results in Segmentation fault - //int textureId = map->tiles[i][j].textureId; - int textureId = 0; - if(i == input->selectedTile.x && j == input->selectedTile.y){ - textureId = 1; - } + int textureId = map->tiles[i][j]->textureId; + + //int textureId = 0; + //if(i == input->selectedTile.x && j == input->selectedTile.y){ + // textureId = 1; + //} + DrawTexture(map->tileTextures[textureId], x, y, WHITE); } } diff --git a/README.md b/README.md index 479fa7c..25277de 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,5 @@ Fantasy Welt oder Realistisch? ## TODO -+ Bug in isometricRenderer.c -> Segmentation Fault + Sprites in LinkedList speichern + LinkedList erweitern diff --git a/inputHandler.o b/inputHandler.o new file mode 100644 index 0000000..2c06c30 Binary files /dev/null and b/inputHandler.o differ diff --git a/isometricMap.o b/isometricMap.o new file mode 100644 index 0000000..b31a2be Binary files /dev/null and b/isometricMap.o differ diff --git a/isometricRenderer.o b/isometricRenderer.o new file mode 100644 index 0000000..ca97651 Binary files /dev/null and b/isometricRenderer.o differ diff --git a/list.o b/list.o new file mode 100644 index 0000000..eb4318e Binary files /dev/null and b/list.o differ diff --git a/main.c b/main.c index 28c66bb..d7f102b 100644 --- a/main.c +++ b/main.c @@ -28,7 +28,16 @@ int main(){ camera.rotation = 0.0f; camera.zoom = 1.0f; - IsometricMap *map = IsometricMapInit(20, 20); + // TODO -> Isometric Map Array for multiple Layers + // -> Make only most upper layer selectable + // take selected Tile, if that tile has one above select a tile in the upper layer + IsometricMap *map = IsometricMapInit(50, 80, 0); + IsometricMap *Layer1 = IsometricMapInit(20, 20, 1); + IsometricMap *Layer2 = IsometricMapInit(15, 15, 2); + IsometricMap *Layer3 = IsometricMapInit(10, 10, 3); + IsometricMap *Layer4 = IsometricMapInit(4, 4, 4); + + IsometricMapAddTile(Layer4, 2, 2, 1); SetTargetFPS(60); while(!WindowShouldClose()){ @@ -40,6 +49,10 @@ int main(){ BeginMode2D(camera); IsometricRendererRenderIsometricMap(map, &inputHandler); + IsometricRendererRenderIsometricMap(Layer1, &inputHandler); + IsometricRendererRenderIsometricMap(Layer2, &inputHandler); + IsometricRendererRenderIsometricMap(Layer3, &inputHandler); + IsometricRendererRenderIsometricMap(Layer4, &inputHandler); ListDrawAllSprites(sprites); diff --git a/main.o b/main.o new file mode 100644 index 0000000..90818e8 Binary files /dev/null and b/main.o differ diff --git a/spiel b/spiel new file mode 100755 index 0000000..653fa6a Binary files /dev/null and b/spiel differ diff --git a/sprite.o b/sprite.o new file mode 100644 index 0000000..31f9dba 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