//
//  Chest.cpp
//  GlobalGameJam15
//
//  Created by Cesar Parent on 25/01/2015.
//  Copyright (c) 2015 Cesar Parent. All rights reserved.
//

#include "Chest.h"
#include "Defines.h"
#include "MapLayer.h"

Chest::Chest() : Entity("assets/maps/chest.png")
{
	addCollisionBody(0, 0, kTileSize, kTileSize);
	collisionBody.categoryBitmask = 0b01;
	collisionBody.collisionBitmask = 0b10;
}

void Chest::draw(SDL_Renderer *renderer)
{
	if(_parent == nullptr) return;
	
	MapLayer* map = (MapLayer*)_parent;
	float opacity = 1.0f - map->distanceToPlayer(_position.x, _position.y) /
	(float)(kVisionRadius*kTileSize);
	
	opacity = (opacity > 0)? opacity : 0.0f;
	opacity = (opacity < 1)? opacity : 1.0f;
	SDL_SetTextureColorMod(_texture,
						   _colorMod.red*map->flicker*opacity,
						   _colorMod.green*map->flicker*opacity,
						   _colorMod.blue*map->flicker*opacity);
	
	Entity::draw(renderer);
}