From 11c5d147b845d4323f2e94c1ac47b6001420d8e6 Mon Sep 17 00:00:00 2001 From: tom Date: Thu, 19 Jan 2017 13:33:46 -0600 Subject: -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 --- src/resource.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/resource.cpp') 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; } -- cgit v1.2.3