예제 #1
0
void MainWindow::pauseGame(){
	if(paused && human){
		resumeGame();
		return;
	}
	timer->stop();
	paused = true;
}
예제 #2
0
파일: board.cpp 프로젝트: estan/tetris
void Board::mousePressEvent(QMouseEvent* event)
{
	if (m_paused) {
		resumeGame();
	} else if (m_done || !m_started) {
		newGame();
	}
	QWidget::mousePressEvent(event);
}
예제 #3
0
int check_keys(XEvent *e, Game *g){
	g->mouseThrustOn=false;
	//keyboard input?
	static int shift=0;
	int key = XLookupKeysym(&e->xkey, 0);
	//Log("key: %i\n", key);
	if (e->type == KeyRelease) {
		keys[key]=0;
		if (key == XK_Shift_L || key == XK_Shift_R)
			shift=0;
		if(key == XK_w){
			paddle1YVel = 0;
			paddle1.setYPos(paddle1.getYPos());
		}
		if(key == XK_s){
			paddle1YVel = 0;
			paddle1.setYPos(paddle1.getYPos());
		}
		if(key == XK_o){
			paddle2YVel = 0;
			paddle2.setYPos(paddle2.getYPos());

		}
		if(key == XK_l){
			paddle2YVel = 0;
			paddle2.setYPos(paddle2.getYPos());
		}
		return 0;
	}

	if (e->type == KeyPress) {
		keys[key]=1;
		if (key == XK_Shift_L || key == XK_Shift_R) {
			shift=1;
			return 0;
		}
		if(key == XK_Return) {
			//printf("Enter pressed\n");
			createSound2();
			hud->setPaused(false);
			gameStarted = true;
			hud->setPlayer1Health(100);
			hud->setPlayer2Health(100);
			if (is_gameover == true){				
				hud->setIsShowWelcome(true);				
				gameStarted = false;
				intro = 0;
			}
			else{
				hud->setIsShowWelcome(false);
				init_ball_paddles();
				//REINITIALIZE OBSTACLE POSITION AND VELIOCITY:
				obstacle->setXPos((1250 / 2.0) - 25);
				obstacle->setYPos(900 / 2.0);	
				obstacle->setYVel(-5.0f);	
				intro = 1;
			}
			is_gameover = false;
			timer.reset();
			timer.start();            
		}
		if (hud->isShowHelpMenu()==false && hud->isShowWelcome()==false){
			if (key == XK_p && hud->isPaused()==true){				
				hud->setPaused(false);
				resumeGame();
			}
			else if (key == XK_p && hud->isPaused()==false){
				hud->setPaused(true);
				pauseGame();
			}
			else if (key == XK_q){//to quit out of game
				hud->setIsShowWelcome(true);
				hud->setPaused(false);
				gameStarted = false;
				intro = 0;
			}
		}
		if (hud->isShowWelcome() == true){
			if (key == XK_Left) {
				bgTexture = generateTexture(bgTexture, bgImage1);
				selected_screen = LEFT;
				level = 1;
			}
			else if (key == XK_Right) {
				bgTexture = generateTexture(bgTexture, bgImage2);            
				selected_screen = RIGHT;
				level = 2;
			}
			else if (key == XK_Up) {
				hud->setAI(false);//player 2 is human
				paddle2.setCpuPlayer(false);
			}
			else if (key == XK_Down){
				hud->setAI(true);//player 2 is computer
				paddle2.setCpuPlayer(true);
			}
			else if (key == XK_h) {
				hud->setIsShowWelcome(false);
				hud->setIsShowHelpMenu(true);
			}
			return 0;
		}
		if (hud->isShowHelpMenu() == true){
			if (key == XK_b){
				//SHOW HELP MENU:
				hud->setIsShowHelpMenu(false);
				hud->setIsShowWelcome(true);
			}
		}
	}
	else {
		return 0;
	}

	float paddleSpeed = 20.0f;
	if (shift){}
	switch(key) {
		case XK_Escape:
			return 1;
		case XK_w:
			paddle1YVel = paddleSpeed;
			break;
		case XK_s:
			paddle1YVel = -paddleSpeed;
			break;
		case XK_a:
			break;
		case XK_d:
			break;
		case XK_o:
			paddle2YVel = paddleSpeed;
			break;
		case XK_l:
			paddle2YVel = -paddleSpeed;
			break;
	}
	return 0;

}
예제 #4
0
Window::Window(QWidget *parent, Qt::WindowFlags wf)
:	QMainWindow(parent, wf)
{
	QWidget* contents = new QWidget(this);
	setCentralWidget(contents);

	// Create preview
	m_preview = new QLabel(contents);
	m_preview->setFixedSize(80, 100);
	m_preview->setAutoFillBackground(true);
	{
		QPalette palette = m_preview->palette();
		palette.setColor(m_preview->backgroundRole(), Qt::black);
		m_preview->setPalette(palette);
	}

	// Create level display
	m_level = new QLabel("0", contents);
	m_level->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
	m_level->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
	m_level->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);

	// Create lines display
	m_lines = new QLabel("0", contents);
	m_lines->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
	m_lines->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
	m_lines->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);

	// Create score display
	m_score = new QLabel("0", contents);
	m_score->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
	m_score->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
	m_score->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);

	// Create scoreboard
	m_score_board = new ScoreBoard(this);

	// Create board
	m_board = new Board(contents);
	connect(m_board, &Board::pauseAvailable, this, &Window::pauseAvailable);
	connect(m_board, &Board::nextPieceAvailable, m_preview, &QLabel::setPixmap);
	connect(m_board, &Board::levelUpdated, m_level, static_cast<void (QLabel::*)(int)>(&QLabel::setNum));
	connect(m_board, &Board::linesRemovedUpdated, m_lines, static_cast<void (QLabel::*)(int)>(&QLabel::setNum));
	connect(m_board, &Board::scoreUpdated, this, &Window::scoreUpdated);
	connect(m_board, static_cast<void (Board::*)(int,int,int)>(&Board::gameOver), m_score_board, &ScoreBoard::addHighScore);
	connect(m_board, static_cast<void (Board::*)(int,int,int)>(&Board::gameOver), this, &Window::gameOver);
	connect(m_board, &Board::gameStarted, this, &Window::newGame);

	// Create overlay message
	QLabel* message = new QLabel(tr("Click to start a new game."), contents);
	message->setAttribute(Qt::WA_TransparentForMouseEvents);
	message->setAlignment(Qt::AlignCenter);
	message->setStyleSheet(
		"QLabel {"
			"background-color: rgba(255, 255, 255, 200);"
			"color: black;"
			"margin: 0;"
			"padding: 0.5em;"
			"border-radius: 0.5em;"
		"}");
	message->setWordWrap(true);
	connect(m_board, &Board::showMessage, message, &QLabel::show);
	connect(m_board, &Board::showMessage, message, &QLabel::setText);
	connect(m_board, &Board::hideMessage, message, &QLabel::hide);
	connect(m_board, &Board::hideMessage, message, &QLabel::clear);

	// Create menus
	QMenu* menu = menuBar()->addMenu(tr("&Game"));
	menu->addAction(tr("&New"), m_board, SLOT(newGame()), QKeySequence::New);
	m_pause_action = menu->addAction(tr("&Pause"), m_board, SLOT(pauseGame()), tr("P"));
	m_pause_action->setEnabled(false);
	m_resume_action = menu->addAction(tr("&Resume"), m_board, SLOT(resumeGame()), tr("P"));
	m_resume_action->setVisible(false);
	menu->addSeparator();
	menu->addAction(tr("&Scores"), m_score_board, SLOT(show()));
	menu->addSeparator();
	QAction* action = menu->addAction(tr("&Quit"), this, SLOT(close()), QKeySequence::Quit);
	action->setMenuRole(QAction::QuitRole);

	menu = menuBar()->addMenu(tr("&Settings"));
	menu->addAction(tr("Application &Language..."), this, SLOT(setLocale()));

	menu = menuBar()->addMenu(tr("&Help"));
	action = menu->addAction(tr("&About"), this, SLOT(about()));
	action->setMenuRole(QAction::AboutRole);
	action = menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
	action->setMenuRole(QAction::AboutQtRole);

	// Layout window
	QGridLayout* layout = new QGridLayout(contents);
	layout->setMargin(12);
	layout->setSpacing(0);
	layout->setColumnStretch(0, 1);
	layout->setColumnMinimumWidth(1, 12);
	layout->setRowStretch(11, 1);
	layout->setRowMinimumHeight(2, 24);
	layout->setRowMinimumHeight(5, 24);
	layout->setRowMinimumHeight(8, 24);
	layout->addWidget(m_board, 0, 0, 12, 1);
	layout->addWidget(message, 0, 0, 12, 1, Qt::AlignCenter);
	layout->addWidget(new QLabel(tr("Next Piece"), contents), 0, 2, 1, 1, Qt::AlignCenter);
	layout->addWidget(m_preview, 1, 2, Qt::AlignCenter);
	layout->addWidget(new QLabel(tr("Level"), contents), 3, 2, 1, 1, Qt::AlignCenter);
	layout->addWidget(m_level, 4, 2);
	layout->addWidget(new QLabel(tr("Removed Lines"), contents), 6, 2, 1, 1, Qt::AlignCenter);
	layout->addWidget(m_lines, 7, 2);
	layout->addWidget(new QLabel(tr("Score"), contents), 9, 2, 1, 1, Qt::AlignCenter);
	layout->addWidget(m_score, 10, 2);

	// Restore window
	restoreGeometry(QSettings().value("Geometry").toByteArray());
}
예제 #5
0
파일: game.cpp 프로젝트: Zelgunn/ZelPac
void Game::nextGameFrame()
{
    static float chaseTimer = 0.0;
    static QTime lastFrameTime;

    if(!lastFrameTime.isNull())
    {
        chaseTimer += lastFrameTime.msecsTo(QTime::currentTime())/1000.0;
    }
    lastFrameTime = QTime::currentTime();

    Level *level = m_levels.at(m_currentLevel);

    // Mouvements
    QList<Ghost*> collision;
    level->movePacman();
    level->moveGhosts();
    collision.append(level->checkUnitsPositions());
    level->updateTimer();
    //
    if(level->eatenPellets() == level->pelletCount())
    {
        m_timer->stop();
        m_currentLevel++;
        if(m_currentLevel == m_levels.size())
        {
            m_victory = true;
            emit gameFinished();
            return;
        }
        else
        {
            m_isChangingLevel = true;
            m_currentLevelImageReady = false;
            Level *level = m_levels.at(m_currentLevel);
            level->startLevel();
            return;
        }
    }

    if(collision.size() > 0)
    {
        if(!Ghost::areGhostsScared())
        {
            m_lifes--;
            if(m_lifes>0)
            {
                level->resetUnitsPosition();
            }
            else
            {
                m_defeat = true;
                emit gameFinished();
                return;
            }
            m_timer->stop();
        }
        else
        {
            for(int i=0; i<collision.size(); i++)
            {
                m_score += 200 * qPow(2, m_consecutivesEnergizers);
                m_consecutivesEnergizers ++;
                QTimer::singleShot(500, this, SLOT(resumeGame()));
                m_timer->stop();
            }
        }
    }

    if(!Ghost::areGhostsScared())
        m_consecutivesEnergizers = 0;

    QPixmap *image = level->render();
    m_image = *image;
    delete image;
    m_currentLevelImageReady = true;
}
예제 #6
0
int main_thread(SceSize args, void *argp) {
sceKernelDelayThread(3000000);
        u32 keycombination;
    SceCtrlData pad;
    u32 oldButtons = 0;
       int extra = 0;
         keycombination = PSP_CTRL_RTRIGGER; //Button to start interpreter (Basic)
         u32 keycombination2 = PSP_CTRL_RTRIGGER + PSP_CTRL_LTRIGGER; // Button to start interpreter (Extra PSP Go)
        while(1){
            oldButtons = pad.Buttons;
            if (go==0){
             sceCtrlPeekBufferPositive(&pad, 1);
                          if(oldButtons != pad.Buttons)
                          {
            if(pad.Buttons & keycombination2)
			{
			pauseGame(thid1);
                    go=1;
					extra=1;
                    pspDebugScreenInit();
                    pspDebugScreenClear();
                    oldButtons = pad.Buttons;
			}else if(pad.Buttons & keycombination)
            {
                	pauseGame(thid1);
                    go=1;
                    pspDebugScreenInit();
                    pspDebugScreenClear();
                    oldButtons = pad.Buttons;
            }
            }
            }
                if (go ==1){
    pspDebugScreenSetXY(0,0);
    pspDebugScreenSetTextColor(0xffffff);
       
        int go2=1;
        SceUID id;
        if (((kuKernelGetModel() + 1) == 4) || ((kuKernelGetModel() + 1) == 5)){
		if (extra==1){
		id = sceIoDopen("ms0:/seplugins/script"); //PSP Go MS Support
		}else{
        id = sceIoDopen("ef0:/seplugins/script"); //PSP Go Internal HD Support
		}
        }else{
        id = sceIoDopen("ms0:/seplugins/script");
        }
                                 SceIoDirent entry;
                                 int script_files = -2;
                                 memset(&entry, 0, sizeof(SceIoDirent));
                             while (sceIoDread(id, &entry) > 0)
                                {
                                        script_files = script_files+1;
                                        memset(&entry, 0, sizeof(SceIoDirent));
                                }
                                sceIoDclose(id);
                                char script[256];
                                if (((kuKernelGetModel() + 1) == 4) || ((kuKernelGetModel() + 1) == 5)){
								if (extra==1){
								strcpy(script,"ms0:/seplugins/script/index.lua"); //PSP Go MS Support
								}else{
                                strcpy(script,"ef0:/seplugins/script/index.lua"); //PSP Go Internal HD Support
                                }
								}else{
                                 strcpy(script,"ms0:/seplugins/script/index.lua");
                                 }
        while(go2==1)
        {
                                 
                                const char *errMsg;
                                if (script_files>1){            
                                errMsg = runScript(extralibs, true);
                                }else{
    SceUID fp = sceIoOpen(script, PSP_O_RDONLY,0777);  
    int size = sceIoLseek(fp, 0, SEEK_END);
    sceIoLseek(fp, 0, SEEK_SET);
    unsigned char *buffer;
    buffer = malloc((size+1) * sizeof (char));
    sceIoRead(fp, buffer, size);
        buffer[size]=0;
    sceIoClose(fp);
    errMsg = runScript(buffer, true);
    free(buffer);
    }
	// System.restart sourcecode
	if (strstr(errMsg, "lpp_restart")){
    go2=0;
	// End System.restart sources
    // Temp replacing for loadfile/dofile functions: System.protodofile
    }else if (strstr(errMsg, "lpp_open")){
    char dum1[20], dum2[20], dum3[20];
    char script_path2[256];
    sscanf( errMsg, "%s %s %s %s", dum1, dum2, dum3, script_path2 );
    strcpy(script,script_path2);
    script_files=1;
    // End System.protodofile sources
                                }else if (strstr(errMsg, "resumeThread")){
                                go=0;
                                go2=0;
                                }else{
                if (errMsg != NULL);
                {
                                                pspDebugScreenClear();
                                                pspDebugScreenSetTextColor(0xffffff);
                        debugOutput("\nError: %s\n", errMsg);
                }
                debugOutput("\nPress start to restart\nPress select to resume thread\n");
                SceCtrlData pad;
               
                                int restore = 0;
                while(restore==0){
                                sceCtrlPeekBufferPositive(&pad, 1);
                                if (pad.Buttons&PSP_CTRL_START){
                                restore=1;
                                go2=0;
                                }
                                if (pad.Buttons&PSP_CTRL_SELECT){
                                resumeGame(thid1);
                                restore=1;
                                go=0;
                                go2=0;
                                }
                                }
                                }
        }


}
sceDisplayWaitVblankStart();
        }
       
        sceKernelSleepThread();
return 0;
}
예제 #7
0
Npcdialog::Npcdialog(QWidget *parent, Room *_room) : QLabel(parent)
{
    //Create Labels
    NPCimage = new QLabel(this);
    dialoglabel = new QLabel(this);
    NPCname = new QLabel(this);
    dialogtextlabel = new QLabel(this);
    dialogselectlabel[0] = new QLabel(this);
    dialogselectlabel[1] = new QLabel(this);
    inputpwlabel[0] = new QLabel(this);
    inputpwlabel[1] = new QLabel(this);
    inputpwlabel[2] = new QLabel(this);
    inputpwlabel[3] = new QLabel(this);

    //Set Position of Label
    setGeometry(0,50,740,515);
    dialoglabel->setGeometry(0,-70, 740,515);
    NPCimage->setGeometry(50,65,300,300);
    NPCname->setGeometry(45,260,300, 30);
    dialogtextlabel->setGeometry(45,280,648,63);
    dialogselectlabel[0]->setGeometry(450,350,262,26);
    dialogselectlabel[1]->setGeometry(450,375,262,26);
    inputpwlabel[0]->setGeometry(248,408,50,50);
    inputpwlabel[1]->setGeometry(320,408,50,50);
    inputpwlabel[2]->setGeometry(390,408,50,50);
    inputpwlabel[3]->setGeometry(460,408,50,50);

    //Make it visible
    this->setVisible(true);
    NPCname->setVisible(true);
    NPCimage->setVisible(true);
    dialoglabel->setVisible(true);
    dialogtextlabel->setVisible(true);
    for(int i = 0;i<2;i++)
        dialogselectlabel[i]->setVisible(true);

    //Set Font & Font color
    setLabelTextColor(NPCname);
    setLabelTextColor(dialogtextlabel);
    for(int i = 0;i<2;i++)
        setLabelTextColor(dialogselectlabel[i]);


    //Set Inner variables
    room = _room;
    unlocked = !(room->isClosed());
    map = dynamic_cast<Map*>(parent);

    //Connect
    connect(this, SIGNAL(resumeGame()), map, SLOT(resume()));
    connect(this, SIGNAL(reset()), map, SLOT(reset()));

    //typedef enum{INSOL1,INSOL2,INSOL3,FRIEND,EMPTY,TRAP}ROOMTYPE;
    if(room->isClosed())
    {
        passwdDialog();
    }
    else
    {
        ROOMTYPE roomtype = room->getroomtype();
        switch(roomtype)
        {
        case INSOL1:
            if(map->getstory()==1)
                insol1Dialog(1);
            else if(map->getstory()==0)
                insol1Dialog(5);
            else if(map->getstory()>=2)
                insol1Dialog(6);
            break;
        case INSOL2:
            if(map->getstory()==2)
                insol2DIalog(1);
            else if(map->getstory()!=2)
                insol2DIalog(4);
            break;
        case INSOL3:
            trapDialog();
            break;
        case FRIEND:
        {
            if((room->getfriend()->friendtype)==0)
                friendDialog(1);
            else
                friendDialog(2);
            break;
        }
        case TRAP:
            trapDialog();
            break;
        case EMPTY:
            emptyDialog();
            break;
        }
    }
    this->setFocus();
}
예제 #8
0
void Npcdialog::closeDialog()
{
    emit resumeGame();
}
예제 #9
0
파일: sdl.cpp 프로젝트: dtzWill/supernes
int main(int argc, char ** argv) {
	// Initialise SDL
	if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) 
		DIE("SDL_Init: %s", SDL_GetError());

  GL_Init();

  //Init SDL_TTF to print text to the screen...
  if ( TTF_Init() )
  {
    fprintf( stderr, "Error initializing SDL_ttf!\n" );
    exit ( 1 );
  }

	S9xInitDisplay(argc, argv);

	// Configure snes9x
