/* Send a new blob travelling upward.
   This blob will actually be composed of N metaballs that are near
   each other.
 */
static void
launch_balls (ModeInfo *mi)
{
  lavalite_configuration *bp = &bps[MI_SCREEN(mi)];
  metaball *b0 = get_ball (mi);
  int i;

  if (!b0) return;
  reset_ball (mi, b0);

  for (i = 0; i < bp->blobs_per_group; i++)
    {
      metaball *b1 = get_ball (mi);
      if (!b1) break;
      *b1 = *b0;

      reset_ball (mi, b1);
      b1->leader = b0;

# define FROB(FIELD,AMT) \
         b1->FIELD += (bellrand(AMT) * b0->FIELD)

   /* FROB (pos_r,  0.7); */
   /* FROB (pos_th, 0.7); */
      FROB (dr, 0.8);
      FROB (dz, 0.6);
# undef FROB
    }

}
/**
 * Draw ball animation
 */
void draw_balls(SDL_Surface* screen, int time)
{
    SDL_Rect spritepos;
    
    // Clear screen
    SDL_FillRect(screen, NULL, 0x00000000);
    
    // Draw balls
    for(int i = 0; i < NUM_BALLS; i++)
    {
      // Advance ball
      balls[i].x += balls[i].speedx;
      balls[i].angle += balls[i].dangle;
      balls[i].amplitude *= 0.995;
      
      spritepos.x = balls[i].x;
      spritepos.y = HEIGHT - 32 - abs(balls[i].amplitude * fast_sin((balls[i].angle / 180.0) * MATH_PI));

      SDL_BlitSurface(ball_surface[balls[i].color], NULL, screen, &spritepos);
      
      // Reset ball if needed
      if(balls[i].x > WIDTH)
	 reset_ball(i);
    }
}
Beispiel #3
0
static void command (int cmd)
{
  switch (cmd) 
  {
    case ' ':
	  reset_ball();
      break;
  }
}
Beispiel #4
0
t_ball				*init_ball(void)
{
	t_ball	*ball;

	ball = (t_ball *)ft_memalloc(sizeof(t_ball));
	if (!ball)
		exit(EXIT_FAILURE);
	reset_ball(ball);
	return (ball);
}
/* Generate the blobs that don't move: the ones at teh top and bottom
   that are part of the scenery.
 */
