Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/core/shoot_rocket.cc @ 1921

Last change on this file since 1921 was 1921, checked in by bensch, 21 years ago

orxonox/trunk: missiles are slower, and there are less

File size: 3.7 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:  Benjamin Grauer
16*/
17
18
19#include "shoot_rocket.h"
20
21#include <iostream>
22
23
24using namespace std;
25
26
27
28ShootRocket::ShootRocket ()
29{
30  lastShoot = null;
31  step = 1.0;
32  inhibitor =0;
33}
34
35
36ShootRocket::~ShootRocket () {}
37
38
39void ShootRocket::drawShoot() 
40{
41
42  //cout << "ShootRocket::drawShoot" << endl;
43  /* now draw all the shoots (many) */
44  shoot* tmpShoot = lastShoot;
45  shoot* lastRef = null;
46  while( tmpShoot != null )
47    {
48      glPushMatrix(); 
49      glTranslatef(tmpShoot->xCor, tmpShoot->yCor, tmpShoot->zCor);
50      tmpShoot->xCor+=tmpShoot->xVel;
51      tmpShoot->yCor+=tmpShoot->yVel;
52      tmpShoot->xVel+=tmpShoot->xAcc;
53      tmpShoot->yVel+=tmpShoot->yAcc;
54     
55      glScalef(0.1, 0.1, 0.1);
56      glutWireCube(1.0);
57      glPopMatrix();
58
59      /* garbage collection: look if shoot is outside world */
60      /* fix1: weak boundaries check all four sides */
61      /* fix2: conditions, that a struct tree can be cut off */
62      /* fix3: more efficent and nicer please */
63      if (tmpShoot->yCor - DataTank::yOffset > 20) 
64        {
65          /* normal case: delete one element, link the others */
66          if (lastRef != null) 
67            {
68              //cout << "garbage collection" << endl;
69              lastRef->next = tmpShoot->next;
70              delete tmpShoot;
71              tmpShoot = lastRef->next;
72              //cout << "garbage collection left" << endl;
73            }
74          else
75            {
76              /* special case: first element to be processed */
77              //cout << "garbage collecton: first el in queue" << endl;
78              lastRef = tmpShoot->next;
79              delete tmpShoot;
80              tmpShoot = lastRef;
81              lastShoot = tmpShoot;
82              if (tmpShoot != null) 
83                {
84                  tmpShoot = tmpShoot->next;
85                  //cout << "noch nich null" << endl;
86                }
87              else 
88                {
89                  lastRef = null;
90                  tmpShoot = null;
91                  lastShoot = null;
92                  //cout << "endl null" << endl;
93                }
94             
95              //cout << "garbage collection: firtst el in queue left" << endl;
96            }
97        }
98      else 
99        {
100          lastRef = tmpShoot;
101          tmpShoot = tmpShoot->next;
102        }
103    }
104  //cout << "ShootRocket::drawShoot - finished" << endl;
105}
106
107
108void ShootRocket::addShoot(shoot* sh) 
109{
110  sh->next = null;
111  lastShoot = sh;
112}
113
114void ShootRocket::addShoot(float x, float y, float z)
115{
116  inhibitor++;
117  if (inhibitor >= 10)
118    {
119      //cout << "ShootRocket::addShoot" << endl;
120      shoot* sh = new shoot;
121      sh->xCor = x; sh->yCor = y; sh->zCor = z;
122      sh->xVel = (-1+(float)random() / 1000000000/step)/5; 
123      sh->yVel = -.3;
124      sh->zVel = (1-(float)random() / 1000000000/step)/5;
125      sh->xAcc = 0; sh->yAcc = .01/step; sh->zAcc = 0;
126      sh->next = lastShoot;
127      lastShoot = sh;
128      inhibitor =0;
129    }
130}
131
132void ShootRocket::addShootExt(float x, float y, float z, 
133                             float xVel, float yVel, float zVel)
134{
135  //cout << "ShootRocket::addShootExtended" << endl;
136  shoot* sh = new shoot;
137  sh->xCor = x; sh->yCor = y; sh->zCor = z;
138  sh->xVel = xVel/step; sh->yVel = yVel/step; sh->zVel = zVel/step;
139  sh->xAcc = 0; sh->yAcc = .02; sh->zAcc = 0;
140  sh->next = lastShoot;
141  lastShoot = sh;
142}
143
144void ShootRocket::setShootStep(float step) 
145{
146  cout << "ShootRocket::setShootStep to " << step << endl;
147  this->step = step;
148}
149
150
151/* Exterminate shoot from game, implement this method  */
152/* if you like to add animatiion */
153void ShootRocket::removeShoot(shoot* sh)
154{
155  glPushMatrix(); 
156  glTranslatef(sh->xCor, sh->yCor, sh->zCor);
157  glutWireCube(1.0);
158  glPopMatrix();
159}
Note: See TracBrowser for help on using the repository browser.