forked from secondstory/LYT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractiveObject.cpp
91 lines (65 loc) · 1.59 KB
/
InteractiveObject.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
Copyright (c) 2013 - Philippe Laulheret, Second Story [http://www.secondstory.com]
This code is protected under MIT license.
For more information visit : https://github.com/secondstory/LYT
*/
#include "InteractiveObject.h"
#include <algorithm> //for min max
InteractiveObject::InteractiveObject()
{
_defaultLife = 500;
}
void InteractiveObject::setDefaultLife(int defaultVal)
{
_defaultLife = defaultVal;
}
void InteractiveObject::reset(int x, int y)
{
this->x =x ;
this->y = y;
life = _defaultLife;
onReset();
}
void InteractiveObject::draw()
{
}
void InteractiveObject::update()
{
life--;
onUpdate();
}
//---------------------------------------------------------------------
// PlusObject
//--------------------------------------------------------------------
PlusObject::PlusObject() : InteractiveObject()
{
setDefaultLife(100);
onReset();
}
void PlusObject::onUpdate()
{
brightness = std::max( (float)(default_brightness + (255-default_brightness)*exp( (life-_defaultLife)*decaySpeed)), (float)default_brightness );
//if (x==0) life=0;
//else {
// if (life % 60 == 0) x--; //fall 1 led every 10 frame
// }
}
void PlusObject::onReset()
{
brightness = default_brightness;
}
void PlusObject::draw()
{
float h = current_hue + hueAdjust;
float s = default_sat + satAdjust;
if (h >= 255) h-= 255;
if (h <= 0 ) h+= 255;
if( s >= 255 ) s-=255;
if( s <= 0 ) s+=255;
setColor(h,s,brightness);
drawPixel(x,y);
drawPixel(x+1,y);
drawPixel(x-1,y);
drawPixel(x,y+1);
drawPixel(x,y-1);
}