Esempio n. 1
0
int main (int argc, char **argv) {
    cpSpace *space = cpSpaceNew();
    cpSpaceSetGravity(space, cpv(0, GRAVITY));
    cpEnableSegmentToSegmentCollisions();
    
    cpShape *ground = cpSpaceAddShape(space, cpSegmentShapeNew(space->staticBody, cpv(0, 5), cpv(10, -5), 0));
    cpShapeSetFriction(ground, 0.3);
    
    cpBody *drawing = drawing_new(2, 7, 0);
    drawing = drawing_update(space, drawing, 3, 8);
    drawing = drawing_update(space, drawing, 3, 9);
    drawing = drawing_update(space, drawing, 2, 9);
    //cpBody *drawing = drawing_new(0, 0, 0);
    //drawing = drawing_update(space, drawing, 2, 0);
    //drawing = drawing_update(space, drawing, 2, 2);
    //drawing = drawing_update(space, drawing, 0, 2);
    print_positions(drawing);
    
    //drawing_activate(drawing);
    //print_positions(drawing);
    
    cpVect vel, pos;
    int i = 0;
    for(cpFloat time = 0; time < 2; time += TIMESTEP){
        pos = cpBodyGetPos(drawing);
        vel = cpBodyGetVel(drawing);
        
        printf( "Time = %2.2f Position = (%2.2f, %2.2f) Velocity = (%2.2f, %2.2f)\n",
            time, pos.x, pos.y, vel.x, vel.y);
        cpSpaceStep(space, TIMESTEP);
        
        i++;
        if (i == 20) {
            drawing_activate(space, drawing);
            print_positions(drawing);
        }
    }
    print_positions(drawing);
    
    free_body_full(drawing);
    cpShapeFree(ground);
    cpSpaceFree(space);
    return EXIT_SUCCESS;
}
Esempio n. 2
0
// make cpSpace object to pass to GUI
cpSpace * core_create_space () {
    
    //create and return new cpSpace
    cpSpace *space;
    space = cpSpaceNew ();
    core_set_gravity ( space, DEFAULT_GRAVITY );
    
    cpSpaceAddCollisionHandler ( space, ASTEROID_COLLISION_TYPE, GOAL_COLLISION_TYPE, core_begin_collision, NULL, NULL, NULL, NULL );
    
    BodyInfo * bi = body_info_new ( 0 );
    bi->index = 0;
    space->staticBody->data = bi; // sets index of static body to 0
    
    GameInfo *gameInfo = game_info_new ();
    cpSpaceSetUserData(space, ( cpDataPointer ) gameInfo);
    
    cpEnableSegmentToSegmentCollisions ();
    return space;
}
Esempio n. 3
0
int main (int argc, char *argv[]){
  Gui *gui = (Gui *)malloc(sizeof(Gui));;
  gui->space = cpSpaceNew();
  gui->current_body = NULL;
  cpSpaceSetGravity(gui->space, cpv(0, GRAVITY));
  cpEnableSegmentToSegmentCollisions();
  
  gtk_init(&argc, &argv); 

  initialize_window(gui);

  initialize_client(gui);  
  
  pthread_t t1;
  int iret1 = pthread_create(&t1, NULL, client_recv1, gui);

  gtk_main();
  
  cpSpaceFree(gui->space);
  free(gui);
  return 0;
}