diff options
author | majortom6 <tombarrett@siu.edu> | 2017-02-19 12:00:52 -0600 |
---|---|---|
committer | Tom Barrett <tombarrett@siu.edu> | 2017-03-07 13:23:41 -0600 |
commit | 0846d5802965d257f176e033d7a6ac353ed648f3 (patch) | |
tree | 1ada2e260970883decd2165d3dd3b74ad34212fd /src | |
parent | bfdc713b68dd6f8d61e7b26fc2cff15caf24b44d (diff) |
-speedcaps now working again
-creatures now randomize target better again
-thats enough for today, src is still a mess and main can be cleaned a bit
Diffstat (limited to 'src')
-rw-r--r-- | src/creature.cpp | 102 | ||||
-rw-r--r-- | src/list.cpp | 1 | ||||
-rw-r--r-- | src/main.cpp | 1 | ||||
-rw-r--r-- | src/resource.cpp | 38 | ||||
-rw-r--r-- | src/window.cpp | 1 |
5 files changed, 70 insertions, 73 deletions
diff --git a/src/creature.cpp b/src/creature.cpp index 9f8204b..bf0ad43 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -2,66 +2,61 @@ Creature::Creature(Rectangle t, DNA D) { - rect = t; - myDNA = D; - - if(rect.x == 0 && rect.y == 0){ - rect.x = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); - rect.y = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); - } + rect = t; + myDNA = D; - gfxData.sides = 4.0; - gfxData.x = rect.x; - gfxData.y = rect.y; - - type = CREATURE_TYPE; - health = myDNA.maxHealth/2; - gender = rand() % 2; - age = 0; - pregnancyTime = 0; - pregnancyReady = false; - pregnate = false; - hasTarget = false; - - if(gender){ - gfxData.r = 1.0; - gfxData.g = 0.0; - gfxData.b = 0.0; - } - else if(pregnate){ - gfxData.r = 1.0; - gfxData.g = 0.0; - gfxData.b = 1.0; - } - else{ - gfxData.r = 0.0; - gfxData.g = 0.0; - gfxData.b = 1.0; - } + if(rect.x == 0 && rect.y == 0){ + rect.x = getRandom(50); + rect.y = getRandom(50); + } + + gfxData.sides = 4.0; + gfxData.x = rect.x; + gfxData.y = rect.y; + + type = CREATURE_TYPE; + health = myDNA.maxHealth/2; + gender = rand() % 2; + age = 0; + pregnancyTime = 0; + pregnancyReady = false; + pregnate = false; + hasTarget = false; + + if(gender){ + gfxData.r = 1.0; + gfxData.g = 0.0; + gfxData.b = 0.0; + } + else{ + gfxData.r = 0.0; + gfxData.g = 0.0; + gfxData.b = 1.0; + } } void Creature::Behavior() { - health-=1; + health-=1; this->Priority(); - if(!hasTarget) - this->setTarget(); - else - this->checkTarget(); + if(!hasTarget) + this->setTarget(); + else + this->checkTarget(); this->Action(); - if(pregnate){ - pregnancyTime++; - if(pregnancyTime > myDNA.expectedPregnancyTime) - pregnancyReady = true; - } + if(pregnate){ + pregnancyTime++; + if(pregnancyTime > myDNA.expectedPregnancyTime) + pregnancyReady = true; + } - age++; - if(age > myDNA.expectedAge) - health = 0; + age++; + if(age > myDNA.expectedAge) + health = 0; } void Creature::Priority() @@ -78,8 +73,9 @@ void Creature::Priority() void Creature::setTarget() { - //std::random_shuffle(N.begin(),N.end()); - for(std::list <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++){ + std::random_shuffle(nearMe.begin(),nearMe.end()); + + for(std::vector <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++){ if( (*it)->getType() == RESOURCE_TYPE && hungry){ target = *it; hasTarget = true; @@ -96,8 +92,8 @@ void Creature::setTarget() if(!hasTarget&&!wander){ wander = true; - float x = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); - float y = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); + float x = getRandom(50); + float y = getRandom(50); Rectangle tmp; tmp.x = x; tmp.y = y; @@ -107,7 +103,7 @@ void Creature::setTarget() void Creature::checkTarget() { - for(std::list <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++) + for(std::vector <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++) if( target == *it ) return; diff --git a/src/list.cpp b/src/list.cpp index 71c0ba9..e91e1aa 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -11,7 +11,6 @@ List::List() creatures.push_back(X); } - //rect = {0,0,RESOURCE_SIZE_START,RESOURCE_SIZE_START}; for(i=0;i<RESOURCES;i++){ Resource Y(tmp); resources.push_back(Y); diff --git a/src/main.cpp b/src/main.cpp index d5a192d..1cec997 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,6 +46,7 @@ int main() shader.Bind();
_spriteBatch.begin();
+ printf("%d\n",L.creatures.size());
for(std::list<Creature>::iterator it = L.creatures.begin(); it != L.creatures.end(); it++)
_spriteBatch.draw(it->getGFXD());
diff --git a/src/resource.cpp b/src/resource.cpp index 9933c4f..81fd6b7 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -2,23 +2,23 @@ Resource::Resource(Rectangle t) { - rect = t; - - if(rect.x == 0 && rect.y == 0){ - rect.x = -30 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30.0-(-30.0)))); - rect.y = -30 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30.0-(-30.0)))); - } + rect = t; - gfxData.x = rect.x; - gfxData.y = rect.y; - gfxData.r = 0.0; - gfxData.g = 1.0; - gfxData.b = 0.0; - gfxData.sides = 10.0; + if(rect.x == 0 && rect.y == 0){ + rect.x = getRandom(50); + rect.y = getRandom(50); + } - type = RESOURCE_TYPE; - amount = RESOURCE_AMOUNT_START; - growAmount = RESOURCE_GROW; + gfxData.x = rect.x; + gfxData.y = rect.y; + gfxData.r = 0.0; + gfxData.g = 1.0; + gfxData.b = 0.0; + gfxData.sides = 10.0; + + type = RESOURCE_TYPE; + amount = RESOURCE_AMOUNT_START; + growAmount = RESOURCE_GROW; } void Resource::eat(int bite) @@ -28,8 +28,8 @@ void Resource::eat(int bite) void Resource::grow() { - if(amount < RESOURCE_AMOUNT_MAX){ - amount+=growAmount; - rect.h = rect.w = map(amount,0,RESOURCE_AMOUNT_MAX,0,RESOURCE_SIZE_MAX); - } + if(amount < RESOURCE_AMOUNT_MAX){ + amount+=growAmount; + rect.h = rect.w = map(amount,0,RESOURCE_AMOUNT_MAX,0,RESOURCE_SIZE_MAX); + } } diff --git a/src/window.cpp b/src/window.cpp index 9306b15..bd6fdcf 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -13,6 +13,7 @@ Window::Window(int width, int height, const std::string& title) main = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,width,height,SDL_WINDOW_OPENGL); glContext = SDL_GL_CreateContext(main); + SDL_GL_SetSwapInterval(0); GLenum status = glewInit(); closed = false; |