aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--assets/style/classic/stallFruit.pngbin0 -> 641 bytes
-rw-r--r--include/common.h25
-rw-r--r--include/entities.h1
-rw-r--r--include/inventory.h14
-rw-r--r--include/ui.h6
-rw-r--r--include/world.h1
-rw-r--r--main.cpp19
-rw-r--r--src/entities.cpp90
-rw-r--r--src/gameplay.cpp122
-rw-r--r--src/inventory.cpp292
-rw-r--r--src/ui.cpp92
-rw-r--r--src/world.cpp29
12 files changed, 474 insertions, 217 deletions
diff --git a/assets/style/classic/stallFruit.png b/assets/style/classic/stallFruit.png
new file mode 100644
index 0000000..d9378d7
--- /dev/null
+++ b/assets/style/classic/stallFruit.png
Binary files differ
diff --git a/include/common.h b/include/common.h
index 58d561f..6f453b0 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1,6 +1,6 @@
/** @file common.h
* @brief Common items needed by most other files.
- *
+ *
* This file contains headers, variables and functions that are needed in
* most other files included in this project.
*/
@@ -14,12 +14,13 @@
#include <string>
#include <vector>
#include <string>
-#include <fstream>
+#include <fstream>
#include <thread>
#include <mutex>
#include <future>
#include <math.h>
#include <threadpool.h>
+#include <algorithm>
#define GLEW_STATIC
#include <GL/glew.h>
@@ -48,6 +49,17 @@ N abso(N v){
return v;
}
+template<class A>
+float averagef(A v){
+ float avg = 0;
+ for(auto &a : v){
+ avg += a;
+ }
+ avg /= v.size();
+ return avg;
+}
+
+
extern GLuint colorIndex; // Texture.cpp?
/**
@@ -130,7 +142,7 @@ extern std::mutex mtx;
* definition was made. Every item being drawn to the screen and most object detection/physic
* handling is done based off of this number. Increasing it will give the game a zoomed-in
* feel, while decreasing it will do the opposite.
- *
+ *
*/
extern unsigned int HLINE;
@@ -159,7 +171,7 @@ extern float VOLUME_SFX;
* Included in common.h is a prototype for DEBUG_prints, which writes a formatted
* string to the console containing the callee's file and line number. This macro simplifies
* it to a simple printf call.
- *
+ *
* DEBUG must be defined for this macro to function.
*/
@@ -181,7 +193,7 @@ extern unsigned int deltaTime;
/**
* References the variable in main.cpp, used for drawing with the player.
*/
-
+
extern vec2 offset;
/**
@@ -211,11 +223,12 @@ void safeSetColor(int r,int g,int b);
void safeSetColorA(int r,int g,int b,int a);
+
/**
* We've encountered many problems when attempting to create delays for triggering
* the logic function. As a result, we decided on using the timing libraries given
* by <chrono> in the standard C++ library. This function simply returns the amount
- * of milliseconds that have passed sine the epoch.
+ * of milliseconds that have passed since the epoch.
*/
#ifdef __WIN32__
diff --git a/include/entities.h b/include/entities.h
index ef421f5..450975f 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -219,6 +219,7 @@ public:
class Merchant : public NPC{
public:
std::vector<Trade>trade;
+ uint currTrade;
void interact();
diff --git a/include/inventory.h b/include/inventory.h
index 69cf073..7369642 100644
--- a/include/inventory.h
+++ b/include/inventory.h
@@ -11,11 +11,11 @@
class Item{
public:
std::string name,type;
-
+
float width;
float height;
int maxStackSize;
-
+
std::string texloc;
Texturec *tex;
@@ -45,16 +45,18 @@ public:
Inventory(unsigned int s); // Creates an inventory of size 's'
~Inventory(void); // Free's allocated memory
-
+
int addItem(std::string name,uint count);
int takeItem(std::string name,uint count);
int hasItem(std::string name);
-
+
int useItem(void);
bool detectCollision(vec2,vec2);
-
+
void setSelection(unsigned int s);
-
+ void setSelectionUp();
+ void setSelectionDown();
+
void draw(void); // Draws a text list of items in this inventory (should only be called for the player for now)
};
diff --git a/include/ui.h b/include/ui.h
index 072d418..2a7518f 100644
--- a/include/ui.h
+++ b/include/ui.h
@@ -6,6 +6,7 @@
#define UI_H
#include <common.h>
+#include <inventory.h>
#include <cstdarg>
#include <config.h>
@@ -106,11 +107,13 @@ namespace ui {
extern bool posFlag;
extern unsigned char dialogOptChosen;
+ extern unsigned char merchOptChosen;
extern bool dialogBoxExists;
extern bool dialogImportant;
extern bool dialogPassive;
extern unsigned int textWrapLimit;
+ extern int fontTransInv;
/*
* Initializes the FreeType system.
@@ -126,6 +129,7 @@ namespace ui {
void setFontFace(const char *ttf);
void setFontSize(unsigned int size);
+ void setFontColor(unsigned char r,unsigned char g,unsigned char b, unsigned char a);
/*
* Draw a centered string.
@@ -148,10 +152,10 @@ namespace ui {
void dialogBox(const char *name,const char *opt,bool passive,const char *text,...);
void merchantBox(const char *name,Trade trade,const char *opt,bool passive,const char *text,...);
void merchantBox();
+ void closeBox();
void waitForDialog(void);
void drawPage( std::string path );
-
/*
* Draws a larger string in the center of the screen. Drawing is done inside this function.
*/
diff --git a/include/world.h b/include/world.h
index 553cd8d..a2469ff 100644
--- a/include/world.h
+++ b/include/world.h
@@ -53,6 +53,7 @@ enum class WorldWeather : unsigned char {
typedef struct {
vec2 loc; /**< Light location */
Color color; /**< Light color */
+ float radius;
} Light;
/**
diff --git a/main.cpp b/main.cpp
index 69aab76..e7494a9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -415,9 +415,8 @@ int main(int argc, char *argv[]){
//currentWorld->mob.back()->followee = player;
gameRunning = true;
-
- while ( gameRunning )
- mainLoop();
+
+ while(gameRunning)mainLoop();
/**************************
**** CLOSE PROGRAM ****
@@ -492,6 +491,13 @@ void mainLoop(void){
prevPrevTime = currentTime;
}
+ /*
+ * Update player and entity coordinates.
+ */
+
+ /*pool.Enqueue([](){
+ currentWorld->update(player,deltaTime);
+ });*/
currentWorld->update( player, deltaTime );
/*
@@ -770,9 +776,9 @@ void logic(){
if(n->canMove)
n->wander((rand() % 120 + 30));
- /*if(!player->inv->usingi) n->hit = false;
+ if(!player->inv->usingi) n->hit = false;
- if(player->inv->usingi && !n->hit && player->inv->detectCollision((vec2){n->loc.x, n->loc.y},(vec2){n->loc.x+n->width,n->loc.y+n->height})){
+ if(player->inv->usingi && !n->hit && player->inv->detectCollision({n->loc.x, n->loc.y},{n->loc.x+n->width,n->loc.y+n->height})){
n->health -= 25;
n->hit = true;
for(int r = 0; r < (rand()%5);r++)
@@ -781,8 +787,7 @@ void logic(){
for(int r = 0; r < (rand()%30)+15;r++)
currentWorld->addParticle(rand()%HLINE*3 + n->loc.x - .05f,n->loc.y + n->height*.5, HLINE,HLINE, -(rand()%10)*.01,((rand()%10)*.01-.05), {(rand()%75)+10/100.0f,0,0}, 10000);
}
- }*/
-
+ }
/*
* Don't bother handling the NPC if another has already been handled.
*/
diff --git a/src/entities.cpp b/src/entities.cpp
index 7d906ea..c047eff 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -169,6 +169,7 @@ Merchant::Merchant(){ //sets all of the Merchant specific traits on object creat
canMove = true;
trade.reserve(100);
+ currTrade = 0;
//tex = new Texturec(1,"assets/NPC.png");
//inv = new Inventory(NPC_INV_SIZE);
@@ -433,50 +434,68 @@ void NPC::clearAIFunc(void){
}
void NPC::interact(){ //have the npc's interact back to the player
- int (*func)(NPC *);
- loc.y += 5;
-
- canMove=false;
- left = (player->loc.x < loc.x);
- right = !left;
-
- if(aiFunc.size()){
- func=aiFunc.front();
+ std::thread([this]{
+ int (*func)(NPC *);
+ loc.y += 5;
+
+ canMove=false;
+ left = (player->loc.x < loc.x);
+ right = !left;
- if(!func(this)){
- if(aiFunc.size())aiFunc.erase(aiFunc.begin());
+ if(aiFunc.size()){
+ func=aiFunc.front();
+
+ if(!func(this)){
+ if(aiFunc.size())aiFunc.erase(aiFunc.begin());
+ }
+ }else{
+ ui::dialogBox(name,NULL,false,randomDialog[randDialog]);
}
- }else{
- ui::dialogBox(name,NULL,false,randomDialog[randDialog]);
- }
- ui::waitForDialog();
- canMove=true;
+ ui::waitForDialog();
+ canMove=true;
+ }).detach();
}
void Merchant::interact(){
- ui::merchantBox(name, trade.back(), ":Accept:Good-Bye", false, "Welcome to Smithy\'s. Buy your sausages here you freaking meme lording screw-face");
- ui::waitForDialog();
- if(ui::dialogOptChosen == 1){
- std::cout << "Gimme ye' munny" << std::endl;
- if(player->inv->takeItem(trade.back().item[1],trade.back().quantity[1]) >= 0)
- player->inv->addItem(trade.back().item[0],trade.back().quantity[0]);
- }else{
- std::cout << "See ye!" << std::endl;
- }
+ std::thread([this]{
+ ui::merchantBox(name, trade[currTrade], ":Accept:Good-Bye", false, "Welcome to Smithy\'s. Buy your sausages here you freaking meme lording screw-face");
+ ui::waitForDialog();
+ if(ui::dialogOptChosen == 1){
+ std::cout << "Gimme ye' munny" << std::endl;
+ if(!(player->inv->takeItem(trade[currTrade].item[1],trade[currTrade].quantity[1])))
+ player->inv->addItem(trade[currTrade].item[0],trade[currTrade].quantity[0]);
+ }else if(ui::dialogOptChosen == 2){
+ std::cout << "See ye!" << std::endl;
+ }else if(ui::merchOptChosen == 1){
+ if(currTrade != 0){
+ currTrade--;
+ std::cout << "Last trade" << std::endl;
+ interact();
+ }
+ }else if(ui::merchOptChosen == 2){
+ if(currTrade < trade.size()){
+ currTrade++;
+ std::cout << "Next trade" << std::endl;
+ interact();
+ }
+ }
+ }).detach();
}
void Object::interact(void){
- if(questObject && alive){
- ui::dialogBox( player->name, ":Yes:No", false, pickupDialog.c_str());
- ui::waitForDialog();
- if(ui::dialogOptChosen == 1){
- player->inv->addItem( iname, 1 );
+ std::thread([this]{
+ if(questObject && alive){
+ ui::dialogBox( player->name, ":Yes:No", false, pickupDialog.c_str());
+ ui::waitForDialog();
+ if(ui::dialogOptChosen == 1){
+ player->inv->addItem( iname, 1 );
+ alive = false;
+ }
+ }else{
alive = false;
+ player->inv->addItem(iname, 1);
}
- }else{
- alive = false;
- player->inv->addItem(iname, 1);
- }
+ }).detach();
}
void Entity::
@@ -603,7 +622,8 @@ void Mob::wander(int timeRun){
case MS_TRIGGER:
if(player->loc.x + player->width / 2 > loc.x &&
player->loc.x + player->width / 2 < loc.x + width )
- hey(this);
+ std::thread([this]{hey(this);}).detach();
+ //hey(this);
break;
case MS_PAGE:
if(player->loc.x > loc.x - 100 &&
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 7155678..075aec3 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -29,33 +29,33 @@ inline void segFault() {
int commonAIFunc(NPC *speaker){
XMLDocument xml;
XMLElement *exml,*oxml;
-
+
static unsigned int oldidx = 9999;
-
+
const char *name;
unsigned int idx = 0;
bool stop = false;
-
+
/*
* Load the current world's XML file into memory for reading.
*/
-
+
xml.LoadFile(currentXML.c_str());
exml = xml.FirstChildElement("Dialog");
-
+
/*
* Search for the correct dialog block.
*/
-
+
while(strcmp(exml->Attribute("name"),speaker->name))
exml = exml->NextSiblingElement();
-
+
exml = exml->FirstChildElement();
-
+
/*
* Search for which text block should be used.
*/
-
+
do{
if(!strcmp(exml->Name(),"text")){
if(exml->UnsignedAttribute("id") == (unsigned)speaker->dialogIndex){
@@ -63,10 +63,10 @@ int commonAIFunc(NPC *speaker){
/*
* Handle any quest tags
*/
-
+
if((oxml = exml->FirstChildElement("quest"))){
std::string qname;
-
+
while ( oxml ) {
if ( !(qname = oxml->StrAttribute("assign")).empty() )
player->qh.assign(qname,"None",(std::string)oxml->GetText());
@@ -78,8 +78,8 @@ int commonAIFunc(NPC *speaker){
speaker->dialogIndex = oxml->UnsignedAttribute("fail");
return commonAIFunc(speaker);
}
- }
-
+ }
+
oxml = oxml->NextSiblingElement();
}
}
@@ -89,68 +89,68 @@ CONT:
/*
* Handle any 'give' requests.
*/
-
+
if((oxml = exml->FirstChildElement("give"))){
while(oxml){
player->inv->addItem(oxml->Attribute("id"),oxml->UnsignedAttribute("count"));
oxml = oxml->NextSiblingElement();
}
}
-
+
/*
* Handle any 'take' requests.
*/
-
+
if((oxml = exml->FirstChildElement("take"))){
while(oxml){
player->inv->takeItem(oxml->Attribute("id"),oxml->UnsignedAttribute("count"));
oxml = oxml->NextSiblingElement();
}
}
-
+
/*
* Handle dialog options.
*/
-
+
if((oxml = exml->FirstChildElement("option"))){
-
+
/*
* Convert the list of options into a single colon-separated string.
*/
-
+
std::string optstr;
while(oxml){
-
+
/*
* Create a buffer big enough for the next option.
*/
-
+
optstr.append((std::string)":" + oxml->Attribute("text"));
-
+
/*
* Append the next option.
*/
-
+
dopt.push_back(oxml);
-
+
oxml = oxml->NextSiblingElement();
}
-
+
/*
* Get the player's choice, then set the XMLElement to the option's block.
*/
-
+
ui::dialogBox(speaker->name,optstr.c_str(),false,exml->GetText()+1);
ui::waitForDialog();
-
+
if(ui::dialogOptChosen)
exml = dopt[ui::dialogOptChosen-1];
-
+
while(!dopt.empty())
dopt.pop_back();
}else{
-
+
/*
* No options - simply print the text.
*/
@@ -158,11 +158,11 @@ CONT:
ui::dialogBox(speaker->name,NULL,false,exml->GetText());
ui::waitForDialog();
}
-
+
/*
* Give another NPC dialog if requested.
*/
-
+
if((name = exml->Attribute("call"))){
for(auto &n : currentWorld->npc){
if(!strcmp(n->name,name)){
@@ -173,14 +173,14 @@ CONT:
}
}
}
-
+
/*
* Handle the next dialog block if this one leads to another.
*/
-
+
if(exml->QueryUnsignedAttribute("nextid",&idx) == XML_NO_ERROR){
speaker->dialogIndex = idx;
-
+
if(exml->QueryBoolAttribute("stop",&stop) == XML_NO_ERROR && stop){
speaker->dialogIndex = 9999;
return 0;
@@ -201,11 +201,11 @@ CONT:
//return 1;
}
}
-
+
exml = exml->NextSiblingElement();
-
+
}while(exml);
-
+
return 0;
}
@@ -228,37 +228,37 @@ void commonTriggerFunc(Mob *callee){
static bool lock = false;
XMLDocument xml;
XMLElement *exml;
-
- char *text,*pch;
+
+ char *text,*pch;
if(!lock){
lock = true;
-
+
xml.LoadFile(currentXML.c_str());
exml = xml.FirstChildElement("Trigger");
-
+
while(strcmp(exml->Attribute("id"),callee->heyid.c_str()))
exml = exml->NextSiblingElement();
-
+
player->vel.x = 0;
ui::toggleBlackFast();
ui::waitForCover();
-
+
text = new char[256];
strcpy(text,exml->GetText());
pch = strtok(text,"\n");
-
+
while(pch){
ui::importantText(pch);
ui::waitForDialog();
-
+
pch = strtok(NULL,"\n");
}
-
+
delete[] text;
-
+
ui::toggleBlackFast();
-
+
callee->alive = false;
lock = false;
}
@@ -267,38 +267,38 @@ void commonTriggerFunc(Mob *callee){
void initEverything(void){
std::vector<std::string> xmlFiles;
XMLDocument xml;
-
+
/*
* Read the XML directory into an array.
*/
-
+
if(getdir("./xml/",xmlFiles)){
std::cout<<"Error reading XML files!!!1"<<std::endl;
abort();
}
-
+
/*
* Sort the files alphabetically.
*/
-
+
strVectorSortAlpha(&xmlFiles);
-
+
/*
* Load the first file found as currentWorld.
*/
-
+
for(unsigned int i=0;i<xmlFiles.size();i++){
if(xmlFiles[i] != "." && xmlFiles[i] != ".." && strcmp(xmlFiles[i].c_str()+xmlFiles[i].size()-3,"dat")){
-
+
/*
* Read in the XML file.
*/
-
+
currentWorld = loadWorldFromXML(xmlFiles[i]);
break;
}
}
-
+
pauseMenu.items.push_back(ui::createParentButton({-256/2,0},{256,75},{0.0f,0.0f,0.0f}, "Resume"));
pauseMenu.items.push_back(ui::createChildButton({-256/2,-100},{256,75},{0.0f,0.0f,0.0f}, "Options"));
pauseMenu.items.push_back(ui::createButton({-256/2,-200},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", ui::quitGame));
@@ -313,7 +313,7 @@ void initEverything(void){
optionsMenu.child = NULL;
optionsMenu.parent = &pauseMenu;
// optionsMenu.push_back(ui::createButton({-256/2,-200},{256,75},{0.0f,0.0f,0.0f}, (const char*)("Save and Quit"), );
-
+
/*
* Spawn the player and begin the game.
*/
@@ -327,9 +327,9 @@ void initEverything(void){
void destroyEverything(void){
currentWorld->save();
- delete currentWorld;
+ //delete currentWorld;
//delete[] currentXML;
-
+
while(!AIpreload.empty())
AIpreload.pop_back();
while(!AIpreaddr.empty())
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 795fb55..7ba5909 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -11,6 +11,7 @@ static float hangle = 0.0f;
static bool swing = false;
//static float xc,yc;
static vec2 itemLoc;
+static const unsigned char numSlot = 7;
Mix_Chunk* swordSwing;
static std::vector<Item *> itemMap;
@@ -23,18 +24,18 @@ void items(void){
xml.LoadFile("config/items.xml");
exml = xml.FirstChildElement("item");
while(exml){
-
+
itemMap.push_back(new Item());
itemMap.back()->width = exml->FloatAttribute("width") * HLINE;
itemMap.back()->height = exml->FloatAttribute("height") * HLINE;
itemMap.back()->maxStackSize = exml->UnsignedAttribute("maxstack");
-
+
itemMap.back()->name = exml->Attribute("name");
itemMap.back()->type = exml->Attribute("type");
itemMap.back()->texloc = exml->Attribute("sprite");
exml = exml->NextSiblingElement();
- }
+ }
}
int Inventory::addItem(std::string name,uint count){
@@ -55,25 +56,25 @@ int Inventory::addItem(std::string name,uint count){
int Inventory::takeItem(std::string name,uint count){
unsigned int id = 999999;
-
+
/*
* Name to ID lookup
*/
-
+
for(unsigned int i=0;i<itemMap.size();i++){
if(itemMap[i]->name == name){
id = i;
break;
}
}
-
+
if(id == 999999)
return -1; //if no such item exists
-
+
/*
* Inventory lookup
*/
-
+
for(unsigned int i=0;i<items.size();i++){
if(items[i].id == id){
if(count > items[i].count)
@@ -98,7 +99,7 @@ int Inventory::hasItem(std::string name){
break;
}
}
-
+
if(id == 999999)
return 0;
@@ -106,15 +107,15 @@ int Inventory::hasItem(std::string name){
if(i.id == id)
return i.count;
}
-
+
return 0;
}
void initInventorySprites(void){
-
+
items();
itemtex = new GLuint[itemMap.size()];
-
+
for(unsigned int i = 0;i<itemMap.size();i++){
itemtex[i] = Texture::loadTexture(getItemTexturePath(itemMap[i]->name));
}
@@ -124,12 +125,12 @@ void initInventorySprites(void){
}
void destroyInventory(void){
-
+
while(!itemMap.empty()){
delete itemMap.front();
itemMap.erase(itemMap.begin());
}
-
+
Mix_FreeChunk(swordSwing);
}
@@ -178,27 +179,71 @@ void Inventory::setSelection(unsigned int s){
sel=s;
}
+void Inventory::setSelectionUp(){
+ if(!sel--)sel++;
+}
+
+void Inventory::setSelectionDown(){
+ sel++;
+ if(sel>=numSlot)sel=numSlot-1;
+}
+
void Inventory::draw(void){
static unsigned int lop = 0;
- const unsigned int numSlot = 7;
+ //const unsigned int numSlot = 7;
static std::vector<int>dfp(numSlot);
static std::vector<Ray>iray(numSlot);
static std::vector<vec2>curCoord(numSlot);
static int range = 200;
+
+ static std::vector<int>curdfp(4);
+ static std::vector<Ray>curRay(4);
+ static std::vector<vec2>curCurCoord(4);
+ static int curRange = 100;
+
+ static std::vector<int>massDfp(32);
+ static std::vector<vec2>massRay(32);
+ static std::vector<int>massOrder = {9,10,11,12,13,14,22,21,20,19,18,17,16,8,0,1,2,3,4,5,6,7,15,23,31,30,29,28,27,26,25,24};
+ static std::vector<int>massOrderClosing = {31,30,23,29,22,15,28,21,14,7,27,20,13,6,26,19,12,5,25,18,11,4,24,17,10,3,16,9,2,8,1,0};
+ static int massRange = 200;
+
static int itemWide = 45;
float angleB = (float)180/(float)numSlot;
float angle = float(angleB/2.0f);
unsigned int a = 0;
- unsigned int end = 0;
+ static bool end = false;
static vec2 mouseStart = {0,0};
-
+
for(auto &r : iray){
r.start.x = player->loc.x + (player->width/2);
r.start.y = player->loc.y + (player->height/2);
curCoord[a++] = r.start;
}a=0;
-
- if(invOpening){
+
+ for(auto &cr : curRay){
+ cr.start.x = (offset.x + SCREEN_WIDTH/2);
+ cr.start.y = offset.y - (a*itemWide*1.5);
+ curCurCoord[a++] = cr.start;
+ }a=0;
+
+ for(int r = 0; r < 4; r++){
+ for(int c = 0; c < 8; c++){
+ //std::cout << a << ",";
+ massRay[a].x = ((offset.x - SCREEN_WIDTH/2) + itemWide) + c*itemWide*1.5;
+ massRay[a++].y = ((offset.y + SCREEN_HEIGHT/2) - itemWide*1.5) - r*itemWide*1.5;
+ //std::cout << massRay[a-1].x << "," << massRay[a-1].y << " " << std::endl;
+ }
+ //std::cout << std::endl;
+ }a=0;
+ //std::cout << std::endl;
+
+ ui::fontTransInv = 255*(averagef(dfp)/range);
+ if(ui::fontTransInv > 255)
+ ui::fontTransInv = 255;
+ if(ui::fontTransInv < 0)
+ ui::fontTransInv = 0;
+
+ if(invOpening){
for(auto &d : dfp){
if(!a || dfp[a - 1] > 50)
d += 1.65 * deltaTime;
@@ -206,24 +251,87 @@ void Inventory::draw(void){
d = range;
a++;
}a=0;
-
+ for(auto &cd : curdfp){
+ if(!a || curdfp[a-1] > 90)
+ cd += 1.5 * deltaTime;
+ if(cd >= curRange)
+ cd = curRange;
+ a++;
+ }a=0;
+ for(uint i = 0; i < massOrder.size();i++){
+ if(!a || massDfp[massOrder[a-1]] > massRange*.75)
+ massDfp[massOrder[a]] += 5.00 * deltaTime;
+ if(massDfp[massOrder[a]] >= massRange)
+ massDfp[massOrder[a]] = massRange;
+ a++;
+ }a=0;
+
if(numSlot > 0)invOpen=true;
}else{
for(auto &d : dfp){
if(d > 0){
d -= 1.65 * deltaTime;
- }else end++;
+ }
}
- if(end >= numSlot)
+ for(auto &cd : curdfp){
+ if(cd > 0){
+ cd -= 1.0 * deltaTime;
+ }
+ }
+
+ for(uint i = 0; i < massRay.size();i++){
+ if(!a || massDfp[massOrderClosing[a-1]] <= 0)
+ massDfp[massOrderClosing[a]] -= 10.0f * deltaTime;
+ if(massDfp[massOrderClosing[a-1]] <= 0){
+ massDfp[massOrderClosing[a-1]] = 0;
+ }
+ a++;
+ }a=0;
+ end = std::all_of(std::begin(massDfp),std::end(massDfp),[](auto d){return d <= 0;});
+
+ if(end){
invOpen = false;
+ for(auto &md : massDfp){
+ if(md < 0){
+ md = 0;
+ }
+ }
+ }
+
}
-
+
/*
* a = 0
*/
-
+
if(invOpen){
-
+
+ for(auto &mr : massRay){
+ glColor4f(0.0f,0.0f,0.0f, ((float)massDfp[a]/(float)massRange)*.5f);
+ glBegin(GL_QUADS);
+ glVertex2i(mr.x-(itemWide/2), mr.y-(itemWide/2));
+ glVertex2i(mr.x-(itemWide/2)+itemWide,mr.y-(itemWide/2));
+ glVertex2i(mr.x-(itemWide/2)+itemWide,mr.y-(itemWide/2)+itemWide);
+ glVertex2i(mr.x-(itemWide/2), mr.y-(itemWide/2)+itemWide);
+ glEnd();
+ a++;
+ }a=0;
+
+ for(auto &cr : curRay){
+ curCurCoord[a].x -= float((curdfp[a]) * cos(-1));
+ curCurCoord[a].y += float((curdfp[a]) * sin(0));
+ cr.end = curCurCoord[a];
+
+ glColor4f(0.0f, 0.0f, 0.0f, ((float)curdfp[a]/(float)(curRange?curRange:1))*0.5f);
+ glBegin(GL_QUADS);
+ glVertex2i(cr.end.x-(itemWide/2), cr.end.y-(itemWide/2));
+ glVertex2i(cr.end.x-(itemWide/2)+itemWide,cr.end.y-(itemWide/2));
+ glVertex2i(cr.end.x-(itemWide/2)+itemWide,cr.end.y-(itemWide/2)+itemWide);
+ glVertex2i(cr.end.x-(itemWide/2), cr.end.y-(itemWide/2)+itemWide);
+ glEnd();
+ a++;
+ }a=0;
+
for(auto &r : iray){
angle = 180 - (angleB * a) - angleB / 2.0f;
curCoord[a].x += float((dfp[a]) * cos(angle*PI/180));
@@ -260,16 +368,47 @@ void Inventory::draw(void){
ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",items[a].count);
}
- a++;
-
- if(sel == a - 1){
- glBegin(GL_LINES);
- glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
- glVertex2i(r.start.x,r.start.y);
- glColor4f(1.0f, 0.0f, 0.0f, 0.8f);
- glVertex2i(r.end.x+20, r.end.y-20);
+ if(sel == a){
+ static float sc = 1;
+ static bool up;
+ up ? sc += .01 : sc -= .01;
+ if(sc > 1.2){
+ up = false;
+ sc = 1.2;
+ }
+ if(sc < 1.0){
+ up = true;
+ sc = 1.0;
+ }
+ glPushMatrix();
+ glLoadIdentity();
+ //glTranslatef(-sc, -sc, 0);
+ //glScalef(sc,sc,0.0f);
+ glBegin(GL_QUADS);
+ glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)(range?range:1)));
+ glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
+ glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
+ glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2);
+ glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2);
+
+ glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
+ glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
+ glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2);
+ glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2);
+
+ glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
+ glVertex2f(r.end.x - (itemWide*sc)/2 ,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
+ glVertex2f(r.end.x - (itemWide*sc)/2 ,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
+ glVertex2f(r.end.x - (itemWide*sc)/2 - (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
+
+ glVertex2f(r.end.x + (itemWide*sc)/2 ,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
+ glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y - (itemWide*sc)/2 - (itemWide*sc)*.09);
+ glVertex2f(r.end.x + (itemWide*sc)/2 + (itemWide*sc)*.09,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
+ glVertex2f(r.end.x + (itemWide*sc)/2 ,r.end.y + (itemWide*sc)/2 + (itemWide*sc)*.09);
glEnd();
+ glPopMatrix();
}
+ a++;
}
}else if(invHover){
static unsigned int highlight = 0;
@@ -279,14 +418,23 @@ void Inventory::draw(void){
if(!mouseSel){
mouseStart.x = ui::mouse.x - offset.x;
+ std::cout << "Setting highlight" << std::endl;
highlight = sel;
+ std::cout << "Setting thing" << std::endl;
thing = sel;
+ std::cout << "Setting mouseSel" << std::endl;
mouseSel=true;
+ std::cout << "Done" << std::endl;
}else{
+ std::cout << "Is mousex greater than the start" << std::endl;
if((ui::mouse.x - offset.x) >= mouseStart.x){
+ std::cout << "Thing" << std::endl;
thing = (ui::mouse.x - offset.x - mouseStart.x)/80;
+ std::cout << "Highlight" << std::endl;
highlight=sel+thing;
+ std::cout << "Highlight Check" << std::endl;
if(highlight>numSlot-1)highlight=numSlot-1;
+ std::cout << "Left Click" << std::endl;
if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)){
sel = highlight;
mouseSel=false;
@@ -297,7 +445,7 @@ void Inventory::draw(void){
if((ui::mouse.x - offset.x) < mouseStart.x){
thing = (mouseStart.x - (ui::mouse.x - offset.x))/80;
if((int)sel-(int)thing<0)highlight=0;
- else highlight=sel-thing;
+ else highlight=sel-thing;
if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)){
sel = highlight;
mouseSel=false;
@@ -306,12 +454,17 @@ void Inventory::draw(void){
}
}
}
+ std::cout << "Rays" << std::endl;
for(auto &r : iray){
+ std::cout << "Setting angle" << std::endl;
angle=180-(angleB*a) - angleB/2.0f;
+ std::cout << "Currcourd" << std::endl;
curCoord[a].x += float(range) * cos(angle*PI/180);
curCoord[a].y += float(range) * sin(angle*PI/180);
+ std::cout << "Ray.end" << std::endl;
r.end = curCoord[a];
+ std::cout << "Draw" << std::endl;
glColor4f(0.0f, 0.0f, 0.0f, a == highlight ? 0.5f : 0.1f);
glBegin(GL_QUADS);
glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2));
@@ -320,29 +473,36 @@ void Inventory::draw(void){
glVertex2i(r.end.x-(itemWide/2), r.end.y+(itemWide/2));
glEnd();
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, itemtex[items[a].id]);
- glColor4f(1.0f, 1.0f, 1.0f, a == highlight ? 0.8f : 0.2f);
- glBegin(GL_QUADS);
- if(itemMap[items[a].id]->height > itemMap[items[a].id]->width){
- glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y-(itemWide/2));
- glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y-(itemWide/2));
- glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y+(itemWide/2));
- glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y+(itemWide/2));
- }else{
- glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
- glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
- glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
- glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
- }
- glEnd();
- glDisable(GL_TEXTURE_2D);
-
- a++;
+ std::cout << "Draw items" << std::endl;
+ if(!items.empty() && a < items.size() && items[a].count){
+ std::cout << "Jamie" << std::endl;
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, itemtex[items[a].id]);
+ glColor4f(1.0f, 1.0f, 1.0f, a == highlight ? 0.8f : 0.2f);
+ std::cout << "Done Binding" << std::endl;
+ glBegin(GL_QUADS);
+ std::cout << "jdjdjd" << std::endl;
+ if(itemMap[items[a].id]->height > itemMap[items[a].id]->width){
+ std::cout << "map" << std::endl;
+ glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y-(itemWide/2));
+ glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y-(itemWide/2));
+ glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y+(itemWide/2));
+ glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)itemMap[items[a].id]->width/(float)itemMap[items[a].id]->height)),r.end.y+(itemWide/2));
+ }else{
+ glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+ glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2),r.end.y-(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+ glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+ glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2),r.end.y+(itemWide/2)*((float)itemMap[items[a].id]->height/(float)itemMap[items[a].id]->width));
+ }
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
+ std::cout << "Adding a" << std::endl;
+ a++;
+ }
}
ui::putStringCentered(player->loc.x+player->width/2, player->loc.y + range*.75,itemMap[items[highlight].id]->name.c_str());
}
-
+
if(!items.empty() && items.size() > sel && items[sel].count)
itemDraw(player,items[sel].id);
lop++;
@@ -352,9 +512,9 @@ void itemDraw(Player *p,uint id){
itemLoc.y = p->loc.y+(p->height/3);
itemLoc.x = p->left?p->loc.x:p->loc.x+p->width;
glPushMatrix();
-
+
if(!id)return;
-
+
if(itemMap[id]->type == "Sword"){
if(p->left){
if(hangle < 15){
@@ -368,7 +528,7 @@ void itemDraw(Player *p,uint id){
}
}
}else hangle = 0.0f;
-
+
glUseProgram(shaderProgram);
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glTranslatef(itemLoc.x,itemLoc.y,0);
@@ -392,9 +552,9 @@ void itemDraw(Player *p,uint id){
int Inventory::useItem(void){
static bool up = false;
if(!invHover){
-
+
if(itemMap[items[sel].id]->type == "Sword"){
-
+
if(swing){
if(!player->left){
if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);}
@@ -417,9 +577,10 @@ int Inventory::useItem(void){
bool Inventory::detectCollision(vec2 one, vec2 two){
(void)one;
(void)two;
- //float i = 0.0f;
-
- /*if(items.empty() || !items[sel].count)
+ float xc, yc;
+ float i = 0.0f;
+
+ if(items.empty() || !items[sel].count)
return false;
if(itemMap[items[sel].id]->type == "Sword"){
std::cout<<"Collision???"<<std::endl;
@@ -428,11 +589,11 @@ bool Inventory::detectCollision(vec2 one, vec2 two){
xc += float(i) * cos((hangle+90)*PI/180);
yc += float(i) * sin((hangle+90)*PI/180);
- *glColor4f(1.0f,1.0f,1.0f,1.0f);
+ /*glColor4f(1.0f,1.0f,1.0f,1.0f);
glBegin(GL_LINES);
glVertex2f(player->loc.x,player->loc.y+player->height/3);
glVertex2f(xc,yc);
- glEnd();*
+ glEnd();*/
if(xc >= one.x && xc <= two.x){
if(yc >= one.y && yc <= two.y){
@@ -442,7 +603,6 @@ bool Inventory::detectCollision(vec2 one, vec2 two){
i+=HLINE;
}
- }*/
+ }
return false;
}
-
diff --git a/src/ui.cpp b/src/ui.cpp
index f69bfe8..245f1d7 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -43,7 +43,7 @@ static vec2 ftexwh[93];
static vec2 ftexbl[93];
static vec2 ftexad[93];
-static unsigned char fontColor[3] = {255,255,255};
+static unsigned char fontColor[4] = {255,255,255,255};
/*
* Variables for dialog boxes / options.
@@ -126,6 +126,7 @@ namespace ui {
int dialogPassiveTime = 0;
Trade merchTrade;
+ int fontTransInv = 255;
/*
* Dialog stuff that needs to be 'public'.
@@ -193,6 +194,7 @@ namespace ui {
*/
void setFontSize(unsigned int size){
+ mtx.lock();
unsigned int i,j;
unsigned char *buf;
@@ -255,6 +257,7 @@ namespace ui {
delete[] buf; //free(buf);
}
+ mtx.unlock();
}
/*
@@ -265,6 +268,14 @@ namespace ui {
fontColor[0]=r;
fontColor[1]=g;
fontColor[2]=b;
+ fontColor[3]=255;
+ }
+
+ void setFontColor(unsigned char r,unsigned char g,unsigned char b, unsigned char a){
+ fontColor[0]=r;
+ fontColor[1]=g;
+ fontColor[2]=b;
+ fontColor[3]=a;
}
/*
@@ -293,7 +304,7 @@ namespace ui {
glPushMatrix();
glTranslatef(0,-c2.y,0);
glBegin(GL_QUADS);
- glColor3ub(fontColor[0],fontColor[1],fontColor[2]);
+ glColor4ub(fontColor[0],fontColor[1],fontColor[2],fontColor[3]);
glTexCoord2f(0,1);glVertex2f(c1.x ,c1.y );
glTexCoord2f(1,1);glVertex2f(c1.x+c2.x,c1.y );
glTexCoord2f(1,0);glVertex2f(c1.x+c2.x,c1.y+c2.y);
@@ -321,7 +332,7 @@ namespace ui {
* Loop on each character:
*/
- do {
+ do{
if(i && ((i / 110.0) == (i / 110))){
o.y -= fontSize * 1.05f;
o.x = x;
@@ -384,7 +395,6 @@ namespace ui {
break;
}
} while(s[++i]);
-
putString(floor(x-width/2),y,s);
return width;
}
@@ -569,6 +579,7 @@ namespace ui {
};
dialogOptChosen = 0;
+ merchOptChosen = 0;
memset(&dialogOptLoc, 0, sizeof(float) * 12);
// handle options if desired
@@ -605,8 +616,9 @@ namespace ui {
void waitForDialog(void){
do{
- mainLoop();
- }while(ui::dialogBoxExists);
+ //std::thread(dialogAdvance);
+ //mainLoop();
+ }while(dialogBoxExists);
}
void waitForCover(void){
do{
@@ -802,10 +814,10 @@ namespace ui {
glBegin(GL_LINE_STRIP);
glVertex2i(x-1 ,y+1);
- glVertex2i(x+1 +SCREEN_WIDTH-HLINE*16,y+1);
+ glVertex2i(x+1+SCREEN_WIDTH-HLINE*16,y+1);
glVertex2i(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4);
glVertex2i(x-1 ,y-1-SCREEN_HEIGHT/4);
- glVertex2i( x - 1, y + 1 );
+ glVertex2i(x-1 ,y+1);
glEnd();
glColor3ub(0,0,0);
@@ -862,6 +874,7 @@ namespace ui {
* Lists all of the quests the player is currently taking.
*/
+ setFontColor(255,255,255,fontTransInv);
if(player->inv->invOpen){
hub.y = player->loc.y + fontSize * 8;
hub.x = player->loc.x;// + player->width / 2;
@@ -872,7 +885,18 @@ namespace ui {
hub.y -= fontSize * 1.15;
putStringCentered(hub.x,hub.y,c.title.c_str());
}
+
+ hub.y = offset.y + 40*1.2;
+ hub.x = offset.x + SCREEN_WIDTH/2 - 40*1.5;
+
+ putStringCentered(hub.x,hub.y,"Equipment:");
+
+ hub.y = offset.y + SCREEN_HEIGHT/2 - 20;
+ hub.x = offset.x - SCREEN_WIDTH/2 + 45*4*1.5;
+
+ putStringCentered(hub.x,hub.y,"Inventory:");
}
+ setFontColor(255,255,255,255);
}
}
@@ -1210,6 +1234,11 @@ namespace ui {
fclose(bmp);
}
+ void closeBox(){
+ dialogBoxExists = false;
+ dialogMerchant = false;
+ }
+
void dialogAdvance(void){
unsigned char i;
@@ -1223,31 +1252,46 @@ namespace ui {
typeOutDone = true;
return;
}
-
for(i=0;i<dialogOptCount;i++){
if(mouse.x > dialogOptLoc[i][0] &&
mouse.x < dialogOptLoc[i][2] &&
mouse.y > dialogOptLoc[i][1] &&
mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
dialogOptChosen = i + 1;
- goto DONE;
+ goto EXIT;
+ }
+ }
+ if(dialogMerchant){
+ for(i=0;i<2;i++){
+ if(((merchAOptLoc[i][0] < merchAOptLoc[i][2]) ?
+ (mouse.x > merchAOptLoc[i][0] && mouse.x < merchAOptLoc[i][2]) :
+ (mouse.x < merchAOptLoc[i][0] && mouse.x > merchAOptLoc[i][2])) &&
+ mouse.y > merchAOptLoc[i][1] - 8 && mouse.y < merchAOptLoc[i][1] + 8){ // fontSize
+ merchOptChosen = i + 1;
+ goto EXIT;
+ }
}
}
-DONE:
+
+
+ EXIT:
+ //if(!dialogMerchant)closeBox();
+ dialogBoxExists = false;
+ dialogMerchant = false;
+
+ //DONE:
// handle important text
if(dialogImportant){
dialogImportant = false;
setFontSize(16);
}
-
- if(dialogMerchant) dialogMerchant = false;
- dialogBoxExists = false;
}
void handleEvents(void){
static bool left=true,right=false;
static int heyOhLetsGo = 0;
+ static int mouseWheelUpCount = 0, mouseWheelDownCount = 0;
World *tmp;
vec2 oldpos,tmppos;
SDL_Event e;
@@ -1279,7 +1323,19 @@ DONE:
if ( ( e.button.button & SDL_BUTTON_LEFT ) && !dialogBoxExists )
player->inv->usingi = true;
break;
-
+ case SDL_MOUSEWHEEL:
+ if (e.wheel.y < 0){
+ if(mouseWheelUpCount++ && mouseWheelUpCount%5==0){
+ player->inv->setSelectionUp();
+ mouseWheelUpCount = 0;
+ }
+ }else{
+ if(mouseWheelDownCount-- && mouseWheelDownCount%5==0){
+ player->inv->setSelectionDown();
+ mouseWheelDownCount = 0;
+ }
+ }
+ break;
// key presses
case SDL_KEYDOWN:
@@ -1432,12 +1488,6 @@ DONE:
}
heyOhLetsGo = 0;
break;
- case SDLK_LEFT:
- if(player->inv->sel)player->inv->sel--;
- break;
- case SDLK_RIGHT:
- player->inv->sel++;
- break;
case SDLK_l:
player->light^=true;
break;
diff --git a/src/world.cpp b/src/world.cpp
index dec9a64..b1eb12e 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -218,7 +218,6 @@ World::
Mix_FreeMusic(bgmObj);
delete bgTex;
-
deleteEntities();
}
@@ -772,22 +771,21 @@ singleDetect( Entity *e )
if ( e->loc.y < worldData[i].groundHeight ) {
- if ( worldData[i].groundHeight - e->loc.y > 30 ) {
- int dir = e->vel.x > 0 ? -1 : 1;
- e->loc.x += HLINE * 8 * dir;
- e->loc.y = worldData[i + 8 * dir].groundHeight;
- } else {
- e->loc.y = worldData[i].groundHeight - .001 * deltaTime;
- e->ground = true;
- e->vel.y = 0;
- }
+ if ( worldData[i].groundHeight - e->loc.y > 30 ) {
+ int dir = e->vel.x > 0 ? -1 : 1;
+ e->loc.x += HLINE * 8 * dir;
+ e->loc.y = worldData[i + 8 * dir].groundHeight;
+ } else {
+ e->loc.y = worldData[i].groundHeight - .001 * deltaTime;
+ e->ground = true;
+ e->vel.y = 0;
+ }
/*
* Handle gravity if the entity is above the line.
*/
- } else {
-
+ }else{
if(e->type == STRUCTURET && e->loc.y > 2000){
e->loc.y = worldData[i].groundHeight;
e->vel.y = 0;
@@ -988,6 +986,7 @@ setToRight( std::string file )
return (toRight = file);
}
+//what is this clyne why are they differnet
World *World::
goWorldLeft( Player *p )
{
@@ -1134,9 +1133,11 @@ void World::save(void){
}
data.append("dOnE\0");
+ std::cout << "Writing to the file" << std::endl;
out.write(data.c_str(),data.size());
out.close();
+ std::cout << "Done saving" << std::endl;
}
void World::load(void){
@@ -1506,8 +1507,6 @@ loadWorldFromXMLNoSave( std::string path ) {
tmp->addMerchant(0,100);
if(vil->FirstChildElement("buy")){
std::cout << "Buy" << std::endl;
- //Trade goodMeme(1,"Dank MayMay",1,"Sword");
- //tmp->merchant.back()->trade.push_back(Trade());
}if(vil->FirstChildElement("sell")){
std::cout << "Sell" << std::endl;
}if(vil->FirstChildElement("trade")){
@@ -1516,7 +1515,9 @@ loadWorldFromXMLNoSave( std::string path ) {
vil->FirstChildElement("trade")->Attribute("item"),
vil->FirstChildElement("trade")->IntAttribute("quantity1"),
vil->FirstChildElement("trade")->Attribute("item1")));
+ tmp->merchant.back()->trade.push_back(Trade(1,"Wood Sword", 420, "Dank MayMay"));
}
+ std::cout << "new trade" << std::endl;
strcpy(tmp->merchant.back()->name,"meme");
}else if(!strcmp(vil->Attribute("type"),"trader")){