<commit_before>#include "Object.h"
#include <iostream>

Object * Object::fromID(unsigned char objectID, unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    switch(objectID)
    {
        case 'a':
            return Bed(x,y,objectTexture, fireTexture);
            break;
        case 'b':
            return Sofa(x,y,objectTexture, fireTexture);
            break;
        case 'c':
            return Toilet(x,y,objectTexture, fireTexture);
            break;
        case 'd':
            return Table(x,y,objectTexture, fireTexture);
            break;
        case 'e':
            return Oven(x,y,objectTexture, fireTexture);
            break;
        case 'f':
            return Fridge(x,y,objectTexture, fireTexture);
            break;
        case 'g':
            return KitchenTable(x,y,objectTexture, fireTexture);
            break;
        case 'h':
            return Tub(x,y,objectTexture, fireTexture);
            break;
        default:
            return new Object(0,0,0,0,0,0,x,y,objectTexture, fireTexture);
            break;
    }

}

Object * Object::Bed(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.6,15, 2,3, 0,0, x,y, objectTexture, fireTexture);
}

Object * Object::Sofa(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.5,25, 2,1, 0,3, x,y, objectTexture, fireTexture);
}

Object * Object::Toilet(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.0,10, 1,1, 2,0, x,y, objectTexture, fireTexture);
}

Object * Object::Table(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(1.0,20, 1,1, 2,1, x,y, objectTexture, fireTexture);
}

Object * Object::Oven(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.5,50, 1,1, 2,2, x,y, objectTexture, fireTexture);
}

Object * Object::Fridge(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.5,50, 1,1, 2,3, x,y, objectTexture, fireTexture);
}

Object * Object::KitchenTable(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.5,50, 1,1, 3,0, x,y, objectTexture, fireTexture);
}

Object * Object::Tub(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.0,10, 1,2, 3,1, x,y, objectTexture, fireTexture);
}


Object::Object(double flameVelocity, unsigned int maxBurnedDamage, unsigned int width, unsigned int height, unsigned int offsetX, unsigned int offsetY, unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture) :
    m_width(width),
    m_height(height),

    m_x(x),
    m_y(y),

    m_offsetX(offsetX),
    m_offsetY(offsetY),

	m_burn(false),
    m_flameVelocity(flameVelocity),
    m_maxBurnedDamage(maxBurnedDamage),
    m_currentFlameIntensity(0),
    m_currentBurnedDamage(0),

    m_lastUpdatedTime(),
    m_typeFire(-1),
    m_animFrame(0),

    m_objectTexture(objectTexture),
    m_fireTexture(fireTexture),
    m_clock()

{	
    m_time = sf::seconds(0.0f);
    m_clock.restart();	
}

Object::~Object()
{
}

void Object::update(sf::Clock const & clk)
{
    m_time = m_clock.getElapsedTime();
	if (m_burn)
	{
		m_currentBurnedDamage += m_currentFlameIntensity;
		if (m_currentBurnedDamage > m_maxBurnedDamage)
		{
            this->stopFire();
		}
	}

    sf::Time time = clk.getElapsedTime();
    if((time - m_lastUpdatedTime).asMilliseconds() > 400)
    {
        m_animFrame++;
        if(m_animFrame == 8)
        {
            if(m_typeFire == 0)
                m_typeFire = 1;
            else if(m_typeFire == 2)
                m_typeFire = -1;

            m_animFrame %= 8;
        }
    }
}

void Object::draw(sf::RenderWindow * window) const
{
    //TODO: set object to black
    sf::Sprite sprite;
    sprite.setTexture(*m_objectTexture);
    sprite.setTextureRect(sf::IntRect(32*m_offsetX, 32*m_offsetY, 32*m_width, 32*m_height));
    sprite.setPosition(m_x * 32, m_y * 32);
    window->draw(sprite);

    //TODO: draw fire sprite
    if(m_typeFire >= 0)
    {
        sf::Sprite fireSprite;
        fireSprite.setTexture(*m_fireTexture);
        fireSprite.setTextureRect(sf::IntRect(64*m_animFrame, 4*32*m_typeFire, 64, 4*32));
        fireSprite.setOrigin(32, 3*32 + 16);
        fireSprite.setPosition(m_x*32 + m_width * 16, m_y*32 + m_height*16);
        window->draw(fireSprite);
    }
}

void Object::ignite(double fire)
{
    std::cout << "ignite" << std::endl;
	if (!m_burn)
	{
		m_burn = true;
		m_currentFlameIntensity = fire;
        m_typeFire = 0;
        m_animFrame = 0;
	}
}

void Object::stopFire()
{
    m_currentFlameIntensity = 0;
    m_typeFire = 2;
    m_animFrame = 0;
}

<commit_msg>blacken objects when on fire<commit_after>#include "Object.h"
#include <iostream>

