[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: |
---|
[5434] | 12 | main-programmer: Benjamin Grauer |
---|
[2077] | 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[5439] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
[2077] | 17 | |
---|
[5458] | 18 | #include "laser_power_up.h" |
---|
[7193] | 19 | #include "util/loading/factory.h" |
---|
[5435] | 20 | #include "state.h" |
---|
[6424] | 21 | #include "network_game_manager.h" |
---|
[2077] | 22 | |
---|
[5437] | 23 | #include "primitive_model.h" |
---|
| 24 | |
---|
[2077] | 25 | |
---|
[10114] | 26 | |
---|
| 27 | ObjectListDefinition(LaserPowerUp); |
---|
[9869] | 28 | CREATE_FACTORY(LaserPowerUp); |
---|
[9406] | 29 | |
---|
[6113] | 30 | LaserPowerUp::LaserPowerUp () : PowerUp(0.0, 1.0, 0.0) |
---|
[4597] | 31 | { |
---|
[5434] | 32 | this->init(); |
---|
[4597] | 33 | } |
---|
[2077] | 34 | |
---|
[6113] | 35 | LaserPowerUp::LaserPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0) |
---|
[5434] | 36 | { |
---|
| 37 | this->init(); |
---|
[2077] | 38 | |
---|
[5434] | 39 | this->loadParams(root); |
---|
| 40 | } |
---|
[2077] | 41 | |
---|
| 42 | |
---|
[5458] | 43 | LaserPowerUp::~LaserPowerUp () |
---|
[5437] | 44 | { |
---|
| 45 | delete this->sphereModel; |
---|
| 46 | delete this->sphereMaterial; |
---|
[5435] | 47 | } |
---|
[5434] | 48 | |
---|
[5435] | 49 | |
---|
[5458] | 50 | void LaserPowerUp::init() |
---|
[5434] | 51 | { |
---|
[9869] | 52 | this->registerObject(this, LaserPowerUp::_objectList); |
---|
[5499] | 53 | this->loadModel("models/guns/test_gun.obj", 2.0); |
---|
[5435] | 54 | |
---|
[5437] | 55 | this->sphereModel = new PrimitiveModel(PRIM_SPHERE, 7, 5); |
---|
| 56 | this->sphereMaterial = new Material; |
---|
[5439] | 57 | this->sphereMaterial->setTransparency(.1); |
---|
[5458] | 58 | this->sphereMaterial->setDiffuse(.7, .7, .1); |
---|
[5437] | 59 | |
---|
[5435] | 60 | this->rotation = Vector(0,1,0); |
---|
[5437] | 61 | this->cycle = (float)rand()/RAND_MAX*M_2_PI; |
---|
| 62 | this->shiftDir(Quaternion((float)rand()/RAND_MAX*M_2_PI, this->rotation)); |
---|
[5434] | 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
[5458] | 66 | void LaserPowerUp::loadParams(const TiXmlElement* root) |
---|
[5434] | 67 | { |
---|
[6512] | 68 | PowerUp::loadParams(root); |
---|
[5434] | 69 | |
---|
| 70 | } |
---|
[5435] | 71 | |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | * this function is called, when two entities collide |
---|
| 75 | * @param entity: the world entity with whom it collides |
---|
| 76 | * |
---|
| 77 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 78 | */ |
---|
[5458] | 79 | void LaserPowerUp::collidesWith(WorldEntity* entity, const Vector& location) |
---|
[5435] | 80 | { |
---|
[9406] | 81 | // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassCName(), entity->getClassCName(), location.x, location.y, location.z); |
---|
[10114] | 82 | if (entity->isA(Playable::staticClassID())) |
---|
[6142] | 83 | this->toList(OM_DEAD); |
---|
[5435] | 84 | } |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | * this method is called every frame |
---|
| 88 | * @param time: the time in seconds that has passed since the last tick |
---|
| 89 | * |
---|
| 90 | * Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
| 91 | */ |
---|
[5458] | 92 | void LaserPowerUp::tick(float dt) |
---|
[5435] | 93 | { |
---|
| 94 | this->shiftDir(Quaternion(dt, this->rotation)); |
---|
| 95 | this->cycle+=dt; |
---|
| 96 | |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | * the entity is drawn onto the screen with this function |
---|
| 101 | * |
---|
| 102 | * This is a central function of an entity: call it to let the entity painted to the screen. |
---|
| 103 | * Just override this function with whatever you want to be drawn. |
---|
| 104 | */ |
---|
[5500] | 105 | void LaserPowerUp::draw() const |
---|
[6780] | 106 | { |
---|
| 107 | glMatrixMode(GL_MODELVIEW); |
---|
[5435] | 108 | glPushMatrix(); |
---|
| 109 | /* translate */ |
---|
| 110 | glTranslatef (this->getAbsCoor ().x, |
---|
| 111 | this->getAbsCoor ().y + cos(this->cycle*3.0)*2.0, |
---|
| 112 | this->getAbsCoor ().z); |
---|
| 113 | /* rotate */ |
---|
| 114 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 115 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[5994] | 116 | this->getModel()->draw(); |
---|
[5437] | 117 | |
---|
| 118 | this->sphereMaterial->select(); |
---|
| 119 | this->sphereModel->draw(); |
---|
[5435] | 120 | glPopMatrix(); |
---|
| 121 | } |
---|
| 122 | |
---|
[6424] | 123 | |
---|