From a9281bfcf21861e621a3243ecb633a299c8d8e52 Mon Sep 17 00:00:00 2001 From: tom Date: Sat, 21 Jan 2017 08:58:12 -0600 Subject: -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 --- src/resource.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/resource.cpp') 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); + } } -- cgit v1.2.3