Esempio n. 1
0
static void run_demo (void)
{
	set_color_depth (16);
	if (set_gfx_mode(GFX_OPENGL, width, height, 0, 0) < 0) {
		allegro_message ("Error setting OpenGL graphics mode:\n%s\nAllegro GL error : %s\n", allegro_error, allegro_gl_error);
		return;
	}

	install_keyboard();

	LOCK_FUNCTION(secs_timer);
	LOCK_VARIABLE(secs);

	glClearColor (0, 0, 0, 0);
	glShadeModel (GL_FLAT);
	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
	glPolygonMode (GL_BACK, GL_POINTS);
	glEnable (GL_DEPTH_TEST);
	glCullFace (GL_BACK);
	glEnable (GL_CULL_FACE);

	install_int (secs_timer, 1000);

	do {
		keyboard();
		rest(2);
	} while (!key[KEY_ESC]);

	remove_int (secs_timer);

	remove_keyboard();
}
Esempio n. 2
0
void OSD::Exit (bool fReInit_/*=false*/)
{
    remove_int(TimerCallback);

    if (!fReInit_)
        allegro_exit();
}
Esempio n. 3
0
void _ji_system_exit()
{
  SetDisplay(NULL);
  set_mouse_cursor(NULL);

  remove_int(clock_inc);
}
Esempio n. 4
0
/* close_fli:
 *  Shuts down the FLI player at the end of the file.
 */
void close_fli(void)
{
   remove_int(fli_timer_callback);

   if (fli_file) {
      pack_fclose(fli_file);
      fli_file = NULL;
   }

   if (fli_filename) {
      _AL_FREE(fli_filename);
      fli_filename = NULL;
   }

   if (fli_bitmap) {
      destroy_bitmap(fli_bitmap);
      fli_bitmap = NULL;
   }

   fli_mem_data = NULL;
   fli_mem_pos = 0;

   reset_fli_variables();

   fli_status = FLI_NOT_OPEN;
}
Esempio n. 5
0
void ShutdownTimer() {
	if (!installed) return;

	remove_int(_maped_timer_handler);
	remove_timer();
	installed=false;
}
Esempio n. 6
0
/* gfx_gdi_lock:
 */
static void gfx_gdi_lock(struct BITMAP *bmp)
{
   /* to prevent the drawing threads and the rendering proc
    * from concurrently accessing the dirty lines array
    */
   _enter_gfx_critical();

   /* arrange for drawing requests to pause when we are in the background */
   if (!_win_app_foreground) {
      /* stop timer */
      remove_int(render_proc);

      _exit_gfx_critical();

      if (GFX_CRITICAL_RELEASED)
         _win_thread_switch_out();

      _enter_gfx_critical();

      /* restart timer */
      install_int(render_proc, RENDER_DELAY);
   }

   lock_nesting++;
   bmp->id |= BMP_ID_LOCKED;
}
Esempio n. 7
0
int main( void )
{
   /* first, set up Allegro and the graphics mode */
   allegro_init(); /* initialize Allegro */
   install_keyboard(); /* install the keyboard for Allegro to use */
   install_sound( DIGI_AUTODETECT, MIDI_AUTODETECT, NULL );
   install_timer(); /* install the timer handler */
   set_color_depth( 16 ); /* set the color depth to 16-bit */
   set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0 ); /* set graphics mode */
   buffer = create_bitmap(SCREEN_W, SCREEN_H);/* create buffer */
   pongData = load_datafile( "pongdatafile.dat" ); /* load the datafile */
   ball_x = SCREEN_W / 2; /* give ball its initial x-coordinate */
   ball_y = SCREEN_H / 2; /* give ball its initial y-coordinate */
   barL_y = SCREEN_H / 2; /* give left paddle its initial y-coordinate */
   barR_y = SCREEN_H / 2; /* give right paddle its initial y-coordinate */
   scoreL = 0; /* set left player’s score to 0 */
   scoreR = 0; /* set right player’s score to 0 */
   srand( time( NULL ) ); /* seed the random function ... */
   direction = rand() % 4; /* and then make a random initial direction */
   /* add timer that calls moveBall every 5 milliseconds */
   install_int( moveBall, 5 );
   /* add timer that calls respondToKeyboard every 10 milliseconds */
   install_int( respondToKeyboard, 10 );
   
   while ( !key[KEY_ESC] ) /* until the escape key is pressed ... */
   {
      /* now, perform double buffering */
      clear_to_color( buffer, makecol( 255, 255, 255 ) );
      blit( pongData[BALL].dat, buffer, 0, 0, ball_x, ball_y, 40, 40 );
      blit( pongData[BAR].dat, buffer, 0, 0, 0, barL_y, 20, 100 );  
      blit( pongData[BAR].dat, buffer, 0, 0, 620, barR_y, 20, 100 );
      line( buffer, 0, 30, 640, 30, makecol( 0, 0, 0 ) );
      /* draw text onto the buffer */
      textprintf_ex( buffer, pongData[PONGFONT].dat, 75, 0, makecol( 0, 0, 0 ),
                     -1, "Left Player Score: %d", scoreL );             
      textprintf_ex( buffer, pongData[PONGFONT].dat, 400, 0, makecol( 0, 0, 0 ),
                     -1, "Right Player Score: %d", scoreR );            
      blit( buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h );    
      clear_bitmap( buffer );                                      
   } /* end while */
 
   remove_int( moveBall ); /* remove moveBall timer */
   remove_int( respondToKeyboard ); /* remove respondToKeyboard timer */
   destroy_bitmap( buffer ); /* destroy the buffer bitmap */
   unload_datafile( pongData ); /* unload the datafile */
   return 0;
} /* end function main */
Esempio n. 8
0
File: sleep.c Progetto: cravo/damp
void sleep_timeout(void)
{
   remove_int(sleep_timeout);
   if(sleep_want_fade)
      install_int_ex(sleep_fadeout, BPS_TO_TIMER(2));
   else
      need_to_quit_program = TRUE;
}
Esempio n. 9
0
File: lcd.c Progetto: cravo/damp
void lcd_deinit(void)
{
   remove_int(lcd_scroll);
   lcd_external_function("lcd_clear");

   scFree_Instance(lcd_driver_instance);
   free(lcd_driver_script);
}
Esempio n. 10
0
File: timers.c Progetto: Azizou/XaoS
void tl_allegromode(int mode)
{
    allegromode = mode;
    if (!allegromode && ainstalled) {
	remove_int(timer);
	ainstalled = 0;
	counter = -1;
    }
}
Esempio n. 11
0
static int deinit_vidmode (void)
{
	set_gfx_mode (GFX_TEXT, 0, 0, 0, 0);
	destroy_bitmap (screen_buffer);
	remove_int (tick_increment);

	allegro_exit();

	return err_OK;
}
Esempio n. 12
0
int main()
{
  std::srand(std::time(NULL));

  allegro_init();
  install_timer();
  install_keyboard();
//   install_mouse();
  install_joystick(JOY_TYPE_AUTODETECT);

  override_config_file(redir("defnot.ini").c_str());

  gfx_widescreen = get_config_int("Game", "Widescreen", gfx_widescreen);
  gfx_fullscreen = get_config_int("Game", "Fullscreen", gfx_fullscreen);

  if (!setup_gfx() != 0) {
    allegro_message("Unable to setup the graphics mode\n");
    return 1;
  }

//   if (gfx_capabilities & GFX_HW_CURSOR) {
//     enable_hardware_cursor();
//     select_mouse_cursor(MOUSE_CURSOR_ARROW);
//     show_mouse(screen);
//   }

  if (!load_media()) {
    allegro_message("Unable to load data files to play the game\n");
    return 1;
  }

  // install the timer to control the game speed
  LOCK_VARIABLE(beats);
  LOCK_FUNCTION(timer_control);

  beats = 0;
  install_int_ex(timer_control, BPS_TO_TIMER(BPS));

  // insert the callback routine for the close-button
  LOCK_VARIABLE(continuing);
  LOCK_FUNCTION(close_button);

  set_close_button_callback(close_button);

  // play the game
  game_loop();

  set_config_int("Game", "Widescreen", gfx_widescreen);
  set_config_int("Game", "Fullscreen", gfx_fullscreen);

  remove_int(timer_control);
  allegro_exit();
  return 0;
}
Esempio n. 13
0
/* show_os_cursor:
 *  Tries to display the OS cursor. Returns 0 if a cursor is displayed after the
 *  function returns, else -1. This is similar to calling show_mouse(screen)
 *  after calling enable_hardware_cursor and checking gfx_capabilities for
 *  GFX_HW_CURSOR, but is easier to use in cases where you don't need Allegro's
 *  software cursor even if no os cursor is available.
 */
