- player can now complete assigned requests
- player's name is displayed
- improved gravity so entities don't shake on the ground
+
+10/2/2015:
+==========
+
+ - added a basic inventory
+ - quests can reward one type of item (but any quantity of that item)
+ - added texture loading, began working on player textures
- have basic quest handling/player can interact with NPCs to take quests
- have basic mobs/animals
-...
+End of November:
+================
+
+ - have a working player inventory
+ - receive items from things like quests and mobs
+ - weapons n stuff
+
+End of December:
+================
+
+ - have a basic world scripter thing to script worlds
+ - create world saving/loading functionality
+ (maybe work on prettying up inventory/save-load/quest stuff)
+
+January - February:
+===================
+
+ - work on a story line
+
+February - March:
+=================
+
+ - work on sound effects / background music
End of March:
=============
===========
- Have game fully deployed with a way to receive feedback from the players
+
#include <cstdlib>\r
#include <cstring>\r
\r
+#include <inventory.h>\r
+\r
#define TOTAL_QUESTS 1\r
\r
class Quest {\r
public:\r
char *title,*desc;\r
- unsigned int reward;\r
- Quest(const char *t,const char *d,unsigned int r);\r
+ struct item_t reward;\r
+ Quest(const char *t,const char *d,struct item_t r);\r
~Quest();\r
};\r
\r
std::vector<const Quest *>current;\r
int assign(const char *t);\r
int drop(const char *t);\r
- int finish(const char *t);\r
+ int finish(const char *t,void *completer);\r
bool hasQuest(const char *t);\r
};\r
\r
#define ENTITIES_H
#include <common.h>
+#include <inventory.h>
#define NPCp(n) ((NPC *)n)
+#define PLAYER_INV_SIZE 30 // The size of the player's inventory
+#define NPC_INV_SIZE 3 // Size of an NPC's inventory
+
extern FILE* names;
class Entity{
public:
+ Inventory *inv;
+
void *inWorld;
+
float width; //width and height of the player
float height;
float speed; //speed of the play
- //type and subtype
+
int subtype;
_TYPE type;
//example:
// |(subtype)
// |-> 0 Base NPC
// |-> 1 Merchant
+
vec2 loc; //location and velocity of the entity
vec2 vel;
+
bool near;
bool right,left, canMove; //movement variables
bool alive; //the flag for whether or not the entity is alive
--- /dev/null
+#ifndef INVENTORY_H
+#define INVENTORY_H
+
+#include <cstdlib>
+
+enum ITEM_ID { // Contains item IDs for every item in the game, this is how items are stored. IDs are also used to lookup item strings
+ TEST_ITEM = 1 // A test item (duh)
+};
+
+struct item_t { // Used to define entries in an entity's inventory
+ short count; // Quantity of the item in this slot
+ ITEM_ID id; // ID of the item
+} __attribute__ ((packed));
+
+class Inventory {
+private:
+ unsigned int size; // Size of 'item' array
+ struct item_t *item; // An array of the items contained in this inventory.
+public:
+ Inventory(unsigned int s); // Creates an inventory of size 's'
+ ~Inventory(void); // Free's 'item'
+
+ 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
+
+ void draw(void); // Draws a text list of items in this inventory (should only be called for the player for now)
+};
+
+#endif // INVENTORY_H
#include <Quest.h>\r
+#include <entities.h>\r
\r
const Quest QuestList[TOTAL_QUESTS]={\r
- Quest("Test","A test quest",0)\r
+ Quest("Test","A test quest",(struct item_t){1,TEST_ITEM})\r
};\r
\r
-Quest::Quest(const char *t,const char *d,unsigned int r){\r
+Quest::Quest(const char *t,const char *d,struct item_t r){\r
size_t len;\r
title=(char *)malloc((len=strlen(t)));\r
strncpy(title,t,len);\r
desc=(char *)malloc((len=strlen(d)));\r
strncpy(desc,d,len);\r
- reward=r;\r
+ memcpy(&reward,&r,sizeof(struct item_t));\r
}\r
\r
Quest::~Quest(){\r
free(title);\r
free(desc);\r
- reward=0;\r
+ memset(&reward,0,sizeof(struct item_t));\r
}\r
\r
int QuestHandler::assign(const char *t){\r
return -1;\r
}\r
\r
-int QuestHandler::finish(const char *t){\r
+int QuestHandler::finish(const char *t,void *completer){\r
unsigned char i;\r
unsigned int r;\r
for(i=0;i<current.size();i++){\r
if(!strcmp(current[i]->title,t)){\r
- r=current[i]->reward;\r
+ ((Entity *)completer)->inv->addItem(current[i]->reward.id,current[i]->reward.count);\r
current.erase(current.begin()+i);\r
- return r;\r
+ return 0;\r
}\r
}\r
return -1;\r
alive = true;
ground = false;
near = true;
+ inv = new Inventory(PLAYER_INV_SIZE);
}
void Player::interact(){ //the function that will cause the player to search for things to interact with
alive = true;
canMove = true;
near = false;
+ inv = new Inventory(NPC_INV_SIZE);
}
void NPC::addAIFunc(int (*func)(NPC *)){
int compTestQuest(NPC *speaker){
if(player->qh.hasQuest("Test")){
ui::dialogBox(speaker->name,"Ooo, that's a nice quest you got there. Lemme finish that for you ;).");
- player->qh.finish("Test");
+ player->qh.finish("Test",player);
return 0;
}else{
ui::dialogBox(speaker->name,"You need to get a quest from %s first.",entity[1]->name);
switch(i){
case 1:
NPCp(entity[i])->addAIFunc(giveTestQuest);
+ entity[i]->inv->addItem(TEST_ITEM,3);
break;
case 2:
NPCp(entity[i])->addAIFunc(compTestQuest);
--- /dev/null
+#include <inventory.h>
+#include <ui.h>
+
+const char *itemName[]={
+ "\0",
+ "Dank Maymay"
+};
+
+Inventory::Inventory(unsigned int s){
+ size=s;
+ item=(struct item_t *)calloc(size,sizeof(struct item_t));
+}
+
+Inventory::~Inventory(void){
+ free(item);
+}
+
+int Inventory::addItem(ITEM_ID id,unsigned char count){
+ unsigned int i;
+ for(i=0;i<size;i++){
+ if(item[i].id==id){
+ item[i].count+=count;
+ return 0;
+ }else if(!item[i].count){
+ item[i].id=id;
+ item[i].count=count;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+int Inventory::takeItem(ITEM_ID id,unsigned char count){
+ unsigned int i;
+ for(i=0;i<size;i++){
+ if(item[i].id==id){
+ item[i].count-=count;
+ if(item[i].count<0)
+ return item[i].count*-1;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+#include <entities.h>
+extern Player *player;
+
+void Inventory::draw(void){
+ unsigned int i=0;
+ float y=SCREEN_HEIGHT/2;
+ ui::putText(player->loc.x-SCREEN_WIDTH/2,y,"Inventory:");
+ while(item[i].count){
+ y-=ui::fontSize*1.15;
+ ui::putText(player->loc.x-SCREEN_WIDTH/2,y,"%d x %s",item[i].count,itemName[(unsigned)item[i].id]);
+ i++;
+ }
+}
glColor3ub(0,0,0);
player->near=true;
player->draw(); // Draw the player
+ player->inv->draw();
+
+ ui::draw(); // Draw any UI elements if they need to be
if(ui::debug){
static unsigned int debugDiv=0;
fps,d,player->ground,SCREEN_WIDTH,SCREEN_HEIGHT,entity.size(),player->loc.x,rndy,player->qh.current.size());
}
- ui::draw(); // Draw any UI elements if they need to be
-
for(int i=0;i<=entity.size();i++){
//entity[i]->draw();
entity[i]->loc.x += entity[i]->vel.x * deltaTime;