-
Notifications
You must be signed in to change notification settings - Fork 0
/
laser.cpp
56 lines (47 loc) · 1.27 KB
/
laser.cpp
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
// weapon.cpp
#include "laser.h"
#include "ship.h"
struct laser {
float x;
float y;
float h;
float w;
ofColor color;
};
struct laser* construct_laser(float h, float w) {
struct laser* this_laser;
this_laser = (struct laser*) malloc(sizeof(struct laser));
this_laser->h = h;
this_laser->w = w;
this_laser->x = 0;
this_laser->y = ofGetHeight() + (h * 2);
return this_laser;
}
void fire_laser(struct ship* ship, struct laser* laser) {
laser->x = get_ship_x(ship) + (get_ship_w(ship) / 2 - (laser->w / 2));
}
void fire_laser(struct ship* ship, struct laser* laser, ofSoundPlayer sound, int* sm) {
laser->x = get_ship_x(ship) + (get_ship_w(ship) / 2 - laser->w / 2);
laser->y = get_ship_y(ship) + (get_ship_h(ship) / 2);
sound.play();
*sm += 1;
cycle_ship_lc(ship);
}
void move_laser(struct laser* laser) {
if (laser->y < ofGetHeight() && laser->y > laser->h * -1) {
laser->y -= 8;
}
else {
laser->x = 0;
laser->y = ofGetHeight() + (laser->h * 2);
}
}
void draw_laser(struct laser* laser, ofImage* image) {
if (laser->y < ofGetHeight() && laser->y > laser->h * -1) {
ofSetColor(255, 255, 255);
image->draw(laser->x, laser->y, laser->w, laser->h);
}
}
bool laser_on_screen(struct laser* laser) {
return (laser->y < ofGetHeight() && laser->y > laser->h * -1);
}