summaryrefslogtreecommitdiff
path: root/src/resource.cpp
diff options
context:
space:
mode:
authortom <tombarrett@siu.edu>2017-01-19 13:33:46 -0600
committertom <tombarrett@siu.edu>2017-01-19 13:33:46 -0600
commit11c5d147b845d4323f2e94c1ac47b6001420d8e6 (patch)
treeeafc67bb6844dc14b56ad5d8eadf6d200b78e0d1 /src/resource.cpp
parent0c2335f4a717e53c2456e49407dfbbd0ffa20f06 (diff)
-added entity growing
-added bite functionality for creature/resource -added gender (next largest feature is reproduction) -refractored creature setTarget function to make more sense -added constants for starting size of entity and max size of entity -refractored list to make make much more sense -added constants for types
Diffstat (limited to 'src/resource.cpp')
-rw-r--r--src/resource.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/resource.cpp b/src/resource.cpp
index eec1113..07f7ca9 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -3,7 +3,7 @@
Resource::Resource(Window m, SDL_Rect R)
{
renderer = m.getRenderer();
- type = 2;
+ type = RESOURCE_TYPE;
rect = R;
if(rect.x == 0 && rect.y == 0){
@@ -11,10 +11,24 @@ Resource::Resource(Window m, SDL_Rect R)
rect.y = rand()%WINDOW_Y;
}
- amount = RESOURCE_AMOUNT;
+ amount = RESOURCE_AMOUNT_START;
+ growAmount = RESOURCE_GROW;
}
-void Resource::eat()
+void Resource::eat(int bite)
{
- amount-=10;
+ amount-=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);
+}
+
+int Resource::map(int x, int inMin, int inMax, int outMin, int outMax)
+{
+ return (x-inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}