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