Beispiel #1
0
void gController_keyboard_thread(void *data)
{
	int key_pressed;

	clear_keybuf();

	while((key_pressed = readkey())) {

		key_pressed = key_pressed >> 8;

		switch(key_pressed) {
			/* Movement event. */
			case KEY_UP:
			case KEY_RIGHT:
			case KEY_DOWN:
			case KEY_LEFT:
				gController_keyboard_move(key_pressed);
			break;

			case KEY_ESC:
				gController_keyboard_misc(key_pressed);
			break;

			default:
				error("No action registered to this key. Key %d", (key_pressed));
			break;
		}

		clear_keybuf();
		usleep(GCONTROLLER_KB_ACTION_INTERVAL_IN_USEC);
	}
}
Beispiel #2
0
/* let the user input a list of path nodes */
void input_nodes(void)
{
   clear_to_color(screen, makecol(255, 255, 255));

   textout_centre_ex(screen, font, "Click the left mouse button to add path "
		     "nodes", SCREEN_W/2, 8, palette_color[255],
		     palette_color[0]);
   textout_centre_ex(screen, font, "Right mouse button or any key to finish",
		     SCREEN_W/2, 24, palette_color[255], palette_color[0]);

   node_count = 1;

   show_mouse(screen);

   do {
      poll_mouse();
   } while (mouse_b);

   clear_keybuf();

   for (;;) {
      poll_mouse();

      if (mouse_b & 1) {
	 if (node_count < MAX_NODES-1) {
	    nodes[node_count].x = mouse_x;
	    nodes[node_count].y = mouse_y;

	    show_mouse(NULL);
	    draw_node(node_count);
	    show_mouse(screen);

	    node_count++;
	 }

	 do {
	    poll_mouse();
	 } while (mouse_b & 1);
      }

      if ((mouse_b & 2) || (keypressed())) {
	 if (node_count < 3)
	    alert("You must enter at least two nodes",
		  NULL, NULL, "OK", NULL, 13, 0);
	 else
	    break;
      }
   }

   show_mouse(NULL);

   do {
      poll_mouse();
   } while (mouse_b);

   clear_keybuf();
}
Beispiel #3
0
/*
There was going to be a nice fadeout effect using the allegro fade_out and
fade_in functions, but for some reason these screwed up the palette. Oh well.
*/
void end_game(int fade_speed)
{

// fade_out(fade_speed);


 rest(1000 / fade_speed);
 clear_keybuf();

 clear_bitmap(screen);
// set_palette(palet);
 init_palette();
 set_palette(palet);

 int challenge_winner = 0;

 if (arena[0].teams == 0)
  challenge_winner = score_table();
   else
    challenge_winner = score_table_team();

 if (arena[0].challenge_level != 0)
 {
  if (challenge_winner == 0)
  {
   switch(arena[0].challenge_level)
   {
    case 1: information_box("", "Norbert won?", "Hmm.", 0); break;
    case 2: information_box("", "Looks like you need some more practice.", "", 0); break;
    case 3: information_box("", "Sorry, you lose.", "", 0); break;
    case 4: information_box("", "Good, but not great.", "", 0); break;
    case 5: information_box("", "Oh well, better luck next time.", "", 0); break;
    case 6: information_box("", "Almost there. Try again.", "", 0); break;
    case 7: information_box("", "Very good, but not quite good enough.", "", 0); break;
   }
   end_challenge();
  }
 }

 if (arena[0].qstart != QSTART_NONE)
  end_qstart();

    //shutdown_network();

// fade_in(*palet, fade_speed);
// set_palette(*palet);
 do
 {

 } while (keypressed() == 0);

 clear_keybuf();

 //net_init();

}
Beispiel #4
0
void showAssignment()
{
     BITMAP *background = makeBitmap("Menu_Images/Instructions0.gif");

     draw_sprite(menuBuffer, background, 0, 0);
     blit(menuBuffer, screen, 0,0,0,0,1024,768);
		clear_keybuf();
		readkey();
		background = makeBitmap("Menu_Images/Instructions1.gif");
     draw_sprite(menuBuffer, background, 0, 0);
     blit(menuBuffer, screen, 0,0,0,0,1024,768);
		clear_keybuf();
		readkey();
}
Beispiel #5
0
void term_reinit(int wait)             /* fixup after running other progs */
{
   struct text_info dat;

   gppconio_init();
   gettextinfo(&dat);

   if (dat.screenheight != screen_h) {
      _set_screen_lines(screen_h);
      gettextinfo(&dat);
      screen_h = dat.screenheight;
      screen_w = dat.screenwidth;
      mouse_init();
   }

   set_bright_backgrounds();

   if (wait) {
      clear_keybuf();
      gch();
   }

   __djgpp_set_ctrl_c(0);
   setcbrk(0);
}
Beispiel #6
0
int NinmanGameGraph::DrawGameOptions() {

    int y = 220;
    DrawOptions(y);
    while (true) {
        clear_keybuf();
        readkey();
        if (key[KEY_DOWN]) {
            y = y + 55;
            {
                if (y > 330)
                    y = 220;
            }
        }
        if (key[KEY_UP]) {
            y = y - 55;
            {
                if (y < 220)
                    y = 330;
            }
        }
        if (key[KEY_ENTER]) {
            return y;
        }
        DrawOptions(y);
    }
}
Beispiel #7
0
int cin_num(char *lab, int x, int y, int col)
{
  clear_keybuf();
  char *st_edit = new char[101];
  st_edit[100] = char(NULL);
  char null_char = char(NULL);
  st_edit[0] = null_char;
  int st_pos = 0;
  while(!key[KEY_ENTER])
  {
    rectfill(screen,x,y,screen->w-1,y+10,BLACK);
    textprintf(screen,font,x,y,col,lab); textprintf(screen,font,x+text_length(font,lab),y,col,st_edit);
    st_edit[st_pos] = readkey() % 256;
    st_edit[st_pos+1] = null_char;
    if(!key[KEY_BACKSPACE]) st_pos++;
    else if(st_pos) {st_pos--; st_edit[st_pos] = null_char;}
    int char_num = int(st_edit[st_pos-1]);
    if((char_num < 48 || char_num > 57) && st_pos){st_pos--;st_edit[st_pos] = null_char;}
  }
  int ret_num = 0;
  for(int snum = 0; snum < st_pos; snum++)
    ret_num += int((int(st_edit[snum])-48) * pow(10,st_pos-snum-1));

  return ret_num;
}
Beispiel #8
0
int selecionarItemTeclado(OPCOES *menu, int *selected, int *keyCount)
{
	clear_keybuf();

	if (key[KEY_UP] && *keyCount == 0 && *selected != 0)
	{	
		*keyCount += 1;
		*selected -= 1;
	}	
	if (key[KEY_DOWN] && *keyCount == 0 && *selected < NUM_ITENS-1)
	{
		*keyCount += 1;
		*selected += 1;
	}
	
	if (!key[KEY_UP] && !key[KEY_DOWN])
		*keyCount = 0;
		
	if (key[KEY_ENTER])
	{
		return menu->itens[*selected].code;
	}
		
	return -1;
}
Beispiel #9
0
int main ()
{
    // initialize Allegro
    if (allegro_init () < 0)
    {
        allegro_message ("Error: Could not initialize Allegro");
        return -1;
    }
    // initialize gfx mode
    if (set_gfx_mode (GFX_AUTODETECT, 320, 200, 0, 0) < 0)
    {
        allegro_message ("Error: Could not set graphics mode");
        return -1;
    }
    // initialize keyboard
    install_keyboard ();
    clear_keybuf ();

    // call the example function
    test_mode_7 ();

    // exit Allegro
    allegro_exit ();

    return 0;

} END_OF_MAIN ();
Beispiel #10
0
//the final score screen
void CGame::ShowResults() {

	int i;
	int finalscore;
	WINDOWS_BITMAP *text;

	text = create_bitmap(220, 130);
	clear_to_color(text,makecol(255,0,255));
	

	scare_mouse();

	//background image
	blit((WINDOWS_BITMAP *)data[ZSCORE_BMP].dat, background,0,0,0,0,SCREEN_W,SCREEN_H);
	
	//print text on temp image and resize
	text_mode(-1);

	for (i=0;i<numplayers;i++) {
		
		finalscore = players[i].CalcFinalScore();
		textprintf_centre(text,font,110,(i*40),players[i].color,"%d - %s",finalscore,players[i].name);
	}
	
	masked_stretch_blit(text,background,0,0,220,130,210,190,390,250);

	blit(background,screen,0,0,0,0,SCREEN_W,SCREEN_H);

	clear_keybuf();
	readkey();

	destroy_bitmap(text);

}
Beispiel #11
0
// ==========================================================================
// MAIN loop
void interfac_user_handler(int start_ds1_idx)
{
    //int  ds1_idx;
    //
    int  done, cx, cy;
    int  old_mouse_x = mouse_x, old_mouse_y=mouse_y, old_mouse_b=0;
    int  cur_mouse_z = 0, old_mouse_z = 0;
    int  ticks_elapsed;


    // init
    ds1_idx               = start_ds1_idx;
    done                  = FALSE;


    // main loop

    clear_keybuf();



    while (! done) {

        my_set_fps();

        old_mouse_x = mouse_x;
        old_mouse_y = mouse_y;
        old_mouse_b = mouse_b;

        cur_mouse_z = mouse_z;

        mouse_to_tile(ds1_idx, &cx, &cy);

        if (cx < 0) { cx = 0; } else if (cx >= glb_ds1.width)  { cx = glb_ds1.width  - 1; }
        if (cy < 0) { cy = 0; } else if (cy >= glb_ds1.height) { cy = glb_ds1.height - 1; }

        // check if need to redraw the screen because of floor animation
        ticks_elapsed = glb_ds1edit.ticks_elapsed;
        if ( ticks_elapsed && (glb_ds1.animations_layer_mask == 1)) {
            // animated floor rate = 10 fps
            // therefore it's at 2/5 of 25 fps
            // but internal unit is in 5th
            glb_ds1.cur_anim_floor_frame += ticks_elapsed * 2;
        } else {
            glb_ds1edit.ticks_elapsed = 0;
        }

        // redraw the whole screen
        wpreview_draw_tiles(ds1_idx);
        glb_ds1edit.fps++;




        done = process_input();

    }
}
Beispiel #12
0
	void Abstract::doGuardFinalize()
	{
		if (pArea && pArea->background == gfx->glfond)
			pArea->background = 0;
		doFinalize();
		reset_keyboard();
		clear_keybuf();
		reset_mouse();
	}