int show_os_cursor(int cursor)
{
   int r = -1;
   if (!mouse_driver)
      return r;

   remove_int(mouse_move);

   gfx_capabilities &= ~(GFX_HW_CURSOR|GFX_SYSTEM_CURSOR);
   if (cursor != MOUSE_CURSOR_NONE) {

      if (mouse_driver->enable_hardware_cursor) {
         mouse_driver->enable_hardware_cursor(TRUE);
      }

      /* default system cursor? */
      if (cursor != MOUSE_CURSOR_ALLEGRO) {
         if (mouse_driver->select_system_cursor) {
            if (mouse_driver->select_system_cursor(cursor) != 0) {
               gfx_capabilities |= (GFX_HW_CURSOR|GFX_SYSTEM_CURSOR);
               r = 0;
               goto done;
            }
         }
         goto done;
      }
      else {
         /* set custom hardware cursor */
         if (gfx_driver) {
            if (gfx_driver->set_mouse_sprite) {
               if (gfx_driver->set_mouse_sprite(mouse_sprite, mouse_x_focus, mouse_y_focus))
                  goto done;
            }
            if (gfx_driver->show_mouse) {
               if (gfx_driver->show_mouse(screen, mouse_x, mouse_y))
                  goto done;
            }
            gfx_capabilities |= GFX_HW_CURSOR;
            r = 0;
            goto done;
         }
      }
   }
   else {
      if (gfx_driver && gfx_driver->hide_mouse)
         gfx_driver->hide_mouse();
   }

done:
   if (mouse_driver->timer_poll) 
      install_int(mouse_move, 10);
   return r;
}
Esempio n. 14
0
/**
    rimuove un percorso da monitorare

    \param path percorso per il file da rimuovere
    \param inotify istanza di inotify_t di riferimento
    \sa rm_all_watches(), utils.h
    \return 0 se non ci sono stati problemi, -1 altrimenti
 */
