|
|
|
|
@ -1,12 +1,20 @@
|
|
|
|
|
#include "isometricMap.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#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; n<x; n++){
|
|
|
|
|
@ -50,6 +58,38 @@ Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){
|
|
|
|
|
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){
|
|
|
|
|
|
|
|
|
|
int mouseAdjustmentX = -8;
|
|
|
|
|
int mouseAdjustmentY = -4;
|
|
|
|
|
|
|
|
|
|
float tileWidthHalf = isometricMap->tileTextures[0].width / 2;
|
|
|
|
|
float tileHeightHalf = isometricMap->tileTextures[0].height / 4;
|
|
|
|
|
|
|
|
|
|
x += camera->target.x + mouseAdjustmentX;
|
|
|
|
|
y += camera->target.y + mouseAdjustmentY;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|