Bueno, aun habria mucha tela que cortar a este respecto de temas Isometricos pero os muestro lo que hice asi por probar a ver como dibujar un terreno con un sprite isometrico
el sprite es este:
y el codigo es este:
(tened en cuenta que TABLERO es un TImage pero para que dibuje ha de contener primero algun Bitmap (si el TImage no tiene nada fallara al dibujar))
y luego hice 2 funciones una que dibuja el terreno de forma romboide (que personalmente no me gusta mucho) y otro mas ajustado a toda la pantalla de forma rectangular
Código:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "acPNG"
#pragma resource "*.dfm"
TForm1 *Form1;
void DibujarMapaIsometricoConSprite(TImage *mapImage, TImage *spriteImage, int filas, int columnas);
void DibujarMapaIsometricoRectangular(TImage *mapImage, TImage *spriteImage, int filas, int columnas);
int spriteWidth = 128;
int spriteHeight = 128;
int filas = 10; // Número de filas del mapa
int columnas = 10; // Número de columnas del mapa
inline TPoint PosPt(int x, int y)
{
/* --> */ const int sx = 60, sy = 34; //separación
return Point((y&1)*sx + x*sx*2, y*sy);
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
DibujarMapaIsometricoRectangular(Form1->TABLERO, Form1->SpriteImage, 10, 10);
}
//---------------------------------------------------------------------------
void DibujarMapaIsometricoConSprite(TImage *mapImage, TImage *spriteImage, int filas, int columnas) {
// Limpiar el lienzo antes de dibujar
mapImage->Picture->Bitmap->Canvas->FillRect(mapImage->ClientRect);
for (int y = 0; y < filas; y++) {
for (int x = 0; x < columnas; x++) {
// Convertir coordenadas de la cuadrícula a coordenadas isométricas
int x_iso = (x - y) * (spriteWidth / 2) + (mapImage->Width / 2);
int y_iso = (x + y) * (spriteHeight / 2);
// Dibujar el sprite en las coordenadas calculadas
mapImage->Canvas->Draw(x_iso, y_iso, spriteImage->Picture->Bitmap);
}
}
}
void DibujarMapaIsometricoRectangular(TImage *mapImage, TImage *spriteImage, int filas, int columnas) {
// Limpiar el lienzo antes de dibujar
mapImage->Picture->Bitmap->Canvas->FillRect(mapImage->ClientRect);
// Dimensiones del sprite
int spriteWidth = spriteImage->Width;
int spriteHeight = spriteImage->Height;
for (int y = 0; y < filas; ++y)
{
for (int x = 0; x < columnas; ++x)
{
TPoint pos = PosPt(x, y);
// Dibujar el sprite en las coordenadas calculadas
mapImage->Canvas->Draw(pos.x, pos.y, spriteImage->Picture->Bitmap);
}
}
}
y el resultado es este:
