diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2015-12-14 08:25:15 -0500 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2015-12-14 08:25:15 -0500 |
commit | c5050b17d16670c6151d5c135c3b01d66b7530f9 (patch) | |
tree | d8cffed7b2a576023e013b2133504d273e85b652 /src | |
parent | b477db406b9d7aa4f62a750c9ae3c3cedc533b3b (diff) |
Added particles
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 24 | ||||
-rw-r--r-- | src/gameplay.cpp | 6 | ||||
-rw-r--r-- | src/inventory.cpp | 12 | ||||
-rw-r--r-- | src/ui.cpp | 2 | ||||
-rw-r--r-- | src/world.cpp | 77 |
5 files changed, 103 insertions, 18 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index a04b638..1fefa9a 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; @@ -369,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; @@ -378,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 b9aa328..54ef432 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -127,7 +127,11 @@ void initEverything(void){ playerSpawnHill->addMob(MS_TRIGGER,player->loc.x,0,story); - playerSpawnHill->addStructure(STRUCTURET,(rand()%120*HLINE),100,test,iw); + playerSpawnHill->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,test,iw); + 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); playerSpawnHill->addObject(SWORD_WOOD, false, "", 480,200); diff --git a/src/inventory.cpp b/src/inventory.cpp index 585af47..5ae97b4 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -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){ @@ -317,10 +317,14 @@ int Inventory::useItem(void){ case SWORD: if(swing){ if(!player->left){ - /*if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);} + if(hangle==-15){up=true;Mix_PlayChannel(2,swordSwing,0);} if(up)hangle-=.75*deltaTime; - if(hangle<=-90)hangle=-14;*/ + 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; @@ -329,7 +333,7 @@ int Inventory::useItem(void){ swing=false; hangle=15; return 0; - } + }*/ } }else if(!swing){ swing=true; @@ -682,7 +682,7 @@ DONE: } break; case SDLK_LSHIFT: - player->speed = debug ? 4.0f : 3.0f; + player->speed = debug ? 4.0f : 1.75f; break; case SDLK_LCTRL: player->speed = .5; diff --git a/src/world.cpp b/src/world.cpp index 7a47c97..8994f6c 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -108,7 +108,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){ @@ -294,6 +301,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); @@ -523,7 +552,7 @@ LOOP2: //b->loc.y+=(yoff-DRAW_Y_OFFSET); b->draw(); //b->loc.y-=(yoff-DRAW_Y_OFFSET); - std::cout<<b->loc.x<<" "<<b->loc.y<<std::endl; + //std::cout<<b->loc.x<<" "<<b->loc.y<<std::endl; } /* @@ -604,7 +633,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(); @@ -621,7 +650,7 @@ LOOP2: o->draw(); o->loc.y-=(yoff-DRAW_Y_OFFSET); } - }for(auto &o : particles){o->draw();} + } /* @@ -851,23 +880,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); @@ -897,8 +955,9 @@ 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, Color color){ - particles.push_back(new Particles(x,y,w,h,color)); +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){ |