예제 #1
0
파일: gtext.c 프로젝트: cravo/damp
void gtext_render(void)
{
   char tempstr[64];          /* temp variable */
   int n;                     /* loop counter */


   /* clear the buffer */
   clear(damp_gfx_buffer);


   /* display volume */
   textout(damp_gfx_buffer,font,"Volume:",0,30,makecol(255,255,0));
   sprintf(tempstr,"%d",damp_volume);
   textout(damp_gfx_buffer,font,tempstr,text_length(font,"Volume:"),30,makecol(128,128,128));

   /* display track time */
   textout(damp_gfx_buffer,font,"Time:",160,30,makecol(255,255,0));
   sprintf(tempstr,"%s",damp_display_time_remaining ? timeremainstr : timestr);
   textout(damp_gfx_buffer,font,tempstr,160+text_length(font,"Time:"),30,makecol(128,128,128));

   /* display status */
   textout(damp_gfx_buffer,font,"================ STATUS ================", 0, 50, makecol(255,128,64));
   textout(damp_gfx_buffer,font,"Surround",30,60,audio_driver->surround ? makecol(255,255,0) : makecol(64,64,64));
   textout(damp_gfx_buffer,font,"Continuous",30+text_length(font,"Surround   "),60,damp_playlist_continuous ? makecol(255,255,0) : makecol(64,64,64));
   textout(damp_gfx_buffer,font,"Random",30+text_length(font,"Surround   Continuous   "),60,damp_playlist_random ? makecol(255,255,0) : makecol(64,64,64));

   /* display scrolling track name */
   textout(damp_gfx_buffer,font,"============== NOW PLAYING =============", 0, 80, makecol(255,128,64));
   textout(damp_gfx_buffer,font,&damp_gfx_scroll_name[damp_gfx_scroll_name_pos],0,90,makecol(255,255,255));
   if(track_sel_pos > 0)
      textout_centre(damp_gfx_buffer,font,track_sel,160,100,makecol(255,255,255));

   /* display vu */
   if(damp_want_scope)
   {
      textout(damp_gfx_buffer,font,"VU-meter:",0,110,makecol(255,255,0));
      for(n=0;n<32;n++)
         textout(damp_gfx_buffer,font,n==gtext_vu_max/2 ? "I" : (n<damp_vu/2 ? "=" : "-"),n*10,120,(n < damp_vu/2) ? (n<16 ? makecol(0,255,0) : (n<24 ? makecol(255,255,0) : makecol(255,0,0))) : makecol(128,128,128));
   }

   /* display "advert" :-) */
   textout_centre(damp_gfx_buffer,font,"DAMP",160,140,makecol(255,0,0));
   textout_centre(damp_gfx_buffer,font,"Copyright 1999/2000 Hedgehog Software",160,150,makecol(255,0,0));
   textout_centre(damp_gfx_buffer,font,"http://www.damp-mp3.co.uk/",160,160,makecol(255,0,0));

   /* display it all */
   if(!damp_using_gui)
      blit(damp_gfx_buffer,screen,0,0,0,0,DAMP_GFX_SCREEN_WIDTH,DAMP_GFX_SCREEN_HEIGHT);
}
예제 #2
0
void initialise_screen() {

   if (have_allegro_window) {
      set_gfx_mode(GFX_SAFE, 320, 200, 0, 0);
      set_palette(desktop_palette);

      acquire_screen();
      textout_centre(screen, font, "Type Here!!",
		     SCREEN_W/2, SCREEN_H/2-60, 255);
      textout(screen, font, "Ctrl-M: switch between comm ports",
	      0, SCREEN_H/2-32, 255);
      textout(screen, font, "Ctrl-B: send a half second break signal",
	      0, SCREEN_H/2-16, 255);
      textout(screen, font, "Ctrl-C: quit", 0, SCREEN_H/2, 255);
      textout(screen, font, "Other key presses sent to current port.",
	      0, SCREEN_H/2+16, 255);
      textout(screen, font, "Current port:", 0, SCREEN_H/2+40, 255);
      textout(screen, font, cur_port->szName,
	      SCREEN_W/2, SCREEN_H/2+40, 255);
      release_screen();
   }
   else {
      printf("Ctrl-M: switch between comm ports\n");
      printf("Ctrl-B: send a half second break signal\n");
      printf("Ctrl-C: quit\n");
      printf("Other key presses sent to current port.\n");
      printf("\nCurrent port: %s\n\n", cur_port->szName);
   }
}
예제 #3
0
void CGame::DrawPlayer() {
	
	// draw players name and tile rack and temp tile rack
	// and buttons to do stuff
	// all color coded
	
	int i; //used to calculate rack position offset when drawing sprite
	CObject *object; //object pointer
	POSITION pos; //CObList position
	CTile *tile; //tile pointer

	//boarder around board
	rect(background,0,0,570,570,players[currplayer].color);
	
	//player hud
	rect(background,570,101,SCREEN_W-1,SCREEN_H-1,players[currplayer].color);
	
	//player name ("rub out" old one. cheap and nasty style)
	textout_centre(background,font,"Current player is:",685,105,players[currplayer].color);
	textout(background,font,".                          .",571,125,players[currplayer].color);
	textprintf_centre(background,font,685,125,players[currplayer].color,"%s",players[currplayer].name);
	
	//rack 1
	rectfill(background,580,150,790,180,players[currplayer].color);
	//rack2
	rectfill(background,580,210,790,240,players[currplayer].color);

	// render rack1 tiles
	i = 1;
	if (!players[currplayer].rack.IsEmpty()) {
		for( pos = players[currplayer].rack.GetHeadPosition(); pos != NULL; i++) {	

			object = players[currplayer].rack.GetNext(pos);
			tile = (CTile *)object;

			draw_sprite(background, smalltiles[tile->GetIndex()], (551+(i*30)),151);
		}
	}

	//render rack2 tiles
	i = 1;
	if (!players[currplayer].tmprack.IsEmpty()) {
		for( pos = players[currplayer].tmprack.GetHeadPosition(); pos != NULL; i++) {	
		
			object = players[currplayer].tmprack.GetNext(pos);
			tile = (CTile *)object;
		
			draw_sprite(background, smalltiles[tile->GetIndex()], (551+(i*30)),211);
		}

	}

	//draw buttons + spam banner :)
	draw_sprite(background, (WINDOWS_BITMAP *)data[ZRESET_BMP].dat, 580,260);
	draw_sprite(background, (WINDOWS_BITMAP *)data[ZSWAP_BMP].dat, 690,260);
	draw_sprite(background, (WINDOWS_BITMAP *)data[ZSPAM_BMP].dat, 571,310);	
	draw_sprite(background, (WINDOWS_BITMAP *)data[ZDONE_BMP].dat, 635,530);

}
예제 #4
0
	static int loop_callback(void *data)
	{
		(void)data;
		if (gfx_half_width) {
			acquire_screen();
			textout_centre(screen, font, "Music has looped.", gfx_half_width, 36, 10);
			release_screen();
		}
		return 0;
	}
