game::briceLoad();
game::briceUpdate();
- //
+ // load sprites used in the inventory menu. See src/inventory.cpp
+ //initInventorySprites();
+
- // load mouse texture, and other inventory textures
- mouseTex = Texture::loadTexture("assets/goodmouse.png");
-
// get a world
+ //
+
if (xmlFolder.empty())
xmlFolder = "xml/";
const bool &run = game::engine.shouldRun;
while (run) {
render();
- game::engine.render(0);
+ game::engine.resetRender(0);
}
+ // on game end, get back together
thMain.join();
thDebug.join();
- //game::engine.getSystem<WorldSystem>()->thAmbient.join();
+ //game::engine.getSystem<WorldSystem>()->thAmbient.join(); // segfault or something
}
- // put away the brice for later
+ //
+ // put away the brice for later, save world
+ //
+
game::briceSave();
+ worldSys->save();
+
+ //
+ // close things, free stuff, yada yada
+ //
- // free library resources
Mix_HaltMusic();
Mix_CloseAudio();
}
void render() {
- const auto SCREEN_WIDTH = game::SCREEN_WIDTH;
- const auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
- static const Texture mouseTex ("assets/mouse.png");
++ static const Texture mouseTex ("assets/goodmouse.png");
+ static const glm::mat4 view = glm::lookAt(
+ glm::vec3(0.0f, 0.0f, 0.0f), // pos
+ glm::vec3(0.0f, 0.0f, -10.0f), // looking at
+ glm::vec3(0.0f, 1.0f, 0.0f) // up vector
+ );
+
+ static const auto& SCREEN_WIDTH2 = game::SCREEN_WIDTH / 2.0f;
+ static const auto& SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2.0f;
+
+ //
+ // set the ortho
+ //
auto ps = game::engine.getSystem<PlayerSystem>();
auto ploc = ps->getPosition();
// draw the mouse
Render::textShader.use();
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, mouseTex);
+ mouseTex.use();
Render::useShader(&Render::textShader);
- Render::drawRect(ui::mouse, ui::mouse + 15, -9.9);
+ Render::drawRect(vec2(ui::mouse.x, ui::mouse.y - 64), vec2(ui::mouse.x + 64, ui::mouse.y), -9.9);
Render::textShader.unuse();
}
-
- void logic(){
- // static bool NPCSelected = false;
- // static bool ObjectSelected = false;
-
- // exit the game if the player falls out of the world
- /*if (player->loc.y < 0)
- game::endGame();*/
-
- /*if (player->inv->usingi) {
- for (auto &e : currentWorld->entity) {
- if (player->inv->usingi && !e->isHit() &&
- player->inv->detectCollision(vec2 { e->loc.x, e->loc.y }, vec2 { e->loc.x + e->width, e->loc.y + e->height})) {
- e->takeHit(25, 10);
- break;
- }
- }
- player->inv->usingi = false;
- }*/
-
- /*for (auto &e : currentWorld->entity) {
- if (e->isAlive() && ((e->type == NPCT) || (e->type == MERCHT) || (e->type == OBJECTT))) {
- if (e->type == OBJECTT && ObjectSelected) {
- e->near = false;
- continue;
- } else if (e->canMove) {
- if (!currentWorld->goWorldLeft(dynamic_cast<NPC *>(e)))
- currentWorld->goWorldRight(dynamic_cast<NPC *>(e));
- e->wander((rand() % 120 + 30));
- if (NPCSelected) {
- e->near = false;
- continue;
- }
- }
-
- if(e->isInside(ui::mouse) && player->isNear(e)) {
- e->near = true;
- if (e->type == OBJECTT)
- ObjectSelected = true;
- else
- NPCSelected = true;
-
- if ((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)) && !ui::dialogBoxExists) {
- if (ui::mouse.x < player->loc.x && player->right)
- player->left = true, player->right = false;
- else if(ui::mouse.x > player->loc.x && player->left)
- player->right = true, player->left = false;
- e->interact();
- }
- } else {
- e->near = false;
- }
- } else if (e->type == MOBT) {
- e->near = player->isNear(e);
- e->wander();
- }
- }*/
-
- // calculate the world shading value
- worldShade = 50 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
-
- // update fades
- ui::fadeUpdate();
-
- // create weather particles if necessary
- /*auto weather = game::engine.getSystem<WorldSystem>()->getWeatherId();
- auto worldWidth = game::engine.getSystem<WorldSystem>()->getWidth();
- if (weather == WorldWeather::Rain) {
- for (unsigned int r = (randGet() % 25) + 11; r--;) {
- currentWorld->addParticle(randGet() % worldWidth - (worldWidth / 2),
- offset.y + game::SCREEN_HEIGHT / 2,
- HLINES(1.25), // width
- HLINES(1.25), // height
- randGet() % 7 * .01 * (randGet() % 2 == 0 ? -1 : 1), // vel.x
- (4 + randGet() % 6) * .05, // vel.y
- { 0, 0, 255 }, // RGB color
- 2500, // duration (ms)
- (1 << 0) | (1 << 1) // gravity and bounce
- );
- }
- } else if (weather == WorldWeather::Snowy) {
- for (unsigned int r = (randGet() % 25) + 11; r--;) {
- currentWorld->addParticle(randGet() % worldWidth - (worldWidth / 2),
- offset.y + game::SCREEN_HEIGHT / 2,
- HLINES(1.25), // width
- HLINES(1.25), // height
- .0001 + randGet() % 7 * .01 * (randGet() % 2 == 0 ? -1 : 1), // vel.x
- (4 + randGet() % 6) * -.03, // vel.y
- { 255, 255, 255 }, // RGB color
- 5000, // duration (ms)
- 0 // no gravity, no bounce
- );
- }
- }*/
-
- // increment game ticker
- game::time::tick();
- //NPCSelected = false;
- //ObjectSelected = false;
- }
position.x += direction.x * dt;
position.y += direction.y * dt;
-- if (entity.has_component<Animate>() && entity.has_component<Sprite>()) {
- if (direction.x) {
- entity.component<Animate>()->nextFrame(entity.component<Sprite>()->sprite);
- } else {
- entity.component<Animate>()->firstFrame(entity.component<Sprite>()->sprite);
- }
- }
++ /*if (entity.has_component<Animate>() && entity.has_component<Sprite>()) {
+ auto animate = entity.component<Animate>();
+ entity.component<Sprite>()->sprite =
+ (direction.x != 0) ? animate->nextFrame() : animate->firstFrame();
- }
++ }*/
if (entity.has_component<Dialog>() && entity.component<Dialog>()->talking) {
direction.x = 0;
} else {
en.each<Visible, Sprite, Position>([dt](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
(void)entity;
// Verticies and shit
- GLfloat tex_coord[] = {0.0, 0.0,
- 1.0, 0.0,
- 1.0, 1.0,
-
- 1.0, 1.0,
- 0.0, 1.0,
- 0.0, 0.0};
+ float its = 0;
+ for (auto &S : sprite.sprite) {
+ auto sp = S.first;
- float width = HLINES(S.first.size.x);
- float height = HLINES(S.first.size.y);
++ auto size = sp.size * game::HLINE;
+ vec2 drawOffset(HLINES(S.second.x), HLINES(S.second.y));
+ vec2 loc(pos.x + drawOffset.x, pos.y + drawOffset.y);
- GLfloat tex_coordL[] = {1.0, 0.0,
- 0.0, 0.0,
- 0.0, 1.0,
+ GLfloat tex_coord[] = {sp.offset_tex.x, sp.offset_tex.y,
+ sp.offset_tex.x + sp.size_tex.x, sp.offset_tex.y,
+ sp.offset_tex.x + sp.size_tex.x, sp.offset_tex.y + sp.size_tex.y,
- 0.0, 1.0,
- 1.0, 1.0,
- 1.0, 0.0};
+ sp.offset_tex.x + sp.size_tex.x, sp.offset_tex.y + sp.size_tex.y,
+ sp.offset_tex.x, sp.offset_tex.y + sp.size_tex.y,
+ sp.offset_tex.x, sp.offset_tex.y};
- for (auto &S : sprite.sprite) {
- const auto& size = S.first.tex.getDim() * game::HLINE;
+ if(sprite.faceLeft) {
-
+ glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(-1.0f,1.0f,1.0f));
- glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(0-width-pos.x*2, 0.0f, 0.0f));
++ glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f - size.x - pos.x * 2.0f, 0.0f, 0.0f));
- vec2 loc = vec2(pos.x + S.first.offset.x, pos.y + S.first.offset.y);
+ glm::mat4 mov = scale * translate;
+ glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(mov));
-
- } else {
-
+ }
- GLfloat coords[] = {loc.x, loc.y, visible.z,
- loc.x + size.x, loc.y, visible.z,
- loc.x + size.x, loc.y + size.y, visible.z,
+ GLfloat coords[] = {loc.x, loc.y, visible.z + its,
- loc.x + width, loc.y, visible.z + its,
- loc.x + width, loc.y + height, visible.z + its,
++ loc.x + size.x, loc.y, visible.z + its,
++ loc.x + size.x, loc.y + size.y, visible.z + its,
- loc.x + width, loc.y + height, visible.z + its,
- loc.x, loc.y + height, visible.z + its,
- loc.x + size.x, loc.y + size.y, visible.z,
- loc.x, loc.y + size.y, visible.z,
- loc.x, loc.y, visible.z};
++ loc.x + size.x, loc.y + size.y, visible.z + its,
++ loc.x, loc.y + size.y, visible.z + its,
+ loc.x, loc.y, visible.z + its};
// make the entity hit flash red
glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, flashAmt, flashAmt, 1.0);
}*/
- glBindTexture(GL_TEXTURE_2D, S.first.pic);
- S.first.tex.use();
++ sp.tex.use();
glUniform1i(Render::worldShader.uniform[WU_texture], 0);
Render::worldShader.enable();
c2.x, c2.y, z, 1.0f, 1.0f,
c2.x, c2.y, z, 1.0f, 1.0f,
- c2.x - box_corner_dim.x, c2.y, z, 0.5f, 1.0f,
- c2.x - box_corner_dim.x, c2.y - box_corner_dim.y, z, 0.5f, 0.5f};
+ c2.x - boxCornerDim2.x, c2.y, z, 0.5f, 1.0f,
+ c2.x - boxCornerDim2.x, c2.y - boxCornerDim2.y, z, 0.5f, 0.5f};
- GLfloat box_lr[] = {c2.x - box_corner_dim.x, c1.y, z, 0.5f, 0.0f,
+ GLfloat box_lr[] = {c2.x - boxCornerDim2.x, c1.y, z, 0.5f, 0.0f,
c2.x, c1.y, z, 1.0f, 0.0f,
- c2.x, c1.y + box_corner_dim.y, z, 1.0f, 0.5f,
+ c2.x, c1.y + boxCornerDim2.y, z, 1.0f, 0.5f,
- c2.x, c1.y + box_corner_dim.y, z, 1.0f, 0.5f,
- c2.x - box_corner_dim.x, c1.y + box_corner_dim.y, z, 0.5f, 0.5f,
- c2.x - box_corner_dim.x, c1.y, z, 0.5f, 0.0f};
+ c2.x, c1.y + boxCornerDim2.y, z, 1.0f, 0.5f,
- c2.x - boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.0f, 0.5f,
++ c2.x - boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.5f, 0.5f,
+ c2.x - boxCornerDim2.x, c1.y, z, 0.5f, 0.0f};
- GLfloat box_l[] = {c1.x, c1.y + box_corner_dim.y, z, 0.0f, 0.0f,
- c1.x + box_corner_dim.x, c1.y + box_corner_dim.y, z, 0.5f, 0.0f,
- c1.x + box_corner_dim.x, c2.y - box_corner_dim.y, z, 0.5f, 1.0f,
+ GLfloat box_l[] = {c1.x, c1.y + boxCornerDim2.y, z, 0.0f, 0.0f,
+ c1.x + boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.5f, 0.0f,
+ c1.x + boxCornerDim2.x, c2.y - boxCornerDim2.y, z, 0.5f, 1.0f,
- c1.x + box_corner_dim.x, c2.y - box_corner_dim.y, z, 0.5f, 1.0f,
- c1.x, c2.y - box_corner_dim.y, z, 0.0f, 1.0f,
- c1.x, c1.y + box_corner_dim.y, z, 0.0f, 0.0f};
+ c1.x + boxCornerDim2.x, c2.y - boxCornerDim2.y, z, 0.5f, 1.0f,
+ c1.x, c2.y - boxCornerDim2.y, z, 0.0f, 1.0f,
+ c1.x, c1.y + boxCornerDim2.y, z, 0.0f, 0.0f};
- GLfloat box_r[] = {c2.x - box_corner_dim.x, c1.y + box_corner_dim.y, z, 0.5f, 0.0f,
- c2.x, c1.y + box_corner_dim.y, z, 1.0f, 0.0f,
- c2.x, c2.y - box_corner_dim.y, z, 1.0f, 1.0f,
+ GLfloat box_r[] = {c2.x - boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.5f, 0.0f,
+ c2.x, c1.y + boxCornerDim2.y, z, 1.0f, 0.0f,
+ c2.x, c2.y - boxCornerDim2.y, z, 1.0f, 1.0f,
- c2.x, c2.y - box_corner_dim.y, z, 1.0f, 1.0f,
- c2.x - box_corner_dim.x, c2.y - box_corner_dim.y, z, 0.5f, 1.0f,
- c2.x - box_corner_dim.x, c1.y + box_corner_dim.y, z, 0.5f, 0.0f};
+ c2.x, c2.y - boxCornerDim2.y, z, 1.0f, 1.0f,
+ c2.x - boxCornerDim2.x, c2.y - boxCornerDim2.y, z, 0.5f, 1.0f,
+ c2.x - boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.5f, 0.0f};
- GLfloat box_b[] = {c1.x + box_corner_dim.x, c1.y, z, 0.0f, 0.0f,
- c2.x - box_corner_dim.x, c1.y, z, 1.0f, 0.0f,
- c2.x - box_corner_dim.x, c1.y + box_corner_dim.y, z, 1.0f, 0.5f,
+ GLfloat box_b[] = {c1.x + boxCornerDim2.x, c1.y, z, 0.0f, 0.0f,
+ c2.x - boxCornerDim2.x, c1.y, z, 1.0f, 0.0f,
+ c2.x - boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 1.0f, 0.5f,
- c2.x - box_corner_dim.x, c1.y + box_corner_dim.y, z, 1.0f, 0.5f,
- c1.x + box_corner_dim.x, c1.y + box_corner_dim.y, z, 0.0f, 0.5f,
- c1.x + box_corner_dim.x, c1.y, z, 0.0f, 0.0f};
+ c2.x - boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 1.0f, 0.5f,
+ c1.x + boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.0f, 0.5f,
+ c1.x + boxCornerDim2.x, c1.y, z, 0.0f, 0.0f};
- GLfloat box_t[] = {c1.x + box_corner_dim.x, c2.y - box_corner_dim.y, z, 0.0f, 0.5f,
- c2.x - box_corner_dim.x, c2.y - box_corner_dim.y, z, 1.0f, 0.5f,
- c2.x - box_corner_dim.x, c2.y, z, 1.0f, 1.0f,
+ GLfloat box_t[] = {c1.x + boxCornerDim2.x, c2.y - boxCornerDim2.y, z, 0.0f, 0.5f,
+ c2.x - boxCornerDim2.x, c2.y - boxCornerDim2.y, z, 1.0f, 0.5f,
+ c2.x - boxCornerDim2.x, c2.y, z, 1.0f, 1.0f,
- c2.x - box_corner_dim.x, c2.y, z, 1.0f, 1.0f,
- c1.x + box_corner_dim.x, c2.y, z, 0.0f, 1.0f,
- c1.x + box_corner_dim.x, c2.y - box_corner_dim.y, z, 0.0f, 0.5f};
+ c2.x - boxCornerDim2.x, c2.y, z, 1.0f, 1.0f,
+ c1.x + boxCornerDim2.x, c2.y, z, 0.0f, 1.0f,
+ c1.x + boxCornerDim2.x, c2.y - boxCornerDim2.y, z, 0.0f, 0.5f};
- GLfloat box_f[] = {c1.x + box_corner_dim.x, c1.y + box_corner_dim.y, z, 0.5f, 0.5f,
- c2.x - box_corner_dim.x, c1.y + box_corner_dim.y, z, 0.5f, 0.5f,
- c2.x - box_corner_dim.x, c2.y - box_corner_dim.y, z, 0.5f, 0.5f,
+ GLfloat box_f[] = {c1.x + boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.5f, 0.5f,
+ c2.x - boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.5f, 0.5f,
+ c2.x - boxCornerDim2.x, c2.y - boxCornerDim2.y, z, 0.5f, 0.5f,
- c2.x - box_corner_dim.x, c2.y - box_corner_dim.y, z, 0.5f, 0.5f,
- c1.x + box_corner_dim.x, c2.y - box_corner_dim.y, z, 0.5f, 0.5f,
- c1.x + box_corner_dim.x, c1.y + box_corner_dim.y, z, 0.5f, 0.5f};
+ c2.x - boxCornerDim2.x, c2.y - boxCornerDim2.y, z, 0.5f, 0.5f,
+ c1.x + boxCornerDim2.x, c2.y - boxCornerDim2.y, z, 0.5f, 0.5f,
+ c1.x + boxCornerDim2.x, c1.y + boxCornerDim2.y, z, 0.5f, 0.5f};
glActiveTexture(GL_TEXTURE0);
glUniform1f(Render::textShader.uniform[WU_texture], 0);