-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpaceship.cpp
More file actions
68 lines (61 loc) · 1.74 KB
/
Spaceship.cpp
File metadata and controls
68 lines (61 loc) · 1.74 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"Spaceship.h"
Spaceship::Spaceship(int a, int b, int s) :Fl_Widget(a, b, a, b), x(a), y(b),start_x(a), sz(s) {}
void Spaceship::draw() {
double xx = x;
double yy = y;
double ssz = sz;
fl_color(fc);
fl_begin_complex_polygon();
fl_vertex(xx,yy+ssz);
fl_vertex(xx+ssz/4,yy+ssz/16*10);
fl_vertex(xx+ssz/4,yy+ssz/2);
fl_vertex(xx+ssz/2,yy);
fl_vertex(xx + ssz / 16*12, yy+ssz/2);
fl_vertex(xx + ssz / 16 * 12, yy + ssz / 16*10);
fl_vertex(xx + ssz , yy + ssz );
fl_vertex(xx + ssz / 2, yy + ssz / 16*12);
fl_end_complex_polygon();
fl_color(lc);
fl_line_style(0, 3, 0);
fl_line(x, y+sz,x+sz/4,y+sz/16*10);
fl_line(x + sz / 4, y + sz / 16 * 10, x + sz / 4, y + sz / 2);
fl_line( x + sz / 4, y + sz / 2,x+sz/2,y);
fl_line(x + sz / 2, y, x+sz/16*12, y+sz/2);
fl_line( x + sz / 16 * 12, y + sz / 2,x+sz/16*12,y+sz/16*10);
fl_line( x + sz / 16 * 12, y + sz / 16 * 10,x+sz,y+sz);
fl_line( x + sz, y + sz,x+sz/2,y+sz/16*12);
fl_line(x + sz / 2, y + sz / 16 * 12, x, y + sz);
}
void Spaceship::move(int a) {
x += a;
deactivate();
position(x, y);
activate();
}
void Spaceship::set_color(Fl_Color c) { lc = c; }
void Spaceship::set_fill_color(Fl_Color c) { fc = c; }
void Spaceship::reset_pos() {
x = start_x;
this->hide();
this->show();
}
std::pair<int, int> Spaceship::get_pos()const {
std::pair<int, int>cannon{ x + sz / 2,y };
return cannon;
}
Laser_beam::Laser_beam(int a, int b, int s) :
Fl_Widget(a, b, a, b), x(a), y(b), sz(s) {}
void Laser_beam::draw() {
fl_color(lc);
fl_line_style(0, 6, 0);
fl_line(x, y, x, y - sz);
}
void Laser_beam::move(int b) {
y += b;
draw();
}
void Laser_beam::set_color(Fl_Color c) { lc = c; }
std::pair<int, int> Laser_beam::get_pos()const {
std::pair<int, int>laser{ x ,y-sz/3 };
return laser;
}