-
Notifications
You must be signed in to change notification settings - Fork 0
/
food.cpp
30 lines (25 loc) · 844 Bytes
/
food.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
#include <QPainter>
#include "food.h"
Food::Food(ObjectType t)
{
FunctionOfFood=(t==REWARD)?Function(rand()%FUNCTION_TYPE):NOFUNCTION;
ColorOfFood=color[FunctionOfFood];
setData(GD_Type,t);
setPos(px=(rand()%60-30)*10,py=(rand()%40-20)*10);
}
QRectF Food::boundingRect() const{
return QRectF(-SNAKE_SIZE, -SNAKE_SIZE,
SNAKE_SIZE * 2, SNAKE_SIZE * 2 );
}
void Food::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *){
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
painter->fillPath(shape(),ColorOfFood);
painter->restore();
}
QPainterPath Food::shape() const
{
QPainterPath p;
p.addEllipse(QPointF(SNAKE_SIZE / 2, SNAKE_SIZE / 2), FOOD_RADIUS, FOOD_RADIUS);
return p;
}