[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 | PowerUp::PowerUp(float r, float g, float b) |
---|
| 26 | { |
---|
[6424] | 27 | this->setClassID(CL_POWER_UP, "PowerUp"); |
---|
| 28 | |
---|
[6243] | 29 | this->respawnType = RESPAWN_NONE; |
---|
[6282] | 30 | /* if(!PowerUp::sphereModel) {*/ |
---|
| 31 | |
---|
| 32 | Model* sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5); |
---|
| 33 | |
---|
| 34 | this->setModel(sphereModel); |
---|
| 35 | this->buildObbTree( 4); |
---|
[6113] | 36 | this->sphereMaterial = new Material; |
---|
| 37 | this->sphereMaterial->setTransparency(.1); |
---|
| 38 | this->sphereMaterial->setDiffuse(r, g, b); |
---|
[6150] | 39 | this->toList(OM_COMMON); |
---|
[6113] | 40 | } |
---|
[2077] | 41 | |
---|
[6113] | 42 | PowerUp::~PowerUp () |
---|
[4597] | 43 | { |
---|
[6113] | 44 | delete this->sphereMaterial; |
---|
[4597] | 45 | } |
---|
[2077] | 46 | |
---|
| 47 | |
---|
[6113] | 48 | void PowerUp::loadParams(const TiXmlElement* root) |
---|
| 49 | { |
---|
| 50 | static_cast<WorldEntity*>(this)->loadParams(root); |
---|
| 51 | } |
---|
[2077] | 52 | |
---|
| 53 | |
---|
[6113] | 54 | void PowerUp::collidesWith (WorldEntity* entity, const Vector& location) |
---|
| 55 | { |
---|
[6424] | 56 | if(entity->isA(CL_EXTENDABLE)) |
---|
[6113] | 57 | { |
---|
| 58 | if(dynamic_cast<Extendable*>(entity)->pickup(this)) |
---|
| 59 | { |
---|
[6282] | 60 | this->toList(OM_DEAD_TICK); |
---|
[6113] | 61 | } |
---|
| 62 | } |
---|
| 63 | } |
---|
[2077] | 64 | |
---|
[6113] | 65 | void PowerUp::draw() const |
---|
[5434] | 66 | { |
---|
[6113] | 67 | glMatrixMode(GL_MODELVIEW); |
---|
| 68 | glPushMatrix(); |
---|
| 69 | |
---|
| 70 | /* translate */ |
---|
| 71 | glTranslatef (this->getAbsCoor ().x, |
---|
| 72 | this->getAbsCoor ().y, |
---|
| 73 | this->getAbsCoor ().z); |
---|
[6282] | 74 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 75 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[6113] | 76 | |
---|
[6282] | 77 | this->sphereMaterial->select(); |
---|
| 78 | this->getModel(0)->draw(); |
---|
[6113] | 79 | |
---|
[6282] | 80 | glPopMatrix(); |
---|
[5434] | 81 | } |
---|
| 82 | |
---|
[6113] | 83 | const char* PowerUp::respawnTypes[] = { |
---|
| 84 | "none", |
---|
| 85 | "time" |
---|
| 86 | }; |
---|
| 87 | |
---|
| 88 | void PowerUp::setRespawnType(const char* type) |
---|
| 89 | { |
---|
| 90 | for(int i = 0; i < RESPAWN_size; ++i) { |
---|
[6243] | 91 | if(!strcmp(type, respawnTypes[i])) { |
---|
[6113] | 92 | this->respawnType = (PowerUpRespawn)i; |
---|
| 93 | break; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
[6424] | 98 | /** |
---|
| 99 | * data copied in data will bee sent to another host |
---|
| 100 | * @param data pointer to data |
---|
| 101 | * @param maxLength max length of data |
---|
| 102 | * @return the number of bytes writen |
---|
| 103 | */ |
---|
| 104 | int PowerUp::readState( byte * data, int maxLength ) |
---|
| 105 | { |
---|
| 106 | SYNCHELP_WRITE_BEGIN(); |
---|
| 107 | SYNCHELP_WRITE_FKT( WorldEntity::readState ); |
---|
| 108 | return SYNCHELP_WRITE_N; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | /** |
---|
| 112 | * Writes data from network containing information about the state |
---|
| 113 | * @param data pointer to data |
---|
| 114 | * @param length length of data |
---|
| 115 | * @param sender hostID of sender |
---|
| 116 | */ |
---|
| 117 | int PowerUp::writeState( const byte * data, int length, int sender ) |
---|
| 118 | { |
---|
| 119 | SYNCHELP_READ_BEGIN(); |
---|
| 120 | SYNCHELP_READ_FKT( WorldEntity::writeState ); |
---|
| 121 | return SYNCHELP_READ_N; |
---|
| 122 | } |
---|
| 123 | |
---|