-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEnemy.dart
More file actions
32 lines (24 loc) · 713 Bytes
/
Enemy.dart
File metadata and controls
32 lines (24 loc) · 713 Bytes
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
/**
*
* Class represeting a single Enemy
*
*/
class Enemy extends ScreenObject {
int startX, direction;
static final int SIZE = 40;
static final int DX = 2;
static final int DY = 1;
Enemy(CanvasRenderingContext2D context, int direction, int x, int y):
super(context, x, y, SIZE, Game.enemyImage) {
this.startX = x;
this.direction = direction;
draw();
}
bool get atBottom() => y > 700;
/** Check for direction change before calling super class */
void updatePosition(int dx, int dy) {
if (x >= startX + 2 * SIZE) direction = Directions.LEFT;
else if (x <= startX) direction = Directions.RIGHT;
super.updatePosition(direction * dx, dy);
}
}