1 | /* |
---|
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: |
---|
12 | main-programmer: Manuel Leuenberger |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
17 | |
---|
18 | |
---|
19 | #include "power_up.h" |
---|
20 | #include "extendable.h" |
---|
21 | #include "primitive_model.h" |
---|
22 | |
---|
23 | using namespace std; |
---|
24 | |
---|
25 | Model* PowerUp::sphereModel = NULL; |
---|
26 | |
---|
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); |
---|
35 | } |
---|
36 | |
---|
37 | PowerUp::~PowerUp () |
---|
38 | { |
---|
39 | delete this->sphereMaterial; |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | void PowerUp::loadParams(const TiXmlElement* root) |
---|
44 | { |
---|
45 | static_cast<WorldEntity*>(this)->loadParams(root); |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | void PowerUp::collidesWith (WorldEntity* entity, const Vector& location) |
---|
50 | { |
---|
51 | if(entity->isA(CL_EXTENDABLE)) |
---|
52 | { |
---|
53 | if(dynamic_cast<Extendable*>(entity)->pickup(this)) |
---|
54 | { |
---|
55 | this->setVisibiliy(false); |
---|
56 | } |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | void PowerUp::draw() const |
---|
61 | { |
---|
62 | WorldEntity::draw(); |
---|
63 | |
---|
64 | glMatrixMode(GL_MODELVIEW); |
---|
65 | glPushMatrix(); |
---|
66 | float matrix[4][4]; |
---|
67 | |
---|
68 | /* translate */ |
---|
69 | glTranslatef (this->getAbsCoor ().x, |
---|
70 | this->getAbsCoor ().y, |
---|
71 | this->getAbsCoor ().z); |
---|
72 | /* rotate */ // FIXME: devise a new Way to rotate this |
---|
73 | this->getAbsDir ().matrix (matrix); |
---|
74 | glMultMatrixf((float*)matrix); |
---|
75 | |
---|
76 | this->sphereMaterial->select(); |
---|
77 | sphereModel->draw(); |
---|
78 | |
---|
79 | glPopMatrix(); |
---|
80 | } |
---|
81 | |
---|
82 | const char* PowerUp::respawnTypes[] = { |
---|
83 | "none", |
---|
84 | "time" |
---|
85 | }; |
---|
86 | |
---|
87 | void PowerUp::setRespawnType(const char* type) |
---|
88 | { |
---|
89 | for(int i = 0; i < RESPAWN_size; ++i) { |
---|
90 | if(strcmp(type, respawnTypes[i]) == 0) { |
---|
91 | this->respawnType = (PowerUpRespawn)i; |
---|
92 | break; |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|