aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/entities.h3
-rw-r--r--include/inventory.h3
-rw-r--r--main.cpp49
-rw-r--r--src/entities.cpp12
-rw-r--r--src/inventory.cpp50
-rw-r--r--src/ui.cpp10
6 files changed, 39 insertions, 88 deletions
diff --git a/include/entities.h b/include/entities.h
index c593710..4413d41 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -145,9 +145,6 @@ public:
~Object();
void interact(void);
- std::thread runInteract() {
- return std::thread([=] { interact(); });
- }
};
#endif // ENTITIES_H
diff --git a/include/inventory.h b/include/inventory.h
index ec71e94..b62e491 100644
--- a/include/inventory.h
+++ b/include/inventory.h
@@ -81,9 +81,6 @@ public:
int takeItem(ITEM_ID id,unsigned char count); // Take 'count' items with an id of 'id' from the inventory
int useItem(void);
- bool tossd;
- int itemToss(void);
-
void setSelection(unsigned int s);
void draw(void); // Draws a text list of items in this inventory (should only be called for the player for now)
diff --git a/main.cpp b/main.cpp
index ffd9ead..6230e72 100644
--- a/main.cpp
+++ b/main.cpp
@@ -413,7 +413,7 @@ int main(int argc, char *argv[]){
* src/gameplay.cpp
*
*/
- fadeIntensity = 254;
+ fadeIntensity = 250;
initEverything();
/*
@@ -809,6 +809,8 @@ void render(){
SDL_GL_SwapWindow(window);
}
+static volatile bool objectInteracting = false;
+
void logic(){
/*
* NPCSelected is used to insure that only one NPC is made interactable with the mouse
@@ -930,28 +932,31 @@ void logic(){
}
}
}
- for(auto &o : currentWorld->object){
- if(o->alive){
- if(ui::mouse.x >= o->loc.x &&
- ui::mouse.x <= o->loc.x + o->width &&
- ui::mouse.y >= o->loc.y &&
- ui::mouse.y <= o->loc.y + o->width ){
- if(pow((o->loc.x - player->loc.x),2) + pow((o->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
-
- /*
- * Check for a right click, and allow the Object to interact with the
- * player if one was made.
- */
-
- if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
- std::thread thr(o->runInteract());
- thr.detach();
+ if(!objectInteracting){
+ for(auto &o : currentWorld->object){
+ if(o->alive){
+ if(ui::mouse.x >= o->loc.x &&
+ ui::mouse.x <= o->loc.x + o->width &&
+ ui::mouse.y >= o->loc.y &&
+ ui::mouse.y <= o->loc.y + o->width ){
+ if(pow((o->loc.x - player->loc.x),2) + pow((o->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
+
+ /*
+ * Check for a right click, and allow the Object to interact with the
+ * player if one was made.
+ */
+
+ if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
+ objectInteracting=true;
+ o->interact();
+ objectInteracting=false;
+ }
}
}
}
}
}
-
+
/*
* Switch between day and night (SUNNY and DARK) if necessary.
*/
@@ -973,11 +978,11 @@ void logic(){
* Transition to and from black if necessary.
*/
if(fadeEnable){
- if(fadeIntensity < 160)fadeIntensity+=5;
- else if(fadeIntensity < 255)fadeIntensity+=1;
+ if(fadeIntensity < 160)fadeIntensity+=10;
+ else if(fadeIntensity < 255)fadeIntensity+=5;
}else{
- if(fadeIntensity > 150)fadeIntensity-=1;
- else if(fadeIntensity) fadeIntensity-=5;
+ if(fadeIntensity > 150)fadeIntensity-=5;
+ else if(fadeIntensity > 0) fadeIntensity-=10;
}
/*
diff --git a/src/entities.cpp b/src/entities.cpp
index 1e6fad5..3286784 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -339,18 +339,14 @@ void NPC::interact(){ //have the npc's interact back to the player
}
}
-extern void waitForDialog(void);
-void Object::interact(void){
+void Object::interact(void){
if(questObject && alive){
-
ui::dialogBox("You",":Yes:No",pickupDialog);
- while(ui::dialogBoxExists);
-
- if(ui::dialogOptChosen == 1 && alive){
+ ui::waitForDialog();
+ if(ui::dialogOptChosen == 1){
player->inv->addItem((ITEM_ID)(identifier), (char)1);
alive = false;
- return;
- }
+ }
}else{
alive = false;
player->inv->addItem((ITEM_ID)(identifier), (char)1);
diff --git a/src/inventory.cpp b/src/inventory.cpp
index e67f031..a365204 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -41,7 +41,6 @@ Inventory::Inventory(unsigned int s){
size=s;
inv = new struct item_t[size];
memset(inv,0,size*sizeof(struct item_t));
- tossd=false;
for(int i = 0;i<ITEM_COUNT;i++){
itemtex[i]=Texture::loadTexture(getItemTexturePath((ITEM_ID)i));
}
@@ -162,29 +161,16 @@ void Inventory::draw(void){
lop++;
}
-static vec2 item_coord = {0,0};
-static vec2 item_velcd = {0,0};
-static bool item_tossd = false;
-static bool yes=false;
-
void itemDraw(Player *p,ITEM_ID id){
- static vec2 p1,p2;
if(!id)return;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,itemtex[id]);
- if(!yes){
- p1 = {p->loc.x+p->width/2,
- p->loc.y+p->width/2+HLINE*3};
- p2 = {(float)(p1.x+p->width*(p->left?-.5:.5)),
- p->loc.y+HLINE*3};
- }
- if(p->inv->tossd) yes=true;
glColor4ub(255,255,255,255);
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2f(item_coord.x+p->loc.x, item_coord.y+p->loc.y);
- glTexCoord2i(1,1);glVertex2f(item_coord.x+item[id].width+p->loc.x, item_coord.y+p->loc.y);
- glTexCoord2i(1,0);glVertex2f(item_coord.x+item[id].width+p->loc.x, item_coord.y+item[id].height+p->loc.y);
- glTexCoord2i(0,0);glVertex2f(item_coord.x+p->loc.x, item_coord.y+item[id].height+p->loc.y);
+ glTexCoord2i(0,1);glVertex2f(p->loc.x, p->loc.y);
+ glTexCoord2i(1,1);glVertex2f(p->loc.x+item[id].width,p->loc.y);
+ glTexCoord2i(1,0);glVertex2f(p->loc.x+item[id].width,p->loc.y+item[id].height);
+ glTexCoord2i(0,0);glVertex2f(p->loc.x, p->loc.y+item[id].height);
glEnd();
glDisable(GL_TEXTURE_2D);
}
@@ -202,31 +188,3 @@ int Inventory::useItem(void){
return 0;
}
-int Inventory::itemToss(void){
- if(!item_tossd && item[sel].count && item[sel].id){
- item_tossd = true;
- item_coord.x = HLINE;
- item_velcd.x = 0;
- item_velcd.y = 3;
- tossd = true;
- return 1;
- }else if(item_tossd){
- if(item_coord.y<0){
- memset(&item_coord,0,sizeof(vec2));
- memset(&item_velcd,0,sizeof(vec2));
- item_tossd = false;
-
- takeItem(item[sel].id,1);
-
- tossd = yes = false;
-
- return 0;
- }else{
- item_coord.x += item_velcd.x;
- item_coord.y += item_velcd.y;
- //item_velcd.x -= .005;
- item_velcd.y -= .1;
- return 1;
- }
- }
-}
diff --git a/src/ui.cpp b/src/ui.cpp
index a37a97c..e10ed46 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -514,12 +514,14 @@ namespace ui {
}
}
void handleEvents(void){
- unsigned char i;
static bool left=false,right=false;
static vec2 premouse={0,0};
+ unsigned char i;
SDL_Event e;
+
mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
mouse.y=(offset.y+SCREEN_HEIGHT/2)-premouse.y;
+
while(SDL_PollEvent(&e)){
switch(e.type){
case SDL_QUIT:
@@ -602,9 +604,7 @@ DONE:
player->ground=false;
}
}
- if(SDL_KEY==SDLK_q){
- player->inv->itemToss();
- }
+
if(SDL_KEY==SDLK_LSHIFT)player->speed = debug?4:3; // Sprint
if(SDL_KEY==SDLK_LCTRL)player->speed = .5;
}
@@ -632,8 +632,6 @@ DONE:
}
}
- if(player->inv->tossd)player->inv->itemToss();
-
if(!dialogBoxExists&&AIpreaddr.size()){ // Flush preloaded AI functions if necessary
for(i=0;i<AIpreaddr.size();i++){
AIpreaddr.front()->addAIFunc(AIpreload.front(),false);