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