-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.cpp
More file actions
49 lines (41 loc) · 1.42 KB
/
enemy.cpp
File metadata and controls
49 lines (41 loc) · 1.42 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
#include "enemy.h"
#include "splashkit.h"
//Obtain the Enemy bitmap corresponding to the enumerated kind
bitmap enemy_bitmap(enemy_kind kind)
{
switch (kind)
{
case PAWN:
return bitmap_named("pawn");
case BISHOP:
return bitmap_named("bishop");
case KNIGHT:
return bitmap_named("knight");
default:
return bitmap_named("rook");
}
}
//Create a new Enemy
enemy_data new_enemy(double x)
{
enemy_data result; //Declare Enemy
result.kind = static_cast<enemy_kind>(rnd(6)); //Obtain a random Enemy Kind
bitmap default_bitmap = enemy_bitmap(result.kind); //Declare and assign default bitmap for the Enemy Kind
result.enemy_sprite = create_sprite(default_bitmap); //Create the Enemy sprite
//Position the Enemy in the specified x- and y- coordinates
sprite_set_x(result.enemy_sprite, x);
sprite_set_y(result.enemy_sprite, camera_y() - sprite_height(result.enemy_sprite) - 800);
//Set random movement velocities (incl. speed and direction) for the Power Up in the 2D plane
sprite_set_dy(result.enemy_sprite, rnd()*3+0.3);
return result;
}
//Draw the Enemy
void draw_enemy(const enemy_data &enemy_to_draw)
{
draw_sprite(enemy_to_draw.enemy_sprite); //Draw the Enemy
}
//Update the Enemy
void update_enemy(enemy_data &enemy_to_update)
{
update_sprite(enemy_to_update.enemy_sprite); //Update the Enemy
}