File: planetype.cpp

package info (click to toggle)
wing 0.7-27.1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 2,528 kB
  • ctags: 363
  • sloc: cpp: 2,468; sh: 64; makefile: 56
file content (187 lines) | stat: -rw-r--r-- 5,716 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

//========================================================================
PlaneTYPE :: PlaneTYPE ( )
: myXPos       ( 287 ),
  myYPos       ( 380 ),
  myHealth     ( 100 ),
  myImageIndex ( 0 ),
  explode_stage ( 0 ),  
  last_shot_time ( 0 ),
  myScore		(0),
  myNumLives   ( MAX_NUM_LIVES )
{ }
//========================================================================
PlaneTYPE :: ~PlaneTYPE ( )
{  }
//========================================================================
void PlaneTYPE :: LoadPlane ( char * PlaneF, char * BulletF, char * explodeF  )
{
	explode_images.LoadImages ( explodeF );
   myArrayOfImages.LoadImages ( PlaneF );
	myPlaneMasks.resize ( myArrayOfImages.Length() );
   init_sp_bb ( myPlaneMasks );
   for ( int i = 0; i < myPlaneMasks.length(); i++ )
   	mk_spr_mask ( myArrayOfImages.GetImage (i), myPlaneMasks [i] );
   myBullets.LoadWeapon ( BulletF );
}
//========================================================================
void PlaneTYPE :: SetWeapon  ( WeaponEnum new_weapon )
{
   myWeapon = new_weapon;
}
//========================================================================
int PlaneTYPE :: GetImageIndex ( ) const
{
	return myImageIndex;
}
//========================================================================
WeaponEnum PlaneTYPE ::  GetWeapon   ( ) const
{
    return myWeapon;
}
//========================================================================
int PlaneTYPE :: GetXPos       ( ) const
{
	return myXPos;
}
//========================================================================
int PlaneTYPE :: GetYPos       ( ) const
{
	return myYPos;
}
//========================================================================
int PlaneTYPE ::  GetHealth     ( ) const
{
	return myHealth;
}
//========================================================================
void PlaneTYPE :: SetHealth     ( int health )
{
	myHealth = health;
}
//========================================================================
void PlaneTYPE :: SetNumLives     ( int new_lives )
{
	myNumLives = new_lives;
}
//========================================================================
void PlaneTYPE :: SetScore ( long int score )
{
	myScore = score;
}
//========================================================================
long int PlaneTYPE :: GetScore ( ) const
{
	return myScore;
}
//========================================================================
bool PlaneTYPE :: GetDead ( ) const
{
	return dead;
}
//========================================================================
int PlaneTYPE :: GetNumLives ( ) const
{
	return myNumLives;
}
//========================================================================
void PlaneTYPE :: SetDead ( bool not_alive )
{
	dead = not_alive;
}
//========================================================================
void PlaneTYPE :: Display (  BITMAP * buffer )
{
	myBullets.UpdateAndDisplayShot ( buffer );
   if ( ! dead )
		draw_sprite ( buffer, myArrayOfImages.GetImage( myImageIndex ), myXPos, myYPos );
	else if ( explode_stage != PLANE_EXPLODE_STAGES - 1 )
   {
		draw_sprite ( buffer, explode_images.GetImage( explode_stage ), myXPos, myYPos );
		explode_stage ++;
   }
   else
		Regen_Defaults ( );
}
//========================================================================
void PlaneTYPE :: MoveLeft ( )
{
	if ( myXPos >= 0)
   {
   	myXPos-= X_VELOCITY;
      if ( myImageIndex > 0 )
        myImageIndex--;
   }
}
//========================================================================
void PlaneTYPE :: MoveRight ( )
{
   if (myXPos <= SCREEN_WIDTH-75)
   {
   	myXPos+= X_VELOCITY;
      if ( myImageIndex < myArrayOfImages.Length()-1 )
        myImageIndex++;
   }
}
//=========================================================================
void PlaneTYPE :: MoveUp   ( )
{
	if (myYPos >= 0 )
     myYPos-= Y_VELOCITY;
}
//========================================================================
void PlaneTYPE :: MoveDown ( )
{
  if ( myYPos <= SCREEN_HEIGHT-75 )
      myYPos+= Y_VELOCITY;
}
//=======================================================================
bool PlaneTYPE :: Fire ( )
{
	if ( timer - last_shot_time > BULLET_PAUSE )
   {
   	last_shot_time = timer;
		return myBullets.Fire ( myXPos, myYPos,myWeapon );
	}
	return false;
}
//=======================================================================
void PlaneTYPE :: Normalize      ( )
{
	if ( myImageIndex != myArrayOfImages.Length()/2 )
     if ( myImageIndex > myArrayOfImages.Length()/2 ) myImageIndex--;
       else myImageIndex++;
}
//=======================================================================
BITMAP * PlaneTYPE ::  GetImage ( int index ) const
{
	return myArrayOfImages.GetImage ( index );
}
//=======================================================================
BulletTYPE * PlaneTYPE ::  GetBullets   (  )
{
	return  (& myBullets) ;
}
//=======================================================================
spr_mask  * PlaneTYPE :: GetMask ( )
{
	return (&myPlaneMasks[myImageIndex]);
}
//=======================================================================
void PlaneTYPE :: Game_Defaults ( )
{
	myNumLives = MAX_NUM_LIVES ;
   myScore = 0 ;
   Regen_Defaults ( );
}
//=======================================================================
void PlaneTYPE :: Regen_Defaults ( )
{
   myXPos = 287;
   myYPos = 380;
   myWeapon = laser;
   myImageIndex = myArrayOfImages.Length () / 2;
   dead = false;
   explode_stage = 0;
}
//=======================================================================