예제 #5
0
파일: aphoton.c 프로젝트: Fomka/ufo2000
int d_aphoton_window_proc(int msg, DIALOG *d, int c)
{
    int rtm, cl, ct, cr, cb;
    (void)c;

    if (msg == MSG_DRAW) {
	rect(screen, d->x, d->y, d->x+d->w-1, d->y+d->h-1, black);
	rect(screen, d->x+1, d->y+1, d->x+d->w-2, d->y+d->h-2, window_black);
	
	/* gray frame */
	vline(screen, d->x+2, d->y+2, d->y+d->h-3, white);
	hline(screen, d->x+2, d->y+d->h-3, d->x+d->w-3, window_gray);
	vline(screen, d->x+d->w-3, d->y+2, d->y+d->h-3, window_gray);
	
	vline(screen, d->x+3, d->y+3, d->y+d->h-4, menu_gray_to);
	hline(screen, d->x+3, d->y+d->h-4, d->x+d->w-4, menu_gray_to);
	vline(screen, d->x+d->w-4, d->y+3, d->y+d->h-4, menu_gray_to);
	
	vline(screen, d->x+4, d->y+4, d->y+d->h-5, window_gray);
	hline(screen, d->x+4, d->y+d->h-5, d->x+d->w-5, white);
	vline(screen, d->x+d->w-5, d->y+4, d->y+d->h-5, white);

	/* blue frame */
	hline(screen, d->x+2, d->y+2, d->x+d->w-3, window_blue1);
	hline(screen, d->x+2, d->y+3, d->x+d->w-3, window_blue2);
	hline(screen, d->x+2, d->y+4, d->x+d->w-3, window_blue3);
	hline(screen, d->x+2, d->y+5, d->x+d->w-3, window_blue2);
	
	rectgouraud(screen, d->x+2, d->y+6, d->x+d->w-3, d->y+19, &window_blue_range, FALSE);
	hline(screen, d->x+2, d->y+20, d->x+d->w-3, window_blue3);
	
	vline(screen, d->x+2, d->y+6, d->y+20, window_blue1);
	vline(screen, d->x+d->w-3, d->y+6, d->y+20, window_blue3);
	
	/* background */
	rectfill(screen, d->x+5, d->y+21, d->x+d->w-6, d->y+d->h-6, normal);

	if (d->dp) {
	    rtm = text_mode(-1);
	    cl = screen->cl;
	    ct = screen->ct;
	    cr = screen->cr;
	    cb = screen->cb;
	    
	    set_clip(screen, d->x, d->y, d->x+d->w-1, d->y+d->h-1);
	    
	    textout_centre(screen, font, (char *)d->dp, d->x+d->w/2, d->y+8, black);

	    set_clip(screen, cl, ct, cr, cb);
	    text_mode(rtm);
	}
    }

    return D_O_K;
}
예제 #6
0
	static int xm_speed_zero_callback(void *data)
	{
		(void)data;
		if (gfx_half_width) {
			text_mode(0); /* In case this is overwriting "Music has looped." */
			acquire_screen();
			textout_centre(screen, font, "Music has stopped.", gfx_half_width, 36, 10);
			release_screen();
		}
		return 0;
	}