Beispiel #13
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
}
Beispiel #14
0
/* handle the setup command */
static void setup_all_keys(void)
{
   int focus = 2;
   int i;

   /* Prepare dialog.  */
   set_dialog_color(keymap_dialog, black, white);
   centre_dialog(keymap_dialog);

   /* Parse input.  */
   while (1) {
      focus = do_dialog(keymap_dialog, focus);
      switch (focus) {
	 case 2:
	 case 4:

	    textprintf_centre_ex (screen, font,
	       keymap_dialog[7].x, keymap_dialog[7].y, red, -1,
	       "Press a key to map to the current scancode");
	    textprintf_centre_ex (screen, font,
	       keymap_dialog[7].x, keymap_dialog[7].y + 8, red, -1,
	       "(or a mouse button to leave it unchanged)");

	    /* Wait for new key press.  */
	    new_keycode = -1;
	    waiting_for_key = 1;

	    do {
	       poll_keyboard();
	       poll_mouse();

	       if (mouse_b)
		  waiting_for_key = 0;
	    }
	    while (waiting_for_key);

	    /* Save keycode to scancode mapping.  */
	    if ((new_keycode >= 0) && (new_keycode < 256)) {
	       keycode_to_scancode[new_keycode] = keymap_dialog[2].d1 + 1;
	    }

	    clear_keybuf();

	    break;
	 case 5:
	    return;
	 case 6:
	    for (i = 0; i < 256; i++) {
               if (keycode_to_scancode[i] >= 0)
		  _xwin.keycode_to_scancode[i] = keycode_to_scancode[i];
            }
	    return;
      }
   }
}
Beispiel #15
0
/***
* Cleanup and unloading
*/
void descarregar() {
	clear_keybuf();
	destroy_bitmap(fundo);
	destroy_bitmap(bomba);
	destroy_bitmap(coracao);
    
    for(int i =0;i<framesPersonagem;i++)
    {
	 delete personagem[i];
    }
	delete[] personagem;
}
Beispiel #16
0
/* handles double-clicking on a FLIC object in the grabber */
static int view_fli(DATAFILE *dat)
{
   show_mouse(NULL);
   clear_to_color(screen, gui_mg_color);
   play_memory_fli(dat->dat, screen, TRUE, fli_stopper);
   do {
   } while (mouse_b);
   clear_keybuf();
   set_pallete(datedit_current_palette);
   show_mouse(screen);
   return D_REDRAW;
}
Beispiel #17
0
void exit_sequence(Game* game){
    //check exit keypress
    if(key[KEY_ESC] || key[KEY_Q]){
        fprintf(fpLog, "Game paused.\n");
        stop_sample(game->bgMusic);
        //ensure exit
        textprintf_ex(screen, font, 5, 5,
                      makecol(255, 255, 255), -1,
                      "Press Q again to quit.");
        clear_keybuf();
        if(readkey() >> 8 == KEY_Q){
            game->running = false;
        }else{
Beispiel #18
0
	bool Abstract::doGuardInitialize()
	{
		pMouseX = -1;
		pMouseY = -1;
		pMouseZ = -1;
		pMouseB = -1;
		cursor_type = CURSOR_DEFAULT;
		reset_keyboard();
		reset_mouse();
		clear_keybuf();
		bool r = doInitialize();
		return r;
	}
Beispiel #19
0
KEYPRESS input_char()
{
   KEYPRESS c;

   /* all keyboard input should come through this function instead of
      calling gch() directly. This function normally just calls getc(),
      but will insert codes from the macro buffer instead if a macro is
      being executed */

   if (macro_mode == MACRO_FINISHED)
      macro_mode = 0;

   #if (defined TARGET_CURSES) || (defined TARGET_WIN)
      if (macro_mode)
	 nosleep = TRUE;
      else
	 nosleep = FALSE;
   #endif

   if (macro_mode == MACRO_PLAY) {
      c = macro[macro_pos++];
      if (macro_pos >= macro_size)
	 macro_mode = MACRO_FINISHED;
   }
   else {
      if (unget_count > 0) {
	 int l;
	 c.key = _unget[0];
	 c.flags = 0;
	 unget_count--;
	 for (l=0; l<unget_count; l++)
	    _unget[l] = _unget[l+1];
      }
      else {
	 c.key = gch();
	 c.flags = modifiers();
      }
   }

   if (macro_mode == MACRO_RECORD) {
      if (macro_size >= MACRO_LENGTH) {
	 macro_mode = 0;
	 clear_keybuf();
	 alert_box("Macro too long");
      }
      else
	 macro[macro_size++] = c;
   }

   return c;
}
//---------------------------------------------------------------------
void deinicia_allegro() {
	clear_keybuf();
	//salvando o arquivo de configuracao
	set_config_int("Inicializacao", "volume", volume);
	set_config_int("Inicializacao", "vsync", vSync);
	//fechando o allegro
    if (get_update_method())
    {
        shutdown_screen_updating();
    }
	allegro_exit();
	exit(0);
	/* adicione outras deiniciacoes aqui */
}
Beispiel #21
0
void startNew()
{
    clear_keybuf();
    readkey();
    clear_to_color( buffer, makecol( 0, 0, 0));
    ball_x = 320;
    ball_y = 240;

    p1_x = 20;
    p1_y = 210;

    p2_x = 620;
    p2_y = 210;
}    
Beispiel #22
0
void GameInit(void)
{

	allegro_init();
   	install_keyboard();
   	install_timer();
	install_mouse();
	clear_keybuf();

   	set_gfx_mode(GFX_AUTODETECT, 320, 240, 0, 0);
   	set_pallete(desktop_pallete);

	return;
}
Beispiel #23
0
void lerNomeRecorde(BITMAP *buffer, char result[NAME_LEN])
{
	int val, scancode, i;
	char name[NAME_LEN], ascii;
	
	memset(name, '\0', NAME_LEN);	
	strcpy(name, "None");
	i = strlen(name)-1;
	
	clear_keybuf();

	do
	{
		clear(buffer);
		textprintf_centre_ex(buffer, font, RES_X/2, RES_Y/2, makecol(255,255,255), -1, "Entre com o nome do recordista:");
		
		if (keypressed() && i < NAME_LEN)
		{
			val = readkey();
			ascii = val & 0xff;
			scancode = val >> 8;
			
			if (scancode == KEY_BACKSPACE)
			{
				if (i > 0) i--;
				name[i] = '\0';
				continue;
			}
						
			if (ascii >= 33 && ascii <= 126)
			{
				name[i] = ascii;
				i++;				
			}			
		}
		
		textprintf_centre_ex(buffer, font, RES_X/2, RES_Y/2+30, makecol(0,0,200), -1, "%s", name);

		if (i == 50)
		{
			textprintf_centre_ex(buffer, font, RES_X/2, RES_Y/2+60, makecol(255,0,0), -1, 
				"Limite de caracteres atingido!");
		}

		textprintf_centre_ex(buffer, font, RES_X/2, RES_Y/2+90, makecol(255,255,255), -1, "Pressione ENTER para concluir...");
		draw_sprite(screen, buffer, 0, 0);
		
		rest(10);
	} while (!key[KEY_ENTER]);
Beispiel #24
0
void set_hscore(int points)
{
    clear_keybuf();
    char name[10];
    FONT *fonte = (FONT*)fnt_datafile[COMICSANS].dat;
    rect(screen, SCREEN_W/3.23, SCREEN_H/2.13, SCREEN_W/1.46, SCREEN_H/1.89, WHITE); /// Draws the rectangle for the user input the name
    textout_ex(screen, fonte, "Your name: ", SCREEN_W/6.3, SCREEN_H/2.1, WHITE, -1);
    read_string(name, SCREEN_W/3, SCREEN_H/2, 10); /// get the player's name
    strcat(name, " "); ///Add some trash in the end of the name, so we can point it out later
    strcpy(score_table[10].player_name, name);
    score_table[10].player_score = points; /// Inserts the score in the last position of the SCORE_TABLE
    sort_scores(); /// Since we add another player in the last position of the score_table, we should sort it to get its proper position
    show_hscore_list(name); /// Show highscore list pointing out name
    return;
}
Beispiel #25
0
Datei: setup.c Projekt: rj76/kq
/*! \brief Process keypresses when mapping new keys
 *
 * This grabs whatever key is being pressed and returns it to the caller.
 * PH 20030527 Removed call to keypressed() and added poll_music()
 *
 * \returns the key being pressed, 0 if error (or cancel?)
 */
static int getakey (void)
{
   int a;

   clear_keybuf ();
   menubox (double_buffer, 108 + xofs, 108 + yofs, 11, 1, DARKBLUE);
   print_font (double_buffer, 116 + xofs, 116 + yofs, _("Press a key"), FNORMAL);
   blit2screen (xofs, yofs);

   while (1) {
      poll_music ();
      for (a = 0; a < KEY_MAX; a++)
         if (key[a] != 0)
            return a;
   }
   return 0;
}
Beispiel #26
0
int NinmanMenu::MainMenu() {
    int y = 220;
    while (true) {
        readkey();
        if (key[KEY_ESC])
            return 0;
        if (key[KEY_DOWN]) {
            y = y + 55;
            if (y > 440)
                y = 220;
        }
        if (key[KEY_UP]) {
            y = y - 55;
            if (y < 220)
                y = 440;
        }
        if (key[KEY_ENTER]) {
            if (y == 220) {
                std::string player;
                while (player == "")
                    player = TextBox();
                if (player != "-1")
                    NinmanGame(player.c_str());
            }
            if (y == 275) {
                Score();
                y = 220;
            }
            if (y == 330) {
                OptionMenu();
                y = 220;
            }
            if (y == 385) {
                About();
                y = 220;
            }

            if (y == 440)
                break;
            clear_keybuf();
        }
        DrawMenu(y);
    }
    return 0;
}
Beispiel #27
0
Hardware::Hardware()
:
    al_mouse_x_last(LEMSCR_X/2),
    al_mouse_y_last(LEMSCR_Y/2),
    mouse_own_x    (LEMSCR_X/2),
    mouse_own_y    (LEMSCR_Y/2),
    mickey_x(0),
    mickey_y(0)
{
    mouse_buffer[0]            = false;
    mouse_buffer[1]            = false;
    mouse_buffer[2]            = false;
    mouse_since [0]            = 0;
    mouse_since [1]            = 0;
    mouse_since [2]            = 0;
    key_from_buffer            = -1;
    key_from_buffer_ascii      = -1;
    clear_keybuf();
}
Beispiel #28
0
void SwapScreen::waitForKey(){
	BITMAP* textBuf;
	textBuf = create_bitmap(150,50);
	clear_to_color(textBuf,makecol(255,0,255));
	counter=255;
	flag=false;

	rest(20);
	clear_keybuf();
	  while (!keypressed()){
		textprintf_ex(textBuf,font,5,5, makecol(counter,counter,counter), -1, "<Press Any Key>");
		draw_sprite(screen,textBuf,160, SCREEN_H/2);
		setCounter();
	}
	rest(20);
	  
	destroy_bitmap(textBuf);

}
void IniciaGrafica(){
    if (allegro_init() != 0) return;
    install_keyboard();
    install_timer();

   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, VentanaX, VentanaY, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, VentanaX, VentanaY, 0, 0) != 0) {
     set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
     allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
     return;
      }
   }
    set_palette(desktop_palette);
    /* allocate the memory buffer */
    buffer = create_bitmap(SCREEN_W, SCREEN_H);
    clear_keybuf();

    divisionY = VentanaY/nCeldas_i;
    divisionX = VentanaX/nCeldas_j;
}
Beispiel #30
0
char *cin_str(char *lab, int x, int y, int col)
{
  clear_keybuf();
  char *st_edit = new char[101];
  st_edit[100] = char(NULL);
  char null_char = char(NULL);
  st_edit[0] = null_char;
  int st_pos = 0;
  while(!key[KEY_ENTER])
  {
    rectfill(screen,x,y,screen->w-1,y+10,BLACK);
    textprintf(screen,font,x,y,col,lab); textprintf(screen,font,x+text_length(font,lab),y,col,st_edit);
    st_edit[st_pos] = readkey() % 256;
    st_edit[st_pos+1] = null_char;
    if(!key[KEY_BACKSPACE]) st_pos++;
    else if(st_pos) {st_pos--; st_edit[st_pos] = null_char;}
  }
  st_pos--; st_edit[st_pos] = null_char;
  return st_edit;
}