Ejemplo n.º 1
0
void update_man(void){
	int x, y;

	Oldman.pos.x = Curman.pos.x;
	Oldman.pos.y = Curman.pos.y;
	
	Curman.pos.x -= Curman.vel.x;
	Curman.pos.y += Curman.vel.y;

	if (left_key && right_key) ;
	else if (left_key){
		Curman.pos.y -= bspeed * 3;
/*		if (Curman.state == Stand && Curstep[Curman.stone].type == Roll)
		Curman.pos.y += bspeed;
		*/
	}
	else if (right_key)
		Curman.pos.y += bspeed * 3;


	y = Curman.pos.y >> frac;
	if (y <= Halwid+1)
		Curman.pos.y = (Halwid+1) << frac;
	else if (y + Halwid >= 140)
		Curman.pos.y = (140-Halwid) << frac;
	
	if (Curman.state == Stand)
		jumpcheck();
	else landcheck();


	x = Curman.pos.x >> frac;
	if (x > 195){
		alive = FALSE;
		Curman.pos.x = 187 << frac;
		}

	if (alive) clear_man();
	clear_step();

	draw_man();
	draw_step();

	if (x <= 11 && Curman.state != Jump){
		Curman.state = Jump;
		Curman.blood -= 3;
		if (Curman.blood <= 0)
			alive = FALSE;
		Curman.vel.x = 0;
		}
}
Ejemplo n.º 2
0
void die_animation(int x, int y) {
	man_is_dead = true;
	if (y<(LCD_HEIGHT_PX-dash_height-cart_height)) {
		draw_man(x, y);
	} else if (y<(LCD_HEIGHT_PX-dash_height-9)) {
		CopySpriteNbitMasked(man_dieing, x-5, LCD_HEIGHT_PX-dash_height-9, 10, 9, man_dieing_palette, COLOR_WHITE, 1);
		wait(3);
	} else if (y<(LCD_HEIGHT_PX-dash_height-3)) {
		CopySpriteNbitMasked(man_dead, x-6, LCD_HEIGHT_PX-dash_height-3, 13, 3, man_dead_palette, COLOR_WHITE, 1);
		wait(3);
	} else if (y<(LCD_HEIGHT_PX-dash_height)) {
		next_try();
	}
}
Ejemplo n.º 3
0
Archivo: lab3.c Proyecto: worm6206/lab3
void display()
{
  glEnable(GL_DEPTH_TEST); 
  glClearColor(0,0,0,1);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_PROJECTION); 
  glLoadIdentity(); 
  gluPerspective(60, 1, 0.1, 100); 

  // glLoadMatrixf(&modelM[0][0]);

  glMatrixMode(GL_MODELVIEW); 
  glLoadIdentity(); 
  gluLookAt(0,0,15 , 0,0,0, 0,1,0); 

  glRotatef(x_angle, 0,1,0);   
  glRotatef(y_angle, 1,0,0); 
  glScalef(scale_size, scale_size, scale_size); 

  glBindBuffer(GL_ARRAY_BUFFER, vboHandle);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBO);
  glEnableClientState(GL_VERTEX_ARRAY); // enable the vertex array on the client side
  //glEnableClientState(GL_COLOR_ARRAY); // enable the color array on the client side
  // number of coordinates per vertex (4 here), type of the coordinates,
  // stride between consecutive vertices, and pointers to the first coordinate
  // glColorPointer(4, GL_FLOAT, sizeof(Vertex), (char*) NULL+ sizeof(float)*4);
  glVertexPointer(4,GL_FLOAT, sizeof(Vertex), (char*) NULL+ 0);
  // glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, (char*) NULL+0);

  //draw_cube(1,c1);

  //draw_cylinder(1.0f,3.0f,5.0f,12,c2);

  //draw_sphere(1,12,12,c3);

  draw_floor();

  draw_man();

  //draw_square2(modelM,cc);
  glDisableClientState(GL_VERTEX_ARRAY); 
  //glDisableClientState(GL_COLOR_ARRAY);
  glutSwapBuffers();
} 
Ejemplo n.º 4
0
void game() {
	/* MAIN LOOP, DO NOT BREAK */
	while (1) {
		/* GETKEY */
		keyupdate();
		// handle [menu]
		if (PRGM_GetKey()==48) {
			GetKey(&key);
		}

		// direction keys
		if (keydownlast(KEY_PRGM_LEFT) && cursor_pos[0]>33) {
			cursor_pos[0] -= cursor_speed;
		} else if (keydownlast(KEY_PRGM_RIGHT) && cursor_pos[0]<LCD_WIDTH_PX-33) {
			cursor_pos[0] += cursor_speed;
		}
		if (keydownlast(KEY_PRGM_UP) && cursor_pos[1]>0) {
			cursor_pos[1] -= cursor_speed;
		} else if (keydownlast(KEY_PRGM_DOWN) && cursor_pos[1]<(LCD_HEIGHT_PX-dash_height-cart_height-man_height-10)) {
			cursor_pos[1] += cursor_speed;
		}

		// control keys
		// shift
		if (keydownlast(KEY_PRGM_SHIFT) && man_is_hanging) {
			// drop man
			man_is_hanging = false;
			man_pos[0] = copter_pos[0];
			man_pos[1] = copter_pos[1]+9;
		}

		/* OPERATIONS */
		// move copter
		if (cursor_pos[0] > copter_pos[0]) {
			copter_pos[0]+=copter_speed;
		} else if (cursor_pos[0] < copter_pos[0]) {
			copter_pos[0]-=copter_speed;
		}

		if (cursor_pos[1] > copter_pos[1]) {
			copter_pos[1]+=copter_speed;
		} else if (cursor_pos[1] < copter_pos[1]) {
			copter_pos[1]-=copter_speed;
		}

		// if man is falling, drop him
		if (!man_is_hanging) {
			man_pos[1] += man_speed;
		}
		// if man is below cart level, check if he is in the cart
		if (!man_is_hanging && man_pos[1]>(LCD_HEIGHT_PX-dash_height-cart_height-5)) {
			if (!man_is_dead && man_pos[0]>cart_pos && man_pos[0]<cart_pos+35) {
				next_try();
			} else {
				die_animation(man_pos[0], man_pos[1]);
			}
		}

		// move cart
		cart_counter = (cart_counter+1) % LCD_WIDTH_PX;
		cart_pos = cart_counter-70;
		// update frame
		cart_frame = (cart_frame+1) % 2;

		/* GRAPHICS */
		// clear screen
		Bdisp_AllClr_VRAM();

		// display functions
		draw_copter(copter_pos[0], copter_pos[1], man_is_hanging);
		draw_cart(cart_pos, LCD_HEIGHT_PX-dash_height-cart_height, cart_frame);

		// if man is falling, draw him
		if (!man_is_hanging /* && !man_is_dead */) {
			draw_man(man_pos[0], man_pos[1]);
		}

		// draw dash
		draw_dash();

		// draw cursor on top of everything
		draw_cursor(cursor_pos[0], cursor_pos[1]);
		
		// copy VRAM to screen
		Bdisp_PutDisp_DD();
	}
}
Ejemplo n.º 5
0
void game()
{
	static int count = 0;
	static unsigned char first_time = 1;

	/***********/
	char buff[64];
	int i, j;
	/***********/

	if (first_time==1)
	{

		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);		
//		glEnable(GL_LIGHT1);
		glEnable(GL_DEPTH_TEST);
		glEnable(GL_COLOR_MATERIAL);
		LoadPic1();




		for (i=0; i<BOX_MAX; i++)
		{
			box[i].x = BOX_X_INIT;
			box[i].y = BOX_Y_INIT;
			box[i].status = BOX_OFF;
		}
		/*
		for (j=0; j<N_ROW; j++)
		{
			for (i=0; i<N_COL; i++)
			{
				pole[i][j] = 0;
			}
		}
		*/
		srand(time);
		new_box();
		
		man.x = fmod(rand(), N_COL);
		man.y = 0;
		man.flag_up = MAN_FLAG_UP_0;
		man.ay = 0;

		first_time = 0;
	}


	glPushMatrix(); // all