Object * Object::fromID(unsigned char objectID, unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    switch(objectID)
    {
        case 'a':
            return Bed(x,y,objectTexture, fireTexture);
            break;
        case 'b':
            return Sofa(x,y,objectTexture, fireTexture);
            break;
        case 'c':
            return Toilet(x,y,objectTexture, fireTexture);
            break;
        case 'd':
            return Table(x,y,objectTexture, fireTexture);
            break;
        case 'e':
            return Oven(x,y,objectTexture, fireTexture);
            break;
        case 'f':
            return Fridge(x,y,objectTexture, fireTexture);
            break;
        case 'g':
            return KitchenTable(x,y,objectTexture, fireTexture);
            break;
        case 'h':
            return Tub(x,y,objectTexture, fireTexture);
            break;
        default:
            return new Object(0,0,0,0,0,0,x,y,objectTexture, fireTexture);
            break;
    }

}

Object * Object::Bed(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.6,15, 2,3, 0,0, x,y, objectTexture, fireTexture);
}

Object * Object::Sofa(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.5,25, 2,1, 0,3, x,y, objectTexture, fireTexture);
}

Object * Object::Toilet(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.0,10, 1,1, 2,0, x,y, objectTexture, fireTexture);
}

Object * Object::Table(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(1.0,20, 1,1, 2,1, x,y, objectTexture, fireTexture);
}

Object * Object::Oven(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.5,50, 1,1, 2,2, x,y, objectTexture, fireTexture);
}

Object * Object::Fridge(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.5,50, 1,1, 2,3, x,y, objectTexture, fireTexture);
}

Object * Object::KitchenTable(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.5,50, 1,1, 3,0, x,y, objectTexture, fireTexture);
}

Object * Object::Tub(unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture)
{
    return new Object(0.0,10, 1,2, 3,1, x,y, objectTexture, fireTexture);
}


Object::Object(double flameVelocity, unsigned int maxBurnedDamage, unsigned int width, unsigned int height, unsigned int offsetX, unsigned int offsetY, unsigned int x, unsigned int y, sf::Texture * objectTexture, sf::Texture * fireTexture) :
    m_width(width),
    m_height(height),

    m_x(x),
    m_y(y),

    m_offsetX(offsetX),
    m_offsetY(offsetY),

	m_burn(false),
    m_flameVelocity(flameVelocity),
    m_maxBurnedDamage(maxBurnedDamage),
    m_currentFlameIntensity(0),
    m_currentBurnedDamage(0),

    m_lastUpdatedTime(),
    m_typeFire(-1),
    m_animFrame(0),

    m_objectTexture(objectTexture),
    m_fireTexture(fireTexture),
    m_clock()

{	
    m_time = sf::seconds(0.0f);
    m_clock.restart();	
}

Object::~Object()
{
}

void Object::update(sf::Clock const & clk)
{
    m_time = m_clock.getElapsedTime();
	if (m_burn)
	{
		m_currentBurnedDamage += m_currentFlameIntensity;
		if (m_currentBurnedDamage > m_maxBurnedDamage)
		{
            this->stopFire();
		}
	}

    sf::Time time = clk.getElapsedTime();
    if((time - m_lastUpdatedTime).asMilliseconds() > 400)
    {
        m_animFrame++;
        if(m_animFrame == 8)
        {
            if(m_typeFire == 0)
                m_typeFire = 1;
            else if(m_typeFire == 2)
                m_typeFire = -1;

            m_animFrame %= 8;
        }
    }
}

void Object::draw(sf::RenderWindow * window) const
{
    sf::Sprite sprite;
    sprite.setTexture(*m_objectTexture);
    unsigned int ndg = 255 - ((float)m_currentBurnedDamage/m_maxBurnedDamage)*255;
    sprite.setColor(sf::Color(ndg, ndg, ndg));
    sprite.setTextureRect(sf::IntRect(32*m_offsetX, 32*m_offsetY, 32*m_width, 32*m_height));
    sprite.setPosition(m_x * 32, m_y * 32);
    window->draw(sprite);

    if(m_typeFire >= 0)
    {
        sf::Sprite fireSprite;
        fireSprite.setTexture(*m_fireTexture);
        fireSprite.setTextureRect(sf::IntRect(64*m_animFrame, 4*32*m_typeFire, 64, 4*32));
        fireSprite.setOrigin(32, 3*32 + 16);
        fireSprite.setPosition(m_x*32 + m_width * 16, m_y*32 + m_height*16);
        window->draw(fireSprite);
    }
}

void Object::ignite(double fire)
{
    std::cout << "ignite" << std::endl;
	if (!m_burn)
	{
		m_burn = true;
		m_currentFlameIntensity = fire;
        m_typeFire = 0;
        m_animFrame = 0;
	}
}

void Object::stopFire()
{
    m_currentFlameIntensity = 0;
    m_typeFire = 2;
    m_animFrame = 0;
}


{'fraction_non_alphanumeric': 0.13361812040532486, 'fraction_numerical': 0.026028213788992647, 'mean_word_length': 3.1376900945334976, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '62840', 'n_tokens_mistral': 3638, 'n_tokens_neox': 3460, 'n_words': 751}