示例#1
0
Uint32 move_ball(Uint32 interval, void * param)
{
  struct ball * the_ball = (struct ball *) param;

  if( myabs(the_ball->x - the_ball->destx) > myabs(the_ball->dx) )
    the_ball->x += the_ball->dx;
  
  if( myabs(the_ball->y - the_ball->desty) > myabs(the_ball->dy) )
    the_ball->y += the_ball->dy;

  render_ball(the_ball);
  
  return interval;
}
示例#2
0
void render() {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  //Configurando el frustrum
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(camera->aperture,(GLfloat)screen_width/(GLfloat)screen_height,1.0f,1000.0f);
	
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();


  gluLookAt(camera->position.x, camera->position.y, camera->position.z,
	    camera->center.x,   camera->center.y,   camera->center.z,
	    camera->up.x,       camera->up.y,       camera->up.z);

  /*
  //Rendering light point
  glPushMatrix();
  glDisable(GL_LIGHTING);
  glColor3f(0, 0.7, 0);
  glTranslatef(light_point->position[0], 
	      light_point->position[1],
	      light_point->position[2]);
  glutSolidSphere(0.1, 10, 10);
  glEnable(GL_LIGHTING);
  glPopMatrix();
  */
  glPushMatrix();
  glRotatef(surface->alphax,1.0,0.0,0.0);
  glRotatef(surface->alphaz,0.0,0.0,1.0);
 
	
  render_surface(surface);
  render_control_points(surface);
  render_ball(ball, surface);
  glPopMatrix();
  render_level();
  render_text();


  glFlush();
  glutSwapBuffers();
}
示例#3
0
void loop() {

    is_diff_game_mode(); // different game modes

    movePaddle();
    render_ball();
    render_right_wall();
    render_score();
    render_lives();

    lBtn2 = GPIOPinRead(BTN2Port, BTN2);

    if (lBtn2 == BTN2)
    {
        render_credits();
    }

    ballMove();

    OrbitOledUpdate();
    oledReset();
}
示例#4
0
int main(int argc,char* argv[])
{
  SDL_Surface *screen;
  SDL_Surface *ball_bmp;

  int k;

  struct ball red_ball, blue_ball;

  SDL_TimerID timer, timer2;

  int done;

  init(&screen);

  //This could be put in an init function:
  red_ball.startx=50; red_ball.starty=50; red_ball.destx=50; red_ball.desty=50;
  red_ball.x = (float)red_ball.startx; red_ball.y = (float)red_ball.starty;
  red_ball.dx = 0.0; red_ball.dy = 0.0;
  red_ball.r = 1; red_ball.g = 0; red_ball.b = 0;
  red_ball.screen = screen;
  
  blue_ball.startx=100; blue_ball.starty=50; blue_ball.destx=100; blue_ball.desty=50;
  blue_ball.x = (float)blue_ball.startx; blue_ball.y = (float)blue_ball.starty;
  blue_ball.dx = 0.0; blue_ball.dy = 0.0;
  blue_ball.r = 0; blue_ball.g = 0; blue_ball.b = 1;
  blue_ball.screen = screen;

  render_ball(&red_ball);
  render_ball(&blue_ball);

  timer = SDL_AddTimer(20, move_ball, &red_ball);
  SDL_Delay(10);
  timer2 = SDL_AddTimer(20, move_ball, &blue_ball);

  /*Handle the keyboards events here. Catch the SDL_Quit event to exit*/
  done = 0;
  while (!done)
  {
    SDL_Event event;

    /* Check for events */
    while (SDL_PollEvent (&event))
    {
      switch (event.type)
      {
        case SDL_KEYDOWN:
	  break;

        case SDL_MOUSEBUTTONDOWN: 
	{
          switch(event.button.button) 
	  {
	    case SDL_BUTTON_LEFT: 
	    {
	      
              red_ball.destx = event.button.x;
	      red_ball.desty = event.button.y;

	      red_ball.dx = (red_ball.destx - red_ball.x)/50.0;
	      red_ball.dy = (red_ball.desty - red_ball.y)/50.0;

	      break;
	    }

	    case SDL_BUTTON_RIGHT:
	    {
              blue_ball.destx = event.button.x;
	      blue_ball.desty = event.button.y;

	      blue_ball.dx = (blue_ball.destx - blue_ball.x)/50.0;
	      blue_ball.dy = (blue_ball.desty - blue_ball.y)/50.0;

	      break;
	    }

	  }
	}
	break;

	case SDL_QUIT:
	  done = 1;
	  break;

	default:
	  break;

      }
    } 
  }
}