Exemple #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();
}
Exemple #2
0
int main()
{
	int ok;
	allegro_init();
	install_timer();

	do {
		set_color_depth(8);
		if (set_gfx_mode (GFX_AUTODETECT, 640, 480, 0, 0) < 0) {
			allegro_message ("Error setting plain graphics mode:\n%s\n", allegro_error);
			return -1;
		}
		
		install_allegro_gl();

		install_keyboard();
		install_mouse();
		ok = setup();
		remove_keyboard();
		remove_mouse();

		if (ok) run_demo();

		remove_allegro_gl();
	} while (ok);

	return 0;
}
void uip_textmode(void)
{
  if (uip_vga) {
    remove_keyboard();
    set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
  }
  uip_vga = 0;
}
Exemple #4
0
void textgfx_init()
{
#ifdef UNIX
	strcpy(_xwin.application_name, "vitetris");
	strcpy(_xwin.application_class, "Vitetris");
#endif
	if (install_allegro(SYSTEM_AUTODETECT, &errno, NULL) != 0)
		exit(1);
#ifdef UNIX
	sigaction(SIGINT, NULL, &allegro_sigint_handler);
	signal(SIGINT, sigint_handler);
#endif
	load_pc8x16_font();
	set_window_title(VITETRIS_VER);
	set_close_button_callback(close_btn);
#ifndef UNIX
	/* Seems to cause seg fault later quite randomly on Linux  */
	int depth = desktop_color_depth();
	if (depth != 0)
		set_color_depth(depth);
#endif
	virt_screen = set_screen(getopt_int("", "fullscreen"));
	lang |= LATIN1;
	if (!font8x16) {
		font8x16 = font;
		textgfx_flags |= ASCII;
	}
	setattr_normal();
#if WIN32 && !ALLEGRO_USE_CONSOLE
	if (exists("stdout.tmp")) {
		FILE *fp;
		freopen("stdout2.tmp", "w", stdout);
		fp = fopen("stdout.tmp", "r");
		if (fp) {
			char line[80];
			int i;
			for (i=0; i < 25 && fgets(line, 80, fp); i++) {
				setcurs(0, i);
				i += printline(line);	
			}
			fclose(fp);
			if (i) {
				refreshscreen();
				if (!strncmp(line, "Press ", 6)) {
					install_keyboard();
					clear_keybuf();
					readkey();
					remove_keyboard();
				}
			}
		}
		freopen("stdout.tmp", "w", stdout);
		delete_file("stdout2.tmp");
	}
#endif
}
Exemple #5
0
void S9xTextMode ()
{
    if (!in_text_mode)
    {
	set_color_depth (8);
	remove_keyboard ();
	remove_mouse ();
	set_gfx_mode (GFX_TEXT, 0, 0, 0, 0);
	in_text_mode = TRUE;
    }
}
Exemple #6
0
void GameExit(void)
{

	remove_keyboard();
	remove_timer();
	remove_mouse();

	allegro_exit();

 	return;
}
void Clearing()
{
	#ifdef SOUND_ENABLED
		Clean_Music();
	#endif

	#ifdef DEBUG
		fprintf(stderr, "Clean surface and free Allegro from memory\n");
	#endif

	Clear_Images();

	remove_keyboard();
	allegro_exit();
}
Exemple #8
0
void uninstall()
{
  destroy_bitmap(ball[1]);
  destroy_bitmap(ball[0]);
  destroy_bitmap(bar_left);
  destroy_bitmap(bar_right);
  destroy_bitmap(logo_c);
  destroy_bitmap(logo);
  destroy_bitmap(court);
  destroy_bitmap(screen_buffer);
  destroy_font(font);
  remove_timer();
  remove_keyboard();
  close13h();
}
Exemple #9
0
int cControls::Exit()
{
   if(!m_exited)
   {
      remove_keyboard();
      remove_joystick();
      remove_mouse();

      FreeAll();

      m_exited = true;
   }

   return 0;
}
Exemple #10
0
/* exit_window_modules:
 *  Removes the modules that depend upon the main window:
 *   - keyboard (DirectInput),
 *   - mouse (DirectInput),
 *   - joystick (DirectInput),
 *   - sound (DirectSound),
 *   - sound input (DirectSoundCapture).
 *  If WM is not NULL, record which modules are really removed.
 */
