You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.7 KiB

#include "isometricRenderer.h"
#include "raylib.h"
#include "isometricMap.h"
#include "../Input/inputHandler.h"
#include <stdio.h>
//TODO: Isometric Tilemap Struct, which can be scanned for clicked Tile
// General coordinate translation function
void IsometricRendererDrawMap(IsometricRenderer *renderer, int height){
float originX = 0.0f;
float originY = 0.0f;
int i = 0;
int j = 0;
int amount = 1;
for(i=0; i<=height; i++){
for(j=0; j<amount; j++){
float x = originX - amount/2 * renderer->texture->width + j * renderer->texture->width;
if(amount%2 == 1){
x -= renderer->texture->width/2;
}
float y = i * renderer->texture->height/4;
DrawTexture(*renderer->texture, x, y, WHITE);
}
if(i < height/2){
amount++;
}
else{
amount--;
}
}
}
void IsometricRendererRenderIsometricMap(IsometricMap *map, InputHandler *input){
int i = 0;
int j = 0;
for(i=0; i < map->sizeX; i++){
for(j=0; j < map->sizeY; j++){
Vector2 *offset = IsometricMapCalcOffsetForTileAt(i,j, map->tileTextures[0].width);
float x = map->originX + offset->x;
float y = map->originY + offset->y;
// TODO -> results in Segmentation fault
int textureId = map->tiles[i][j]->textureId;
//int textureId = 0;
//if(i == input->selectedTile.x && j == input->selectedTile.y){
// textureId = 1;
//}
DrawTexture(map->tileTextures[textureId], x, y, WHITE);
}
}
}