55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#include "camera.h"
|
|
#include "render.h"
|
|
#include <stdio.h>
|
|
|
|
WorldRect Camera::validCenters() const
|
|
{
|
|
WorldRect b = this->world->worldBorder;
|
|
|
|
/* Allow up to just next to the world border */
|
|
return WorldRect(b.xmin + 1, b.xmax - 1, b.ymin + 1, b.ymax - 1);
|
|
}
|
|
|
|
void Camera::moveBy(WorldCoord direction)
|
|
{
|
|
this->center = this->validCenters().clampPoint(this->center + direction);
|
|
}
|
|
|
|
namespace Nooncraft {
|
|
|
|
void renderCamera(int x, int y, Camera *camera)
|
|
{
|
|
if(!camera)
|
|
return;
|
|
|
|
WorldRect r = camera->visible;
|
|
for(int dy = r.ymin; dy <= r.ymax; dy++)
|
|
for(int dx = r.xmin; dx <= r.xmax; dx++) {
|
|
int wx = camera->center.x + dx;
|
|
int wy = camera->center.y + dy;
|
|
|
|
if(!camera->world->worldBorder.contains(WorldCoord(wx, wy))) {
|
|
continue;
|
|
}
|
|
else if(camera->world->isPointOnWorldBorder(wx, wy)) {
|
|
GlyphCluster c('{', '}', '{', '}');
|
|
renderCluster(x+2*dx, y+2*dy, c);
|
|
}
|
|
else {
|
|
Block b = camera->world->cellAt(wx, wy);
|
|
BlockInfo *info = Nooncraft::getBlockInfo(b);
|
|
if(info) {
|
|
renderCluster(x+2*dx, y+2*dy, info->cluster);
|
|
}
|
|
else {
|
|
char str[5];
|
|
sprintf(str, "%04X", 0x55);
|
|
GlyphCluster c(str[0], str[1], str[2], str[3]);
|
|
renderCluster(x+2*dx, y+2*dy, c);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} /* namespace Nooncraft */
|