static void
generate_static_blobs (ModeInfo *mi)
{
  lavalite_configuration *bp = &bps[MI_SCREEN(mi)];
  metaball *b0, *b1;
  int i;

  b0 = get_ball (mi);
  if (!b0) abort();
  b0->static_p = True;
  b0->alive_p = True;
  b0->R = 0.6;
  b0->r = 0.3;

  /* the giant blob at the bottom of the bottle.
   */
  b0->pos_r = 0;
  b0->pos_th = 0;
  b0->dr = 0;
  b0->dz = 0;
  b0->x = 0;
  b0->y = 0;
  b0->z = -0.43;

  /* the small blob at the top of the bottle.
   */
  b1 = get_ball (mi);
  if (!b1) abort();

  *b1 = *b0;
  b1->R = 0.16;
  b1->r = 0.135;
  b1->z = 1.078;

  /* Some extra blobs at the bottom of the bottle, to jumble the surface.
   */
  for (i = 0; i < bp->blobs_per_group; i++)
    {
      b1 = get_ball (mi);
      if (!b1) abort();
      reset_ball (mi, b1);
      b1->static_p = True;
      b1->z = frand(0.04);
      b1->dr = 0;
      b1->dz = 0;
    }
}
Beispiel #6
0
void				update_ball(t_ball *ball, t_list_node *bricks)
{
	int				i;
	t_game			*game;

	game = get_game();
	i = 0;
	while (i < 10)
	{
		ball->x += (ball->speedx) / 10.0f;
		ball->y += (ball->speedy) / 10.0f;
		handle_bounds(ball);
		if (!INVINCIBLE_MODE && is_ball_outside(ball))
		{
			game->cur_level->lives--;
			reset_ball(ball);
		}
		check_collisions(ball, bricks);
		i++;
	}
}
int main(int argc, char** argv)
{
  SDL_Event event;

  int keypress = 0;
  int t = 0;
  
  // Init everything
  sdl_init();
  init_sin_table();
  
  // Init random number generator
  srand(clock());
  
  // Init balls
  for(int i = 0; i < NUM_BALLS; i++)
    reset_ball(i);
  
  // Create sprites
  ball_surface[0] = sprite_create_ball(1.0, 0.0, 0.0);
  ball_surface[1] = sprite_create_ball(0.0, 1.0, 0.0);
  ball_surface[2] = sprite_create_ball(0.0, 0.0, 1.0);
  
  // Loop until the end
  while(!keypress) 
  {
    // Lock SDL surface if needed
    if(SDL_MUSTLOCK(screen)) 
      if(SDL_LockSurface(screen) < 0)
	exit(EXIT_FAILURE);
  
    // Draw the plasma
    draw_balls(screen, t);

    // Unlock the SDL surface if needed
    if(SDL_MUSTLOCK(screen))
      SDL_UnlockSurface(screen);
  
    // Flip surfaces
    SDL_UpdateRect(screen, 0, 0, 0, 0);
      
    // Handle SDL events
    while(SDL_PollEvent(&event)) 
    {      
      switch (event.type) 
      {
	case SDL_QUIT:
	case SDL_KEYDOWN:
	  keypress = 1;
	  break;
      }
    }
    
    // Sleep until next frame (25 FPS)
    usleep(40000);
    
    // Advance time
    t++;
  }
  
  // Exit gracefully
  SDL_Quit();
  return EXIT_SUCCESS;
}
Beispiel #8
0
int main (int argc, char **argv)
{
  dMass m;
  dMatrix3 R;

  // setup pointers to drawstuff callback functions
  dsFunctions fn;
  fn.version = DS_VERSION;
  fn.start = &start;
  fn.step = &simLoop;
  fn.command = &command;
  fn.stop = 0;
  fn.path_to_textures = "../../drawstuff/textures";
  if(argc==2)
    fn.path_to_textures = argv[1];

  // create world
  world = dWorldCreate();
  space = dHashSpaceCreate (0);

  contactgroup = dJointGroupCreate (0);
  dWorldSetGravity (world,0,0,-9.8);
  dWorldSetQuickStepNumIterations (world, 64);

  // Create a static world using a triangle mesh that we can collide with.
  int numv = sizeof(world_vertices)/(3*sizeof(float));
  int numi = sizeof(world_indices)/ sizeof(int);
  printf("numv=%d, numi=%d\n", numv, numi);
  dTriMeshDataID Data = dGeomTriMeshDataCreate();

//  fprintf(stderr,"Building Single Precision Mesh\n");

  dGeomTriMeshDataBuildSingle
  (
    Data, 
    world_vertices, 
    3 * sizeof(float), 
    numv, 
    world_indices, 
    numi, 
    3 * sizeof(int)
  );

  world_mesh = dCreateTriMesh(space, Data, 0, 0, 0);
  dGeomTriMeshEnableTC(world_mesh, dSphereClass, false);
  dGeomTriMeshEnableTC(world_mesh, dBoxClass, false);
  dGeomSetPosition(world_mesh, 0, 0, 0.5);
  dRSetIdentity(R);
  //dIASSERT(dVALIDMAT3(R));

  dGeomSetRotation (world_mesh, R);

  float sx=0.0, sy=3.40, sz=6.80;
  sphbody = dBodyCreate (world);
  dMassSetSphere (&m,1,RADIUS);
  dBodySetMass (sphbody,&m);
  sphgeom = dCreateSphere(0, RADIUS);
  dGeomSetBody (sphgeom,sphbody);
  reset_ball();
  dSpaceAdd (space, sphgeom);

  // run simulation
  dsSimulationLoop (argc,argv,352,288,&fn);

  // Causes segm violation? Why?
  // (because dWorldDestroy() destroys body connected to geom; must call first!)
  dGeomDestroy(sphgeom);
  dGeomDestroy (world_mesh);

  dJointGroupEmpty (contactgroup);
  dJointGroupDestroy (contactgroup);
  dSpaceDestroy (space);
  dWorldDestroy (world);

  return 0;
}