Ejemplo n.º 1
0
Game::Game()
    : m_scene(new QGraphicsScene(this))
    , m_scoreDisplay(new QGraphicsTextItem)
    , m_timerDisplay(new QGraphicsTextItem)
    , m_score(0)
    , m_seconds(60)
    , m_timer(new QTimer)
    , m_isActive(false)
{
    setScene(m_scene);

    auto bg = new QGraphicsPixmapItem(QPixmap(":/assets/BackGround.jpg"));
    m_scene->addItem(bg);

    auto button = new QPushButton("Start");
    button->setGeometry(80, 200, 80, 40);
    m_scene->addWidget(button);
    connect(button, SIGNAL(clicked()), this, SLOT(start()));

    m_timer->setInterval(1000);
    connect(m_timer, SIGNAL(timeout()), this, SLOT(updateTimerDisplay()));

    m_scoreDisplay->setScale(3.5);
    m_scoreDisplay->setDefaultTextColor(QColor(255, 255, 255));
    m_scoreDisplay->setPos(30, 30);
    m_scoreDisplay->setPlainText(QString("Score: 0"));
    m_scene->addItem(m_scoreDisplay);

    m_timerDisplay->setScale(3.5);
    m_timerDisplay->setDefaultTextColor(QColor(255, 255, 255));
    m_timerDisplay->setPos(30, 100);
    m_timerDisplay->setPlainText(QString("Time: 60"));
    m_scene->addItem(m_timerDisplay);
}
Ejemplo n.º 2
0
/*
 * Called every seconds to update the visuals
 */
void second_timer_callback(struct tick_t *t)
{
	t->delay = TICK_SECOND;
	
	if (state & state_IncrementTime) {
		pwmSet(pwmRunning);
		decimalInc();
	} else {
		if (tick_timer_fired(delay_StopFade)) {
			stopTimerCount++;
			if (stopTimerCount >= STANDBY_DELAY) {
				if (OCR0A < 0xff) {
					if ((stopTimerCount & 0xf) == 0) // very gradualy fade out to zero (notch every 8 secs)
						OCR0A++;
				} else
					sleepTimer(); // this will stop the one second timer
			} else {
				if (OCR0A != pwmStopped) {
					if (OCR0A > pwmStopped)
						OCR0A--;
					else
						OCR0A++;
				}
			}
		}			
	}
	updateTimerDisplay();
}
Ejemplo n.º 3
0
int main(void)
{
	PORTD = 0;
	DDRD = 0xff;

	// set power reduction register, disable everything we don't need
	PRR = (1 << PRTWI) | (1 << PRTIM1) | (1 << PRUSART0) | (1 << PRADC);

	DDRB = ~3; PORTB = 3; // pullups on PB0/PB1
	DDRC = ~1; PORTC = 1; // pullups on PC0
	PCMSK0 = (1 << PCINT1) | (1 << PCINT0);	// enable interupt for these pins
	PCMSK1 = (1 << PCINT8);					// enable interupt for these pins
	PCICR = (1 << PCIE0) | (1 << PCIE1);	// PCIE0 enable pin interupt PCINT7..0.

	tick_init();

	startShowHours(4 * TICK_SECOND);
	
	timer[delay_Second].callback = second_timer_callback;
	timer[delay_Update].callback = update_timer_callback;
	second_timer_callback(&timer[delay_Second]);	// get started
	update_timer_callback(&timer[delay_Update]);	// get started

    startTimer();
    updateKeyValues();
    keyState = lastKeyValue;
    
	SET_SRESET();

	spi_init();
	pwmInit();
		
    sei();
	
    for (;;) {    /* main event loop */
    	/* If our internal ideal of which keys are down is different from the one that has been
			updated cia the interupts, we start counting. If the 'different' key(s) stays the same for
			50ms, we declare it an 'event' and update the internsl key state
		 */
    	if (keyState != lastKeyValue) {
    		for (uint8_t ki = 0; ki < KEY_MAX; ki++)
    			if ((keyState & (1 << ki)) != (lastKeyValue & (1 << ki))) {
    				if (keyDebounce[ki] < 50) {
        				keyDebounce[ki]++;
        				if (keyDebounce[ki] == 50) {
        					keyEvent |= (1 << ki);
        					keyState = 	(keyState & ~(1 << ki)) | (lastKeyValue & (1 << ki)); 
        				}
    				}
    			}
    		/*
    		 * if a Key changed state, let's check it out
    		 */
    		if (keyEvent) {
    			if ((keyEvent & (1 << KEY_START)) &&  (keyState & (1 << KEY_START)) == 0) {
    				if (!startTimer())
    					startShowHours(4 * TICK_SECOND);
    			}
    			if ((keyEvent & (1 << KEY_STOP)) && (keyState & (1 << KEY_STOP)) == 0) {
    				if (!stopTimer())
    					startShowHours(4 * TICK_SECOND);
    			}
    			if ((keyEvent & (1 << KEY_RESET)) && (keyState & (1 << KEY_RESET)) == 0) {
    				resetTimer();
    			}
    			keyEvent = 0;
    			updateTimerDisplay();
    			updateTimer();
    		}
    		delay_ms(1);
    	} else {
    		sleep_mode();
    	}
    }
    return 0;
}