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