Example #1
0
MainWindow::MainWindow(QWidget *parent) 
    : QMainWindow(parent),
      canvasWidget(new CanvasWidget(this)),
      gameIsPaused(true),
      thereIsAnotherDialog(false)
{
    Item::setCanvas(canvasWidget);
    new Background; // the background put's itself into the canvasWidget
    gameEngine = new GameEngine(this); // must be called after Item::setCanvas()

#if defined ANDROID
    setAttribute(Qt::WA_AcceptTouchEvents);
#endif
    
    connect(canvasWidget, SIGNAL(mouseMoved(int)),
            gameEngine, SLOT(moveBar(int)));
    connect(canvasWidget, SIGNAL(barMovedLeft()),
            gameEngine, SLOT(moveBarLeft()));
    connect(canvasWidget, SIGNAL(barMovedRight()),
            gameEngine, SLOT(moveBarRight()));
    connect(canvasWidget, SIGNAL(focusLost()),
            this, SLOT(pauseGame()));
    
    connect(gameEngine, SIGNAL(gamePaused()), 
            canvasWidget, SLOT(handleGamePaused()));
    connect(gameEngine, SIGNAL(gameResumed()),
            canvasWidget, SLOT(handleGameResumed()));
    connect(gameEngine, SIGNAL(gameResumed()),
            this, SLOT(handleGameResumed()));
    connect(gameEngine, SIGNAL(resetMousePosition()),
            canvasWidget, SLOT(handleResetMousePosition()));
    connect(gameEngine, SIGNAL(gameEnded(int,int,int)), 
            SLOT(handleEndedGame(int,int,int)));
    
    // cheating keys, debugging and testing only TODO: REMOVE
    connect(canvasWidget, SIGNAL(cheatSkipLevel()),
            gameEngine, SLOT(cheatSkipLevel()));
    connect(canvasWidget, SIGNAL(cheatAddLife()),
            gameEngine, SLOT(cheatAddLife()));

    connect(gameEngine, SIGNAL(levelChanged()),
            this, SLOT(handleLevelChanged()));

    connect(Settings::self(), SIGNAL(themeChanged()),
            canvasWidget, SLOT(reloadSprites()));
    
    setCentralWidget(canvasWidget);
    
    setupActions();
    setFocusProxy(canvasWidget);
    
    QSize defaultSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // show here (instead of in main) else the mouse can't be grabbed
    show();
    gameEngine->start(Settings::self()->getLevelset());
}
Example #2
0
	void GraphicsEngine::init()
	{
		scene_.setBackgroundBrush(RuneItem::colorBackground());
		view_.setScene(&scene_);

		// Loading rune images
		reloadSprites();
		
		// Setting up the scene
		Spell* s = runeEngine_.getCurrentSpell();
		Q_ASSERT(s);
		
		// Loading the current spell
		drawSpell(s);

		cout << "The scene contains : " << scene_.items().size() << endl;
	}
Example #3
0
void CanvasWidget::resizeEvent(QResizeEvent */*event*/)
{
    qDebug() << "resized!\n";
    reloadSprites();
}