| 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: |
|---|
| 11 | main-programmer: Lieni |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #include "blink.h" |
|---|
| 15 | |
|---|
| 16 | #include "util/loading/load_param.h" |
|---|
| 17 | #include "util/loading/factory.h" |
|---|
| 18 | #include "debug.h" |
|---|
| 19 | #include "state.h" |
|---|
| 20 | #include "effects/billboard.h" |
|---|
| 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 | |
|---|
| 35 | if(root) |
|---|
| 36 | this->loadParams(root); |
|---|
| 37 | |
|---|
| 38 | // calculation of the symbolTime |
|---|
| 39 | this->symbolTime = this->period / this->blinkSequence.length(); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | /** |
|---|
| 44 | * destroys a Blink |
|---|
| 45 | */ |
|---|
| 46 | Blink::~Blink () |
|---|
| 47 | { |
|---|
| 48 | if(bBoard) |
|---|
| 49 | delete bBoard; |
|---|
| 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 | |
|---|
| 63 | this->bBoard = new Billboard; |
|---|
| 64 | this->bBoard->setVisibiliy(true); |
|---|
| 65 | this->bBoard->setTexture("textures/light/blink.png"); |
|---|
| 66 | |
|---|
| 67 | /// Standard values |
|---|
| 68 | this->bBoard->setAbsCoor(0, 0, 0); |
|---|
| 69 | // default position if not set in xml |
|---|
| 70 | this->color = Color(1, 0, 0); |
|---|
| 71 | // 10x10 pxl if not defined in xml |
|---|
| 72 | this->size = 10; |
|---|
| 73 | // default period |
|---|
| 74 | this->period = 1; |
|---|
| 75 | // default blink sequence |
|---|
| 76 | this->blinkSequence = "00011234567889998876543211"; |
|---|
| 77 | |
|---|
| 78 | // start values of non-loadable variables |
|---|
| 79 | this->blinkStr = 0; |
|---|
| 80 | this->timer = 0; |
|---|
| 81 | this->seqCounter = 0; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | /** |
|---|
| 86 | * load params |
|---|
| 87 | * @param root TiXmlElement object |
|---|
| 88 | */ |
|---|
| 89 | void Blink::loadParams(const TiXmlElement* root) |
|---|
| 90 | { |
|---|
| 91 | WorldEntity::loadParams(root); |
|---|
| 92 | |
|---|
| 93 | LoadParam(root, "position", this, Blink, setPosition); |
|---|
| 94 | LoadParam(root, "size", this, Blink, setSize); |
|---|
| 95 | LoadParam(root, "color", this, Blink, setColor); |
|---|
| 96 | LoadParam(root, "period", this, Blink, setPeriod); |
|---|
| 97 | LoadParam(root, "sequence", this, Blink, loadBlinkSequence); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | /** |
|---|
| 102 | * ticks the Blink |
|---|
| 103 | * @param dt the time to ticks |
|---|
| 104 | */ |
|---|
| 105 | void Blink::tick(float dt) |
|---|
| 106 | { |
|---|
| 107 | timer += dt; |
|---|
| 108 | |
|---|
| 109 | while(this->timer >= this->symbolTime) |
|---|
| 110 | { |
|---|
| 111 | this->blinkStr = (float)((int)(blinkSequence[seqCounter]) - 48) / 9; |
|---|
| 112 | |
|---|
| 113 | this->timer -= symbolTime; |
|---|
| 114 | |
|---|
| 115 | seqCounter++; |
|---|
| 116 | seqCounter %= this->blinkSequence.length(); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | this->bBoard->colorTexture(Color(color.r(), color.g(), color.b(), this->blinkStr)); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | /** |
|---|
| 124 | * draws the blink |
|---|
| 125 | */ |
|---|
| 126 | void Blink::draw() const |
|---|
| 127 | { |
|---|
| 128 | |
|---|
| 129 | } |
|---|