int rem_watch(inotify_t* inotify, const char* path) {
    int i = index_of_str(inotify->files, path);
    if (i == -1)
        return -1;
    int fd = inotify->watch_fds.buf[i];
    if (inotify_rm_watch(inotify->instance, fd) == -1) {
        perror("inotify_rm_watch");
        return -1;
    }
    remove_int(&(inotify->watch_fds), fd);
    remove_str(&(inotify->files), path);
    return 0;
}
void uninstall()
{
    int i;
    remove_int(Ticks);
    remove_int(ProcessKeys);

    KillTextures();
    for(i=0; i<TextureCount; i++)
    {
        free(GlobalTextures[i]);
    }
    free(GlobalTextures);
    TextureCount=0;
    free(screenimage);
    UnLoadCollisionData();
    destroy_gfx_mode_list(Resolutions);

    DisposeVoices();

    uninstall_fonts();
    IsInstalled=0; //Allegro will dispose on exit
}
Esempio n. 16
0
static void register_timer_callback(void)
{
    if (timer_speed == 0) {
        remove_int(my_timer_callback);
    } else {
        int rate = (int)((double)TIMERS_PER_SECOND / (refresh_frequency * ((double)timer_speed / 100.0)) + .5);

        /* We use `install_int_ex()' instead of `install_int()' for increased
           accuracy.  */
        if (install_int_ex(my_timer_callback, rate) < 0) {
            /* FIXME: Maybe we could handle this better?  Well, it is not
               very likely to happen after all...  */
            relative_speed = timer_speed = 0;
        }
    }
}
Esempio n. 17
0
/* gfx_gdi_exit:
 */
static void gfx_gdi_exit(struct BITMAP *bmp)
{
   _enter_critical();

   _enter_gfx_critical();

   if (bmp) {
      save_window_pos();
      clear_bitmap(bmp);
   }

   /* stop timer */
   remove_int(render_proc);
   CloseHandle(vsync_event);

   /* disconnect from the system driver */
   win_gfx_driver = NULL;

   /* destroy dirty lines array */   
   _AL_FREE(gdi_dirty_lines);
   gdi_dirty_lines = NULL;   

   /* destroy screen surface */
   _AL_FREE(screen_surf);
   gdi_screen = NULL;

   /* destroy mouse bitmaps */
   if (wgdi_mouse_sprite) {
      destroy_bitmap(wgdi_mouse_sprite);
      wgdi_mouse_sprite = NULL;

      destroy_bitmap(mouse_frontbuffer);
      mouse_frontbuffer = NULL;

      destroy_bitmap(mouse_backbuffer);
      mouse_backbuffer = NULL;
   }

   _exit_gfx_critical();

   /* before restoring video mode, hide window */
   set_display_switch_mode(SWITCH_PAUSE);
   system_driver->restore_console_state();
   restore_window_style();

   _exit_critical();
}
Esempio n. 18
0
void remove_mod (void)
{
    int index;

    stop_mod();
    remove_int (mod_interrupt);

    for (index=0; index<MAX_ALLEG_VOICE; index++)
        {
        if (voice_table[index] >= 0)
            deallocate_voice (voice_table[index]);

        voice_table[index] = -1;
        }

    mod_init = FALSE;
}
Esempio n. 19
0
/* remove_mouse:
 *  Removes the mouse handler. You don't normally need to call this, because
 *  allegro_exit() will do it for you.
 */
