summaryrefslogtreecommitdiff
path: root/src/resource.cpp
diff options
context:
space:
mode:
authortom <tombarrett@siu.edu>2017-01-21 08:58:12 -0600
committertom <tombarrett@siu.edu>2017-01-21 08:58:12 -0600
commita9281bfcf21861e621a3243ecb633a299c8d8e52 (patch)
tree7d4687fd9a8f40e806e6b7c8803c0e87fcae6639 /src/resource.cpp
parentccb66c8d6d175b1bd3d8ecaa540e80baac5181b6 (diff)
-took basic math functions and put it into functions.hpp
-spaced various lines -reorganized variables by datatype -implemented reproduction -reorganized pathing so once a target is set, the creature checks if that same target is near every cycle
Diffstat (limited to 'src/resource.cpp')
-rw-r--r--src/resource.cpp21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/resource.cpp b/src/resource.cpp
index 07f7ca9..2f2181f 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -2,13 +2,13 @@
Resource::Resource(Window m, SDL_Rect R)
{
- renderer = m.getRenderer();
- type = RESOURCE_TYPE;
- rect = R;
+ renderer = m.getRenderer();
+ type = RESOURCE_TYPE;
+ rect = R;
if(rect.x == 0 && rect.y == 0){
- rect.x = rand()%WINDOW_X;
- rect.y = rand()%WINDOW_Y;
+ rect.x = rand()%WINDOW_X;
+ rect.y = rand()%WINDOW_Y;
}
amount = RESOURCE_AMOUNT_START;
@@ -22,13 +22,8 @@ void Resource::eat(int bite)
void Resource::grow()
{
- if(amount < RESOURCE_AMOUNT_MAX)
+ 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;
+ rect.h = rect.w = map(amount,0,RESOURCE_AMOUNT_MAX,0,RESOURCE_SIZE_MAX);
+ }
}