void Level_1::createFirstSnake() { snake = new Snake; QGraphicsEllipseItem* item1 = createEllipse(100, 170, 14, 14, QPen(Qt::black), QBrush(Qt::black)); QGraphicsEllipseItem* item2 = createEllipse(86, 170, 14, 14, QPen(Qt::black), QBrush (Qt::darkGray)); QGraphicsEllipseItem* item3 = createEllipse(72, 170, 14, 14, QPen(Qt::black), QBrush (Qt::darkGray)); QGraphicsEllipseItem* item4 = createEllipse(58, 170, 14, 14, QPen(Qt::black), QBrush (Qt::darkGray)); snake->balls->append(QList<QGraphicsEllipseItem*>() << item1 << item2 << item3 << item4); snake->length = 4; scene->addItem(item1); scene->addItem(item2); scene->addItem(item3); scene->addItem(item4); }
// --- QGAMES::Ellipse* QGAMES::ObjectBuilder::readEllipse (TiXmlElement* e) { int id = -1; double vX, vY, vZ, r1, r2; vX = vY = vZ = r1 = r2 = 0.0; std::string color (__NULL_STRING__); std::map <std::string, std::string> pties; e -> Attribute (__QGAMES_ELLIPSEATTRID__, &id); e -> Attribute (__QGAMES_ELLIPSEATTRVX__, &vX); e -> Attribute (__QGAMES_ELLIPSEATTRVY__, &vY); e -> Attribute (__QGAMES_ELLIPSEATTRVZ__, &vZ); e -> Attribute (__QGAMES_ELLIPSEATTRR1__, &r1); e -> Attribute (__QGAMES_ELLIPSEATTRR2__, &r2); color = e -> Attribute (__QGAMES_ELLIPSEATTRCOLOR__); assert (id != -1); // Read the attributes...if any for (TiXmlElement* groupElement = e -> FirstChildElement (); groupElement != NULL; groupElement = groupElement -> NextSiblingElement ()) if (strcmp (groupElement -> Value (), __QGAMES_ATTRSBLOCK__) == 0) pties = readPropertiesSection (groupElement); // Creates the ellipse and returns... return (createEllipse (id, QGAMES::Position::_cero, QGAMES::Vector (__BD vX, __BD vY, __BD vZ), __BD r1, __BD r2, QGAMES::Color (color), pties)); }
/** * Draws a rotated ellipse arc. */ void RS_PainterQt::drawEllipse(const RS_Vector& cp, double radius1, double radius2, double angle, double a1, double a2, bool reversed) { QPolygon pa; createEllipse(pa, cp, radius1, radius2, angle, a1, a2, reversed); drawPolyline(pa); }
void Level_1::onAppleIntersection() { bool result = throwApple(); while (result) result = throwApple(); emit applesCountChanged(++applesCount); QGraphicsEllipseItem *item = createEllipse(snake->balls->at(snake->length - 1)->rect().x() , snake->balls->at(snake->length - 1)->rect().y(), 14, 14, QPen(Qt::black), QBrush(Qt::darkGray)); snake->balls->append(item); snake->length++; scene->addItem(item); }
Level_1::Level_1(QWidget *parent) { level = 1; maxApplesOnLevel = 1; levelSpeed = 300; walls = new QList<QGraphicsPolygonItem*>; scene = new QGraphicsScene(this); setScene(scene); scene->setSceneRect(0, 0, 750, 365); createFirstSnake(); connect(&gameTimer, SIGNAL(timeout()), this, SLOT(snakeMovement())); gameTimer.start(levelSpeed); apple = createEllipse(10, 10, 14, 14, QPen(Qt::black), QBrush(Qt::green)); applesCount = 0; throwApple(); scene->addItem(apple); }
Path Path::createCircle(const FloatPoint& center, float r) { return createEllipse(center, r, r); }