void remove_mouse(void)
{
   if (!mouse_driver)
      return;

   show_mouse(NULL);
   remove_int(mouse_move);

   mouse_driver->exit();
   mouse_driver = NULL;

   _mouse_installed = FALSE;

   mouse_x = mouse_y = _mouse_x = _mouse_y = 0;
   mouse_z = _mouse_z = 0;
   mouse_w = _mouse_w = 0;
   mouse_b = _mouse_b = 0;
   mouse_pos = 0;

   mouse_polled = FALSE;

   destroy_bitmap(default_cursors[MOUSE_CURSOR_ARROW]);
   destroy_bitmap(default_cursors[MOUSE_CURSOR_BUSY]);
   destroy_bitmap(default_cursors[MOUSE_CURSOR_QUESTION]);
   destroy_bitmap(default_cursors[MOUSE_CURSOR_EDIT]);

   cursors[MOUSE_CURSOR_ARROW] = default_cursors[MOUSE_CURSOR_ARROW] = NULL;
   cursors[MOUSE_CURSOR_BUSY] = default_cursors[MOUSE_CURSOR_BUSY] = NULL;
   cursors[MOUSE_CURSOR_QUESTION] = default_cursors[MOUSE_CURSOR_QUESTION] = NULL;
   cursors[MOUSE_CURSOR_EDIT] = default_cursors[MOUSE_CURSOR_EDIT] = NULL;

   if (_mouse_pointer) {
      destroy_bitmap(_mouse_pointer);
      _mouse_pointer = NULL;
   }

   if (ms) {
      destroy_bitmap(ms);
      ms = NULL;

      destroy_bitmap(mtemp);
      mtemp = NULL;
   }

   _remove_exit_func(remove_mouse);
}
Esempio n. 20
0
void deallocate_credits(void)
{
    destroy_bitmap(wk);
    wk = NULL;
    remove_int(ticker);
}
Esempio n. 21
0
void abortAutoReload()
{
	config.automatic_reload_time = 0;
	remove_int( automaticReloadProc );	
}
Esempio n. 22
0
void clock_exit()
{
  remove_int(clock_inc);
}
Esempio n. 23
0
void stop_serial_timer()
{
   remove_int(serial_time_out_handler);
   serial_time_out = FALSE;
   serial_timer_running = FALSE;
}
Esempio n. 24
0
File: main.c Progetto: hoglet67/b-em
void changetimerspeed(int i)
{
        remove_int(int50);
        install_int_ex(int50, BPS_TO_TIMER(i));
}
Esempio n. 25
0
/* Mode: 0 - Speed mode, 1 - time mode (other settings set globally) */
int game(int mode) {
		/* Vars */
	int i=0,j=0,k=0; /* Multi use variables */
	int x_max=64,y_max=64; /* Max coordinates */
	int step = 8; /* Moneyman pixel per step */
	int padding = 16; /* Field's distance from window edge */

	int starttime=0; /* Start time (saved there later) */
	int currtime=0;

	int p1collectedcoins = 0; /* Number of collected coins */
	int p2collectedcoins = 0;
	int score = 0; /* Score if P1 (in 2P mode no scores) */
	int p1wins=0;
	int p2wins=0;
	int finished = 0; /* Finished (0=none, 1 =p1, 2=p2) */

	/* Moneyman coordinates */
	int p1_x=x_max/2, p2_x=p1_x;
	int p1_y=y_max/2, p2_y=p1_y;


	struct obj_struct *objs=0; /* Dyn. array with coins + exit door */

	BITMAP *buffer=0,*p1pic=0,*p2pic=0,*coinpic=0,*exitpic=0; /* all bitmaps */

	/* Init movement timer */
	install_int_ex(increment_coinmove_counter, SECS_TO_TIMER(relocinterval));

	/* Load bitmaps */
	buffer = create_bitmap(800,600);
	p1pic = load_bitmap("gfx/MoneyMan.bmp",NULL);
	p2pic = load_bitmap("gfx/Player2.bmp",NULL);
	coinpic = load_bitmap("gfx/Coin.bmp",NULL);
	exitpic = load_bitmap("gfx/Exit.bmp",NULL);

	/* Random seed */
	srand(time(NULL));

	/* Init objects */
	objs = malloc(sizeof(*objs)*(coinnumber+1)); /* Allocate */
	if (objs==0) { /* Allocation failed */
		fprintf(stderr,"Memory couldn't be allocated, sorry :( free your RAM!\n");
		return 1;
	}
	init_objs(objs,coinnumber+1); /* Init with 0 */
	objs[0].hidden = 1; /* Door invisible */
	relocate_objs(objs,coinnumber+1,x_max,y_max); /* Random position */

	readysetgo();
	starttime = time(NULL); /* Here it's fair to start time counting */
	while (!key[KEY_ESC] && !close_button_pressed) { /* ESC quits game */
		clear_bitmap(buffer);
		rectfill(buffer,0,0,buffer->w,buffer->h,backcolor);

		while (speed_counter > 0) { /* logical tick event happened */
			/* Collision check */
			for (i=1; i<coinnumber+1; i++) {
			/* For coins - if visible, hide, increase counter */
				if (PicCollision(p1pic,p1_x*step,p1_y*step,
						coinpic,objs[i].x*step,objs[i].y*step)
						&& objs[i].hidden==0) {
					objs[i].hidden=1;
					p1collectedcoins++;
				}
				if (players==2)
					if (PicCollision(p2pic,p2_x*step,p2_y*step,
							coinpic,objs[i].x*step,objs[i].y*step)
							&& objs[i].hidden==0) {
						objs[i].hidden=1;
						p2collectedcoins++;
					}
			}

			/* All coins collected - show door (speed mode) */
			if (mode==0 && p1collectedcoins+p2collectedcoins == coinnumber) {
				objs[0].hidden=0;
			}

			currtime = time(NULL)-starttime;

			/* Calculate current score */
			if (players==1) {
				if (mode==0)
					score = get_score(p1collectedcoins,relocinterval,currtime);
				else if (mode==1)
					score = get_score(p1collectedcoins,relocinterval,ttime);
			}


			if ((mode==0 && PicCollision(p1pic,p1_x*step,p1_y*step,
							exitpic,objs[0].x*step,objs[0].y*step)
							&& objs[0].hidden==0) ||
							(mode==1 && currtime>=ttime)) {
				finished = 1;
			} else if (players == 2)
				if (mode==0 && PicCollision(p2pic,p2_x*step,p2_y*step,
							exitpic,objs[0].x*step,objs[0].y*step)
							&& objs[0].hidden==0)
					finished = 2;

			/* Movement of MoneyMan */
			if(key[KEY_LEFT] && p1_x > 0)
				p1_x--;
			else if(key[KEY_RIGHT] && p1_x < x_max)
				p1_x++;
			if(key[KEY_UP] && p1_y > 0)
				p1_y--;
			else if(key[KEY_DOWN] && p1_y < y_max)
				p1_y++;
			/* Movement of P2 */
			if(key[KEY_A] && p2_x > 0)
				p2_x--;
			else if(key[KEY_D] && p2_x < x_max)
				p2_x++;
			if(key[KEY_W] && p2_y > 0)
				p2_y--;
			else if(key[KEY_S] && p2_y < y_max)
				p2_y++;

			/*Reset tick counter*/
			speed_counter=0;
		}

		/* win count (must be here) */
		if (players==2 && mode==0) { /* More coins + reaches door -> win, else -> draw */
			if (finished==1 && p1collectedcoins>p2collectedcoins)
				p1wins++;
			else if (finished==2 && p2collectedcoins>p1collectedcoins)
				p2wins++;
		} else if (players==2 && mode==1 && finished) { /* more coins -> win, else -> draw */
			if (p1collectedcoins>p2collectedcoins)
				p1wins++;
			else if (p2collectedcoins>p1collectedcoins)
				p2wins++;
		}

		/* Move coins every some secs */
		if (coinmove_counter > 0) {
			relocate_objs(objs,coinnumber+1,x_max,y_max);
			if (mode==1) /* Time mode */
				for(i=1;i<coinnumber+1;i++)  /* Make visible again */
					objs[i].hidden=0;
			coinmove_counter = 0; /* reset interval tick */
		}

		/* Fill buffer */
		if (objs[0].hidden==0) /* index 0 = exit door */
			draw_sprite(buffer,exitpic,step*objs[0].x+padding,step*objs[0].y+padding);
		for(i=1;i<=coinnumber;i++) /* the coins */
			if (objs[i].hidden==0)
				draw_sprite(buffer,coinpic,step*objs[i].x+padding,step*objs[i].y+padding);

		/* Draw money man */
		draw_sprite(buffer,p1pic,step*p1_x+padding,step*p1_y+padding);
		if (players==2)
			draw_sprite(buffer,p2pic,step*p2_x+padding,step*p2_y+padding);

		/* Borders of game field */
		i=(x_max+p1pic->w/step)*step+padding;
		j=(y_max+p1pic->h/step)*step+padding;

		/* Draw borders */
		for (k=0;k<5;k++)
			rect(buffer,padding-k,padding-k,i+k,j+k,makecol(0,0,255-k*20));


		/* Print info */
		textprintf_ex(buffer,myfont,i+padding,32,titlecol,-1,"MoneyMan");
		textprintf_ex(buffer,myfont,i+padding,fontpxsize * 2,
			menuselcol,-1,
			(mode==0) ? "Time: %d" : "Time left: %d",
			(mode==0) ? currtime : ttime-currtime );
		textprintf_ex(buffer,myfont,i+padding,fontpxsize * 3,
				menuselcol,-1,
				(mode==0) ? "Coins left: %d" : "P1 Coins: %d" ,
				(mode==0) ? coinnumber-(p1collectedcoins+p2collectedcoins) : p1collectedcoins );
		if (players==2 && mode==1)
			textprintf_ex(buffer,myfont,i+padding,fontpxsize * 4,
				menuselcol,-1, "P2 Coins: %d" , p2collectedcoins );
		if (players==1)
			textprintf_ex(buffer,myfont,
						(x_max+p1pic->w/step)*step+2*padding,fontpxsize*5,
						menuselcol,-1,
						"Score: %d",score);
		/* Draw wins info */
		if (players==2) {
			textprintf_ex(buffer,myfont,
				(x_max+p1pic->w/step)*step+2*padding,fontpxsize*11,
				infocol,backcolor,
				"P1 wins: %d",p1wins);
			textprintf_ex(buffer,myfont,
				(x_max+p1pic->w/step)*step+2*padding,fontpxsize*12,
				infocol,backcolor,
				"P2 wins: %d",p2wins);
		}

		/* Apply on screen */
		blit(buffer,screen,0,0,0,0,800,600); /*Copy buffer to screen*/

		/* If win */
		if (finished) {
			if (mode==0)
				textprintf_ex(screen,myfont,
					(x_max+p1pic->w/step)*step+2*padding,fontpxsize*6,
					infocol,-1,
					"Finished!");
			else if (mode==1)
				textprintf_ex(screen,myfont,
					(x_max+p1pic->w/step)*step+2*padding,fontpxsize*6,
					infocol,-1,
					"Time is over!");
				if (players==1)
				add_if_highscore(score);
				textprintf_ex(screen,myfont,
				(x_max+p1pic->w/step)*step+2*padding,fontpxsize*8,
				infocol,-1,
				"ENTER=retry");
			textprintf_ex(screen,myfont,
				(x_max+p1pic->w/step)*step+2*padding,fontpxsize*9,
				infocol,-1,
				"ESC=quit");
			while(!(key[KEY_ENTER] || key[KEY_ESC]));
			if (key[KEY_ENTER]) {
				readysetgo();
				finished = 0;
				p1collectedcoins = 0;
				p2collectedcoins = 0;
				init_objs(objs,coinnumber+1);
				relocate_objs(objs,coinnumber+1,x_max,y_max);
				objs[0].hidden = 1; /* hide door again */
				remove_int(increment_coinmove_counter);
				install_int_ex(increment_coinmove_counter, SECS_TO_TIMER(relocinterval));
				starttime = time(NULL);
			}
		}
	}

	/* clean up on finish */
	remove_int(increment_coinmove_counter);
	destroy_bitmap(exitpic);
	destroy_bitmap(coinpic);
	destroy_bitmap(p1pic);
	destroy_bitmap(p2pic);
	destroy_bitmap(buffer);
	free(objs); objs=0;
	clear_bitmap(screen);
	rectfill(screen,0,0,screen->w,screen->h,backcolor);
	return 0;
}
int main()
{
    if(!initialize())    return 1;
    int spawn, lastspawn=-1,spawnbomb,lastspawnbomb=-1;
    if(!loadplayer()) {
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load tarma");
        return 1;
    }
    if(!loadenemy()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load bulldogs");
        return 1;
    }
    if(!loadpistol()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load pistols");
        return 1;
    }
    if(!loadbomber()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load bomber");
        return 1;
    }
    if(!loadbomb()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load bomb");
        return 1;
    }

    /*if(!loadgun()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load guns");
        return 1;
    }*/
    /*if(!loadboss()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load boss");
        return 1;
    }*/
    //int volume=250,pan=128,pitch=1000;
    //play_sample(level1,volume,pan,pitch,TRUE);
    int intro=0,exits=0;
    while(!exits){
         intro=counter;
         while(counter-intro<2)
        blit(welcome,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;
        while(counter-intro<2)
        blit(instruction1,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;
        while(counter-intro<2)
        blit(instruction2,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;

        while(counter-intro<2)
        blit(instruction3,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;
        gameover=0;
        loadplayer();
        loadenemy();
        loadbomber();
        loadpistol();
        loadbomb();

        while(!key[KEY_ESC] && !gameover){
       // clear_bitmap(buffer);

        if(mils-lastinput>2) inputflag=1;
        if(inputflag)   checkinputs();

        updatehero();
        if(gameover==1) break;
        if((tarma.x%(640*2))<5 && lastspawn!=tarma.x/(640*2)){
            spawn=1;
            lastspawn=tarma.x/(640*2);
        }
         if((tarma.x%(640*5))<5 && lastspawnbomb!=tarma.x/(640*5)){
            spawnbomb=1;
            lastspawnbomb=tarma.x/(640*5);
        }


        updateenemy(spawn);
        updatebombers(spawnbomb);
        updatedeaths();
        updatebullets();
        updatebombs();
        displaystats();
        acquire_screen();
        blit(buffer,screen,0,0,0,0,WIDTH,HEIGHT);
        release_screen();
        ticks++;
        rest(DELAY);
    }
    intro=counter;
    while(counter-intro<2)
        blit(gameoverscreen,screen,0,0,0,0,WIDTH,HEIGHT);
    if(key[KEY_ESC])     exits=1;

    }

     destroy_sample(level1);
     remove_sound();
    remove_int(timer1);
    destroy_bitmap(buffer);
    destroy_bitmap(welcome);
    destroy_bitmap(instruction1);
    destroy_bitmap(instruction2);
    destroy_bitmap(instruction3);
    destroy_bitmap(gameoverscreen);
    delete []bulldogs;
    delete []pistols;
    delete gun;
    delete []bomb;
    delete []bombman;
    delete rocket;
     for(int i=0;i<6;i++)
                for(int j=0;j<TARMAMAX[i];j++)
                    destroy_bitmap(tarma.heroimg[i][j]);
     for(int i=2;i<5;i++)
                for(int j=0;j<REBELMAX[i];j++)
                destroy_bitmap(enemypics.enemyimg[i][j]);
    for(int i=0;i<4;i++)
                destroy_bitmap(bulletpics.bullets[i]);
    for(int i=0;i<14;i++)
        destroy_bitmap(bomberpics.bomber[i]);

    MapFreeMem();
    allegro_exit();
    return 0;
}
Esempio n. 27
0
void    Frame_Skipper_Auto_Reinstall_Handler (void)
{
    remove_int (Frame_Skipper_Auto_Adjust_Handler);
    Frame_Skipper_Auto_Install_Handler ();
}
Esempio n. 28
0
/* show_mouse:
 *  Tells Allegro to display a mouse pointer. This only works when the timer 
 *  module is active. The mouse pointer will be drawn onto the bitmap bmp, 
 *  which should normally be the hardware screen. To turn off the mouse 
 *  pointer, which you must do before you draw anything onto the screen, call 
 *  show_mouse(NULL). If you forget to turn off the mouse pointer when 
 *  drawing something, the SVGA bank switching code will become confused and 
 *  will produce garbage all over the screen.
 */
void show_mouse(BITMAP *bmp)
{
   if (!mouse_driver)
      return;

   remove_int(mouse_move);

   /* Remove the mouse cursor */
   if (_mouse_screen) {
      acquire_bitmap(_mouse_screen);

      if (gfx_capabilities & GFX_HW_CURSOR) {
	 gfx_driver->hide_mouse();
	 gfx_capabilities &= ~(GFX_HW_CURSOR|GFX_SYSTEM_CURSOR);
 	 hw_cursor_dirty = TRUE;
      }
      else
	 draw_mouse(TRUE, FALSE);

      release_bitmap(_mouse_screen);
   }

   _mouse_screen = bmp;

   if (bmp && (current_cursor != MOUSE_CURSOR_NONE)) {
      acquire_bitmap(_mouse_screen);

      /* Default system cursor? */
      if ((current_cursor != MOUSE_CURSOR_ALLEGRO) && allow_system_cursor) {
         if (mouse_driver && mouse_driver->select_system_cursor) {
            use_system_cursor = mouse_driver->select_system_cursor(current_cursor);
            if (use_system_cursor) {
               gfx_capabilities |= GFX_HW_CURSOR|GFX_SYSTEM_CURSOR;
               hw_cursor_dirty = FALSE;
               got_hw_cursor = TRUE;
            }
         }
      }
      else {
         use_system_cursor = FALSE;
      }

      /* Custom hardware cursor? */
      if (hw_cursor_dirty) {
	 got_hw_cursor = FALSE;

	 if ((gfx_driver) && (gfx_driver->set_mouse_sprite) && (!_dispsw_status))
	    if (gfx_driver->set_mouse_sprite(mouse_sprite, mouse_x_focus, mouse_y_focus) == 0)
	       got_hw_cursor = TRUE;

	 hw_cursor_dirty = FALSE;
      }
      
      /* Try to display hardware (custom or system) cursor */
      if ((got_hw_cursor) && (is_same_bitmap(bmp, screen)))
	 if (gfx_driver->show_mouse(bmp, mx=mouse_x, my=mouse_y) == 0)
	    gfx_capabilities |= GFX_HW_CURSOR;

      /* Draw cursor manually if we can't do that */
      if (!(gfx_capabilities & GFX_HW_CURSOR)) {
	 draw_mouse(FALSE, TRUE);
         use_system_cursor = FALSE;
      }

      release_bitmap(_mouse_screen);

      install_int(mouse_move, 10);
   }
   else {
      if (mouse_driver->timer_poll) 
	 install_int(mouse_move, 10);
   }
}
Esempio n. 29
0
int humanvspsp(Player *p1, Player *p2)
{
	BITMAP* buffer_field_game = create_bitmap(MAX_WIDTH, MAX_HEIGTH);
	BITMAP* buffer_border_and_info = create_bitmap(SCREEN_WIDTH, SCREEN_HEIGTH);
	int koniec = -1;

	reset_player(p1, 136, 230, 2);
	reset_player(p2, 136, 245, 3);

	clear_to_color(buffer_field_game, makecol(0, 0, 0));
	rysuj_obramowanie(buffer_border_and_info, p1, p2);
	blit(buffer_border_and_info, screen, 0, 0, 0, 0, buffer_border_and_info->w, buffer_border_and_info->h);
	clear_keybuf();

	odliczanie();

	blit(buffer_border_and_info, screen, 0, 0, 0, 0, buffer_border_and_info->w, buffer_border_and_info->h);

	clear_key();

	blit(buffer_field_game, buffer_border_and_info, 0, 0, 1, 1, buffer_field_game->w, buffer_field_game->h);
	blit(buffer_border_and_info, screen, 0, 0, 0, 0, buffer_border_and_info->w, buffer_border_and_info->h);

	p1_speed = 0;
	p2_speed = 0;
	speed = 25;
	install_int_ex(p1_speed_func, MSEC_TO_TIMER(speed));
	install_int_ex(p2_speed_func, MSEC_TO_TIMER(speed));
	install_int_ex(speed_func, SECS_TO_TIMER(1));

	while(TRUE)
	{
		ai_run(p2, buffer_field_game);
		if((p1->x == p2->x) && (p1->y == p2->y))
		{
			koniec = 0;
			break;
		}


		switch(p1->direction)
		{
			case UP:
				if(getpixel(buffer_field_game, p1->y, p1->x-1) != makecol(0, 0, 0))
				{
					koniec = 1;
				}
			break;
			case DOWN:
				if(getpixel(buffer_field_game, p1->y, p1->x+1) != makecol(0, 0, 0))
				{
					koniec = 1;
				}
			break;
			case LEFT:
				if(getpixel(buffer_field_game, p1->y-1, p1->x) != makecol(0, 0, 0))
				{
					koniec = 1;
				}
			break;
			case RIGHT:
				if(getpixel(buffer_field_game, p1->y+1, p1->x) != makecol(0, 0, 0))
				{
					koniec = 1;
				}
			break;
		}

		switch(p2->direction)
		{
			case UP:
				if(getpixel(buffer_field_game, p2->y, p2->x-1) != makecol(0, 0, 0))
				{
					if(koniec == 1)
					{
						koniec = 0;
						break;
					}
					else
					{
						koniec = 2;
					}
				}
			break;
			case DOWN:
				if(getpixel(buffer_field_game, p2->y, p2->x+1) != makecol(0, 0, 0))
				{
					if(koniec == 1)
					{
						koniec = 0;
						break;
					}
					else
					{
						koniec = 2;
					}
				}
			break;
			case LEFT:
				if(getpixel(buffer_field_game, p2->y-1, p2->x) != makecol(0, 0, 0))
				{
					if(koniec == 1)
					{
						koniec = 0;
						break;
					}
					else
					{
						koniec = 2;
					}
				}
			break;
			case RIGHT:
				if(getpixel(buffer_field_game, p2->y+1, p2->x) != makecol(0, 0, 0))
				{
					if(koniec == 1)
					{
						koniec = 0;
						break;
					}
					else
					{
						koniec = 2;
					}
				}
			break;
		}

		putpixel(buffer_field_game, p1->y, p1->x, makecol(255, 255, 255));
		putpixel(buffer_field_game, p2->y, p2->x, makecol(86, 160, 222));

		if(p1->x < MIN_HEIGTH || p1->x > MAX_HEIGTH-1 || p1->y < MIN_WIDTH || p1->y > MAX_WIDTH-1)
		{
			koniec = 1;
		}

		if(p2->x < MIN_HEIGTH || p2->x > MAX_HEIGTH-1 || p2->y < MIN_WIDTH || p2->y > MAX_WIDTH-1)
		{
			if(koniec == 1)
			{
				koniec = 0;
				break;
			}
			else
			{
				koniec = 2;
			}
		}

		blit(buffer_field_game, screen, 0, 0, 1, 1, buffer_field_game->w, buffer_field_game->h);

		if(koniec != -1)
			break;


		if(key[KEY_ESC])
			break;

		if(key[KEY_ENTER])
		{
			pause_game(0, p1, p2);
			odliczanie();
		}

#ifdef PSP
		if(key[KEY_RSHIFT])
		{
			thid = sceKernelCreateThread("Screenshotpsp", screenshotpsp,
			   0x11, 256 * 1024, PSP_THREAD_ATTR_USER, NULL);
			sceKernelStartThread(thid, 0, NULL);
		}
#else
		if(key[KEY_M])
		{
			screenshot();
		}
#endif

#if PSP
		if(key[KEY_UP])
#else
		if(key[KEY_W])
#endif
		{
			if(p1->direction != DOWN)
				p1->direction = UP;
		}
#if PSP
		else if(key[KEY_DOWN])
#else
		else if(key[KEY_S])
#endif
		{
			if(p1->direction != UP)
				p1->direction = DOWN;
		}
#if PSP
		else if(key[KEY_LEFT])
#else
		else if(key[KEY_A])
#endif
		{
			if(p1->direction != RIGHT)
				p1->direction = LEFT;
		}
#if PSP
		else if(key[KEY_RIGHT])
#else
		else if(key[KEY_D])
#endif
		{
			if(p1->direction != LEFT)
				p1->direction = RIGHT;
		}
		clear_keybuf();
		keypressed();


		while(p1_speed > 0)
		{
			switch(p1->direction)
			{
				case UP:
					p1->x--;
				break;
				case DOWN:
					p1->x++;
				break;
				case LEFT:
					p1->y--;
				break;
				case RIGHT:
					p1->y++;
				break;
			}
			p1_speed--;
		}

		while(p2_speed > 0)
		{
			switch(p2->direction)
			{
				case UP:
					p2->x--;
				break;
				case DOWN:
					p2->x++;
				break;
				case LEFT:
					p2->y--;
				break;
				case RIGHT:
					p2->y++;
				break;
			}
			p2_speed--;
		}

	}

	remove_int(p1_speed_func);
	remove_int(p2_speed_func);
	remove_int(speed_func);

	destroy_bitmap(buffer_field_game);
	destroy_bitmap(buffer_border_and_info);

	return koniec;
}
Esempio n. 30
0
//main function
void main()
{
    //setup allegro
    allegro_init();
    install_mouse();
    install_timer();
    set_color_depth(COLOR_DEPTH);
    set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);

    //setup the timer
    install_int(update_timer, 1);

    //seed random number
    srand(time(NULL));

    //set up the close button
    set_close_button_callback(quit);

    //initialize the buffer
    buffer = create_bitmap(WIDTH, HEIGHT);

    //main loop
    while (!end_game)
    {
        //log the start time
        start_time = timer;

        F_PLUS = (loop_num/50);
        if (F_PLUS > 120) F_PLUS = 120;

        mx = (mouse_x+mx*7)/8;
        my = (mouse_y+my*7)/8;

        if (mouse_b & 2) {nshots = 0; score = 0; ray_t = 50; game_over = false;}

        //fire a new shot
        if (loop_num % 10-F_PLUS/30 == 0)
        {
                if (rand()%2)
                {
                        shot[nshots].x = rand()%2*WIDTH;
                        shot[nshots].y = rand()%HEIGHT;
                        shot[nshots].vy = 0;
                        shot[nshots].vx = (WIDTH/2-shot[nshots].x)/(WIDTH/2);
                        nshots++;
                }
                else
                {
                        shot[nshots].y = rand()%2*HEIGHT;
                        shot[nshots].x = rand()%WIDTH;
                        shot[nshots].vx = 0;
                        shot[nshots].vy = (HEIGHT/2-shot[nshots].y)/(HEIGHT/2);
                        nshots++;
                }
        }
        //rays
        if ((loop_num % 300-F_PLUS == 0)&&(loop_num > 300))
        {
                ray_x = mx+rand()%11-5;
                ray_y = my+rand()%11-5;
                ray_t = -40;
        }

        if (loop_num % 2) ray_t++;

        //bullet move
        for (int i = 0; i < nshots; i++)
        {
                shot[i].x += shot[i].vx;
                shot[i].y += shot[i].vy;
                if ((shot[i].x > WIDTH)||(shot[i].y > HEIGHT)||(shot[i].x < 0)||(shot[i].y < 0)){nshots--; shot[i] = shot[nshots];}
                if (hit(mx, my, shot[i].x, shot[i].y, 5)){game_over = true;}
        }

        //death
        if ((abs(ray_t) < 20)&&(((mx < ray_x+(20-abs(ray_t)))&&(mx > ray_x-(20-abs(ray_t))))
        ||((my < ray_y+(20-abs(ray_t)))&&(my > ray_y-(20-abs(ray_t)))))){game_over = true;}

        ////drawing////

        //player
        if (!game_over)
        circle(buffer, mx, my, 5, WHITE);
        else
        circle(buffer, mx, my, 5, makecol(255, 0, 0));

        //bullets
        for (int i = 0; i < nshots; i++)
        {
                circlefill(buffer, shot[i].x, shot[i].y, 2, WHITE);
        }

        //beams
        if (ray_t <= -20)
        {
                hline(buffer, 0, ray_y, WIDTH, WHITE);
                vline(buffer, ray_x, 0, HEIGHT, WHITE);
        }
        if (abs(ray_t) < 20)
        {
                rectfill(buffer, 0, ray_y-(20-abs(ray_t)), WIDTH, ray_y+(20-abs(ray_t)), WHITE);
                rectfill(buffer, ray_x-(20-abs(ray_t)), 0, ray_x+(20-abs(ray_t)), HEIGHT, WHITE);
                rectfill(buffer, 0, ray_y-(20-abs(ray_t))/2, WIDTH, ray_y+(20-abs(ray_t))/2, SILVER);
                rectfill(buffer, ray_x-(20-abs(ray_t))/2, 0, ray_x+(20-abs(ray_t))/2, HEIGHT, SILVER);
        }

        //text
        if (!game_over)
        textprintf_centre_ex(buffer, font, WIDTH/2, 10, WHITE, BLACK, "%i", score*LOOP_TIME/1000);
        else
        {
        textprintf_centre_ex(buffer, font, WIDTH/2, 10, makecol(255, 0, 0), BLACK, "%i", score*LOOP_TIME/1000);
        textprintf_centre_ex(buffer, font, WIDTH/2, HEIGHT/2-5, WHITE, BLACK, "Game Over");
        textprintf_centre_ex(buffer, font, WIDTH/2, HEIGHT/2+10, WHITE, BLACK, "Right-Click to restart");
        }

        //draw to the screen
        blit(buffer, screen, 0, 0, 0, 0, WIDTH, HEIGHT);

        //clear the buffer
        clear_to_color(buffer, BLACK);

        //wait
        while (timer < start_time + LOOP_TIME)
        {rest(1);}
        loop_num++;
        if (game_over == false) score++;
    }
    remove_int(update_timer);
    destroy_bitmap(buffer);
    return;
}