Exemplo n.º 1
0
int main (void)
{
// Golobal Integers
    extern int level;
    extern int lifes;
    extern int score;
    extern int health;
// Local Integers
   register int mapxoff, mapyoff;
   extern int oldpy, oldpx;
   extern int facing;
   extern int jump;
   int n, m;
  // DATAFILE *data;
//initilization    
	allegro_init();	
	install_timer();
	install_keyboard();
    set_color_depth(32);
	set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);

//load data
data = load_datafile("test.dat");
    temp = (BITMAP *)data[NEWGUY_BMP].dat;
    for (n=0; n<4; n++)
    player_image[n] = grabframe(temp,43,77,0,0,4,n);
    destroy_bitmap(temp);
    temp2 = (BITMAP *)data[BAT1_BMP].dat;
    for (m=0; m<2; m++)
    bat_img[m] = grabframe(temp2,87,72,0,0,2,m);
    destroy_bitmap(temp2);

    test_img = load_bitmap("test.bmp", NULL);
gameover:
Start();
first:
//initilize Player
    player = malloc(sizeof(SPRITE));
    player->x = 80;
    player->y = 200;
    player->curframe=0;
    player->framecount=0;
    player->framedelay=11;
    player->maxframe=3;
    player->width=player_image[0]->w;
    player->height=player_image[0]->h;
//initilize Bat
    bat = malloc(sizeof(SPRITE));
    bat->x = 170;
    bat->y = 100;
    bat->curframe=0;
    bat->framecount=0;
    bat->framedelay=11;
    bat->maxframe=1;
    bat->width=bat_img[0]->w;
    bat->height=bat_img[0]->h;
    bat->dir = 0;
    bat->xspeed = 0;
//ini test
test = malloc(sizeof(SPRITE));
    test->x = 270;
    test->y = 400;
    test->curframe=0;
    test->framecount=0;
    test->framedelay=11;
    test->maxframe=1;
    test->width=bat_img[0]->w;
    test->height=bat_img[0]->h;
    test->dir = 0;
    test->xspeed = 0;

loadlevel();

    //main loop
	while (!key[KEY_ESC])
	{
      oldpy = player->y; 
      oldpx = player->x;

if (player->x > 3000)
        {level = 2;
		goto first;}

if (lifes == 0)
{lifes = 3;
          goto gameover;}

if (health < 1)
{lifes -=1;
  health =100;
  goto first;}

  updateEnemy(150, 300, test);
  updateEnemy(150, 300, bat);       
  enemycoll(player->x, player->y, bat);       
  keyinput();
//collition control
	if (!facing) 
        { 
            if (collided(player->x, player->y + player->height)) 
                player->x = oldpx; 
                if (collidedobj(player->x, player->y + player->height))
                   {ClearCell(player->x, player->y + player->height); 
                   AddScore();}
                      if (collidedkill(player->x+9, player->y + player->height))
                         {health -= 25;}        
        }
		else 
        { 
            if (collided(player->x + player->width, player->y + player->height)) 
                player->x = oldpx; 
                if (collidedobj(player->x + player->width, player->y + player->height))
                   {ClearCell(player->x + player->width, player->y + player->height);
                   AddScore();}
                      if (collidedkill(player->x + player->width-15, player->y + player->height))
                         {health -= 25;}        
        }
		
        //update the map scroll position
		mapxoff = player->x + player->width/2 - WIDTH/2 + 10;
		mapyoff = player->y + player->height/2 - HEIGHT/2 + 10;
        //avoid moving beyond the map edge
		if (mapxoff < 0) mapxoff = 0;
		if (mapxoff > (mapwidth * mapblockwidth - WIDTH))
            mapxoff = mapwidth * mapblockwidth - WIDTH;
		if (mapyoff < 0) 
            mapyoff = 0;
		if (mapyoff > (mapheight * mapblockheight - HEIGHT)) 
            mapyoff = mapheight * mapblockheight - HEIGHT;

        //draw the background tiles
		MapDrawBG(buffer, mapxoff, mapyoff, 0, 0, WIDTH-1, HEIGHT-1);
        //draw foreground tiles
		MapDrawFG(buffer, mapxoff, mapyoff, 0, 0, WIDTH-1, HEIGHT-1, 0);
        //draw the player's sprite
		if (facing) 
            draw_sprite(buffer, player_image[player->curframe], 
                (player->x-mapxoff), (player->y-mapyoff+1));
		else 
            draw_sprite_h_flip(buffer, player_image[player->curframe], 
                (player->x-mapxoff), (player->y-mapyoff));

        //blit the double buffer 
		vsync();
        acquire_screen();
		if (bat->dir == 1)
           draw_sprite(buffer, bat_img[bat->curframe],(bat->x-mapxoff),(bat->y-mapyoff));
        else
           draw_sprite_h_flip(buffer, bat_img[bat->curframe],(bat->x-mapxoff),(bat->y-mapyoff)); 
        
        draw_sprite(buffer, test_img,(test->x-mapxoff),(test->y-mapyoff));
        textprintf(buffer,font,0,0,9999999,"lifes = %d  Score = %d  Health = %d",lifes,score,health);
        blit(buffer, screen, 0, 0, 0, 0, WIDTH-1, HEIGHT-1);
       	release_screen();

	} //End of game loop




    for (n=0; n<4; n++)
        destroy_bitmap(player_image[n]);
    for (m=0; m<2; m++)
        destroy_bitmap(bat_img[m]);

