[10175] | 1 | /* |
---|
[10618] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[10175] | 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: |
---|
[10431] | 12 | main-programmer: Lieni |
---|
[10175] | 13 | */ |
---|
| 14 | |
---|
| 15 | #include "blink.h" |
---|
| 16 | |
---|
| 17 | #include "util/loading/load_param.h" |
---|
| 18 | #include "util/loading/factory.h" |
---|
| 19 | #include "debug.h" |
---|
[10253] | 20 | #include "state.h" |
---|
[10407] | 21 | #include "effects/billboard.h" |
---|
[10175] | 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 | |
---|
[10431] | 36 | if(root) |
---|
[10175] | 37 | this->loadParams(root); |
---|
[10445] | 38 | |
---|
| 39 | // calculation of the symbolTime |
---|
| 40 | this->symbolTime = this->period / this->blinkSequence.length(); |
---|
[10491] | 41 | //PRINTF(0)("\n\n\nperiod: %f\n\n\n", this->period); |
---|
[10175] | 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * destroys a Blink |
---|
| 47 | */ |
---|
| 48 | Blink::~Blink () |
---|
| 49 | { |
---|
[10431] | 50 | if(bBoard) |
---|
| 51 | delete bBoard; |
---|
[10175] | 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 | |
---|
[10407] | 65 | this->bBoard = new Billboard; |
---|
[10511] | 66 | this->bBoard->setVisibility(true); |
---|
[10445] | 67 | this->bBoard->setTexture("textures/light/blink.png"); |
---|
[10407] | 68 | |
---|
[10698] | 69 | //!< Standard values |
---|
[10431] | 70 | this->bBoard->setAbsCoor(0, 0, 0); |
---|
| 71 | // default position if not set in xml |
---|
[10426] | 72 | this->color = Color(1, 0, 0); |
---|
[10429] | 73 | // 10x10 pxl if not defined in xml |
---|
[10253] | 74 | this->size = 10; |
---|
[10445] | 75 | // default period |
---|
| 76 | this->period = 1; |
---|
| 77 | // default blink sequence |
---|
| 78 | this->blinkSequence = "00011234567889998876543211"; |
---|
[10431] | 79 | |
---|
[10445] | 80 | // start values of non-loadable variables |
---|
| 81 | this->blinkStr = 0; |
---|
| 82 | this->timer = 0; |
---|
| 83 | this->seqCounter = 0; |
---|
[10491] | 84 | |
---|
| 85 | // ugly hack continued |
---|
| 86 | this->setCoor = true; |
---|
[10175] | 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | /** |
---|
| 91 | * load params |
---|
| 92 | * @param root TiXmlElement object |
---|
| 93 | */ |
---|
| 94 | void Blink::loadParams(const TiXmlElement* root) |
---|
| 95 | { |
---|
[10253] | 96 | WorldEntity::loadParams(root); |
---|
| 97 | |
---|
[10491] | 98 | LoadParam(root, "position", this, Blink, PNode::setAbsCoor); |
---|
[10253] | 99 | LoadParam(root, "size", this, Blink, setSize); |
---|
[10325] | 100 | LoadParam(root, "color", this, Blink, setColor); |
---|
[10445] | 101 | LoadParam(root, "period", this, Blink, setPeriod); |
---|
| 102 | LoadParam(root, "sequence", this, Blink, loadBlinkSequence); |
---|
[10175] | 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * ticks the Blink |
---|
| 108 | * @param dt the time to ticks |
---|
| 109 | */ |
---|
| 110 | void Blink::tick(float dt) |
---|
| 111 | { |
---|
[10491] | 112 | // ugly hack continued, set absCoor only once |
---|
| 113 | if(this->setCoor) { |
---|
| 114 | this->bBoard->setAbsCoor(this->getAbsCoor()); |
---|
[10530] | 115 | this->bBoard->setAbsDir(this->getAbsDir()); |
---|
| 116 | this->bBoard->setRelCoor(this->getRelCoor()); |
---|
| 117 | this->bBoard->setRelDir(this->getRelDir()); |
---|
| 118 | this->bBoard->setParent(this); |
---|
[10491] | 119 | this->setCoor = false; |
---|
| 120 | this->symbolTime = this->period / this->blinkSequence.length(); |
---|
| 121 | } |
---|
| 122 | |
---|
[10445] | 123 | timer += dt; |
---|
[10325] | 124 | |
---|
[10445] | 125 | while(this->timer >= this->symbolTime) |
---|
| 126 | { |
---|
| 127 | this->blinkStr = (float)((int)(blinkSequence[seqCounter]) - 48) / 9; |
---|
[10325] | 128 | |
---|
[10445] | 129 | this->timer -= symbolTime; |
---|
[10427] | 130 | |
---|
[10445] | 131 | seqCounter++; |
---|
| 132 | seqCounter %= this->blinkSequence.length(); |
---|
| 133 | } |
---|
| 134 | |
---|
[10431] | 135 | this->bBoard->colorTexture(Color(color.r(), color.g(), color.b(), this->blinkStr)); |
---|
[10175] | 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | * draws the blink |
---|
| 141 | */ |
---|
| 142 | void Blink::draw() const |
---|
| 143 | { |
---|
| 144 | |
---|
| 145 | } |
---|