Wasser ist animiert, ist aktuell aber noch gehardcoded in der IsometricMapDraw

main
Jan 3 years ago
parent 394190999a
commit 3ac62681aa

@ -7,26 +7,20 @@
#include "../Sprite/sprite.h" #include "../Sprite/sprite.h"
#include "../game.h" #include "../game.h"
IsometricMap * IsometricMapInit(){ IsometricMap * IsometricMapInit(Game *game){
IsometricMap* map = malloc(sizeof(IsometricMap)); IsometricMap* map = malloc(sizeof(IsometricMap));
int counter = 0; int counter = 0;
map->tileTextures[counter++] = LoadTexture("assets/tiles/grass.png"); for(counter = 0; counter < TE_TILES_LENGTH; counter++){
map->tileTextures[counter++] = LoadTexture("assets/tiles/desert.png"); map->tileTextures[counter] = &(game->textures->textures[TE_TILES][counter]);
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");
map->width = 500; map->width = 500;
map->height = 500; map->height = 500;
map->textureWidth = map->tileTextures[0].width; map->textureWidth = map->tileTextures[0]->width;
map->textureHeight = map->tileTextures[0].height; map->textureHeight = map->tileTextures[0]->height;
map->worldPixelWidth = map->width * map->textureWidth; map->worldPixelWidth = map->width * map->textureWidth;
map->worldPixelWidth = map->height * map->textureHeight; map->worldPixelWidth = map->height * map->textureHeight;
map->timer = 0;
// mallocating the twodimensional Tiles Array // mallocating the twodimensional Tiles Array
Tile*** tiles = malloc(map->width*sizeof(Tile*)); 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){ 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 windowWidth = GetScreenWidth();
int windowHeight = GetScreenHeight(); int windowHeight = GetScreenHeight();
Vector2 topleft = {0, 0}; Vector2 topleft = {0, 0};
@ -164,11 +174,10 @@ void IsometricMapDraw(Game *game){
continue; continue;
} }
else{ else{
;
DrawTexture( 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]->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); WHITE);
continue; continue;
} }

@ -6,7 +6,7 @@
typedef struct IsometricMap{ typedef struct IsometricMap{
// Array with all the needed textures for this layer // 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 // twodimensional array of all the tiles in this layer
Tile ***tiles; Tile ***tiles;
@ -28,10 +28,12 @@ typedef struct IsometricMap{
// pixel height of the entire map // pixel height of the entire map
int worldPixelHeight; int worldPixelHeight;
float timer;
} IsometricMap; } IsometricMap;
// returns pointer to IsometricMap Instance // returns pointer to IsometricMap Instance
IsometricMap * IsometricMapInit(); IsometricMap * IsometricMapInit(Game *game);
// For Rendering: calculates coordinate offset for a single tile at arrayPosition x y // 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?) // Only works for tiles with texture width == height (and for 22.5 degree?)

@ -41,6 +41,7 @@ Allgemein:
+ Maps in eigenen Dateien speichern + Maps in eigenen Dateien speichern
+ Parser für Map-Dateien + Parser für Map-Dateien
+ MapEditor + MapEditor
+ Batching in Raylib für die TileMap
## Anleitungen ## Anleitungen

@ -50,6 +50,10 @@ void TextureAtlasLoadTextures(Texture2D **textures){
textures[TE_BUTTON] = malloc(TE_BUTTON_LENGTH * sizeof(Texture2D)); textures[TE_BUTTON] = malloc(TE_BUTTON_LENGTH * sizeof(Texture2D));
LoadButtonTextures(textures[TE_BUTTON]); LoadButtonTextures(textures[TE_BUTTON]);
break; break;
case TE_TILES:
textures[TE_TILES] = malloc(TE_TILES_LENGTH * sizeof(Texture2D));
LoadTileTextures(textures[TE_TILES]);
break;
default: default:
printf("WARNING: TEXTUREATLAS TRIED LOADING NON DEFINED TEXTUREID!!\n"); 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[1] = LoadTexture("assets/button_hovered.png");
atlasrow[2] = LoadTexture("assets/button_pressed.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){ void LoadCursorTextures(Texture2D *cursorTextures){

@ -23,6 +23,7 @@ void LoadEntityTextures(Texture2D *atlasrow, char *directoryPrefix);
void LoadMapObjectTextures(Texture2D *atlasrow, char *directoryPrefix); void LoadMapObjectTextures(Texture2D *atlasrow, char *directoryPrefix);
void LoadSelectableBackgroundTextures(Texture2D *atlasrow); void LoadSelectableBackgroundTextures(Texture2D *atlasrow);
void LoadButtonTextures(Texture2D *atlasrow); void LoadButtonTextures(Texture2D *atlasrow);
void LoadTileTextures(Texture2D *atlasrow);
void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures); void LoadWorkerAnimations(Animation **workerAnimations, Texture2D *workerTextures);
void TextureAtlasLoadAnimations(Animation ****animations, Texture2D **textures); void TextureAtlasLoadAnimations(Animation ****animations, Texture2D **textures);

@ -97,7 +97,7 @@ static UiContainer * UiContainerInitGameUiContainer(Game *game){
position = (Vector2){GetScreenWidth()-50, 2}; position = (Vector2){GetScreenWidth()-50, 2};
for(i; i < ISOMETRICMAP_TILE_TEXTURE_AMOUNT; i++){ for(i; i < ISOMETRICMAP_TILE_TEXTURE_AMOUNT; i++){
UiContainerAddSelectable(uiContainer, 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, showDescription, 0/*String len*/, fontSize, SELECTABLE_ID_DRAWING_TILE+i,
1/*Group*/, 1, 0.5f) 1/*Group*/, 1, 0.5f)
); );

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

@ -26,12 +26,15 @@
#define TE_LUMBERJACK 5 #define TE_LUMBERJACK 5
#define TE_SELECTABLE_BACKGROUND 6 #define TE_SELECTABLE_BACKGROUND 6
#define TE_BUTTON 7 #define TE_BUTTON 7
#define TE_TILES 8
#define TE_AMOUNT 9
#define TE_AMOUNT 8
#define TE_ENTITY_LENGTH 104 #define TE_ENTITY_LENGTH 104
#define TE_MAPOBJECT_LENGTH 1 #define TE_MAPOBJECT_LENGTH 1
#define TE_SELECTABLE_BACKGROUND_LENGTH 3 #define TE_SELECTABLE_BACKGROUND_LENGTH 3
#define TE_BUTTON_LENGTH 3 #define TE_BUTTON_LENGTH 3
#define TE_TILES_LENGTH 13
// Definitions for animations // Definitions for animations
#define AN_WORKER 0 #define AN_WORKER 0

@ -46,7 +46,7 @@ Game *GameInit()
game->buildings = BuildingListInit(); game->buildings = BuildingListInit();
game->objects = StaticObjectListInit(); 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 //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; int i,j;
for (i = 0; i < game->map->width; i++) for (i = 0; i < game->map->width; i++)

Loading…
Cancel
Save