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.

116 lines
3.4 KiB

#include "isometricRenderer.h"
#include "raylib.h"
#include "isometricMap.h"
#include "../Input/inputHandler.h"
#include <stdio.h>
#include <stdlib.h>
#include "../game.h"
#include "../List/list.h"
// @param deprecated
void IsometricRendererDrawMap(IsometricRenderer *renderer, int height)
{
printf("WARNING: Using deprecated Function IsometricRendererDrawMap!\n");
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--;
}
}
}
// parameter could be changed to only IsometricMap[]
void IsometricRendererRenderIsometricMap(Game *game){
int windowWidth = GetScreenWidth();
int windowHeight = GetScreenHeight();
// HARDCODED
Vector2 topleft = {0, 0};
IsometricMapProject(game->layers[0], game->camera, topleft.x, topleft.y, &topleft);
Vector2 topright = {windowWidth, 0};
IsometricMapProject(game->layers[0], game->camera, topright.x, topright.y, &topright);
Vector2 botleft = {0, windowHeight};
IsometricMapProject(game->layers[0], game->camera, botleft.x, botleft.y, &botleft);
Vector2 botright = {windowWidth, windowHeight};
IsometricMapProject(game->layers[0], game->camera, botright.x, botright.y, &botright);
// drawing some extra corner tiles
// if extraTiles == 0 you can see flickering in the corners
int extraTiles = 1;
int n = 0;
int itmp = (int)(topleft.x / game->layers[0]->textureWidth) - extraTiles;
int jtmp = (int)(topright.y / game->layers[0]->textureHeight) - extraTiles;
int maxI = (int)(botright.x / game->layers[0]->textureWidth) + extraTiles;
int maxJ = (int)(botleft.y / game->layers[0]->textureHeight) + extraTiles;
if (itmp < 0)
{
itmp = 0;
}
if (jtmp < 0)
{
jtmp = 0;
}
if (maxI > game->layers[0]->width)
{
maxI = game->layers[0]->width;
}
if (maxJ > game->layers[0]->height)
{
maxJ = game->layers[0]->height;
}
int i = 0; // x
int j = 0; // y
for (n = 0; n < 10; n++){
Node *current = game->sprites->head;
for (j = jtmp; j < maxJ; j++){
for (i = itmp; i < maxI; i++){
if (game->layers[n]->tiles[i][j]->textureId == -1){
}
else{
DrawTexture(
game->layers[n]->tileTextures[game->layers[n]->tiles[i][j]->textureId],
game->layers[n]->tiles[i][j]->offsetX,
game->layers[n]->tiles[i][j]->offsetY,
WHITE);
}
// Draw sprites that are over the tile
while(current != 0 && current->data.y <= (j + 1) * game->layers[n]->textureWidth){
if(current->data.z == n){
DrawSpriteToWorld(&current->data, game->layers, game->camera);
}
current = current->next;
}
}
}
}
}