#if CONF_GUI
	OssoInit();						// Hildon-games-wrapper initialization.
#endif
	S9xLoadConfig(argc, argv);		// Load config files and parse cmd line.
  readOptions();
#if CONF_GUI
	OssoConfig();					// Apply specific hildon-games config.
#endif

  // S9x initialization
  S9xInitDisplay(argc, argv);
  S9xInitAudioOutput();
  S9xInitInputDevices();

  while(1)
  {
    S9xInit();
    S9xReset();

    char * rom = romSelector();
    S9xSetRomFile(rom);
    free(rom);

    // Load rom and related files: state, unfreeze if needed
    loadRom();
    resumeGame();

    // Late initialization
    sprintf(String, "DrNokSnes - %s", Memory.ROMName);
    S9xSetTitle(String);
    S9xHacksLoadFile(Config.hacksFile);
    if (!S9xGraphicsInit())
      DIE("S9xGraphicsInit failed");
    S9xAudioOutputEnable(true);
    SDL_PauseAudio(0);
    S9xVideoReset();

    Config.running = true;
    do {
      frameSync();			// May block, or set frameskip to true.
      S9xMainLoop();			// Does CPU things, renders if needed.
      pollEvents();
      //Ouch that this is going here...
      updateBindingMessage();
    } while (Config.running);

    S9xVideoReset();
    S9xGraphicsDeinit();

    // Save state
    Memory.SaveSRAM(S9xGetFilename(FILE_SRAM));
    pauseGame();
    Memory.Deinit();
    S9xDeinitAPU();
  }

  // Deinitialization
  S9xAudioOutputEnable(false);
  S9xDeinitInputDevices();
  S9xDeinitAudioOutput();
  S9xDeinitDisplay();

	// Late deinitialization
	S9xUnloadConfig();
#if CONF_GUI
	OssoDeinit();
#endif

	SDL_Quit();

	return 0;
}