aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/common.h2
-rw-r--r--include/entities.h14
-rw-r--r--include/world.h4
-rw-r--r--main.cpp54
-rw-r--r--src/common.cpp2
-rw-r--r--src/entities.cpp4
-rw-r--r--src/gameplay.cpp54
-rw-r--r--src/ui.cpp13
-rw-r--r--src/world.cpp56
-rw-r--r--test.frag12
-rw-r--r--xml/playerSpawnHill1.xml4
-rw-r--r--xml/playerSpawnHill1_Building1.xml9
12 files changed, 148 insertions, 80 deletions
diff --git a/include/common.h b/include/common.h
index 22ecb22..be32019 100644
--- a/include/common.h
+++ b/include/common.h
@@ -203,4 +203,6 @@ unsigned int millis(void);
int getdir(const char *dir, std::vector<std::string> &files);
void strVectorSortAlpha(std::vector<std::string> *v);
+extern void *NULLPTR;
+
#endif // COMMON_H
diff --git a/include/entities.h b/include/entities.h
index fe0d014..8ef7c90 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -82,11 +82,11 @@ public:
float velx;
float vely;
Color color;
- int duration;
+ float duration;
bool canMove;
bool fountain;
bool gravity;
- Particles(float x, float y, float w, float h, float vx, float vy, Color c, int d){
+ Particles(float x, float y, float w, float h, float vx, float vy, Color c, float d){
loc.x = (x);
loc.y = (y);
width = (w);
@@ -100,14 +100,16 @@ public:
fountain = false;
gravity = true;
}
- ~Particles(){}
+ ~Particles(){
+
+ }
void draw(){
glColor3f(color.red,color.green,color.blue);
glRectf(loc.x,loc.y,loc.x+width,loc.y+height);
}
bool kill(float delta){
duration -= delta;
- if(duration <= 0){
+ if(duration <= 0.0f){
return true;
}
else return false;
@@ -204,15 +206,13 @@ public:
typedef struct {
EntitySavePacket esp;
- World *inWorld;
- World *inside;
BUILD_SUB bsubtype;
} __attribute__ ((packed)) StructuresSavePacket;
class Structures : public Entity{
public:
World *inWorld;
- World *inside;
+ World **inside;
BUILD_SUB bsubtype;
Structures();
diff --git a/include/world.h b/include/world.h
index 7f22cba..27936f7 100644
--- a/include/world.h
+++ b/include/world.h
@@ -176,8 +176,8 @@ public:
std::vector<Particles *> particles;
std::vector<Light > light;
- void addStructure(BUILD_SUB sub,float x,float y,World *inside);
- void addVillage(int x, int y, int bCount, int npcMin, int npcMax,World *inside);
+ void addStructure(BUILD_SUB sub,float x,float y,World **inside);//,World **outside);
+ void addVillage(int bCount, int npcMin, int npcMax,World **inside);
void addMob(int t,float x,float y);
void addMob(int t,float x,float y,void (*hey)(Mob *));
void addNPC(float x,float y);
diff --git a/main.cpp b/main.cpp
index 8254d9b..bd3d89b 100644
--- a/main.cpp
+++ b/main.cpp
@@ -341,43 +341,41 @@ int main(/*int argc, char *argv[]*/){
* Initializes our shaders so that the game has shadows.
*/
- #ifdef SHADERS
- std::cout << "Initializing shaders!" << std::endl;
+ std::cout << "Initializing shaders!" << std::endl;
- fragShader = glCreateShader(GL_FRAGMENT_SHADER);
+ fragShader = glCreateShader(GL_FRAGMENT_SHADER);
- std::string shaderFileContents = readFile("test.frag");
- const GLchar *shaderSource = shaderFileContents.c_str();
+ std::string shaderFileContents = readFile("test.frag");
+ const GLchar *shaderSource = shaderFileContents.c_str();
- GLint bufferln = GL_FALSE;
- int logLength;
+ GLint bufferln = GL_FALSE;
+ int logLength;
- glShaderSource(fragShader, 1, &shaderSource, NULL);
- glCompileShader(fragShader);
+ glShaderSource(fragShader, 1, &shaderSource, NULL);
+ glCompileShader(fragShader);
- glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bufferln);
- glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength);
- std::vector<char>fragShaderError((logLength > 1) ? logLength : 1);
- glGetShaderInfoLog(fragShader, logLength, NULL, &fragShaderError[0]);
- std::cout << &fragShaderError[0] << std::endl;
-
- if(bufferln == GL_FALSE){
- std::cout << "Error compiling shader" << std::endl;
- }
+ glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bufferln);
+ glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength);
+ std::vector<char>fragShaderError((logLength > 1) ? logLength : 1);
+ glGetShaderInfoLog(fragShader, logLength, NULL, &fragShaderError[0]);
+ std::cout << &fragShaderError[0] << std::endl;
+
+ if(bufferln == GL_FALSE){
+ std::cout << "Error compiling shader" << std::endl;
+ }
- shaderProgram = glCreateProgram();
- glAttachShader(shaderProgram, fragShader);
- glLinkProgram(shaderProgram);
- glValidateProgram(shaderProgram);
+ shaderProgram = glCreateProgram();
+ glAttachShader(shaderProgram, fragShader);
+ glLinkProgram(shaderProgram);
+ glValidateProgram(shaderProgram);
- glGetProgramiv(shaderProgram, GL_LINK_STATUS, &bufferln);
- glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &logLength);
- std::vector<char> programError( (logLength > 1) ? logLength : 1 );
- glGetProgramInfoLog(shaderProgram, logLength, NULL, &programError[0]);
- std::cout << &programError[0] << std::endl;
+ glGetProgramiv(shaderProgram, GL_LINK_STATUS, &bufferln);
+ glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &logLength);
+ std::vector<char> programError( (logLength > 1) ? logLength : 1 );
+ glGetProgramInfoLog(shaderProgram, logLength, NULL, &programError[0]);
+ std::cout << &programError[0] << std::endl;
- #endif //SHADERS
//glEnable(GL_DEPTH_TEST); //THIS DOESN'T WORK ON LINUX
glEnable(GL_MULTISAMPLE);
diff --git a/src/common.cpp b/src/common.cpp
index ead2dc3..84515c3 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -10,6 +10,8 @@
#include <vector>
#endif // __WIN32__
+void *NULLPTR = NULL;
+
#ifndef __WIN32__
unsigned int millis(void){
diff --git a/src/entities.cpp b/src/entities.cpp
index abb1427..817a1b0 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -681,8 +681,6 @@ char *Structures::save(void){
esp = baseSave();
memcpy(&ssp->esp,esp,sizeof(EntitySavePacket));
delete[] esp;
- ssp->inWorld = inWorld;
- ssp->inside = inside;
ssp->bsubtype = bsubtype;
return (char *)ssp;
}
@@ -690,8 +688,6 @@ char *Structures::save(void){
void Structures::load(char *s){
StructuresSavePacket *ssp = (StructuresSavePacket *)s;
baseLoad((char *)&ssp->esp);
- inWorld = ssp->inWorld;
- inside = ssp->inside;
bsubtype = ssp->bsubtype;
}
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 55161f9..d647270 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -153,8 +153,12 @@ void initEverything(void){
const char *name;
std::vector<std::string> xmlFiles;
static char *file;
+
+ static bool Indoor = false;
bool dialog;
float spawnx;
+ World **yoyo;//,**yoyo2;
+
XMLDocument xml;
XMLElement *wxml;
@@ -181,9 +185,17 @@ void initEverything(void){
std::cout<<std::endl<<"Loading "<<file<<" ..."<<std::endl<<std::endl;
xml.LoadFile(file);
- wxml = xml.FirstChildElement("World")->FirstChildElement();
+ wxml = xml.FirstChildElement("World");//->FirstChildElement();
- earth.push_back(new World());
+ if(wxml){
+ wxml = wxml->FirstChildElement();
+ earth.push_back(new World());
+ Indoor = false;
+ }else if((wxml = xml.FirstChildElement("IndoorWorld"))){
+ wxml = wxml->FirstChildElement();
+ earth.push_back(new IndoorWorld());
+ Indoor = true;
+ }
for(auto &l : earthlnk){
if(!strcmp(file+4,l.name)){
@@ -209,12 +221,28 @@ void initEverything(void){
break;
}
}
+ }else if(Indoor && !strcmp(name,"link") && wxml->Attribute("outside")){
+ for(auto &l : earthlnk){
+ if(!strcmp(l.name,wxml->Attribute("outside"))){
+ for(auto &b : l.ptr->build){
+ if(*b->inside == earth.back()){
+ ((IndoorWorld *)*b->inside)->outside = l.ptr;
+ }
+ }
+ break;
+ }
+ }
}else if(!strcmp(name,"style")){
earth.back()->setBackground((WORLD_BG_TYPE)wxml->UnsignedAttribute("background"));
earth.back()->setBGM(wxml->Attribute("bgm"));
}else if(!strcmp(name,"generation")){
if(!strcmp(wxml->Attribute("type"),"Random")){
- earth.back()->generate(wxml->UnsignedAttribute("width"));
+ if(Indoor)
+ ((IndoorWorld *)earth.back())->generate(wxml->UnsignedAttribute("width"));
+ else
+ earth.back()->generate(wxml->UnsignedAttribute("width"));
+ }else if(Indoor){
+ abort();
}
}else if(!strcmp(name,"mob")){
if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
@@ -245,10 +273,24 @@ SKIP:
npcd.push_back((NPCDialog){earth.back()->npc.back(),0});
}
}else if(!strcmp(name,"structure")){
- /*if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
- earth.back()->addStructure((getRand() % earth.back()->getTheWidth() / 2.0f,100);
+ if(wxml->Attribute("inside")){
+ for(auto &l : earthlnk){
+ if(!strcmp(l.name,wxml->Attribute("inside"))){
+ yoyo = &l.ptr;
+ break;
+ }
+ }
+ }
+ /*for(auto &l : earthlnk){
+ if(!strcmp(file+4,l.name)){
+ yoyo2 = &l.ptr;
+ break;
+ }
+ }*/
+ if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
+ earth.back()->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"),getRand() % earth.back()->getTheWidth() / 2.0f,100,yoyo);//,yoyo2);
else
- earth.back()->addNPC(wxml->FloatAttribute("x"),wxml->FloatAttribute("y"));*/
+ earth.back()->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"),spawnx,wxml->FloatAttribute("y"),yoyo);//,yoyo2);
}
wxml = wxml->NextSiblingElement();
diff --git a/src/ui.cpp b/src/ui.cpp
index 4212307..4670220 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -718,8 +718,9 @@ DONE:
//delete &tmp;
toggleBlackFast();
}
- }else
+ }else{
currentWorld=currentWorld->goInsideStructure(player);
+ }
break;
case SDLK_i:
currentWorld=currentWorld->goWorldBack(player); // Go back a layer if possible
@@ -823,19 +824,19 @@ DONE:
currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
break;
case SDLK_g:
- currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, currentWorld);
+ //currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, currentWorld);
break;
case SDLK_h:
- currentWorld->addStructure(TOWN_HALL, player->loc.x, player->loc.y, currentWorld);
+ //currentWorld->addStructure(TOWN_HALL, player->loc.x, player->loc.y, currentWorld);
break;
case SDLK_j:
- currentWorld->addStructure(FOUNTAIN, player->loc.x, player->loc.y, currentWorld);
+ //currentWorld->addStructure(FOUNTAIN, player->loc.x, player->loc.y, currentWorld);
break;
case SDLK_v:
- currentWorld->addVillage(player->loc.x, player->loc.y, 5, 10, 100, currentWorld);
+ //currentWorld->addVillage(player->loc.x, player->loc.y, 5, 10, 100, currentWorld);
break;
case SDLK_b:
- currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, currentWorld);
+ currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, NULL);
break;
case SDLK_F12:
std::cout << "Took screenshot" << std::endl;
diff --git a/src/world.cpp b/src/world.cpp
index e56720d..58606e5 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -185,8 +185,6 @@ void World::load(std::ifstream *i){
}
}
-void *NULLPTR = NULL;
-
World::World(void){
bgm = NULL;
@@ -426,11 +424,12 @@ void World::update(Player *p,unsigned int delta){
else if(e->vel.x > 0)e->left = false;
}
}
- uint oh = 0;
for(auto &pa : particles){
if(pa->kill(deltaTime)){
//delete pa;
- particles.erase(particles.begin()+oh);
+ //particles.erase(particles.begin()+oh);
+ std::cout << pa.duration;
+ std::cout << particles[oh].duration;
}else if(pa->canMove){
pa->loc.y += pa->vely * deltaTime;
pa->loc.x += pa->velx * deltaTime;
@@ -444,8 +443,8 @@ void World::update(Player *p,unsigned int delta){
}
}
}
- }oh++;
- }oh=0;
+ }
+ }
if(ui::dialogImportant){
Mix_FadeOutMusic(2000);
@@ -1049,7 +1048,7 @@ LOOOOP:
part->velx = 0;
part->canMove = false;
}else{
- if(!part->gravity && part->vely > -2)part->vely-=.003 * deltaTime;
+ if(part->gravity && part->vely > -2)part->vely-=.003 * deltaTime;
}
what++;
}what=0;
@@ -1058,22 +1057,38 @@ LOOOOP:
goto LOOOOP;
}
}
-void World::addStructure(BUILD_SUB sub, float x,float y,World *inside){
+void World::addStructure(BUILD_SUB sub, float x,float y,World **inside){//,World **outside){
build.push_back(new Structures());
build.back()->spawn(sub,x,y,this);
build.back()->inWorld=this;
- build.back()->inside = (World *)inside;
- ((IndoorWorld *)inside)->outside = this;
+ build.back()->inside = inside;
+ //std::cout<<"yo"<<std::endl;
+
+
+// void * |void ** - *|void ** | void **
+ //((IndoorWorld *)inside[0])->outside = outside;
+
+
+ //std::cout<<"yo"<<std::endl;
entity.push_back(build.back());
}
-void World::addVillage(int x, int y, int bCount, int npcMin, int npcMax,World *inside){
+void World::addVillage(int bCount, int npcMin, int npcMax,World **inside){
std::cout << npcMin << ", " << npcMax << std::endl;
- this->addStructure(TOWN_HALL, x,y, inside);
- bCount--;
- this->addStructure(LAMP_POST, x-3*HLINE,y, this);
- this->addStructure(LAMP_POST, x+53*HLINE,y, this);
+ //int xwasd;
+ for(int i = 0; i < bCount; i++){
+ addStructure(HOUSE,x_start + (i * 300),100,inside);//,(World **)&NULLPTR);
+ /*std::cout<<"1\n";
+ HERE:
+ xwasd = (rand()%(int)x+1000*HLINE);
+ for(auto &bu : build){
+ if(xwasd > bu->loc.x && xwasd < bu->loc.x+bu->width)goto HERE;
+ }
+ std::cout<<"2\n";
+ addStructure(t,HOUSE,xwasd,y,inside);
+ std::cout<<"3\n";*/
+ }
}
void World::addMob(int t,float x,float y){
mob.push_back(new Mob(t));
@@ -1189,24 +1204,25 @@ World *World::goInsideStructure(Player *p){
if(!thing.size()){
for(auto &b : build){
if(p->loc.x > b->loc.x &&
- p->loc.x + p->width < b->loc.x + b->width ){
+ p->loc.x + p->width < b->loc.x + b->width &&
+ *b->inside != this ){
thing.push_back(this);
ui::toggleBlackFast();
ui::waitForCover();
ui::toggleBlackFast();
- return (World *)b->inside;
+ return (World *)*b->inside;
}
}
}else{
for(auto &b : ((World *)thing.back())->build){
- if(b->inside == this){
- World *tmp = (World *)thing.back();
+ if(*b->inside == this){
+ //World *tmp = (World *)thing.back();
p->loc.x = b->loc.x + (b->width / 2) - (p->width / 2);
thing.erase(thing.end()-1);
ui::toggleBlackFast();
ui::waitForCover();
ui::toggleBlackFast();
- return tmp;
+ return ((IndoorWorld *)(*b->inside))->outside;
}
}
}
diff --git a/test.frag b/test.frag
index 5c9054e..07b4a8a 100644
--- a/test.frag
+++ b/test.frag
@@ -2,7 +2,7 @@
uniform sampler2D sampler;
uniform int numLight;
-uniform vec2 lightLocation[1024];
+uniform vec2 lightLocation[64];
uniform vec3 lightColor;
uniform float amb;
@@ -10,20 +10,22 @@ float b = .0005;
float minLight = .05;
float radius = sqrt(1.0 / (b * minLight));
+//float radius = b*minlight;
+
void main(){
- vec4 color = vec4(0.0f,0.0f,0.0f,0.0f);
+ vec4 color = vec4(0.0,0.0,0.0,0.0);
for(int i = 0; i < numLight; i++){
vec2 loc = lightLocation[i];
float dist = length(loc - gl_FragCoord.xy);
//float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);
float attenuation = clamp(1.0 - dist*dist/(radius*radius), 0.0, 1.0); attenuation *= attenuation;
- color += vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f);
+ color += vec4(attenuation, attenuation, attenuation, 1.0) * vec4(lightColor, 1.0);
}
vec2 coords = gl_TexCoord[0].st;
vec4 tex = texture2D(sampler, coords);
- color += vec4(amb,amb,amb,1.0f+amb);
+ color += vec4(amb,amb,amb,1.0+amb);
gl_FragColor = tex * vec4(color)*tex.a;
}
@@ -34,4 +36,4 @@ void main(){
.00008 500
.00002 1000
.00005 2000
-*/
+*/ \ No newline at end of file
diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml
index c8ea827..a9bde4f 100644
--- a/xml/playerSpawnHill1.xml
+++ b/xml/playerSpawnHill1.xml
@@ -3,13 +3,13 @@
<style background="0" bgm="assets/music/embark.wav" />
<generation type="Random" width="800" />
- <link right="playerSpawnHill2.xml" />
+ <!--<link right="playerSpawnHill2.xml" />-->
<mob type="1" />
<npc name="Ralph" hasDialog="true" />
<npc name="Johnny" hasDialog="true" />
- <structure type="6"/>
+ <structure type="5" inside="playerSpawnHill1_Building1.xml" />
</World>
diff --git a/xml/playerSpawnHill1_Building1.xml b/xml/playerSpawnHill1_Building1.xml
new file mode 100644
index 0000000..a9245e7
--- /dev/null
+++ b/xml/playerSpawnHill1_Building1.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<IndoorWorld>
+ <style background="1" bgm="assets/music/theme_jazz.wav" />
+ <generation type="Random" width="400" />
+
+ <link outside="playerSpawnHill1.xml" />
+
+</IndoorWorld>
+