AVALANCHE: Add some graphic functions for Nim.

This commit is contained in:
uruk
2013-12-17 08:35:42 +01:00
parent 5a1fe83911
commit 16194e227f
2 changed files with 58 additions and 21 deletions
+51 -21
View File
@@ -59,6 +59,7 @@ GraphicManager::~GraphicManager() {
_screen.free();
_scrolls.free();
_backup.free();
_nimStone.free();
for (int i = 0; i < 10; i++)
_digits[i].free();
@@ -451,6 +452,28 @@ void GraphicManager::drawDebugLines() {
}
}
void GraphicManager::blackOutScreen() {
_surface.fillRect(Common::Rect(0, 0, _surface.w, _surface.h), Color::kColorBlack);
}
void GraphicManager::loadNimStone() {
Common::File file;
Common::String filename = "nim.avd";
if (!file.open(filename))
error("AVALANCHE: Scrolls: File not found: %s", filename.c_str());
file.seek(41);
_nimStone = loadPictureSign(file, 7, 23);
file.close();
}
void GraphicManager::drawNimStone(int x, int y) {
drawPicture(_surface, _nimStone, x, y);
}
/**
* This function mimics Pascal's getimage().
*/
@@ -503,6 +526,31 @@ Graphics::Surface GraphicManager::loadPictureRaw(Common::File &file, uint16 widt
return picture;
}
Graphics::Surface GraphicManager::loadPictureSign(Common::File &file, int xl, int yl) {
// I know it looks very similar to the other loadPicture methods, but in truth it's the combination of the two.
uint16 width = xl * 8;
uint16 height = yl;
Graphics::Surface picture; // We make a Surface object for the picture itself.
picture.create(width, height, Graphics::PixelFormat::createFormatCLUT8());
// Produce the picture. We read it in row-by-row, and every row has 4 planes.
for (int yy = 0; yy < height; yy++) {
for (int8 plane = 0; plane < 4; plane++) { // The planes are in the "right" order.
for (uint16 xx = 0; xx < width; xx += 8) {
byte pixel = file.readByte();
for (int bit = 0; bit < 8; bit++) {
byte pixelBit = (pixel >> bit) & 1;
if (pixelBit != 0)
*(byte *)picture.getBasePtr(xx + 7 - bit, yy) += (pixelBit << plane);
}
}
}
}
return picture;
}
void GraphicManager::clearAlso() {
_magics.fillRect(Common::Rect(0, 0, 640, 200), 0);
_magics.frameRect(Common::Rect(0, 45, 640, 161), 15);
@@ -603,28 +651,10 @@ void GraphicManager::drawSign(Common::String fn, int16 xl, int16 yl, int16 y) {
if (!file.open(filename))
error("AVALANCHE: Scrolls: File not found: %s", filename.c_str());
// I know it looks very similar to the loadPicture methods, but in truth it's the combination of the two.
uint16 width = xl * 8;
uint16 height = yl;
Graphics::Surface sign; // We make a Surface object for the picture itself.
sign.create(width, height, Graphics::PixelFormat::createFormatCLUT8());
// Produce the picture. We read it in row-by-row, and every row has 4 planes.
for (int yy = 0; yy < height; yy++) {
for (int8 plane = 0; plane < 4; plane++) { // The planes are in the "right" order.
for (uint16 xx = 0; xx < width; xx += 8) {
byte pixel = file.readByte();
for (int bit = 0; bit < 8; bit++) {
byte pixelBit = (pixel >> bit) & 1;
if (pixelBit != 0)
*(byte *)sign.getBasePtr(xx + 7 - bit, yy) += (pixelBit << plane);
}
}
}
}
drawPicture(_scrolls, sign, kScreenWidth / 2 - width / 2, y);
sign = loadPictureSign(file, xl, yl);
uint16 width = xl * 8;
drawPicture(_scrolls, sign, kScreenWidth / 2 - width / 2, y); // x coord: center the picture.
file.close();
}
+7
View File
@@ -77,6 +77,11 @@ public:
void drawChar(byte ander, int x, int y, Color color);
void drawDebugLines();
// For the mini-game "Nim".
void blackOutScreen();
void loadNimStone();
void drawNimStone(int x, int y);
void clearAlso();
void clearTextBar();
void setAlsoLine(int x1, int y1, int x2, int y2, Color color);
@@ -125,11 +130,13 @@ private:
Graphics::Surface _screen; // Only used in refreshScreen() to make it more optimized. (No recreation of it at every call of the function.)
Graphics::Surface _scrolls;
Graphics::Surface _surface;
Graphics::Surface _nimStone; // For the mini-game "Nim".
byte _egaPalette[64][3];
AvalancheEngine *_vm;
Graphics::Surface loadPictureGraphic(Common::File &file); // Reads Graphic-planar EGA data.
Graphics::Surface loadPictureSign(Common::File &file, int xl, int yl); // Reads a tricky type of picture used for the "game over"/"about" scrolls and in the mini-game Nim.
void drawText(Graphics::Surface &surface, const Common::String text, FontType font, byte fontHeight, int16 x, int16 y, Color color);
// Taken from Free Pascal's Procedure InternalEllipseDefault. Used to replace Pascal's procedure arc.
// Returns the end point of the arc. (Needed in Clock.)