Newer
Older
Grégoire Payen de La Garanderie
committed
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
#include "simul/table.h"
#include "simul/robot.h"
#include <iostream>
#include <QPainter>
Table::Table(QWidget* parent) : QWidget(parent)
{
dt=0;
setAutoFillBackground(true);
QPalette p = palette();
p.setColor(QPalette::Window,QColor(Qt::darkGray));
setPalette(p);
robots.push_back(new Robot());
}
Table::~Table()
{
}
void Table::update(int dt)
{
this->dt = dt;
repaint();
}
void Table::paintEvent(QPaintEvent* evt)
{
static float l = 0;
l+= dt*0.005;
QPainter p(this);
p.setWindow(QRect(0,0,tableWidth,tableHeight));
p.setWorldMatrixEnabled(true);
for(unsigned int i=0; i<6; i++)
for(unsigned int j=0; j<6; j++)
p.fillRect(450+i*350,j*350,350,350, ((i+j) & 1) ? Qt::red : Qt::blue);
p.drawEllipse(QRectF(50.0,50.0f,100,l));
//Starting zones
p.fillRect(0,400,400,1700,QColor(0,146,54));
p.fillRect(2600,400,400,1700,QColor(0,146,54));
//Green zones
p.fillRect(0,0,400,400,Qt::red);
p.fillRect(2600,0,400,400,Qt::blue);
//Starting zones borders
p.fillRect(0,389,400,22,Qt::black);
p.fillRect(2600,389,400,22,Qt::black);
//Blocked zones
p.fillRect(450,1980,700,120,Qt::black);
p.fillRect(1850,1980,700,120,Qt::black);
p.fillRect(450,1850,22,130,Qt::black);
p.fillRect(1850,1850,22,130,Qt::black);
p.fillRect(1128,1850,22,130,Qt::black);
p.fillRect(2528,1850,22,130,Qt::black);
for(unsigned int i=0; i < robots.size(); i++)
robots[i]->paint(p,dt);
dt = 0;
}