int play2pMario(void){ //Return 0 if terminating, 1 if not done, 2 if 1p wins, 3 if 2p wins
	int xDrawTop;//Drawing variables for x and y of top and bottom players
	int yDrawTop;
	int xDrawBot;
	int yDrawBot;
	int topDone = 0; //0 if not done, 1 if done
	int botDone = 0; //0 if not done, 1 if done
	
	
	//Player 1
	if(stateMarTop == 3){//Check if top player is done
		topDone = 1;//Set top player as done
		if(finishedFirst == 0){finishedFirst = 1;} //If top player finishes first, set finishedFirst to 1.
	}
	
	else if(stateMarTop == 0){//Walking state for player 1
		if(buttonsLast[0] == 1){ //move left if possible
			if((yMarTop < 0 && xMarTop != 0) || !(xMarTop == 0 || marioBack[levelMark][yMarTop][xMarTop - 1] == GREEN)){//Check for collision with green pixel or left border
				xMarTop--;
			}
		}
		if(buttonsLast[1] == 1){//Move right if possible
			if((yMarTop < 0 && xMarTop != MARIOLINE[levelMark] - 1) || !(xMarTop == MARIOLINE[levelMark] - 1 || marioBack[levelMark][yMarTop][xMarTop + 1] == GREEN)){ //Check for collision with green
				xMarTop++;
			}
		}
		if(buttons[2] == 1){ //Jump if possible
			if(yMarTop <= 0 || marioBack[levelMark][yMarTop - 1][xMarTop] != GREEN){//Check for collision, if not then jump
				yMarTop--;
				stateMarTop = 1;
			}
		}
		if(stateMarTop == 0){//Check make sure still walking
			if(yMarTop < -1 || marioBack[levelMark][yMarTop + 1][xMarTop] != GREEN){//If so, then fall if no collision below
				yMarTop++;
			}
		}
	}
	
	else if(stateMarTop == 1){//Jumping state player 1
		if(buttonsLast[0] == 1){//Move left if possible
			if((yMarTop < 0 && xMarTop != 0) || !(xMarTop == 0 || marioBack[levelMark][yMarTop][xMarTop - 1]  == GREEN)){ //Check for collision/border
				xMarTop--;
			}
		}
		if(buttonsLast[1] == 1){//Move right if possible
			if((yMarTop < 0 && xMarTop != MARIOLINE[levelMark] - 1) || !(xMarTop == MARIOLINE[levelMark] - 1 || marioBack[levelMark][yMarTop][xMarTop + 1] == GREEN)){ //Check for collision
				xMarTop++;
			}
		}
		if(yMarTop <= 0 || marioBack[levelMark][yMarTop - 1][xMarTop] != GREEN){ //Continue jumping if possible, if so go up 1 and then go into falling state, otherwise if collision go to falling state
				yMarTop--;
				stateMarTop = 2;
		}
		else{
			stateMarTop = 2;
		}
	}
	
	else if(stateMarTop == 2){ //Falling state for player 1
		if(buttonsLast[0] == 1){ //Move left if possible
			if((yMarTop < 0 && xMarTop != 0) || !(xMarTop == 0 || marioBack[levelMark][yMarTop][xMarTop - 1]  == GREEN)){//Check for collision/border
				xMarTop--;
			}
		}
		if(buttonsLast[1] == 1){ //Move right if possible
			if((yMarTop < 0 && xMarTop != MARIOLINE[levelMark] - 1) || !(xMarTop == MARIOLINE[levelMark] - 1 || marioBack[levelMark][yMarTop][xMarTop + 1] == GREEN)){ //Check for collision
				xMarTop++;
			}
		}
		if(yMarTop < -1 || marioBack[levelMark][yMarTop + 1][xMarTop] != GREEN){ //Continue falling if no collision, otherwise set to walking state
			yMarTop++;
		}
		else{
			stateMarTop = 0;
		}
	}
	
	if(xMarTop == MARIOLINE[levelMark] - 1){//If reach end, set state to finished state
		stateMarTop = 3;
	}
	
	//Player 2(same as player 1)
	if(stateMarBot == 3){
		botDone = 1;
		if(finishedFirst == 0){finishedFirst = 2;}
	}
	
	else if(stateMarBot == 0){
		if(buttonsLast[3] == 1){
			if((yMarBot < 0 && xMarBot != 0) || !(xMarBot == 0 || marioBack[levelMark][yMarBot][xMarBot - 1] == GREEN)){
				xMarBot--;
			}
		}
		if(buttonsLast[4] == 1){
			if((yMarBot < 0 && xMarBot != MARIOLINE[levelMark] - 1) || !(xMarBot == MARIOLINE[levelMark] - 1 || marioBack[levelMark][yMarBot][xMarBot + 1] == GREEN)){
				xMarBot++;
			}
		}
		if(buttons[5] == 1){
			if(yMarBot <= 0 || marioBack[levelMark][yMarBot - 1][xMarBot] != GREEN){
				yMarBot--;
				stateMarBot = 1;
			}
		}
		if(stateMarBot == 0){
			if(yMarBot < -1 || marioBack[levelMark][yMarBot + 1][xMarBot] != GREEN){
				yMarBot++;
			}
		}
	}
	
	else if(stateMarBot == 1){
		if(buttonsLast[3] == 1){
			if((yMarBot < 0 && xMarBot != 0) || !(xMarBot == 0 || marioBack[levelMark][yMarBot][xMarBot - 1]  == GREEN)){
				xMarBot--;
			}
		}
		if(buttonsLast[4] == 1){
			if((yMarBot < 0 && xMarBot != MARIOLINE[levelMark] - 1) || !(xMarBot == MARIOLINE[levelMark] - 1 || marioBack[levelMark][yMarBot][xMarBot + 1] == GREEN)){
				xMarBot++;
			}
		}
		if(yMarBot <= 0 || marioBack[levelMark][yMarBot - 1][xMarBot] != GREEN){
				yMarBot--;
				stateMarBot = 2;
		}
		else{
			stateMarBot = 2;
		}
	}
	
	else if(stateMarBot == 2){
		if(buttonsLast[3] == 1){
			if((yMarBot < 0 && xMarBot != 0) || !(xMarBot == 0 || marioBack[levelMark][yMarBot][xMarBot - 1]  == GREEN)){
				xMarBot--;
			}
		}
		if(buttonsLast[4] == 1){
			if((yMarBot < 0 && xMarBot != MARIOLINE[levelMark] - 1) || !(xMarBot == MARIOLINE[levelMark] - 1 || marioBack[levelMark][yMarBot][xMarBot + 1] == GREEN)){
				xMarBot++;
			}
		}
		if(yMarBot < -1 || marioBack[levelMark][yMarBot + 1][xMarBot] != GREEN){
			yMarBot++;
		}
		else{
			stateMarBot = 0;
		}
	}
	
	if(xMarBot == MARIOLINE[levelMark] - 1){
		stateMarBot = 3;
	}
	
	
	//Check if player 1 has fallen below map
	if(yMarTop >= 4){//If so, reset them based on level start
		yMarTop = yStarts[levelMark];
		xMarTop = xStarts[levelMark];
	}
	//Player 2 fallen below map reset check
	if(yMarBot >= 4){
		yMarBot = yStarts[levelMark];
		xMarBot = xStarts[levelMark];
	}
	
	
	fixAllMario();//Fix the map to base state
	if(yMarTop >= 0){//If top player can be drawn, set their pixel to blue
		marioBack[levelMark][yMarTop][xMarTop] = BLUE;
	}
	yDrawTop = 0;//Always draw at this y position
	xDrawTop = xMarTop - 3;	//x position slides to follow player
	if (xDrawTop < 0){xDrawTop = 0;}	//Make sure x position is clipped to matrix bounds (0)
	loadtoBackBufferFullMario(xDrawTop, yDrawTop, 0, 0, 0, 0, 1, 0, 0);//Draw map for player 1, drawing clear afterwards in the x position
	fixAllMario(); //Fix map for 2nd player
	if(yMarBot >= 0){ //Draw 2nd player if possible
		marioBack[levelMark][yMarBot][xMarBot] = BLUE;
	}
	yDrawBot = 0;//Y position is always 0 for drawing
	xDrawBot = xMarBot - 3;	//Set x position
	if (xDrawBot < 0) {xDrawBot = 0;}//clip as necessary
	loadtoBackBufferFullMario(xDrawBot, yDrawBot, 0, 4, 0, 0, 1, 0, 1);//Draw map for player 2, drawing clear afterwards in the x position, and marking that this is drawn for player 2 
																																		 //(drawBot = 1 and backdrop y position starts at 4)
	swapScreens(); //Load backdrop to screen
	delay(6000);
	if(topDone == 1 && botDone == 1){ //If both players are done, return the victor
		return finishedFirst + 1;
	}
	else{	//Otherwise say game isn't done yet
		return 1;
	}
}
Exemple #2
0
DSPDFViewer::DSPDFViewer(const RuntimeConfiguration& r): 
	runtimeConfiguration(r),
	pdfDocument(Poppler::Document::load(r.filePathQString()))
	,
 renderFactory(r.filePathQString()),
 m_pagenumber(0),
 audienceWindow(0,  r.useFullPage()? PagePart::FullPage : PagePart::LeftHalf , false, r),
 secondaryWindow(1, r.useFullPage()? PagePart::FullPage : PagePart::RightHalf, true, r, r.useSecondScreen() )
{
  qDebug() << "Starting constructor" ;
  
  if ( ! r.useSecondScreen() ) {
    secondaryWindow.hide();
  }
  
  audienceWindow.showLoadingScreen(0);
  secondaryWindow.showLoadingScreen(0);
  
  if ( ! pdfDocument  || pdfDocument->isLocked() )
  {
    /// FIXME: Error message
    throw std::runtime_error("I was not able to open the PDF document. Sorry.");
  }
  setHighQuality(true);
  
  qDebug() << "Connecting audience window";
  
  audienceWindow.setPageNumberLimits(0, numberOfPages()-1);
  
  connect( &renderFactory, SIGNAL(pageRendered(QSharedPointer<RenderedPage>)), &audienceWindow, SLOT(renderedPageIncoming(QSharedPointer<RenderedPage>)));
  connect( &renderFactory, SIGNAL(thumbnailRendered(QSharedPointer<RenderedPage>)), &audienceWindow, SLOT(renderedThumbnailIncoming(QSharedPointer<RenderedPage>)));
  
  connect( &audienceWindow, SIGNAL(nextPageRequested()), this, SLOT(goForward()));
  connect( &audienceWindow, SIGNAL(previousPageRequested()), this, SLOT(goBackward()));
  connect( &audienceWindow, SIGNAL(pageRequested(uint)), this, SLOT(gotoPage(uint)));
  
  connect( &audienceWindow, SIGNAL(quitRequested()), this, SLOT(exit()));
  connect( &audienceWindow, SIGNAL(rerenderRequested()), this, SLOT(renderPage()));
  connect( &audienceWindow, SIGNAL(restartRequested()), this, SLOT(goToStartAndResetClocks()));
  
  connect( &audienceWindow, SIGNAL(screenSwapRequested()), this, SLOT(swapScreens()) );
  
  if ( r.useSecondScreen() )
  {
    qDebug() << "Connecting secondary window";
    
    secondaryWindow.setPageNumberLimits(0, numberOfPages()-1);
    
    connect( &renderFactory, SIGNAL(pageRendered(QSharedPointer<RenderedPage>)), &secondaryWindow, SLOT(renderedPageIncoming(QSharedPointer<RenderedPage>)));
    connect( &renderFactory, SIGNAL(thumbnailRendered(QSharedPointer<RenderedPage>)), &secondaryWindow, SLOT(renderedThumbnailIncoming(QSharedPointer<RenderedPage>)));

    connect( &secondaryWindow, SIGNAL(nextPageRequested()), this, SLOT(goForward()));
    connect( &secondaryWindow, SIGNAL(previousPageRequested()), this, SLOT(goBackward()));
    connect( &secondaryWindow, SIGNAL(pageRequested(uint)), this, SLOT(gotoPage(uint)));
    
    connect( &secondaryWindow, SIGNAL(quitRequested()), this, SLOT(exit()));
    connect( &secondaryWindow, SIGNAL(rerenderRequested()), this, SLOT(renderPage()));
    connect( &secondaryWindow, SIGNAL(restartRequested()), this, SLOT(goToStartAndResetClocks()));
    
    connect( &secondaryWindow, SIGNAL(screenSwapRequested()), this, SLOT(swapScreens()) );
    
    connect( this, SIGNAL(presentationClockUpdate(QTime)), &secondaryWindow, SLOT(updatePresentationClock(QTime)));
    connect( this, SIGNAL(slideClockUpdate(QTime)), &secondaryWindow, SLOT(updateSlideClock(QTime)));
    connect( this, SIGNAL(wallClockUpdate(QTime)), &secondaryWindow, SLOT(updateWallClock(QTime)));
  

  }
  
  renderPage();
  
  clockDisplayTimer.setInterval(TIMER_UPDATE_INTERVAL);
  clockDisplayTimer.start();
  connect( &clockDisplayTimer, SIGNAL(timeout()), this, SLOT(sendAllClockSignals()));
  sendAllClockSignals();
}