diff options
author | tom <tombarrett@siu.edu> | 2017-01-21 08:58:12 -0600 |
---|---|---|
committer | tom <tombarrett@siu.edu> | 2017-01-21 08:58:12 -0600 |
commit | a9281bfcf21861e621a3243ecb633a299c8d8e52 (patch) | |
tree | 7d4687fd9a8f40e806e6b7c8803c0e87fcae6639 /src/resource.cpp | |
parent | ccb66c8d6d175b1bd3d8ecaa540e80baac5181b6 (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.cpp | 21 |
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); + } } |