| [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); | 
|---|
 | 37 | } | 
|---|
 | 38 |  | 
|---|
 | 39 |  | 
|---|
 | 40 | /** | 
|---|
 | 41 |  * destroys a Blink | 
|---|
 | 42 |  */ | 
|---|
 | 43 | Blink::~Blink () | 
|---|
 | 44 | { | 
|---|
| [10431] | 45 |   if(bBoard) | 
|---|
 | 46 |     delete bBoard; | 
|---|
| [10175] | 47 | } | 
|---|
 | 48 |  | 
|---|
 | 49 |  | 
|---|
 | 50 | /** | 
|---|
 | 51 |  * initializes the Blink | 
|---|
 | 52 |  */ | 
|---|
 | 53 | void Blink::init() | 
|---|
 | 54 | { | 
|---|
 | 55 |   this->registerObject(this, Blink::_objectList); | 
|---|
 | 56 |   this->setName("Blink"); | 
|---|
 | 57 |  | 
|---|
 | 58 |   this->toList(OM_COMMON); | 
|---|
 | 59 |  | 
|---|
| [10407] | 60 |   this->bBoard = new Billboard; | 
|---|
 | 61 |   this->bBoard->setVisibiliy(true); | 
|---|
 | 62 |   this->bBoard->setTexture("maps/star_alpha.png"); | 
|---|
 | 63 |  | 
|---|
| [10325] | 64 |   /// Standard values | 
|---|
| [10431] | 65 |   this->bBoard->setAbsCoor(0, 0, 0); | 
|---|
 | 66 |   // default position if not set in xml | 
|---|
| [10426] | 67 |   this->color = Color(1, 0, 0); | 
|---|
| [10429] | 68 |   // 10x10 pxl if not defined in xml | 
|---|
| [10253] | 69 |   this->size = 10; | 
|---|
| [10431] | 70 |   // default angular rate | 
|---|
| [10325] | 71 |   this->omega = 10; | 
|---|
| [10431] | 72 |  | 
|---|
 | 73 |   // random start angle, blinkies shouldn't blink synchronous | 
|---|
 | 74 |   this->angle = (float)rand()/(float)RAND_MAX * 2 * M_PI; | 
|---|
| [10175] | 75 | } | 
|---|
 | 76 |  | 
|---|
 | 77 |  | 
|---|
 | 78 | /** | 
|---|
 | 79 |  *  load params | 
|---|
 | 80 |  * @param root TiXmlElement object | 
|---|
 | 81 |  */ | 
|---|
 | 82 | void Blink::loadParams(const TiXmlElement* root) | 
|---|
 | 83 | { | 
|---|
| [10253] | 84 |   WorldEntity::loadParams(root); | 
|---|
 | 85 |  | 
|---|
 | 86 |   LoadParam(root, "position", this, Blink, setPosition); | 
|---|
 | 87 |   LoadParam(root, "size", this, Blink, setSize); | 
|---|
| [10325] | 88 |   LoadParam(root, "color", this, Blink, setColor); | 
|---|
 | 89 |   LoadParam(root, "omega", this, Blink, setOmega); | 
|---|
| [10175] | 90 | } | 
|---|
 | 91 |  | 
|---|
 | 92 |  | 
|---|
 | 93 | /** | 
|---|
 | 94 |  * ticks the Blink | 
|---|
 | 95 |  * @param dt the time to ticks | 
|---|
 | 96 |  */ | 
|---|
 | 97 | void Blink::tick(float dt) | 
|---|
 | 98 | { | 
|---|
| [10325] | 99 |   this->angle += dt * this->omega; | 
|---|
 | 100 |  | 
|---|
| [10431] | 101 |   while (this->angle > 2 * M_PI) | 
|---|
| [10325] | 102 |     this->angle -= 2 * M_PI; | 
|---|
 | 103 |  | 
|---|
| [10431] | 104 |   // blinkStr should be element of [0, 1] | 
|---|
 | 105 |   this->blinkStr = (sinf(angle) + 1) / 2; | 
|---|
| [10427] | 106 |  | 
|---|
| [10431] | 107 |   this->bBoard->colorTexture(Color(color.r(), color.g(), color.b(), this->blinkStr)); | 
|---|
| [10175] | 108 | } | 
|---|
 | 109 |  | 
|---|
 | 110 |  | 
|---|
 | 111 | /** | 
|---|
 | 112 |  * draws the blink | 
|---|
 | 113 |  */ | 
|---|
 | 114 | void Blink::draw() const | 
|---|
 | 115 | { | 
|---|
 | 116 |  | 
|---|
 | 117 | } | 
|---|