[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 | |
---|
| 23 | using namespace std; |
---|
| 24 | |
---|
[6113] | 25 | Model* PowerUp::sphereModel = NULL; |
---|
[2077] | 26 | |
---|
[6113] | 27 | PowerUp::PowerUp(float r, float g, float b) |
---|
| 28 | { |
---|
| 29 | if(!PowerUp::sphereModel) { |
---|
| 30 | PowerUp::sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5); |
---|
| 31 | } |
---|
| 32 | this->sphereMaterial = new Material; |
---|
| 33 | this->sphereMaterial->setTransparency(.1); |
---|
| 34 | this->sphereMaterial->setDiffuse(r, g, b); |
---|
[6150] | 35 | |
---|
| 36 | this->toList(OM_COMMON); |
---|
[6113] | 37 | } |
---|
[2077] | 38 | |
---|
[6113] | 39 | PowerUp::~PowerUp () |
---|
[4597] | 40 | { |
---|
[6113] | 41 | delete this->sphereMaterial; |
---|
[4597] | 42 | } |
---|
[2077] | 43 | |
---|
| 44 | |
---|
[6113] | 45 | void PowerUp::loadParams(const TiXmlElement* root) |
---|
| 46 | { |
---|
| 47 | static_cast<WorldEntity*>(this)->loadParams(root); |
---|
| 48 | } |
---|
[2077] | 49 | |
---|
| 50 | |
---|
[6113] | 51 | void PowerUp::collidesWith (WorldEntity* entity, const Vector& location) |
---|
| 52 | { |
---|
| 53 | if(entity->isA(CL_EXTENDABLE)) |
---|
| 54 | { |
---|
| 55 | if(dynamic_cast<Extendable*>(entity)->pickup(this)) |
---|
| 56 | { |
---|
| 57 | this->setVisibiliy(false); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | } |
---|
[2077] | 61 | |
---|
[6113] | 62 | void PowerUp::draw() const |
---|
[5434] | 63 | { |
---|
[6113] | 64 | WorldEntity::draw(); |
---|
[5434] | 65 | |
---|
[6113] | 66 | glMatrixMode(GL_MODELVIEW); |
---|
| 67 | glPushMatrix(); |
---|
| 68 | float matrix[4][4]; |
---|
| 69 | |
---|
| 70 | /* translate */ |
---|
| 71 | glTranslatef (this->getAbsCoor ().x, |
---|
| 72 | this->getAbsCoor ().y, |
---|
| 73 | this->getAbsCoor ().z); |
---|
| 74 | /* rotate */ // FIXME: devise a new Way to rotate this |
---|
| 75 | this->getAbsDir ().matrix (matrix); |
---|
| 76 | glMultMatrixf((float*)matrix); |
---|
| 77 | |
---|
| 78 | this->sphereMaterial->select(); |
---|
| 79 | sphereModel->draw(); |
---|
| 80 | |
---|
| 81 | glPopMatrix(); |
---|
[5434] | 82 | } |
---|
| 83 | |
---|
[6113] | 84 | const char* PowerUp::respawnTypes[] = { |
---|
| 85 | "none", |
---|
| 86 | "time" |
---|
| 87 | }; |
---|
| 88 | |
---|
| 89 | void PowerUp::setRespawnType(const char* type) |
---|
| 90 | { |
---|
| 91 | for(int i = 0; i < RESPAWN_size; ++i) { |
---|
| 92 | if(strcmp(type, respawnTypes[i]) == 0) { |
---|
| 93 | this->respawnType = (PowerUpRespawn)i; |
---|
| 94 | break; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|