- began working on pages, made sprite and handler
- GLSL shaders are better
- redid theme_jazz
+
+12/21/2015:
+===========
+
+ - fixed dialog options issues, finished basic pages
+ - added World::getAvailableNPC() for easy quest assigner assigning
+ - added the Condition class, so that events and actions can be remembered by NPCs
+ - added functionality for multiple lights (GLSL)
*/
extern unsigned int loops;
+/**
+ * This class contains a string for identification and a value. It can be used to
+ * save certain events for and decisions so that they can be recalled later.
+ */
+
+class Condition {
+private:
+ char *id;
+ void *value;
+public:
+ Condition(const char *_id,void *val);
+ ~Condition();
+
+ bool sameID(const char *s);
+ void *getValue(void);
+};
+
/**
* Prints a formatted debug message to the console, along with the callee's file and line
* number.
void addNPC(float x,float y);
void addObject(ITEM_ID, bool, const char *, float, float);
void addParticle(float, float, float, float, float, float, Color color, int);
+
+ NPC *getAvailableNPC(void);
+
+ /*
+ * Update coordinates of all entities.
+ */
void update(Player *p,unsigned int delta);
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 <fstream>
+#include <istream>
#include <thread>
#include <common.h>
* referenced in src/entities.cpp for getting random names.
*/
-FILE *names;
+std::istream *names;
/*
* loops is used for texture animation. It is believed to be passed to entity
*
*/
- names = fopen("assets/names_en-us", "r+");
+ static std::filebuf fb;
+ fb.open("assets/names_en-us",std::ios::in);
+ names = new std::istream(&fb);
+
crickets=Mix_LoadWAV("assets/sounds/crickets.wav");
//Mix_Volume(2,25);
Mix_HaltMusic();
- fclose(names);
+ fb.close();
SDL_GL_DeleteContext(mainGLContext);
SDL_DestroyWindow(window);
#include <common.h>
+#include <cstring>
#include <cstdio>
#include <chrono>
#endif // __WIN32__
+Condition::Condition(const char *_id,void *val){
+ id = new char[strlen(_id)+1];
+ strcpy(id,_id);
+ value = val;
+}
+Condition::~Condition(){
+ delete[] id;
+}
+
+bool Condition::sameID(const char *s){
+ return !strcmp(id,s);
+}
+void *Condition::getValue(void){
+ return value;
+}
+
void DEBUG_prints(const char* file, int line, const char *s,...){
va_list args;
printf("%s:%d: ",file,line);
#include <entities.h>
#include <ui.h>
+#include <istream>
//#include <unistd.h>
-extern FILE* names;
+extern std::istream *names;
extern unsigned int loops;
extern World *currentWorld;
extern const char *itemName;
-extern
-
void getRandomName(Entity *e){
- int tempNum,max=0;
+ unsigned int tempNum,max=0;
char *bufs;
- rewind(names);
+ names->seekg(0,names->beg);
- bufs = new char[16]; //(char *)malloc(16);
+ bufs = new char[32];
- for(;!feof(names);max++){
- fgets(bufs,16,(FILE*)names);
- }
+ for(;!names->eof();max++)
+ names->getline(bufs,32);
tempNum = rand() % max;
- rewind(names);
+ names->seekg(0,names->beg);
- for(int i=0;i<tempNum;i++){
- fgets(bufs,16,(FILE*)names);
- }
+ for(unsigned int i=0;i<tempNum;i++)
+ names->getline(bufs,32);
- switch(fgetc(names)){
+ switch(bufs[0]){
+ default :
case 'm': e->gender = MALE; break;
case 'f': e->gender = FEMALE;break;
- default : break;
}
- if((fgets(bufs,16,(FILE*)names)) != NULL){
- bufs[strlen(bufs)] = '\0';
- strcpy(e->name,bufs);
- if(e->name[strlen(e->name)-1] == '\n')
- e->name[strlen(e->name)-1] = '\0';
- }
+ strcpy(e->name,bufs+1);
delete[] bufs;
}
}
}
- name = new char[16];
+ name = new char[32];
getRandomName(this);
}
}
break;
case MS_PAGE:
- if(ui::mouse.x > loc.x &&
- ui::mouse.x < loc.x + width &&
+ if(player->loc.x > loc.x - 100 &&
+ player->loc.x < loc.x + 100 &&
+ ui::mouse.x > loc.x &&
+ ui::mouse.x < loc.x + width &&
+ ui::mouse.y > loc.y - width / 2 &&
+ ui::mouse.y < loc.y + width * 1.5 &&
SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)){
if(speed != 666){
speed = 666;
callee->alive = false;
}
+/*
+ * Gens
+ */
+
float gen_worldSpawnHill1(float x){
return (float)(pow(2,(-x+200)/5) + GEN_MIN);
}
*/
void worldSpawnHill1_hillBlock(Mob *callee){
- std::cout<<"oi";
player->vel.x = 0;
player->loc.x = callee->loc.x + callee->width;
ui::dialogBox(player->name,NULL,false,"This hill seems to steep to climb up...");
static Arena *a;
void worldSpawnHill2_infoSprint(Mob *callee){
- ui::dialogBox(player->name,":Nah:Sure",false,"This page would like to take you somewhere.");
+ ui::dialogBox(player->name,":Sure:Nah",false,"This page would like to take you somewhere.");
ui::waitForDialog();
switch(ui::dialogOptChosen){
case 1:
//ui::dialogBox("B-) ",NULL,true,"Press \'Shift\' to run!");
}
-void worldSpawnHill3_itemGet(Mob *callee){
- ui::dialogBox("B-) ",NULL,true,"Right click to pick up items!");
- callee->alive = false;
-}
-
-void worldSpawnHill3_itemSee(Mob *callee){
- ui::dialogBox("B-) ",NULL,true,"Press \'e\' to open your inventory!");
- callee->alive = false;
+int worldSpawnHill2_Quest2(NPC *callee){
+ ui::dialogBox(callee->name,NULL,false,"Yo.");
+ ui::waitForDialog();
+ return 0;
}
-void worldSpawnHill3_leave(Mob *callee){
- ui::dialogBox("B-) ",NULL,true,"Now jump in this hole, and let your journey begin :)");
- callee->alive = false;
+int worldSpawnHill2_Quest1(NPC *callee){
+ ui::dialogBox(callee->name,":Cool.",false,"Did you know that I\'m the coolest NPC in the world?");
+ ui::waitForDialog();
+ if(ui::dialogOptChosen == 1){
+ ui::dialogBox(callee->name,NULL,false,"Yeah, it is.");
+ currentWorld->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest2,true);
+ ui::waitForDialog();
+ return 0;
+ }
+ return 1;
}
/*
worldSpawnHill3->generateFunc(1000,gen_worldSpawnHill3);
worldSpawnHill3->setBackground(BG_FOREST);
worldSpawnHill3->setBGM("assets/music/ozone.wav");
- worldSpawnHill3->addMob(MS_TRIGGER,-500,0,worldSpawnHill3_itemGet);
- worldSpawnHill3->addMob(MS_TRIGGER,0,0,worldSpawnHill3_itemSee);
- worldSpawnHill3->addObject(TEST_ITEM,false,"",-200,300);
- worldSpawnHill3->addMob(MS_TRIGGER,650,0,worldSpawnHill3_leave);
worldSpawnHill3->addHole(800,1000);
worldSpawnHill1->toRight = worldSpawnHill2;
worldSpawnHill2_Building1->setBGM("assets/music/theme_jazz.wav");
worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill2_Building1);
+ worldSpawnHill2->getAvailableNPC()->addAIFunc(worldSpawnHill2_Quest1,false);
player = new Player();
player->spawn(200,100);
}
}while(s[++i]);
- return putString(x-width/2,y,s);
+ putString(x-width/2,y,s);
+ return width;
}
/*
}
void draw(void){
unsigned char i;
- float x,y;
+ float x,y,tmp;
char *rtext;
if(dialogBoxExists){
for(i=0;i<dialogOptCount;i++){
setFontColor(255,255,255);
- dialogOptLoc[i][1]=y-SCREEN_HEIGHT/4+(fontSize+HLINE)*(i+1);
- dialogOptLoc[i][2]=
- putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
- dialogOptLoc[i][0]=offset.x-dialogOptLoc[i][2]/2;
+ tmp = putStringCentered(offset.x,dialogOptLoc[i][1],dialogOptText[i]);
+ dialogOptLoc[i][2] = offset.x + tmp;
+ dialogOptLoc[i][0] = offset.x - tmp;
+ dialogOptLoc[i][1] = y - SCREEN_HEIGHT / 4 + (fontSize + HLINE) * (i + 1);
if(mouse.x > dialogOptLoc[i][0] &&
- mouse.x < dialogOptLoc[i][0] + dialogOptLoc[i][2] &&
+ mouse.x < dialogOptLoc[i][2] &&
mouse.y > dialogOptLoc[i][1] &&
mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize
setFontColor(255,255,0);
behind->bgTex=bgTex;
}
+NPC *World::getAvailableNPC(void){
+ for(auto &n : npc){
+ if(n->aiFunc.empty())
+ return n;
+ }
+ return (NPC *)NULL;
+}
+
World *World::goWorldLeft(Player *p){
if(toLeft&&p->loc.x<x_start+HLINE*15){
p->loc.x=toLeft->x_start+getWidth(toLeft)-HLINE*10;