aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-01-26 07:33:28 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-01-26 07:33:28 -0500
commit368b446c29d2001246cab2d40e406708f7c6bf7d (patch)
treeef90399051e79660c9b9eb8322c0e74348951b74 /src
parentcc28c882ce57c23bf79a2afec24b72f9942d6077 (diff)
merge
Diffstat (limited to 'src')
-rw-r--r--src/Texture.cpp32
-rw-r--r--src/entities.cpp21
-rw-r--r--src/ui.cpp13
-rw-r--r--src/world.cpp21
4 files changed, 52 insertions, 35 deletions
diff --git a/src/Texture.cpp b/src/Texture.cpp
index 4418a3b..e715b1e 100644
--- a/src/Texture.cpp
+++ b/src/Texture.cpp
@@ -79,30 +79,38 @@ namespace Texture{
}
}
+ #define CINDEX_WIDTH (8*4*3)
void initColorIndex(){
+ unsigned int i;
+ GLubyte *buffer;
+ GLfloat *bufferf;
+
+ buffer = new GLubyte[CINDEX_WIDTH];
+ bufferf = new GLfloat[CINDEX_WIDTH];
+
colorIndex = loadTexture("assets/colorIndex.png");
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, colorIndex);
- GLubyte* buffer = new GLubyte[8*4*3];
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
- GLfloat* bufferf = new GLfloat[8*4*3];
- for(uint iu = 0; iu < 8*4*3; iu++){
- bufferf[iu] = float(buffer[iu]) / 255.0f;
- }
- uint i = 0;
- for(uint y = 0; y < 8; y++){
- for(uint x = 0; x < 4; x++){
- if(i >= 8*4*3){
+
+ for(i = 0; i < CINDEX_WIDTH; i++)
+ bufferf[i] = (float)buffer[i] / 255.0f;
+
+ i = 0;
+ for(unsigned int y = 0; y < 8; y++){
+ for(unsigned int x = 0; x < 4; x++){
+ if(i >= CINDEX_WIDTH){
+ delete[] buffer;
+ delete[] bufferf;
return;
}
pixels[y][x].red = buffer[i++];
pixels[y][x].green = buffer[i++];
pixels[y][x].blue = buffer[i++];
- //std::cout << pixels[y][x].red << "," << pixels[y][x].green << "," << pixels[y][x].blue << std::endl;
- //std::cout << std::endl;
}
}
-
+ delete[] buffer;
+ delete[] bufferf;
}
//sqrt((255-145)^2+(90-145)^2+(0-0)^2);
diff --git a/src/entities.cpp b/src/entities.cpp
index 8608aeb..4a8e6b7 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -38,13 +38,9 @@ void getRandomName(Entity *e){
bufs = new char[32];
- std::cout<<"1\n";
-
for(;!names.eof();max++)
names.getline(bufs,32);
- std::cout<<"2\n";
-
tempNum = rand() % max;
names.seekg(0,names.beg);
@@ -218,13 +214,18 @@ Object::Object(){
inv = NULL;
}
-Object::Object(ITEM_ID id, bool qo, const char *pd){
+Object::Object(ITEM_ID id, const char *pd){
identifier = id;
- questObject = qo;
-
- pickupDialog = new char[strlen(pd)+1];
- strcpy(pickupDialog,pd);
-
+
+ if(pd){
+ pickupDialog = new char[strlen(pd)+1];
+ strcpy(pickupDialog,pd);
+ questObject = true;
+ }else{
+ pickupDialog = new char[1];
+ *pickupDialog = '\0';
+ questObject = false;
+ }
type = OBJECTT;
alive = true;
diff --git a/src/ui.cpp b/src/ui.cpp
index f865360..1520e9f 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -585,13 +585,19 @@ namespace ui {
};
putText(hub.x,hub.y,"Health: %u/%u",player->health>0?(unsigned)player->health:0,
- (unsigned)player->maxHealth);
+ (unsigned)player->maxHealth
+ );
if(player->alive){
- glColor3ub(255,0,0);
+ glColor3ub(150,0,0);
hub.y-=fontSize*1.15;
glRectf(hub.x,
hub.y,
- hub.x+(player->health/player->maxHealth?player->maxHealth:1)*130,
+ hub.x+150,
+ hub.y+12);
+ glColor3ub(255,0,0);
+ glRectf(hub.x,
+ hub.y,
+ hub.x+(player->health/player->maxHealth * 150),
hub.y+12);
}
@@ -916,6 +922,7 @@ DONE:
player->loc.y+=HLINE*5;
player->ground=false;
}*/
+ player->health -= 5;
break;
case SDLK_k:
/*currentWorld=currentWorld->goWorldFront(player); // Go forward a layer if possible
diff --git a/src/world.cpp b/src/world.cpp
index 71bd0f4..c8b4bde 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -962,12 +962,12 @@ void World::addStructure(BUILD_SUB sub, float x,float y,const char *inside){
entity.push_back(build.back());
}
-void World::addVillage(int bCount, int npcMin, int npcMax,const char *inside){
+/*void World::addVillage(int bCount, int npcMin, int npcMax,const char *inside){
std::cout << npcMin << ", " << npcMax << std::endl;
//int xwasd;
for(int i = 0; i < bCount; i++){
addStructure(HOUSE,x_start + (i * 300),100,inside);
- /*std::cout<<"1\n";
+ std::cout<<"1\n";
HERE:
xwasd = (rand()%(int)x+1000*HLINE);
for(auto &bu : build){
@@ -975,9 +975,10 @@ void World::addVillage(int bCount, int npcMin, int npcMax,const char *inside){
}
std::cout<<"2\n";
addStructure(t,HOUSE,xwasd,y,inside);
- std::cout<<"3\n";*/
+ std::cout<<"3\n";
}
-}
+}*/
+
void World::addMob(int t,float x,float y){
mob.push_back(new Mob(t));
mob.back()->spawn(x,y);
@@ -1000,8 +1001,8 @@ void World::addNPC(float x,float y){
entity.push_back(npc.back());
}
-void World::addObject(ITEM_ID i, bool q, const char *p, float x, float y){
- object.push_back(new Object(i,q, p));
+void World::addObject(ITEM_ID i,const char *p, float x, float y){
+ object.push_back(new Object(i,p));
object.back()->spawn(x,y);
entity.push_back(object.back());
@@ -1203,9 +1204,11 @@ extern int commonAIFunc(NPC *);
void World::load(void){
std::string save,data,line;
+ const char *filedata;
save = (std::string)currentXML + ".dat";
- data = readFile(save.c_str());
+ filedata = readFile(save.c_str());
+ data = filedata;
std::istringstream iss (data);
for(auto &n : npc){
@@ -1244,11 +1247,9 @@ void World::load(void){
while(std::getline(iss,line)){
if(line == "dOnE")
break;
-
- //std::cout<<line<<std::endl;
}
- //abort();
+ delete[] filedata;
}
IndoorWorld::IndoorWorld(void){