Exemplo n.º 1
0
void Joystick::JoyRead() {

breath();	// just a sleep	
	
}
Exemplo n.º 2
0
/**
 * This function add all of the necessary components for game play to the scene.
 * @brief RoundOne::start_game sets the speed of the dragon and fireballs and adds objects of classes Harry, Dragon, Egg, Score, and Health to the scene and then begins the game by starting the horntail breathing fire.
 */
void RoundOne::start_game(){
    ///Close the main menu
    main_widget->close();
    ///if retrying game again, clear away the game over window
    scene_one->clearFocus();
    scene_one->clear();


    int n=0;
    ///set the level depending on which QRadioButton was checked
    if(easy->isChecked()){
        speed= 100;
        n=650;
    }else if(medium->isChecked()){
        speed=70;
        n=500;
    }else if(hard->isChecked()){
        speed=40;
        n=300;
    }

    ///create new Egg
    egg= new Egg();

    ///create new Dragon
    horntail= new Dragon();

    ///create new Harry called player, scale player, set position of player
    player = new Harry();
    player->setScale(.20);
    player-> setPos(375, 540);

    ///make player focusable and then set focus
    player->setFlag(QGraphicsItem::ItemIsFocusable);
    player->setFocus();


    ///add player, horntail, and egg to the scene
    scene_one->addItem(player);
    scene_one->addItem(horntail);
    scene_one->addItem(egg);

    ///create and add score to the scene
    score= new Score();
    scene_one->addItem(score);

    ///create and add health to the scene and set its position
    health= new Health();
    health->setPos(700, 0);
    scene_one->addItem(health);

    ///add sound
    flying_music= new QMediaPlayer();
    flying_music->setMedia(QUrl("qrc:/new/prefix2/03 The Quidditch World Cup 2.mp3"));
    QTimer* flying_music_timer= new QTimer();
    //QObject::connect(flying_music_timer, SIGNAL(timeout()), flying_music, SLOT(play()));
    //flying_music_timer->start(1000);
    flying_music->play();


    ///create QTimer and then connect it to the horntail breathing fire at player
    QTimer* timer= new QTimer();
    QObject::connect(timer, SIGNAL(timeout()), horntail, SLOT(breath()));
    timer->start(n);



    ///show the scene
    show();


}
Exemplo n.º 3
0
void Joystick::JoyRead() {
	
	struct js_event js;		// joystick structure
	MPI_Status status;
	int received;
	int input_update;
	MPI_Request request;	

	MPI_Irecv(&input_update, 1, MPI_INT, MAIN, INPUT_UPDATE, MPI_COMM_WORLD, &request);
	received=1;
	
	int checkUpdate=0; // to check if joystick was removed
	
	while(true)	{

		if(this->sucess) {
		
    	    if (read(this->fd, &js, sizeof(struct js_event)) != sizeof(struct js_event)) {
				checkUpdate++;
				if(checkUpdate>800) {
					close(this->fd);
					if(!joyInit(this->deviceName)) {
						cout << "Connection lost with joystick" << endl;
						this->sucess=false;
					}
					checkUpdate=0;
				}
    	    }
    	    else {
				checkUpdate=0;
				switch (js.type) {
					case JS_EVENT_BUTTON: // Botoes controlam movimentacao
						button[((int)js.number)] = (short int)js.value;
						break;
					case JS_EVENT_AXIS:   // Axis controla direcao do olhar
						axis[((int)js.number)] = (short int)js.value;
						break;
				}
        	}
		
			MPI_Test(&request, &received, &status);
			if(received) {
				MPI_Wait(&request, &status);
				MPI_Irecv(&input_update, 1, MPI_INT, MAIN, INPUT_UPDATE, MPI_COMM_WORLD, &request);
	
				this->data[0]=0;
				this->data[1]=0;
				this->data[2]=0;
				this->data[3]=0;
				this->data[4]=0;
				this->data[5]=0;


				if(this->lll->conf->getJoystick(0)) {
					cout << "Joystick defined in the configuration file" << endl;
					
					
					
				} else {
					//cout << "Joystick not defined in the configuration file" << endl;
				}
				
				switch(this->mode) {
				case 1: // force feedback
					if (button[2]==1) { this->data[1]= speed;}
					if (button[3]==1) { this->data[1]= -speed; } 
					if ( (!button[2]) && (!button[3])) { this->data[1]= 0; }
					this->data[4]= speed*((float)((int)(-axis[4])))/32767 ; // rotate in y
					this->data[2]= (speed*20*((float)((int)(-axis[1])))/327670) + (speed*((float)((int)(-axis[5])))/327670); // translate in z
					this->data[0]= speed*20*((float)((int)axis[0]))/327670 ; // translate in x
					this->data[3]= speed*((float)((int)axis[7]))/32767 ; // rotate in x
				break;

				case 2: //skate
					if (button[0]==1) { this->data[0]= -speed;} // translate to left
					if (button[2]==1) { this->data[0]= speed;} // translate to right
					if ( (!button[0]) && (!(int)button[2])) { this->data[0]= 0; } // not left and right
					if (button[1]==1) { this->data[1]= speed;} // translate down
					if (button[3]==1) { this->data[1]= -speed;} // translate up
					if ( (!button[1]) && (!(int)button[3])) { this->data[1]= 0; } // not up and down
					if (button[8]==1 || (((int)axis[1]) < 0 )) { this->data[2]= speed;} // left

					//if ((int)button[9]==1 || (((int)axis[1]) > 0 )){ this->data[2]= -0.1; } // fowrward
					if ( ((axis[1]) > 0 )){ this->data[2]= -speed; } // fowrward
					if ( (!button[8]) && (!(int)button[9]) && (((int)axis[1])==0) ) { this->data[2]= 0; } // not left and right
						
					this->data[4]= -((float)((int)axis[0]))/32767;
					break;

				case 3: //game pad
					if ( ((axis[1]) <  -1 )) { this->data[2]= speed;} // 
					if ( ((axis[1]) >  1 )) { this->data[2]= -speed;} // 
					if ( ((axis[0]) <  -1 )) { this->data[4]=+1.25+speed*0.12;} // 
					if ( ((axis[0]) >  1 )) { this->data[4]= -1.25-speed*0.12;} // 

					if ( button[0]==1 ) { this->data[1]= speed;} // 
					if ( button[1]==1 ) { this->data[0]= speed;} // 
					if ( button[2]==1 ) { this->data[0]= -speed;} // 
					if ( button[3]==1 ) { this->data[1]= -speed;} // 

					if (button[4]==1) { speed /= 1.04;} // 
					if (button[5]==1) { speed *= 1.04;} // 
					break;
											
				case 4: //soundblaster
					if(axis[0]<30000) this->data[4] = speed/3; else
					if(axis[0]<10000) this->data[4] = 0; else
					this->data[4] = -speed/3; 

					if(axis[1]<20000) this->data[1] = speed/3; else
					if(axis[1]<10000) this->data[1] = 0; else
					this->data[1] = -speed/3; 
					
					this->data[2]= 2*speed/3;
					break;

				case 5: // 
					if(axis[0]<30000) this->data[4] = speed/3; else
					if(axis[0]<10000) this->data[4] = 0; else
					this->data[4] = -speed/3; 

					if(axis[1]<20000) this->data[1] = speed/3; else
					if(axis[1]<10000) this->data[1] = 0; else
					this->data[1] = -speed/3; 

					this->data[2]= 2*speed/3;
					break;
					
					
				case 6: //game pad
					if ( ((axis[1]) <  -1 )) { this->data[2]= speed;} // 
					if ( ((axis[1]) >  1 )) { this->data[2]= -speed;} // 

					if ( ((axis[0]) <  -1 )) { this->data[4]=+1.25+speed*0.12;} // 
					if ( ((axis[0]) >  1 )) { this->data[4]= -1.25-speed*0.12;} // 

					if ( button[0]==1 ) { this->data[1]= speed;} // 
					if ( button[1]==1 ) { this->data[0]= speed;} // 
					if ( button[3]==1 ) { this->data[0]= -speed;} // 
					if ( button[4]==1 ) { this->data[1]= -speed;} // 

					if (button[6]==1) { speed /= 1.04;} // 
					if (button[7]==1) { speed *= 1.04;} // 
					break;
					
				case 7: //soundblaster
					if(axis[0]<-10000) this->data[4] = 1*speed; else
					//if(axis[0]<-100) this->data[4] = 0; else
					this->data[4] = -1*speed; 

					this->data[1]= 0.3*speed*((float)((int)(-axis[1])))/(32767) ; // rotate in y
					/*
					if(axis[1]<20000) this->data[1] = speed/3; else
					if(axis[1]<10000) this->data[1] = 0; else
					this->data[1] = -speed/3; 
					
					this->data[2]= 2*speed/3;
					
					*/
					break;

					
				default:
					if ( ((axis[1]) <  -1 )) { this->data[2]= speed;} // 
					if ( ((axis[1]) >  1 )) { this->data[2]= -speed;} // 

					if ( ((axis[0]) <  -1 )) { this->data[4]= 2;} // 
					if ( ((axis[0]) >  1 )) { this->data[4]= -2;} // 

					if ( button[0]==1 ) { this->data[1]= speed;} // 
					if ( button[1]==1 ) { this->data[0]= speed;} // 
					if ( button[2]==1 ) { this->data[0]= -speed;} // 
					if ( button[3]==1 ) { this->data[1]= -speed;} // 

					if (button[4]==1) { speed /= 1.1;} // 
					if (button[5]==1) { speed *= 1.1;} // 
					break;
			}

			Input::move(this->data);
					
		}
		
		#ifdef DEBUG
			unsigned short int f;
			for(f=0;f<(this->numberOfAxes);f++) 
				cout << "Axes " << f << " : " << axis[f] << endl;
			for(f=0;f<(this->numberOfButtons);f++) 
				cout << "Button " << f << " : " << button[f] << endl;
			for(f=0;f<6;f++)
				cout << "Data " << f << " : " << data[f] << endl; 
		#endif
			
	} else {
		
		// do nothing
		MPI_Test(&request, &received, &status);
		if(received) {
			MPI_Wait(&request, &status);
			MPI_Irecv(&input_update, 1, MPI_INT, MAIN, INPUT_UPDATE, MPI_COMM_WORLD, &request);
			Input::move(this->data); //just for not locking but have to be fixed
		}
		
		joyInit(this->deviceName); // try to reconect
	}
	
	breath();	// just a sleep	

	}
	
}