Exemple #1
0
// waits for x millis or ESC
void esc_rest(int millis) {
	int clicks = millis / 20;
	int count = 0;
	while(count < clicks && !key[KEY_ESC]) {
		cycle_count = 0;
		poll_music();
		count ++;
		while(!cycle_count);
		yield_timeslice();
	}
    if (key[KEY_ESC]) script_done = -1;
}
Exemple #2
0
/* \brief Enter console mode
*
* Run the console. Does not return until the console
* is closed.
*/
void run_console(void) {
	int c;
	int sl;
	int running;
	g_console.inputline[0]='\0';
	g_console.on = 1;
	/* Wait for all keys up */
	while(keypressed()) {
		readkey();
	}
	running = 1;
	while (running == 1) {
		sl = strlen(g_console.inputline);
		/* Get a key */
		while (!keypressed()) {
			check_animation ();
			blit2screen (xofs, yofs);
			poll_music ();
			kq_yield();
		}			
		switch((c = readkey()) & 0xff) {
			case '\r': /* Return */
				if (sl == 0) {
					/* Stop when blank line is entered */
					running = 0;
					g_console.on = 0;
				}
				else {
					g_console.on = 0;
					scroll_console(g_console.inputline);
					do_console_command(g_console.inputline);
					g_console.inputline[0] = '\0';
					g_console.on = 1;
				}
				break;
			case 127: /* backspace */
				if (strlen(g_console.inputline) > 0)
					g_console.inputline[sl - 1] = '\0';
				break;
			default:
				if (strlen(g_console.inputline) < sizeof(g_console.inputline) - 1) {
					g_console.inputline[sl] = c & 0xff;
					g_console.inputline[sl + 1] = '\0';
				}
				break;
		}
	}
	/* Wait for enter key up */
	do {
		readcontrols();
	} while (benter);
}
Exemple #3
0
Fichier : setup.c Projet : 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;
}
Exemple #4
0
void cmd_run(Ttoken *t) {
	Tscript_object *o;
	int loops;
	static int i = 0;

	loops = atoi(t->word);

	cycle_count = 0;
	while(loops && !script_done) {

		while(cycle_count > 0 && loops && !script_done) {
			logic_count ++;

			poll_music();

			// update objects
			o = objects;
			while(o != NULL) {
				if (!o->line) {
					o->x += o->vx;
					o->y += o->vy;
				}
				o = (Tscript_object *) o->next;
			}

			if (key[KEY_ESC]) script_done = -1;

			i ++;
			loops --;
			cycle_count --;
		}

		// let other processes play
		yield_timeslice();

		// blit buffer to swap buffer
		blit(buffer, swap_buffer, 0, 0, 0, 0, 160, 120);
		
		// draw objects
		o = objects;
		while(o != NULL) {
			if (o->bmp[0] != NULL) {
				int frame = (o->frames ? logic_count % o->frames : 0);
				if (o->dir == 1)
					draw_sprite_h_flip(swap_buffer, o->bmp[frame], o->x, o->y);
				else if (o->dir == 0)
					draw_sprite(swap_buffer, o->bmp[frame], o->x, o->y);
				else // rotate
					rotate_sprite(swap_buffer, o->bmp[frame], o->x, o->y, itofix(-8*i));
			}
			else if (o->line) {
				line(swap_buffer, ((Tscript_object *)o->line_from)->x + o->x,
					((Tscript_object *)o->line_from)->y + o->y,
					((Tscript_object *)o->line_to)->x + o->vx,
					((Tscript_object *)o->line_to)->y + o->vy,
					1);
			}
			o = (Tscript_object *) o->next;
		}
		
		// blit to screen
		blit_to_screen(swap_buffer);
	}
	
}
Exemple #5
0
Fichier : combat.c Projet : rj76/kq
/*! \brief Really do combat once fighters have been inited
 *
 * \param   bg Background image
 * \param   mus Music
 * \param   is_rnd If !=0 then this is a random combat
 * \returns 1 if battle occurred
 */
static int do_combat (char *bg, char *mus, int is_rnd)
{
   int zoom_step;
   in_combat = 1;
   backart = load_datafile_object (PCX_DATAFILE, bg);
   if (is_rnd) {
      if ((numchrs == 1) && (pidx[0] == AYLA)) {
         hs = rand () % 100 + 1;
         ms = rand () % 3 + 1;
      } else {
         if (numchrs > 1 && (in_party (AYLA) > 0)) {
            hs = rand () % 20 + 1;
            ms = rand () % 5 + 1;
         } else {
            hs = rand () % 10 + 1;
            ms = rand () % 10 + 1;
         }
      }
   } else {
      hs = 10;
      ms = 10;
   }

   /*  RB: do the zoom at the beginning of the combat.  */
   pause_music ();
   set_music_volume ((gmvol / 250.0) * 0.75);
   play_music (mus, 0);
   if (stretch_view == 2) {
      do_transition (TRANS_FADE_OUT, 2);
      clear_bitmap (double_buffer);
      do_transition (TRANS_FADE_IN, 64);
   } else
      /* TT TODO:
       * Change this so when we zoom into the battle, it won't just zoom into the middle
       * of the screen.  Instead, it's going to zoom into the location where the player
       * is, so if he's on the side of the map somewhere...
       */
      for (zoom_step = 0; zoom_step < 9; zoom_step++) {
         poll_music ();

         /*  RB FIXME: stretching when 640x480, stretching when 320x240?  */
         /*            shouldn't one of those be the "common" size, and   */
         /*            therefore not needing to stretch it?               */
         /*            320x240 is the double_buffer size...               */
         if (stretch_view == 1)
            stretch_blit (double_buffer, screen, zoom_step * 16 + xofs,
                          zoom_step * 12 + yofs, 320 - (zoom_step * 32),
                          240 - (zoom_step * 24), 0, 0, 640, 480);

         else
            stretch_blit (double_buffer, screen, zoom_step * 16 + xofs,
                          zoom_step * 12 + yofs, 320 - (zoom_step * 32),
                          240 - (zoom_step * 24), 0, 0, 320, 240);

         /*  RB FIXME: should we vsync here rather than rest?  */
         kq_wait (100);
      }
   snap_togrid ();
   roll_initiative ();
   curx = 0;
   cury = 0;
   vspell = 0;
   combatend = 0;

   /*  RB: execute combat  */
   do_round ();
   unload_datafile_object (backart);
   set_music_volume (gmvol / 250.0);
   resume_music ();
   if (alldead)
      stop_music ();
   steps = 0;
   in_combat = 0;
   timer_count = 0;
   return (1);
}