1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2006 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Lieni |
---|
13 | */ |
---|
14 | |
---|
15 | #include "blink.h" |
---|
16 | |
---|
17 | #include "util/loading/load_param.h" |
---|
18 | #include "util/loading/factory.h" |
---|
19 | #include "debug.h" |
---|
20 | #include "state.h" |
---|
21 | #include "effects/billboard.h" |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | ObjectListDefinition(Blink); |
---|
27 | CREATE_FACTORY(Blink); |
---|
28 | |
---|
29 | /** |
---|
30 | * standart constructor |
---|
31 | */ |
---|
32 | Blink::Blink (const TiXmlElement* root) |
---|
33 | { |
---|
34 | this->init(); |
---|
35 | |
---|
36 | if(root) |
---|
37 | this->loadParams(root); |
---|
38 | |
---|
39 | // calculation of the symbolTime |
---|
40 | this->symbolTime = this->period / this->blinkSequence.length(); |
---|
41 | //PRINTF(0)("\n\n\nperiod: %f\n\n\n", this->period); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | /** |
---|
46 | * destroys a Blink |
---|
47 | */ |
---|
48 | Blink::~Blink () |
---|
49 | { |
---|
50 | if(bBoard) |
---|
51 | delete bBoard; |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | /** |
---|
56 | * initializes the Blink |
---|
57 | */ |
---|
58 | void Blink::init() |
---|
59 | { |
---|
60 | this->registerObject(this, Blink::_objectList); |
---|
61 | this->setName("Blink"); |
---|
62 | |
---|
63 | this->toList(OM_COMMON); |
---|
64 | |
---|
65 | this->bBoard = new Billboard; |
---|
66 | this->bBoard->setVisibility(true); |
---|
67 | this->bBoard->setTexture("textures/light/blink.png"); |
---|
68 | |
---|
69 | //!< Standard values |
---|
70 | this->bBoard->setAbsCoor(0, 0, 0); |
---|
71 | // default position if not set in xml |
---|
72 | this->color = Color(1, 0, 0); |
---|
73 | // 10x10 pxl if not defined in xml |
---|
74 | this->size = 10; |
---|
75 | // default period |
---|
76 | this->period = 1; |
---|
77 | // default blink sequence |
---|
78 | this->blinkSequence = "00011234567889998876543211"; |
---|
79 | |
---|
80 | // start values of non-loadable variables |
---|
81 | this->blinkStr = 0; |
---|
82 | this->timer = 0; |
---|
83 | this->seqCounter = 0; |
---|
84 | |
---|
85 | // ugly hack continued |
---|
86 | this->setCoor = true; |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | /** |
---|
91 | * load params |
---|
92 | * @param root TiXmlElement object |
---|
93 | */ |
---|
94 | void Blink::loadParams(const TiXmlElement* root) |
---|
95 | { |
---|
96 | WorldEntity::loadParams(root); |
---|
97 | |
---|
98 | LoadParam(root, "position", this, Blink, PNode::setAbsCoor); |
---|
99 | LoadParam(root, "size", this, Blink, setSize); |
---|
100 | LoadParam(root, "color", this, Blink, setColor); |
---|
101 | LoadParam(root, "period", this, Blink, setPeriod); |
---|
102 | LoadParam(root, "sequence", this, Blink, loadBlinkSequence); |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | /** |
---|
107 | * ticks the Blink |
---|
108 | * @param dt the time to ticks |
---|
109 | */ |
---|
110 | void Blink::tick(float dt) |
---|
111 | { |
---|
112 | // ugly hack continued, set absCoor only once |
---|
113 | if(this->setCoor) { |
---|
114 | this->bBoard->setAbsCoor(this->getAbsCoor()); |
---|
115 | this->bBoard->setAbsDir(this->getAbsDir()); |
---|
116 | this->bBoard->setRelCoor(this->getRelCoor()); |
---|
117 | this->bBoard->setRelDir(this->getRelDir()); |
---|
118 | this->bBoard->setParent(this); |
---|
119 | this->setCoor = false; |
---|
120 | this->symbolTime = this->period / this->blinkSequence.length(); |
---|
121 | } |
---|
122 | |
---|
123 | timer += dt; |
---|
124 | |
---|
125 | while(this->timer >= this->symbolTime) |
---|
126 | { |
---|
127 | this->blinkStr = (float)((int)(blinkSequence[seqCounter]) - 48) / 9; |
---|
128 | |
---|
129 | this->timer -= symbolTime; |
---|
130 | |
---|
131 | seqCounter++; |
---|
132 | seqCounter %= this->blinkSequence.length(); |
---|
133 | } |
---|
134 | |
---|
135 | this->bBoard->colorTexture(Color(color.r(), color.g(), color.b(), this->blinkStr)); |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | /** |
---|
140 | * draws the blink |
---|
141 | */ |
---|
142 | void Blink::draw() const |
---|
143 | { |
---|
144 | |
---|
145 | } |
---|