[4597] | 1 | /* |
---|
[2077] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 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: |
---|
[6113] | 12 | main-programmer: Manuel Leuenberger |
---|
[2077] | 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[5439] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
[2077] | 17 | |
---|
[5439] | 18 | |
---|
[2077] | 19 | #include "power_up.h" |
---|
[6113] | 20 | #include "extendable.h" |
---|
| 21 | #include "primitive_model.h" |
---|
[2077] | 22 | |
---|
[9869] | 23 | #include "sound/resource_sound_buffer.h" |
---|
[7193] | 24 | #include "util/loading/load_param.h" |
---|
[6815] | 25 | |
---|
[9869] | 26 | #include "debug.h" |
---|
[2077] | 27 | |
---|
[9869] | 28 | ObjectListDefinition(PowerUp); |
---|
[9406] | 29 | |
---|
[6113] | 30 | PowerUp::PowerUp(float r, float g, float b) |
---|
| 31 | { |
---|
[9869] | 32 | this->registerObject(this, PowerUp::_objectList); |
---|
[6424] | 33 | |
---|
[6973] | 34 | this->respawnType = RESPAWN_TIME; |
---|
[6589] | 35 | this->respawnStart = 10; |
---|
| 36 | this->model = NULL; |
---|
[7221] | 37 | /* if(!PowerUp::sphereModel) {*/ |
---|
[6282] | 38 | |
---|
| 39 | Model* sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5); |
---|
| 40 | |
---|
| 41 | this->setModel(sphereModel); |
---|
| 42 | this->buildObbTree( 4); |
---|
[6113] | 43 | this->sphereMaterial = new Material; |
---|
[6973] | 44 | this->sphereMaterial->setTransparency(.8); |
---|
[6113] | 45 | this->sphereMaterial->setDiffuse(r, g, b); |
---|
[6150] | 46 | this->toList(OM_COMMON); |
---|
[7065] | 47 | |
---|
| 48 | this->soundSource.setSourceNode(this); |
---|
[7102] | 49 | |
---|
| 50 | this->collider = NULL; |
---|
[6113] | 51 | } |
---|
[2077] | 52 | |
---|
[6113] | 53 | PowerUp::~PowerUp () |
---|
[4597] | 54 | { |
---|
[6113] | 55 | delete this->sphereMaterial; |
---|
[4597] | 56 | } |
---|
[2077] | 57 | |
---|
| 58 | |
---|
[6113] | 59 | void PowerUp::loadParams(const TiXmlElement* root) |
---|
| 60 | { |
---|
[6512] | 61 | WorldEntity::loadParams(root); |
---|
[7065] | 62 | |
---|
[6973] | 63 | LoadParam(root, "respawnType", this, PowerUp, setRespawnType); |
---|
[7065] | 64 | |
---|
[6973] | 65 | LoadParam(root, "respawnTime", this, PowerUp, setRespawnTime); |
---|
[7065] | 66 | |
---|
| 67 | LoadParam(root, "pickup-sound", this, PowerUp, loadPickupSound); |
---|
[7066] | 68 | |
---|
| 69 | LoadParam(root, "respawn-sound", this, PowerUp, loadRespawnSound); |
---|
[6113] | 70 | } |
---|
[2077] | 71 | |
---|
| 72 | |
---|
[7221] | 73 | void PowerUp::loadPickupSound(const std::string& pickupSound) |
---|
[7065] | 74 | { |
---|
[9869] | 75 | if (!pickupSound.empty()) |
---|
| 76 | this->pickupBuffer = OrxSound::ResourceSoundBuffer(pickupSound); |
---|
[7065] | 77 | else |
---|
[9869] | 78 | this->pickupBuffer = OrxSound::SoundBuffer(); |
---|
[7065] | 79 | } |
---|
| 80 | |
---|
[7221] | 81 | void PowerUp::loadRespawnSound(const std::string& respawnSound) |
---|
[7066] | 82 | { |
---|
[9869] | 83 | if (!respawnSound.empty()) |
---|
| 84 | this->respawnBuffer = OrxSound::ResourceSoundBuffer(respawnSound); |
---|
[7066] | 85 | else |
---|
[9869] | 86 | this->respawnBuffer = OrxSound::SoundBuffer(); |
---|
[7066] | 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
[6113] | 90 | void PowerUp::collidesWith (WorldEntity* entity, const Vector& location) |
---|
| 91 | { |
---|
[9869] | 92 | if(this->collider != entity && entity->isA(Extendable::staticClassID())) |
---|
[6113] | 93 | { |
---|
[7102] | 94 | this->collider = entity; |
---|
[6113] | 95 | if(dynamic_cast<Extendable*>(entity)->pickup(this)) |
---|
| 96 | { |
---|
[9869] | 97 | if(pickupBuffer.loaded()) |
---|
[7066] | 98 | this->soundSource.play(this->pickupBuffer); |
---|
[7065] | 99 | |
---|
[7221] | 100 | switch(respawnType) |
---|
| 101 | { |
---|
| 102 | case RESPAWN_NONE: |
---|
| 103 | this->toList(OM_DEAD); |
---|
| 104 | break; |
---|
| 105 | case RESPAWN_TIME: |
---|
| 106 | this->toList(OM_DEAD_TICK); |
---|
| 107 | this->respawnTime = this->respawnStart; |
---|
| 108 | break; |
---|
[8350] | 109 | default: |
---|
| 110 | /* NOT HANDLED */ |
---|
| 111 | break; |
---|
[6973] | 112 | } |
---|
[6113] | 113 | } |
---|
| 114 | } |
---|
| 115 | } |
---|
[2077] | 116 | |
---|
[7221] | 117 | void PowerUp::tick(float dt) |
---|
| 118 | { |
---|
| 119 | if(this->getOMListNumber() != OM_COMMON) |
---|
| 120 | { |
---|
[6589] | 121 | this->respawnTime -= dt; |
---|
[7066] | 122 | if(this->respawnTime <= 0) |
---|
| 123 | { |
---|
[6589] | 124 | this->toList(OM_COMMON); |
---|
[7102] | 125 | this->collider = NULL; |
---|
[9869] | 126 | if (likely(this->respawnBuffer.loaded())) |
---|
[7077] | 127 | this->soundSource.play(this->respawnBuffer); |
---|
[7066] | 128 | |
---|
[6589] | 129 | } |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
[6113] | 133 | void PowerUp::draw() const |
---|
[5434] | 134 | { |
---|
[7221] | 135 | if(this->model != NULL) |
---|
| 136 | { |
---|
[6589] | 137 | glMatrixMode(GL_MODELVIEW); |
---|
| 138 | glPushMatrix(); |
---|
| 139 | glTranslatef (this->getAbsCoor ().x, |
---|
| 140 | this->getAbsCoor ().y, |
---|
| 141 | this->getAbsCoor ().z); |
---|
| 142 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 143 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 144 | this->model->draw(); |
---|
| 145 | glPopMatrix(); |
---|
| 146 | } |
---|
[6547] | 147 | this->sphereMaterial->select(); |
---|
| 148 | WorldEntity::draw(); |
---|
[5434] | 149 | } |
---|
| 150 | |
---|
[7221] | 151 | const char* PowerUp::respawnTypes[] = |
---|
| 152 | { |
---|
| 153 | "none", |
---|
| 154 | "time" |
---|
| 155 | }; |
---|
[6113] | 156 | |
---|
[7221] | 157 | |
---|
| 158 | void PowerUp::setRespawnType(const std::string& type) |
---|
[6113] | 159 | { |
---|
[7221] | 160 | for(int i = 0; i < RESPAWN_size; ++i) |
---|
| 161 | { |
---|
| 162 | if(type == respawnTypes[i]) |
---|
| 163 | { |
---|
[6113] | 164 | this->respawnType = (PowerUpRespawn)i; |
---|
| 165 | break; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | |
---|
[6973] | 170 | void PowerUp::setRespawnTime(const float respawnTime) |
---|
| 171 | { |
---|
| 172 | this->respawnStart = respawnTime; |
---|
| 173 | } |
---|
[6498] | 174 | |
---|
| 175 | |
---|