-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.cpp
More file actions
182 lines (157 loc) · 4.1 KB
/
Copy pathEnemy.cpp
File metadata and controls
182 lines (157 loc) · 4.1 KB
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
/*******************************************************************************
CommanderTux
Penguin In Space
Released under the GNU Public License
2005 by Andr� Schnabel (thefrogs@web.de)
*******************************************************************************/
// Enemy.cpp
#include "Enemy.h"
//
// CEnemy
// Constructor
//
CEnemy::CEnemy( int s_x, int s_y, SLevel *level,
SDL_Texture *images[NUM_ACTOR_IMAGES], int fall_speed, bool shootable )
: CActor( s_x, s_y, level, images, fall_speed )
{
m_shootable = shootable;
// Reset score
SetScoreValue( 0 );
}
//
// CWalkingEnemy
// Constructor
//
CWalkingEnemy::CWalkingEnemy( int s_x, int s_y, SLevel *level,
SDL_Texture *images[NUM_ACTOR_IMAGES], int fall_speed, int walk_speed )
: CEnemy( s_x, s_y, level, images, fall_speed, true )
{
// Start to walk into the right direction right now
if( WalkPossible( DIR_LEFT ) )
m_walking_dir = DIR_LEFT;
else
m_walking_dir = DIR_RIGHT;
m_walk_speed = walk_speed;
}
//
// Update
//
void CWalkingEnemy::Update( int *scroll_x, int *scroll_y )
{
// Walk until blob hits an obstacle and then reverse the direction
if( WalkPossible( m_walking_dir ) )
Walk( m_walking_dir, m_walk_speed );
else
g_framework->ReverseDirection( &m_walking_dir );
// Standard update func
CActor::Update( scroll_x, scroll_y, true );
}
//
// CBlob
// Constructor
//
CBlob::CBlob( int s_x, int s_y, SLevel *level,
SDL_Texture *images[NUM_ACTOR_IMAGES], int walk_speed )
: CWalkingEnemy( s_x, s_y, level, images, BLOB_FALL_SPEED, walk_speed )
{
SetId( ENEMY_BLOB );
// Blob specific score
SetScoreValue( BLOB_SCORE );
}
//
// CRobot
// Constructor
//
CRobot::CRobot( int s_x, int s_y, SLevel *level,
SDL_Texture *images[NUM_ACTOR_IMAGES], int walk_speed )
: CWalkingEnemy( s_x, s_y, level, images, ROBOT_FALL_SPEED, walk_speed )
{
SetId( ENEMY_ROBOT );
// Robot specific score
SetScoreValue( ROBOT_SCORE );
}
//
// CStoney
// Constructor
//
CStoney::CStoney( int s_x, int s_y, SLevel *level,
SDL_Texture *images[NUM_ACTOR_IMAGES] )
: CEnemy( s_x, s_y, level, images, STONEY_FALL_SPEED, false )
{
SetId( ENEMY_STONEY );
SetScoreValue( STONEY_SCORE );
// Because normally you come from left
SetDirection( DIR_LEFT );
}
//
// Update
//
void CStoney::Update( int *scroll_x, int *scroll_y )
{
int i;
// Standard update func
CActor::Update( scroll_x, scroll_y, true );
if( !GetFalling() && !IsJumping() )
{
Jump();
for( i=0; i<STONEY_JUMP_INCREASE; i+=JUMP_INCREASE_POWER )
IncreaseJump( true );
}
}
//
// CPlant
// Constructor
//
CPlant::CPlant( int s_x, int s_y, SLevel *level,
SDL_Texture *images[NUM_ACTOR_IMAGES] )
: CEnemy( s_x, s_y, level, images, 0, false )
{
SetId( ENEMY_PLANT );
SetScoreValue( PLANT_SCORE );
SetImage( m_images[DEAD_RIGHT] );
// This is stupid...
SetDirection( DIR_RIGHT );
m_last_time = g_framework->GetTicks();
m_count = 0;
}
//
// Update
//
void CPlant::Update( int *scroll_x, int *scroll_y )
{
if( g_framework->GetTicks() - m_last_time > 1000 )
{
m_last_time = g_framework->GetTicks();
if( m_count < NUM_ACTOR_IMAGES/2-1 )
m_count++;
else
m_count = 1;
SetImage( m_images[m_count] );
}
// Standard update func
CActor::Update( scroll_x, scroll_y, true );
}
//
// CSnail
// Constructor
//
CSnail::CSnail( int s_x, int s_y, SLevel *level,
SDL_Texture *images[NUM_ACTOR_IMAGES], int walk_speed )
: CWalkingEnemy( s_x, s_y, level, images, SNAIL_FALL_SPEED, walk_speed )
{
SetId( ENEMY_SNAIL );
// Snail specific score
SetScoreValue( SNAIL_SCORE );
}
//
// CRocketBall
// Constructor
//
CRocketBall::CRocketBall( int s_x, int s_y, SLevel *level,
SDL_Texture *images[NUM_ACTOR_IMAGES], int walk_speed )
: CWalkingEnemy( s_x, s_y, level, images, ROCKETBALL_FALL_SPEED, walk_speed )
{
SetId( ENEMY_ROCKETBALL );
// Rocketball specific score
SetScoreValue( ROCKETBALL_SCORE );
}