-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeam.cpp
More file actions
68 lines (58 loc) · 2.24 KB
/
beam.cpp
File metadata and controls
68 lines (58 loc) · 2.24 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
#include "splashkit.h"
#include "battlestar.h"
#include "player.h"
#include "beam.h"
using namespace std;
//Obtain the Beam bitmap corresponding to the enumerated kind
bitmap beam_bitmap(beam_kind kind)
{
switch (kind)
{
case LASER_BLUE:
return bitmap_named("beam_laser_blue");
default:
return bitmap_named("beam_laser_red");
}
}
//Create a new Player or Enemy Beam
beam_data new_beam(point_2d starting_point, beam_origin origin)
{
//Declare variables
beam_data beam; //Beam
bitmap beam_bmp; //Bitmap of the Beam
//Obtain the Beam Origin corresponding to the enumerated kind
switch(origin)
{
case (BEAM_PLAYER_ORIGIN): //Player Origin
beam_bmp = beam_bitmap(LASER_BLUE); //Obtain bitmap of the Player Beam
break;
case(BEAM_ENEMY_ORIGIN): //Enemy Origin
beam_bmp = beam_bitmap(LASER_RED); //Obtain bitmap of the Enemy Beam
break;
}
beam.beam_sprite = create_sprite(beam_bmp); //Create the sprite of the Beam
sprite_set_x(beam.beam_sprite, starting_point.x-10); //Set the starting World x-coordinate to create the beam
sprite_set_y(beam.beam_sprite, starting_point.y-35); //Set the starting World y-coordinate to create the beam
sprite_set_dx(beam.beam_sprite, 0); //Set random movement velocities (incl. speed and direction) for the Power Up in the 2D plane
//Obtain the Beam Origin corresponding to the enumerated kind
switch(origin)
{
case (BEAM_PLAYER_ORIGIN): //Player Origin
sprite_set_dy(beam.beam_sprite, BEAM_SPEED); //Set the vertical velocity of the Player Beam to the Beam Speed
break;
case(BEAM_ENEMY_ORIGIN): //Enemy Origin
sprite_set_dy(beam.beam_sprite, - BEAM_SPEED); //Set the vertical velocity of the Player Beam to the negative of the Beam Speed
break;
}
return beam;
}
//Update the Beam
void update_beam(beam_data &beam_to_update)
{
update_sprite(beam_to_update.beam_sprite); // Apply movement based on the velocity of the Beam
}
//Draw the Background
void draw_beam(const beam_data &beam_to_draw)
{
draw_sprite(beam_to_draw.beam_sprite); //Draw the Beam
}