summaryrefslogtreecommitdiff
path: root/src/resource.cpp
blob: 07f7ca93f16319b4024f21408a142d63f8ba9863 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "resource.hpp"

Resource::Resource(Window m, SDL_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;
    }

	amount      = RESOURCE_AMOUNT_START;
    growAmount  = RESOURCE_GROW;
}

void Resource::eat(int bite)
{
	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;
}