#include <world.h>
#include <ft2build.h>
#include <SDL2/SDL_opengl.h>
++#include <fstream>
#include FT_FREETYPE_H
#define DEBUG
void gotoParent();
};
++typedef unsigned long DWORD;
++typedef unsigned short WORD;
++
++typedef struct{
++ WORD bfType;
++ DWORD bfSize;
++ WORD bfReserved1, bfReserved2;
++ DWORD bfOffBits; //how many bytes before the image data
++} __attribute__ ((packed)) BITMAPFILEHEADER;
++
++typedef struct{
++ DWORD biSize; //size of header in bytes
++ long biWidth;
++ long biHeight;
++ WORD biPlanes;
++ WORD biBitCount; //how many bits are in a pixel
++ DWORD biCompression;
++ DWORD biSizeImage; //size of image in bytes
++ long biXPelsPerMeter;
++ long biYPelsPerMeter;
++ DWORD biClrUsed; //how many colors there are
++ DWORD biClrImportant; //important colors
++} __attribute__ ((packed)) BITMAPINFOHEADER;
++
namespace ui {
menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f);
menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t);
}
/*
- * Initialize the FreeType libraries and select what font to use using functions from the ui
- * namespace, defined in include/ui.h and src/ui.cpp. These functions should abort with errors
- * if they have error.
- *
- */
+ * Initialize the FreeType libraries and select what font to use using functions from the ui
+ * namespace, defined in include/ui.h and src/ui.cpp. These functions should abort with errors
+ * if they have error.
+ */
ui::initFonts();
- ui::setFontFace("ttf/Perfect DOS VGA 437.ttf"); // as in gamedev/ttf/<font>
+ ui::setFontFace("ttf/VCR_OSD_MONO_1.001.ttf"); // as in gamedev/ttf/<font>
/*
- * Initialize the random number generator. At the moment, initRand is a macro pointing to libc's
- * srand, and its partner getRand points to rand. This is because having our own random number
- * generator may be favorable in the future, but at the moment is not implemented.
- *
- */
+ * Initialize the random number generator. At the moment, initRand is a macro pointing to libc's
+ * srand, and its partner getRand points to rand. This is because having our own random number
+ * generator may be favorable in the future, but at the moment is not implemented.
+ */
initRand(millis());
}
/*
- * Load sprites used in the inventory menu. See src/inventory.cpp
- */
+ * Load sprites used in the inventory menu. See src/inventory.cpp
+ */
invUI = Texture::loadTexture("assets/invUI.png" );
+ mouseTex = Texture::loadTexture("assets/mouse.png");
initInventorySprites();
currentTime = millis();
deltaTime = currentTime - prevTime;
- if(currentMenu != NULL)
- goto MENU;
+ if(currentMenu)goto MENU;
/*
- * Run the logic handler if MSEC_PER_TICK milliseconds have passed.
- */
+ * Run the logic handler if MSEC_PER_TICK milliseconds have passed.
+ */
prev = currentWorld;
ui::handleEvents();
currentWorld->draw(player);
--
+ /*
+ * Calculate the player's hand angle.
+ */
-
handAngle = atan((ui::mouse.y - (player->loc.y + player->height/2)) / (ui::mouse.x - player->loc.x + player->width/2))*180/PI;
if(ui::mouse.x < player->loc.x){
if(handAngle <= 0)
player->inv->draw();
/*
++<<<<<<< HEAD
+ * Here we draw a black overlay if it's been requested.
+ */
++
++ /*
+ * Here we draw a black overlay if it's been requested.
+ */
if(fadeIntensity){
if(fadeWhite)
}
/*
- * Draw a white triangle as a replacement for the mouse's cursor.
- */
+ * Draw a white triangle as a replacement for the mouse's cursor.
+ */
- glColor3ub(255,200,255);
-
- glBegin(GL_TRIANGLES);
- glVertex2i(ui::mouse.x ,ui::mouse.y );
- glVertex2i(ui::mouse.x+HLINE*3.5,ui::mouse.y );
- glVertex2i(ui::mouse.x ,ui::mouse.y-HLINE*3.5);
+ glColor3ub(255,255,255);
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, mouseTex);
+ glBegin(GL_QUADS);
+ glTexCoord2f(0,0);glVertex2i(ui::mouse.x ,ui::mouse.y );
+ glTexCoord2f(1,0);glVertex2i(ui::mouse.x+HLINE*5 ,ui::mouse.y );
+ glTexCoord2f(1,1);glVertex2i(ui::mouse.x+HLINE*5 ,ui::mouse.y-HLINE*5 );
+ glTexCoord2f(0,1);glVertex2i(ui::mouse.x ,ui::mouse.y-HLINE*5 );
glEnd();
+ glDisable(GL_TEXTURE_2D);
/**************************
**** END RENDERING ****
extern float VOLUME_MUSIC;
XMLDocument xml;
+XMLElement *scr;
+XMLElement *vol;
-void readConfig(void){
- XMLElement *scr;
- XMLElement *vol;
-
+void readConfig(){
+ unsigned int uval;
+ bool bval;
- //float fval;
-
++
xml.LoadFile("config/settings.xml");
scr = xml.FirstChildElement("screen");
- SCREEN_WIDTH = scr->UnsignedAttribute("width");
+
+ if(scr->QueryUnsignedAttribute("width",&uval) == XML_NO_ERROR)
+ SCREEN_WIDTH = uval;
+ else SCREEN_WIDTH = 1280;
+ if(scr->QueryUnsignedAttribute("height",&uval) == XML_NO_ERROR)
+ SCREEN_HEIGHT = uval;
+ else SCREEN_HEIGHT = 800;
+ if(scr->QueryBoolAttribute("fullscreen",&bval) == XML_NO_ERROR)
+ FULLSCREEN = bval;
+ else FULLSCREEN = false;
+ if(xml.FirstChildElement("hline")->QueryUnsignedAttribute("size",&uval) == XML_NO_ERROR)
+ HLINE = uval;
+ else HLINE = 3;
+
+ /*SCREEN_WIDTH = scr->UnsignedAttribute("width");
SCREEN_HEIGHT = scr->UnsignedAttribute("height");
FULLSCREEN = scr->BoolAttribute("fullscreen");
- HLINE = xml.FirstChildElement("hline")->UnsignedAttribute("size");
+ HLINE = xml.FirstChildElement("hline")->UnsignedAttribute("size");*/
vol = xml.FirstChildElement("volume");
VOLUME_MASTER = vol->FirstChildElement("master")->FloatAttribute("volume");
buf[j*4 ]=fontColor[0];
buf[j*4+1]=fontColor[1];
buf[j*4+2]=fontColor[2];
- buf[j*4+3]=ftf->glyph->bitmap.buffer[j] ? 255 : 0;
++ //buf[j*4+3]=ftf->glyph->bitmap.buffer[j] == 255 ? 255 : 0;
+ buf[j*4+3]=ftf->glyph->bitmap.buffer[j];
}
ftexwh[i-33].x=ftf->glyph->bitmap.width;
}
}
}
+ setFontSize(16);
}
++
++ void takeScreenshot(GLubyte* pixels){
++ GLubyte bgr[SCREEN_WIDTH*SCREEN_HEIGHT*3];
++ for(uint x = 0; x < SCREEN_WIDTH*SCREEN_HEIGHT*3; x+=3){
++ bgr[x] = pixels[x+2];
++ bgr[x+1] = pixels[x+1];
++ bgr[x+2] = pixels[x];
++ }
++
++ time_t epoch = time(NULL);
++ struct tm* timen = localtime(&epoch);
++
++ std::string name = "screenshots/";
++ name += std::to_string(1900 + timen->tm_year) += "-";
++ name += std::to_string(timen->tm_mon + 1) += "-";
++ name += std::to_string(timen->tm_mday) += "_";
++ name += std::to_string(timen->tm_hour) += "-";
++ name += std::to_string(timen->tm_min) += "-";
++ name += std::to_string(timen->tm_sec);
++ name += ".bmp";
++ FILE* bmp = fopen(name.c_str(), "w+");
++
++ unsigned long header_size = sizeof(BITMAPFILEHEADER) +
++ sizeof(BITMAPINFOHEADER);
++
++ BITMAPFILEHEADER bmfh;
++ BITMAPINFOHEADER bmih;
++
++ memset(&bmfh, 0, sizeof(BITMAPFILEHEADER));
++ memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
++
++ bmfh.bfType = 0x4d42;
++
++ bmfh.bfOffBits = 0x36;
++ bmfh.bfSize = header_size;
++ bmfh.bfReserved1 = 0;
++ bmfh.bfReserved2 = 0;
++
++
++ bmih.biSize = sizeof(BITMAPINFOHEADER);
++ bmih.biBitCount = 24;
++
++ bmih.biClrImportant = 0;
++ bmih.biClrUsed = 0;
++
++ bmih.biCompression = 0;
++
++ bmih.biWidth = SCREEN_WIDTH;
++ bmih.biHeight = SCREEN_HEIGHT;
++
++ bmih.biPlanes = 1;
++ bmih.biSizeImage = 0;
++
++ bmih.biXPelsPerMeter = 0x0ec4;
++ bmih.biYPelsPerMeter = 0x0ec4;
++
++ fwrite(&bmfh, 1,sizeof(BITMAPFILEHEADER),bmp);
++ fwrite(&bmih, 1,sizeof(BITMAPINFOHEADER),bmp);
++ fwrite(&bgr, 1,3*SCREEN_WIDTH*SCREEN_HEIGHT,bmp);
++
++ }
++
void dialogAdvance(void){
unsigned char i;
if(!typeOutDone){
currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
break;
case SDLK_F12:
-- std::cout << "Took screenshot" << std::endl;
// Make the BYTE array, factor of 3 because it's RBG.
static GLubyte* pixels = new GLubyte[ 3 * SCREEN_WIDTH * SCREEN_HEIGHT];
glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels);
++ takeScreenshot(pixels);
++ std::cout << "Took screenshot" << std::endl;
break;
default:
break;