#include "isometricMap.h" #include #include #include "tile.h" #include "raymath.h" #include "raylib.h" IsometricMap * IsometricMapInit(int x, int y){ 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->width = x * map->tileTextures[0].width; map->height = y * map->tileTextures[0].height; Tile* tiles[x]; int n = 0; for(n=0; nsizeX = x; map->sizeY = y; int i = 0; int j = 0; 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; } } } map->tiles = tiles; return map; } Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){ Vector2* offset = (Vector2 *)malloc(sizeof(Vector2)); offset->x = x * textureSize/2; offset->y = x * textureSize/4; offset->x -= y * textureSize/2; offset->y += y * textureSize/4; return offset; } Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *map, int x, int y){ return &(map->tiles[x][y]); } void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, int x, int y, Vector2 *tmp){ float tileWidthHalf = isometricMap->tileTextures[0].width / 2; float tileHeightHalf = isometricMap->tileTextures[0].height / 2; x += camera->target.x; y += camera->target.y; float xPos = (float) x; float yPos = (float) y; int isoX = 0.5 * ( xPos / tileWidthHalf + yPos / tileHeightHalf); int isoY = 0.5 * ( -xPos / tileWidthHalf + yPos / tileHeightHalf); //Vector2 tmp = {isoX * tileWidthHalf * 2, isoY * tileHeightHalf * 2}; //Vector2* tmp = (Vector2 *) malloc(sizeof(Vector2)); tmp->x = isoX; tmp->y = isoY; //return tmp; }