示例#1
0
int main (void)
{
    int tick;
    boing_state_t balls[3];

    system_init ();
    tinygl_init (LOOP_RATE);

    pacer_init (LOOP_RATE);
    tick = 0;

    balls[0] = boing_init (0, 1, DIR_NE);
    balls[1] = boing_init (4, 5, DIR_SE);
    balls[2] = boing_init (4, 5, DIR_SW);

    /* Paced loop.  */
    while (1)
    {
        /* Wait for next tick.  */
        pacer_wait ();

        tick++;

        /* Flash the first two balls at different rates.  */
        tinygl_draw_point (balls[0].pos, tick % 2 < 1);
        tinygl_draw_point (balls[1].pos, tick % 4 < 2);

        if (tick >= 40)
        {
            int i;

            tick = 0;

            for (i = 0; i < 3; i++)
            {
                /* Erase previous position.  */
                tinygl_draw_point (balls[i].pos, 0);
                
                /* Check for collision; if so reverse direction.  */
                balls[i] = boing_update (balls[i]);

                /* Perhaps should make ball that is hit reverse as well?  */
                if (collision_detect (balls, 2, i) > 0)
                {
                    balls[i] = boing_reverse (balls[i]);
                }

                /* Draw previous position.  */
                tinygl_draw_point (balls[i].pos, 1);
            }
        }

        tinygl_update ();
    }
}
示例#2
0
文件: tick.c 项目: F483/cleanspace
void update_tick_trash(){
  for(Uint32 i = 0; i < TRASH_SIZE; i++){
    tick_trash[i].pos = vec_add(tick_trash[i].pos, tick_trash[i].vec);
    collision_detect(&tick_trash[i]);
    Sint32 x = vec_get_x_int(tick_trash[i].pos);
    Sint32 y = vec_get_y_int(tick_trash[i].pos);
    Sint32 rm_left = vec_get_x_int(tick_avatar.pos) - TRASH_REM_LEFT;
    if (x < rm_left or y < TRASH_REM_TOP or y > TRASH_REM_BOTTOM){
      spawn_tick_trash(&tick_trash[i], &TRASH_OBJS[i]);
    }
  }
}