robots.cpp
1.77 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "jwindow.h"
#include "jthread.h"
#include "joptions.h"
#include "iostream"
#include "vector"
class Robot : public jgui::Component {
private:
double angle;
int steps;
public:
Robot()
{
angle = M_PI;
}
virtual ~Robot()
{
}
void MoveForward(int n)
{
steps = n;
}
virtual void Paint(jgui::Graphics *g)
{
angle += 0.04;
double cangle = cos(angle),
sangle = sin(angle);
int x = 400,
y = 400,
w = 64,
h = 64;
int size = 32;
g->SetColor(0x00, 0x00, 0x00, 0xff);
g->DrawRectangle(x, y, w, h);
jgui::jpoint_t ph[] = {
{(int)(size*cos(angle+M_PI/2)), (int)(size*sin(angle+M_PI/2))},
{(int)(2*size*cos(angle)), (int)(2*size*sin(angle))},
{(int)(size*cos(angle+3*M_PI/2)), (int)(size*sin(angle+3*M_PI/2))},
};
g->DrawPolygon(x-(int)(2*size*cos(angle))/2, y-(int)(2*size*sin(angle))/2, ph, 3, true);
}
};
class Arena : public jgui::Window, public jthread::Thread {
private:
public:
Arena():
jgui::Window(0, 0, 1920, 1080)
{
Show();
}
virtual ~Arena()
{
}
virtual void Paint(jgui::Graphics *g)
{
jgui::Window::Paint(g);
for (std::vector<jgui::Component *>::iterator i=_components.begin(); i!=_components.end(); i++) {
(*i)->Paint(g);
}
g->Flip();
}
virtual void Run()
{
while (true) {
Repaint();
}
}
};
class SimpleRobot : public Robot {
private:
public:
SimpleRobot()
{
}
virtual ~SimpleRobot()
{
}
};
int main(int argc, char **argv)
{
jcommon::Options o(argc, argv);
o.SetOptions("h");
if (o.ExistsOption("h") == true) {
std::cout << ".. Robot Arena .." << std::endl;
std::cout << "version 0.01 alpha" << std::endl;
return 0;
}
Arena arena;
arena.Add(new SimpleRobot());
arena.Run();
return 0;
}