aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/GuiParticle.cpp
blob: 1e6bcc7080eaa78554075d602bc2e0dfcca693ef (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "stdafx.h"
#include "GuiParticle.h"
#include "..\Minecraft.World\Random.h"

Random *GuiParticle::random = new Random();

GuiParticle::GuiParticle(double x, double y, double xa, double ya)
{
	// 4J - added initialisation block
    removed = false;
    life = 0;
    a = 1;
    oR = oG = oB = oA = 0;
		
	this->xo = this->x = x;
    this->yo = this->y = y;
    this->xa = xa;
    this->ya = ya;

    int col = Color::HSBtoRGB(random->nextFloat(), 0.5f, 1);
    r = ((col >> 16) & 0xff) / 255.0;
    g = ((col >> 8) & 0xff) / 255.0;
    b = ((col) & 0xff) / 255.0;

    friction = 1.0 / (random->nextDouble() * 0.05 + 1.01);

    lifeTime = static_cast<int>(10.0 / (random->nextDouble() * 2 + 0.1));
}

void GuiParticle::tick(GuiParticles *guiParticles)
{
    x += xa;
    y += ya;

    xa *= friction;
    ya *= friction;

    ya += 0.1;
    if (++life > lifeTime) remove();
    a = 2 - (life / static_cast<double>(lifeTime)) * 2;
    if (a > 1) a = 1;
    a = a * a;
    a *= 0.5;
}

void GuiParticle::preTick()
{
    oR = r;
    oG = g;
    oB = b;
    oA = a;

    xo = x;
    yo = y;
}

void GuiParticle::remove()
{
	removed = true;
}