コード例 #1
0
ファイル: controller.cpp プロジェクト: Esclapion/qt-mobility
void Controller::restart_ball()
{
    if(!timer->isActive())
        return;

    elapsed->start();

    ball_x = Board::Width/2;
    ball_y = Board::Height/2;

//    ball_y = (qrand()%(Board::Height/2))+Board::Height/4;
    ball_y = (qrand()%(Board::Height-48))+24;

    // Speed in in pixels/second

    const int max = 4*FRAME_RATE;
    const int min_x = 2*FRAME_RATE;
    const int min_y = 1.5*FRAME_RATE;


    speed_y = min_y+qrand()%(max-min_y);
    if(speed_y%2)
        speed_y *= -1;


    speed_x = min_x+qrand()%(max-min_y);
    if(speed_x%2)
        speed_x *= -1;

    leftPowerUp = rightPowerUp = 0;

    emit moveBall(ball_x, ball_y);
}
コード例 #2
0
ファイル: pong.c プロジェクト: CyberjujuM/tacos
int main() {
    vesa_fd = open("$vesa", O_RDONLY);
    struct vesa_setmode_req req = { WIDTH, HEIGHT, BITS_PER_PIXEL };
    color_t color;

    int fd = open("$mouse", O_RDONLY);
    struct mousedata data;

    int ballX = WIDTH/2 - BALL_SIZE / 2;
    int ballY = HEIGHT/2 - BALL_SIZE /2;
    int velX = 10;
    int velY = 10;

    COLOR(color, BITS_PER_PIXEL).r = 255;
    COLOR(color, BITS_PER_PIXEL).g = 255;
    COLOR(color, BITS_PER_PIXEL).b = 255;
    ioctl(vesa_fd, SETMODE, &req);

    while (1) {	
	// read mouse position
	read(fd, &data, sizeof(data));
	data.y = 199 - data.y;
	data.x = data.x * WIDTH / 320;
	data.y = data.y * HEIGHT / 200;

	// draw ball and racket
	moveBall(&ballX,&ballY,&velX,&velY,data.y);
	drawBall(ballX,ballY,color);
	drawRacket(data.y,color);
	ioctl(vesa_fd, FLUSH, 0);
	
	usleep(10000);
    }
    return 0;
}
コード例 #3
0
void HelloWorld::update(float delta)
{
    int32 velocityIterations = 10;
    int32 positionIterations = 10;
    
    mWorld->Step(delta, velocityIterations, positionIterations);
    //mWorld->ClearForces();
    b2Vec2 _b2 =mBallBody->GetPosition();
    b2Vec2 _offset = _b2 - m_center;
    
    if (m_enableCenter) {
        this->setPosition(Vec2(int (-_offset.x / PTM_RATIO * this->getScale()), int (-_offset.y / PTM_RATIO* this->getScale())));
    }
    
//    mBallBody->ApplyForceToCenter(b2Vec2(10,0), true);
//    b2Vec2 _b2 = mBallBody->GetLinearVelocity();
//    float _tan = _b2.y/_b2.x ;
//    float _radian = tanh(_tan);
    //float velocity = 5;
//    float _x = velocity * sin(_radian);
//    float _y = velocity * cos(_radian);
    
//    log("%f, %f", _x, _y);
    moveBall();
}
コード例 #4
0
ファイル: main.c プロジェクト: deanrather/pong-ds
/**
 * Entry point of program.
 */
