14static const int AsteroidCount = 10;
16int main(
int argc,
char **argv)
19 QApplication app(argc, argv);
21 srand( QTime(0, 0, 0).secsTo(QTime::currentTime()));
24 QGraphicsScene graphical_scene;
25 graphical_scene.setSceneRect(0, 0, IMAGE_SIZE, IMAGE_SIZE);
26 graphical_scene.setItemIndexMethod(QGraphicsScene::NoIndex);
32 for (
int i = 0; i < AsteroidCount; ++i) {
33 QColor cok( 150, 130, 110 );
34 QColor cko( 255, 240, 0 );
38 ( rand() % 20 + 20 ) / 10.0 ,
39 (
double) (10 + rand() % 40) );
41 asteroid->setRotation(rand() % 360);
42 asteroid->setPos( IMAGE_SIZE/2 + ::sin((i * 6.28) / AsteroidCount) * 200,
43 IMAGE_SIZE/2 + ::cos((i * 6.28) / AsteroidCount) * 200 );
45 graphical_scene.addItem( asteroid );
47 logical_scene->formes.push_back( asteroid );
52 QGraphicsView view(&graphical_scene);
53 view.setRenderHint(QPainter::Antialiasing);
54 view.setBackgroundBrush(QPixmap(
":/images/stars.jpg"));
55 view.setCacheMode(QGraphicsView::CacheBackground);
56 view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
57 view.setDragMode(QGraphicsView::NoDrag);
58 view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView,
"Space - the final frontier"));
59 view.setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
60 view.setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
61 view.resize( IMAGE_SIZE, IMAGE_SIZE );
66 QObject::connect(&timer, SIGNAL(timeout()), &graphical_scene, SLOT(advance()));
An asteroid is a simple shape that moves linearly in some direction.
A class to store master shapes and to test their possible collisions with a randomized algorithm.
Polymorphic class that represents the top class of any complex shape.