Пример #1
0
int main(){
    ball b;
    wall w[50];
    int i=0;
    for(;i<15;++i){
        w[i].y=15;
        w[i].x=10+i;
        w[i].flag=URWALL;
    }
    for(;i<30;++i){
        w[i].y=w[14].y+i-15;
        w[i].x=w[14].x;
        w[i].flag=WALL;
    }
    for(;i<50;++i){
        w[i].y=w[29].y;
        w[i].x=w[29].x+i-30;
        w[i].flag=DRWALL;
    }

    initscr();
    raw();
    keypad(stdscr,TRUE);
    noecho();
    curs_set(FALSE);

    initball(&b,DELAY,'O');
    b.direction_x=1;
    drawMap(w,50);

    timeout(DELAY);

    while(1){
        /* getmaxyx(stdscr,max_y,max_x); */
        /* clear(); */

        /* drawMap(NULL,0); */
        /* collision(&b); */
        drawball(&b);

        refresh();

        changedirection(&b);
        updateball(&b);
        /* ch=halfdelay(190); */
        if(quit)
            break;
    }

    endwin();
    exit(EXIT_SUCCESS);
}
Пример #2
0
void
drawimage(void)
{
    register short i;
    static int start, end, last;

    glutSetWindow(window);

    if (performance)
	start = glutGet(GLUT_ELAPSED_TIME);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    tbMatrix();

    for (i=0; i < TOTALBALLS; i++) {
	newpos[0] = balls[i].p[0];
	newpos[1] = balls[i].p[1];
	newpos[2] = balls[i].p[2];
	glLightfv(GL_LIGHT0 + i, GL_POSITION, newpos);
    }

    glCallList(wall_material);
    glEnable(GL_LIGHTING);
    drawbox();

    glEnable(GL_DEPTH_TEST);

    if (objecton)
    {
	glCallList(plane_material);
	glPushMatrix();
	glScalef(1.5, 1.5, 1.5);
	glRotatef(180.0, 0.0, 0.0, 1.0);
	if (spin)
	{
	    orx += 50;
	    ory += 50;
	}
	glRotatef(orx/10.0, 1.0, 0.0, 0.0);
	glRotatef(ory/10.0, 0.0, 1.0, 0.0);
	drawfastobj(obj);
	glPopMatrix();
    }

    glDisable(GL_LIGHTING);

    for (i=0; i < TOTALBALLS; i++) {
	if (lighton[i])
	{
	    glPushMatrix();
	    glTranslatef(balls[i].p[0],balls[i].p[1],balls[i].p[2]);
	    glColor3ubv(balls[i].color);
	    drawball();
	    glPopMatrix();
	}
    }

    glColor3f(1.0, 1.0, 1.0);
    if (performance) {
        if (end - last == 0) {
	    text(10, 73, 20, "unknown fps");
	} else {
	    text(10, 73, 20, "%.0f fps", 1.0 / ((end - last) / 1000.0));
	}
	last = start;
    }
    text(10, 43, 14, "Attenuation [%.2f]", fatt);
    text(10, 13, 14, "Tesselation [%3d]", wallgrid);


    glPopMatrix();
    glutSwapBuffers();

    if (performance)
	end = glutGet(GLUT_ELAPSED_TIME);
}
Пример #3
0
/*
 * main rendering loop
 */