//	glScalef(0.1, 0.1, 1);

	// pole
	glColor3f(0.0, 0.0, 0.5);


	rectangletex(	START_X + 0*SX, START_Y + 0*SY, 
				START_X + (N_COL)*SX, START_Y + (N_ROW)*SY);
	glColor3f(0, 1.0, 0.5);



	// box to pole
	// box_to_pole();

	// draw
/*

	for (j=0; j<N_ROW; j++)
	{
		for (i=0; i<N_COL; i++)
		{
			if (pole[i][j] != BOX_OFF)
			{
		/ *		rectangle(	START_X + i*SX, START_Y + j*SY, 
							START_X + (i+0.9)*SX, START_Y + (j+0.9)*SY);* /
				drawbox()
				/ *textout(	START_X + i*SX, START_Y + j*SY, 1, &num[pole[i][j]] );* /
			}
		}
	}
*/

	if (gamestatus == GAMEMENU)
	{
		draw_menu_new();
	}
	if (gamestatus == GAME)
	{
		for (i=0; i<BOX_MAX; i++)
		{
			if (box[i].status != BOX_OFF)
			{
				drawbox(box[i]);
			}
		}
		draw_man(man);
	}
	
	// lines
	if (lines > 0)
	{
		sprintf(buff, "Линий: %d", lines);
		textout(RES_LINES_X, RES_LINES_Y, strlen(buff), buff);
	}
	if (pobashke > 0)
	{
		sprintf(buff, "По башке: %d", pobashke);
		textout(RES_POBASHKE_X, RES_POBASHKE_Y, strlen(buff), buff);
	}

	if (gamestatus == GAMEOVER)
	{
		glColor3f(1.0, 1.0, 1.0);
		textout(	START_X + N_COL*HSX, START_Y + N_ROW*HSY, 9, "GAME OVER" );
	}

	if (gamestatus == GAMEPAUSE)
	{
		glColor3f(1.0, 1.0, 1.0);
		textout(	START_X + N_COL*HSX, START_Y + N_ROW*HSY, 5, "PAUSE" );
	}


	glPopMatrix(); // all
}
Ejemplo n.º 6
0
int main()
{
  SDL_Surface* background, *background2, *background3, *background4;
  SDL_Rect src, dest;
  int frames;  
  Uint32 colorkey;


  SDL_AudioSpec desired, obtained;
  sound_t bus_sound;

  /*initialize video and sound subsystem*/
  if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0){
    printf("Unable to initialize video: %s\n.", SDL_GetError());
    return 1;
  }

  /*ensure all subsystems exit safely*/
  atexit(SDL_Quit);
  atexit(SDL_CloseAudio);

  /*set video mode*/
  screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF | SDL_HWSURFACE);
  if (screen == NULL) {
    printf("Unable to set video mode: %s\n", SDL_GetError());
    return 1;
  }

  /*load background images*/
  background = SDL_LoadBMP("img/src.bmp");
  if (background == NULL) {
    printf("Unable to load image.");
    return 1;
  }

  background2 = SDL_LoadBMP("img/background2.bmp");
  if (background2 == NULL) {
    printf("Unable to load background2.");
    return 1;
  }

  background3 = SDL_LoadBMP("img/background3.bmp");
  if (background3 == NULL) {
    printf("Unable to load background3.");
    return 1;
  }

  background4 = SDL_LoadBMP("img/background4.bmp");
  if (background4 == NULL) {
    printf("Unable to load background4.");
    return 1;
  }

  /*load bus*/
  bus = SDL_LoadBMP("img/bus.bmp");
  if (bus == NULL) {
    printf("Unable to load image.");
    return 1;
  }
  colorkey = SDL_MapRGB(bus->format, 255, 255, 255);

  /*set color key*/
  SDL_SetColorKey(bus,
		  SDL_SRCCOLORKEY,
		  colorkey);
  
  /*load man*/
  man = SDL_LoadBMP("img/man.bmp");
  if (man == NULL) {
    printf("Unable to load image");
    return 1;
  }

  colorkey = SDL_MapRGB(man->format, 255, 255, 255);

  /*set color key*/
  SDL_SetColorKey(man,
		  SDL_SRCCOLORKEY,
		  colorkey);

  man2 = SDL_LoadBMP("img/man2.bmp");
  if (man2 == NULL) {
    printf("Unable to load image");
    return 1;
  }

  colorkey = SDL_MapRGB(man2->format, 255, 255, 255);

  /*set color key*/
  SDL_SetColorKey(man2,
		  SDL_SRCCOLORKEY,
		  colorkey);

  car1 = SDL_LoadBMP("img/car1.bmp");
  if (car1 == NULL) {
    printf("Unable to load image");
    return 1;
  }

  colorkey = SDL_MapRGB(car1->format, 255, 255, 255);

  /*set color key*/
  SDL_SetColorKey(car1,
		  SDL_SRCCOLORKEY,
		  colorkey);


  car2 = SDL_LoadBMP("img/car2.bmp");
  if (car2 == NULL) {
    printf("Unable to load image");
    return 1;
  }

  colorkey = SDL_MapRGB(car2->format, 255, 255, 255);

  /*set color key*/
  SDL_SetColorKey(car2,
		  SDL_SRCCOLORKEY,
		  colorkey);

  
  //open audio device
  desired.freq = 44100;
  desired.format = AUDIO_S16;
  desired.samples = 4096;
  desired.channels = 2;
  desired.callback = AudioCallback;
  desired.userdata = NULL;

  if (SDL_OpenAudio(&desired, &obtained) < 0) {
    printf("Unable to open audio device: %s\n", SDL_GetError());
    return 1;
  }

  //load sound files and convert them to sound card's format
  if (LoadAndConvertSound("audio/bus-pass.wav", &obtained, &bus_sound) != 0) {
    printf("Unable to load sound.\n");
    return 1;
  }

  ClearPlayingSounds();
  SDL_PauseAudio(0);

  init_bus();
  init_man();
  
  int passenger_in = 0;

  PlaySound(&bus_sound);
  while (psv.x > 0) {
    src.x = 0;
    src.y = 0;
    src.w = background->w;
    src.h = background->h; 
    dest = src;
    SDL_BlitSurface(background, &src, screen, &dest);

    draw_obj(&psv, bus);
    
    if (psv.x < screen->w/2 && !passenger_in) { /*pause bus for passenger to enter*/
      SDL_PauseAudio(1);
      if (passenger.x > psv.x + 40){  /*check if passenger has got in*/
	passenger_in = 1; SDL_PauseAudio(0);
      }

      draw_man();
      SDL_Flip(screen);
      move_obj(&passenger);
    } else {
      SDL_Flip(screen);
      move_obj(&psv);
    }
  }

  psv.x = 639;  psv.y = 320;
  init_cars();
  PlaySound(&bus_sound);
  while (psv.x + bus->w/2 > 0) {
    SDL_BlitSurface(background2, &src, screen, &dest);
    draw_obj(&priv1, car1); draw_obj(&priv2, car2);
    draw_obj(&psv, bus);
    SDL_Flip(screen);
    move_obj(&psv);
    move_obj(&priv1); move_obj(&priv2);
  }

  psv.x = 639; psv.y = 350;
  PlaySound(&bus_sound);
  while (psv.x + bus->w/2 > 0) {
    SDL_BlitSurface(background3, &src, screen, &dest);
    draw_obj(&psv, bus);
    SDL_Flip(screen);
    move_obj(&psv);
  }

  psv.x = 639; psv.y = 267; passenger.y = 270;
  passenger_in = 1;
  int has_paused = 0;
  PlaySound(&bus_sound);
  while (psv.x + bus->w/2 > 0) {
    SDL_BlitSurface(background4, &src, screen, &dest);
    if (screen->w/2 > psv.x && passenger_in == 1) {
      SDL_PauseAudio(1);
      if (has_paused == 0) { SDL_Delay(1000); has_paused = 1;}
      if (passenger.x > 639) {passenger_in = 0; SDL_PauseAudio(0);}
      draw_obj(&psv, bus);
      draw_man();
      SDL_Flip(screen);
      move_obj(&passenger);
    } else {
      draw_obj(&psv, bus);
      SDL_Flip(screen);
      move_obj(&psv);
    }
  }

  //pause and lock sound system
  SDL_PauseAudio(1);
  SDL_LockAudio();

  free(bus_sound.samples);

  SDL_UnlockAudio();


  SDL_FreeSurface(background4);
  SDL_FreeSurface(background3);
  SDL_FreeSurface(background2);
  SDL_FreeSurface(background);
  SDL_FreeSurface(man);
  SDL_FreeSurface(bus);
  return 0;
}
Ejemplo n.º 7
0
   void dogde()
   {   int i,j,ran;
	   char ch,menu;
   loading();

   cleardevice();

   setbkcolor(YELLOW);
   setcolor(BLUE);
    h:
    outtextxy(100,100,"Press I to read instructions.");
    outtextxy(100,200,"Press S to start the game.");
    outtextxy(100,300,"Press E to exit.");

    menu=getchar();
    clrscr();
    toupper(menu);
    switch(menu)
   { case 'S' : break;
     case 's' : break;
     case 'I' : instructions();
		goto h;
     case 'i' : instructions();
		goto h;
     case 'E' : exit(0);
     case 'e' : exit(0);
     default : goto h;
   }

   setviewport(0,170,639,310,1);

  start:

   setbkcolor(YELLOW);
   randomize();
   ran=random(2);


  if(ran==0)
{

  for(i=0;i<639;i++)

  {  draw_man();

       setcolor(RED);
       rectangle(635-i,120,639-i,140);
       setcolor(BLACK);
       rectangle(637-i,120,641-i,140);

       man.top_y=90;
       man.top_x=55;
       man.bottom_x=55;
       man.bottom_y=140;

       obstacle.x=635-i;
       obstacle.y=120;

     if(kbhit())
     { ch=getch();

	  if(ch=='y'||ch=='Y')
	  {  i=jump(i,ran);
	     draw_man();

	     if(man.bottom_x>obstacle.x)
	       {  score++;
		  goto start; }

	 else if(man.bottom_y >=obstacle.y && man.bottom_x==obstacle.x)
	    {

	      gameover();
	    }




	  }

	else if(ch=='h'||ch=='H')
	{     i=bend(i,ran);
	     draw_man();


	     if(man.bottom_x>obstacle.x)
	       {  score++;
		  goto start; }

	 else if(man.bottom_y >=obstacle.y && man.bottom_x==obstacle.x)
	    {

	      gameover();
	    }

	 }
      }
  delay(10);
  }

}


else  if(ran==1)
{

  for(i=0;i<639;i++)

  {  draw_man();
      setcolor(RED);
      rectangle(635-i,20,639-i,80);
      setcolor(BLACK);
      rectangle(637-i,20,641-i,80);

       obstacle.x=635-i;
       obstacle.y=60;

     if(kbhit())
     { ch=getch();



	 if(ch=='y'||ch=='Y')
	  {  i=jump(i,ran);

	    draw_man();


	     if(man.bottom_x>obstacle.x)
	       {  score++;
		  goto start; }



	    else if(man.top_y<=obstacle.y && man.bottom_x==obstacle.x)

	    {

	      gameover();
	    }

	  }

	else if(ch=='h'||ch=='H')
	{     i=bend(i,ran);

	  draw_man();


	     if(man.bottom_x>obstacle.x)
	       {  score++;
		  goto start; }

	 else if(man.bottom_y >=obstacle.y && man.bottom_x==obstacle.x)
	    {

	      gameover();
	    }

	 }
      }
    delay(10);
  }

}
  gameover();
  closegraph();
}