|
|
|
@ -5,6 +5,7 @@
|
|
|
|
#include "raymath.h"
|
|
|
|
#include "raymath.h"
|
|
|
|
#include "raylib.h"
|
|
|
|
#include "raylib.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// returns pointer to IsometricMap Instance
|
|
|
|
IsometricMap * IsometricMapInit(int layer){
|
|
|
|
IsometricMap * IsometricMapInit(int layer){
|
|
|
|
IsometricMap* map = (IsometricMap *) malloc(sizeof(IsometricMap));
|
|
|
|
IsometricMap* map = (IsometricMap *) malloc(sizeof(IsometricMap));
|
|
|
|
|
|
|
|
|
|
|
|
@ -50,6 +51,7 @@ IsometricMap * IsometricMapInit(int layer){
|
|
|
|
return map;
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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?)
|
|
|
|
Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){
|
|
|
|
Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){
|
|
|
|
Vector2* offset = (Vector2 *)malloc(sizeof(Vector2));
|
|
|
|
Vector2* offset = (Vector2 *)malloc(sizeof(Vector2));
|
|
|
|
@ -58,10 +60,12 @@ Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){
|
|
|
|
return offset;
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// returns Tile at x y on layer isometricMap
|
|
|
|
Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *map, int x, int y){
|
|
|
|
Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *map, int x, int y){
|
|
|
|
return map->tiles[x][y];
|
|
|
|
return map->tiles[x][y];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Unproject: World Coordinates -> Screen Coordinates writes result in tmp Vector
|
|
|
|
void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float y, Vector2 *tmp){
|
|
|
|
void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float y, Vector2 *tmp){
|
|
|
|
|
|
|
|
|
|
|
|
float tileWidthHalf = isometricMap->textureWidth / 2;
|
|
|
|
float tileWidthHalf = isometricMap->textureWidth / 2;
|
|
|
|
@ -92,13 +96,14 @@ void IsometricMapUnproject(IsometricMap **isometricMap, Camera2D *camera, int x,
|
|
|
|
screenY += camera->target.y;
|
|
|
|
screenY += camera->target.y;
|
|
|
|
|
|
|
|
|
|
|
|
// z is currently implemented as z=1 equals 1 layer, z=2 would be two layers height (could be smoothed)
|
|
|
|
// z is currently implemented as z=1 equals 1 layer, z=2 would be two layers height (could be smoothed)
|
|
|
|
// TODO drift
|
|
|
|
// hardcoded tile height
|
|
|
|
screenY -= z *(isometricMap[0]->textureHeight/2);
|
|
|
|
screenY -= z * 10;
|
|
|
|
|
|
|
|
|
|
|
|
tmp->x = screenX;
|
|
|
|
tmp->x = screenX;
|
|
|
|
tmp->y = screenY;
|
|
|
|
tmp->y = screenY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// returns Tile * -> tile at coordinates x y z=layer
|
|
|
|
Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap **isometricMap, float x, float y, float z){
|
|
|
|
Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap **isometricMap, float x, float y, float z){
|
|
|
|
|
|
|
|
|
|
|
|
int layer = (int) z;
|
|
|
|
int layer = (int) z;
|
|
|
|
@ -115,6 +120,7 @@ Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap **isometricMap, floa
|
|
|
|
return ptr;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Gives the most upper Tile above *tile
|
|
|
|
Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile){
|
|
|
|
Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile){
|
|
|
|
Tile *ptr = (Tile *) malloc(sizeof(Tile *));
|
|
|
|
Tile *ptr = (Tile *) malloc(sizeof(Tile *));
|
|
|
|
// hardcoded layer amount
|
|
|
|
// hardcoded layer amount
|
|
|
|
@ -134,6 +140,7 @@ Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile){
|
|
|
|
return ptr;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// changes to Texture ID of tile at x y on maplayer layer
|
|
|
|
void IsometricMapChangeTextureIdOfTile(IsometricMap **map, int x, int y, int layer, int id){
|
|
|
|
void IsometricMapChangeTextureIdOfTile(IsometricMap **map, int x, int y, int layer, int id){
|
|
|
|
if( x < map[layer]->width && y < map[layer]->height &&
|
|
|
|
if( x < map[layer]->width && y < map[layer]->height &&
|
|
|
|
x >= 0 && y >= 0 ){
|
|
|
|
x >= 0 && y >= 0 ){
|
|
|
|
|