Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/fps_sniper_rifle.cc @ 9235

Last change on this file since 9235 was 9235, checked in by bensch, 18 years ago

merged the presentation back

File size: 3.9 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific
14   main-programmer: Patrick Boenzli
15   co-programmer:
16
17
18   @todo: direction in which the projectile flights
19   @todo: a target to set/hit
20*/
21#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
22
23#include "world_entities/projectiles/projectile.h"
24
25#include "world_entity.h"
26#include "static_model.h"
27#include "weapon_manager.h"
28#include "util/loading/factory.h"
29
30
31#include "fast_factory.h"
32
33#include "fps_sniper_rifle.h"
34
35
36#include "effects/explosion.h"
37
38using namespace std;
39
40
41CREATE_FACTORY(FPSSniperRifle, CL_FPS_SNIPER_RIFLE);
42
43/**
44 *  standard constructor
45
46   creates a new weapon
47*/
48FPSSniperRifle::FPSSniperRifle ( int leftRight)
49  : Weapon()
50{
51  this->init();
52
53  this->leftRight = leftRight;
54}
55
56
57FPSSniperRifle::FPSSniperRifle(const TiXmlElement* root)
58{
59  this->init();
60
61  if (root != NULL)
62    this->loadParams(root);
63}
64
65/**
66 *  standard deconstructor
67*/
68FPSSniperRifle::~FPSSniperRifle ()
69{
70  // model will be deleted from WorldEntity-destructor
71  if( this->material != NULL)
72    delete this->material;
73}
74
75
76void FPSSniperRifle::init()
77{
78  this->setClassID(CL_FPS_SNIPER_RIFLE, "FPSSniperRifle");
79
80  this->loadModel("models/guns/fps_sniper_rifle.obj", 0.2);
81  this->material = new Material();
82  this->material->setIllum(3);
83  this->material->setAmbient(1.0, 1.0, 1.0);
84  this->material->setDiffuseMap("maps/rifle01tex.jpg");
85
86  this->setStateDuration(WS_SHOOTING, .1);
87  this->setStateDuration(WS_RELOADING, .1);
88  this->setStateDuration(WS_ACTIVATING, .4);
89  this->setStateDuration(WS_DEACTIVATING, .4);
90
91  this->setEnergyMax(100000);
92  this->increaseEnergy(100000);
93  //this->minCharge = 2;
94
95  this->setActionSound(WA_SHOOT, "sound/laser.wav");
96  this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav");
97
98
99  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
100  this->setProjectileType(CL_LASER);
101  this->prepareProjectiles(20);
102
103}
104
105
106void FPSSniperRifle::loadParams(const TiXmlElement* root)
107{
108  Weapon::loadParams(root);
109
110}
111
112
113/**
114 *  this activates the weapon
115
116   This is needed, since there can be more than one weapon on a ship. the
117   activation can be connected with an animation. for example the weapon is
118   been armed out.
119*/
120void FPSSniperRifle::activate()
121{
122}
123
124
125/**
126 *  this deactivates the weapon
127
128   This is needed, since there can be more than one weapon on a ship. the
129   activation can be connected with an animation. for example the weapon is
130   been armed out.
131*/
132void FPSSniperRifle::deactivate()
133{
134}
135
136
137/**
138 *  fires the weapon
139
140   this is called from the player.cc, when fire-button is been pushed
141   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
142*/
143void FPSSniperRifle::fire()
144{
145  Projectile* pj =  this->getProjectile();
146  if (pj == NULL)
147    return;
148
149//   Explosion::explode(this, Vector(0.1,0.1,0.1));
150
151  pj->setParent(this);
152  pj->setParentMode(PNODE_ROTATE_AND_MOVE);
153
154  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*550 + VECTOR_RAND(5) );
155
156  pj->setAbsCoor(this->getEmissionPoint() + this->getAbsDirX() * 25.0f);
157  pj->setAbsDir(this->getAbsDir());
158  pj->activate();
159}
160
161
162
163
164/**
165 *  this will draw the weapon
166 */
167void FPSSniperRifle::draw () const
168{
169  /* draw gun body */
170  glMatrixMode(GL_MODELVIEW);
171  glPushMatrix();
172  glTranslatef (this->getAbsCoor ().x,
173                this->getAbsCoor ().y,
174                this->getAbsCoor ().z);
175
176  Vector tmpRot = this->getAbsDir().getSpacialAxis();
177  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
178
179  if( this->leftRight == W_RIGHT)
180    glScalef(1.0, 1.0, -1.0);
181
182  this->material->select();
183  static_cast<StaticModel*>(this->getModel())->draw();
184
185  glPopMatrix();
186
187}
188
189
190
Note: See TracBrowser for help on using the repository browser.