diff options
-rw-r--r-- | assets/fountain1.png | bin | 0 -> 524 bytes | |||
-rw-r--r-- | assets/house2.png | bin | 0 -> 747 bytes | |||
-rw-r--r-- | include/common.h | 8 | ||||
-rw-r--r-- | include/entities.h | 48 | ||||
-rw-r--r-- | include/world.h | 5 | ||||
-rw-r--r-- | main.cpp | 26 | ||||
-rw-r--r-- | src/entities.cpp | 27 | ||||
-rw-r--r-- | src/gameplay.cpp | 20 | ||||
-rw-r--r-- | src/inventory.cpp | 42 | ||||
-rw-r--r-- | src/world.cpp | 74 |
10 files changed, 214 insertions, 36 deletions
diff --git a/assets/fountain1.png b/assets/fountain1.png Binary files differnew file mode 100644 index 0000000..46f7c44 --- /dev/null +++ b/assets/fountain1.png diff --git a/assets/house2.png b/assets/house2.png Binary files differnew file mode 100644 index 0000000..7404cd9 --- /dev/null +++ b/assets/house2.png diff --git a/include/common.h b/include/common.h index 095b3e3..31126d7 100644 --- a/include/common.h +++ b/include/common.h @@ -54,11 +54,17 @@ typedef struct { vec2 end; } Ray; +typedef struct{ + float red; + float green; + float blue; +} Color; + /** * Define the game's name (displayed in the window title). */ -#define GAME_NAME "Independent Study v.0.4 alpha" +#define GAME_NAME "Independent Study v.0.5 alpha - NOW WITH SOUND!" /** * The desired width of the game window. diff --git a/include/entities.h b/include/entities.h index dd3adab..141d29a 100644 --- a/include/entities.h +++ b/include/entities.h @@ -34,6 +34,50 @@ enum MOB_SUB { MS_TRIGGER }; +enum BUILD_SUB{ + TOWN_HALL = 1, + HOUSE, + HOUSE2, + HOUSE3, + HOUSE4, + FOUNTAIN +}; + +class Particles{ +public: + vec2 loc; + float width; + float height; + float velx; + float vely; + Color color; + int duration; + bool canMove; + Particles(float x, float y, float w, float h, float vx, float vy, Color c, int d){ + loc.x = (x); + loc.y = (y); + width = (w); + height = (h); + velx = vx; + vely = vy; + color.red = (c.red); + color.green = (c.green); + color.blue = (c.blue); + duration = d; + } + ~Particles(){} + void draw(){ + glColor3f(color.red,color.green,color.blue); + glRectf(loc.x,loc.y,loc.x+width,loc.y+height); + } + bool kill(float delta){ + duration -= delta; + if(duration <= 0) + return true; + else return false; + } +}; + class Entity{ public: Inventory *inv; @@ -58,6 +102,7 @@ public: bool canMove; // Enables movement bool right,left; // Direction faced by Entity bool alive; + bool hit; unsigned char ground; // Shows how the Entity is grounded (if it is) /* @@ -118,11 +163,12 @@ class Structures : public Entity{ public: void *inWorld; void *inside; + BUILD_SUB bsubtype; Structures(); ~Structures(); - unsigned int spawn(_TYPE, float, float); + unsigned int spawn(_TYPE, BUILD_SUB, float, float); }; class Mob : public Entity{ diff --git a/include/world.h b/include/world.h index 1e78cd0..4e02a08 100644 --- a/include/world.h +++ b/include/world.h @@ -164,12 +164,15 @@ public: std::vector<Mob *> mob; std::vector<Entity *> entity; std::vector<Object *> object; + std::vector<Particles *> particles; - void addStructure(_TYPE t,float x,float y,World *outside,World *inside); + void addStructure(_TYPE t,BUILD_SUB sub,float x,float y,World *outside,World *inside); + void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside,World *inside); void addMob(int t,float x,float y); void addMob(int t,float x,float y,void (*hey)(Mob *)); 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); void update(Player *p,unsigned int delta); @@ -515,7 +515,6 @@ void mainLoop(void){ debugDiv=0; fps=1000/deltaTime; - }else if(!(debugDiv%10)){ debugY = player->loc.y; } @@ -839,9 +838,16 @@ void logic(){ */ if(n->canMove) n->wander((rand() % 120 + 30)); - - if(player->inv->usingi && player->inv->detectCollision(vec2{n->loc.x, n->loc.y},vec2{n->loc.x+n->width,n->loc.y+n->height})){ - n->alive=false; + 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++) + currentWorld->addParticle(rand()%HLINE*3 + n->loc.x - .05f,n->loc.y + n->height*.5, HLINE,HLINE, -(rand()%10)*.01,((rand()%4)*.001-.002), {(rand()%75+10)/100.0f,0,0}, 10000); + if(n->health <= 0){ + 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. @@ -866,9 +872,7 @@ 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 - * radius (40 HLINEs) of the player's coordinates. - * + * 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)){ @@ -928,7 +932,7 @@ void logic(){ 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 ){ + ui::mouse.y <= o->loc.y + o->height ){ if(pow((o->loc.x - player->loc.x),2) + pow((o->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){ /* @@ -948,6 +952,12 @@ void logic(){ } } } + for(auto &b : currentWorld->build){ + if(b->bsubtype == FOUNTAIN){ + for(int r = 0; r < (rand()%20)+10;r++) + currentWorld->addParticle(rand()%HLINE*3 + b->loc.x + b->width/2,b->loc.y + b->height, HLINE,HLINE, rand()%2 == 0?-(rand()%7)*.01:(rand()%7)*.01,((4+rand()%6)*.05), {0,0,1.0f}, 2500); + } + } /* * Switch between day and night (SUNNY and DARK) if necessary. diff --git a/src/entities.cpp b/src/entities.cpp index 5c00cc7..9d0ea9b 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -10,6 +10,8 @@ extern Player *player; extern const char *itemName; +extern + void getRandomName(Entity *e){ int tempNum,max=0; char *bufs; @@ -57,6 +59,7 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o near = false; canMove = true; ground = false; + hit = false; ticksToUse = 0; @@ -116,12 +119,12 @@ NPC::~NPC(){ } Structures::Structures(){ //sets the structure type - health = maxHealth = 1; + health = maxHealth = 25; alive = false; near = false; - tex = new Texturec(1,"assets/house1.png"); + tex = new Texturec(3,"assets/house1.png", "assets/house2.png", "assets/fountain1.png"); inWorld = NULL; name = NULL; @@ -211,6 +214,7 @@ void Entity::draw(void){ //draws the entities static int texState = 0; static bool up = true; if(loops % (int)((float)4/(float)speed) == 0){ + //currentWorld->addParticle(loc.x,loc.y-HLINE,HLINE,HLINE,0,0,{0.0f,.17f,0.0f},1000); if(up){ if(++texState==2)up=false; tex->bindNext(); @@ -241,6 +245,19 @@ void Entity::draw(void){ //draws the entities break; } break; + case STRUCTURET: + for(auto &strt : currentWorld->build){ + if(this == strt){ + if(strt->bsubtype == HOUSE){ + tex->bind(0); + }else if(strt->bsubtype == HOUSE2){ + tex->bind(1); + }else if(strt->bsubtype == FOUNTAIN){ + tex->bind(2); + } + } + } + break; default: tex->bind(0); break; @@ -319,7 +336,8 @@ const char *randomDialog[] = { "Did you know this game has over 4000 lines of code? I didn\'t. I didn't even know I was in a game until now...", "HELP MY CAPS LOCK IS STUCK", "You know, if anyone ever asked me who I wanted to be when I grow up, I would say Abby Ross.", - "I want to have the wallpaper in our house changed. It doesn\'t really fit the environment." + "I want to have the wallpaper in our house changed. It doesn\'t really fit the environment.", + "Frig." }; void NPC::interact(){ //have the npc's interact back to the player @@ -368,7 +386,7 @@ void Object::interact(void){ * point to have non-normal traits so it could be invisible or invincible... */ -unsigned int Structures::spawn(_TYPE t, float x, float y){ +unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y){ loc.x = x; loc.y = y; type = t; @@ -377,6 +395,7 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ width = 50 * HLINE; height = 40 * HLINE; + bsubtype = sub; /* * tempN is the amount of entities that will be spawned in the village. Currently the village diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 74414d7..59320af 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -103,7 +103,7 @@ void initEverything(void){ worldSpawnHill2->setBackground(BG_FOREST); worldSpawnHill2->setBGM("assets/music/embark.wav"); worldSpawnHill2->addMob(MS_TRIGGER,-400,0,worldSpawnHill2_infoSprint); - + worldSpawnHill3 = new World(); worldSpawnHill3->generateFunc(1000,gen_worldSpawnHill3); worldSpawnHill3->setBackground(BG_FOREST); @@ -116,11 +116,25 @@ void initEverything(void){ worldSpawnHill1->toRight = worldSpawnHill2; worldSpawnHill2->toLeft = worldSpawnHill1; - worldSpawnHill2->toRight = worldSpawnHill3; worldSpawnHill3->toLeft = worldSpawnHill2; - + + /* + * Spawn some entities. + */ + + //playerSpawnHill->addMob(MS_TRIGGER,player->loc.x,0,story); + + //worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2); + //playerSpawnHill->addStructure(STRUCTURET,FOUNTAIN,(rand()%120*HLINE)+100*HLINE,100,test,iw); + //playerSpawnHill->addStructure(STRUCTURET,HOUSE2,(rand()%120*HLINE)+300*HLINE,100,test,iw); + + //playerSpawnHill->addVillage(5,1,4,STRUCTURET,rand()%500+120,(float)200,playerSpawnHill,iw); + //playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);*/ + + currentWorld = worldSpawnHill1; + worldSpawnHill2->addStructure(STRUCTURET,FOUNTAIN,(rand()%120*HLINE)+100*HLINE,100,worldSpawnHill2,worldSpawnHill2); player = new Player(); player->spawn(200,100); diff --git a/src/inventory.cpp b/src/inventory.cpp index 8d8f958..5ae97b4 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -7,7 +7,7 @@ extern Player *player; extern GLuint invUI; static float hangle = 0.0f; -static bool up = true; +static bool swing = false; static float xc,yc; static vec2 itemLoc; Mix_Chunk* swordSwing; @@ -26,7 +26,7 @@ void initInventorySprites(void){ } swordSwing = Mix_LoadWAV("assets/sounds/shortSwing.wav"); - Mix_Volume(2,75); + Mix_Volume(2,100); } char *getItemTexturePath(ITEM_ID id){ @@ -278,13 +278,13 @@ void itemDraw(Player *p,ITEM_ID id,ITEM_TYPE type){ if(hangle < 15){ hangle=15.0f; p->inv->usingi = false; - up = false; + //swing=false; } }else{ if(hangle > -15){ hangle=-15.0f; p->inv->usingi = false; - up = false; + //swing=false; } } break; @@ -310,19 +310,35 @@ 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; if(!invHover){ switch(type){ case SWORD: - if(!player->left){ - if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);} - if(up)hangle-=15; - if(hangle<=-90)hangle=-14; - }else{ - if(hangle==15){up=true;Mix_PlayChannel(2,swordSwing,0);} - if(up)hangle+=15; - if(hangle>=90)hangle=14; - } + if(swing){ + if(!player->left){ + if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);} + if(up)hangle-=.75*deltaTime; + if(hangle<=-90)hangle=-14; + }else{ + if(hangle==15){up=true;Mix_PlayChannel(2,swordSwing,0);} + if(up)hangle+=.75*deltaTime; + if(hangle>=90)hangle=14; + /* + if(hangle<90&&!up)hangle+=.75*deltaTime; + if(hangle>=90&&!up)up=true; + if(up)hangle-=.75*deltaTime; + if(up&&hangle<=15){ + up=false; + swing=false; + hangle=15; + return 0; + }*/ + } + }else if(!swing){ + swing=true; + Mix_PlayChannel(2,swordSwing,0); + } break; default: break; diff --git a/src/world.cpp b/src/world.cpp index 3f35e21..c1c306e 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -106,7 +106,14 @@ void World::deleteEntities(void){ delete object.back(); object.pop_back(); } - while(!entity.empty()) entity.pop_back(); + while(!entity.empty()){ + entity.pop_back(); + } + + while(!particles.empty()){ + delete particles.back(); + particles.pop_back(); + }//particles.clear(); } World::~World(void){ @@ -296,6 +303,28 @@ void World::update(Player *p,unsigned int delta){ else if(e->vel.x > 0)e->left = false; } } + uint oh = 0; + for(auto &pa : particles){ + if(pa->kill(deltaTime)){ + delete pa; + particles.erase(particles.begin()+oh); + }else if(pa->canMove){ + pa->loc.y += pa->vely * deltaTime; + pa->loc.x += pa->velx * deltaTime; + + for(auto &b : build){ + if(b->bsubtype==FOUNTAIN){ + if(pa->loc.x >= b->loc.x && pa->loc.x <= b->loc.x+b->width){ + if(pa->loc.y <= b->loc.y + b->height*.25){ + delete pa; + particles.erase(particles.begin()+oh); + } + } + } + } + } + oh++; + }oh=0; if(ui::dialogImportant){ Mix_FadeOutMusic(2000); @@ -592,7 +621,7 @@ LOOP2: /* * Draw non-structure entities. */ - + for(auto &part : particles){part->draw();} for(auto &n : current->npc){ n->loc.y+=(yoff-DRAW_Y_OFFSET); n->draw(); @@ -610,6 +639,7 @@ LOOP2: o->loc.y-=(yoff-DRAW_Y_OFFSET); } } + /* * If we're drawing the closest/last world, handle and draw the player. @@ -842,23 +872,52 @@ void World::detect(Player *p){ */ LOOOOP: + static int what = 0; for(auto &e : hey->entity) hey->singleDetect(e); + for(auto &part : particles){ + int l; + unsigned int i; + l=(part->loc.x + part->width / 2 - x_start) / HLINE; + if(l < 0) l=0; + i = l; + if(i > lineCount-1) i=lineCount-1; + if(part->loc.y < line[i].y){ + part->loc.y = line[i].y; + part->vely = 0; + part->velx = 0; + part->canMove = false; + }else{ + if(part->vely > -2)part->vely-=.003 * deltaTime; + } + what++; + }what=0; if(hey->infront){ hey = hey->infront; goto LOOOOP; } } - -void World::addStructure(_TYPE t,float x,float y,World *outside,World *inside){ +void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *outside,World *inside){ build.push_back(new Structures()); - build.back()->spawn(t,x,y); + build.back()->spawn(t,sub,x,y); build.back()->inWorld=outside; build.back()->inside=(void *)inside; entity.push_back(build.back()); } +void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside,World *inside){ + std::cout << npcMin << ", " << npcMax << std::endl; + int xwasd; + for(int i = 0; i < bCount; i++){ + xwasd = (rand()%(int)x+1000*HLINE); + HERE: + for(auto &bu : build){ + if(xwasd > bu->loc.x && xwasd < bu->loc.x+bu->width)goto HERE; + } + addStructure(t,HOUSE,xwasd,y,outside,inside); + } +} void World::addMob(int t,float x,float y){ mob.push_back(new Mob(t)); mob.back()->spawn(x,y); @@ -888,6 +947,11 @@ void World::addObject(ITEM_ID i, bool q, const char *p, float x, float y){ entity.push_back(object.back()); } +void World::addParticle(float x, float y, float w, float h, float vx, float vy, Color color, int d){ + particles.push_back(new Particles(x,y,w,h,vx,vy,color,d)); + particles.back()->canMove = true; +} + /*void World::removeObject(Object i){ object.delete[](i); }*/ |