Как сделать так чтобы карта корректно рисовалась начиная с левого верхнего угла?
Coordinates::Coordinates()
{
half_viewport_width=1;
half_viewport_height=1;
}
Coordinates::~Coordinates()
{
}
void Coordinates::initialize(const int viewport_width,const int viewport_height)
{
if (viewport_width>1)
{
half_viewport_width=viewport_width/2;
}
if (viewport_height>1)
{
half_viewport_height=viewport_height/2;
}
}
int Coordinates::get_lowest_cartesian_x() const
{
return -1*half_viewport_width;
}
int Coordinates::get_highest_cartesian_x() const
{
return half_viewport_width;
}
int Coordinates::get_lowest_cartesian_y() const
{
return -1*half_viewport_height;
}
int Coordinates::get_highest_cartesian_y() const
{
return half_viewport_height;
}
bool Coordinates::check_cartesian_x(const int x) const
{
return (x>=this->get_lowest_cartesian_x()) && (x<=this->get_highest_cartesian_x());
}
bool Coordinates::check_cartesian_y(const int y) const
{
return (y>=this->get_lowest_cartesian_y()) && (y<=this->get_highest_cartesian_y());
}
int Coordinates::get_cartesian_x(const int x) const
{
return (x<0) ? 0:(x-half_viewport_width);
}
int Coordinates::get_cartesian_y(const int y) const
{
return (y<0) ? 0:(half_viewport_height-y);
}
int Coordinates::get_screen_x(const int x) const
{
return x+half_viewport_width;
}
int Coordinates::get_screen_y(const int y) const
{
return half_viewport_height-y;
}
Isometric::Isometric()
{
half_tile_width=1;
half_tile_height=1;
}
Isometric::~Isometric()
{
}
void Isometric::initialize(const int tile_width,const int tile_height)
{
if (tile_width>1)
{
half_tile_width=tile_width/2;
}
if (tile_height>1)
{
half_tile_height=tile_height/2;
}
}
int Isometric::get_target_x(const int row,const int column) const
{
return (row-column)*half_tile_width;
}
int Isometric::get_target_y(const int row,const int column) const
{
return (row+column)*half_tile_height;
}
int main()
{
int x,y,row,column;
EUGENEGDK::Graphics::Screen screen;
EUGENEGDK::Graphics::Background sky;
EUGENEGDK::Graphics::Sprite ground;
EUGENEGDK::Graphics::Text text;
EUGENEGDK::Transformation::Coordinates cartesian;
EUGENEGDK::Transformation::Isometric isometric;
EUGENEGDK::Input::Keyboard keyboard;
keyboard.initialize();
screen.initialize();
sky.load("sky.tga");
sky.prepare(screen);
ground.load("ground.tga");
text.load_font("font.tga");
text.set_position(text.get_font_width(),text.get_font_height());
cartesian.initialize(screen.get_width(),screen.get_height());
isometric.initialize(ground.get_width(),ground.get_height());
while (screen.sync())
{
if (keyboard.check_hold(1)==true)
{
break;
}
sky.draw();
for (row=0;row<5;++row)
{
for (column=0;column<5;++column)
{
x=isometric.get_target_x(row,column);
y=isometric.get_target_y(row,column);
ground.draw(cartesian.get_screen_x(x),cartesian.get_screen_y(y));
}
}
text.print("Press Esc to exit");
}
return 0;
}
не сильно разбираюсь по тебе, но friendly reminder, код больше 10 строк намного лучше кидать в что-то типа github gists/wgetpaste/etc
Обсуждают сегодня