aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-02-02 08:49:38 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-02-02 08:49:38 -0500
commitd83b7f3d1f50ee1b164095c0e9d94cc87a44ad8c (patch)
treed7b76cb1907f781e1eccd1691bc7a622ed27a63c
parent32855b564c2a7cd5c1a644dcf7039ab9b69295e4 (diff)
inventory rewrite
-rw-r--r--.gitignore1
-rw-r--r--Changelog11
-rw-r--r--config/items.xml7
-rw-r--r--include/Quest.h7
-rw-r--r--include/entities.h6
-rw-r--r--include/inventory.h84
-rw-r--r--include/world.h2
-rw-r--r--main.cpp46
-rw-r--r--src/Quest.cpp31
-rw-r--r--src/entities.cpp21
-rw-r--r--src/gameplay.cpp10
-rw-r--r--src/inventory.cpp302
-rw-r--r--src/ui.cpp7
-rw-r--r--src/world.cpp8
-rw-r--r--xml/playerSpawnHill1.xml2
15 files changed, 325 insertions, 220 deletions
diff --git a/.gitignore b/.gitignore
index c00a3b1..c3f1695 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,2 @@
-main.exe
main
doc/**
diff --git a/Changelog b/Changelog
index c74cbc2..f5b6847 100644
--- a/Changelog
+++ b/Changelog
@@ -582,3 +582,14 @@
- Game has a menu API
- Pause Menu
+1/26/2016:
+==========
+
+ - wrote paper regarding what we've learned, and where we're at
+ - ported game to Windows, left EXE and DLLs in repo
+
+2/1/2016:
+=========
+
+ - began rewriting item/inventory system
+ - worked on option menu actually modifying options (updating settings.xml)
diff --git a/config/items.xml b/config/items.xml
new file mode 100644
index 0000000..02d199e
--- /dev/null
+++ b/config/items.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+
+<item name="Debug" type="Tool" maxStackSize="1" width="1" height="1" sprite="assets/items/ITEM_TEST.png" />
+<item name="Dank Maymay" type="Tool" maxStackSize="420" width="10" height="10" sprite="assets/items/ITEM_TEST.png" />
+<item name="Your Bag" type="Equip" maxStackSize="1" width="5" height="5" sprite="assets/items/ITEM_TEST.png" />
+<item name="Flashlight" type="Tool" maxStackSize="1" width="4" height="8" sprite="assets/items/flashlight_off.png" />
+<item name="Wood Sword" type="Sword" maxStackSize="1" width="4" height="10" sprite="assets/items/SWORD_WOOD.png" />
diff --git a/include/Quest.h b/include/Quest.h
index 8f5446c..d17ade4 100644
--- a/include/Quest.h
+++ b/include/Quest.h
@@ -21,13 +21,6 @@
#define DEBUG
/**
- * Contains the total number of quests in the game at compile time, see Quest.cpp
- * for the actual definition of these quests.
- */
-
-#define TOTAL_QUESTS 1
-
-/**
* The Quest class.
*
* This contains information for a single quest, and should only really be interacted
diff --git a/include/entities.h b/include/entities.h
index 28fd7e9..f4959d6 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -220,13 +220,15 @@ public:
class Object : public Entity{
private:
- ITEM_ID identifier;
+ std::string iname;
+ //ITEM_ID identifier;
public:
char *pickupDialog;
bool questObject = false;
Object();
- Object(ITEM_ID id,const char *pd);
+ //Object(ITEM_ID id,const char *pd);
+ Object(std::string in,const char *pd);
~Object();
void reloadTexture(void);
diff --git a/include/inventory.h b/include/inventory.h
index a08954a..d3bdd4d 100644
--- a/include/inventory.h
+++ b/include/inventory.h
@@ -6,7 +6,7 @@
#define DEBUG
-#define ID Item(
+/*#define ID Item(
#define NAME ,
#define TYPE ,
#define WIDTH ,
@@ -14,62 +14,66 @@
#define STACKSIZE ,
#define TEX ,
#define ENI ),
-#define STOP )
+#define STOP )*/
/*
* A list of all item IDs.
*/
+/*#define ITEM_COUNT 5
+
enum ITEM_ID {
DEBUG_ITEM = 0,
- TEST_ITEM = 1,
- PLAYER_BAG = 2,
- FLASHLIGHT = 3,
- SWORD_WOOD = 4
+ TEST_ITEM,
+ PLAYER_BAG,
+ FLASHLIGHT,
+ SWORD_WOOD
};
-enum ITEM_TYPE{
+enum ITEM_TYPE {
TOOL = 1,
- SWORD = 2,
- RANGED = 3,
- EQUIP = 4,
- FOOD = 5
-};
+ SWORD,
+ RANGED,
+ EQUIP,
+ FOOD
+};*/
class Item{
protected:
public:
- ITEM_ID id; // ID of the item
- char *name;
- ITEM_TYPE type; // What category the item falls under
+ //ITEM_ID id; // ID of the item
+ //ITEM_TYPE type; // What category the item falls under
+
+ //char *name;
+ //char *type;
+
+ std::string name,type;
+
float width;
float height;
- int maxStackSize;
- char* textureLoc;
+ int maxStackSize;
+
+ std::string texloc;
Texturec *tex;
- GLuint text;
- Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl);
+ //Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl);
GLuint rtex(){
return tex->image[0];
}
};
struct item_t{
- int count;
- ITEM_ID id;
+ uint count;
+ uint/*ITEM_ID*/ id;
} __attribute__((packed));
-typedef struct {
- unsigned int size;
- int os;
- unsigned int sel;
-} __attribute__ ((packed)) InventorySavePacket;
-
class Inventory {
private:
+
+ std::vector<item_t> items;
+
unsigned int size; // Size of 'item' array
- item_t *inv;
+ //item_t *inv;
int os = 0;
public:
unsigned int sel;
@@ -83,34 +87,22 @@ public:
Inventory(unsigned int s); // Creates an inventory of size 's'
~Inventory(void); // Free's allocated memory
- int addItem(ITEM_ID id,unsigned char count); // Add 'count' items with an id of 'id' to the inventory
- int takeItem(ITEM_ID id,unsigned char count); // Take 'count' items with an id of 'id' from the inventory
+ int addItem(std::string name,uint count);
+ int takeItem(std::string name,uint count);
+
int useItem(void);
bool detectCollision(vec2,vec2);
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)
-
- char *save(void){
- static InventorySavePacket *isp = new InventorySavePacket();
- isp->size = size;
- isp->os = os;
- isp->sel = sel;
- return (char *)isp;
- }
- void load(InventorySavePacket *isp){
- size = isp->size;
- os = isp->os;
- sel = isp->sel;
- }
};
void initInventorySprites(void);
void destroyInventory(void);
-char *getItemTexturePath(ITEM_ID id);
-int getItemWidth(ITEM_ID);
-int getItemHeight(ITEM_ID);
+const char *getItemTexturePath(std::string name);
+float getItemWidth(std::string name);
+float getItemHeight(std::string name);
#endif // INVENTORY_H
diff --git a/include/world.h b/include/world.h
index d752728..a0c9a63 100644
--- a/include/world.h
+++ b/include/world.h
@@ -285,7 +285,7 @@ public:
* upon object interaction.
*/
- void addObject(ITEM_ID id,const char *pickupDialog, float x, float y);
+ void addObject(/*ITEM_ID id*/std::string in,const char *pickupDialog, float x, float y);
/**
* Adds a particle to the world with the specified coordinates, dimensions,
diff --git a/main.cpp b/main.cpp
index 320b87b..4aef268 100644
--- a/main.cpp
+++ b/main.cpp
@@ -503,8 +503,7 @@ void mainLoop(void){
debugY = player->loc.y;
}
- MENU:
-
+MENU:
render(); // Call the render loop;
}
@@ -789,7 +788,7 @@ void logic(){
/*
* NPCSelected is used to insure that only one NPC is made interactable with the mouse
* if, for example, multiple entities are occupying one space.
- */
+ */
static bool NPCSelected = false;
@@ -802,7 +801,8 @@ void logic(){
/*
* Run the world's detect function. This handles the physics of the player and any entities
* that exist in this world.
- */
+ */
+
currentWorld->detect(player);
if(player->loc.y<.02)gameRunning=false;
@@ -810,20 +810,23 @@ void logic(){
* Entity logic: This loop finds every entity that is alive and in the current world. It then
* basically runs their AI functions depending on what type of entity they are. For NPCs,
* click detection is done as well for NPC/player interaction.
- *
- */
+ */
+
for(auto &n : currentWorld->npc){
if(n->alive){
+
/*
* Make the NPC 'wander' about the world if they're allowed to do so.
* Entity->canMove is modified when a player interacts with an NPC so
* that the NPC doesn't move when it talks to the player.
- *
- */
+ */
- if(n->canMove) n->wander((rand() % 120 + 30));
- 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(n->canMove)
+ n->wander((rand() % 120 + 30));
+
+ /*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})){
n->health -= 25;
n->hit = true;
for(int r = 0; r < (rand()%5);r++)
@@ -832,10 +835,11 @@ 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.
- */
+ */
if(NPCSelected){
n->near=false;
@@ -844,7 +848,7 @@ void logic(){
/*
* Check if the NPC is under the mouse.
- */
+ */
if(ui::mouse.x >= n->loc.x &&
ui::mouse.x <= n->loc.x + n->width &&
@@ -856,15 +860,15 @@ void logic(){
* considered legal. In other words, require the player to be close to
* the NPC in order to interact with it.
*
- * This uses the Pythagorean theorem to check for NPCs within a certain *
- */
+ * This uses the Pythagorean theorem to check for NPCs within a certain
+ */
if(pow((n->loc.x - player->loc.x),2) + pow((n->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
/*
* Set Entity->near so that this NPC's name is drawn under them, and toggle NPCSelected
* so this NPC is the only one that's clickable.
- */
+ */
n->near=true;
NPCSelected=true;
@@ -872,7 +876,7 @@ void logic(){
/*
* Check for a right click, and allow the NPC to interact with the
* player if one was made.
- */
+ */
if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
@@ -884,17 +888,18 @@ void logic(){
/*
* Hide the NPC's name if the mouse isn't on the NPC.
- */
+ */
}else n->near=false;
}
}
+
for(auto &m : currentWorld->mob){
if(m->alive){
/*
* Run the Mob's AI function.
- */
+ */
switch(m->subtype){
case MS_RABBIT:
@@ -913,6 +918,7 @@ void logic(){
}
}
}
+
if(!objectInteracting){
for(auto &o : currentWorld->object){
if(o->alive){
diff --git a/src/Quest.cpp b/src/Quest.cpp
index 0905a87..4328dc5 100644
--- a/src/Quest.cpp
+++ b/src/Quest.cpp
@@ -1,14 +1,7 @@
#include <Quest.h>
-#define TITLE Quest(
-#define DESC ,
-#define REWARD ,(struct item_t){
-#define x ,
-#define END }),
-
-const Quest QuestList[TOTAL_QUESTS]={
-// Get quest list
-#include "../config/quest_list.txt"
+const Quest QuestList[1] = {
+ Quest("Not a quest","Stop",(struct item_t){0,0})
};
@@ -27,7 +20,7 @@ Quest::~Quest(){
}
int QuestHandler::assign(const char *t){
- unsigned char i;
+ /*unsigned char i;
for(i=0;i<current.size();i++){ // Make sure we don't already have this quest
if(!strcmp(current[i]->title,t)){
#ifdef DEBUG
@@ -36,7 +29,7 @@ int QuestHandler::assign(const char *t){
return -2;
}
}
- for(i=0;i<TOTAL_QUESTS;i++){ // Add the quest (if it really exists)
+ for(i=0;i<0;i++){ // Add the quest (if it really exists)
if(!strcmp(QuestList[i].title,t)){
current.push_back(&QuestList[i]);
#ifdef DEBUG
@@ -50,23 +43,23 @@ int QuestHandler::assign(const char *t){
}
#ifdef DEBUG
DEBUG_printf("Quest %s does not exist.\n",t);
-#endif // DEBUG
- return -1;
+#endif // DEBUG*/
+ return strcmp(t,"h");
}
int QuestHandler::drop(const char *t){
- unsigned char i;
+ /*unsigned char i;
for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
current.erase(current.begin()+i);
return current.size();
}
- }
- return -1;
+ }*/
+ return strcmp(t,"h");
}
int QuestHandler::finish(const char *t,void *completer){
- unsigned char i;
+ /*unsigned char i;
for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
#ifdef DEBUG
@@ -82,8 +75,8 @@ int QuestHandler::finish(const char *t,void *completer){
}
#ifdef DEBUG
DEBUG_printf("QuestHandler never had quest %s.\n",t);
-#endif // DEBUG
- return -1;
+#endif // DEBUG*/
+ return strncmp(t,(char *)completer,1);
}
bool QuestHandler::hasQuest(const char *t){
diff --git a/src/entities.cpp b/src/entities.cpp
index 4a8e6b7..4c1d326 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -214,8 +214,9 @@ Object::Object(){
inv = NULL;
}
-Object::Object(ITEM_ID id, const char *pd){
- identifier = id;
+Object::Object(/*ITEM_ID id*/std::string in, const char *pd){
+ //identifier = id;
+ iname = in;
if(pd){
pickupDialog = new char[strlen(pd)+1];
@@ -230,11 +231,11 @@ Object::Object(ITEM_ID id, const char *pd){
type = OBJECTT;
alive = true;
near = false;
- width = getItemWidth(id);
- height = getItemHeight(id);
+ width = getItemWidth(in);
+ height = getItemHeight(in);
maxHealth = health = 1;
- tex = new Texturec(1,getItemTexturePath(id));
+ tex = new Texturec(1,getItemTexturePath(in));
inv = NULL;
}
Object::~Object(){
@@ -247,9 +248,9 @@ void Object::reloadTexture(void){
if(tex)
delete tex;
- tex = new Texturec(1,getItemTexturePath(identifier));
- width = getItemWidth(identifier);
- height = getItemHeight(identifier);
+ tex = new Texturec(1,getItemTexturePath(iname));
+ width = getItemWidth(iname);
+ height = getItemHeight(iname);
}
void Entity::draw(void){ //draws the entities
@@ -449,12 +450,12 @@ void Object::interact(void){
ui::dialogBox(player->name,":Yes:No",false,pickupDialog);
ui::waitForDialog();
if(ui::dialogOptChosen == 1){
- player->inv->addItem((ITEM_ID)(identifier), (char)1);
+ player->inv->addItem(/*(ITEM_ID)(identifier)*/iname, 1);
alive = false;
}
}else{
alive = false;
- player->inv->addItem((ITEM_ID)(identifier), (char)1);
+ player->inv->addItem(iname, 1);
}
}
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 7c238b4..8e68783 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -17,7 +17,7 @@ extern std::vector<menuItem>optionsMenu;
extern void mainLoop(void);
void segFault(){
- ((vec2 *)currentWorld + 2934)[10].x = *((unsigned int *)&currentXML) * *((int *)NULL);
+ (*((int *)NULL))++;
}
@@ -26,7 +26,7 @@ typedef struct {
unsigned int index;
} NPCDialog;
-std::vector<XMLElement *> dopt;
+std::vector<XMLElement *> dopt;
int commonAIFunc(NPC *speaker){
XMLDocument xml;
@@ -66,7 +66,7 @@ int commonAIFunc(NPC *speaker){
if((oxml = exml->FirstChildElement("give"))){
while(oxml){
- player->inv->addItem((ITEM_ID)oxml->UnsignedAttribute("id"),oxml->UnsignedAttribute("count"));
+ player->inv->addItem(oxml->Attribute("id"),oxml->UnsignedAttribute("count"));
oxml = oxml->NextSiblingElement();
}
}
@@ -77,7 +77,7 @@ int commonAIFunc(NPC *speaker){
if((oxml = exml->FirstChildElement("take"))){
while(oxml){
- player->inv->takeItem((ITEM_ID)oxml->UnsignedAttribute("id"),oxml->UnsignedAttribute("count"));
+ player->inv->takeItem(oxml->Attribute("id"),oxml->UnsignedAttribute("count"));
oxml = oxml->NextSiblingElement();
}
}
@@ -128,7 +128,7 @@ int commonAIFunc(NPC *speaker){
/*
* No options - simply print the text.
*/
-
+
ui::dialogBox(speaker->name,"",false,exml->GetText());
ui::waitForDialog();
}
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 108051c..4d94831 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -2,27 +2,89 @@
#include <entities.h>
#include <ui.h>
-#define ITEM_COUNT 5 // Total number of items that actually exist
+#include <tinyxml2.h>
+using namespace tinyxml2;
extern Player *player;
extern GLuint invUI;
static float hangle = 0.0f;
static bool swing = false;
-static float xc,yc;
+//static float xc,yc;
static vec2 itemLoc;
Mix_Chunk* swordSwing;
-static const Item item[ITEM_COUNT]= {
+std::vector<Item *> itemMap;
+
+void items(void){
+ XMLDocument xml;
+ XMLElement *exml;
+ 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){
+ for(unsigned int i=0;i<itemMap.size();i++){
+ if(itemMap[i]->name == name){
+ for(auto &in : items){
+ if(in.id == i){
+ in.count += count;
+ return 0;
+ }
+ }
+ items.push_back((item_t){i,count});
+ return 0;
+ }
+ }
+ return -1;
+}
+
+int Inventory::takeItem(std::string name,uint count){
+ unsigned int id = 999999;
+ for(unsigned int i=0;i<itemMap.size();i++){
+ if(itemMap[i]->name == name){
+ id = i;
+ break;
+ }
+ }
+ for(unsigned int i=0;i<items.size();i++){
+ if(items[i].id == id){
+ if(count > items[i].count)
+ items.erase(items.begin()+i);
+ else
+ items[i].count -= count;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+/*static const Item item[ITEM_COUNT]= {
#include "../config/items.h"
-};
+};*/
-static GLuint itemtex[ITEM_COUNT];
-void itemDraw(Player *p,ITEM_ID id, ITEM_TYPE type);
+static GLuint *itemtex;//[ITEM_COUNT];
+void itemDraw(Player *p,uint id);
void initInventorySprites(void){
- unsigned int i;
- for(i = 0;i < ITEM_COUNT;i++){
- itemtex[i] = Texture::loadTexture(getItemTexturePath((ITEM_ID)i));
+
+ items();
+ itemtex = new GLuint[itemMap.size()];
+
+ for(unsigned int i = 0;i<itemMap.size();i++){
+ itemtex[i] = Texture::loadTexture(getItemTexturePath(itemMap[i]->name));
}
swordSwing = Mix_LoadWAV("assets/sounds/shortSwing.wav");
@@ -33,19 +95,43 @@ void destroyInventory(void){
Mix_FreeChunk(swordSwing);
}
-char *getItemTexturePath(ITEM_ID id){
+const char *getItemTexturePath(std::string name){
+ for(auto &i : itemMap){
+ if(i->name == name)
+ return i->texloc.c_str();
+ }
+ return NULL;
+}
+
+/*char *getItemTexturePath(ITEM_ID id){
return item[id].textureLoc;
+}*/
+
+float getItemWidth(std::string name){
+ for(auto &i : itemMap){
+ if(i->name == name)
+ return i->width;
+ }
+ return 0;
}
-int getItemWidth(ITEM_ID id){
+/*int getItemWidth(ITEM_ID id){
return item[id].width;
+}*/
+
+float getItemHeight(std::string name){
+ for(auto &i : itemMap){
+ if(i->name == name)
+ return i->height;
+ }
+ return 0;
}
-int getItemHeight(ITEM_ID id){
+/*int getItemHeight(ITEM_ID id){
return item[id].height;
-}
+}*/
-Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl){
+/*Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl){
id = i;
type = t;
width = w;
@@ -59,24 +145,24 @@ Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const
strcpy(textureLoc,tl);
//tex= new Texturec(1,textureLoc);
-}
+}*/
Inventory::Inventory(unsigned int s){
sel=0;
size=s;
- inv = new struct item_t[size];
- memset(inv,0,size*sizeof(struct item_t));
+ //inv = new struct item_t[size];
+ //memset(inv,0,size*sizeof(struct item_t));
}
Inventory::~Inventory(void){
- delete[] inv;
+ //delete[] inv;
}
void Inventory::setSelection(unsigned int s){
sel=s;
}
-int Inventory::addItem(ITEM_ID id,unsigned char count){
+/*int Inventory::addItem(ITEM_ID id,unsigned char count){
//std::cout << id << "," << inv[os].id << std::endl;
for(unsigned int i = 0; i < size; i++){
@@ -94,9 +180,9 @@ int Inventory::addItem(ITEM_ID id,unsigned char count){
#endif // DEBUG
return 0;
-}
+}*/
-int Inventory::takeItem(ITEM_ID id,unsigned char count){
+/*int Inventory::takeItem(ITEM_ID id,unsigned char count){
for(unsigned int i = 0;i < size;i++){
if(inv[i].id == id){
#ifdef DEBUG
@@ -107,7 +193,7 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
}
}
return -1;
-}
+}*/
void Inventory::draw(void){
static unsigned int lop = 0;
@@ -122,72 +208,83 @@ void Inventory::draw(void){
unsigned int a = 0;
unsigned int end = 0;
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;
+ curCoord[a++] = r.start;
//dfp[a] = 0;
- a++;
+ //a++;
}a=0;
+
if(invOpening){
- end = 0;
+ //end = 0;
+
for(auto &d : dfp){
- if(a != 0){
- if(dfp[a-1]>50)d+=1.65*deltaTime;
- }else{
- d += 1.65*deltaTime;
- }
+ if(!a || dfp[a - 1] > 50)
+ d += 1.65 * deltaTime;
if(d >= range)
d = range;
a++;
}a=0;
- if(end < numSlot)invOpen=true;
- }else if(!invOpening){
+
+ // if(end < numSlot)
+ if(numSlot > 0)invOpen=true;
+ }else{
for(auto &d : dfp){
if(d > 0){
- d-=1.65*deltaTime;
+ d -= 1.65 * deltaTime;
}else end++;
}
- if(end >= numSlot)invOpen=false;
+ if(end >= numSlot)
+ invOpen = false;
}
+
+ /*
+ * a = 0
+ */
+
if(invOpen){
+
for(auto &r : iray){
- angle=180-(angleB*a) - angleB/2.0f;
+ angle = 180 - (angleB * a) - angleB / 2.0f;
curCoord[a].x += float((dfp[a]) * cos(angle*PI/180));
curCoord[a].y += float((dfp[a]) * sin(angle*PI/180));
r.end = curCoord[a];
glColor4f(0.0f, 0.0f, 0.0f, ((float)dfp[a]/(float)(range?range:1))*0.5f);
glBegin(GL_QUADS);
- glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2));
- glVertex2i(r.end.x-(itemWide/2)+itemWide, r.end.y-(itemWide/2));
- glVertex2i(r.end.x-(itemWide/2)+itemWide, r.end.y-(itemWide/2)+itemWide);
- glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)+itemWide);
+ glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2));
+ glVertex2i(r.end.x-(itemWide/2)+itemWide,r.end.y-(itemWide/2));
+ glVertex2i(r.end.x-(itemWide/2)+itemWide,r.end.y-(itemWide/2)+itemWide);
+ glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)+itemWide);
glEnd();
- if(inv[a].count > 0){
+ if(!items.empty() && a < items.size() && items[a].count){
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, itemtex[inv[a].id]);
+ glBindTexture(GL_TEXTURE_2D, itemtex[items[a].id/*inv[a].id*/]);
glColor4f(1.0f, 1.0f, 1.0f, ((float)dfp[a]/(float)(range?range:1))*0.8f);
- glBegin(GL_QUADS);
- if(item[inv[a].id].height > item[inv[a].id].width){
- glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y-(itemWide/2));
- glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y-(itemWide/2));
- glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y+(itemWide/2));
- glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y+(itemWide/2));
+ glBegin(GL_QUADS);
+ if(itemMap[items[a].id]->height > itemMap[items[a].id]->width){//item[inv[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)item[inv[a].id].height/(float)item[inv[a].id].width));
- glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2), r.end.y-(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
- glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2), r.end.y+(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
- glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2), r.end.y+(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
+ 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);
- ui::putText(r.end.x-(itemWide/2),r.end.y-(itemWide*.9),"%s",item[inv[a].id].name);
- ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",inv[a].count);
+ ui::putText(r.end.x-(itemWide/2),r.end.y-(itemWide*.9),"%s",itemMap[items[a].id]->name);
+ ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",items[a].count);
}
+
a++;
- if(sel==a){
+
+ if(sel == a){
glBegin(GL_LINES);
glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
glVertex2i(r.start.x,r.start.y);
@@ -200,6 +297,8 @@ void Inventory::draw(void){
static unsigned int highlight = 0;
static unsigned int thing = 0;
+ std::cout<<"Inventory2???"<<std::endl;
+
if(!mouseSel){
mouseStart.x = ui::mouse.x - offset.x;
highlight = sel;
@@ -243,41 +342,43 @@ void Inventory::draw(void){
glVertex2i(r.end.x-(itemWide/2), r.end.y+(itemWide/2));
glEnd();
- if(inv[a].count > 0){
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, itemtex[inv[a].id]);
- glColor4f(1.0f, 1.0f, 1.0f, a == highlight ? 0.8f : 0.2f);
- glBegin(GL_QUADS);
- if(item[inv[a].id].height > item[inv[a].id].width){
- glTexCoord2i(0,1);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y-(itemWide/2));
- glTexCoord2i(1,1);glVertex2i(r.end.x+((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y-(itemWide/2));
- glTexCoord2i(1,0);glVertex2i(r.end.x+((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y+(itemWide/2));
- glTexCoord2i(0,0);glVertex2i(r.end.x-((itemWide/2)*((float)item[inv[a].id].width/(float)item[inv[a].id].height)), r.end.y+(itemWide/2));
- }else{
- glTexCoord2i(0,1);glVertex2i(r.end.x-(itemWide/2), r.end.y-(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
- glTexCoord2i(1,1);glVertex2i(r.end.x+(itemWide/2), r.end.y-(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
- glTexCoord2i(1,0);glVertex2i(r.end.x+(itemWide/2), r.end.y+(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
- glTexCoord2i(0,0);glVertex2i(r.end.x-(itemWide/2), r.end.y+(itemWide/2)*((float)item[inv[a].id].height/(float)item[inv[a].id].width));
- }
- glEnd();
- glDisable(GL_TEXTURE_2D);
- //ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/1.75),"%d",inv[a].count);
- }
+ 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);
+ //ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/1.75),"%d",inv[a].count);
+
a++;
}
- if(inv[highlight].count > 0)ui::putStringCentered(player->loc.x+player->width/2, player->loc.y + range*.75,item[inv[highlight].id].name);
+ ui::putStringCentered(player->loc.x+player->width/2, player->loc.y + range*.75,itemMap[items[highlight].id]->name.c_str());
}
- if(inv[sel].count)itemDraw(player,inv[sel].id,item[inv[sel].id].type);
+
+ if(!items.empty() && items[sel].count)
+ itemDraw(player,items[sel].id);
lop++;
}
-void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
+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;
- switch(type){
- case SWORD:
+
+ if(itemMap[id]->type == "Sword"){
if(p->left){
if(hangle < 15){
hangle=15.0f;
@@ -291,10 +392,8 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
//swing=false;
}
}
- break;
- default:
- hangle = 0.0f;
- }
+ }else hangle = 0.0f;
+
glUseProgram(shaderProgram);
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glTranslatef(itemLoc.x,itemLoc.y,0);
@@ -304,10 +403,10 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
glBindTexture(GL_TEXTURE_2D,itemtex[id]);
glColor4ub(255,255,255,255);
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2f(itemLoc.x, itemLoc.y);
- glTexCoord2i(1,1);glVertex2f(itemLoc.x+item[id].width,itemLoc.y);
- glTexCoord2i(1,0);glVertex2f(itemLoc.x+item[id].width,itemLoc.y+item[id].height);
- glTexCoord2i(0,0);glVertex2f(itemLoc.x, itemLoc.y+item[id].height);
+ glTexCoord2i(0,1);glVertex2f(itemLoc.x, itemLoc.y);
+ glTexCoord2i(1,1);glVertex2f(itemLoc.x+itemMap[id]->width,itemLoc.y);
+ glTexCoord2i(1,0);glVertex2f(itemLoc.x+itemMap[id]->width,itemLoc.y+itemMap[id]->height);
+ glTexCoord2i(0,0);glVertex2f(itemLoc.x, itemLoc.y+itemMap[id]->height);
glEnd();
glDisable(GL_TEXTURE_2D);
glTranslatef(player->loc.x*2,0,0);
@@ -317,10 +416,11 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){
int Inventory::useItem(void){
static bool up = false;
- ITEM_TYPE type = item[inv[sel].id].type;
+ //ITEM_TYPE type = item[inv[sel].id].type;
if(!invHover){
- switch(type){
- case SWORD:
+
+ if(itemMap[items[sel].id]->type == "Sword"){
+
if(swing){
if(!player->left){
if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);}
@@ -345,28 +445,30 @@ int Inventory::useItem(void){
swing=true;
Mix_PlayChannel(2,swordSwing,0);
}
- break;
- default:
//hangle++;
- break;
+ //break;
}
}
return 0;
}
bool Inventory::detectCollision(vec2 one, vec2 two){
- float i = 0.0f;
- if(item[inv[sel].id].type == SWORD){
- while(i<item[inv[sel].id].height){
+ //float i = 0.0f;
+
+ /*if(items.empty() || !items[sel].count)
+ return false;
+ if(itemMap[items[sel].id]->type == "Sword"){
+ std::cout<<"Collision???"<<std::endl;
+ while(i<itemMap[items[sel].id]->height){
xc = itemLoc.x; yc = itemLoc.y;
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){
@@ -376,7 +478,7 @@ bool Inventory::detectCollision(vec2 one, vec2 two){
i+=HLINE;
}
- }
- return false;
+ }*/
+ return !(one.x == two.y);
}
diff --git a/src/ui.cpp b/src/ui.cpp
index 1520e9f..28b8314 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -806,6 +806,7 @@ DONE:
setFontSize(16);
toggleBlack();
}
+
dialogBoxExists = false;
}
void handleEvents(void){
@@ -828,12 +829,10 @@ DONE:
premouse.y=e.motion.y;
break;
case SDL_MOUSEBUTTONDOWN:
- if((e.button.button&SDL_BUTTON_RIGHT)&&dialogBoxExists){
+ if((e.button.button & SDL_BUTTON_RIGHT) && dialogBoxExists)
dialogAdvance();
- }
- if((e.button.button&SDL_BUTTON_LEFT)&&!dialogBoxExists){
+ if((e.button.button & SDL_BUTTON_LEFT) && !dialogBoxExists)
player->inv->usingi = true;
- }
break;
/*
KEYDOWN
diff --git a/src/world.cpp b/src/world.cpp
index c8b4bde..df0f0ac 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -284,9 +284,9 @@ void World::update(Player *p,unsigned int delta){
p->loc.y += p->vel.y * delta;
p->loc.x +=(p->vel.x * p->speed) * delta;
- if(p->inv->usingi){
+ /*if(p->inv->usingi){
p->inv->useItem();
- }
+ }*/
/*
* Update coordinates of all entities except for structures.
@@ -1001,8 +1001,8 @@ void World::addNPC(float x,float y){
entity.push_back(npc.back());
}
-void World::addObject(ITEM_ID i,const char *p, float x, float y){
- object.push_back(new Object(i,p));
+void World::addObject(/*ITEM_ID i*/std::string in,const char *p, float x, float y){
+ object.push_back(new Object(in,p));
object.back()->spawn(x,y);
entity.push_back(object.back());
diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml
index 7911bfd..6fe220c 100644
--- a/xml/playerSpawnHill1.xml
+++ b/xml/playerSpawnHill1.xml
@@ -38,6 +38,6 @@
<text id="1" >
My name's Johnny.
- <give id="0" count="1" />
+ <give id="Dank Maymay" count="1" />
</text>
</Dialog>