aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2016-02-23 22:29:12 -0500
committerdrumsetmonkey <abelleisle@roadrunner.com>2016-02-23 22:29:12 -0500
commit8a2517c3068bb8fc7b22a01a2f75ab5537342063 (patch)
treed1a9973766afa8f09a6676155ff78908db4821ef
parentd1ee9a1b4b4d02b564b554a30314a97c1982da22 (diff)
parent0396f428411eb015f796643f9e7e38ca97f8fd42 (diff)
Merge branch 'master' of http://github.com/tcsullivan/gamedev
-rw-r--r--assets/style/classic/bg/bgFarTreeTile.pngbin9433 -> 0 bytes
-rw-r--r--assets/style/classic/bg/bgFrontTreeTile.pngbin27660 -> 0 bytes
-rw-r--r--assets/style/classic/bg/bgMidTreeTile.pngbin30605 -> 0 bytes
-rw-r--r--assets/style/classic/bg/bgWoodTile.pngbin0 -> 75181 bytes
-rw-r--r--assets/style/classic/bg/forestTileFar.pngbin0 -> 14112 bytes
-rw-r--r--assets/style/rustic/bg/bgFarTreeTile.pngbin9433 -> 0 bytes
-rw-r--r--assets/style/rustic/bg/bgFrontTreeTile.pngbin27660 -> 0 bytes
-rw-r--r--assets/style/rustic/bg/bgMidTreeTile.pngbin30605 -> 0 bytes
-rw-r--r--assets/style/rustic/bg/bgWoodTile.pngbin0 -> 75181 bytes
-rw-r--r--assets/style/rustic/bg/forestTileFar.pngbin0 -> 14112 bytes
-rw-r--r--include/common.h2
-rw-r--r--include/ui.h8
-rw-r--r--include/world.h25
-rw-r--r--main.cpp8
-rw-r--r--src/entities.cpp10
-rw-r--r--src/ui.cpp38
-rw-r--r--src/world.cpp163
-rw-r--r--xml/playerSpawnHill1.xml6
18 files changed, 201 insertions, 59 deletions
diff --git a/assets/style/classic/bg/bgFarTreeTile.png b/assets/style/classic/bg/bgFarTreeTile.png
deleted file mode 100644
index 07546a5..0000000
--- a/assets/style/classic/bg/bgFarTreeTile.png
+++ /dev/null
Binary files differ
diff --git a/assets/style/classic/bg/bgFrontTreeTile.png b/assets/style/classic/bg/bgFrontTreeTile.png
deleted file mode 100644
index 7fc7450..0000000
--- a/assets/style/classic/bg/bgFrontTreeTile.png
+++ /dev/null
Binary files differ
diff --git a/assets/style/classic/bg/bgMidTreeTile.png b/assets/style/classic/bg/bgMidTreeTile.png
deleted file mode 100644
index 126723e..0000000
--- a/assets/style/classic/bg/bgMidTreeTile.png
+++ /dev/null
Binary files differ
diff --git a/assets/style/classic/bg/bgWoodTile.png b/assets/style/classic/bg/bgWoodTile.png
new file mode 100644
index 0000000..5b631bf
--- /dev/null
+++ b/assets/style/classic/bg/bgWoodTile.png
Binary files differ
diff --git a/assets/style/classic/bg/forestTileFar.png b/assets/style/classic/bg/forestTileFar.png
new file mode 100644
index 0000000..241e479
--- /dev/null
+++ b/assets/style/classic/bg/forestTileFar.png
Binary files differ
diff --git a/assets/style/rustic/bg/bgFarTreeTile.png b/assets/style/rustic/bg/bgFarTreeTile.png
deleted file mode 100644
index 07546a5..0000000
--- a/assets/style/rustic/bg/bgFarTreeTile.png
+++ /dev/null
Binary files differ
diff --git a/assets/style/rustic/bg/bgFrontTreeTile.png b/assets/style/rustic/bg/bgFrontTreeTile.png
deleted file mode 100644
index 7fc7450..0000000
--- a/assets/style/rustic/bg/bgFrontTreeTile.png
+++ /dev/null
Binary files differ
diff --git a/assets/style/rustic/bg/bgMidTreeTile.png b/assets/style/rustic/bg/bgMidTreeTile.png
deleted file mode 100644
index 126723e..0000000
--- a/assets/style/rustic/bg/bgMidTreeTile.png
+++ /dev/null
Binary files differ
diff --git a/assets/style/rustic/bg/bgWoodTile.png b/assets/style/rustic/bg/bgWoodTile.png
new file mode 100644
index 0000000..5b631bf
--- /dev/null
+++ b/assets/style/rustic/bg/bgWoodTile.png
Binary files differ
diff --git a/assets/style/rustic/bg/forestTileFar.png b/assets/style/rustic/bg/forestTileFar.png
new file mode 100644
index 0000000..241e479
--- /dev/null
+++ b/assets/style/rustic/bg/forestTileFar.png
Binary files differ
diff --git a/include/common.h b/include/common.h
index 34260c9..a99e352 100644
--- a/include/common.h
+++ b/include/common.h
@@ -16,6 +16,8 @@
#include <string>
#include <fstream>
#include <thread>
+#include <mutex>
+#include <future>
#define GLEW_STATIC
#include <GL/glew.h>
diff --git a/include/ui.h b/include/ui.h
index 671a92c..6a81ff8 100644
--- a/include/ui.h
+++ b/include/ui.h
@@ -50,6 +50,12 @@ public:
std::vector<menuItem>items;
Menu *child;
Menu *parent;
+ ~Menu(){
+ child = NULL;
+ parent = NULL;
+ delete child;
+ delete parent;
+ }
void gotoChild();
void gotoParent();
@@ -104,6 +110,7 @@ namespace ui {
extern unsigned char dialogOptChosen;
extern bool dialogBoxExists;
extern bool dialogImportant;
+ extern bool dialogPassive;
extern unsigned int textWrapLimit;
@@ -148,6 +155,7 @@ namespace ui {
*/
void importantText(const char *text,...);
+ void passiveImportantText(int duration,const char *text,...);
/*
* Draw various UI elements (dialogBox, player health)
diff --git a/include/world.h b/include/world.h
index 48ab409..f9e952e 100644
--- a/include/world.h
+++ b/include/world.h
@@ -81,13 +81,32 @@ typedef struct line_t {
unsigned char color; /**< Lightness of dirt (brown) */
} line_t;
+/*
+ * Handle all logic that has to do with villages
+ */
+
+
+struct Village{
+ std::string name;
+ vec2 start;
+ vec2 end;
+ bool in;
+
+ std::vector<Structures *> build;
+ Village(const char *meme){
+ name = meme;
+ end.x = -0xffffffff;
+ start.x = 0xffffffff;
+ in = false;
+ }
+};
+
/**
* The world class. This class does everything a world should do.
*/
class World {
protected:
-
/**
* The line array.
* This array is created through 'new' in World::generate(), with an amount
@@ -113,6 +132,8 @@ protected:
*/
void singleDetect(Entity *e);
+
+ static void villageLogic(World *world);
/**
* Empties all entity vectors.
@@ -244,6 +265,8 @@ public:
std::vector<std::string > sTexLoc;
+ std::vector<Village>village;
+
/**
* NULLifies pointers and allocates necessary memory. This should be
diff --git a/main.cpp b/main.cpp
index 4f6e4ab..0adb0d5 100644
--- a/main.cpp
+++ b/main.cpp
@@ -231,6 +231,7 @@ int main(/*int argc, char *argv[]*/){
return -1;
}
Mix_AllocateChannels(8);
+ updateConfig();
// Run Mix_Quit when main returns
atexit(Mix_Quit);
@@ -523,7 +524,7 @@ void render(){
if(player->loc.x - SCREEN_WIDTH/2 < currentWorld->getTheWidth() * -0.5f)
offset.x = ((currentWorld->getTheWidth() * -0.5f) + SCREEN_WIDTH / 2) + player->width / 2;
if(player->loc.x + player->width + SCREEN_WIDTH/2 > currentWorld->getTheWidth() * 0.5f)
- offset.x = ((currentWorld->getTheWidth() * 0.5f) - SCREEN_WIDTH / 2);// + player->width / 2;
+ offset.x = ((currentWorld->getTheWidth() * 0.5f) - SCREEN_WIDTH / 2) - player->width / 2;
}
if(player->loc.y > SCREEN_HEIGHT/2)
@@ -569,6 +570,7 @@ void render(){
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
+ // glOrtho((offset.x-SCREEN_WIDTH/2),(offset.x+SCREEN_WIDTH/2),(offset.y-SCREEN_HEIGHT/2),(offset.y+SCREEN_HEIGHT/2),-1,1);
glOrtho(floor(offset.x-SCREEN_WIDTH/2),floor(offset.x+SCREEN_WIDTH/2),floor(offset.y-SCREEN_HEIGHT/2),floor(offset.y+SCREEN_HEIGHT/2),-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@@ -890,7 +892,7 @@ void logic(){
}
}
}
- for(auto &b : currentWorld->build){
+ /*for(auto &b : currentWorld->build){
switch(b->bsubtype){
case FOUNTAIN:
for(int r = 0; r < (rand()%25)+10;r++){
@@ -915,7 +917,7 @@ void logic(){
break;
default: break;
}
- }
+ }*/
/*
* Switch between day and night (SUNNY and DARK) if necessary.
diff --git a/src/entities.cpp b/src/entities.cpp
index 8c19bb0..6c2da81 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 0b1af33..971325c 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){
@@ -341,8 +328,7 @@ void World::update(Player *p,unsigned int delta){
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;
}
}
@@ -489,10 +475,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]);
@@ -590,8 +576,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.
*/
@@ -735,7 +720,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.
@@ -960,15 +944,17 @@ void World::detect(Player *p){
* 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.
*/
+//LOOOOP:
for(auto &e : entity)
- singleDetect(e);
-
+ std::thread(&World::singleDetect,this,e).detach();
+ //hey->singleDetect(e);
for(auto &part : particles){
int l;
unsigned int i;
@@ -985,7 +971,50 @@ void World::detect(Player *p){
if(part->gravity && part->vely > -2)part->vely-=.003 * deltaTime;
}
}
+ 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;
@@ -1128,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 +1514,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;
@@ -1502,6 +1532,7 @@ World *loadWorldFromXMLNoSave(const char *path){
xml.LoadFile(currentXML);
wxml = xml.FirstChildElement("World");
+ vil = xml.FirstChildElement("World")->FirstChildElement("village");
if(wxml){
wxml = wxml->FirstChildElement();
@@ -1515,7 +1546,6 @@ World *loadWorldFromXMLNoSave(const char *path){
while(wxml){
name = wxml->Name();
-
if(!strcmp(name,"link")){
if((ptr = wxml->Attribute("left")))
tmp->setToLeft(ptr);
@@ -1580,9 +1610,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()){
diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml
index 0c0fe4c..269b393 100644
--- a/xml/playerSpawnHill1.xml
+++ b/xml/playerSpawnHill1.xml
@@ -10,7 +10,11 @@
<npc name="Ralph" hasDialog="true" />
<npc name="Johnny" hasDialog="false" />
- <structure type="5" inside="playerSpawnHill1_Building1.xml" />
+ <!-- <structure type="5" inside="playerSpawnHill1_Building1.xml" /> -->
+ <village name="Meme-Town">
+ <structure type="0" x="-100" inside="playerSpawnHill1_Building1.xml"/>
+ <structure type="5" x="-500" inside="playerSpawnHill1_Building1.xml"/>
+ </village>
</World>