[1920] | 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 | |
---|
| 24 | using namespace std; |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | |
---|
[1921] | 28 | ShootRocket::ShootRocket () |
---|
[1920] | 29 | { |
---|
| 30 | lastShoot = null; |
---|
| 31 | step = 1.0; |
---|
[1921] | 32 | inhibitor =0; |
---|
[1926] | 33 | rotateAngle = 0.0; |
---|
[1920] | 34 | } |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | ShootRocket::~ShootRocket () {} |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | void ShootRocket::drawShoot() |
---|
| 41 | { |
---|
| 42 | |
---|
| 43 | //cout << "ShootRocket::drawShoot" << endl; |
---|
| 44 | /* now draw all the shoots (many) */ |
---|
| 45 | shoot* tmpShoot = lastShoot; |
---|
| 46 | shoot* lastRef = null; |
---|
| 47 | while( tmpShoot != null ) |
---|
| 48 | { |
---|
| 49 | glPushMatrix(); |
---|
| 50 | glTranslatef(tmpShoot->xCor, tmpShoot->yCor, tmpShoot->zCor); |
---|
[1924] | 51 | switch (tmpShoot->type) |
---|
| 52 | { |
---|
| 53 | case BACKPARABLE: |
---|
| 54 | tmpShoot->xCor+=tmpShoot->xVel; |
---|
| 55 | tmpShoot->yCor+=tmpShoot->yVel; |
---|
| 56 | tmpShoot->xVel+=tmpShoot->xAcc; |
---|
| 57 | tmpShoot->yVel+=tmpShoot->yAcc; |
---|
| 58 | break; |
---|
| 59 | |
---|
| 60 | case SIDEACC: |
---|
| 61 | if (tmpShoot->xVel >= .01 || tmpShoot->xVel <= -.01) |
---|
| 62 | { |
---|
| 63 | tmpShoot->xCor+=tmpShoot->xVel; |
---|
[1925] | 64 | tmpShoot->yCor+=tmpShoot->yVel; |
---|
[1924] | 65 | tmpShoot->xVel*=tmpShoot->xAcc; |
---|
| 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
[1925] | 69 | tmpShoot->xCor+=tmpShoot->xVel; |
---|
[1924] | 70 | tmpShoot->yCor+=tmpShoot->yVel; |
---|
| 71 | tmpShoot->yVel+=tmpShoot->yVel*tmpShoot->yAcc; |
---|
| 72 | } |
---|
| 73 | break; |
---|
[1926] | 74 | |
---|
| 75 | case ROTATER: |
---|
[1927] | 76 | tmpShoot->xCor+=tmpShoot->xVel; |
---|
[1926] | 77 | tmpShoot->yCor+=tmpShoot->yVel; |
---|
[1927] | 78 | tmpShoot->zCor+=tmpShoot->zVel; |
---|
[1926] | 79 | break; |
---|
| 80 | |
---|
[1924] | 81 | } |
---|
[1926] | 82 | |
---|
[1920] | 83 | glScalef(0.1, 0.1, 0.1); |
---|
| 84 | glutWireCube(1.0); |
---|
| 85 | glPopMatrix(); |
---|
| 86 | |
---|
| 87 | /* garbage collection: look if shoot is outside world */ |
---|
| 88 | /* fix1: weak boundaries check all four sides */ |
---|
| 89 | /* fix2: conditions, that a struct tree can be cut off */ |
---|
| 90 | /* fix3: more efficent and nicer please */ |
---|
| 91 | if (tmpShoot->yCor - DataTank::yOffset > 20) |
---|
| 92 | { |
---|
| 93 | /* normal case: delete one element, link the others */ |
---|
| 94 | if (lastRef != null) |
---|
| 95 | { |
---|
| 96 | //cout << "garbage collection" << endl; |
---|
| 97 | lastRef->next = tmpShoot->next; |
---|
| 98 | delete tmpShoot; |
---|
| 99 | tmpShoot = lastRef->next; |
---|
| 100 | //cout << "garbage collection left" << endl; |
---|
| 101 | } |
---|
| 102 | else |
---|
| 103 | { |
---|
| 104 | /* special case: first element to be processed */ |
---|
| 105 | //cout << "garbage collecton: first el in queue" << endl; |
---|
| 106 | lastRef = tmpShoot->next; |
---|
| 107 | delete tmpShoot; |
---|
| 108 | tmpShoot = lastRef; |
---|
| 109 | lastShoot = tmpShoot; |
---|
| 110 | if (tmpShoot != null) |
---|
| 111 | { |
---|
| 112 | tmpShoot = tmpShoot->next; |
---|
| 113 | //cout << "noch nich null" << endl; |
---|
| 114 | } |
---|
| 115 | else |
---|
| 116 | { |
---|
| 117 | lastRef = null; |
---|
| 118 | tmpShoot = null; |
---|
| 119 | lastShoot = null; |
---|
| 120 | //cout << "endl null" << endl; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | //cout << "garbage collection: firtst el in queue left" << endl; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | else |
---|
| 127 | { |
---|
| 128 | lastRef = tmpShoot; |
---|
| 129 | tmpShoot = tmpShoot->next; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | //cout << "ShootRocket::drawShoot - finished" << endl; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | void ShootRocket::addShoot(shoot* sh) |
---|
| 137 | { |
---|
| 138 | sh->next = null; |
---|
| 139 | lastShoot = sh; |
---|
| 140 | } |
---|
| 141 | |
---|
[1924] | 142 | void ShootRocket::addBackParable(float x, float y, float z) |
---|
[1920] | 143 | { |
---|
[1926] | 144 | |
---|
| 145 | //cout << "ShootRocket::addShoot" << endl; |
---|
| 146 | shoot* sh = new shoot; |
---|
| 147 | sh->type = BACKPARABLE; |
---|
| 148 | sh->xCor = x; sh->yCor = y; sh->zCor = z; |
---|
[1955] | 149 | sh->xVel = (-1+(float)rand() / 1000000000/step)/5; |
---|
[1926] | 150 | sh->yVel = -.3; |
---|
[1955] | 151 | sh->zVel = (1-(float)rand() / 1000000000/step)/5; |
---|
[1926] | 152 | sh->xAcc = 0; sh->yAcc = .01/step; sh->zAcc = 0; |
---|
| 153 | sh->next = lastShoot; |
---|
| 154 | lastShoot = sh; |
---|
[1929] | 155 | } |
---|
[1924] | 156 | void ShootRocket::addSideAcc(float x, float y, float z, enum RocketDirection direction) |
---|
[1920] | 157 | { |
---|
[1926] | 158 | //cout << "ShootRocket::addShoot" << endl; |
---|
| 159 | shoot* sh = new shoot; |
---|
| 160 | sh->type = SIDEACC; |
---|
| 161 | sh->xCor = x; sh->yCor = y; sh->zCor = z; |
---|
| 162 | switch (direction) |
---|
[1924] | 163 | { |
---|
[1926] | 164 | case LEFT: |
---|
| 165 | sh->xVel = -.5; sh->yVel = .05; sh->zVel = 0; |
---|
| 166 | break; |
---|
| 167 | case RIGHT: |
---|
| 168 | sh->xVel = .5; sh->yVel = .05; sh->zVel = 0; |
---|
| 169 | break; |
---|
[1924] | 170 | } |
---|
[1926] | 171 | sh->xAcc = .9; sh->yAcc = .02; sh->zAcc = 0; |
---|
| 172 | sh->next = lastShoot; |
---|
| 173 | lastShoot = sh; |
---|
[1929] | 174 | } |
---|
[1926] | 175 | |
---|
| 176 | void ShootRocket::addRotater(float x, float y, float z) |
---|
| 177 | { |
---|
| 178 | |
---|
| 179 | static float radius = 2; |
---|
[1927] | 180 | rotateAngle+=.1; |
---|
[1926] | 181 | //cout << "ShootRocket::addShoot" << endl; |
---|
| 182 | shoot* sh = new shoot; |
---|
| 183 | sh->type = ROTATER; |
---|
| 184 | sh->xCor = x+radius*sin(rotateAngle); sh->yCor = y; sh->zCor = z+radius*cos(rotateAngle); |
---|
[1942] | 185 | sh->xVel = .1*cos(rotateAngle)/step; |
---|
| 186 | sh->yVel = 0.4/step; |
---|
| 187 | sh->zVel = .1*sin(rotateAngle)/step; |
---|
[1927] | 188 | sh->xAcc = 1.01; sh->yAcc = 1.01/step; sh->zAcc = 1.01; |
---|
[1926] | 189 | sh->next = lastShoot; |
---|
| 190 | lastShoot = sh; |
---|
| 191 | } |
---|
[1920] | 192 | |
---|
| 193 | void ShootRocket::setShootStep(float step) |
---|
| 194 | { |
---|
| 195 | cout << "ShootRocket::setShootStep to " << step << endl; |
---|
| 196 | this->step = step; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | /* Exterminate shoot from game, implement this method */ |
---|
| 201 | /* if you like to add animatiion */ |
---|
| 202 | void ShootRocket::removeShoot(shoot* sh) |
---|
| 203 | { |
---|
| 204 | glPushMatrix(); |
---|
| 205 | glTranslatef(sh->xCor, sh->yCor, sh->zCor); |
---|
| 206 | glutWireCube(1.0); |
---|
| 207 | glPopMatrix(); |
---|
| 208 | } |
---|