static void exit_window_modules(struct WINDOW_MODULES *wm)
{
   if (wm)
      memset(wm, 0, sizeof(*wm));

   if (_keyboard_installed) {
     if (wm)
         wm->keyboard = TRUE;

      remove_keyboard();
   }

   if (_mouse_installed) {
      if (wm)
         wm->mouse = TRUE;

      remove_mouse();
   }

   if (_joystick_installed) {
      if (wm) {
         wm->joystick = TRUE;
         wm->joy_type = _joy_type;
      }

      remove_joystick();
   }

   if (_sound_installed) {
      if (wm) {
         wm->sound = TRUE;
         wm->digi_card = digi_card;
         wm->midi_card = midi_card;
      }

      remove_sound();
   }

   if (_sound_input_installed) {
      if (wm) {
         wm->sound_input = TRUE;
         wm->digi_input_card = digi_input_card;
         wm->midi_input_card = midi_input_card;
      }

      remove_sound_input();
   }
}
void Graphic::deinit()
{
    for (int i=0; i<MAX_SPRITE; i++)
    {
        imageDestroy(this->pSprites[i]);
    }
    for (int i=0; i<MAX_SPRITE_PLAYER; i++)
    {
        imageDestroy(this->pSpritesPlayer[i]);
    }

    imageDestroy(pBuffer);
    remove_mouse();
    remove_keyboard();
    allegro_exit();
}
Exemple #12
0
void keyswitch(int keyswitch_lang)
{
	push_config_state();
	set_config_file(F("$(home)/ufo2000.ini"));

	switch (keyswitch_lang) {
		case 0: {
			const char *current_keyboard = get_config_string("system", "keyboard", "us");
			const char *primary_keyboard = get_config_string("system", "primary_keyboard", "us");
			const char *secondary_keyboard = get_config_string("system", "secondary_keyboard", "ru");
			if (strcmp(current_keyboard, primary_keyboard) == 0)
				set_config_string("system", "keyboard", secondary_keyboard);
			else
				set_config_string("system", "keyboard", primary_keyboard);
			break;
		}
		case KEY_E: 
			set_config_string("system", "keyboard", "us"); 
			break;
		case KEY_R: 
			set_config_string("system", "keyboard", "ru"); 
			break;
		case KEY_B: 
			set_config_string("system", "keyboard", "by"); 
			break;
		case KEY_P: 
			set_config_string("system", "keyboard", "pl"); 
			break;
		case KEY_D: 
			set_config_string("system", "keyboard", "de"); 
			break;
		default: 
			pop_config_state(); 
			return;
	}
	
	clear_keybuf();
	remove_keyboard();
	install_keyboard();
	pop_config_state();
}
Exemple #13
0
void exit_module_gui()
{
    save_gui_config();

    // destroy shortcuts
    ASSERT(shortcuts != NULL);
    for (Shortcut* shortcut : *shortcuts)
        delete shortcut;
    delete shortcuts;
    shortcuts = NULL;

    delete manager;

    // Now we can destroy theme
    CurrentTheme::set(NULL);
    delete ase_theme;

    remove_keyboard();
    remove_mouse();

    main_clipboard->dispose();
    main_display->dispose();
}
Exemple #14
0
void alleg_exit() {
	clear_keybuf();
	remove_keyboard();
	remove_timer();
	allegro_exit();
}
int main(int argc, char *argv[])
{//start of main function

	//set gameover = true to stop the game from loading before the player plays
	GAMEOVER=true;

	//variable declerations
	int id;

	//variables used for the threads
	pthread_t pthread0;
    pthread_t pthread1;
    int threadid0 = 0;
	int threadid1 = 1;
	int threadid2 = 2;
	int threadid3 = 3;
	int threadid4 = 4;
	int threadid5 = 5;
	int threadid6 = 6;


	//set is intro to true to play the intro
	bool inIntro =true; 

	//variable used to display the players message
	char *playermessage;

	//map variables 
	int mapxoff = 0;
	int mapyoff = 0;

	//game speed variables declerations and initalization
	int frames_per_sec=0;
	int frames_done=0;
	int old_time =0;
	int totaltime=0;

	//declare allegro variables
	//BITMAP *buffer;
	BITMAP *intro;

	//initalize the classes
	//player *owl;
	sprite *hearts[3];
	sprhandler = new spritehandler();
	snake *snakeboss;

	//initalize allegro
	allegro_init();
	install_keyboard();
	install_timer();
	set_keyboard_rate(1000,1000);
	install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL);

	//initalize the screen
	set_color_depth(COLORDEPTH);
	set_gfx_mode(MODE,WIDTH,HEIGHT,0,0);

	//lock both the varibale and the funciton to be used by the interrupt handler
	LOCK_VARIABLE(ticks);
	LOCK_FUNCTION(ticker);
	//install the interrupt handler which calls the ticker 60 times a second
	install_int_ex(ticker,BPS_TO_TIMER(FPS));
	
	//lock both the varibale and the funciton to be used by the interrupt handler
	//these 
	LOCK_VARIABLE(gametime);
	LOCK_FUNCTION(game_time_ticker);
	
	//install the interrupt handler which calls the game time ticker
	//game time ticker is in 10ths of seconds
	install_int_ex(game_time_ticker,BPS_TO_TIMER(10));

	//create back buffer
    buffer = create_bitmap(SCREEN_W, SCREEN_H);

	//create the intro screen by loading the bitmap into the intro buffer
	intro = load_bitmap("flightless title.bmp",NULL);
	if(!intro){
		allegro_message("Error loading intro image");
		return 1;
	}

	//seed the random function
	srand(time(NULL));
	
	//load fonts
	FONT *dicot_22_font;
	PALETTE palette;
	
	//load the the font for the header of the application
	dicot_22_font = load_font("dicot_22.pcx", palette, NULL);
	
	//load and display the intro screen
	while(inIntro)
	{
		//display the intro screen for the game
		blit(intro,screen,0,0,0,0,SCREEN_W,SCREEN_H);
		
		//wait for the player to press enter to start the game
		if(key[KEY_ENTER]){
			inIntro=false;
			GAMEOVER=false;
		}
		
		//if the player presses esc then exit the game and the intro
		if(key[KEY_ESC]){
			inIntro=false;
			GAMEOVER=true;
		}
	}
	//for as many badies make sprites to hold the bugs
	for(int i=0;i<BADIES;i++)
	{
			//initalize the bug sprite
			 bug[i] = new bugs();

			//load the bug sprite sheet
			if(!bug[i]->load("bug.bmp")){
			allegro_message("Error loading bug sprite");
			return 1;
			}

			//initalize the bug propertys
			bug[i]->init();
			
			//add sprites to the sprite handler
			sprhandler->addbugs(bug[i]);
	}
	//initalize the player
	owl = new player();

	//load the players sprite sheet
	if(!owl->load("owl sprite_new.bmp")){
		allegro_message("Error loading owl sprite");
		return 1;
	}
	
	//initalize the sprite properties
	owl->init();

	//add the player object to the sprite handler
	sprhandler->addsprite(owl);

	//create the new snake object
	snakeboss = new snake();

	//load the snake
	if(!snakeboss->load("snake_Tiles.bmp")){
		allegro_message("Error loading snake sprite");
		return 1;
	}
	//initalize the snake
	snakeboss->init();
	//snakeboss->alive=false;

	//add the snake to the sprite handler
	sprhandler->addboss(snakeboss);

	//create for loop to load the players health indicator
	for(int i=1;i<4;i++)
	{
		//create new sprite objects to hold the images
		hearts[i-1] = new sprite();

		//load the players health image
		if(!hearts[i-1]->load("FullHealth.bmp")){
			allegro_message("Error loading player Health");
			return 1;
		}
			//set sprite properties
			hearts[i-1]->x = SCREEN_W-35*i;
			hearts[i-1]->y = 10;
			hearts[i-1]->width = 30;
			hearts[i-1]->height = 30;
			hearts[i-1]->velx = 0;
			hearts[i-1]->vely = 0;
			hearts[i-1]->animcolumns = 0;
			hearts[i-1]->curframe = 0;
			hearts[i-1]->totalframes =1;
			hearts[i-1]->animdir = 0;
			//object type of non moving sprite
			hearts[i-1]->objecttype=2;
			hearts[i-1]->alive=0;

		//add the players health to the sprite handler
		sprhandler->addsprite(hearts[i-1]);
	}
	

	//create the music samples
	SAMPLE *ingamesong;

	//load the wav file into the samples
	//main game soundtrack
	ingamesong=load_sample("melo-24_Clip.wav");
	if(ingamesong==NULL){
			allegro_message("Error loading game soundtrack");
			return 1;
	}

	//use mappy.h global function MapLoad to load the .FMP file
	MapLoad("flightless.FMP");
	
	//play the sample music
	int playing = play_sample(ingamesong,150,125,1000,true);

	//start the clock to time the player
	startTime = time(NULL);

	//create the thread for player
    id = pthread_create(&pthread0, NULL, playerdraw_thread, (void*)&threadid5);

	//create the thread for the bugs
	id = pthread_create(&pthread1, NULL, wormdraw_thread, (void*)&threadid0);
	id = pthread_create(&pthread1, NULL, wormdraw_thread, (void*)&threadid1);
	id = pthread_create(&pthread1, NULL, wormdraw_thread, (void*)&threadid2);
	id = pthread_create(&pthread1, NULL, wormdraw_thread, (void*)&threadid3);
	id = pthread_create(&pthread1, NULL, wormdraw_thread, (void*)&threadid4);

	//create the thread to draw the snake
	id = pthread_create(&pthread1, NULL, snakedraw_thread, (void*)&threadid0);

	//main game loop
	while (!GAMEOVER)
	{		

		while (ticks==0)
		{
			rest(1);
		}
		while(ticks>0)
		{
			if(key[KEY_ESC])
			{
				playermessage="You quit :( Please come back again.";
				GAMEOVER=true;
			}
			
			//get the previous value of ticks and store them
			old_ticks=ticks;

			//each time we hit this loop we increment the mapxoffset +1 			
			if(mapxoff<mapwidth*mapblockwidth)
			{
				//if the player is not hiding update the map
				if(owl->state!=2)
				{
					mapxoff++;
				}
			}
			//draw the background tiles via the mappy global funciton MapDrawBG
			MapDrawBG(buffer,mapxoff,0,0,0,WIDTH-1,HEIGHT-1);
	
			//draw the players health indicator based on the owls health/30
			for (int i=0;i<((owl->health)/30);i++)
			{
				hearts[i]->draw(buffer);
			}
			
			//lock the varibales to protect them from the unsynced threads
			pthread_mutex_lock(&threadsafe);

			//get the player input
			owl->getinput();	

			sprhandler->updatebugs();
			sprhandler->updatesnake();

			//decrement the ticks
			ticks--;
			
			//unlock the mutex
			pthread_mutex_unlock(&threadsafe);
			//if the logic is taking too long abort and draw the screen
			if(old_ticks<=ticks)
				break;
		}
		//for every second that passess we need to call this function
		if(gametime - old_time >= 10)
		{
			//frames_per_sec holds the number of frames drawn in the last sec
			frames_per_sec = frames_done;

			//reset these variables for the next second
			frames_done =0;
			old_time=gametime;
		}
		//Decrement the players health
		if(gametime%120==0)
		{
 			owl->takedamage(2);
		}
		if(sprhandler->getsnakes(0)->alive==false && gametime%400==0)
		{
			sprhandler->getsnakes(0)->resurrect();
		}
		//check players health
		if(owl->health<=0)
		{
			playermessage="You have died...please remeber to eat next time.";
			GAMEOVER=true;
		}
		//stop the window from scrolling
		if(GAMEOVER==true ||mapxoff>=mapwidth*mapblockwidth-WIDTH)
		{
			if(mapxoff>=mapwidth*mapblockwidth-WIDTH)
				playermessage="Great job player you passed the game! Way to go.";
			//stop the map from moving
			mapxoff=mapwidth*mapblockwidth-WIDTH;
			
			//stop the music from playing
			stop_sample(ingamesong);

			//create the music samples
			SAMPLE *cheer=NULL;
	
			//load the wav file into the sample
			cheer=load_sample("app.wav");
			if(cheer==NULL){
					allegro_message("Error loading game soundtrack");
					return 1;
				}

			//play the sample music
			play_sample(cheer,255,125,1000,true);

			//message the player...even if they are a quiter!
			textprintf_ex(screen,dicot_22_font,200,SCREEN_H/2,makecol(255,0,0),-1,playermessage);

			rest(2000);
 	  	 	GAMEOVER=true;
		}
		//show frames fer second on the screen by pressing "cntrl f"
		if(key[KEY_F])
		{
			if(key_shifts & KB_CTRL_FLAG)
			{
				//switch the showFPS flag to display the FPS
				SHOWFPS=!SHOWFPS;
			}
			//SHOWFPS=SHOWFPS;
		}
		if(SHOWFPS==true)
			textprintf_ex(buffer,font,20,20,WHITE,0,"frames= :%d",frames_per_sec);

		if(key[KEY_H])
		{
			if(key_shifts & KB_CTRL_FLAG)
			{
				//switch the SHOWHEALTH flag to display the FPS
				SHOWHEALTH=!SHOWHEALTH;
			}
			//SHOWHEALTH=SHOWHEALTH;
		}
		
      
		//update the screen using a double buffering technique
		acquire_screen();

		blit(buffer,screen,0,0,0,0,WIDTH,HEIGHT);
		release_screen();
		
		//everytime we bilt from buffer to screen increase frames_done
		frames_done++;
    }
	
	//find the time that the game ended
	endTime = time(NULL);

		//kill the mutex (thread protection)
    pthread_mutex_destroy(&threadsafe);

	//call to create the final image to present to the user
 	create_close(buffer,dicot_22_font,owl);
	
	//Garbage Collection clean up all of the objects that are being used in memory
	remove_keyboard();
	remove_timer();
	
	//destory the bitmaps that we are using
	destroy_bitmap(buffer);
	destroy_bitmap(intro);

	//destroy the map
	MapFreeMem();

	//delete the sprites
	delete sprhandler;

	//call to allegro exit
	allegro_exit();
	return 0;

}//end of main
Exemple #16
0
void Set_Old_Int9(void){
   remove_keyboard();
   new_int=0;
}
Exemple #17
0
int main()
{	
	unsigned long usedchannel = RCSERVO_USECHANNEL0 +RCSERVO_USECHANNEL1 +RCSERVO_USECHANNEL2 +
		          RCSERVO_USECHANNEL4 +RCSERVO_USECHANNEL5 +RCSERVO_USECHANNEL6+
				  RCSERVO_USECHANNEL9 +RCSERVO_USECHANNEL10+RCSERVO_USECHANNEL11+
				  RCSERVO_USECHANNEL13+RCSERVO_USECHANNEL14+RCSERVO_USECHANNEL15+
				  RCSERVO_USECHANNEL16+RCSERVO_USECHANNEL17+RCSERVO_USECHANNEL18+
				  RCSERVO_USECHANNEL21+RCSERVO_USECHANNEL22+RCSERVO_USECHANNEL23; // for RB-100
		
	if(allegro_init())
	{
		printf("error:initialize allegro library failed!!\n");
		return -1;
	}
	if(install_keyboard())
	{
		printf("error:initialize keybaord failed!!\n");
		return -1;
	}
	roboio_SetRBVer(RB_100);
	
	if(rcservo_SetServos(usedchannel, RCSERVO_DMP_RS0263) == false)
	{
		printf("Set servo fails!%s\n",roboio_GetErrMsg());
		return -1;
	}
	if(rcservo_Initialize(usedchannel) == false)
	{
		printf("RC servo initialize fails!%s\n",roboio_GetErrMsg());
		return -1;
	}
	
	rcservo_SetFPS(500);
	rcservo_EnterPlayMode_NOFB(NORMAL);
	SetVal();
	PRE_STATE = STATE = BALANCE;
	ADJUST = 0.0;
	BODY_YAW = 0.0;
	BODY_PITCH = 0.0;
	BODY_ROLL = 0.0;
	POS_GAIN[0] = 0.0;
	POS_GAIN[1] = 0.0;
	POS_GAIN[2] = 0.0;
	Prepare();
	while(STATE != EXIT)
	{
		GetInput();
		switch(STATE)
		{
			case FORWARD:
			case BACKWARD:
			case RIGHTWARD:
			case LEFTWARD:
			case FLWARD:
			case FRWARD:
			case BLWARD:
			case BRWARD:
			case LCIRCLE:
			case RCIRCLE:
					PlayMotion();
				break;
		
			case IDLE:
					Idle();
				break;	
			case BALANCE:
					Stable();
				break;
			default:
				break;
		}
	}

	rcservo_Close();
	i2c_Close();
	remove_keyboard();
	
	return 0;
}
Exemple #18
0
void denit()
{
	remove_keyboard();
	remove_timer();
	allegro_exit();
}