int main(int argc, char ** argv)
{
	init();
	while(true) // Keep app running
	{
		setupGame();
		while(game.lives) // New Round
		{
			setupRound();
			while(!game.gameover) // Neither player missed the ball
			{
				getInput();
				processAI();
				moveBall();
				displayOutput();
				
				// Sleep
				PA_CheckLid();
				PA_WaitForVBL();
			}
			postRound();
		}
		postGame();
	}
	return 0;
}
コード例 #5
0
ファイル: fig15_07.c プロジェクト: AlterTiton/bcit-courses
int main( void )
{
   int depth;   /* represents color depth */

   /* first, set up Allegro and the graphics mode */
   allegro_init(); /* initialize Allegro */
   install_keyboard(); /* install the keyboard for Allegro to use */
   
   depth = desktop_color_depth();  /* find out what color depth is on our computer */
   if (depth == 0)
	   depth = 32;
   set_color_depth( depth ); /* set the color depth to depth used by our computer */

   set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 ); /* set graphics mode */
   ball = load_bitmap( "ball.bmp", NULL ); /* load the ball bitmap */
   buffer = create_bitmap( SCREEN_W, SCREEN_H ); /* create buffer */
   ball_x = SCREEN_W / 2; /* give the ball its initial x-coordinate */
   ball_y = SCREEN_H / 2; /* give the ball its initial y-coordinate */
   srand( time( NULL ) ); /* seed the random function ... */
   direction = rand() % 4; /* and then make a random initial direction */

   while ( !key[KEY_ESC] ) /* until the escape key is pressed ... */
   {
      moveBall(); /* move the ball */
      /* now, perform double buffering */
      clear_to_color( buffer, makecol( 255, 255, 255 ) );
      blit( ball, buffer, 0, 0, ball_x, ball_y, ball->w, ball->h );
      blit( buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h );    
      clear_bitmap( buffer );
   } /* end while */

   destroy_bitmap( ball ); /* destroy the ball bitmap */
   destroy_bitmap( buffer ); /* destroy the buffer bitmap */
   return 0;
} /* end function main */
コード例 #6
0
void Breakout::play(int controls){
  moveBall();
  checkCollision();
  level[7-ball.y][ball.x] = 'O';
  movePaddle(controls);
  
}
コード例 #7
0
int GLWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QGLWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: clicked(); break;
        case 1: selectedRobot(); break;
        case 2: closeSignal((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 3: toggleFullScreen((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 4: robotTurnedOnOff((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
        case 5: moveRobot(); break;
        case 6: resetRobot(); break;
        case 7: selectRobot(); break;
        case 8: moveCurrentRobot(); break;
        case 9: resetCurrentRobot(); break;
        case 10: moveBall(); break;
        case 11: changeCameraMode(); break;
        case 12: yellowRobotsMenuTriggered((*reinterpret_cast< QAction*(*)>(_a[1]))); break;
        case 13: blueRobotsMenuTriggered((*reinterpret_cast< QAction*(*)>(_a[1]))); break;
        case 14: switchRobotOnOff(); break;
        case 15: moveRobotHere(); break;
        case 16: moveBallHere(); break;
        case 17: lockCameraToRobot(); break;
        case 18: lockCameraToBall(); break;
        default: ;
        }
        _id -= 19;
    }
    return _id;
}
コード例 #8
0
ファイル: World.cpp プロジェクト: Splo/SploPong
 void World::moveBall(float elapsedTime)
 {
     float x = _ball.getX();
     float y = _ball.getY();
     float orientation = _ball.getOrientation();
     float speed = _ball.getSpeed();
     float dx = std::cos(orientation) * speed * elapsedTime;
     float dy = std::sin(orientation) * speed * elapsedTime;
     if ((y + dy) > _height || (y + dy) < -_height)
     {
         float bound = (y + dy) > _height ? _height : -_height;
         float xIntersec;
         float timeIntersec;
         if (dx == 0.f)
         {
             xIntersec = x;
             timeIntersec = (bound - y) / speed;
         } else {
             float slope = dy / dx;
             xIntersec = (bound - y) / slope + x;
             timeIntersec = std::abs((bound - y) / speed);
         }
         _ball.setPosition(xIntersec, bound);
         _ball.setOrientation(- _ball.getOrientation());
         moveBall(elapsedTime - timeIntersec);
         return;
     } else {
         _ball.setPosition(x + dx, y + dy);
     }
 }
コード例 #9
0
ファイル: main.c プロジェクト: gabrielvincent/Drifts
void dispatchBalls(Ball *collectibleBalls, SDL_Surface *buffer) {
    
	float lastDispatchedInterval = SDL_GetTicks()	- lastDispatchedTicks;

	int i = 0;
	int j = 0;

  if (lastDispatchedInterval >= nextDispatchInterval) {

  	int numberOfBallsToAppearEachInterval = 1 + rand() % MAXIMUM_NUMBER_OF_BALLS_DISPATCHED;

    while (j < numberOfBallsToAppearEachInterval) {

    	if (!(collectibleBalls[i]).visible) {

    		(collectibleBalls[i]).visible = YES;
    		j++;
    	}

    	i++;
    }
 		
   	lastDispatchedTicks = SDL_GetTicks(); 
   	nextDispatchInterval = (1 + rand() % 3) * 1000; // Interval expressed in miliseconds

    return;
  }

  for (i = 0; i < MAXIMUM_BALLS; i++)
  	if ((collectibleBalls[i]).visible)
  		moveBall(&collectibleBalls[i]);
}
コード例 #10
0
ファイル: main.cpp プロジェクト: chasemc67/Asteroids
// program code aways begins at the top of main()
int main(){
  //The next line is a function drom core.cpp
  // it sets up Allegro for graphics and keyboard
  techInit();
    
  gameSetup();  
    
  // this next while loop
  while(key[KEY_ESC] == false){
    updatePaddlePosition();
    
    moveBall();
    
    if(numberOfBricksRemaining() == 0) {
      resetBricks();
    }
    
    drawingThings();
    
    // this line draws the screenBuffer to the screen
    // by drawing to off-screen memory first, then
    // copying the new total image to screen all at once,
    // we can avoid any flickering/flashing from the player
    // seeing characters drawn sequentially.
    // The technique us called double buffering.
    updateScreen();
    
    // is the game going too fast on your awesome modern hardware?
    // Experiment with numbers 0-15 here to slow down the application:
    rest(1);
    }
  return 0;
  } END_OF_MAIN()// putting this line after the main() function
コード例 #11
0
ファイル: pong.c プロジェクト: TacOS-team/tacos-gui
int main() {
    vga_fd = open("/dev/vga", O_RDONLY);
    ioctl(vga_fd, SETVGAMODE, (void*)vga_mode_320x200x256); 

    int fd = open("/dev/mouse", O_RDONLY);
    mousestate_t data;

    int ballX = WIDTH/2 - BALL_SIZE / 2;
    int ballY = HEIGHT/2 - BALL_SIZE /2;
    int velX = 10;
    int velY = 10;

    char color = 1;

    while (1) {
	clear_buffer(buffer);

	// read mouse position
	read(fd, &data, sizeof(data));
	data.y = 199 - data.y;
	data.x = data.x * WIDTH / 320;
	data.y = data.y * HEIGHT / 200;

	// draw ball and racket
	moveBall(&ballX,&ballY,&velX,&velY,data.y);
	drawBall(ballX,ballY,color);
	drawRacket(data.y,color);
	ioctl(vga_fd, FLUSHVGA, buffer);
	
	usleep(10000);
    }
    return 0;
}
コード例 #12
0
//--------------------------------------------------------------
void ofApp::draw(){
    ofSetColor(0, 0, 0);
    
    moveBall();
    ofPoint* target = reach(segments[0], ball->x, ball->y);
    for(int i=1; i<numSegments; i++){
        Segment* segment = segments[i];
        target = reach(segment, target->x, target->y);
    }
    
    for(int i=numSegments - 1; i>0; i--){
        Segment* segmentA = segments[i];
        Segment* segmentB = segments[i - 1];
        position(segmentB, segmentA);
    }
    
    checkHit();
    ofNoFill();
    ofSetColor(0, 255, 0);
    for(int i=0; i<numSegments; i++){
        segments[i]->update();
    }
    
    ofFill();
    ball->update();
}
コード例 #13
0
ファイル: main.c プロジェクト: Phillrb/vecpong
/*
 * BALL & PLAYER MOVEMENT
 */
void moveBallSprite(GameVars *gameVars){
    
    //Reposition ball - check for events
    moveBall(gameVars);
    
    //Draw ball
    drawBall(gameVars->ball);
}
コード例 #14
0
ファイル: griditem.cpp プロジェクト: FlorinLozneanu/lines
/*!
*/
void GridItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    if (!m_ballSelected) {
        event->ignore();
        return;
    }

    GridPos pt;
    fromViewToGridCoordinate(event->pos(), pt);

    if (m_beginPos == pt) {
        m_ballSelected = false;
        selectBall(pt, false);

        // clear the path tracker and repaint the grid
        m_pathTracker.clear();
        update();
        //
    } else if (isValidPosition(pt) && isFreePos(pt)) {
        QVector<GridPos>& path = m_pathTracker.path();
        if (!path.isEmpty()) {
            // have we moved onto a square occupied by a hint ball ? if we have then a new set of the hint balls
            // needs to be generated.
            BallItem *ball = ballAt(path.back());
            bool enforceHintBalls = (ball && ball->isHint());
            //

            moveBall(ballAt(m_beginPos), path);

            // unselect the moving ball
            ball = ballAt(path.back());
            ball->select(false);
            m_ballSelected = false;

            // searches for the lines of the same ball items that have the same colours.
            checkLines(ball);

            // do we have more available positions ? if we do then proceed with a new set of ball items.
            if (!BallItemsProvider::instance()->availableIndexes().isEmpty()) {
                // get the next set of balls
                const QList<BallItem*> &currentBalls = BallItemsProvider::instance()->nextBalls(enforceHintBalls);
                // searches for the lines of the same ball items that have the same colours.
                checkLines(currentBalls);
            } 
            
            // even more available positions ? if not then quit or reset the game.
            if (BallItemsProvider::instance()->availableIndexes().isEmpty()){
                if (promptForGameEnd()) {
                    QCoreApplication::quit();
                } else {
                    MainWidget::instance()->boardView()->reset();
                } 
            }
        }
    }
}
コード例 #15
0
void Game::timerEvent(QTimerEvent *)
{
    moveBall();
    repaint();

    if (leftScore >= 10 || rightScore >= 10)
    {
        endGame();
    }
}
コード例 #16
0
ファイル: fig15_12.c プロジェクト: rjgodia30/bcit-courses
int main( void )
{
    int depth;   /* represents color depth */

    /* first, set up Allegro and the graphics mode */
    allegro_init(); /* initialize Allegro */
    install_keyboard(); /* install the keyboard for Allegro to use */
    install_sound( DIGI_AUTODETECT, MIDI_AUTODETECT, NULL );

    depth = desktop_color_depth();  /* find out what color depth is on our computer */
    if (depth == 0)
        depth = 32;
    set_color_depth( depth ); /* set the color depth to depth used by our computer */

    set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 ); /* set graphics mode */
    ball = load_bitmap( "ball.bmp", NULL ); /* load the ball bitmap */
    bar = load_bitmap( "bar.bmp", NULL); /* load the bar bitmap */
    buffer = create_bitmap(SCREEN_W, SCREEN_H);/* create buffer */
    boing = load_sample( "boing.wav" ); /* load the sound file */
    pongFont = load_font( "pongfont.pcx", NULL, NULL ); /* load the font */
    ball_x = SCREEN_W / 2; /* give the ball its initial x-coordinate */
    ball_y = SCREEN_H / 2; /* give the ball its initial y-coordinate */
    barL_y = SCREEN_H / 2; /* give left paddle its initial y-coordinate */
    barR_y = SCREEN_H / 2; /* give right paddle its initial y-coordinate */
    scoreL = 0; /* set left player’s score to 0 */
    scoreR = 0; /* set right player’s score to 0 */
    srand( time( NULL ) ); /* seed the random function ... */
    direction = rand() % 4; /* and then make a random initial direction */

    while ( !key[KEY_ESC] )/* until the escape key is pressed ... */
    {
        moveBall(); /* move the ball */
        respondToKeyboard(); /* respond to keyboard input */
        /* now, perform double buffering */
        clear_to_color( buffer, makecol( 255, 255, 255 ) );
        blit( ball, buffer, 0, 0, ball_x, ball_y, ball->w, ball->h );
        blit( bar, buffer, 0, 0, 0, barL_y, bar->w, bar->h );
        blit( bar, buffer, 0, 0, 620, barR_y, bar->w, bar->h );
        /* draw text onto the buffer */
        textprintf_ex( buffer, pongFont, 75, 0, makecol( 0, 0, 0 ),
                       -1, "Left Player Score: %d", scoreL );
        textprintf_ex( buffer, pongFont, 400, 0, makecol( 0, 0, 0 ),
                       -1, "Right Player Score: %d", scoreR );
        blit( buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h );
        clear_bitmap( buffer );
    } /* end while */

    destroy_bitmap( ball ); /* destroy the ball bitmap */
    destroy_bitmap( bar ); /* destroy the bar bitmap */
    destroy_bitmap( buffer ); /* destroy the buffer bitmap */
    destroy_sample( boing ); /* destroy the boing sound file */
    destroy_font( pongFont ); /* destroy the font */
    return 0;
} /* end function main */
コード例 #17
0
main() {
    for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++) {
        ballCosines[loopVar] = cos(loopVar * 2 * PI / BALL_RESOLUTION);
        ballSines[loopVar] = sin(loopVar * 2 * PI / BALL_RESOLUTION);
    }
    loadFile();
    glfwInit();
    glfwOpenWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
    glFrustum(-1, 1, -WINDOW_HEIGHT / WINDOW_WIDTH, WINDOW_HEIGHT / WINDOW_WIDTH, 1, CAMERA_RANGE);
    for(glfwSetWindowTitle("Camera Demo"); glfwGetWindowParam(GLFW_OPENED) == GL_TRUE; glfwSwapBuffers(), glClear(GL_COLOR_BUFFER_BIT)) {
        if(glfwGetKey('A') == GLFW_PRESS)
            moveBall(-.1,0,0);
        if(glfwGetKey('D') == GLFW_PRESS)
            moveBall(.1,0,0);
        if(glfwGetKey('S') == GLFW_PRESS)
            moveBall(0,-.1,0);
        if(glfwGetKey('W') == GLFW_PRESS)
            moveBall(0,.1,0);
        if(glfwGetKey('Q') == GLFW_PRESS)
            moveBall(0,0,.1);
        if(glfwGetKey('E') == GLFW_PRESS)
            moveBall(0,0,-.1);
        if(glfwGetKey('Z') == GLFW_PRESS)
            moveBall(-xPos,-yPos,-zPos);
        if(glfwGetKey('X') == GLFW_PRESS)
            loadFile();
        physicsStep();
        glPushMatrix();
        glTranslatef(-xCam - xPos, -yCam - yPos, -zCam - zPos);
        glBegin(GL_LINE_LOOP);
        for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++)
            glVertex3f(ballCosines[loopVar] + xPos, ballSines[loopVar] + yPos, zPos);
        glEnd();
        glBegin(GL_LINE_LOOP);
        for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++)
            glVertex3f(xPos, ballCosines[loopVar] + yPos, ballSines[loopVar] + zPos);
        glEnd();
        glBegin(GL_LINE_LOOP);
        for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++)
            glVertex3f(ballSines[loopVar] + xPos, yPos, ballCosines[loopVar] + zPos);
        glEnd();
        glBegin(GL_LINE_STRIP);
        for(loopVar = 0; loopVar < vertexDataSize; loopVar += 3) {
            if(vertices[loopVar] == 0 && vertices[loopVar + 1] == 0 && vertices[loopVar + 2] == 0) {
                glEnd();
                glBegin(GL_LINE_STRIP);
            }
            else
                glVertex3f(vertices[loopVar],vertices[loopVar+1],vertices[loopVar+2]);
        }
        glEnd();
        glPopMatrix();
        for(glfwSetTime(glfwGetTime() - 1 / FPS); glfwGetTime() < 1 / FPS; );
    }
}
コード例 #18
0
void moveBalls(void)
{
  int i,j;
  for (i=0;i<lastShot;i++){
    //    shot s = shots[i];
    for (j=0;j<Length(waves[waveNumber-1].m);j++) {
      if (waves[waveNumber-1].m[j].inPlay) {
	moveBall(i,waveNumber-1,j);
	break;
      } 
    } 
  } 
}
コード例 #19
0
ファイル: DkPong.cpp プロジェクト: ice-pice/nomacs
void DkPongPort::gameLoop() {

	// logic first
	moveBall();

	movePlayer(player1, player1Speed);
	movePlayer(player2, player2Speed);

	//repaint();
	viewport()->update();
	
	//QGraphicsView::update();
}
コード例 #20
0
ファイル: mainwindow.cpp プロジェクト: edlau/GABot
MainWindow::MainWindow()
{
	setCaption(tr("GA Bots " VERSION));

	initActions();
	initMenuBar();
	initToolBar();
	initStatusBar();

	initGABotDoc();
	initView();

	ViewToolBar->setOn(true);
	ViewStatusBar->setOn(true);
	//ViewGame->setOn(true);

	connect(GABotDoc, SIGNAL(gameReady(bool)), this, SLOT(slotGameReady(bool)));
	connect(GABotDoc, SIGNAL(teamAScores()), View, SLOT(slotScoreA()));
	connect(GABotDoc, SIGNAL(teamBScores()), View, SLOT(slotScoreB()));
	connect(GABotDoc, SIGNAL(clearScores()), View, SLOT(slotClearScores()));

	connect(GABotDoc, SIGNAL(moveTeamA(Coordinate, Coordinate)), View,
		SLOT(slotMoveTeamA(Coordinate, Coordinate)));
	connect(GABotDoc, SIGNAL(moveTeamB(Coordinate, Coordinate)), View,
		SLOT(slotMoveTeamB(Coordinate, Coordinate)));
	connect(GABotDoc, SIGNAL(turnTeamA(Coordinate, Direction)), View,
		SLOT(slotTurnTeamA(Coordinate, Direction)));
	connect(GABotDoc, SIGNAL(turnTeamB(Coordinate, Direction)), View,
		SLOT(slotTurnTeamB(Coordinate, Direction)));

	connect(GABotDoc, SIGNAL(moveBall(Coordinate,Coordinate)), View,
		SLOT(slotMoveBall(Coordinate,Coordinate)));

	connect(GoGame, SIGNAL(activated()), this, SLOT(slotGoGame()));
	connect(GoGame, SIGNAL(activated()), GABotDoc, SLOT(slotStartTimer()));
	connect(StopGame, SIGNAL(activated()), GABotDoc, SLOT(slotStopTimer()));
	connect(StopGame, SIGNAL(activated()), this, SLOT(slotStopGame()));

	connect(View, SIGNAL(valueChanged(int)), this, SLOT(slotTickInterval(int)));
	connect(GABotDoc, SIGNAL(clearField()), View, SLOT(slotClearField()));

	connect(ResetScreen, SIGNAL(activated()), View, SLOT(slotClearField()));
//not sure if we should clear the field whenever regenerating the team
//	connect(TeamAGenerate,SIGNAL(activated()), View, SLOT(slotClearField()));
//	connect(TeamBGenerate,SIGNAL(activated()), View, SLOT(slotClearField()));

	connect(GABotDoc, SIGNAL(gameOver()), View, SLOT(slotClearField()));
	connect(GABotDoc, SIGNAL(gameOver()), View, SLOT(slotClearScores()));
	connect(GABotDoc, SIGNAL(gameOver()), this, SLOT(slotGameOver()));
	
}
コード例 #21
0
ファイル: controller.cpp プロジェクト: Esclapion/qt-mobility
void Controller::tick()
{
    if(col_x)
        col_x--;
    if(col_y)
        col_y--;
    
//    frames++;
//    if(fpscntr->elapsed() > 1000){
//        int f = frames/(fpscntr->elapsed()/1000.0);
//        emit fps(QString("FPS %1").arg(f));
//        frames = 0;
//        fpscntr->restart();
//    }

    int msec = elapsed->elapsed();
    elapsed->restart();

    ball_x += speed_x*msec/1000;
    ball_y += speed_y*msec/1000;


    const int decay = 5;

    if(leftPaddleForce > decay)
        leftPaddleForce-=decay;
    else if(leftPaddleForce < -decay)
        leftPaddleForce+=decay;
    if(rightPaddleForce > decay)
        rightPaddleForce-=decay;
    else if(rightPaddleForce < -decay)
        rightPaddleForce+=decay;

    if(rightPaddleForce <= decay)
        rightPowerUp++;

    if(leftPaddleForce <= decay)
        leftPowerUp++;


//    ttf++;
//    if(msec > 1000/FRAME_RATE+2 || msec < 1000/FRAME_RATE-2)
//        dev++;

//    if(!(i++%120)) {
//        qDebug() << "powerUp: " << leftPowerUp << rightPowerUp << leftPaddleForce << rightPaddleForce << speed_x*msec/1000 << speed_y*msec/1000 << msec << dev;
//        ttf = dev =0;
//    }

    emit moveBall(ball_x, ball_y);
}
コード例 #22
0
ファイル: PluginPong.cpp プロジェクト: kroimon/WordQlock
void PluginPong::update(unsigned long timeDiff, boolean realtimeSync) {
  if (!gameOver) {
    // Update the game
    movePaddles();
    moveBall();
    gameOver = isGameOver();
  }

  // Draw it!
  matrix.clear();
  matrix.drawLine(paddleTop.x, paddleTop.y, paddleTop.x + PADDLE_WIDTH - 1, paddleTop.y);
  matrix.drawLine(paddleBottom.x, paddleBottom.y, paddleBottom.x + PADDLE_WIDTH - 1, paddleBottom.y);
  matrix.setPixel(ball.x, ball.y);
}
コード例 #23
0
bool TutorialApplication::frameRenderingQueued(const Ogre::FrameEvent& evt) {
	float deltaTime = mTimer.getMicroseconds() / 1000.0f;
	deltaTime /= 4;

	mTimer.reset();
	if(BaseApplication::frameRenderingQueued(evt)){
		movePaddles(deltaTime);
		moveBall(deltaTime);
		mSceneMgr->getLight("spotLight")->setDirection(mBall->getPosition()-mSceneMgr->getLight("spotLight")->getPosition());
		mSceneMgr->getLight("spotLight2")->setDirection(mBall->getPosition()-mSceneMgr->getLight("spotLight2")->getPosition());
		return true;
	}
	else {
		return false;
	}
}
コード例 #24
0
ファイル: main.c プロジェクト: IanGoodbody/Assignment_8
void main()
{

	byte pattern[GHOST_WD] = {GHOST}; // Initialize the happy face pattern in memory
	ballStruct ball;


	//Initalize all the ball parameters
	ball.position.x = 5;
	ball.position.y = 5;
	ball.velocity.x = -1;
	ball.velocity.y = -1;

	ball.pattern = pattern;
	ball.width = GHOST_WD;

	ballStruct *ballPtr = &ball;


	// === Initialize system ================================================
	IFG1=0; /* clear interrupt flag1 */
	WDTCTL=WDTPW+WDTHOLD; /* stop WD */


	init();
	initNokia();
	initInterrupt();
	clearDisplay();
	drawBall(ballPtr);


	while(1)
	{

		if(!(TACTL & (BIT5|BIT4)))		// The program uses the Memory Control register to check if there is an inturrupt, an inturrupt has occured with the clock has stopped
		{
			clearDisplay();
			moveBall(ballPtr);
			drawBall(ballPtr);
			TACTL |= MC_1;				// Reset the Memory Control register to count up mode and resume (this process is fairly nice as it slows down the refresh speed)
		}
	}

}
コード例 #25
0
ファイル: tennisclient.cpp プロジェクト: CodeDJ/qt5-hidpi
//! [readSocket]
void TennisClient::readSocket()
{
    if (!socket)
        return;

    while (socket->bytesAvailable()) {
        QString str;

        *stream >> str;

        QStringList args = str.split(QChar(' '));
        QString s = args.takeFirst();

        if (s == "m" && args.count() == 2) {
            emit moveBall(args.at(0).toInt(), args.at(1).toInt());
        }
        else if (s == "s" && args.count() == 2){
            emit score(args.at(0).toInt(), args.at(1).toInt());
        }
        else if (s == "l" && args.count() == 1){
            emit moveLeftPaddle(args.at(0).toInt());
        }
        else if (s == "e"){ // echo
            QByteArray b;
            QDataStream s(&b, QIODevice::WriteOnly);
            s << str;
            socket->write(b);
        }
        else if (s == "E"){
            lagTimeout = 0;
            QTime then = QTime::fromString(args.at(0), "hh:mm:ss.zzz");
            if (then.isValid()) {
                emit lag(then.msecsTo(QTime::currentTime()));
//                qDebug() << "RTT: " << then.msecsTo(QTime::currentTime()) << "ms";
            }
        }
        else {
            qDebug() << Q_FUNC_INFO << "Unknown command" << str;
        }
    }
}
コード例 #26
0
ファイル: ping_pong.c プロジェクト: sanchit234/GamePack
int pingpong()
{
    buffer = create_bitmap( 640, 480); 
    BITMAP *BGpong = load_bitmap("C:\\Sanchit\\Game Pack\\Sprites\\BGpong.bmp", NULL);
    
    
    samSong = load_sample("C:\\Sanchit\\Game Pack\\Sprites\\pingpong.wav");
    play_sample(samSong, 128, 128, 1000, 1);
    setupGame();

    while( !key[KEY_ESC])
    {
        draw_sprite(buffer, BGpong, 0,0);
        textprintf(buffer,font,60,2,makecol(255,255,255), "P1=%d", count1);
        textprintf(buffer,font,540,2,makecol(255,255,255), "P2=%d", count2);        
        p1Move();
        p2Move();
        moveBall();
        
        checkWin();
        
        if(scored==1)
                pingpong_score();
        
        if(key[KEY_BACKSPACE])
        {
                      count1=0;
                      count2=0;
                      ball_x=320;
                      ball_y=240;
                      p1_x = 20;
                      p1_y = 210;
                      p2_x = 620;
                      p2_y = 210;
                      stop_sample(samSong);
                      openscreen();
        }              
    }    
    return 0;
}
コード例 #27
0
ファイル: main_demo1.cpp プロジェクト: DeanKao/ARMWork
void introScreen(){
	GLCD.ClearScreen(BLACK);
  GLCD.DrawBitmap(icon, 32,0); //draw the bitmap at the given x,y position
  countdown(3);
  GLCD.ClearScreen();
  GLCD.SelectFont(Arial_14); // you can also make your own fonts, see playground for details   
  GLCD.CursorToXY(GLCD.Width/2 - 44, 3);
  GLCD.print("GLCD version ");
  GLCD.print(GLCD_VERSION, DEC);
  GLCD.DrawRoundRect(8,0,GLCD.Width-19,17, 5);  // rounded rectangle around text area   
  countdown(3);  
  GLCD.ClearScreen(); 
  scribble(5000);  // run for 5 seconds
  moveBall(6000); // kick ball for 6 seconds
  GLCD.SelectFont(System5x7, BLACK);
  showCharacters((char*)"5x7 font:", System5x7);
  countdown(3);
  showCharacters((char*)"Arial_14:", Arial_14);
  countdown(3);
  textAreaDemo();
  scrollingDemo();
}
コード例 #28
0
ファイル: fig15_10.c プロジェクト: AlterTiton/bcit-courses
int main( void )
{
   /* first, set up Allegro and the graphics mode */
   allegro_init(); /* initialize Allegro */
   install_keyboard(); /* install the keyboard for Allegro to use */
   install_sound( DIGI_AUTODETECT, MIDI_AUTODETECT, NULL );
   set_color_depth( 16 ); /* set the color depth to 16-bit */
   set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0 ); /* set graphics mode */
   ball = load_bitmap( "ball.bmp", NULL ); /* load the ball bitmap */
   bar = load_bitmap( "bar.bmp", NULL); /* load the bar bitmap */
   buffer = create_bitmap(SCREEN_W, SCREEN_H);/* create buffer */
   boing = load_sample( "boing.wav" ); /* load the sound file */
   ball_x = SCREEN_W / 2; /* give the ball its initial x-coordinate */
   ball_y = SCREEN_H / 2; /* give the ball its initial y-coordinate */
   barL_y = SCREEN_H / 2; /* give left paddle its initial y-coordinate */
   barR_y = SCREEN_H / 2; /* give right paddle its initial y-coordinate */
   srand( time( NULL ) ); /* seed the random function ... */
   direction = rand() % 4; /* and then make a random initial direction */
   
   while ( !key[KEY_ESC] )/* until the escape key is pressed ... */
   {
      moveBall(); /* move the ball */
      respondToKeyboard(); /* respond to keyboard input */
      /* now, perform double buffering */
      clear_to_color( buffer, makecol( 255, 255, 255 ) );
      blit( ball, buffer, 0, 0, ball_x, ball_y, ball->w, ball->h );
      blit( bar, buffer, 0, 0, 0, barL_y, bar->w, bar->h );
      blit( bar, buffer, 0, 0, 620, barR_y, bar->w, bar->h );
      blit( buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h );    
      clear_bitmap( buffer );
                                            
   } /* end while */
   destroy_bitmap( ball ); /* destroy the ball bitmap */
   destroy_bitmap( bar ); /* destroy the bar bitmap */
   destroy_bitmap( buffer ); /* destroy the buffer bitmap */
   destroy_sample( boing ); /* destroy the boing sound file */
   return 0;
} /* end function main */
コード例 #29
0
ファイル: pong.cpp プロジェクト: mirgee/exercises
int main(){

    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
    
    buffer = create_bitmap( 640, 480); 
    
    setupGame();
    
    while( !key[KEY_ESC]){

        p1Move();
        p2Move();
        moveBall();
        checkWin();
   
    }    
    
    return 0;

}
コード例 #30
0
void breakoutUpdate()
{
	if(gameOver)
	{
		if(releasedKeys & KEY_TOUCH || releasedKeys & KEY_A)
			reset();	
	}
	else if(playing)
	{
		movePaddle(&paddle);
		moveBall(&ball);
		
		handleBallBricksCollisions(&ball);
		handleBallPaddleCollision(&ball, &paddle);
		
		addNewBricks();
	}
	else
	{
		ticks += timerElapsed(0);
		if(ticks > 50000 || releasedKeys & KEY_TOUCH || releasedKeys & KEY_A)
			playing = 1;
	}
}