mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Pirate.cpp
Go to the documentation of this file.
1 
6 #include "Pirate.h"
7 
8 #ifndef min
9 #define min(a,b) (((a) < (b)) ? (a) : (b))
10 #endif
11 
12 Pirate::Pirate(float r, GLuint displayList, PlayerObject *player, float maxSpeed):ForeignSpaceShip(r,displayList)
13 {
14  this->player = player;
15  this->maxSpeed = maxSpeed;
16 }
17 
19 {
20 }
21 
22 bool Pirate::behindPlayer()
23 {
24  Plane plane = Plane(player->getView(), player->getPos());
25  return ( plane.distance( this->getPos()) < 0);
26 }
27 
28 void Pirate::adjust( float t )
29 {
30  Vector3 playerPos = player->getPos();
31  Vector3 myPos = this->getPos();
32 
33  Vector3 desiredView = playerPos - myPos;
34  float distance = desiredView.length();
35 
36  bool behind = this->behindPlayer();
37  float playerSpeed = player->getSpeed();
38 
39  float actualSpeed = this->getSpeed();
40  if (distance < 6)
41  {
42  if (behind) // we are chasing the player
43  this->setSpeed(playerSpeed-0.005); // move slower to get out of range
44  // (or, if playerSpeed negative, move faster backwards)
45  if (!behind) // we are in front of the player
46  this->setSpeed(-playerSpeed-0.005); // our speed must be vise versa
47 
48  this->setShoot(true);
49  }
50  if (distance >=6 && distance <= 8)
51  {
52  if (behind)
53  this->setSpeed( playerSpeed );
54  if (!behind)
55  this->setSpeed( -playerSpeed );
56  this->setShoot(true);
57  }
58  if (distance > 8 && distance <= 15)
59  {
60  if (behind) // we are chasing the player
61  this->setSpeed(playerSpeed+0.005); // move faster to catch him
62  // (or, if playerSpeed negative, move slower backwards)
63  if (!behind) // we are in front of the player
64  this->setSpeed(-playerSpeed+0.005); // our speed must be vise versa
65  this->setShoot(true);
66  }
67  if (distance > 15 && distance <= 250)
68  {
69  this->setSpeed( maxSpeed );
70  if (this->shipWasHitOnce())
71  this->setShoot(true);
72  else
73  this->setShoot(false);
74  }
75 
76  if (distance > 250)
77  {
78  if (this->shipWasHitOnce())
79  {
80  this->setShoot(true);
81  this->setSpeed(maxSpeed);
82  }
83  else
84  {
85  this->setSpeed(0);
86  this->setShoot(false);
87  }
88  }
89 
90  desiredView.normalize();
91  this->setView(desiredView);
92 
93 }