static void draw(ModeInfo * mi)
{
   boxedstruct *gp = &boxed[MI_SCREEN(mi)];
   int wire = MI_IS_WIREFRAME (mi);
   vectorf v1,v2;
   GLfloat r;
   int dx, dz;
   int i;   
   
   GLfloat dgray[4] = {0.3f, 0.3f, 0.3f, 1.0f};
   GLfloat black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
   GLfloat lblue[4] = {0.4f,0.6f,1.0f };
   
   GLfloat l0_ambient[] =    {0.0, 0.0, 0.0, 1.0};
   GLfloat l0_specular[] =    {1.0, 1.0, 1.0, 1.0};
   GLfloat l0_diffuse[] =    {1.0, 1.0, 1.0, 1.0};
   GLfloat l0_position[] =  {0.0, 0.0, 0.0, 1.0}; /* w != 0 -> positional light */
   GLfloat l1_ambient[] =    {0.0, 0.0, 0.0, 1.0};
   GLfloat l1_specular[] =    {1.0, 1.0, 1.0, 1.0};
   GLfloat l1_diffuse[] =    {0.5, 0.5, 0.5, 1.0};
   GLfloat l1_position[] =  {0.0, 1.0, 0.0, 0.0}; /* w = 0 -> directional light */
   
   mi->polygon_count = 0;

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();
   
# ifdef HAVE_MOBILE	/* Keep it the same relative size when rotated. */
  {
    GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
    int o = (int) current_device_rotation();
    if (o != 0 && o != 180 && o != -180)
      glScalef (1/h, 1/h, 1/h);
    glRotatef(o, 0, 0, 1);
  }
# endif

   gp->tic += 0.01f;
   gp->camtic += 0.01f + 0.01f * sin(gp->tic * speed);
   
   /* rotate camera around (0,0,0), looking at (0,0,0), up is (0,1,0) */
   r = CAMDISTANCE_MIN + (CAMDISTANCE_MAX - CAMDISTANCE_MIN) + (CAMDISTANCE_MAX - CAMDISTANCE_MIN)*cos((gp->camtic/CAMDISTANCE_SPEED) * speed);
   v1.x = r * sin((gp->camtic/gp->cam_x_speed) * speed);
   v1.z = r * cos((gp->camtic/gp->cam_x_speed) * speed);
   v1.y = CAM_HEIGHT * sin((gp->camtic/gp->cam_y_speed) * speed) + 1.02 * CAM_HEIGHT;

   v2.x = LOOKAT_R * sin((gp->camtic/(gp->cam_x_speed * 5.0f)) * speed);
   v2.z = LOOKAT_R * cos((gp->camtic/(gp->cam_x_speed * 5.0f)) * speed);
   v2.y = (CAM_HEIGHT * sin((gp->camtic/gp->cam_y_speed) * speed) + 1.02 * CAM_HEIGHT)/10.0;

   gluLookAt(v1.x,v1.y,v1.z,v2.x,v2.y,v2.x,0.0,1.0,0.0); 

   if (!wire) {
     glLightfv(GL_LIGHT0, GL_AMBIENT, l0_ambient); 
     glLightfv(GL_LIGHT0, GL_DIFFUSE, l0_diffuse); 
     glLightfv(GL_LIGHT0, GL_SPECULAR, l0_specular); 
     glLightfv(GL_LIGHT0, GL_POSITION, l0_position);
     glLightfv(GL_LIGHT1, GL_AMBIENT, l1_ambient); 
     glLightfv(GL_LIGHT1, GL_DIFFUSE, l1_diffuse); 
     glLightfv(GL_LIGHT1, GL_SPECULAR, l1_specular); 
     glLightfv(GL_LIGHT1, GL_POSITION, l1_position);
     glEnable(GL_LIGHT0);
     glEnable(GL_LIGHT1);
   
     glFrontFace(GL_CW);
   
     glMaterialfv(GL_FRONT, GL_SPECULAR, black);
     glMaterialfv(GL_FRONT, GL_EMISSION, lblue);
     glMaterialfv(GL_FRONT,GL_AMBIENT,black);
     glMaterialf(GL_FRONT, GL_SHININESS, 5.0);
   }
   
   
   /* draw ground grid */
   /* glDisable(GL_DEPTH_TEST); */
   glDisable(GL_LIGHTING);
   
   glColor3f(0.1,0.1,0.6);
   for (dx= -2; dx<3; dx++) {
      for (dz= -2; dz<3; dz++) {
	 glPushMatrix();
	 glTranslatef(dx*30.0f, 0.0f, dz*30.0f);
	 drawpattern(gp);
	 glPopMatrix();
      }   
   }
   
   /* Set drawing mode for the boxes */
   glEnable(GL_DEPTH_TEST);
   if (!wire) glEnable(GL_TEXTURE_2D);
   glPushMatrix();
   glColor3f(1.0,1.0,1.0);
   glScalef(20.0,0.25,20.0);
   glTranslatef(0.0,2.0,0.0);
   mi->polygon_count += drawfilledbox(gp, wire);
   glPopMatrix();
   glDisable(GL_TEXTURE_2D);

   glPushMatrix();
   glColor3f(0.2,0.5,0.2);
   glScalef(20.0,20.0,0.25);
   glTranslatef(0.0,1.0,81.0);
   mi->polygon_count += drawbox(gp);
   glPopMatrix();

   glPushMatrix();
   glColor3f(0.2,0.5,0.2);
   glScalef(20.0,20.0,0.25);
   glTranslatef(0.0,1.0,-81.0);
   mi->polygon_count += drawbox(gp);
   glPopMatrix();

   glPushMatrix();
   glColor3f(0.2,0.5,0.2);
   glScalef(.25,20.0,20.0);
   glTranslatef(-81.0,1.0,0.0);
   mi->polygon_count += drawbox(gp);
   glPopMatrix();

   glPushMatrix();
   glColor3f(0.2,0.5,0.2);
   glScalef(.25,20.0,20.0);
   glTranslatef(81.0,1.0,0.0);
   mi->polygon_count += drawbox(gp);
   glPopMatrix();

   if (!wire) {
     glEnable(GL_LIGHTING);
   
     glMaterialfv(GL_FRONT, GL_DIFFUSE, dgray);
     glMaterialfv(GL_FRONT, GL_EMISSION, black); /* turn it off before painting the balls */
   }

   /* move the balls and shrapnel */
   updateballs(&gp->bman);

   glFrontFace(GL_CCW);
   for (i=0;i<gp->bman.num_balls;i++) {
      if (gp->bman.balls[i].justcreated) {
	 gp->bman.balls[i].justcreated = FALSE;
	 freetris(&gp->tman[i]);
      }
      if (gp->bman.balls[i].bounced) { 
	 if (gp->tman[i].vertices == NULL) {
	    createtrisfromball(&gp->tman[i],gp->spherev,gp->spherei,SPHERE_INDICES,&gp->bman.balls[i]);
	 } else {
	    updatetris(&gp->tman[i]);
	 }
	 glDisable(GL_CULL_FACE);
	 mi->polygon_count += drawtriman(&gp->tman[i], wire);
	 if (!wire) glEnable(GL_CULL_FACE);
      } else {
         mi->polygon_count += drawball(gp, &gp->bman.balls[i], wire);
      }
   }
      
   glFlush();
}
Пример #4
0
int playgame(short control)
{
    struct player p1 = {P1_Y, P1_X, 1, 0, 0, 35, 0};
    struct player p2 = {P2_Y, P2_X, 0, 0, 0, 40, 0};
    struct ball b = {B_Y, B_X, B_SPEED, B_DIRY, 1, 0};
    short gameover = 0;
    short bcounter = 0;
    short bbcounter = 0;
    short pcounter = 0;
    int c;

    while (!gameover) {
        /* Draw everything and pause for one tick. */
        drawpaddle(p1);
        drawpaddle(p2);
        drawnet();
        drawball(b);
        refresh();
        napms(SPEED);

        /* Get input. */
        control = controlpaddle(&p1, b, control);
        if (!control)
            break;
        controlpaddle(&p2, b, 0);
        if (pcounter++ == P_SPEED) {
            updatepaddle(&p1);
            updatepaddle(&p2);
            pcounter = 0;
        }
        if (bcounter++ == b.speed) {
            eraseball(b);
            if (updateball(&b, &p1, &p2) == 0) {
                bcounter = 0;
                if (bbcounter++ == 200 && b.speed > 1)
                    --b.speed;
            } else {
                bcounter = 0;
                bbcounter = 0;
                p1.y = P1_Y;
                p1.x = P1_X;
                p1.dir = 0;
                p2.y = P2_Y;
                p2.x = P2_X;
                p2.dir = 0;
                clear();
                drawpaddle(p1);
                drawpaddle(p2);
                drawnet();
                drawball(b);
                refresh();
                /* Wait for space or a mouse click */
                do {
                    c = getch();
                    napms(10);
                    if (c == 'q')
                        return 0;
                } while ((c != ' ') && (c != KEY_MOUSE));
                if (p1.score == 21) {
                    return 1;
                } else if (p2.score == 21) {
                    return 2;
                }
            }
        }
        napms(SPEED);
    }
    return 0;
}