예제 #7
0
//play intro movie etc
void CGame::PlayIntro() {   
	
	//play FLC from memory
	play_memory_fli(data[ZANIMATION].dat,screen, 0, NULL);

	// display flashing prompt

	text_mode(-1); //text with transparent background

	//crude by effective blinking text :)
	while (!keypressed()) {
		
		textout_centre(screen,font,"INSERT COIN(S)..",320,400,makecol(0,0,0));
		rest(600);
		textout_centre(screen,font,"INSERT COIN(S)..",320,400,makecol(206,206,90)); 
		rest(300);
	}

	clear_keybuf();
	
}
예제 #8
0
파일: twgui.cpp 프로젝트: argarak/tw-light
void TextButton::subanimate()
{
	STACKTRACE;
	int xcentre, ycentre;

	xcentre = iround(size.x / 2);
	ycentre = iround(size.y / 2 - text_height(usefont)/2);

	text_mode(-1);
	if (text)
		textout_centre(drawarea, usefont, text, xcentre, ycentre, text_color);
}
/* creates a new bitmap object */
static void *makenew_jpeg(long *size)
{
	BITMAP *bmp = create_bitmap_ex(8, 32, 32);
	int buffer_size = 32 * 32 * 3;
	char *buffer = (char *)_al_malloc(buffer_size);

	clear_bitmap(bmp);
#if (ALLEGRO_VERSION >= 4 && ALLEGRO_SUB_VERSION >= 1 && ALLEGRO_WIP_VERSION >= 4)
	textout_centre_ex(bmp, font, "JPG", 16, 12, 1, -1);
#else
	text_mode(-1);
	textout_centre(bmp, font, "JPG", 16, 12, 1);
#endif
	save_memory_jpg(buffer, &buffer_size, bmp, NULL);
	destroy_bitmap(bmp);

	*size = buffer_size;

	return buffer;
}
예제 #10
0
int title_page() {
	BITMAP *  title     = (BITMAP *)gData[TITLE].dat;
	BITMAP *  avalanche = (BITMAP *)gData[AVALANCHE].dat;
	int highlight = 0;
	int choice    = -1;
	int k;

	clear_keybuf();

	while (choice == -1) {
		// redraw the titlepage
		clear(gBuff);
		blit(title,     gBuff, 0, 0, (SCREEN_W - title->w)/2,     10, title->w, title->h);
		blit(avalanche, gBuff, 0, 0, (SCREEN_W - avalanche->w)/2, 10 + title->h + 10, avalanche->w, avalanche->h);

		textout(gBuff, (FONT *)gData[FONT_NORM].dat, "1 Player Game", 120, 120, 15);
		textout(gBuff, (FONT *)gData[FONT_NORM].dat, "2 Player Game", 120, 130, 15);
		textout(gBuff, (FONT *)gData[FONT_NORM].dat, "Options",       120, 140, 8);
		textout(gBuff, (FONT *)gData[FONT_NORM].dat, "Exit",          120, 150, 15);

		textout(gBuff, (FONT *)gData[FONT_NORM].dat, "@", 110, 120 + highlight*10 - 1, 39);

		textout_centre(gBuff, (FONT *)gData[FONT_NORM].dat, TETRIS_VERSION " " AUTHOR ", " DATES, SCREEN_W/2, SCREEN_H - 10, 15);

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

		// accept input
		k = readkey() >> 8;

		if ((k == KEY_UP) && (highlight > 0))
			--highlight;

		if ((k == KEY_DOWN) && (highlight < 3))
			++highlight;

		if (k == KEY_ENTER)
			choice = highlight;
	}

	return choice;
}
예제 #11
0
파일: aase.c 프로젝트: Fomka/ufo2000
int d_aase_window_proc(int msg, DIALOG *d, int c)
{
  (void)c;

  if (msg == MSG_DRAW) {
    ase_rectbox(screen, d->x, d->y, d->x+d->w-1, d->y+d->h-1, d->flags);

    if (d->dp) {
      int rtm = text_mode(-1);
      int cl = screen->cl, ct = screen->ct, cr = screen->cr, cb = screen->cb;
      set_clip(screen, d->x, d->y, d->x+d->w-1, d->y+d->h-1);

      textout_centre(screen, font, (char *)d->dp, d->x+d->w/2, d->y+4, makecol(0, 0, 0));

      set_clip(screen, cl, ct, cr, cb);
      text_mode(rtm);
    }
  }

  return D_O_K;
}
예제 #12
0
파일: pacman.c 프로젝트: neiderm/turaco
void Maped_Info_PacMan(int mode)
{
#if 0
    char text[80];
    int max;
#ifdef SNOOP_ENABLE
    struct ROMDATA * rd = Driver.RomData;
#endif

    sprintf(text, "Size %04x", Maped_TotalMap_PacMan());
    if (Maped_TotalMap_PacMan() > 0x17d)
	textout(screen, font, text, SCREEN_W - 90, 40, PAL_RED);
    else
	textout(screen, font, text, SCREEN_W - 90, 40, PAL_GREEN);

    max = Driver.RomData->MapData[mapno].OverlayCount;
    sprintf(text, "#p %3d/%3d", Maped_TotalOverlay_PacMan(), max);

    if (Maped_TotalOverlay_PacMan() != max)
	textout(screen, font, text, SCREEN_W - 90, 50, PAL_RED);
    else
	textout(screen, font, text, SCREEN_W - 90, 50, PAL_GREEN);

#ifdef SNOOP_ENABLE
    sprintf(text, "O %08lx", snoop_offset);
    textout(screen, font, text, SCREEN_W - 90, 60, PAL_GREY);

    sprintf(text, "T %08lx", snoop_offset + rd->MapData[mapno].StartAddress);
    textout(screen, font, text, SCREEN_W - 90, 70, PAL_GREY);
#endif

    if (mode == MODE_EDIT)
	textout(screen, font, "M: Map Edit", SCREEN_W - 90, 95, PAL_YELLOW);
    else
	textout(screen, font, "M: Tile Sel", SCREEN_W - 90, 95, PAL_GREEN);

    sprintf(text, " 0x%02x ", GetTileUnderCursor());
    textout_centre(screen, font, text, SCREEN_W - 45, 105, PAL_LTGREY);
#endif
}
예제 #13
0
void key_check() {
	// check for general key presses

	//PALETTE pal;  // for screen capture

	while (key[KEY_PAUSE])
		textout_centre(screen, (FONT *)gData[FONT_TINY].dat, "PAUSED", SCREEN_W/2, (SCREEN_H - 8)/2, 15);

	/*
	// SCREEN CAPTURE
	if (key[KEY_F12])
	  {
	   get_palette(pal);
	   save_bitmap("scrnshot.pcx", gBuff, pal);

	   textout_centre(screen, (FONT *)gData[FONT_TINY].dat, "Screen captured. Press the spacebar to continue...",
	                  SCREEN_W/2, SCREEN_H/2 - 4, 15);

	   do { } while (!key[KEY_SPACE]);
	  }
	*/
}
void Draw(int cycles, int currtour, int besttour) {

	/////////////////////////////////////////////////////////////////////////////////////////////
	// draw a graph (drawing towns and paths is too hard with the current system of random distances)
	// is graph of tour length at each step as well as the current best tour length
	//
	// One important thing with draw() is that it takes the current and best tour lengths and divides them
	// by the number of towns.. this is so that no matter how many towns there are, it wont draw off the screen
	// unless the MAX_DISTANCE is set over 500
	//
	/////////////////////////////////////////////////////////////////////////////////////////////
	acquire_screen();
	
	//graph axis
	vline(screen, 40, 40, SCREEN_H-40, makecol(255,255,255));
	hline(screen, 40, 440, SCREEN_W-40, makecol(255,255,255));
	
	//graph axis text
	textout_centre(screen,font,"CYCLES",SCREEN_W/2, SCREEN_H-20,makecol(0,200,200));
	textout(screen,font,"DISTANCE",1, SCREEN_H/2,makecol(0,200,200));

	//graph legend
	rectfill(screen, SCREEN_W-200, 20, SCREEN_W-170, 40, makecol(0,200,200));
	textprintf(screen,font,SCREEN_W-160, 30,makecol(255,255,255),"Current Tour");
	rectfill(screen, SCREEN_W-200, 50, SCREEN_W-170, 70, makecol(255,0,0));
	textprintf(screen,font,SCREEN_W-160, 60,makecol(255,255,255),"Best Tour");
	
	//draw current cycles distance
	vline(screen,cycles+41,SCREEN_H-40,(SCREEN_H-40)-(currtour/NUM_TOWNS),makecol(0,200,200));
	vline(screen,cycles+41,SCREEN_H-40,(SCREEN_H-40)-(besttour/NUM_TOWNS),makecol(255,0,0));
	

	release_screen();

	
}
예제 #15
0
파일: fedup.c 프로젝트: 10crimes/code
void main(void) {
  
  int xy,i,c,x,y,front,back,n,minc,maxc;
  float dzdx,dzdy,a,b,dot,norm,tmp;
  long p,q;
  RGB rgb;
  long starttime;
  int numframes;
  
  // srand(456789);
  srand((int)time(NULL));
  // printf("%d\n",(int)time(NULL));
  
  
  mytime=10;
  maxc=0; minc=255;
  
  
  // Set up ripples
  numripples=3;
  for (i=0; i<numripples; i++) {
    newripple(i);
  }

  Map2d<int> dzdxmap=Map2d<int>(scrwid,scrhei);
  Map2d<int> dzdymap=Map2d<int>(scrwid,scrhei);  
  
  allegro_init ();
  install_keyboard ();
  install_timer ();
  set_gfx_mode (GFX_AUTODETECT, scrwid, scrhei, 0, 0);
  set_pallete (desktop_palette);
  buffer = create_bitmap (scrwid, scrhei);
  clear (buffer);
  
  // Set up grayscale colours
  for (c=0;c<=255;c++) {
    i=0;
    rgb.r=c*63/255;
    rgb.g=0;
    rgb.b=0;
    set_color(c,&rgb);
    // colors[c]=GrAllocColor(c,i,i);
  }
  
  PALLETE my_pallete;
  BITMAP *scr_buffer;
  scr_buffer = load_bitmap("paulcld.pcx",my_pallete);
  set_pallete (my_pallete);
  blit (scr_buffer, screen, 0,0,0,0,320,200);

  
  // circlefill (buffer, x, y, 3, 255);
  textout_centre (buffer, font, "Press SPACE!", 60, 220, 4);
  
  blit (buffer, screen, 0, 0, 0, 0, scrwid, scrhei);
  
  starttime=uclock();
  numframes=0;
  while(!key[KEY_ESC]) {
    for (x=0; x<scrwid; x=x+jump) {
      for (y=0; y<scrhei; y=y+jump) {
        dzdx=0;
        dzdy=0;
        for (i=0;i<numripples;i++) {
          ripples[i].front=ripples[i].v*(mytime-ripples[i].st);
          ripples[i].back=ripples[i].v*(mytime-ripples[i].st)-ripples[i].w;
          if (ripples[i].back>scrwid)
            newripple(i);
        }
        for (i=0;i<numripples;i++) {
          xy=(sqrt((x-ripples[i].x)*(x-ripples[i].x)+(y-ripples[i].y)*(y-ripples[i].y)));
          // printf("xy%i",xy);
          // printf("x%i",x);
          // printf("y%i",y);
          // printf("rx%i",ripples[i].x);
          // printf("ry%i",ripples[i].y);
          // printf("f%i\n",front);
          // printf("b%i\n",back);
          if ((xy>2)&&(xy<ripples[i].front)&&(xy>ripples[i].back)) {
            // printf("*********");
            a=pi/ripples[i].w*sin(2*pi*ripples[i].n/ripples[i].w*(xy-ripples[i].v*(mytime-ripples[i].st)));
            // printf("a%f",a);
            b=(float)10.0/mysquare(xy+1);
            // printf("b%f",b);
            // norm=1500/(mysquare(xy))*(exp(3*(xy-(ripples[i].v)*((mytime-ripples[i].st)))/ripples[i].w));
            norm=2.0*(xy-ripples[i].back)/(ripples[i].front-ripples[i].back);
            // printf("n%f",norm);
            dzdx=dzdx+a*b*(x-ripples[i].x)*ripples[i].w*norm;
            dzdy=dzdy+a*b*(y-ripples[i].y)*ripples[i].w*norm;
          }
        }

        // dot=dzdx*lx+dzdy*ly;
        // dot=dot*(dzdx*0.8+dzdy*0.6);
        // dot=dzdx*0.8+dzdy*0.6;
//        dot=dzdx * 1 * 0.8 + dzdy * 1 * 0.6;
//        float f=mymod(0.5+dot*0.5*scale);

        dzdxmap.pos[x][y]=refract*dzdx;
        dzdymap.pos[x][y]=refract*dzdy;

        if (x>0 && y>0) {
          int nwdx=dzdxmap.pos[x-jump][y-jump];
          int nedx=dzdxmap.pos[x][y-jump];
          int swdx=dzdxmap.pos[x-jump][y];
          int sedx=dzdxmap.pos[x][y];
          int nwdy=dzdymap.pos[x-jump][y-jump];
          int nedy=dzdymap.pos[x][y-jump];
          int swdy=dzdymap.pos[x-jump][y];
          int sedy=dzdymap.pos[x][y];
          for (int i=0;i<jump;i++)
            for (int j=0;j<jump;j++) {
              float a=(float)i/(float)jump;
              float d=(float)j/(float)jump;
              int idzdx=(1.0-a)*(1.0-d)*nwdx+(a)*(1.0-d)*nedx+(1.0-a)*(d)*swdx+(a)*(d)*sedx;
              int idzdy=(1.0-a)*(1.0-d)*nwdy+(a)*(1.0-d)*nedy+(1.0-a)*(d)*swdy+(a)*(d)*sedy;
              int rx=x-jump+i+idzdx;
              int ry=y-jump+j+idzdy;
              if (rx>=0 && ry>=0 && rx<scrwid && ry<scrhei)
                c=getpixel(scr_buffer,rx,ry);
              else
                c=0;
//              c=ucharchop(8*sqrt(idzdx*idzdx+idzdy*idzdy));
              putpixel(buffer,x-jump+i,y-jump+j,c);
            }
        
        }
        // GrFilledBox(x,y,x+jump-1,y+jump-1,colors[c]);
      }
    }
    /* for (i=0;i<numripples;i++) {
         mycircle(ripples[i].x,ripples[i].y,ripples[i].front,colors[0]);
         mycircle(ripples[i].x,ripples[i].y,ripples[i].back,colors[0]);
       }*/
    blit (buffer, screen, 0, 0, 0, 0, scrwid, scrhei);
    mytime=mytime+2;
    numframes++;
//    save_bitmap(getnextfilename("bmp"),buffer,my_pallete);
  }
  destroy_bitmap(buffer);
  allegro_exit();
  printf("%d frames per second.\n",UCLOCKS_PER_SEC*numframes/(uclock()-starttime));
  printf("max col %d\n",maxc);
  printf("min col %d\n",minc);
  
}
예제 #16
0
int main()
{
  initializeCrap();
  install_int_ex(increment_speed_counter,BPS_TO_TIMER(120));
  int screenMode = 0; //0 for windowed, 1 for fullscreen
  srand((unsigned)time(NULL));

  BITMAP *buffer = create_bitmap(800,600);
  BITMAP *titleimg = load_bitmap("quiximgTitle.bmp",NULL);
  BITMAP *imgPlayers = load_bitmap("quiximgPlayerSet.bmp",NULL);
  MIDI *song = load_midi("quixsong.mid");
  PlayerObject poPlayer[4];
  LaserObject loLaser[4];
  LevelObject Level;
  MenuObject Menu;
  float scrollerX = -150.0, scrollerY = 5.0;
  int winner;

  poPlayer[0].setControlScheme(0);
  poPlayer[1].setControlScheme(1);
  poPlayer[2].setControlScheme(2);
  poPlayer[3].setControlScheme(3);
  poPlayer[0].samSound = load_sample("quixp1Death.wav");
  poPlayer[1].samSound = load_sample("quixp2Death.wav");
  poPlayer[2].samSound = load_sample("quixp3Death.wav");
  poPlayer[3].samSound = load_sample("quixp4Death.wav");
  poPlayer[0].setX(32);
  poPlayer[0].setY(32);
  poPlayer[0].setDir('l');
  poPlayer[1].setX(32);
  poPlayer[1].setY(544);
  poPlayer[1].setDir('l');
  poPlayer[2].setX(736);
  poPlayer[2].setY(544);
  poPlayer[2].setDir('r');
  poPlayer[3].setX(736);
  poPlayer[3].setY(32);
  poPlayer[3].setDir('r');

  int mouseDown[21];    //Kind of a crappy array --- Each button is a #
                        //and it's set to true if that button was clicked.
  for (int i = 0; i < 20; i++) { mouseDown[i] = false; }

  while ( !Menu.isDone() )
  {
    while (speed_counter > 0)
    {
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~~~~~~~~~~~~~~~~~ MENU SCREEN ~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      if ( Menu.getEnabled() == true ) {
        if (key[KEY_Z]) {
          if (Menu.getFullscreen() == true) { Menu.changeScreenSize(0); Menu.setFullscreen(false); }
          else { Menu.changeScreenSize(1); Menu.setFullscreen(true); }
        }

        if (mouse_b & 1)
        {
          mouseDownClick(&Menu, mouseDown);
        }
        else {
          mouseUp(&Menu, mouseDown, poPlayer, &Level, song);
        }
      }
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~~~~~~~~~~~~~~~~~~~ IN-GAME ~~~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      else {

        //Player Input1
        if (key[KEY_ESC]) {
            play_midi(NULL, false);
          if (Menu.fragLimitHit == true) {
            Menu.fragLimitHit == false;

            for (int i=0; i<4; i++) {
              poPlayer[i].resetScore();
              poPlayer[i].resetDeaths();
            }

            poPlayer[0].setX(32);
            poPlayer[0].setY(32);
            poPlayer[0].setDir('l');
            poPlayer[1].setX(32);
            poPlayer[1].setY(544);
            poPlayer[1].setDir('l');
            poPlayer[2].setX(736);
            poPlayer[2].setY(544);
            poPlayer[2].setDir('r');
            poPlayer[3].setX(736);
            poPlayer[3].setY(32);
            poPlayer[3].setDir('r');

            Menu.fragLimitHit = false;

            Menu.resetPressed = false;
            mouseDown[19] = false;

          }
          Level.setEnabled(false); Menu.setEnabled(true);
        }
        for (int i=0; i<4; i++) {
          if (poPlayer[i].getControlScheme() == 0) {
            if (key[KEY_W]) { moveCharacter(Level, &poPlayer[i], i, 'u'); }
            if (key[KEY_A]) { moveCharacter(Level, &poPlayer[i], i, 'l'); }
            if (key[KEY_S]) { moveCharacter(Level, &poPlayer[i], i, 'd'); }
            if (key[KEY_D]) { moveCharacter(Level, &poPlayer[i], i, 'r'); }
            if (key[KEY_F]) {
              if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); }
            }
          }
          else if (poPlayer[i].getControlScheme() == 1) {
            if (key[KEY_I]) { moveCharacter(Level, &poPlayer[i], i, 'u'); }
            if (key[KEY_J]) { moveCharacter(Level, &poPlayer[i], i, 'l'); }
            if (key[KEY_K]) { moveCharacter(Level, &poPlayer[i], i, 'd'); }
            if (key[KEY_L]) { moveCharacter(Level, &poPlayer[i], i, 'r'); }
            if (key[KEY_H]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if (poPlayer[i].getControlScheme() == 2) {
            if (key[KEY_UP]) { moveCharacter(Level, &poPlayer[i], i, 'u'); }
            if (key[KEY_LEFT]) { moveCharacter(Level, &poPlayer[i], i, 'l'); }
            if (key[KEY_DOWN]) { moveCharacter(Level, &poPlayer[i], i, 'd'); }
            if (key[KEY_RIGHT]) { moveCharacter(Level, &poPlayer[i], i, 'r'); }
            if (key[KEY_RCONTROL]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if (poPlayer[i].getControlScheme() == 3) {
            if (key[KEY_8_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'u'); }
            if (key[KEY_4_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'l'); }
            if (key[KEY_2_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'd'); }
            if (key[KEY_6_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'r'); }
            if (key[KEY_PLUS_PAD]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if(poPlayer[i].getControlScheme() == 4) {
            //Joystick #1
            poll_joystick();
            if (joy[0].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up
            if (joy[0].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left
            if (joy[0].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down
            if (joy[0].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right
            if (joy[0].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if(poPlayer[i].getControlScheme() == 5) {
            //Joystick #2
            poll_joystick();
            if (joy[1].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up
            if (joy[1].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left
            if (joy[1].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down
            if (joy[1].stick[0].axis[0].d2) {moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right
            if (joy[1].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if(poPlayer[i].getControlScheme() == 6) {
            //Joystick #3
            poll_joystick();
            if (joy[2].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up
            if (joy[2].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left
            if (joy[2].stick[0].axis[1].d2) {moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down
            if (joy[2].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right
            if (joy[2].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if(poPlayer[i].getControlScheme() == 7) {
            //Joystick #4
            poll_joystick();
            if (joy[3].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up
            if (joy[3].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left
            if (joy[3].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down
            if (joy[3].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right
            if (joy[3].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
        }
        if (Level.timeForAPowerupTimer >= 60) { Level.timeForAPowerupTimer = 0; }
        else { Level.timeForAPowerupTimer++; }
      }
      if ( Level.getFrame() < 32 ) { Level.setFrame( Level.getFrame() + 1 ); }
      else { Level.setFrame(0); }

    //Score Bar
      if (Level.getFragLimit() != 0 && Level.getEnabled() == true) {
        scrollerX += 0.5;
        if (scrollerX >= 1200.0) { scrollerX = -150.0; }
      }
      for (int i=0; i<4; i++) {
        //Res circle
        if (poPlayer[i].getRespawnCounter() >= 0) {
          poPlayer[i].setRespawnCounter( poPlayer[i].getRespawnCounter() + 1);
        }
        //"Laser" movement
        if (loLaser[i].getEnabled() == true) {
          if (loLaser[i].getDir() == 'u') { loLaser[i].moveUp('l'); }
          else if (loLaser[i].getDir() == 'd') { loLaser[i].moveDown('l'); }
          else if (loLaser[i].getDir() == 'l') { loLaser[i].moveLeft('l'); }
          else if (loLaser[i].getDir() == 'r') { loLaser[i].moveRight('l'); }
          checkCollision(&loLaser[i], poPlayer, i, Level);
        }
        if ((poPlayer[i].returnScore() == Level.getFragLimit()) && (Level.getFragLimit() > 0)) {
          //Frag Limit hit
          Menu.fragLimitHit = true;
          winner = i;
        }
      }

      speed_counter--;
    }//while (speed_counter > 0)

    if ( Menu.getEnabled() == true ) {
      drawMenuStuff(buffer, Menu, titleimg, imgPlayers, Level);
    }
    else if (Menu.fragLimitHit == true) {
      //Show win window!
      floodfill  (buffer, 0, 0, makecol(0,0,0));
      textprintf(buffer,font,348,203,makecol(100,0,0), "Player %i Wins!", winner+1 );
      textprintf(buffer,font,347,202,makecol(150,0,0), "Player %i Wins!", winner+1 );
      textprintf(buffer,font,346,201,makecol(200,0,0), "Player %i Wins!", winner+1 );
      textprintf(buffer,font,345,200,makecol(255,0,0), "Player %i Wins!", winner+1 );

      textprintf(buffer,font,330,250,makecol(255,0,0), "Player 1 score: %i", poPlayer[0].returnScore() );
      textprintf(buffer,font,330,260,makecol(255,0,0), "Player 2 score: %i", poPlayer[1].returnScore() );
      textprintf(buffer,font,330,270,makecol(255,0,0), "Player 3 score: %i", poPlayer[2].returnScore() );
      textprintf(buffer,font,330,280,makecol(255,0,0), "Player 4 score: %i", poPlayer[3].returnScore() );

      textprintf(buffer,font,330,249,makecol(255,255,255), "Player 1 score: %i", poPlayer[0].returnScore() );
      textprintf(buffer,font,330,259,makecol(255,255,255), "Player 2 score: %i", poPlayer[1].returnScore() );
      textprintf(buffer,font,330,269,makecol(255,255,255), "Player 3 score: %i", poPlayer[2].returnScore() );
      textprintf(buffer,font,330,279,makecol(255,255,255), "Player 4 score: %i", poPlayer[3].returnScore() );

      textout_centre(buffer, font, "Hit esc to continue", 400, 300, makecol(255,255,255));
    }
    else {
      generateBackground(buffer, Level);
      drawCharacters(poPlayer, Level, buffer);
      drawScoreBar(buffer, poPlayer, scrollerX, scrollerY, Level);
      if (loLaser[0].getEnabled() == true) { drawLaser(loLaser[0], buffer, Level, 0); }
      if (loLaser[1].getEnabled() == true) { drawLaser(loLaser[1], buffer, Level, 1); }
      if (loLaser[2].getEnabled() == true) { drawLaser(loLaser[2], buffer, Level, 2); }
      if (loLaser[3].getEnabled() == true) { drawLaser(loLaser[3], buffer, Level, 3); }
    }


    acquire_screen();
    blit(buffer, screen, 0, 0, 0, 0, 800, 600);
    clear_bitmap(buffer);
    release_screen();
  }//while ( !Menu.isDone() )

    return 0;

  return 0;
}
예제 #17
0
파일: MOUSE.C 프로젝트: kashopi/KMid
int main()
{
   int mickeyx = 0;
   int mickeyy = 0;
   BITMAP *custom_cursor;
   char msg[80];
   int c = 0;

   allegro_init();
   install_keyboard(); 
   install_mouse();
   install_timer();
   set_gfx_mode(GFX_VGA, 320, 200, 0, 0);
   set_pallete(desktop_pallete);

   do {
      /* the mouse position is stored in the variables mouse_x and mouse_y */
      sprintf(msg, "mouse_x = %-5d", mouse_x);
      textout(screen, font, msg, 16, 16, 255);

      sprintf(msg, "mouse_y = %-5d", mouse_y);
      textout(screen, font, msg, 16, 32, 255);

      /* or you can use this function to measure the speed of movement.
       * Note that we only call it every fourth time round the loop: 
       * there's no need for that other than to slow the numbers down 
       * a bit so that you will have time to read them...
       */
      c++;
      if ((c & 3) == 0)
	 get_mouse_mickeys(&mickeyx, &mickeyy);

      sprintf(msg, "mickey_x = %-7d", mickeyx);
      textout(screen, font, msg, 16, 64, 255);

      sprintf(msg, "mickey_y = %-7d", mickeyy);
      textout(screen, font, msg, 16, 80, 255);

      /* the mouse button state is stored in the variable mouse_b */
      if (mouse_b & 1)
	 textout(screen, font, "left button is pressed ", 16, 112, 255);
      else
	 textout(screen, font, "left button not pressed", 16, 112, 255);

      if (mouse_b & 2)
	 textout(screen, font, "right button is pressed ", 16, 128, 255);
      else
	 textout(screen, font, "right button not pressed", 16, 128, 255);

      if (mouse_b & 4)
	 textout(screen, font, "middle button is pressed ", 16, 144, 255);
      else
	 textout(screen, font, "middle button not pressed", 16, 144, 255);

      vsync();

   } while (!keypressed());

   clear_keybuf();

   /*  To display a mouse pointer, call show_mouse(). There are several 
    *  things you should be aware of before you do this, though. For one,
    *  it won't work unless you call install_timer() first. For another,
    *  you must never draw anything onto the screen while the mouse
    *  pointer is visible. So before you draw anything, be sure to turn 
    *  the mouse off with show_mouse(NULL), and turn it back on again when
    *  you are done.
    */
   clear(screen);
   textout_centre(screen, font, "Press a key to change cursor", SCREEN_W/2, SCREEN_H/2, 255);
   show_mouse(screen);
   readkey();
   show_mouse(NULL);

   /* create a custom mouse cursor bitmap... */
   custom_cursor = create_bitmap(32, 32);
   clear(custom_cursor); 
   for (c=0; c<8; c++)
      circle(custom_cursor, 16, 16, c*2, c);

   /* select the custom cursor and set the focus point to the middle of it */
   set_mouse_sprite(custom_cursor);
   set_mouse_sprite_focus(16, 16);

   clear(screen);
   textout_centre(screen, font, "Press a key to quit", SCREEN_W/2, SCREEN_H/2, 255);
   show_mouse(screen);
   readkey();
   show_mouse(NULL);

   destroy_bitmap(custom_cursor);

   return 0;
}
예제 #18
0
파일: ripple1.c 프로젝트: 10crimes/code
void main(void) {
    
    int xy,i,c,x,y,front,back,n,minc,maxc;
    float dzdx,dzdy,a,b,dot,norm,tmp;
    long p,q;
    RGB rgb;

//    srand(456789);
        srand((int)time(NULL));
        //printf("%d\n",(int)time(NULL));


    mytime=10;
    maxc=0; minc=255;


    // Set up ripples
    numripples=5;
    for (i=0; i<numripples; i++) {
        newripple(i);
    }


  allegro_init ();
  install_keyboard ();
  install_timer ();
  set_gfx_mode (GFX_AUTODETECT, scrwid, scrhei, 0, 0);
  set_pallete (desktop_palette);
  buffer = create_bitmap (scrwid, scrhei);
      clear (buffer);

    // Set up grayscale colours
    for (c=0;c<=255;c++) {
        i=0;
        rgb.r=c*63/255;
        rgb.g=0;
        rgb.b=0;
        set_color(c,&rgb);
//        colors[c]=GrAllocColor(c,i,i);
    }
    

//      circlefill (buffer, x, y, 3, 255);
      textout_centre (buffer, font, "Press SPACE!", 60, 220, 4);

      blit (buffer, screen, 0, 0, 0, 0, 320, 240);

    while(!key[KEY_ESC]) {
        for (x=0; x<scrwid; x=x+res) {
        for (y=0; y<scrhei; y=y+res) {
            dzdx=0;
            dzdy=0;
            for (i=0;i<numripples;i++) {
                ripples[i].front=ripples[i].v*(mytime-ripples[i].st);
                ripples[i].back=ripples[i].v*(mytime-ripples[i].st)-ripples[i].w;
                if (ripples[i].back>scrwid)
                        newripple(i);
            }
            for (i=0;i<numripples;i++) {
                xy=(sqrt((x-ripples[i].x)*(x-ripples[i].x)+(y-ripples[i].y)*(y-ripples[i].y)));
                //printf("xy%i",xy);
                //printf("x%i",x);
                //printf("y%i",y);
                //printf("rx%i",ripples[i].x);
                //printf("ry%i",ripples[i].y);
                //printf("f%i\n",front);
                //printf("b%i\n",back);
                if ((xy>2)&&(xy<ripples[i].front)&&(xy>ripples[i].back)) {
                    //printf("*********");
                    a=pi/ripples[i].w*sin(2*pi*ripples[i].n/ripples[i].w*(xy-ripples[i].v*(mytime-ripples[i].st)));
                    //printf("a%f",a);
                    b=(float)1/xy;
                    //printf("b%f",b);
                    norm=1500/(mysquare(xy))*(exp(3*(xy-(ripples[i].v)*((mytime-ripples[i].st)))/ripples[i].w));
                    //printf("n%f",norm);
                    dzdx=dzdx+a*b*(x-ripples[i].x)*ripples[i].w*norm;
                    dzdy=dzdy+a*b*(y-ripples[i].y)*ripples[i].w*norm;
                }
            }
            //dot=dzdx*lx+dzdy*ly;
            //dot=dot*(dzdx*0.8+dzdy*0.6);
            //dot=dzdx*0.8+dzdy*0.6;
            dot=dzdx * 1 * 0.8 + dzdy * 1 * 0.6;
            c=128+dot*128*scale;
            if (c<minc)
                minc=c;
            if (c>maxc)
                maxc=c;
            if (c<0)
                c=0;
            if (c>255)
                c=255;
            /*GrPlot(x,y,colors[c]);
            GrPlot(x+1,y,colors[c]);
            GrPlot(x,y+1,colors[c]);
            GrPlot(x+1,y+1,colors[c]);*/

rectfill(buffer, x, y, x+res-1, y+res-1, c);

//            GrFilledBox(x,y,x+res-1,y+res-1,colors[c]);
        }
        }
    /*for (i=0;i<numripples;i++) {
        mycircle(ripples[i].x,ripples[i].y,ripples[i].front,colors[0]);
        mycircle(ripples[i].x,ripples[i].y,ripples[i].back,colors[0]);
    }*/
      blit (buffer, screen, 0, 0, 0, 0, 320, 240);
    mytime=mytime+2;
    }
destroy_bitmap(buffer);
exit(0);
    getch();

//    GrSetMode(GR_default_text);
    printf("max col %d\n",maxc);
    printf("min col %d\n",minc);
  
}
예제 #19
0
파일: game.c 프로젝트: stavrossk/EggHack
void game_init(int ai)
{
	static int once = 1;
	int x, y;
	BITMAP *tmp;
	int bc = makecol(200, 150, 50);
	
	clear_to_color(screen, makecol(0, 0, 0));
	textout_centre(screen, font, "Generating&Caching Data", SCREEN_W / 2, 0, -1);
	textout_centre(screen, font, "May take a while", SCREEN_W / 2, SCREEN_H / 2, -1);
	textout_centre(screen, font, "(about 10 minutes for first run,", SCREEN_W / 2, SCREEN_H / 2 + 20, -1);
	textout_centre(screen, font, "about 1 minute every first game,", SCREEN_W / 2, SCREEN_H / 2 + 40, -1);
	textout_centre(screen, font, "few seconds else)", SCREEN_W / 2, SCREEN_H / 2 + 60, -1);
		
	if (once) {
		once = 0;
		
		animdata[0] = load_gfx("gravburn", 48);
		animdata[1] = load_gfx("shock", 48);
		animdata[2] = load_gfx("fireball", 48);
		animdata[3] = load_gfx("wheel", 48);
		animdata[4] = load_gfx("glow", 32);
		{
			int a;
			for (a = 0; a < ANIMS; a++) {
				anim[a] = 0;
				animlen[a] = dat_length(animdata[a]);
			}
		}
		
		tower = dat[TOWER_BMP].dat;
		explosion = dat[EXPLOSION_WAV].dat;
		radiating =  dat[RADIATING_WAV].dat;
		teleport =  dat[TELEPORT_WAV].dat;
		bonus =  dat[BONUS_WAV].dat;
		nuclearegg =  dat[NUCLEAREGG_BMP].dat;
		launcher =  dat[LAUNCHER_BMP].dat;
	
		bonuspic[0] = dat[BONUS0_BMP].dat;
		bonuspic[1] = dat[BONUS1_BMP].dat;
		bonuspic[2] = dat[BONUS2_BMP].dat;
	
		map = create_bitmap(SCREEN_W, SCREEN_H);
	}

	ignore[0] = 0;
	ignore[1] = 0;	
	think[0] = 0;
	think[1] = 0;
	memorized[0] = 0;
	memorized[1] = 0;
	AI[0] = 0;
	if (ai) AI[1] = 1; else AI[1] = 0;
	power[0] = 0;
	power[1] = 0;
	bonusnum = 0;
	life[0] = 100;
	life[1] = 100;
	go = 0;
	
	turn = 0;
	
	tmp = create_bitmap_ex(32, SCREEN_W, SCREEN_H);
	draw_back(tmp);
	for (y = 0; y < 16; y++) {
		for (x = 0; x < 16; x++) {
			hills[y][x] = rnd();
		}
	}

	basex[0] = 4 * TW + TW / 2;
	basey[0] = 4 * TH + TH / 2;

	basex[1] = 12 * TW + TW / 2;
	basey[1] = 12 * TH + TH / 2;

	hills[4][4] = 1;
	hills[5][4] = 1;
	hills[5][5] = 1;
	hills[4][5] = 1;

	hills[12][12] = 1;
	hills[13][12] = 1;
	hills[13][13] = 1;
	hills[12][13] = 1;

	x = rnd() * 16;
	y = rnd() * 16;

	for (y = 0; y < MH; y++) {
		for (x = 0; x < MW; x++) {
			int c = 0;
			int t;
			float height = get_height(x, y);
			float h = 0, z = height * ZZZ;
			for (h = height, t = 0; z > 0 && t < 2; z--, h -= 1.0 / (float)ZZZ, t++) {
				int r, g, b;
				float l;
				if (h < 0.2) {
					float p = h / 0.2;
					r = 0;
					g = 100 * p;
					b = 155 + 100 * p;
				} else if (h < 0.5) {
					float p = (h - 0.2) / 0.3;
					r = 0;
					g = 100 + 155 * p;
					b = 255 - 155 * p;
				} else if (h < 0.8) {
					float p = (h - 0.5) / 0.3;
					r = 200 * p;
					g = 255 - 155 * p;
					b = 100;
				} else {
					float p = (h - 0.8) / 0.2;
					r = 200;
					g = 100 + 100 * p;
					b = 100 + 100 * p;
				}
				l = get_height(x + 1, y) - get_height(x, y + 1);
				r = r + l * 2000 + (rnd() - 0.5) * 20;
				g = g + l * 2000 + (rnd() - 0.5) * 20;
				b = b + l * 2000 + (rnd() - 0.5) * 20;
				c = makecol32(M(r), M(g), M(b));
				if (y == MH - 1 && h < height) c = bc;
				putpixel(tmp, 88 + x, y + WINT - z, c);
			}
		}
	}
	{
		float filter[3][3] = {
			{0.025, 0.145, 0.025},
			{0.145, 0.320, 0.145},
			{0.025, 0.145, 0.025}
		};
		for (y = 0; y < SCREEN_H; y++) {
			for (x = 0; x < SCREEN_W; x++) {
				int i = 0, j = 0;
				float r = 0, g = 0, b = 0;
				for (i = -1; i <= 1; i++) {
					for (j = -1; j <= 1; j++) {
						int c = getpixel(tmp, x + j, y + i);
						if (c < 0) c = makecol32(0, 0, 0);
						r += getr32(c) * filter[1 + i][1 + j];
						g += getg32(c) * filter[1 + i][1 + j];
						b += getb32(c) * filter[1 + i][1 + j];
					}
				}
				putpixel(map, x, y, makecol(r, g, b));
			}
		}
	}
	destroy_bitmap(tmp);
	ballx = 240;
	bally = 240;
	balldx = 0;
	balldy = 0;
}
예제 #20
0
int main(int argc, const char *const *argv) /* I'm const-crazy! */
{
	DUH *duh;          /* Encapsulates the music file. */
	AL_DUH_PLAYER *dp; /* Holds the current playback state. */

	/* Initialise Allegro */
	if (allegro_init())
		return EXIT_FAILURE;

	/* Check that we have one argument (plus the executable name). */
	if (argc != 2)
		usage(argv[0]);

	/* Tell Allegro where to find configuration data. This means you can
	 * put any settings for Allegro in dumb.ini. See Allegro's
	 * documentation for more information.
	 */
	set_config_file("dumb.ini");

	/* Initialise Allegro's keyboard input. */
	if (install_keyboard()) {
		allegro_message("Failed to initialise keyboard driver!\n");
		return EXIT_FAILURE;
	}

	/* This function call is appropriate for a program that will play one
	 * sample or one audio stream at a time. If you have sound effects
	 * too, you may want to increase the parameter. See Allegro's
	 * documentation for details on what the parameter means. Note that
	 * newer versions of Allegro act as if set_volume_per_voice() was
	 * called with parameter 1 initially, while older versions behave as
	 * if -1 was passed, so you should call the function if you want
	 * consistent behaviour.
	 */
	set_volume_per_voice(0);

	/* Initialise Allegro's sound output system. */
	if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL)) {
		allegro_message("Failed to initialise sound driver!\n%s\n", allegro_error);
		return EXIT_FAILURE;
	}

	/* dumb_exit() is a function defined by DUMB. This operation arranges
	 * for dumb_exit() to be called last thing before the program exits.
	 * dumb_exit() does a bit of cleaning up for you. atexit() is
	 * declared in stdlib.h.
	 */
	atexit(&dumb_exit);

	/* DUMB defines its own wrappers for file input. There is a struct
	 * called DUMBFILE that holds function pointers for the various file
	 * operations needed by DUMB. You can decide whether to use stdio
	 * FILE objects, Allegro's PACKFILEs or something else entirely. No
	 * wrapper is installed initially, so you must call this or
	 * dumb_register_stdfiles() or set up your own before trying to load
	 * modules by file name. (If you are using another method, such as
	 * loading an Allegro datafile with modules embedded in it, then DUMB
	 * never opens a file by file name so this doesn't apply.)
	 */
	dumb_register_packfiles();

	/* Load the module file into a DUH object. Quick and dirty: try the
	 * loader for each format until one succeeds. Note that 15-sample
	 * mods have no identifying features, so dumb_load_mod() may succeed
	 * on files that aren't mods at all. We therefore try that one last.
	 */
	duh = dumb_load_it(argv[1]);
	if (!duh) {
		duh = dumb_load_xm(argv[1]);
		if (!duh) {
			duh = dumb_load_s3m(argv[1]);
			if (!duh) {
				duh = dumb_load_mod(argv[1]);
				if (!duh) {
					allegro_message("Failed to load %s!\n", argv[1]);
					return EXIT_FAILURE;
				}
			}
		}
	}

	/* Read the quality values from the config file we told Allegro to
	 * use. You may want to hardcode these or provide a more elaborate
	 * interface via which the user can control them.
	 */
	dumb_resampling_quality = get_config_int("sound", "dumb_resampling_quality", 4);
	dumb_it_max_to_mix = get_config_int("sound", "dumb_it_max_to_mix", 128);

	/* If we're not in DOS, show a window and register our close hook
	 * function.
	 */
#	ifndef ALLEGRO_DOS
		{
			const char *fn = get_filename(argv[1]);
			gfx_half_width = strlen(fn);
			if (gfx_half_width < 22) gfx_half_width = 22;
			gfx_half_width = (gfx_half_width + 2) * 4;

			/* set_window_title() is not const-correct (yet). */
			set_window_title((char *)"DUMB Music Player");

			if (set_gfx_mode(GFX_DUMB_MODE, gfx_half_width*2, 80, 0, 0) == 0) {
				acquire_screen();
				textout_centre(screen, font, fn, gfx_half_width, 20, 14);
				textout_centre(screen, font, "Press any key to exit.", gfx_half_width, 52, 11);
				release_screen();
			} else
				gfx_half_width = 0;
		}

		/* Silly check to get around the fact that someone stupidly removed
		 * an old function from Allegro instead of deprecating it. The old
		 * function was put back a version later, but we may as well use the
		 * new one if it's there!
		 */
#		if ALLEGRO_VERSION*10000 + ALLEGRO_SUB_VERSION*100 + ALLEGRO_WIP_VERSION >= 40105
			set_close_button_callback(&closehook);
#		else
			set_window_close_hook(&closehook);
#		endif

#	endif

	/* We want to continue running if the user switches to another
	 * application.
	 */
	set_display_switch_mode(SWITCH_BACKGROUND);

	/* We have the music loaded, but it isn't playing yet. This starts it
	 * playing. We construct a second object, the AL_DUH_PLAYER, to
	 * represent the playing music. This means you can play the music
	 * twice at the same time should you want to!
	 *
	 * Specify the number of channels (2 for stereo), which 'signal' to
	 * play (always 0 for modules), the volume (1.0f for default), the
	 * buffer size (4096 generally works well) and the sampling frequency
	 * (ideally match the final output frequency Allegro is using). An
	 * Allegro audio stream will be started.
	 */
	dp = al_start_duh(duh, 2, 0, 1.0f,
		get_config_int("sound", "buffer_size", 4096),
		get_config_int("sound", "sound_freq", 44100));

	/* Register our callback functions so that they are called when the
	 * music loops or stops. See docs/howto.txt for more information.
	 * There is no threading issue: DUMB will only process playback
	 * in al_poll_duh(), which we call below.
	 */
	{
		DUH_SIGRENDERER *sr = al_duh_get_sigrenderer(dp);
		DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer(sr);
		dumb_it_set_loop_callback(itsr, &loop_callback, NULL);
		dumb_it_set_xm_speed_zero_callback(itsr, &xm_speed_zero_callback, NULL);
	}

	/* Main loop. */
	for (;;) {
		/* Check for keys in the buffer. If we get one, discard it
		 * and exit the main loop.
		 */
		if (keypressed()) {
			readkey();
			break;
		}

		/* Poll the music. We exit the loop if al_poll_duh() has
		 * returned nonzero (music finished) or the window has been
		 * closed. al_poll_duh() might return nonzero if you have set
		 * up a callback that tells the music to stop.
		 */
		if (al_poll_duh(dp) || closed)
			break;

		/* Give other threads a look-in, or allow the processor to
		 * sleep for a bit. YIELD() is defined further up in this
		 * file.
		 */
		YIELD();
	}

	/* Remove the audio stream and deallocate the memory being used for
	 * the playback state. We set dp to NULL to emphasise that the object
	 * has gone.
	 */
	al_stop_duh(dp);
	dp = NULL;

	/* Free the DUH object containing the actual music data. */
	unload_duh(duh);
	duh = NULL;

	/* All done! */
	return EXIT_SUCCESS;
}
예제 #21
0
int CGame::SetupGame(char *argv[]) {

	int bpp = 32; //bits per pixel (truecolor)
	
	//buffers for filename manipulation
	char fullpath[255];
	char filename[10]; 

	int ret; //catches return values for processing
	int i;  //universal loop counter

	//initialise allegro stuff
	allegro_init(); 
	install_keyboard(); 
	install_mouse(); 
	install_timer();

	set_color_depth(bpp);
	
	/* Lets play the color depth game!  tries 32, 24, then 16 bit color modes */
	// set resolution to play intro movie
	ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
	/* did the video mode set properly? */
	if (ret != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Error setting %d bit graphics mode\n%s\nLets try another color depth!", bpp, allegro_error);
		
		bpp = 24;
		set_color_depth(bpp);
		
		// set resolution
		ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
		/* did the video mode set properly? */
		if (ret != 0) {
			set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
			allegro_message("Error setting %d bit graphics mode\n%s\nLets try another color depth!", bpp, allegro_error);

			bpp = 16;
			set_color_depth(bpp);

			// set resolution
			ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
			/* did the video mode set properly? */
			if (ret != 0) {
				set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
				allegro_message("Error setting %d bit graphics mode\n%s\nIm all out of options. Exiting", bpp, allegro_error);
				return 1;
			}
		}
	}
	
	// Load data from data.dat into memory
	textout_centre(screen,font,"NOW LOADING",SCREEN_W/2,SCREEN_H/2,makecol(255,255,255));

	sprintf(filename,"data.dat");
	replace_filename(fullpath, argv[0], filename, sizeof(fullpath));
    data = load_datafile(fullpath);
	if (!data) { 
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Cant load file %s for some reason.\nIt should be in the same directory as the .exe\n"
		"If you have deleted the debug directory to mark this then\ncopy all files from the \"required files\""
		"directory into the directory with the .exe\n\nThanks. Scarbble will now crash horribly", filename);
		return 1;
	}

	//make smaller copy of all tiles
	for (i=0;i<27;i++) {
		smalltiles[i] = create_bitmap(29,29);
		rotate_scaled_sprite(smalltiles[i], (WINDOWS_BITMAP *)data[i].dat, 0,0, 0, ftofix(0.8));
	}
		
	PlayIntro();

	AddPlayers();

	//stuff that cant be done in the players constructor
	InitialisePlayers();
	
	//set video mode to play game
	ret = set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0);
	/* did the video mode set properly? */
	if (ret != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Error setting %d bit graphics mode\n%s\n", bpp, allegro_error);
		return 1;
	}
	
	//initialise the 'background' screen buffer
	background = create_bitmap(SCREEN_W, SCREEN_H);
	clear(background); //clear to black
	boardcolor = makecol(206,206,90);

	show_mouse(screen);
		
	return 0;
}
/////////////////////////////////////
//// MAIN ///////////////////////////
/////////////////////////////////////
int main(int argc, char *argv[])
{
 
/////////////////////////////////////
// START GUI SPECIFIC CODE //////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////
	int bpp; // color depth 
	int ret; // for processing return values
	
	//initialise allegro stuff
	allegro_init(); 
	install_keyboard(); 
	install_timer();

	bpp = desktop_color_depth();
	set_color_depth(bpp);
	
	/* Lets play the color depth game!  tries 32, 24, then 16 bit color modes */
	// set resolution to play intro movie
	ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	/* did the video mode set properly? */
	if (ret != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Error setting %d bit graphics mode\n%s\nLets try another color depth!", bpp, allegro_error);
		
		bpp = 32;
		set_color_depth(bpp);
		
		// set resolution
		ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
		/* did the video mode set properly? */
		if (ret != 0) {
			set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
			allegro_message("Error setting %d bit graphics mode\n%s\nLets try another color depth!", bpp, allegro_error);

			bpp = 16;
			set_color_depth(bpp);

			// set resolution
			ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
			/* did the video mode set properly? */
			if (ret != 0) {
				set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
				allegro_message("Error setting %d bit graphics mode\n%s\nIm all out of options. Exiting", bpp, allegro_error);
				return 1;
			}
		}
	}
	
///////////////////////////
// END OF GUI SPECIFIC //////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////

//////////////////////////
///// VARIABLES //////////
//////////////////////////

	CEdge edgelist; //the edges
	int besttour = MAX_DISTANCE*NUM_TOWNS; //best result ever
	int currtour = MAX_DISTANCE*NUM_TOWNS; //best result from last tour
	int bestant = -1; //stores ant that did really well and adds more phero to its trail
	CAnt colony[NUM_ANTS]; //the ants

	int i,j; //universal for loop counters
	
	int cycles=0;
	
	srand(time(NULL));		 //seed random number
	int limit;				//universal random number limit.. (rand()%limit will give a number between 0 and limit-1)

	// Start Cycling
	while (!key[KEY_ESC] && cycles < MAX_CYCLES) {
		
		textprintf(screen,font,5,5,makecol(255,0,0),"Press Esc to hault processing [Cycle %d]",cycles);
		
		//initialise the ants before they all do a tour	
		//sets each ants first town to somewhere random
		
		limit = NUM_TOWNS;
		for (i=0;i<NUM_ANTS;i++) {			
			//colony[i].SetTown(0,i); //set each ants first tour element to a town 
			colony[i].SetTown(0,rand()%limit); //random version
		}	
		
		
		//each time though loop add another node to each ants tour list 
		//starting at the 2nd node (the 1st node is already set)
		limit = NUM_TOWNS+1;				
		double distance;
		double pheromone;	
		double probability;
		double total;
		double p[NUM_TOWNS];

		for (int tourcount=1;tourcount<NUM_TOWNS;tourcount++) {
			
			for (i=0;i<NUM_ANTS;i++) { //for each ant.. add 1 more tour
				
				//reset probabilities
				probability=0;
				total=0;
				
				//calculate best probability from all possible new paths
				
				//loop through all remaining possible tours left on the current ant
				//each time through the loop calc probability and keep track of best
				int k;
				for (j=tourcount,k=0;j<NUM_TOWNS;j++,k++) {
					
					//get variables used to calc probability
					distance = edgelist.GetDistance(colony[i].GetTown(tourcount-1), colony[i].GetTown(j));
					pheromone = edgelist.GetPhero(colony[i].GetTown(tourcount-1), colony[i].GetTown(j));
					
					probability = pow(pheromone, ALPHA);
					probability = probability * pow(distance, -BETA);
					
					p[k] = probability;
					total += probability;
					
				}
				
				//choose new town based on probability
				int best = 0;
				for (j=0;j<k;j++) {
					
					if ((p[best]/total)  > (p[j]/total)) {
						//new best
						best = j; 
					}
					
				}
				
				//move current ant to new town
				colony[i].SetTown(tourcount, colony[i].GetTown(tourcount+best));
				
			}//for ant
		}
		

		//////////////////////////////////////
		//ants now have full tour lists
		//compute length of each ants list
		//////////////////////////////////////
		for (i=0;i<NUM_ANTS;i++) { //for each ant
			
			int distance = 0;
			
			//reset currtour
			currtour = MAX_DISTANCE*NUM_TOWNS;
			
			printf("\nant %d [%d",i,colony[i].GetTown(0));//display ants tour in console window
			
			for (int j=1;j<NUM_TOWNS;j++) { //for each edge in the ants tour
				
				printf(",%d",colony[i].GetTown(j));//display ants tour in console window
				distance += edgelist.GetDistance(colony[i].GetTown(j-1), colony[i].GetTown(j));
				
			}
			
			printf("]");//display ants tour in console window
			
			//add on loopback distance
			distance += edgelist.GetDistance(colony[i].GetTown(NUM_TOWNS-1), colony[i].GetTown(0));
			
			printf("=%d",distance);//display ants tour distance in console window

			//keep record of best tours
			if (distance < besttour) {
				besttour = distance;
				bestant = i; //we only add extra phero to a tour when a best tour "record" is broken
			}
			if (distance < currtour)
				currtour = distance;

			//store distance on ant
			colony[i].SetDistance(distance);
		}

		
		/////////////////////////
		//evaporate pheromones
		/////////////////////////
		edgelist.Evaporate(EVAP);


		//////////////////////////////////////////////////
		//lay new pheromones based on colony[i].distance
		//////////////////////////////////////////////////
		for (i=0;i<NUM_ANTS;i++) {
			
			double phero;
			
			for (int j=1;j<NUM_TOWNS;j++) { //for each edge in the ants tour
				
				phero = edgelist.GetPhero(colony[i].GetTown(j-1), colony[i].GetTown(j)); //get old phero
				phero = phero + QUE / colony[i].GetDistance(); //calc new phero
				
				//reinforce best path
				if (bestant != -1 && i == bestant) {
					phero += ADD_PHERO;
				}

				edgelist.SetPhero(colony[i].GetTown(j-1), colony[i].GetTown(j), phero);
			}
			
			//loop back 
			phero = edgelist.GetPhero(colony[i].GetTown(NUM_TOWNS-1), colony[i].GetTown(0)); //get old phero
			phero = phero + QUE / colony[i].GetDistance(); //calc new phero
			
			//reinforce best path
			if (bestant != -1 && i == bestant) {
				phero += ADD_PHERO;
				bestant = -1;
			}

			edgelist.SetPhero(colony[i].GetTown(NUM_TOWNS-1), colony[i].GetTown(0), phero); //set phero
		}

		
		/////////////////////////////
		//reset ants and do it again
		/////////////////////////////
		for (i=0;i<NUM_ANTS;i++) {
			
			colony[i].ResetAnt();
			
		}
				
		//cycle done
		
		cycles ++;
		Draw(cycles, currtour, besttour);

	}

	clear_keybuf();
	textprintf_centre(screen,font,SCREEN_W/2,SCREEN_H/2-60,makecol(255,0,0),"Best Tour = %d",besttour);
	textout_centre(screen,font,"Press a key to exit",SCREEN_W/2,SCREEN_H/2-40,makecol(255,0,0));
	readkey();

	return 0;
}