diff --git a/IsometricMap/isometricMap.c b/IsometricMap/isometricMap.c index a53f1a1..029d545 100644 --- a/IsometricMap/isometricMap.c +++ b/IsometricMap/isometricMap.c @@ -7,26 +7,20 @@ #include "../Sprite/sprite.h" #include "../game.h" -IsometricMap * IsometricMapInit(){ +IsometricMap * IsometricMapInit(Game *game){ IsometricMap* map = malloc(sizeof(IsometricMap)); int counter = 0; - map->tileTextures[counter++] = LoadTexture("assets/tiles/grass.png"); - map->tileTextures[counter++] = LoadTexture("assets/tiles/desert.png"); - map->tileTextures[counter++] = LoadTexture("assets/tiles/desert_palm.png"); - map->tileTextures[counter++] = LoadTexture("assets/tiles/tower.png"); - map->tileTextures[counter++] = LoadTexture("assets/tiles/bigtower.png"); - map->tileTextures[counter++] = LoadTexture("assets/tiles/grass_selected.png"); - map->tileTextures[counter++] = LoadTexture("assets/tiles/ice.png"); - map->tileTextures[counter++] = LoadTexture("assets/tiles/water.png"); - map->tileTextures[counter++] = LoadTexture("assets/tiles/empty.png"); - + for(counter = 0; counter < TE_TILES_LENGTH; counter++){ + map->tileTextures[counter] = &(game->textures->textures[TE_TILES][counter]); + } map->width = 500; map->height = 500; - map->textureWidth = map->tileTextures[0].width; - map->textureHeight = map->tileTextures[0].height; + 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->timer = 0; // mallocating the twodimensional Tiles Array Tile*** tiles = malloc(map->width*sizeof(Tile*)); @@ -135,6 +129,22 @@ void IsometricMapChangeTextureIdOfTile(IsometricMap *map, int x, int y, int id){ } void IsometricMapDraw(Game *game){ + + game->map->timer += GetFrameTime(); + if(game->map->timer > 0.2f){ + game->map->tileTextures[7] = &(game->textures->textures[TE_TILES][9]); + } + if(game->map->timer > 0.4f){ + game->map->tileTextures[7] = &(game->textures->textures[TE_TILES][10]); + } + if(game->map->timer > 0.6f){ + game->map->tileTextures[7] = &(game->textures->textures[TE_TILES][11]); + } + if(game->map->timer > 0.8f){ + game->map->tileTextures[7] = &(game->textures->textures[TE_TILES][7]); + game->map->timer = 0; + } + int windowWidth = GetScreenWidth(); int windowHeight = GetScreenHeight(); Vector2 topleft = {0, 0}; @@ -164,11 +174,10 @@ void IsometricMapDraw(Game *game){ continue; } else{ - ; DrawTexture( - game->map->tileTextures[game->map->tiles[i][j]->textureId], + *(game->map->tileTextures[game->map->tiles[i][j]->textureId]), game->map->tiles[i][j]->offsetX, - game->map->tiles[i][j]->offsetY - game->map->tileTextures[game->map->tiles[i][j]->textureId].height + 32, + game->map->tiles[i][j]->offsetY - game->map->tileTextures[game->map->tiles[i][j]->textureId]->height + 32, WHITE); continue; } diff --git a/IsometricMap/isometricMap.h b/IsometricMap/isometricMap.h index df4f296..76d7fc3 100644 --- a/IsometricMap/isometricMap.h +++ b/IsometricMap/isometricMap.h @@ -6,7 +6,7 @@ typedef struct IsometricMap{ // Array with all the needed textures for this layer - Texture2D tileTextures[10]; + Texture2D *tileTextures[TE_TILES_LENGTH]; // twodimensional array of all the tiles in this layer Tile ***tiles; @@ -28,10 +28,12 @@ typedef struct IsometricMap{ // pixel height of the entire map int worldPixelHeight; + + float timer; } IsometricMap; // returns pointer to IsometricMap Instance -IsometricMap * IsometricMapInit(); +IsometricMap * IsometricMapInit(Game *game); // 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?) diff --git a/README.md b/README.md index 04c19d8..d5f7de3 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Allgemein: + Maps in eigenen Dateien speichern + Parser für Map-Dateien + MapEditor ++ Batching in Raylib für die TileMap ## Anleitungen diff --git a/Textures/textureatlas.c b/Textures/textureatlas.c index e5bae35..5a2650a 100644 --- a/Textures/textureatlas.c +++ b/Textures/textureatlas.c @@ -50,6 +50,10 @@ void TextureAtlasLoadTextures(Texture2D **textures){ textures[TE_BUTTON] = malloc(TE_BUTTON_LENGTH * sizeof(Texture2D)); LoadButtonTextures(textures[TE_BUTTON]); break; + case TE_TILES: + textures[TE_TILES] = malloc(TE_TILES_LENGTH * sizeof(Texture2D)); + LoadTileTextures(textures[TE_TILES]); + break; default: printf("WARNING: TEXTUREATLAS TRIED LOADING NON DEFINED TEXTUREID!!\n"); } @@ -167,7 +171,21 @@ void LoadButtonTextures(Texture2D *atlasrow){ atlasrow[1] = LoadTexture("assets/button_hovered.png"); atlasrow[2] = LoadTexture("assets/button_pressed.png"); } - +void LoadTileTextures(Texture2D *atlasrow){ + int counter = 0; + atlasrow[counter++] = LoadTexture("assets/tiles/grass.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/desert.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/desert_palm.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/tower.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/bigtower.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/grass_selected.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/ice.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/water.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/empty.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/water2.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/water3.png"); + atlasrow[counter++] = LoadTexture("assets/tiles/water4.png"); +} void LoadCursorTextures(Texture2D *cursorTextures){ diff --git a/Textures/textureatlas.h b/Textures/textureatlas.h index 44cb916..d4fff66 100644 --- a/Textures/textureatlas.h +++ b/Textures/textureatlas.h @@ -23,6 +23,7 @@ void LoadEntityTextures(Texture2D *atlasrow, char *directoryPrefix); void LoadMapObjectTextures(Texture2D *atlasrow, char *directoryPrefix); void LoadSelectableBackgroundTextures(Texture2D *atlasrow); void LoadButtonTextures(Texture2D *atlasrow); +void LoadTileTextures(Texture2D *atlasrow); void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures); void TextureAtlasLoadAnimations(Animation ****animations, Texture2D **textures); diff --git a/Ui/uiContainer.c b/Ui/uiContainer.c index 6c903cf..25f43f9 100644 --- a/Ui/uiContainer.c +++ b/Ui/uiContainer.c @@ -97,7 +97,7 @@ static UiContainer * UiContainerInitGameUiContainer(Game *game){ position = (Vector2){GetScreenWidth()-50, 2}; for(i; i < ISOMETRICMAP_TILE_TEXTURE_AMOUNT; i++){ UiContainerAddSelectable(uiContainer, - SelectableInit(&(game->map->tileTextures[i]), backgroundTextures, hasBackground , &position, "", + SelectableInit(game->map->tileTextures[i], backgroundTextures, hasBackground , &position, "", showDescription, 0/*String len*/, fontSize, SELECTABLE_ID_DRAWING_TILE+i, 1/*Group*/, 1, 0.5f) ); diff --git a/assets/tiles/water.png b/assets/tiles/water.png index b0ed387..eb23d97 100644 Binary files a/assets/tiles/water.png and b/assets/tiles/water.png differ diff --git a/assets/tiles/water2.png b/assets/tiles/water2.png new file mode 100644 index 0000000..d3ca926 Binary files /dev/null and b/assets/tiles/water2.png differ diff --git a/assets/tiles/water3.png b/assets/tiles/water3.png new file mode 100644 index 0000000..8ec001e Binary files /dev/null and b/assets/tiles/water3.png differ diff --git a/assets/tiles/water4.png b/assets/tiles/water4.png new file mode 100644 index 0000000..481f0a5 Binary files /dev/null and b/assets/tiles/water4.png differ diff --git a/definitions.h b/definitions.h index b8f901c..b94c3c7 100644 --- a/definitions.h +++ b/definitions.h @@ -26,12 +26,15 @@ #define TE_LUMBERJACK 5 #define TE_SELECTABLE_BACKGROUND 6 #define TE_BUTTON 7 +#define TE_TILES 8 + +#define TE_AMOUNT 9 -#define TE_AMOUNT 8 #define TE_ENTITY_LENGTH 104 #define TE_MAPOBJECT_LENGTH 1 #define TE_SELECTABLE_BACKGROUND_LENGTH 3 #define TE_BUTTON_LENGTH 3 +#define TE_TILES_LENGTH 13 // Definitions for animations #define AN_WORKER 0 diff --git a/game.c b/game.c index 4ae4561..6d3767a 100644 --- a/game.c +++ b/game.c @@ -46,7 +46,7 @@ Game *GameInit() game->buildings = BuildingListInit(); game->objects = StaticObjectListInit(); - game->map = IsometricMapInit(); + game->map = IsometricMapInit(game); //das du es weißt man kann wenn du nicht auf hört was machen und dann bist du leise es gibt was das nett sich rufmord int i,j; for (i = 0; i < game->map->width; i++)