--- /dev/null
+ID DEBUG_ITEM
+ NAME "Debug"
+ TYPE TOOL
+ WIDTH 1
+ HEIGHT 1
+ STACKSIZE 1
+ TEX "assets/items/ITEM_TEST.png"
+ ENI
+
+ID TEST_ITEM
+ NAME "Dank MayMay"
+ TYPE TOOL
+ WIDTH HLINE
+ HEIGHT HLINE
+ STACKSIZE 420
+ TEX "assets/items/ITEM_TEST.png"
+ ENI
+
+ID PLAYER_BAG
+ NAME "Your Bag"
+ TYPE EQUIP
+ WIDTH HLINE*5
+ HEIGHT HLINE*5
+ STACKSIZE 1
+ TEX "assets/items/ITEM_TEST.png"
+ ENI
+
+ID FLASHLIGHT
+ NAME "Flashlight"
+ TYPE TOOL
+ WIDTH HLINE*2
+ HEIGHT HLINE*4
+ STACKSIZE 1
+ TEX "assets/items/ITEM_TEST.png"
+ ENI
+
+ID SWORD_WOOD
+ NAME "Wood Sword"
+ TYPE SWORD
+ WIDTH HLINE*4
+ HEIGHT HLINE*10
+ STACKSIZE 1
+ TEX "assets/items/ITEM_SWORD.png"
+ STOP
\ No newline at end of file
-TITLE "Test" DESC "A test quest" REWARD 1 x SWORD_ITEM END
+TITLE "Test" DESC "A test quest" REWARD 1 x TEST_ITEM END
class Object : public Entity{
public:
Object(int);
+ Object(int, bool, char*);
void interact();
+ bool questObject = false;
+ char *pickupDialog;
private:
- int ID;
+ int identifier;
};
#endif // ENTITIES_H
#define DEBUG
+#define ID Item(
+#define NAME ,
+#define TYPE ,
+#define WIDTH ,
+#define HEIGHT ,
+#define STACKSIZE ,
+#define TEX ,
+#define ENI ),
+#define STOP )
+
/*
* A list of all item IDs.
*/
+static unsigned int sel;
+
enum ITEM_ID {
+ DEBUG_ITEM = 69,
TEST_ITEM = 1,
- SWORD_ITEM = 2
+ PLAYER_BAG = 2,
+ FLASHLIGHT = 3,
+ SWORD_WOOD = 4
+};
+
+enum ITEM_TYPE{
+ TOOL = 1,
+ SWORD = 2,
+ RANGED = 3,
+ EQUIP = 4,
+ FOOD = 5
};
-struct item_t { // Used to define entries in an entity's inventory
- short count; // Quantity of the item in this slot
+class Item{
+protected:
+public:
+ friend class Inventory;
+ friend unsigned int initInventorySprites(void);
ITEM_ID id; // ID of the item
-} __attribute__ ((packed));
+ char *name;
+ ITEM_TYPE type; // What category the item falls under
+ float width;
+ float height;
+ int maxStackSize;
+ char* textureLoc;
+ int count;
+ Item(ITEM_ID i, char* n, ITEM_TYPE t, float w, float h, int m, char* tl):
+ id(i), name(n), type(t), width(w), height(h), maxStackSize(m), textureLoc(tl){
+ count = 0;
+ }
+ void addCount(int c){
+ count += c;
+ }
+
+};
+
+static Item item[5]= {
+ #include "../config/items.h"
+};
+
+struct item_t{
+ int count;
+ ITEM_ID itmid;
+ void addC(int c, ITEM_ID i){
+ count = c;
+ itmid = i;
+ item[itmid].addCount(count);
+ }
+} __attribute__((packed));
+
class Inventory {
private:
- unsigned int sel;
unsigned int size; // Size of 'item' array
- struct item_t *item; // An array of the items contained in this inventory.
+ //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'
void addMob(int t,float x,float y);
void addNPC(float x,float y);
void addObject(int, float, float);
+ void addObject(int, bool, char*, float, float);
+
//void removeObjet(Object);
+/*! @file main.cpp
+ @brief The file that links everything together for the game to run.
+ The main game loop contains all of the global variables the game uses, and it runs the main game loop, the render loop, and the logic loop that control all of the entities.
+*/
+
#include <cstdio> // fopen
#include <chrono> // see millis()
*
*/
-static GLuint bgDay, bgNight, bgMtn, bgTreesFront, bgTreesMid, bgTreesFar;
+GLuint bgDay, bgNight, bgMtn, bgTreesFront, bgTreesMid, bgTreesFar, invUI;
/*
* gameRunning
* everything can be moved according to the player
*/
-vec2 offset; /** OFFSET!!!!!!!!!!!!!!!!!!!! **/
+vec2 offset; /* OFFSET!!!!!!!!!!!!!!!!!!!! */
-/*
+/**
* millis
*
* We've encountered many problems when attempting to create delays for triggering
* by <chrono> in the standard C++ library. This function simply returns the amount
* of milliseconds that have passed sine the epoch.
*
-*/
+**/
#ifdef __WIN32__
#define millis() SDL_GetTicks()
static WEATHER weather = SUNNY;
static vec2 star[100];
+static unsigned char fadeIntensity = 0;
/*******************************************************************************
int main(int argc, char *argv[]){
gameRunning=false;
- /*
+ /*!
* (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
* make openGL calls. Exit if there was an error.
*/
// Run SDL_Quit when main returns
atexit(SDL_Quit);
- /*
+ /**`
* (Attempt to) Initialize SDL_image libraries with IMG_INIT_PNG so that we can load PNG
* textures for the entities and stuff.
- */
+ **/
if(!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)){
std::cout << "Could not init image libraries! Error: " << IMG_GetError() << std::endl;
// Run IMG_Quit when main returns
atexit(IMG_Quit);
- /*
+ /**
* (Attempt to) Initialize SDL_mixer libraries for loading and playing music/sound files.
*
- */
+ **/
if(Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0){
std::cout << "SDL_mixer could not initialize! Error: " << Mix_GetError() << std::endl;
* src/gameplay.cpp
*
*/
-
+ fadeIntensity = 254;
initEverything();
/*
bgTreesFront =Texture::loadTexture("assets/bgFrontTree.png" );
bgTreesMid =Texture::loadTexture("assets/bgMidTree.png" );
bgTreesFar =Texture::loadTexture("assets/bgFarTree.png" );
+ invUI =Texture::loadTexture("assets/invUI.png" );
/*
* Load sprites used in the inventory menu. See src/inventory.cpp
*/
+ std::cout << "Before invSprites\n";
initInventorySprites();
+ std::cout << "After invSprites\n";
/*
* Generate coordinates for stars that are drawn at night.
/**************************
**** GAMELOOP ****
**************************/
-
gameRunning=true;
while(gameRunning){
mainLoop();
/*
* Run the logic handler if MSEC_PER_TICK milliseconds have passed.
*/
-
if(prevPrevTime + MSEC_PER_TICK >= currentTime){
logic();
prevPrevTime = currentTime;
}
extern bool fadeEnable;
-static unsigned char fadeIntensity = 0;
void render(){
glUseProgramObjectARB(0);
#endif //SHADERS
- if(player->light){
- handAngle = atan((ui::mouse.y - (player->loc.y + player->height/2)) / (ui::mouse.x - player->loc.x + player->width/2))*180/PI;
- if(ui::mouse.x < player->loc.x){
- if(handAngle <= 0)
- handAngle+=180;
- if(ui::mouse.y < player->loc.y + player->height/2){
- handAngle+=180;
- }
+ handAngle = atan((ui::mouse.y - (player->loc.y + player->height/2)) / (ui::mouse.x - player->loc.x + player->width/2))*180/PI;
+ if(ui::mouse.x < player->loc.x){
+ if(handAngle <= 0)
+ handAngle+=180;
+ if(ui::mouse.y < player->loc.y + player->height/2){
+ handAngle+=180;
}
- if(ui::mouse.x > player->loc.x && ui::mouse.y < player->loc.y+player->height/2 && handAngle <= 0) handAngle = 360+handAngle;
+ }
+ if(ui::mouse.x > player->loc.x && ui::mouse.y < player->loc.y+player->height/2 && handAngle <= 0) handAngle = 360+handAngle;
+ //if(ui::mouse.x < player->loc.x + (player->width/2)){player->left = true;player->right=false;}
+ //if(ui::mouse.x >= player->loc.x + (player->width/2)){player->right = true;player->left=false;}
+ if(player->light){
vec2 light;
int lightStr = 150;
vec2 curCoord;
curCoord.y += float((HLINE) * sin(angle*PI/180));
}
for(auto &en : currentWorld->entity){
- if(curCoord.x > en->loc.x && curCoord.x < en->loc.x + en->width){
+ if(curCoord.x > en->loc.x && curCoord.x < en->loc.x + en->width && en->type!=STRUCTURET){
if(curCoord.y > en->loc.y && curCoord .y < en->loc.y + en->height){
r.end = curCoord;
l=lightStr;
*
*/
+ if((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) && !ui::dialogBoxExists)player->inv->useItem();
+
for(auto &n : currentWorld->npc){
if(n->alive){
/*
unsigned int i = 0;
for(auto &o : currentWorld->object){
if(o->alive){
- if(pow((o->loc.x - player->loc.x),2) + pow((o->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
+ 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
o->interact();
}
}
+ }
}
if(!(o->alive)){
currentWorld->object.erase(currentWorld->object.begin()+i);
#ifdef DEBUG\r
DEBUG_printf("Completing quest %s.\n",t);\r
#endif // DEBUG\r
- ((Entity *)completer)->inv->addItem(current[i]->reward.id,current[i]->reward.count);\r
+ ((Entity *)completer)->inv->addItem(current[i]->reward.itmid,current[i]->reward.count);\r
current.erase(current.begin()+i);\r
#ifdef DEBUG\r
DEBUG_printf("QuestHandler now has %u active quests.\n",current.size());\r
extern Player *player;
+extern const char *itemName;
+
void Entity::spawn(float x, float y){ //spawns the entity you pass to it based off of coords and global entity settings
loc.x = x;
loc.y = y;
inv = new Inventory(NPC_INV_SIZE);
}
-Object::Object(int id):ID(id){
+Object::Object(int id):identifier(id){
+ type = OBJECTT;
+ alive = true;
+ near = false;
+ width = HLINE * 8;
+ height = HLINE * 8;
+
+ maxHealth = health = 1;
+ tex = new Texturec(1, "assets/items/ITEM_SWORD.png");
+
+ questObject = false;
+ pickupDialog="\0";
+}
+
+Object::Object(int id, bool qo, char *pd):identifier(id),questObject(qo),pickupDialog(pd){
type = OBJECTT;
alive = true;
near = false;
default:
break;
}
- }else if(type == OBJECTT){
- tex->bind(0);
}else{
tex->bind(0);
}
}
}
+extern void waitForDialog(void);
void Object::interact(){
- this->alive = false;
- player->inv->addItem((ITEM_ID)(ID), (char)1);
+ if(questObject){
+ char opt[]=":No:Yes";
+ ui::dialogBox("You",opt,pickupDialog);
+ if(ui::dialogOptChosen == 1){
+ this->alive = false;
+ player->inv->addItem((ITEM_ID)(identifier), (char)1);
+ }
+ }else{
+ this->alive = false;
+ player->inv->addItem((ITEM_ID)(identifier), (char)1);
+ }
}
/*
extern World *currentWorld;
extern Player *player;
extern void mainLoop(void);
+extern SDL_Window *window;
+extern bool fadeEnable;
+
+void story(void){
+ for(int i=0;i<600;i++){
+ 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);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glEnable(GL_STENCIL_TEST);
+ glPushMatrix();
+
+ glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT );
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glColor4f(0.0f,0.0f,0.0f,0.0f);
+ glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT);
+ glColor4f(1.0f,1.0f,1.0f,1.0f);
+ ui::importantText("Oh hello, where are you?");
+ //ui::setFontSize(16);
+ //ui::putText(54,540,"BITC.");
+
+ glPopMatrix();
+ SDL_GL_SwapWindow(window);
+ }
+}
void waitForDialog(void){
do{
test->addMob(MS_RABBIT,200,100);
test->addMob(MS_BIRD,-500,500);
- currentWorld->addObject(2, 500,200);
-
+ currentWorld->addObject(SWORD_WOOD, 500,200);
+ currentWorld->addObject(FLASHLIGHT, true, "This looks important, do you want to pick it up?",600,200);
/*
* Link all the entities that were just created to the initial world, and setup a test AI function.
*/
currentWorld->npc[0]->addAIFunc(giveTestQuest,false);
-
}
#include <entities.h>
#include <ui.h>
-#define ITEM_COUNT 2 // Total number of items that actually exist
+#define ITEM_COUNT 5 // Total number of items that actually exist
extern Player *player;
-
-const char *itemName[]={
- "\0",
- "Dank Maymay",
- "Sword"
-};
-
-const char *ITEM_SPRITE[]={
- "\0", // Null
- "assets/items/ITEM_TEST.png", // Dank maymay
- "assets/items/ITEM_SWORD.png"
-};
+extern GLuint invUI;
GLuint *ITEM_TEX;
unsigned int i,loadCount=0;
ITEM_TEX=(GLuint *)calloc(ITEM_COUNT,sizeof(GLuint));
for(i=0;i<ITEM_COUNT;i++){
- if((ITEM_TEX[i]=Texture::loadTexture(ITEM_SPRITE[i+1])))loadCount++;
+ if((ITEM_TEX[i]=Texture::loadTexture(item[i].textureLoc)))loadCount++;
}
#ifdef DEBUG
DEBUG_printf("Loaded %u/%u item texture(s).\n",loadCount,ITEM_COUNT);
Inventory::Inventory(unsigned int s){
sel=0;
size=s;
- item=(struct item_t *)calloc(size,sizeof(struct item_t));
+ //item=(struct item_t *)calloc(size,sizeof(struct item_t));
tossd=false;
}
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;
-#ifdef DEBUG
- DEBUG_printf("Gave player %u more %s(s).\n",count,itemName[item[i].id]);
-#endif // DEBUG
+
+ #ifdef DEBUG
+ DEBUG_printf("Gave player %u more %s(s).\n",count,item[i].name);
+ #endif // DEBUG
+
return 0;
}else if(!item[i].count){
item[i].id=id;
item[i].count=count;
-#ifdef DEBUG
- DEBUG_printf("Gave player %u %s(s).\n",count,itemName[item[i].id]);
-#endif // DEBUG
+
+ #ifdef DEBUG
+ DEBUG_printf("Gave player %u %s(s).\n",count,item[i].name);
+ #endif // DEBUG
+
return 0;
}
}
+
#ifdef DEBUG
DEBUG_printf("Failed to add non-existant item with id %u.\n",id);
#endif // DEBUG
for(i=0;i<size;i++){
if(item[i].id==id){
#ifdef DEBUG
- DEBUG_printf("Took %u of player's %s(s).\n",count,itemName[item[i].id]);
+ DEBUG_printf("Took %u of player's %s(s).\n",count,item[i].name);
#endif // DEBUG
item[i].count-=count;
if(item[i].count<0)
void Inventory::draw(void){
unsigned int i=0;
float y=offset.y,xoff;
- ui::putText(offset.x-SCREEN_WIDTH/2,y,"Inventory:");
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, invUI);
+ glBegin(GL_QUADS);
+ glTexCoord2i(0,1);glVertex2i(offset.x-SCREEN_WIDTH/2, 0);
+ glTexCoord2i(1,1);glVertex2i(offset.x-SCREEN_WIDTH/2+261, 0);
+ glTexCoord2i(1,0);glVertex2i(offset.x-SCREEN_WIDTH/2+261, 57);
+ glTexCoord2i(0,0);glVertex2i(offset.x-SCREEN_WIDTH/2, 57);
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
while(item[i].count){
y-=HLINE*12;
xoff=ui::putText(offset.x-SCREEN_WIDTH/2,y,"%d x ",item[i].count);
glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,ITEM_TEX[item[i].id-1]);
+ glBindTexture(GL_TEXTURE_2D,ITEM_TEX[item[i].id]);
if(sel==i)glColor3ub(255,0,255);
else glColor3ub(255,255,255);
glBegin(GL_QUADS);
glTexCoord2i(0,0);glVertex2i(xoff ,y+HLINE*10);
glEnd();
y-=ui::fontSize*1.15;
- ui::putText(offset.x-SCREEN_WIDTH/2,y,"%s",itemName[(unsigned)item[i].id]);
+ ui::putText(offset.x-SCREEN_WIDTH/2,y,"%s",item[i].name);
glDisable(GL_TEXTURE_2D);
i++;
}
}
if(p->inv->tossd) yes=true;
glBegin(GL_QUADS);
- glTexCoord2i(0,1);glVertex2f(item_coord.x+p1.x,item_coord.y+p2.y);
- glTexCoord2i(1,1);glVertex2f(item_coord.x+p2.x,item_coord.y+p2.y);
- glTexCoord2i(1,0);glVertex2f(item_coord.x+p2.x,item_coord.y+p1.y);
- glTexCoord2i(0,0);glVertex2f(item_coord.x+p1.x,item_coord.y+p1.y);
+ glTexCoord2i(0,1);glVertex2f(item_coord.x+p->loc.x, item_coord.y+p->loc.y);
+ glTexCoord2i(1,1);glVertex2f(item_coord.x+item[sel].width+p->loc.x, item_coord.y+p->loc.y);
+ glTexCoord2i(1,0);glVertex2f(item_coord.x+item[sel].width+p->loc.x, item_coord.y+item[sel].height+p->loc.y);
+ glTexCoord2i(0,0);glVertex2f(item_coord.x+p->loc.x, item_coord.y+item[sel].height+p->loc.y);
glEnd();
glDisable(GL_TEXTURE_2D);
}
int Inventory::useItem(void){
ITEM_ID id = item[sel].id;
switch(id){
+ case SWORD_WOOD:
+
+ break;
default:
- ui::dialogBox(itemName[id],NULL,"You cannot use this item.");
+ ui::dialogBox(item[id].name,NULL,"You cannot use this item.");
break;
}
return 0;
width+=fontSize/2;
}else if(s[i]=='\b'){ // Handle backspaces?
// Why?
+ // Cuz
}else{
width+=ftexwh[i].x+fontSize*.1;
}
* Reset values if a new string is being passed.
*/
- if(!size || ((linc>15)&(strncmp(ret,str,15)))){
+ if(strncmp(ret,str,linc-1)){
memset(ret,0,512); // Zero the buffer
size=strlen(str); // Set the new target string size
linc=0; // Reset the incrementers
hub.y-=fontSize*1.15;
glRectf(hub.x,
hub.y,
- hub.x+(player->health/player->maxHealth)*100,
+ hub.x+(player->health/player->maxHealth)*130,
hub.y+12);
}
entity.push_back(object.back());
}
+void World::addObject(int i, bool q, char *p, float x, float y){
+ object.push_back(new Object(i,q, p));
+ object.back()->spawn(x,y);
+
+ entity.push_back(object.back());
+}
+
/*void World::removeObject(Object i){
object.delete(i);
}*/