aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog6
-rw-r--r--include/inventory.hpp4
-rw-r--r--include/world.hpp4
-rw-r--r--main.cpp8
-rw-r--r--src/brice.cpp4
-rw-r--r--src/common.cpp2
-rw-r--r--src/entities.cpp40
-rw-r--r--src/inventory.cpp7
-rw-r--r--src/mob.cpp29
-rw-r--r--src/shader_utils.cpp23
-rw-r--r--src/ui.cpp6
-rw-r--r--src/ui_menu.cpp2
-rw-r--r--src/world.cpp50
13 files changed, 77 insertions, 108 deletions
diff --git a/Changelog b/Changelog
index 458634d..a37470a 100644
--- a/Changelog
+++ b/Changelog
@@ -977,3 +977,9 @@
- re-added click to speed up dialogs
- almost ready to add new draw stuff
+
+5/5/2016:
+=========
+
+ - pushing new drawing to master, it's okay...
+ - changed how swords function, only hits nearest entity
diff --git a/include/inventory.hpp b/include/inventory.hpp
index 552b30c..1431f42 100644
--- a/include/inventory.hpp
+++ b/include/inventory.hpp
@@ -205,10 +205,6 @@ public:
};
/***********************************************************************************
- * OLD STUFF THAT NEEDS TO BURN *
- **********************************************************************************/
-
-/***********************************************************************************
* OLD STUFF THAT NEEDS TO GET UPDATED *
**********************************************************************************/
class Inventory {
diff --git a/include/world.hpp b/include/world.hpp
index 5bfd9f2..ac17580 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -112,7 +112,7 @@ protected:
unsigned int lineCount;
// the left-most (negative) coordinate of the worldStart
- int worldStart;
+ float worldStart;
// holds / handles textures for background elements
TextureIterator bgTex;
@@ -192,8 +192,6 @@ public:
// gets a pointer to the most recently added mob
Mob *getLastMob(void);
- std::vector<Entity*> getMobs(void);
-
// gets the nearest interactable entity to the given one
Entity *getNearInteractable(Entity &e);
diff --git a/main.cpp b/main.cpp
index 8c3b631..570f12f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -99,9 +99,6 @@ void mainLoop(void);
********************************************************************************/
int main(int argc, char *argv[]){
- (void)argc;
- (void)argv;
-
static SDL_GLContext mainGLContext = NULL;
// handle command line arguments
@@ -275,6 +272,7 @@ int main(int argc, char *argv[]){
if (currentWorld == NULL)
UserError("Plot twist: The world never existed...?");
+ // spawn the arena
arena = new Arena();
arena->setStyle("");
arena->setBackground(WorldBGType::Forest);
@@ -307,9 +305,7 @@ int main(int argc, char *argv[]){
// close up the game stuff
currentWorld->save();
delete arena;
- //delete currentWorld;
- //delete[] currentXML;
- //aipreload.clear();
+ delete currentWorld;
return 0; // Calls everything passed to atexit
}
diff --git a/src/brice.cpp b/src/brice.cpp
index fef336e..6b64d88 100644
--- a/src/brice.cpp
+++ b/src/brice.cpp
@@ -50,11 +50,13 @@ namespace game {
}
void briceLoad(void) {
- const std::string data = readFile("brice.dat");
+ const char *data = readFile("brice.dat");
auto datas = StringTokenizer(data, ',');
for (const auto& d : datas)
std::cout << d << '\n';
+
+ delete[] data;
}
void briceUpdate(void) {
diff --git a/src/common.cpp b/src/common.cpp
index 14fad9c..77be098 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -13,6 +13,8 @@
#include <errno.h>
#include <vector>
+#include <texture.hpp>
+
unsigned int millis(void) {
std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
diff --git a/src/entities.cpp b/src/entities.cpp
index c4e4186..a8f5e48 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -435,38 +435,38 @@ if (health != maxHealth) {
};
GLfloat coord_front[] = {
- loc.x, loc.y + height, 1.0,
- loc.x + width, loc.y + height, 1.0,
- loc.x + width, loc.y + height + game::HLINE * 2, 1.0,
+ loc.x, loc.y + height, 1.0,
+ loc.x + health / maxHealth * width, loc.y + height, 1.0,
+ loc.x + health / maxHealth * width, loc.y + height + game::HLINE * 2, 1.0,
- loc.x + width, loc.y + height + game::HLINE * 2, 1.0,
- loc.x, loc.y + height + game::HLINE * 2, 1.0,
- loc.x, loc.y + height, 1.0,
+ loc.x + health / maxHealth * width, loc.y + height + game::HLINE * 2, 1.0,
+ loc.x, loc.y + height + game::HLINE * 2, 1.0,
+ loc.x, loc.y + height, 1.0,
};
- vec2 index = Texture::getIndex(Color(150,0,0));
+ static const vec2 index1 = Texture::getIndex(Color(0,0,0));
GLfloat back_tex[] = {
- float(.25*index.x), float(.125*index.y),
- float(.25*index.x), float(.125*index.y),
- float(.25*index.x), float(.125*index.y),
+ float(.25*index1.x), float(.125*index1.y),
+ float(.25*index1.x), float(.125*index1.y),
+ float(.25*index1.x), float(.125*index1.y),
- float(.25*index.x), float(.125*index.y),
- float(.25*index.x), float(.125*index.y),
- float(.25*index.x), float(.125*index.y),
+ float(.25*index1.x), float(.125*index1.y),
+ float(.25*index1.x), float(.125*index1.y),
+ float(.25*index1.x), float(.125*index1.y),
};
glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, coord_back);
glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, back_tex);
glDrawArrays(GL_TRIANGLES, 0, 6);
- index = Texture::getIndex(Color(255,0,0));
+ static const vec2 index2 = Texture::getIndex(Color(255,0,0));
GLfloat front_tex[] = {
- float(.25*index.x), float(.125*index.y),
- float(.25*index.x), float(.125*index.y),
- float(.25*index.x), float(.125*index.y),
+ float(.25*index2.x), float(.125*index2.y),
+ float(.25*index2.x), float(.125*index2.y),
+ float(.25*index2.x), float(.125*index2.y),
- float(.25*index.x), float(.125*index.y),
- float(.25*index.x), float(.125*index.y),
- float(.25*index.x), float(.125*index.y),
+ float(.25*index2.x), float(.125*index2.y),
+ float(.25*index2.x), float(.125*index2.y),
+ float(.25*index2.x), float(.125*index2.y),
};
glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, coord_front);
glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, front_tex);
diff --git a/src/inventory.cpp b/src/inventory.cpp
index b363b86..a1181e2 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -63,6 +63,7 @@ void items(void)
Sword *tmpSword = new Sword();
tmpSword->setDamage(exml->FloatAttribute("damage"));
ItemMap.push_back(tmpSword->clone());
+ delete tmpSword;
// if the type is a bow
} else if (strCaseCmp(name, "bow")) {
@@ -70,6 +71,7 @@ void items(void)
Bow *tmpBow = new Bow();
tmpBow->setDamage(exml->FloatAttribute("damage"));
ItemMap.push_back(tmpBow->clone());
+ delete tmpBow;
// arrow
} else if (strCaseCmp(name, "arrow")) {
@@ -77,6 +79,7 @@ void items(void)
Arrow *tmpArrow = new Arrow();
tmpArrow->setDamage(exml->FloatAttribute("damage"));
ItemMap.push_back(tmpArrow->clone());
+ delete tmpArrow;
// uncooked / raw food
}else if (strCaseCmp(name, "raw food")) {
@@ -214,8 +217,8 @@ void destroyInventory(void) {
// NEWEWEWEWEWEWEWEW
while (!ItemMap.empty()) {
- delete ItemMap.front();
- ItemMap.erase(std::begin(ItemMap));
+ delete ItemMap.back();
+ ItemMap.pop_back();
}
Mix_FreeChunk(swordSwing);
diff --git a/src/mob.cpp b/src/mob.cpp
index d524397..ec8b849 100644
--- a/src/mob.cpp
+++ b/src/mob.cpp
@@ -149,28 +149,23 @@ Rabbit::Rabbit(void) : Mob()
actCounter = 1;
}
-extern bool inBattle;
void Rabbit::act(void)
{
static int direction = 0;
- if (inBattle) {
- die();
- } else {
- if (!--actCounter) {
- actCounter = actCounterInitial;
- direction = (randGet() % 3 - 1); //sets the direction to either -1, 0, 1
- if (direction == 0)
- ticksToUse /= 2;
- vel.x *= direction;
- }
+ if (!--actCounter) {
+ actCounter = actCounterInitial;
+ direction = (randGet() % 3 - 1); //sets the direction to either -1, 0, 1
+ if (direction == 0)
+ ticksToUse /= 2;
+ vel.x *= direction;
+ }
- if (ground && direction) {
- ground = false;
- vel.y = .15;
- loc.y += HLINES(0.25f);
- vel.x = 0.05f * direction;
- }
+ if (ground && direction) {
+ ground = false;
+ vel.y = .15;
+ loc.y += HLINES(0.25f);
+ vel.x = 0.05f * direction;
}
}
diff --git a/src/shader_utils.cpp b/src/shader_utils.cpp
index 13b2f74..bc9375c 100644
--- a/src/shader_utils.cpp
+++ b/src/shader_utils.cpp
@@ -1,9 +1,3 @@
-/**
- * From the OpenGL Programming wikibook: http://en.wikibooks.org/wiki/OpenGL_Programming
- * This file is in the public domain.
- * Contributors: Sylvain Beucler, Guus Sliepen
- */
-
#include <iostream>
#include <vector>
using namespace std;
@@ -76,21 +70,8 @@ GLuint create_shader(const char* filename, GLenum type) {
return 0;
}
GLuint res = glCreateShader(type);
- const GLchar* sources[] = {
- // Define GLSL version
- "#version 130\n" // OpenGL 2.0
- ,
- // Define default float precision for fragment shaders:
- (type == GL_FRAGMENT_SHADER) ?
- "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
- "precision highp float; \n"
- "#else \n"
- "precision mediump float; \n"
- "#endif \n"
- : ""
- ,
- source };
- glShaderSource(res, 3, sources, NULL);
+ const GLchar* sources[2] = { "#version 120\n", source };
+ glShaderSource(res, 2, sources,NULL);
delete[] source;
glCompileShader(res);
diff --git a/src/ui.cpp b/src/ui.cpp
index 8d15bcd..6a68cc0 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -1035,8 +1035,10 @@ EXIT:
} else {
// left click uses item
if (e.button.button & SDL_BUTTON_LEFT) {
- player->inv->currentAddInteract(currentWorld->getMobs());
- player->inv->useCurrent();
+ if ((m = currentWorld->getNearMob(*player)) != nullptr) {
+ player->inv->currentAddInteract(m);
+ player->inv->useCurrent();
+ }
}
}
diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp
index 09b09c8..c9510c2 100644
--- a/src/ui_menu.cpp
+++ b/src/ui_menu.cpp
@@ -135,7 +135,7 @@ namespace ui {
//draw the dark transparent background
glColor4f(0.0f, 0.0f, 0.0f, .8f);
- glRectf(offset.x-SCREEN_WIDTH/2,0,offset.x+SCREEN_WIDTH/2,SCREEN_HEIGHT);
+ glRectf(offset.x-SCREEN_WIDTH/2,-SCREEN_HEIGHT/2,offset.x+SCREEN_WIDTH/2,SCREEN_HEIGHT/2);
//loop through all elements of the menu
for (auto &m : currentMenu->items) {
diff --git a/src/world.cpp b/src/world.cpp
index c2cdbc5..362cc8b 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -206,7 +206,7 @@ generate(int width)
// create empty star array, should be filled here as well...
star = std::vector<vec2> (100, vec2 { 0, 400 });
for (auto &s : star) {
- s.x = (randGet() % (-worldStart * 2)) + worldStart;
+ s.x = (randGet() % (static_cast<int>(-worldStart) * 2)) + worldStart;
s.y = (randGet() % game::SCREEN_HEIGHT) + 100;
}
@@ -269,8 +269,6 @@ draw(Player *p)
glUniform1i(worldShader_uniform_texture, 0);
// draw background images.
- //glEnable(GL_TEXTURE_2D);
-
GLfloat tex_coord[] = { 0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
@@ -581,13 +579,13 @@ draw(Player *p)
// glTexCoord2i(1, ty); glVertex2i(worldStart + i * HLINE + HLINE, 0);
// glTexCoord2i(0, ty); glVertex2i(worldStart + i * HLINE , 0);
- c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + i * HLINE, worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
- c.push_back(std::make_pair(vec2(1, 0), vec3(worldStart + i * HLINE + HLINE, worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
- c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + i * HLINE + HLINE, 0, 1.0f)));
+ c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + HLINES(i), worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
+ c.push_back(std::make_pair(vec2(1, 0), vec3(worldStart + HLINES(i) + HLINE, worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
+ c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + HLINES(i) + HLINE, 0, 1.0f)));
- c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + i * HLINE + HLINE, 0, 1.0f)));
- c.push_back(std::make_pair(vec2(0, ty),vec3(worldStart + i * HLINE, 0, 1.0f)));
- c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + i * HLINE, worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
+ c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + HLINES(i) + HLINE, 0, 1.0f)));
+ c.push_back(std::make_pair(vec2(0, ty),vec3(worldStart + HLINES(i), 0, 1.0f)));
+ c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + HLINES(i), worldData[i].groundHeight - GRASS_HEIGHT, 1.0f)));
if (worldData[i].groundHeight == GROUND_HEIGHT_MINIMUM - 1)
worldData[i].groundHeight = 0;
@@ -659,22 +657,22 @@ draw(Player *p)
glTexCoord2i(1, 1); glVertex2i(worldStart + i * HLINE + HLINE , wd.groundHeight - GRASS_HEIGHT);
glTexCoord2i(0, 1); glVertex2i(worldStart + i * HLINE + HLINE / 2, wd.groundHeight - GRASS_HEIGHT);*/
- c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + i * HLINE , wd.groundHeight + gh[0])));
- c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight + gh[0])));
- c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
+ c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) , wd.groundHeight + gh[0])));
+ c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[0])));
+ c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
- c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
- c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + i * HLINE , wd.groundHeight - GRASS_HEIGHT)));
- c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + i * HLINE , wd.groundHeight + gh[0])));
+ c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
+ c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i) , wd.groundHeight - GRASS_HEIGHT)));
+ c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) , wd.groundHeight + gh[0])));
- c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight + gh[1])));
- c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + i * HLINE + HLINE , wd.groundHeight + gh[1])));
- c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + i * HLINE + HLINE , wd.groundHeight - GRASS_HEIGHT)));
+ c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1])));
+ c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE , wd.groundHeight + gh[1])));
+ c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE , wd.groundHeight - GRASS_HEIGHT)));
- c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + i * HLINE + HLINE , wd.groundHeight - GRASS_HEIGHT)));
- c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
- c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + i * HLINE + HLINE / 2, wd.groundHeight + gh[1])));
+ c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE , wd.groundHeight - GRASS_HEIGHT)));
+ c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT)));
+ c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1])));
//glEnd();
}
@@ -1051,16 +1049,6 @@ getLastMob(void)
return mob.back();
}
-std::vector<Entity*> World::
-getMobs(void)
-{
- std::vector<Entity*> meme;
- for (auto &m : mob) {
- meme.push_back(m);
- }
- return meme;
-}
-
/**
* Get the interactable entity that is closest to the entity provided.
*/