aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/entities.cpp10
-rw-r--r--src/ui.cpp38
-rw-r--r--src/world.cpp165
3 files changed, 156 insertions, 57 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index 71a0890..922a07c 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -62,7 +62,7 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o
right = true;
left = false;
near = false;
- canMove = true;
+ //canMove = true;
ground = false;
hit = false;
@@ -88,6 +88,8 @@ Player::Player(){ //sets all of the player specific traits on object creation
subtype = 0;
health = maxHealth = 100;
speed = 1;
+ canMove = true;
+
tex = new Texturec(9, "assets/player/playerk.png",
"assets/player/playerk1.png",
"assets/player/playerk2.png",
@@ -115,6 +117,7 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation
health = maxHealth = 100;
maxHealth = health = 100;
+ canMove = true;
tex = new Texturec(1,"assets/NPC.png");
inv = new Inventory(NPC_INV_SIZE);
@@ -141,6 +144,7 @@ Structures::Structures(){ //sets the structure type
name = NULL;
inv = NULL;
+ canMove = false;
}
Structures::~Structures(){
delete tex;
@@ -155,6 +159,7 @@ Mob::Mob(int sub){
aggressive = false;
maxHealth = health = 50;
+ canMove = true;
switch((subtype = sub)){
case MS_RABBIT:
@@ -198,6 +203,7 @@ Object::Object(){
near = false;
width = 0;
height = 0;
+ canMove = false;
maxHealth = health = 1;
@@ -267,7 +273,7 @@ void Entity::draw(void){ //draws the entities
switch(type){
case PLAYERT:
static int texState = 0;
- if(speed && !(loops % (int)(2.0f/(float)speed))){
+ if(speed && !(loops % ((2.0f/speed) < 1 ? 1 : (int)((float)2.0f/(float)speed)))){
if(++texState==9)texState=1;
glActiveTexture(GL_TEXTURE0);
tex->bind(texState);
diff --git a/src/ui.cpp b/src/ui.cpp
index 2d00453..6e616a7 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -52,7 +52,6 @@ static char dialogBoxText[512];
static char *dialogOptText[4];
static float dialogOptLoc[4][3];
static unsigned char dialogOptCount = 0;
-static bool dialogPassive = false;
static bool typeOutDone = true;
extern Menu* currentMenu;
@@ -114,6 +113,9 @@ namespace ui {
bool debug=false;
bool posFlag=false;
+ bool dialogPassive = false;
+ int dialogPassiveTime = 0;
+
/*
* Dialog stuff that needs to be 'public'.
@@ -544,6 +546,24 @@ namespace ui {
dialogImportant = true;
//toggleBlack();
}
+ void passiveImportantText(int duration, const char *text,...){
+ va_list textArgs;
+
+ //if(!player->ground)return;
+
+ memset(dialogBoxText,0,512);
+
+ va_start(textArgs,text);
+ vsnprintf(dialogBoxText,512,text,textArgs);
+ va_end(textArgs);
+
+ dialogBoxExists = true;
+ dialogImportant = true;
+ dialogPassive = true;
+ dialogPassiveTime = duration;
+ }
+
+
void draw(void){
unsigned char i;
float x,y,tmp;
@@ -555,9 +575,18 @@ namespace ui {
if(dialogImportant){
setFontColor(255,255,255);
- if(fadeIntensity == 255){
+ if(dialogPassive){
+ dialogPassiveTime -= deltaTime;
+ if(dialogPassiveTime < 0){
+ dialogPassive = false;
+ dialogImportant = false;
+ dialogBoxExists = false;
+ }
+ }
+ if(fadeIntensity == 255 || dialogPassive){
setFontSize(24);
putStringCentered(offset.x,offset.y,rtext);
+ setFontSize(16);
}
}else{
@@ -602,7 +631,7 @@ namespace ui {
Mix_PlayChannel(1,dialogClick,0);
}
- }else if(!dialogImportant && !fadeIntensity){
+ }if(!fadeIntensity){
vec2 hub = {
(SCREEN_WIDTH/2+offset.x)-fontSize*10,
(offset.y+SCREEN_HEIGHT/2)-fontSize
@@ -644,6 +673,9 @@ namespace ui {
}
void quitGame(){
+ dialogBoxExists = false;
+ currentMenu = NULL;
+ delete[] currentMenu;
gameRunning = false;
updateConfig();
saveConfig();
diff --git a/src/world.cpp b/src/world.cpp
index 51efaf2..6e72328 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -17,39 +17,25 @@ bool worldInside = false; // True if player is inside a structure
WEATHER weather = SUNNY;
-// const char *bgPaths[2][7]={
-// {"assets/bg.png", // Daytime background
-// "assets/bgn.png", // Nighttime background
-// "assets/bgFarMountain.png", // Furthest layer
-// "assets/forestTileBack.png", // Closer layer
-// "assets/forestTileMid.png", // Near layer
-// "assets/forestTileFront.png", // Closest layer
-// "assets/dirt.png"}, // Dirt
-// {"assets/bgWoodTile.png",
-// NULL,
-// NULL,
-// NULL,
-// NULL,
-// NULL}
-// };
-
-const std::string bgPaths[2][8]={
- {"bg.png", // Daytime background
- "bgn.png", // Nighttime background
- "bgFarMountain.png", // Furthest layer
- "forestTileBack.png", // Closer layer
- "forestTileMid.png", // Near layer
- "forestTileFront.png", // Closest layer
- "dirt.png", // Dirt
- "grass.png"}, // Grass
- {"bgWoodTile.png",
- "bgWoodTile.png",
- "bgWoodTile.png",
- "bgWoodTile.png",
- "bgWoodTile.png",
- "bgWoodTile.png",
- "bgWoodTile.png",
- "bgWoodTile.png"}
+
+const std::string bgPaths[2][9]={
+ {"bg.png", // Daytime background
+ "bgn.png", // Nighttime background
+ "bgFarMountain.png", // Furthest layer
+ "forestTileFar.png", // Furthest away Tree Layer
+ "forestTileBack.png", // Closer layer
+ "forestTileMid.png", // Near layer
+ "forestTileFront.png", // Closest layer
+ "dirt.png", // Dirt
+ "grass.png"}, // Grass
+ {"bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png"}
};
const std::string buildPaths[] = { "townhall.png",
@@ -61,10 +47,11 @@ const std::string buildPaths[] = { "townhall.png",
"lampPost1.png",
"brazzier.png"};
-const float bgDraw[3][3]={
+const float bgDraw[4][3]={
{100,240,.6 },
{150,250,.4 },
- {255,255,.25}
+ {200,255,.25},
+ {255,255,.1}
};
float worldGetYBase(World *w){
@@ -95,18 +82,18 @@ void World::setStyle(const char* pre){
for(uint i = 0; i < arrAmt(buildPaths);i++){
sTexLoc.push_back(prefix);
sTexLoc.back() += buildPaths[i];
- std::cout << sTexLoc.back() << std::endl;
+ //std::cout << sTexLoc.back() << std::endl;
}
prefix += "bg/";
for(uint i = 0; i < arrAmt(bgPaths[0]);i++){
bgFiles.push_back(prefix);
bgFiles.back() += bgPaths[0][i];
- std::cout << bgFiles.back() << std::endl;
+ //std::cout << bgFiles.back() << std::endl;
}
for(uint i = 0; i < arrAmt(bgPaths[1]);i++){
bgFilesIndoors.push_back(prefix);
bgFilesIndoors.back() += bgPaths[1][i];
- std::cout << bgFilesIndoors.back() << std::endl;
+ //std::cout << bgFilesIndoors.back() << std::endl;
}
}
@@ -339,7 +326,7 @@ void World::update(Player *p,unsigned int delta){
if(e->type != STRUCTURET && e->canMove){
e->loc.x += e->vel.x * delta;
if(e->vel.x < 0)e->left = true;
- else if(e->vel.x > 0)e->left = false;
+ else if(e->vel.x > 0)e->left = false;
}
}
@@ -486,10 +473,10 @@ void World::draw(Player *p){
glEnd();
/*
- * Draw three layers of trees.
+ * Draw four layers of trees.
*/
- for(i = 0; i < 3; i++){
+ for(i = 0; i < 4; i++){
bgTex->bindNext();
safeSetColorA(bgDraw[i][0]-bgshade,bgDraw[i][0]-bgshade,bgDraw[i][0]-bgshade,bgDraw[i][1]);
@@ -587,8 +574,7 @@ void World::draw(Player *p){
}
for(auto &b : current->build){
b->draw();
- }
-
+ }
/*
* Draw the layer up until the grass portion, which is done later.
*/
@@ -732,7 +718,6 @@ void World::draw(Player *p){
o->loc.y-=(yoff-DRAW_Y_OFFSET);
}
}
-
/*
* If we're drawing the closest/last world, handle and draw the player.
@@ -952,13 +937,13 @@ void World::singleDetect(Entity *e){
}
void World::detect(Player *p){
- World *hey = this;
/*
* Handle the player.
*/
- singleDetect(p);
+ //auto pl = std::async(&World::singleDetect,this,p);
+ std::thread(&World::singleDetect,this, p).detach();
/*
* Handle all remaining entities in this world.
@@ -966,8 +951,9 @@ void World::detect(Player *p){
//LOOOOP:
static int what = 0;
- for(auto &e : hey->entity)
- hey->singleDetect(e);
+ for(auto &e : entity)
+ std::thread(&World::singleDetect,this,e).detach();
+ //hey->singleDetect(e);
for(auto &part : particles){
int l;
unsigned int i;
@@ -985,11 +971,50 @@ void World::detect(Player *p){
}
what++;
}what=0;
+ for(auto &b : build){
+ switch(b->bsubtype){
+ case FOUNTAIN:
+ for(int r = 0; r < (rand()%25)+10;r++){
+ addParticle( rand()%HLINE*3 + b->loc.x + b->width/2,
+ b->loc.y + b->height,
+ HLINE*1.25,
+ HLINE*1.25,
+ rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01,
+ ((4+rand()%6)*.05),
+ {0,0,255},
+ 2500);
+
+ particles.back()->fountain = true;
+ }
+ break;
+ case FIRE_PIT:
+ for(int r = 0; r < (rand()%20)+10;r++){
+ addParticle(rand()%(int)(b->width/2) + b->loc.x+b->width/4, b->loc.y+3*HLINE, HLINE, HLINE, rand()%2 == 0?-(rand()%3)*.01:(rand()%3)*.01,((4+rand()%6)*.005), {255,0,0}, 400);
+ particles.back()->gravity = false;
+ particles.back()->behind = true;
+ }
+ break;
+ default: break;
+ }
+ }
+
+ for(auto &v : village){
+ if(p->loc.x > v.start.x && p->loc.x < v.end.x){
+ if(!v.in){
+ ui::passiveImportantText(5000,"Welcome to %s",v.name.c_str());
+ v.in = true;
+ }
+ }else{
+ v.in = false;
+ }
+ }
+
/*if(hey->infront){
hey = hey->infront;
goto LOOOOP;
}*/
}
+
void World::addStructure(BUILD_SUB sub, float x,float y, char *tex, const char *inside){
build.push_back(new Structures());
build.back()->inWorld = this;
@@ -1132,7 +1157,7 @@ World *World::goWorldRight(Player *p){
if(toRight && p->loc.x + p->width > -x_start - HLINE * 15){
tmp = loadWorldFromXML(toRight);
- p->loc.x = tmp->x_start + HLINE * 10;
+ p->loc.x = tmp->x_start + (int)HLINE * 10;
p->loc.y = tmp->line[0].y;
return tmp;
@@ -1485,9 +1510,10 @@ World *loadWorldFromXML(const char *path){
World *loadWorldFromXMLNoSave(const char *path){
XMLDocument xml;
XMLElement *wxml;
+ XMLElement *vil;
World *tmp;
- float spawnx;
+ float spawnx, randx;
bool dialog,Indoor;
const char *ptr,*name;
@@ -1500,6 +1526,7 @@ World *loadWorldFromXMLNoSave(const char *path){
xml.LoadFile(currentXML);
wxml = xml.FirstChildElement("World");
+ vil = xml.FirstChildElement("World")->FirstChildElement("village");
if(wxml){
wxml = wxml->FirstChildElement();
@@ -1513,7 +1540,6 @@ World *loadWorldFromXMLNoSave(const char *path){
while(wxml){
name = wxml->Name();
-
if(!strcmp(name,"link")){
if((ptr = wxml->Attribute("left")))
tmp->setToLeft(ptr);
@@ -1578,9 +1604,44 @@ World *loadWorldFromXMLNoSave(const char *path){
tmp->addMob(MS_TRIGGER,wxml->FloatAttribute("x"),0,commonTriggerFunc);
tmp->mob.back()->heyid = wxml->Attribute("id");
}
-
+
wxml = wxml->NextSiblingElement();
}
+
+ if(vil){
+ tmp->village.push_back(vil->Attribute("name"));
+
+ vil = vil->FirstChildElement();
+ }
+
+ while(vil){
+ name = vil->Name();
+ randx = getRand() % tmp->getTheWidth() - (tmp->getTheWidth() / 2.0f);
+
+ /**
+ * READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE
+ */
+ if(!strcmp(name,"structure")){
+ ptr = vil->Attribute("inside");
+ tmp->addStructure((BUILD_SUB)vil->UnsignedAttribute("type"),
+ vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ?
+ randx : spawnx,
+ 100,
+ (char*)vil->Attribute("texture"),
+ ptr);
+
+ tmp->village.back().build.push_back(tmp->build.back());
+ }
+ if(tmp->village.back().build.back()->loc.x < tmp->village.back().start.x){
+ tmp->village.back().start.x = tmp->village.back().build.back()->loc.x;
+ }
+ if(tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width > tmp->village.back().end.x){
+ tmp->village.back().end.x = tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width;
+ }
+
+ //go to the next element in the village block
+ vil = vil->NextSiblingElement();
+ }
std::ifstream dat (((std::string)currentXML + ".dat").c_str());
if(dat.good()){