destroy_bitmap(test_img);

    free(player);
	free(bat);
    free(test);
    destroy_bitmap(buffer);
	MapFreeMem ();
	MapFreeMem ();
    unload_datafile(data);
    allegro_exit();
	return 0;
}
Exemplo n.º 2
0
//Main codee
//
int main(void){

	int mapxoff, mapyoff;
	int oldpy, oldpx;
	int titleX, titleY;
	int facing = 0;
	int jump = JUMPIT;
	int n, VOLUME = 128, PAN = 128, PITCH = 1000;

	//general initialize
	allegro_init();

	install_timer();

	install_keyboard();

	set_color_depth(16);

	set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);
	
	set_window_title(" . . .J.U.M.P.E.R. . .     :: Ryan Bridglal ::");


	
	//
	//sound init
	install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, "");

	//load title
	title = load_bitmap("title.bmp", NULL);
	
	//gameOver = load_bitmap("gameover.bmp", NULL);

	// load the player sprite
	temp = load_bitmap("player.bmp", NULL);
	for (n=0; n < 8; n++)
	player_image[n] = grabframe(temp, 50, 64, 0, 0, 8, n);
	destroy_bitmap(temp);


	// load the sound file
	music = load_sample("music.wav");
	
	//jumpSound = load_sample("jump.wav");

	// initialize the sprite
	player = new SPRITE;
	player->x = 80;
	player->y = 100;
	player->curframe = 0;
	player->framecount = 0;
	player->framedelay = 6;
	player->maxframe = 7;
	player->width = player_image[0]->w;
	player->height = player_image[0]->h;


	// load the map
	MapLoad("map.FMP");

	// create the double buffer
	buffer = create_bitmap(WIDTH, HEIGHT);
	clear(buffer);
	
	//always play background music
	play_sample(music, VOLUME, PAN, PITCH, FALSE);



	// main loop
	while(!key[KEY_ESC]) {
		
		oldpy = player->y;
		oldpx = player->x;


		//
		// PLAYER controls
		//
		//right keypress
		if (key[KEY_RIGHT]) {
			clear_to_color(title, makecol(80, 80, 248));
			facing = 1;
			player->x += 2;
			
			if (++player->framecount > player->framedelay) {
				player->framecount = 0;
				
				if (++player->curframe > player->maxframe)
					player->curframe = 1;
			}
		}
		
		
		//left keypress
		else if (key[KEY_LEFT]) {
			clear_to_color(title, makecol(80, 80, 248));
			facing = 0;
			player->x -= 2;
			
			if (++player->framecount > player->framedelay) {
				player->framecount = 0;
				
				if (++player->curframe > player->maxframe)
					player->curframe = 1;
			}
		}
		
		
		else player->curframe = 0;

		// handle jumping
		if (jump == JUMPIT){
		
			if (!collided(player->x + player->width/2, player->y + player->height + 5))
				jump = 0;

			if (key[KEY_SPACE]) 
				jump = 30;
			//play_sample(jumpSound, VOLUME, PAN, PITCH, FALSE);
			    
		}
		
		else {
		     	player->y -= jump/3;
		     	jump--;
		}

		if (jump < 0){
			
			if (collided(player->x + player->width/2, player->y + player->height)) {
				jump = JUMPIT;
				while (collided(player->x + player->width/2, player->y + player->height))
					player->y -= 2;
			}
		}
		
		
		///
		//collision detection
		// player collision detect with map
		if (!facing) {
		
			if (collided(player->x, player->y + player->height))
				player->x = oldpx;
		}
		
		else {
		
			if (collided(player->x + player->width, player->y + player->height))
				player->x = oldpx;
		}


		// update the map scroll position
		mapxoff = player->x + player->width/2 - WIDTH/2 + 10;
		mapyoff = player->y + player->height/2 - HEIGHT/2 + 10;

		// avoid moving beyond the map edge
		if (mapxoff < 0) 
			mapxoff = 0;
		
		if (mapxoff > (mapwidth * mapblockwidth - WIDTH))
			mapxoff = mapwidth * mapblockwidth - WIDTH;
		
		if (mapyoff < 0) 
			mapyoff = 0;
		
		if (mapyoff > (mapheight * mapblockheight - HEIGHT))
			mapyoff = mapheight * mapblockheight - HEIGHT;


		//
		//Draw things

		// draw the background tiles
		MapDrawBG(buffer, mapxoff, mapyoff, 0, 0, WIDTH - 1, HEIGHT - 1);

		// draw the foreground tiles
		MapDrawFG(buffer, mapxoff, mapyoff, 0, 0, WIDTH - 1, HEIGHT - 1, 0);

		// draw the player's sprite
		if (facing)
			draw_sprite(buffer, player_image[player->curframe], (player->x - mapxoff), (player->y - mapyoff));
		
		else
			draw_sprite_h_flip(buffer, player_image[player->curframe], (player->x - mapxoff), (player->y - mapyoff));


		//load title
		//draw_sprite(screen, title, 160, 20);
		 //draw_sprite(buffer, title[titleSprite->curframe], (title->titleX - mapxoff), (title->y - mapyoff));
		blit(title, screen, 0, 0, 0, 0, 640, 480);


		// blit the double buffer
		vsync();
		acquire_screen();
		blit(buffer, screen, 0, 0, 0, 0, WIDTH - 1, HEIGHT - 1);
		release_screen();


		
	}// endwhile
	//	else {
	//				blit(gameOver, screen, 0, 0, 0, 0, 640, 480); 
	//}

	gameOver();


	// clean up
	for (n = 0; n < 8; n++)
		destroy_bitmap(player_image[n]);
		delete player;
		delete title;

	//	for (n=0; n<NUM_SOUNDS; n++)
	//		destroy_sample(sounds[n]);


		destroy_sample(music);
	//	destroy_sample(jumpSound);
		destroy_bitmap(title);
		destroy_bitmap(buffer);
		
		MapFreeMem();

		remove_sound();
		allegro_exit();

		return 0;

}
Exemplo n.º 3
0
Arquivo: state2.c Projeto: skitt/sysd7
int state2 (void)
{
  packet pkt;
  int errno, current=0, last=1, csz, x, y, *a, *b, *c,doorbell=0, ns;
  /* Set retransmit flag to 1 for first transmission */
  int retransmitFlag=1, changeState=0;
  /* Init Camera */
  QC_init ();
  while(changeState==0)
    {
      /* Check doorbell */
      if (checkkeypad())
	if (getkeypad()==KP_DOORBELL)
	  {
	    informdoorbell ();
	    return 3;
	  }

      /* Check Dallas Ring */
      if (checkring())
	return 5;

      /* Test for retransmit flag */
      if(retransmitFlag==1)
	{    
	  /* Reset last frame so that when it is XORd a full picture is
	     transmitted */
	      for(x=0;x<frameBufferSz;x++)
		{
		  in[last][x]=0;
		}
	}

      /* Attempt to grab a frame */

      if ((changeState = grabframe (in[current])) == 0)
	{
	  /* Correction and smoothing */
	  for(x=0;x<frameBufferSz;x++)
	    {
	      if (in[current][x] != 0)
		in[current][x]=16-in[current][x];
	    }


	  /* XOR frame with previous to obtain difference
	     Here I exploit the fact that the 68040 is 32 bit
	     so by treating the bytes as ints I can XOR
	     4 bytes at a time.... clever huh?
	  */
	  a=(int *) in[current];
	  b=(int *) in[last];
	  c=(int *) diff;
	  for (x = 0; x < (frameBufferSz / 4); x++)
	    c[x] = a[x] ^ b[x];

	  /* Use RLE to compress the difference 
	     (We increment compressed by 1 to make room for
	     a control byte) */
	  csz=RLEencode(diff,frameBufferSz,compressed+1);

	  /* Tell the receiver whether this is the first frame in
	     a sequence (compressed[0]=1) or not (compressed[0]=0) */
	  compressed[0]=retransmitFlag;
	  retransmitFlag=0;
	  /* Construct Packet */

	  pkt.datatype=VIDEO;
	  pkt.length=csz/8+2;
	  pkt.data=compressed;
	  
	  /* Place it in serial Queue and check for change of state
	     instruction from client */

	  ns=senddata(&pkt);
	  if(ns > 0)
	    changeState=ns;
	  
	  /* Reverse what is current and what is previous */
	  current=1-current;
	  last=1-last;
	}
    };
  if (changeState == 3)
    informdoorbell ();
  return changeState;
}