Exemplo n.º 1
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;
}
Exemplo n.º 2
0
void update()
{
  int x, y, z;

  current_view = (current_view == left_view) ? right_view : left_view;

  // draw complete background
  rectfill(current_view, 0, 0, 639, 479, BACKGROUND_COLOR);

  draw_sprite(current_view, new_game, NEW_GAME_BUTTON_X1, BUTTON_YOFF);
  draw_sprite(current_view,	undo,	  UNDO_BUTTON_X1, BUTTON_YOFF);
  draw_sprite(current_view,	help,	  HELP_BUTTON_X1, BUTTON_YOFF);
  draw_sprite(current_view,	quit,	  QUIT_BUTTON_X1, BUTTON_YOFF);

  if(editing)
  {
    textprintf(current_view, font, 200,  2, SELECTED,
	       "Editing: '%s' (%s)", layout_title, get_filename(editing));
    textprintf(current_view, font, 200, 12, SELECTED,
	       "%3i pieces left", n_pieces_left);
  }

  for(z = 0; z <  3; z++)
  for(y = 0; y <  9; y++)
  for(x = 0; x < 16; x++)
    if(board[x][y][z].value < EMPTY || editing)
      drawPiece(current_view, &board[x][y][z]);

  scroll_screen((current_view == left_view) ? 0 : SCREEN_WIDTH, 0);
  show_mouse(current_view);
}
Exemplo n.º 3
0
// debugging
int cControls::DisplayJoyStick()
{
   int i, j, pos = 12;

   JOYSTICK_AXIS_INFO s;
   for(i = 0; i < joy[0].num_sticks; ++i)
   {
      for(j = 0; j < joy[0].stick[i].num_axis; ++j)
      {
         s = joy[0].stick[i].axis[j];
         textprintf(screen, font, 150, pos, 11, "%d,%d (%d,%d,%d)", i, j, s.d1, s.d2, s.pos);
         pos += 12;
      }
   }

   
   JOYSTICK_BUTTON_INFO b;
   for(i = 0; i < joy[0].num_buttons; ++i)
   {
      b = joy[0].button[i];
      textprintf(screen, font, 150, pos, 11, "button #%d %d", i, b.b);
      pos += 12;
   }

   return 0;
}
int menu_class::show_menu(DATAFILE *the_datafile, BITMAP *bmp, int da_font)
{
	text_mode(text_mode_type);
	if (the_datafile != NULL && da_font != -1)
	{
		for (int i = 0; i < (int)menuItems.size(); i++)
		{
			if (i == menuItemIndex)
				textout(bmp, (FONT*)the_datafile[da_font].dat, menuItems[i].first.c_str(), x, y + level_y * i, font1_color);
			else
				textout(bmp, (FONT*)the_datafile[da_font].dat, menuItems[i].first.c_str(), x, y + level_y * i, font2_color);
			if (menuItems[i].second >= 0)
				textprintf(bmp, (FONT*)the_datafile[da_font].dat, x + (font_size + (font_size*menuItems[i].first.size())), y + level_y * i, font1_color, "%d", menuItems[i].second);
		}
	}
	else
	{
		for (int i = 0; i < (int)menuItems.size(); i++)
		{
			if (i == menuItemIndex)
				textout(bmp, font, menuItems[i].first.c_str(), x, y + level_y * i, font1_color);
			else
				textout(bmp, font, menuItems[i].first.c_str(), x, y + level_y * i, font2_color);
			if (menuItems[i].second >= 0)
				textprintf(bmp, font, x + (font_size + (font_size*menuItems[i].first.size())), y + level_y * i, font1_color, "%d", menuItems[i].second);
		}
	}
	return menuItemIndex;
}
Exemplo n.º 5
0
void TiledMap::drawAirborneEntities(BITMAP *dest)
{
	list<EntityP> visibleEnts;
	list<Object*>::iterator i;
	list<EntityP>::iterator j;

	for (i = objects.begin(); i != objects.end(); i++)
	{
		if ((*i)->in_air && (*i)->visible(dest, mapToScreen((*i)->pos)))
		{
			visibleEnts.push_back(EntityP((*i)));
		}
	}

	// Sort the visible entities on y value.
	visibleEnts.sort();

	for (j = visibleEnts.begin(); j != visibleEnts.end(); j++) {
		(*j).ent->draw(dest, mapToScreen((*j).ent->pos));
	}

	if (debug_mode) {
		textprintf(dest, font, cameraScreenRect.x + 10, cameraScreenRect.y + 10, makecol(200,200,200), "%i entities", objects.size());
		textprintf(dest, font, cameraScreenRect.x + 10, cameraScreenRect.y + 20, makecol(200,200,200), "%i drawn entities", visibleEnts.size());
	}
}
Exemplo n.º 6
0
void screen_draw() {
	int x, y;
	int i;
	unsigned long top;
	int halfwin = WIN_W*T_SIZE/2;

	if (gPlayers == 1) {
		blit((BITMAP *)gData[BACK_1PLAYER].dat, gBuff, 0, 0, 0, 0, gBuff->w, gBuff->h);

		// information
		textprintf(gBuff, (FONT *)gData[FONT_TINY].dat, 180, 77,  15, "LEVEL: %d", gDifficulty + 1);
		textprintf(gBuff, (FONT *)gData[FONT_TINY].dat, 180, 109, 15, "LINES: %d", p[0].total_lines);
		textprintf(gBuff, (FONT *)gData[FONT_TINY].dat, 180, 141, 15, "SCORE: %ld", p[0].total_score);

		if (p[0].total_score > gTable[0].score)
			top = p[0].total_score;
		else
			top = gTable[0].score;
		textprintf(gBuff, (FONT *)gData[FONT_TINY].dat, 180, 173, 15, "TOP  : %ld", top);
	} else
		blit((BITMAP *)gData[BACK_2PLAYER].dat, gBuff, 0, 0, 0, 0, gBuff->w, gBuff->h);

	for (i = 0; i != gPlayers; ++i) {
		// draw game area

		// grid
		for (y = 0; y != WIN_H; ++y) {
			hline(gBuff, p[i].win_x, p[i].win_y + y*T_SIZE, p[i].win_x + WIN_W*T_SIZE, 4);
			for (x = 0; x != WIN_W; ++x)
				vline(gBuff, p[i].win_x + x*T_SIZE, p[i].win_y, p[i].win_y + WIN_H*T_SIZE, 4);
		}

		// next piece box
		next_draw();

		// the stack
		player_stack_draw(i);

		// the deleting line effect
		if (p[i].process == DELETING_LINES) {
			for (y = 0; y != 4; ++y) {
				if (p[i].full_lines[y] != -1)
					rectfill(gBuff, p[i].win_x + halfwin - halfwin * gDeleteCounter[i]/cDeleteTime, p[i].win_y + p[i].full_lines[y]*T_SIZE,
					         p[i].win_x + halfwin + halfwin * gDeleteCounter[i]/cDeleteTime, p[i].win_y + p[i].full_lines[y]*T_SIZE + T_SIZE - 1, 0);
			}
		}

		// the current piece
		set_clip(gBuff, p[i].win_x, p[i].win_y,
		         p[i].win_x + WIN_W*T_SIZE,
		         p[i].win_y + WIN_H*T_SIZE);

		piece_draw(p[i].win_x + p[i].piece_x*T_SIZE,
		           p[i].win_y + p[i].piece_y*T_SIZE, p[i].piece_r, p[i].current);
		set_clip(gBuff, 0, 0, gBuff->w, gBuff->h);

		//textprintf(gBuff, font, SCREEN_W/2*i, 0, 15, "(%d, %d, %d)", p[i].piece_x, p[i].piece_y, p[i].piece_r);
	}

}
Exemplo n.º 7
0
void pingpong_score()
{
     if(for_scoring==2)
           count2++;
     else if(for_scoring==1)
           count1++;   
     textprintf(screen,font,60,2,makecol(255,255,255), "P1=%d", count1);
     textprintf(screen,font,540,2,makecol(255,255,255), "P2=%d", count2);
     if(count1==5 || count2==5)
     {
           declare_winner();
           stop_sample(samSong);
           openscreen();
     }
     startNew();
}
Exemplo n.º 8
0
void updatePiece(Piece *p)
{
  BITMAP *work = (current_view == left_view) ? right_view : left_view;

  int i, j, k;
  int lo_i = (p->x >  0) ? p->x - 1 :  0;
  int hi_i = (p->x < 15) ? p->x + 1 : 15;
  int lo_j = (p->y >  0) ? p->y - 1 :  0;
  int hi_j = (p->y <  8) ? p->y + 1 :  8;

  int x = p->x * FACE_WIDTH  - p->z * EDGE_WIDTH  + BOARD_XOFF;
  int y = p->y * FACE_HEIGHT - p->z * EDGE_HEIGHT + BOARD_YOFF;

  rectfill(work, x, y, x + (SPRITE_WIDTH - 1), y + (SPRITE_HEIGHT - 1),
      BACKGROUND_COLOR);

  for(k =    0; k <	3; k++)
  for(j = lo_j; j <= hi_j; j++)
  for(i = lo_i; i <= hi_i; i++)
    if(board[i][j][k].value < EMPTY || editing)
      drawPiece(work, &board[i][j][k]);

  scare_mouse();
  blit(work, current_view, x, y, x, y, SPRITE_WIDTH, SPRITE_HEIGHT);
  if(editing) textprintf(current_view, font, 200, 12, SELECTED,
			 "%3i pieces left", n_pieces_left);
  unscare_mouse();
}
Exemplo n.º 9
0
void gestaff::affiche()
{
    Tf* ptn;
    for(int i=0; i<nb ; i++)
    {
        ptn = (Tf*)tab[i];
        ptn -> affiche();
    }
    textprintf(page,font,550,460,makecol(255,0,0),"nb = %d",nb);
}
Exemplo n.º 10
0
int main()
{
    int koseler[8];
    int kirmizi, yesil, mavi, renk;

    // Allegro'yu ilklendir
    allegro_init();

    // klavyeyi ilklendir
    install_keyboard();

    // rastgele sayı üretecini ilklendir
    srand(time(NULL));

    // ekran kipini ayarla
    int donen = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
    if (donen != 0) {
        allegro_message(allegro_error);
        return;
    }

    // ekran çözünürlüğünü göster
    textprintf(screen, font, 0, 0, 15,
               "Cokgen cizme programı - %dx%d - Cikmak icin ESC tusuna basiniz",
               SCREEN_W, SCREEN_H);

    // çıkış tusuna basılana kadar devam et
    while (!key[KEY_ESC]) {

        // rastgele bir nokta seç
        koseler[0] = 10 + rand() / (RAND_MAX / (SCREEN_W - 20));
        koseler[1] = 10 + rand() / (RAND_MAX / (SCREEN_H - 20));
        koseler[2] = koseler[0] + rand() / (RAND_MAX / 30) + 50;
        koseler[3] = koseler[1] + rand() / (RAND_MAX / 30) + 50;
        koseler[4] = koseler[2] + rand() / (RAND_MAX / 30) - 100;
        koseler[5] = koseler[3] + rand() / (RAND_MAX / 30) + 50;
        koseler[6] = koseler[4] + rand() / (RAND_MAX / 30);
        koseler[7] = koseler[5] + rand() / (RAND_MAX / 30) - 100;

        // rastgele bir renk seç
        kirmizi = rand() / (RAND_MAX / 255 + 1);
        yesil   = rand() / (RAND_MAX / 255 + 1);
        mavi    = rand() / (RAND_MAX / 255 + 1);
        renk = makecol(kirmizi, yesil, mavi);

        // çokgen çiz
        polygon(screen, 4, koseler, renk);

        rest(50);

    }

    // programı sonlandır
    allegro_exit();
}
void optionsScreen::draw()
{
	clear(infoImg->getBitmap());
      // output the string to the screen
      textout(infoImg->getBitmap(), font, edittext.c_str(), 0, 10, makecol(255,255,255));
 
      // output some stats using Allegro's printf functions
      textprintf(infoImg->getBitmap(), font,  0, 20, makecol(255,255,255), "length:   %d", edittext.length());
      textprintf(infoImg->getBitmap(), font,  0, 30, makecol(255,255,255), "capacity: %d", edittext.capacity());
      textprintf(infoImg->getBitmap(), font,  0, 40, makecol(255,255,255), "empty?:   %d", edittext.empty());
      if(insert)
         textout(infoImg->getBitmap(), font, "Inserting", 0, 50, makecol(255,255,255));
      else
         textout(infoImg->getBitmap(), font, "Replacing", 0, 50, makecol(255,255,255));
 
      // draw the caret
      vline(infoImg->getBitmap(), caret * 8, 8, 18, makecol(255,255,255));

	renderer.blitToScreen();
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
int pingpong()
{
    buffer = create_bitmap( 640, 480); 
    BITMAP *BGpong = load_bitmap("C:\\Sanchit\\Game Pack\\Sprites\\BGpong.bmp", NULL);
    
    
    samSong = load_sample("C:\\Sanchit\\Game Pack\\Sprites\\pingpong.wav");
    play_sample(samSong, 128, 128, 1000, 1);
    setupGame();

    while( !key[KEY_ESC])
    {
        draw_sprite(buffer, BGpong, 0,0);
        textprintf(buffer,font,60,2,makecol(255,255,255), "P1=%d", count1);
        textprintf(buffer,font,540,2,makecol(255,255,255), "P2=%d", count2);        
        p1Move();
        p2Move();
        moveBall();
        
        checkWin();
        
        if(scored==1)
                pingpong_score();
        
        if(key[KEY_BACKSPACE])
        {
                      count1=0;
                      count2=0;
                      ball_x=320;
                      ball_y=240;
                      p1_x = 20;
                      p1_y = 210;
                      p2_x = 620;
                      p2_y = 210;
                      stop_sample(samSong);
                      openscreen();
        }              
    }    
    return 0;
}
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();

	
}
Exemplo n.º 15
0
int main()
{
    int x, y1, y2;
    int kirmizi, yesil, mavi, renk;

    // Allegro'yu ilklendir
    allegro_init();

    // klavyeyi ilklendir
    install_keyboard();

    // rastgele sayı üretecini ilklendir
    srand(time(NULL));

    // ekran kipini ayarla
    int donen = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
    if (donen != 0) {
        allegro_message(allegro_error);
        return;
    }

    // ekran çözünürlüğünü göster
    textprintf(screen, font, 0, 0, 15,
               "Dikey cizgi programı - %dx%d - Cikmak icin ESC tusuna basiniz",
               SCREEN_W, SCREEN_H);

    // çıkış tusuna basılana kadar devam et
    while (!key[KEY_ESC]) {

        // rastgele bir nokta seç
        x  = 10 + rand() / (RAND_MAX / (SCREEN_W - 19));
        y1 = 10 + rand() / (RAND_MAX / (SCREEN_H - 19));
        y2 = 10 + rand() / (RAND_MAX / (SCREEN_H - 19));

        // rastgele bir renk seç
        kirmizi = rand() / (RAND_MAX / 255 + 1);
        yesil   = rand() / (RAND_MAX / 255 + 1);
        mavi    = rand() / (RAND_MAX / 255 + 1);
        renk = makecol(kirmizi, yesil, mavi);

        // dikey çizgi çiz
        vline(screen, x, y1, y2, renk);
    }

    // programı sonlandır
    allegro_exit();
}
Exemplo n.º 16
0
int main()
{
    int x, y, yaricapx, yaricapy;
    int kirmizi, yesil, mavi, renk;

    // herşeyi ilklendir
    allegro_init();
    install_keyboard();
    install_timer();
    srand(time(NULL));

    // ekran kipini 640x480 olarak ayarla
    int donen = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
    if (donen != 0) {
        allegro_message(allegro_error);
        return;
    }

    // ekran çözünürlüğünü göster
    textprintf(screen, font, 0, 0, 15,
               "Elips programı - %dx%d - Cikmak icin ESC tusuna basiniz",
               SCREEN_W, SCREEN_H);

    // çıkış tusuna basılana kadar devam et
    while (!key[KEY_ESC]) {

        // rastgele bir nokta seç
        x = 30 + rand() / (RAND_MAX / (SCREEN_W - 60));
        y = 30 + rand() / (RAND_MAX / (SCREEN_H - 60));
        yaricapx = rand() / (RAND_MAX / 30 + 1);
        yaricapy = rand() / (RAND_MAX / 30 + 1);

        // rastgele bir renk seç
        kirmizi = rand() / (RAND_MAX / 255 + 1);
        yesil   = rand() / (RAND_MAX / 255 + 1);
        mavi    = rand() / (RAND_MAX / 255 + 1);
        renk = makecol(kirmizi, yesil, mavi);

        // elipsi çiz
        ellipse(screen, x, y, yaricapx, yaricapy, renk);

        rest(25);
    }

    // programı sonlandır
    allegro_exit();
}
Exemplo n.º 17
0
void movemissile()
{     
     samExplosion2 = load_sample("C:\\Sanchit\\Game Pack\\Sprites\\explosion2.wav");
 
     int x = points[curpoint].x ;
     int y = points[curpoint].y ;
 
     scare_mouse();

     rectfill(buffer,x-6,y-3,x+6,y+1,BLACK);

     if (getpixel(screen,x,y) == GREEN)
     {  
            destroyed++;
            updatescore();
            rectfill(buffer, 2, 14, 636, 352, BLACK);
     }
     else
     {
          putpixel(buffer,x,y-3,SMOKE);
          circlefill(buffer,x,y,2,BLUE);
     }
         
     unscare_mouse();
     
     curpoint++;
     if (curpoint >= totalpoints)
     {        
          play_sample(samExplosion2, 128, 128, 1000, 0);
          destroyed++;

          explosion2(screen, x, y, BLACK);

          textout_ex( screen, font, "Game Over", 300, 230, makecol( 255, 0, 0), makecol( 0, 0, 0));       
          rest(2000);
          textprintf(screen,font,300,245,makecol(255,255,255), "Final Score=%d", score);
          rest(2000);
          
          stop_sample(samSong);
          stop_sample(samExplosion2);
          
          score=-1;
          
          openscreen();
     }
}
Exemplo n.º 18
0
+=j!=I&&i!=J&&i!=I&&j!=J&&*c(I,J)&&q(p(i),p(j),p(I),p(J));return f;}main(){int i
,I,j,J,f,F,a,b,s=-1,X,Y,H,h;BITMAP*B;SAMPLE*S;allegro_init();*c(0,1)=*c(0,2)=*c(
0,3)=1;set_gfx_mode(GFX_AUTODETECT_WINDOWED,w,w,0,0);install_sound(DIGI_DIRECTX(
0),MIDI_NONE,0);B=create_bitmap(w,w);install_keyboard();install_mouse();*c(2,3)=
*c(1,2)=*c(1,3)=1;text_mode(-1);S=create_sample(8,0,9999,9999);for(i=0;i<9999;i
++){((unsigned char*)S->data)[i]=(((i+(fixsin(i<<13)>>13))%100+(i)%152)*i)/9000;
}for(l=4;l<99;l++){play_sample(S,255,55,1600,0);play_sample(S,255,200,1604,0);
for(i=0;i<l;i++){x[i]=((fixcos((i<<24)/l)*w/3)>>16)+w/2;y[i]=((fixsin((i<<24)/l)
*w/3)>>16)+w/2;}do{F=0;key[KEY_ESC]?exit(0):0;clear_to_color(B,15);for(i=0;i<l;i
++){for(j=0;j<l;j++){f=0;if(*c(j,i)){f=M(i,j);for(a=-1;a<2;a++)for(b=-1;b<2;b++)
line(B,a+p(i)+b,a+p(j)+b,f?12:10);}F|=f;}}for(i=0;i<l;i++){circlefill(B,p(i),8,0
);circlefill(B,p(i),6,s==i?7:8);s=mouse_b?s:-1;if(mouse_b&&s<0&&_(mouse_x-x[i],-
7,7)&&_(mouse_y-y[i],-7,7))s=i;}if(s>=0){x[s]=mouse_x;y[s]=mouse_y;}textprintf(B
,font,10,10,0,"Level %d",l-3);draw_sprite(B,mouse_sprite,mouse_x,mouse_y);blit(B
,screen,0,0,0,0,w,w);}while(F||mouse_b);H=0;for(j=0;j<2000;j++){h=0;x[l]=rand()%
w*2-w/2;y[l]=rand()%w*2-w/2;for(i=0;i<l;i++){h+=M(i,l)==0;}if(h>H){H=h;X=x[l];Y=
y[l];}}x[l]=X;y[l]=Y;for(i=0;i<l;i++){*c(i,l)=M(i,l)==0;*c(rand()%l,rand()%l)=0;
}}}END_OF_MAIN();///////////////////////////////////////////////////////////////
Exemplo n.º 19
0
void CGame::DrawScores(){

	//read + display scores from each player

	int i;
	for (i=0;i<numplayers;i++) {
		textprintf(background,font, 580, ((i+1)*20), players[i].color, "%02d - %s",players[i].score,players[i].name);
	}
	//display player names and scores.. color coded
	rect(background,570,0,SCREEN_W-1,100,players[currplayer].color);

	draw_sprite(background, (WINDOWS_BITMAP *)data[ZEXIT_BMP].dat, SCREEN_W-21,1);

	//draw lines through players name that are out of the game
	for (i=0;i<numplayers;i++) {
		if (!players[i].stillplaying) {
			hline(background,580, ((i+1)*20)+4, 790, players[i].color);
		}
	}
}
Exemplo n.º 20
0
void draw_inventory( Player *p, BITMAP *buffer ) {
	Item *it;
	int x, y, q;

	if ( V_length( p->inventory ) == 0 )
		return;

	if ( (it = (Item *)V_get( p->inventory, p->inv_selection )) == NULL )
		return;
	q = IA_read( p->quantity, p->inv_selection );

	x = s_offset_x + (p->cur_image->w / 2);
	y = s_offset_y - ( (it->image->h / 2) + 15 );

	ellipse( buffer, x, y, it->image->w, it->image->h, 56 );
	ellipse( buffer, x, y, it->image->w+1, it->image->h+1, 54 );
	draw_sprite_center( buffer, it->image, x, y );
	if ( q > 1 ) {
		text_mode( -1 );
		textprintf( buffer, font, x+(p->cur_image->w/4), y+(it->image->h/2), GRAY, "%d", q );
		text_mode( 0 );
	}
}
Exemplo n.º 21
0
Arquivo: gui.c Projeto: cravo/damp
void gui_render_window(int n)
{
   int lb, b, x, y, w, h, li; /* Temp variables and loop counters */


   /* Only render the window if its content has changed */

   if(gui_window[n].content_changed)
   {
      /* reset the content_changed flag */

      gui_window[n].content_changed = FALSE;

      /* Render the window to its bitmap */

      clear_to_color(gui_window[n].bmp,GUI_COLOUR_BACKGROUND);

      /* If the window has a background picture, copy it in */

      if(gui_window[n].picture != NULL)
      {
         blit(gui_window[n].picture,gui_window[n].bmp,0,0,gui_border_size,gui_border_size+gui_titlebar_height,gui_window[n].picture->w,gui_window[n].picture->h);
      }
   
      /* draw border */
      rect(gui_window[n].bmp, 0,0, gui_window[n].bmp->w-1, gui_window[n].bmp->h-1, GUI_COLOUR_SHADOW);
      rect(gui_window[n].bmp, 1,1, gui_window[n].bmp->w-2, gui_window[n].bmp->h-2, GUI_COLOUR_SHADOW);
      line(gui_window[n].bmp, 1,1, gui_window[n].bmp->w-2, 1, GUI_COLOUR_HIGHLIGHT);
      line(gui_window[n].bmp, 1,1, 1, gui_window[n].bmp->h-2, GUI_COLOUR_HIGHLIGHT);
      rect(gui_window[n].bmp, 2,2, gui_window[n].bmp->w-3, gui_window[n].bmp->h-3, GUI_COLOUR_WINDOW);
      rect(gui_window[n].bmp, 3,3, gui_window[n].bmp->w-4, gui_window[n].bmp->h-4, GUI_COLOUR_SHADOW);
      line(gui_window[n].bmp, gui_window[n].bmp->w-4, 3, gui_window[n].bmp->w-4,gui_window[n].bmp->h-4, GUI_COLOUR_HIGHLIGHT);
      line(gui_window[n].bmp, gui_window[n].bmp->w-4, gui_window[n].bmp->h-4,3,gui_window[n].bmp->h-4,GUI_COLOUR_HIGHLIGHT);
   
      /* draw titlebar */
      rectfill(gui_window[n].bmp, 4,4, gui_window[n].bmp->w-5, gui_titlebar_height+4, GUI_COLOUR_WINDOW);
      line(gui_window[n].bmp, 4,gui_titlebar_height+3, gui_window[n].bmp->w-5, gui_titlebar_height+3, GUI_COLOUR_HIGHLIGHT);
      line(gui_window[n].bmp, 4,gui_titlebar_height+4, gui_window[n].bmp->w-5, gui_titlebar_height+4, GUI_COLOUR_SHADOW);
      text_mode(-1);
      textprintf(gui_window[n].bmp, font, 7, 7, GUI_COLOUR_SHADOW, "%s", gui_window[n].title);
      textprintf(gui_window[n].bmp, font, 6, 6, GUI_COLOUR_HIGHLIGHT, "%s", gui_window[n].title);
   
      /* Draw labels */
      for(lb=0;lb<gui_window[n].num_labels;lb++)
      {
         rectfill(gui_window[n].bmp, gui_window[n].label[lb].x+gui_border_size, gui_window[n].label[lb].y+gui_titlebar_height+gui_border_size,
              gui_window[n].label[lb].x+gui_window[n].label[lb].width+gui_border_size, gui_window[n].label[lb].y+gui_window[n].label[lb].height+gui_titlebar_height+gui_border_size, GUI_COLOUR_BACKGROUND);
   
         if(gui_window[n].label[lb].textbox)
         {
            rectfill(gui_window[n].bmp, gui_window[n].label[lb].x+gui_border_size, gui_window[n].label[lb].y+gui_titlebar_height+gui_border_size,
                 gui_window[n].label[lb].x+gui_window[n].label[lb].width+gui_border_size, gui_window[n].label[lb].y+gui_window[n].label[lb].height+gui_titlebar_height+gui_border_size, GUI_COLOUR_HIGHLIGHT);
   
            rect(gui_window[n].bmp, gui_window[n].label[lb].x+gui_border_size, gui_window[n].label[lb].y+gui_titlebar_height+gui_border_size,
                 gui_window[n].label[lb].x+gui_window[n].label[lb].width+gui_border_size, gui_window[n].label[lb].y+gui_window[n].label[lb].height+gui_titlebar_height+gui_border_size, GUI_COLOUR_SHADOW);
         }
   
         textprintf(gui_window[n].bmp, font,
                    gui_window[n].label[lb].x+gui_border_size+2, gui_window[n].label[lb].y+gui_titlebar_height+gui_border_size+2,
                    GUI_COLOUR_SHADOW, "%s", gui_window[n].label[lb].caption);
      }

      /* Draw buttons */
      for(b=0;b<gui_window[n].num_buttons;b++)
      {
         rectfill(gui_window[n].bmp, gui_window[n].button[b].x+gui_border_size, gui_window[n].button[b].y+gui_titlebar_height+gui_border_size,
              gui_window[n].button[b].x+gui_window[n].button[b].width+gui_border_size, gui_window[n].button[b].y+gui_window[n].button[b].height+gui_titlebar_height+gui_border_size, GUI_COLOUR_BACKGROUND);
   
         rect(gui_window[n].bmp, gui_window[n].button[b].x+gui_border_size, gui_window[n].button[b].y+gui_titlebar_height+gui_border_size,
              gui_window[n].button[b].x+gui_window[n].button[b].width+gui_border_size, gui_window[n].button[b].y+gui_window[n].button[b].height+gui_titlebar_height+gui_border_size, GUI_COLOUR_SHADOW);
         rect(gui_window[n].bmp, gui_window[n].button[b].x+gui_border_size+1, gui_window[n].button[b].y+gui_titlebar_height+gui_border_size+1,
              gui_window[n].button[b].x+gui_window[n].button[b].width+gui_border_size-1, gui_window[n].button[b].y+gui_window[n].button[b].height+gui_titlebar_height+gui_border_size-1, gui_window[n].button[b].pressed ? GUI_COLOUR_HIGHLIGHT : GUI_COLOUR_SHADOW);

         line(gui_window[n].bmp, gui_window[n].button[b].x+gui_border_size+1, gui_window[n].button[b].y+gui_titlebar_height+gui_border_size+1,
                                 gui_window[n].button[b].x+gui_border_size+1, gui_window[n].button[b].y+gui_titlebar_height+gui_border_size+gui_window[n].button[b].height-1, gui_window[n].button[b].pressed ? GUI_COLOUR_SHADOW : GUI_COLOUR_HIGHLIGHT);
         line(gui_window[n].bmp, gui_window[n].button[b].x+gui_border_size+1, gui_window[n].button[b].y+gui_titlebar_height+gui_border_size+1,
                                 gui_window[n].button[b].x+gui_border_size+1+gui_window[n].button[b].width-2, gui_window[n].button[b].y+gui_titlebar_height+gui_border_size+1, gui_window[n].button[b].pressed ? GUI_COLOUR_SHADOW : GUI_COLOUR_HIGHLIGHT);

         w = text_length(font, gui_window[n].button[n].caption);
         h = text_height(font);
         x = gui_window[n].button[b].x + (gui_window[n].button[b].width/2);
         y = gui_window[n].button[b].y + (gui_window[n].button[b].height/2);
         textprintf(gui_window[n].bmp, font, (x-(w/2))+gui_border_size, (y-(h/2))+gui_titlebar_height+gui_border_size, GUI_COLOUR_SHADOW, gui_window[n].button[b].caption);
      }

      /* draw lists */
      for(b=0;b<gui_window[n].num_lists;b++)
      {
         /* list */
         rectfill(gui_window[n].bmp, gui_window[n].list[b].x+gui_border_size, gui_window[n].list[b].y+gui_titlebar_height+gui_border_size,
              gui_window[n].list[b].x+gui_window[n].list[b].width-10+gui_border_size, gui_window[n].list[b].y+gui_window[n].list[b].height+gui_titlebar_height+gui_border_size, GUI_COLOUR_HIGHLIGHT);
   
         rect(gui_window[n].bmp, gui_window[n].list[b].x+gui_border_size, gui_window[n].list[b].y+gui_titlebar_height+gui_border_size,
              gui_window[n].list[b].x+gui_window[n].list[b].width-10+gui_border_size, gui_window[n].list[b].y+gui_window[n].list[b].height+gui_titlebar_height+gui_border_size, GUI_COLOUR_SHADOW);

         /* slider background */
         rectfill(gui_window[n].bmp, gui_window[n].list[b].x+gui_window[n].list[b].width-10+gui_border_size, gui_window[n].list[b].y+10+gui_titlebar_height+gui_border_size,
              gui_window[n].list[b].x+gui_window[n].list[b].width+gui_border_size, gui_window[n].list[b].y+gui_window[n].list[b].height-10+gui_titlebar_height+gui_border_size, GUI_COLOUR_SHADOW);

         /* slider */
         if(gui_window[n].list[b].num_items == 0)
         {
            rectfill(gui_window[n].bmp, gui_window[n].list[b].x+1+gui_window[n].list[b].width-10+gui_border_size, gui_window[n].list[b].y+1+10+gui_titlebar_height+gui_border_size,
                 gui_window[n].list[b].x-1+gui_window[n].list[b].width+gui_border_size, gui_window[n].list[b].y+gui_window[n].list[b].height-1-10+gui_titlebar_height+gui_border_size, GUI_COLOUR_HIGHLIGHT);
         }else
         {
            y = (gui_window[n].list[b].height-20) * ((float)((float)gui_window[n].list[b].index / (float)gui_window[n].list[b].num_items));
            if(y > gui_window[n].list[b].height - 31)
               y = gui_window[n].list[b].height - 31;
            rectfill(gui_window[n].bmp, gui_window[n].list[b].x+1+gui_window[n].list[b].width-10+gui_border_size, gui_window[n].list[b].y+1+10+y+gui_titlebar_height+gui_border_size,
                 gui_window[n].list[b].x-1+gui_window[n].list[b].width+gui_border_size, gui_window[n].list[b].y+1+10+y+10+gui_titlebar_height+gui_border_size, GUI_COLOUR_HIGHLIGHT);           
         }

         /* list text */
         h = gui_window[n].list[b].index + (gui_window[n].list[b].height/10);
         if(h > gui_window[n].list[b].num_items)
            h = gui_window[n].list[b].num_items;
         x = 0;
         for(li = gui_window[n].list[b].index; li < h; li++)
         {
            w = text_length(font, gui_window[n].list[b].item[li]);
            y = gui_window[n].list[b].y + 2 + (x*10);

            if(w > gui_window[n].list[b].width - 12)
               gui_window[n].list[b].item[li][(gui_window[n].list[b].width/9)+2] = 0;

            textprintf(gui_window[n].bmp, font, gui_window[n].list[b].x + 2+gui_border_size, y+gui_titlebar_height+gui_border_size, GUI_COLOUR_SHADOW, gui_window[n].list[b].item[li]);

            x++;
         }
      }
   }

   /* Copy the window to the gui back-buffer */

   blit(gui_window[n].bmp, gui_buffer, 0,0, gui_window[n].x, gui_window[n].y, gui_window[n].bmp->w, gui_window[n].bmp->h);
}
Exemplo n.º 22
0
/* draws the entire view */
void draw_view()
{
   int SCREEN_W = al_get_display_width();
   int SCREEN_H = al_get_display_height();
   int (*project)(float *f, int *i, int c);
   int r, g, b;
   ALLEGRO_COLOR c;
   int i, n, x, y;
   float point[6];
   int ipoint[6];

   al_clear_to_color(makecol(0, 0, 0));

   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE, al_map_rgba_f(1, 1, 1, 1));

   for (i=0; i<4; i++) {

      view_left   = viewinfo[i].pos[0] * SCREEN_W;
      view_top    = viewinfo[i].pos[1] * SCREEN_H;
      view_right  = viewinfo[i].pos[2] * SCREEN_W;
      view_bottom = viewinfo[i].pos[3] * SCREEN_H;

      if ((view_right > view_left) && (view_bottom > view_top) && 
	  (view_right > 0) && (view_bottom > 0) &&
	  (view_left < SCREEN_W) && (view_top < SCREEN_H)) {

	 switch (i) {

	    case 0:
	       /* flat projection, green */
	       project = project_flat;

	       r = 0;
	       g = 255;
	       b = 0;
	       break;

	    case 1:
	       /* spherical coordinates, yellow */
	       project = project_spherical;

	       r = 255;
	       g = 255;
	       b = 0;
	       break;

	    case 2:
	       /* inside a tube, blue */
	       project = project_tube;

	       r = 0;
	       g = 0;
	       b = 255;
	       break;

	    case 3:
	       /* surface of cylinder, red */
	       project = project_cylinder;

	       r = 255;
	       g = 0;
	       b = 0;
	       break;

	    default:
	       /* oops! */
	       assert(FALSE);
	       return;
	 }

	 if (!no_grid) {
	    c = makecol(r/5, g/5, b/5);

	    n = (low_detail) ? 8 : 16;

	    for (x=0; x<=n; x++) {
	       for (y=0; y<=n; y++) {
		  point[0] = (float)x / n;
		  point[1] = (float)y / n;
		  point[2] = (float)(x+1) / n;
		  point[3] = (float)y / n;
		  point[4] = (float)x / n;
		  point[5] = (float)(y+1) / n;

		  if (project(point, ipoint, 6)) {
		     if (x < n)
			line(ipoint[0], ipoint[1], ipoint[2], ipoint[3], c);

		     if ((y < n) && ((x < n) || (i == 0)))
			line(ipoint[0], ipoint[1], ipoint[4], ipoint[5], c);
		  }
	       }
	    }
	 }

	 draw_player(r, g, b, project);
	 draw_badguys(r, g, b, project);
	 draw_bullets(r, g, b, project);
	 draw_explode(r, g, b, project);
      }
   }

   solid_mode();

   draw_message();

   textprintf(font, 4, 4, makecol(128, 128, 128), "Lives: %d", lives);
   textprintf(font, 4, 16, makecol(128, 128, 128), "Score: %d", score);
   textprintf(font, 4, 28, makecol(128, 128, 128), "Hiscore: %d", get_hiscore());

   al_flip_display();
}
Exemplo n.º 23
0
int main(void)
{
  BITMAP *textura, *back_buffer;
  int x, y, c; // para rellenar la textura
  int tecla;
  int nPol;
  int i;
  char angulo_x = 0, angulo_y = 0, angulo_z = 0;
  POLIGONO3D cara[6]; // un cubo
  PUNTO3D ver_t[4]; // v‚rtices transformados para un pol¡gono
  V3D_f ver_p[4]; // v‚rtices proyectados (2d) para un pol¡gono
  PUNTO3D cam_p; // posici¢n de la camara
  VECTOR cam_f; // vector frente de la camara
  VECTOR cam_a; // vector arriba de la camara
  MATRIX_f matriz;

  printf("\nEjemplo de c mara en un solo plano.");
  printf("\n\nControles:");
  printf("\n  Flechas: mover la camara.");
  printf("\n\n\nPresione una tecla para comenzar...\n");
  getch();

  // inicializar allegro y otras cosas
  allegro_init();
  set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
  install_keyboard();
  install_timer();
  install_int(&cont_frames, 1000);
  LOCK_VARIABLE(nFrames);
  LOCK_VARIABLE(nFramesPorSegundo);
  LOCK_FUNCTION(cont_frames);

  back_buffer = create_bitmap(SCREEN_W, SCREEN_H);
  clear(back_buffer);

  // crear una textura
  textura = create_bitmap(TEX_W, TEX_H);
  clear(textura);

  c = 1; // color
  for(x = 0; x < TEX_W; x++) {
    for(y = 0; y < TEX_H; y++) {
      putpixel(textura, x, y, c);
      if(c++ > 64)
        c = 1;
    }
  }

  line(textura, 0, 0, TEX_W, TEX_H, 4);
  line(textura, TEX_W, 0, 0, TEX_H, 4);

  line(textura, 0, 0, 0, TEX_H, 4);
  line(textura, 0, 0, TEX_W, 0, 4);
  line(textura, 0, TEX_H - 1, TEX_W - 1, TEX_H - 1, 4);
  line(textura, TEX_W - 1, TEX_H - 1, TEX_W - 1, 0, 4);

  textprintf(textura, font, 1, 1, 13, "Textura");

  // inicializar las coordenadas 3d del cubo

  cara[0].ver[0].x = -2;
  cara[0].ver[0].y = -2;
  cara[0].ver[0].z = -2;
  cara[0].ver[1].x = 2;
  cara[0].ver[1].y = -2;
  cara[0].ver[1].z = -2;
  cara[0].ver[2].x = 2;
  cara[0].ver[2].y = 2;
  cara[0].ver[2].z = -2;
  cara[0].ver[3].x = -2;
  cara[0].ver[3].y = 2;
  cara[0].ver[3].z = -2;

  cara[1].ver[0].x = 2;
  cara[1].ver[0].y = -2;
  cara[1].ver[0].z = 2;
  cara[1].ver[1].x = -2;
  cara[1].ver[1].y = -2;
  cara[1].ver[1].z = 2;
  cara[1].ver[2].x = -2;
  cara[1].ver[2].y = 2;
  cara[1].ver[2].z = 2;
  cara[1].ver[3].x = 2;
  cara[1].ver[3].y = 2;
  cara[1].ver[3].z = 2;

  cara[2].ver[0].x = -2;
  cara[2].ver[0].y = -2;
  cara[2].ver[0].z = 2;
  cara[2].ver[1].x = -2;
  cara[2].ver[1].y = -2;
  cara[2].ver[1].z = -2;
  cara[2].ver[2].x = -2;
  cara[2].ver[2].y = 2;
  cara[2].ver[2].z = -2;
  cara[2].ver[3].x = -2;
  cara[2].ver[3].y = 2;
  cara[2].ver[3].z = 2;

  cara[3].ver[0].x = 2;
  cara[3].ver[0].y = -2;
  cara[3].ver[0].z = -2;
  cara[3].ver[1].x = 2;
  cara[3].ver[1].y = -2;
  cara[3].ver[1].z = 2;
  cara[3].ver[2].x = 2;
  cara[3].ver[2].y = 2;
  cara[3].ver[2].z = 2;
  cara[3].ver[3].x = 2;
  cara[3].ver[3].y = 2;
  cara[3].ver[3].z = -2;

  cara[4].ver[0].x = -2;
  cara[4].ver[0].y = -2;
  cara[4].ver[0].z = 2;
  cara[4].ver[1].x = 2;
  cara[4].ver[1].y = -2;
  cara[4].ver[1].z = 2;
  cara[4].ver[2].x = 2;
  cara[4].ver[2].y = -2;
  cara[4].ver[2].z = -2;
  cara[4].ver[3].x = -2;
  cara[4].ver[3].y = -2;
  cara[4].ver[3].z = -2;

  cara[5].ver[0].x = -2;
  cara[5].ver[0].y = 2;
  cara[5].ver[0].z = -2;
  cara[5].ver[1].x = 2;
  cara[5].ver[1].y = 2;
  cara[5].ver[1].z = -2;
  cara[5].ver[2].x = 2;
  cara[5].ver[2].y = 2;
  cara[5].ver[2].z = 2;
  cara[5].ver[3].x = -2;
  cara[5].ver[3].y = 2;
  cara[5].ver[3].z = 2;

  // inicializar las coordenadas de la textura
  ver_p[0].u = 0;
  ver_p[0].v = 0;
  ver_p[1].u = TEX_W;
  ver_p[1].v = 0;
  ver_p[2].u = TEX_W;
  ver_p[2].v = TEX_H;
  ver_p[3].u = 0;
  ver_p[3].v = TEX_H;

  // inicializar c mara
  cam_p.x = 0;
  cam_p.y = 0;
  cam_p.z = -35;

  cam_f.x = 0;
  cam_f.y = 0;
  cam_f.z = 1;

  cam_a.x = 0;
  cam_a.y = -1;
  cam_a.z = 0;

  set_projection_viewport(0, 0, SCREEN_W, SCREEN_H);

  do {

    // teclado
    if(key[KEY_RIGHT]) {
      get_rotation_matrix_f(&matriz,
                            0,
                            -1,
                            0);

      apply_matrix_f(&matriz,
                     cam_f.x,
                     cam_f.y,
                     cam_f.z,
                     &cam_f.x,
                     &cam_f.y,
                     &cam_f.z);

    }
    if(key[KEY_LEFT]) {
      get_rotation_matrix_f(&matriz,
                            0,
                            1,
                            0);

      apply_matrix_f(&matriz,
                     cam_f.x,
                     cam_f.y,
                     cam_f.z,
                     &cam_f.x,
                     &cam_f.y,
                     &cam_f.z);

    }
    if(key[KEY_UP]) {
       cam_p.x += cam_f.x;
       cam_p.y += cam_f.y;
       cam_p.z += cam_f.z;
    }
    if(key[KEY_DOWN]) {
       cam_p.x -= cam_f.x;
       cam_p.y -= cam_f.y;
       cam_p.z -= cam_f.z;
    }

    get_camera_matrix_f(&matriz,
                        cam_p.x,
                        cam_p.y,
                        cam_p.z,
                        cam_f.x,
                        cam_f.y,
                        cam_f.z,
                        cam_a.x,
                        cam_a.y,
                        cam_a.z,
                        32,
                        1);


    for(nPol = 0; nPol < 6; nPol++) { // cada pol¡gono

      for(i = 0; i < 4; i++) { // cada v‚rtice del pol¡gono

        // transformaci¢n
        apply_matrix_f(&matriz,
                       cara[nPol].ver[i].x,
                       cara[nPol].ver[i].y,
                       cara[nPol].ver[i].z,
                       &ver_t[i].x,
                       &ver_t[i].y,
                       &ver_t[i].z);

        // proyecci¢n
        persp_project_f(ver_t[i].x,
                        ver_t[i].y,
                        ver_t[i].z,
                        &ver_p[i].x,
                        &ver_p[i].y);

        ver_p[i].z = ver_t[i].z; // requerido para renderizar la textura
      }

      // backface culling
      if(polygon_z_normal_f(&ver_p[0], &ver_p[1], &ver_p[2]) > 0) {
        quad3d_f(back_buffer,
                 POLYTYPE_PTEX,
                 textura,
                 &ver_p[0],
                 &ver_p[1],
                 &ver_p[2],
                 &ver_p[3]);
      }
    }

    textprintf(back_buffer, font, 0, 190, 2, "%d FPS", nFramesPorSegundo);
    blit(back_buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
    nFrames++;
    clear(back_buffer);

  } while(!key[KEY_ESC]);

  allegro_exit();
  return 0;
}
Exemplo n.º 24
0
/**
 * Show object stats information in the armoury
 */
void Item::od_info(int gx, int gy, int gcol)
{
	int type = m_type;
    text_mode(-1);

    textprintf(screen2, font, gx, gy, gcol, "%s", obdata_name(type).c_str());
    gy += 15;

    if (obdata_wayPoints(type) || obdata_isGun(type)) {
      //textprintf(screen2, font, gx + 5, gy, gcol, "%13s %-8s %s",
        textprintf(screen2, font, gx + 0, gy, gcol, "%13s %-8s %10s",
                       _("Firing-Type"), _("Accuracy"), _("TU cost") );
        gy += 10;
        if (obdata_accuracy(type, 0)) {
            textprintf(screen2, font, gx, gy, gcol, "%10s(%d)     %3d%%    %5d%%",
                       _("Auto"), obdata_autoShots(type), obdata_accuracy(type, 0), 
                       obdata_time(type, 0) * obdata_autoShots(type));
            gy += 10;
        }
        if (obdata_accuracy(type, 1)) {
            textprintf(screen2, font, gx, gy, gcol, "%13s     %3d%%    %5d%%",
                       _("Snap"),
                       obdata_accuracy(type, 1), obdata_time(type, 1));
            gy += 10;
        }
        if (obdata_accuracy(type, 2)) {
            textprintf(screen2, font, gx, gy, gcol, "%13s     %3d%%    %5d%%",
                       _("Aimed"),
                       obdata_accuracy(type, 2), obdata_time(type, 2));
            gy += 10;
        }
        gy += 5;
    }

    if (obdata_isHandToHand(type) || obdata_twoHanded(type)) {
        if (obdata_isHandToHand(type)) {
            textprintf(screen2, font, gx, gy, gcol, _("Hand-to-hand weapon") );
            gy += 10;
        }

        if (obdata_twoHanded(type)) {
            textprintf(screen2, font, gx, gy, gcol, _("Two-handed weapon") );
            gy += 10;
       }
       
       gy += 5;
    }
    
	//! Print medical device data 
	if (obdata_isMed(type)) {
		textprintf(screen2, font, gx, gy, gcol, _("Medical item") );
        gy += 10;

		if (obdata_heal(type, 0) && obdata_heal_max(type, 0)) {
			textprintf(screen2, font, gx, gy, gcol, "%13s: %2d%%, max %2d%%",_("Health"), obdata_heal(type, 0), obdata_heal_max(type, 0));
			gy += 10;
		}
		if (obdata_heal(type, 1) && obdata_heal_max(type, 1)) {
			textprintf(screen2, font, gx, gy, gcol, "%13s: %2d%%, max %2d%%",_("Stun"), obdata_heal(type, 1), obdata_heal_max(type, 1));
			gy += 10;
		}
		if (obdata_heal(type, 2) && obdata_heal_max(type, 2)) {
			textprintf(screen2, font, gx, gy, gcol, "%13s: %2d%%, max %2d%%",_("Energy"), obdata_heal(type, 2), obdata_heal_max(type, 2));
			gy += 10;
		}
		if (obdata_heal(type, 3) && obdata_heal_max(type, 3)) {
			textprintf(screen2, font, gx, gy, gcol, "%13s: %2d%%, max %2d%%",_("Morale"), obdata_heal(type, 3), obdata_heal_max(type, 3));
			gy += 10;
		}
	}
	//! End print medical device data
	
    if (obdata_useTime(type) > 0) {
        textprintf(screen2, font, gx, gy, gcol, "%13s: %2d%%",
                    _("Usage TU cost"), obdata_useTime(type));
        gy += 10;
    }
    
    if (obdata_primeTime(type) > 0) {
        textprintf(screen2, font, gx, gy, gcol, "%13s: %2d%%",
                    _("Prime TU cost"), obdata_primeTime(type));
        gy += 10;
    }
    
    if (obdata_throwTime(type) > 0) {
        textprintf(screen2, font, gx, gy, gcol, "%13s: %2d%%",
                    _("Throw TU cost"), obdata_throwTime(type));
        gy += 10;
    }

    if (obdata_damage(type) > 0) {
        textprintf(screen2, font, gx, gy, gcol, "%13s: %3d (%2d%%)",
                   _("Damage"),     obdata_damage(type), obdata_dDeviation(type));
		gy += 10;
		
        textprintf(screen2, font, gx, gy, gcol, "%13s: %s",
                   _("Ammo-Type"), _(get_damage_description()));
        gy += 10;
    }

    if (obdata_isAmmo(type)) {
        textprintf(screen2, font, gx, gy, gcol, "%13s: %3d", 
                   _("Rounds"), obdata_rounds(type));
        gy += 10;
    }
    
    if (obdata_exploRange(type) > 0) {
        textprintf(screen2, font, gx, gy, gcol, "%13s: %3d",
                   _("Blast range"), obdata_exploRange(type));
        gy += 10;
    }
    
    if (obdata_smokeRange(type) > 0) {
        textprintf(screen2, font, gx, gy, gcol, "%13s: %3d",
                   _("Smoke range"), obdata_smokeRange(type));
        gy += 10;
    }
    
    if (obdata_smokeTime(type) > 0) {
        textprintf(screen2, font, gx, gy, gcol, "%13s: %3d",
                   _("Smoke time"), obdata_smokeTime(type));
        gy += 10;
    }

    std::vector<std::string> ammo;
    get_ammo_list(obdata_name(type), ammo);

    for (int i = 0; i < (int)ammo.size(); i++) {
        textprintf(screen2, font, gx, gy, gcol, "%12s%d: %s", 
                   _("Ammo#"), i + 1, ammo[i].c_str());
        gy += 10;
    }

    textprintf(screen2, font, gx, gy, gcol, "%13s: %3d", 
               _("Weight"), obdata_weight(type));
    gy += 10;
    textprintf(screen2, font, gx, gy, gcol, "%13s: %3d", 
               _("Cost"), obdata_cost(type));
    gy += 10;
}
Exemplo n.º 25
0
int main() {

	BITMAP *backbuffer = NULL, *mysha;
	int count = 0;
	int old_time = 0, old_time2 = 0;
	int depth;
	int i;
	int use_alleg = 0;
	
	allegro_init();
	
	install_keyboard();
	install_timer();
	
	set_config_file("examples.cfg");
	depth = get_config_int("examples", "depth", 16);

	set_color_depth(depth);	
	if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
		set_color_depth(16);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
			set_color_depth(15);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
				set_color_depth(32);
				if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
					allegro_message("Unable to set 640x480 screen mode!\n");
					return -1;
				}
			}
		}
	}
	
	mysha = load_bitmap("mysha.pcx", NULL);
	
	if (!mysha) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to load mysha.pcx. Copy it from the allegro examples directory.\n");
		return -2;
	}
	
	backbuffer = create_bitmap(SCREEN_W, SCREEN_H);
	
	if (!backbuffer) {
		destroy_bitmap(mysha);
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Not enough memory to create backbuffer.\n");
		return -3;
	}
	
	LOCK_FUNCTION(the_timer);
	LOCK_VARIABLE(chrono);

	stretch_blit(mysha, backbuffer, 0, 0, mysha->w, mysha->h, 0, 0, SCREEN_W, SCREEN_H);
	
	for (i = 0; i < 4; i++) {
		fade[i].x = (SCREEN_W/2) * (i & 1);
		fade[i].y = (SCREEN_H/2) * (i & 2) >> 1;
		fade[i].fact = rand() & 255;
		fade[i].dir = (rand() & 1) ? 1 : -1;
		fade[i].src = create_sub_bitmap(backbuffer, fade[i].x, fade[i].y, SCREEN_W/2, SCREEN_H/2);
		fade[i].color = makecol((i & 1) * 255, ((i & 2) >> 1) * 255, 0);
	}
		

	install_int(the_timer, 1);
	old_time = chrono;

	while (!key[KEY_ESC]) {
		if (use_alleg) {
			stretch_blit(mysha, backbuffer, 0, 0, mysha->w, mysha->h, 0, 0, SCREEN_W, SCREEN_H);
		}
		textprintf(backbuffer, font, 0, 0, makecol(255, 255, 255), "%s  %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using FBlend", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono);

		if (use_alleg) {
			drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
			for (i = 0; i < 4; i++) {
				set_trans_blender(0, 0, 0, 255 - fade[i].fact);
				rectfill(fade[i].src, 0, 0, fade[i].src->w - 1, fade[i].src->h - 1, fade[i].color);
			}
			drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
		}
		else {
			for (i = 0; i < 4; i++) {
				fblend_fade_to_color(fade[i].src, screen, fade[i].x, fade[i].y, fade[i].color, fade[i].fact);
			}
		}

		if (key[KEY_SPACE]) {
			use_alleg = !use_alleg;
			key[KEY_SPACE] = 0;
			chrono = 0;
			count = 0;
			old_time = 0;
			old_time2 = 0;
		}
		count++;

		old_time2 = chrono;

		
		/* Draw the buffer */
		if (use_alleg) {
			blit(backbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		}
		
		for (i = 0; i < 4; i++) {
			fade[i].fact += fade[i].dir;
			if (fade[i].fact >= 255 || fade[i].fact <= 0)
				fade[i].dir = -fade[i].dir;
			fade[i].fact = MID(0, fade[i].fact, 255);
		}
	}
	for (i = 0; i < 4; i++) {
		destroy_bitmap(fade[i].src);
	}
	
	destroy_bitmap(backbuffer);
	destroy_bitmap(mysha);
	
	return 0;
}
Exemplo n.º 26
0
int main() {
	
	BITMAP *mysha = NULL, *buffer = NULL;
	PARTICLE *particle[NUM_PARTICLES];
	int old_time = 0, old_time2 = 0;
	int i;
	int count = 0;
	int use_alleg = FALSE;
	int depth = 16;
	
	allegro_init();
	
	install_keyboard();
	install_timer();
	
	set_config_file("examples.cfg");
	depth = get_config_int("examples", "depth", 16);

	set_color_depth(depth);	
	if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
		set_color_depth(16);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
			set_color_depth(15);
			if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
				set_color_depth(32);
				if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)) {
					allegro_message("Unable to set 640x480 screen mode!\n");
					return -1;
				}
			}
		}
	}
	
	mysha = load_bitmap("mysha.pcx", NULL);
	
	if (!mysha) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to load mysha.pcx. Copy it from the allegro examples directory.\n");
		return -2;
	}
	
	TRACE("Got here!\n");
	
	for (i = 0; i < NUM_PARTICLES; i++)
		particle[i] = NULL;
		
	TRACE("Still here!\n");
	
	for (i = 0; i < NUM_PARTICLES; i++) {
		int j;
		int r, g, b;
		
		TRACE("Going for particle: %i\n", i);
	
		particle[i] = malloc(sizeof(PARTICLE));		
		if (!particle[i]) {
			TRACE("Out of memory while creating particle!\n");
			goto Error;
		}
		
		TRACE("Clearing particle\n");
		
		memset(particle[i], 0, sizeof(PARTICLE));
		
		TRACE("Creating bitmap\n");
		
		particle[i]->bmp = create_bitmap(64, 64);		
		if (!particle[i]->bmp) {
			TRACE("Out of memory while creating particle bitmap!\n");
			goto Error;
		}
		
		TRACE("Clearing bitmap\n");
			
		clear(particle[i]->bmp);
			
		TRACE("Setting up coordinates\n");
			
		particle[i]->x = rand() % SCREEN_W;
		particle[i]->y = rand() % SCREEN_H;
		particle[i]->vx = rand() % 10 - 5;
		particle[i]->vy = rand() % 10 - 5;
		particle[i]->a = rand() & 255;
		particle[i]->a_dir = 1;
		
		TRACE("Setting up colors\n");
		hsv_to_rgb(rand() % 360, 1, 1, &r, &g, &b);
		
		TRACE("Drawing circles\n");
		
		for (j = 1; j < 31; j++) {
			circle(particle[i]->bmp, 31, 32, j, makecol(r*2/(j+1), g*2/(j+1), b*2/(j+1)));
			circle(particle[i]->bmp, 32, 32, j, makecol(r*2/(j+1), g*2/(j+1), b*2/(j+1)));
		}
	}
	
	LOCK_FUNCTION(the_timer);
	LOCK_VARIABLE(chrono);
		
	buffer = create_bitmap(SCREEN_W, SCREEN_H);
	
	if (!buffer) {
		TRACE("Out of memory while creating back buffer!\n");
		goto Error;
	}
	
	clear(buffer);

	TRACE("Starting...\n");
	
	install_int(the_timer, 1);
	old_time = chrono;
	
	text_mode(0);
	
	do {
		int chrono2;
	
		/* Tile mysha over the screen */
		#ifndef COMPARE_WITH_ALLEGRO
		blit(mysha, buffer, 0, 0, 0, 0, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 320, 0, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 0, 200, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 320, 200, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 0, 400, mysha->w, mysha->h);
		blit(mysha, buffer, 0, 0, 320, 400, mysha->w, mysha->h);
		#endif
		
		if (use_alleg) {		
			for (i = 0; i < NUM_PARTICLES; i++) {
				set_difference_blender(0, 0, 0, particle[i]->a);
				draw_trans_sprite(buffer, particle[i]->bmp, particle[i]->x - particle[i]->bmp->w/2, particle[i]->y - particle[i]->bmp->h/2);
			}
		}
		else {
			for (i = 0; i < NUM_PARTICLES; i++)
				fblend_sub(particle[i]->bmp, buffer, particle[i]->x - particle[i]->bmp->w/2, particle[i]->y - particle[i]->bmp->h/2, particle[i]->a);
		}
		
		if (key[KEY_SPACE]) {
			use_alleg = !use_alleg;
			key[KEY_SPACE] = 0;
			chrono = 0;
			count = 0;
			old_time = 0;
			old_time2 = 0;
		}
		count++;			

		#ifdef COMPARE_WITH_ALLEGRO			
		textprintf(screen, font, 0, 0, makecol(255, 255, 255), "%s  %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using new", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono);
		#else
		textprintf(buffer, font, 0, 0, makecol(255, 255, 255), "%s  %.2f fps (%.3f avg)", use_alleg ? "Using Allegro" : "Using new", (chrono - old_time2) == 0 ? 1000.0 : 1000 / ((double)chrono - old_time2), count * 1000.0 / chrono);
		#endif
							
		old_time2 = chrono;
	
		
		#ifndef COMPARE_WITH_ALLEGRO
		
		/* Draw the buffer */
		blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		
		#endif

		chrono2 = chrono / 40;		
		for (i = old_time/40; i < chrono2; i++) {
			int j;
			for (j = 0; j < NUM_PARTICLES; j++) {
				particle[j]->x += particle[j]->vx;
				particle[j]->y += particle[j]->vy;
				
				if (particle[j]->x <= 0 || particle[j]->x >= SCREEN_W)
					particle[j]->vx = -particle[j]->vx;
				if (particle[j]->y <= 0 || particle[j]->y >= SCREEN_H)
					particle[j]->vy = -particle[j]->vy;
		
				if (particle[j]->a <= 0 || particle[j]->a >= 256)
					particle[j]->a_dir = -particle[j]->a_dir;
					
				particle[j]->a += particle[j]->a_dir;
			}
		}
		old_time = chrono;
		
	} while (!key[KEY_ESC]);
	
	Error:
	
	TRACE("Shutting down.\n");
	
	if (mysha)
		destroy_bitmap(mysha);
	if (buffer)
		destroy_bitmap(buffer);
	
	for (i = 0; i < NUM_PARTICLES; i++) {
		if (particle[i]) {
			if (particle[i]->bmp)
				destroy_bitmap(particle[i]->bmp);
			free(particle[i]);
		}
	}

	set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	
	return 0;	
	
} END_OF_MAIN();
int main(int argc, char *argv[])
{
    int ret = 0;
    int i;

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

    srand(time(NULL));

    for (i=1; i<argc; i++) {

        if (stricmp(argv[i], "-bpp") == 0) {
            if ((i >= argc-1) || (bpp > 0)) {
                usage();
                return 1;
            }

            bpp = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-frames") == 0) {
            if ((i >= argc-1) || (frames > 0)) {
                usage();
                return 1;
            }

            frames = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-size") == 0) {
            if ((i >= argc-2) || (size_x > 0) || (size_y > 0)) {
                usage();
                return 1;
            }

            size_x = atoi(argv[++i]);
            size_y = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-mode") == 0) {
            if ((i >= argc-2) || (mode_x > 0) || (mode_y > 0)) {
                usage();
                return 1;
            }

            mode_x = atoi(argv[++i]);
            mode_y = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-step") == 0) {
            step = TRUE;
        }
        else if (stricmp(argv[i], "-modesel") == 0) {
            modesel = TRUE;
        }
        else if (stricmp(argv[i], "-pregen") == 0) {
            pregen = TRUE;
        }
        else if (stricmp(argv[i], "-o") == 0) {
            if ((i >= argc-1) || (out_file)) {
                usage();
                return 1;
            }

            out_file = argv[++i];
        }
        else if (stricmp(argv[i], "-pal") == 0) {
            if ((i >= argc-1) || (pal_file)) {
                usage();
                return 1;
            }

            pal_file = argv[++i];
        }
        else {
            if ((*argv[i] == '-') || (in_file)) {
                usage();
                return 1;
            }

            in_file = argv[i];
        }
    }

    if (!in_file) {
        usage();
        return 1;
    }

    if ((pregen) && ((frames <= 0) || (step))) {
        allegro_message("The '-pregen' option requires '-frames num' to be specified,\nand cannot be used at the same time as '-step'\n");
        return 1;
    }

    if (!set_video_mode()) {
        ret = 1;
        goto getout;
    }

    the_egg = load_egg(in_file, error);

    if (!the_egg) {
        set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
        allegro_message("%s", error);
        return 1;
    }

    if (size_x <= 0)
        size_x = 128;

    if (size_y <= 0)
        size_y = 128;

    if (pal_file) {
        BITMAP *tmp = load_bitmap(pal_file, pal);

        if (!tmp) {
            set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
            allegro_message("Error reading palette from '%s'\n", pal_file);
            ret = 1;
            goto getout;
        }

        destroy_bitmap(tmp);
    }
    else
        generate_332_palette(pal);

    clear(screen);

    set_palette(pal);

    text_mode(0);

    do {
        if (pregen) {
            textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2-24, makecol(128, 128, 128), "Rendering frame %d/%d", the_egg->frame+1, frames);
            textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2+24, makecol(128, 128, 128), "Please Wait");
        }

        if (update_egg(the_egg, error) != 0) {
            allegro_exit();
            printf("Error running EGG script:\n%s\n\n", error);
            ret = 1;
            goto getout;
        }

        bmp[frame] = create_bitmap(size_x, size_y);

        lay_egg(the_egg, bmp[frame]);

        if (!pregen) {
            vsync();
            blit(bmp[frame], screen, 0, 0, (SCREEN_W-size_x)/2, (SCREEN_H-size_y)/2, size_x, size_y);
            textprintf(screen, font, 0, 0, makecol(128, 128, 128), "Frame %d, %d particles        ", the_egg->frame, the_egg->part_count);
        }

        if ((!pregen) && (!out_file)) {
            destroy_bitmap(bmp[frame]);
            bmp[frame] = NULL;
        }

        frame++;

        if ((step) || (keypressed())) {
            if ((readkey()&0xFF) == 27)
                break;

            clear_keybuf();
        }

    } while (((frames <= 0) || (frame < frames)) && (frame < 4096));

    if (pregen)
        view_animation();

    if (out_file)
        save_animation();

getout:

    if (the_egg)
        destroy_egg(the_egg);

    for (i=0; i<frame; i++)
        if (bmp[frame])
            destroy_bitmap(bmp[frame]);

    return ret;
}
void view_animation()
{
    int f = 0;
    int fps = 30;
    int lastfps = 30;
    int play = FALSE;

    clear(screen);

    LOCK_VARIABLE(counter);
    LOCK_FUNCTION(counter_proc);

    install_int_ex(counter_proc, BPS_TO_TIMER(fps));

    for (;;) {
        vsync();
        blit(bmp[f], screen, 0, 0, (SCREEN_W-size_x)/2, (SCREEN_H-size_y)/2, size_x, size_y);
        textprintf(screen, font, 0, 0, makecol(128, 128, 128), "Frame %d, %d fps, arrows/home/end/pgup/pgdn/space to control        ", f+1, fps);

        if (play) {
            while (counter > 0) {
                if (f < frame-1)
                    f++;
                else
                    play = FALSE;

                counter--;
            }
        }
        else
            counter = 0;

        while (keypressed()) {

            switch (readkey()>>8) {

            case KEY_LEFT:
            case KEY_DOWN:
                if (f > 0)
                    f--;
                break;

            case KEY_RIGHT:
            case KEY_UP:
                if (f < frame-1)
                    f++;
                break;

            case KEY_HOME:
                f = 0;
                break;

            case KEY_END:
                f = MAX(frame-1, 0);
                break;

            case KEY_PGDN:
                if (fps > 5)
                    fps--;
                break;

            case KEY_PGUP:
                if (fps < 120)
                    fps++;
                break;

            case KEY_SPACE:
                if (play) {
                    play = FALSE;
                }
                else {
                    play = TRUE;
                    if (f >= frame-1)
                        f = 0;
                }
                break;

            case KEY_ESC:
                return;
            }
        }

        if (fps != lastfps) {
            install_int_ex(counter_proc, BPS_TO_TIMER(fps));
            lastfps = fps;
        }
    }
}
Exemplo n.º 29
0
int main(void)
{

	int i,j,k,x,y;
	//byte bi,bj;
	//byte cursize=1;

	//int cursorx=0,cursory=0;

	//byte spritecont=10,spritecont2=10+16;
	//byte sprconmeno,sprconpiu;
	//byte sprconmeno2,sprconpiu2;

	//byte terrancont=0,solidcont=0;

	//bool speed=false;
	//bool print=false,toggleprint=false;
	//bool moved=false,pushed=false;

	int nlevel;

	BITMAP *buffer;				//	Double-buffering
	BITMAP *textures;			//	Immagine globale delle texture
	BITMAP *sprites[256];		// 	Array degli sprite
	//RGB color[256];

	//char nomefile[30],errmess[20];
	//FILE *fp;


	T_Map mappa;


	strcpy(errmess,"");		// inizializzo la stringa

	if(!mappa.InitLevel()){
		strcpy(errmess,"Impossibile allocare la mappa");
		exit(0);
	}

	/////////// INPUT NOME FILE DELLA MAPPA   ///////////////////////
	printf("\n\t Inserta il nome del file della mappa(senza est.) : ");
	gets(nomefile);
	strcat(nomefile,".map");
	/////////////////////////////////////////////////////////////////

	if(!mappa.SetMapFile){
		printf("\n\t File non trovato");
	}

	nlevel=mappa.RetNLevel();

	printf("\n\t Numero attuale di livelli: %d",nlevel);
	printf("\n\t Inserta il numero di livelli da creare nella mappa:");
	printf("\n\t (0 per non aggiungerne)");
	scanf("%d",&i);
	if(i>0){
		nlevel+=i;
		mappa.SetNLevel(nlevel);
		mappa.AllocMap();
	}

	GameInit();

	textures=create_bitmap(128,128);

	mappa.SetTextureFile("D:\\DJGPP\\Game01\\IndexTxt.txt");

/////// Gestione delle texture... s�, lo so, lo so che sono tile
	for(y=0,i=0;y<16&&i<256;y++){
		for(x=0;x<16&&i<256;x++,i++){
			sprites[i]=create_sub_bitmap(textures,x*UNITX,
								y*UNITY,UNITX,UNITY);
		}
	}


/////////// INIZIALIZZAZIONE MATRICE DELLA FINESTRELLA /////
	for(i=0;i<WIMGY;i++){
		for(j=0;j<WIMGX;j++){
			miniwmask[i][j]=0;
		}
	}

////// INIZIALIZZAZIONE MATRICE DELLA LISTA DELLE TILE/////////////

	for(i=0;i<2;i++){
		for(j=0;j<20;j++){
			spritemask1[i][j]=0;
			spritemask2[i][j]=0;
		}
	}

///////////////// BUFFER PER IL DOUBLE BUFFERING //////////////

	buffer=create_bitmap(SCREEN_W,SCREEN_H);
	//show_mouse(buffer);

	clear_to_color(buffer,DESK_COL);
	//clear_to_color(lvldis,BACKG_COL);

//////////////////////////////////////////////////////////////////


/////////////////////////// PUTTAGGIO  ///////////////////////////

	DrawMainWindow();
	DrawMiniWindow();
	DrawTileLists();

	//show_mouse(buffer);

	blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
	//rectfill(screen,0,0,100,100,5);

//////////////////////////////////////////////////////////////////

////////////////// INPUT E CONTROLLI  ////////////////////////////

	while(!key[KEY_ESC]){

		if(key[KEY_RSHIFT]||key[KEY_LSHIFT]){
			speed=true;
		}else{
			speed=false;
		}
		if(key[KEY_P]){
			cursize=2;
			moved=true;
		}
		if(key[KEY_O]){
			cursize=1;
			moved=true;
		}

		if(key[KEY_SPACE]&&!pushed){
		 	print=true;
			pushed=true;
			moved=true;
		}

		if(key[KEY_T]&&!pushed){
			pushed=true;
			moved=true;
			if(toggleprint){
				toggleprint=false;
			}else{
				toggleprint=true;
			}
		}

		if(key[KEY_LEFT]&&cursorx&&!pushed){
			if(!speed)
				pushed=true;
			cursorx--;
			if(cursize==2&&cursorx)
				cursorx--;
			relx=cursorx*MUNITX;
			moved=true;
		}
		if(key[KEY_RIGHT]&&cursorx<NSPRITEX-cursize&&!pushed){
			if(!speed)
				pushed=true;
			cursorx++;
			if(cursize==2&&cursorx<NSPRITEX-cursize)
				cursorx++;
			relx=cursorx*MUNITX;
			moved=true;
		}
		if(key[KEY_UP]&&cursory&&!pushed){
			if(!speed)
				pushed=true;
			cursory--;
			if(cursize==2&&cursory)
				cursory--;
			rely=cursory*MUNITY;
			moved=true;
		}
		if(key[KEY_DOWN]&&cursory<NSPRITEY-cursize&&!pushed){
			if(!speed)
				pushed=true;
			cursory++;
			if(cursize==2&&cursory<NSPRITEY-cursize)
				cursory++;
			rely=cursory*MUNITY;
			moved=true;
		}

		if(key[KEY_PLUS_PAD]&&!pushed){
			//if(!button[KEY_PLUS_PAD]){
			pushed=true;
			BACKG_COL++;
			moved=true;
			//button[KEY_PLUS_PAD]=true;
			//}
		//}else{
		//	button[KEY_PLUS_PAD]=false;
		}
		if(key[KEY_Z]&&!pushed){
			if(!speed)
				pushed=true;

			//spritecont--;
			//spritecont2--;
			//relx=cursorx*MUNITX;
			moved=true;
		}
		if(key[KEY_X]&&!pushed){
			if(!speed)
				pushed=true;
			//spritecont++;
			//spritecont2++;
			//relx=cursorx*MUNITX;
			moved=true;
		}

		if(key[KEY_A]&&!pushed){
			if(!speed)
				pushed=true;
			if(terrancont>0)
				terrancont--;
			else
				terrancont=MAX_TERR;
			//spritecont2++;
			//relx=cursorx*MUNITX;
			moved=true;
		}
		if(key[KEY_S]&&!pushed){
			if(!speed)
				pushed=true;

			terrancont++;
			if(terrancont>MAX_TERR)
				terrancont=0;
			//spritecont2++;
			//relx=cursorx*MUNITX;
			moved=true;
		}

		if(key[KEY_Q]&&!pushed){
			if(!speed)
				pushed=true;
			if(solidcont>0)
				solidcont--;
			else
				solidcont=MAX_SOLID;
			//spritecont2++;
			//relx=cursorx*MUNITX;
			moved=true;
		}
		if(key[KEY_W]&&!pushed){
			if(!speed)
				pushed=true;

			solidcont++;
			if(solidcont>MAX_SOLID)
				solidcont=0;
			//spritecont2++;
			//relx=cursorx*MUNITX;
			moved=true;
		}

		if(key[KEY_F3]&&!pushed){
			pushed=true;

			fp=fopen(nomefile,"rb");
			if(fp!=NULL){
				if(!mappa.LoadLevel(fp))
					strcpy(errmess,"Unable to load");
				fclose(fp);

				for(i=0,k=0;i<NSPRITEY;i++){
					for(j=0;j<NSPRITEX;j++,k++){
						livello[i][j].solid=mappa.RetSolid(k);
						livello[i][j].terran=mappa.RetTerran(k);
					}
				}

			}

			moved=true;
		}

		if(key[KEY_F2]&&!pushed){
			pushed=true;

			/*
			for(i=0,k=0;i<NSPRITEY;i++){
					for(j=0;j<NSPRITEX;j++,k++){
					mappa.SetSolid(k,livello[i][j].solid);
					mappa.SetTerran(k,livello[i][j].terran);
				}
			}

			for(i=OVER_SPACE,k=0;i<OVER_SPACE+NSPRITEY;i++){
					for(j=LEFT_SPACE;j<LEFT_SPACE+NSPRITEX;j++,k++){
					mappa.SetSprite(k,livello[i][j].sprite);
				}
			}
			*/

			fp=fopen(nomefile,"wb");

			//mappa.SaveLevel(fp);

			fclose(fp);
		}

		if(key[KEY_F7]&&!pushed){
			pushed=true;

			for(i=0,k=0;i<NSPRITEY;i++){
				for(j=0;j<NSPRITEX;j++,k++){
					//fwrite(&livello[i][j],sizeof(level),1,fp);
					livello[i][j].solid=mappa.RetSolid(k);
					livello[i][j].terran=mappa.RetTerran(k);
				}
			}

			moved=true;
		}

		if(key[KEY_F5]&&!pushed){
			pushed=true;

			for(i=0,k=0;i<NSPRITEY;i++){
					for(j=0;j<NSPRITEX;j++,k++){
					mappa.SetSolid(k,livello[i][j].solid);
					mappa.SetTerran(k,livello[i][j].terran);
				}
			}

		}

		if(key[KEY_ENTER]){
			clear_to_color(buffer,0);
			for(i=OVER_SPACE,y=0;i<NSPRITEY-BOTTOM_SPACE;i++,y+=UNITY){
				for(j=LEFT_SPACE,x=0;j<NSPRITEX-RIGHT_SPACE;j++,x+=UNITX){
					blit(sprites[livello[i][j].sprite],buffer,0,0,
							x,y,UNITX,UNITY);
				}
			}
			vsync();
			blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);

			while(!key[KEY_BACKSPACE]);
			moved=true;
		}

		if(print||toggleprint){
			livello[cursory][cursorx].sprite=spritecont;
			livello[cursory][cursorx].terran=terrancont;
			livello[cursory][cursorx].solid=solidcont;

			print=false;
			//stretch_blit(sprites[spritecont],lvldis,0,0,UNITX,UNITY,
			//				cursorx*MUNITX,cursory*MUNITY,MUNITX,MUNITY);
			if(cursize>1){
					livello[cursory][cursorx+1].sprite=spritecont+1;
					livello[cursory][cursorx+1].terran=terrancont;
					livello[cursory][cursorx+1].solid=solidcont;
			//		stretch_blit(sprites[spritecont+1],
			//					lvldis,0,0,UNITX,UNITY,(cursorx+1)*MUNITX,
			//								cursory*MUNITY,MUNITX,MUNITY);

					livello[cursory+1][cursorx].sprite=spritecont2;
					livello[cursory+1][cursorx].terran=terrancont;
					livello[cursory+1][cursorx].solid=solidcont;
			//		stretch_blit(sprites[spritecont2],
			//					lvldis,0,0,UNITX,UNITY,cursorx*MUNITX,
			//								(cursory+1)*MUNITY,MUNITX,MUNITY);

					livello[cursory+1][cursorx+1].sprite=spritecont2+1;
					livello[cursory+1][cursorx+1].terran=terrancont;
					livello[cursory+1][cursorx+1].solid=solidcont;
			//		stretch_blit(sprites[spritecont2+1],
			//					lvldis,0,0,UNITX,UNITY,(cursorx+1)*MUNITX,
			//								(cursory+1)*MUNITY,MUNITX,MUNITY);

			}
		}

		if(moved){
			clear_to_color(buffer,DESK_COL);


				// 	Puttaggio dello schema del livello : ex lvldis
			rectfill(buffer,0,0,XLAR,YLAR,BACKG_COL);
			//blit(lvldis,buffer,0,0,0,0,XLAR,YLAR);
			for(i=0,y=0;i<NSPRITEY;i++,y+=MUNITY){
				for(j=0,x=0;j<NSPRITEX;j++,x+=MUNITX){
					if(livello[i][j].sprite){
						stretch_blit(sprites[livello[i][j].sprite],
							buffer,0,0,UNITX,UNITY,x,y,MUNITX,MUNITY);
					}
				}
			}

				// Rettangoli dello schema

			//rect(buffer,LEFT_SPACE*MUNITX,OVER_SPACE*MUNITY,
			//	XLAR-(RIGHT_SPACE*MUNITX)-1,YLAR-(BOTTOM_SPACE*MUNITY)-1,
			//												CONF_COL);

			rect(buffer,relx,rely,relx+(cursize*MUNITX-1),
									rely+(cursize*MUNITY-1),CURS_COL);

				// Disegno della finestra laterale //
			for(i=cursory-2,bi=0;i<cursory+3;i++,bi++){
				for(j=cursorx-2,bj=0;j<cursorx+3;j++,bj++){
			 		if(i<0||j<0){
						windimg[bi][bj]=0;
					}else{
						windimg[bi][bj]=livello[i][j].sprite;
					}
				}
			}

			for(i=0,y=0;i<WIMGY;i++,y+=UNITY){
				for(j=0,x=SCREEN_W-(WIMGX*UNITX);j<WIMGX;j++,x+=UNITX){
					//temp=;
					blit(sprites[windimg[i][j]],buffer,0,0,x,y,UNITX,UNITY);
				}
			}

				// Se � premuto 'toggleprint' ( che � un Pokemon? )
			if(toggleprint){
				rectfill(buffer,300,110,320,130,CURS_COL);
			}else{
				rectfill(buffer,300,110,320,130,DESK_COL);
			}

			textprintf(buffer,font,250,60,255,"Sol : %d",solidcont);
			textprintf(buffer,font,250,70,255,"Terr: %d",terrancont);

				// Disegno elenco sprite
			if(spritecont>10){
				sprconmeno=spritecont-10;
			}else{
			 	sprconmeno=256-(10-spritecont);
			}
			if(spritecont<246){
				sprconpiu=spritecont+10;
			}else{
			 	sprconpiu=10-(256-spritecont);
			}
			if(spritecont2>10){
				sprconmeno2=spritecont2-10;
			}else{
			 	sprconmeno2=256-(10-spritecont2);
			}
			if(spritecont2<246){
				sprconpiu2=spritecont2+10;
			}else{
			 	sprconpiu2=10-(256-spritecont2);
			}

			for(bi=sprconmeno,bj=sprconmeno2,x=0;bi!=sprconpiu;bi++,bj++,x+=BIGUNITX){
				stretch_blit(sprites[bi],buffer,0,0,UNITX,UNITY,x,
						200,BIGUNITX,BIGUNITY);
				if(cursize>1){
					stretch_blit(sprites[bj],buffer,0,0,
						UNITX,UNITY,x,216,BIGUNITX,BIGUNITY);
				}
			}
			rect(buffer,160,199,160+(cursize*BIGUNITX),
									200+(cursize*BIGUNITY),CURS_COL);

			moved=false;
		}

		if(pushed){
			pushed=false;
			for(i=0;i<128;i++){
				if(key[i]){
					pushed=true;
					break;
				}
			}
		}

		show_mouse(buffer);
		vsync();
		blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
		show_mouse(NULL);
	}

		/// Distruzione Bitmap

	for(i=0;i<256;i++){
		destroy_bitmap(sprites[i]);
		//destroy_bitmap(texture[1][i]);
	}

	destroy_bitmap(textures);
	//destroy_bitmap(lvldis);
	destroy_bitmap(buffer);

	readkey();
	GameExit();

	printf("Programmed with DJGPP RHIDE Allegro");

	puts(errmess);

	getch();


	return 0;

}
Exemplo n.º 30
0
void main()
{
    allegro_init();
    install_keyboard();
    install_mouse();
    install_timer();
    set_color_depth(32);
    set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);
    srand(time(NULL)+clock());
    text_mode(-1);

    buffer = create_bitmap(WIDTH, HEIGHT);

    textprintf_centre(screen, font, 320, 200, WHITE, "-Endless Tower-");

    textprintf_centre(screen, font, 320, 240, WHITE, "press enter to start");

    while (!key[KEY_ENTER])
    {}

    for(int i = 0; i < 13; i++)
    {
        land[i].y = rand() % HEIGHT;
        land[i].x = ((rand()%300)*2) + 20;
        land[i].w = (rand()%20) + 20;
    }
    land[13].y = y + 10;
    land[13].x = x;
    land[13].w = 45;

    rest(50);

    while (!key[KEY_ESC])
    {
        start_time = clock();

        /*game goes here*/
        //move left
        if (key[KEY_LEFT])
                x -= 10;

        //move right
        if (key[KEY_RIGHT])
                x += 10;

        //jump
        if ((!jump)&&(key[KEY_SPACE]))
        {
                jump = true;
                jumpforce = 60;
        }

        if ((jump)&&(key[KEY_SPACE]))
        {
                jumpforce += 1;
        }

        //speed up!
        speed = 3 + (game_time/20000);

        //fall
        if (jump)
        {
                jumpforce -= 3;
        }
        if (!jump)
                jumpforce = -12;
        y -= jumpforce/4;

        //drop platforms down
        add_platform();
        for (int i = 0; i < 14; i++)
        {
                land[i].y += speed;
        }

        //collision
        on_land = 0;
        for (int i = 0; i < 14; i++)
        {
                if ((y > land[i].y - 20)&&(y < land[i].y))
                {
                                if ((x < land[i].x + land[i].w)&&(x > land[i].x - land[i].w))
                                {
                                        if (jumpforce < 5)
                                        {
                                                jump = false;
                                        }
                                        jumpforce = -speed*3;
                                        on_land += 1;
                                }
                }
        }
        if (on_land == 0)
                jump = true;
        //warp
        if (x < 0)
            x = 0;
        if (x > WIDTH)
            x = WIDTH;

        //die
        if (y > HEIGHT)
            return;

        /*drawing goes here*/
        rectfill(buffer, 0, 0, WIDTH, HEIGHT, BLACK);
        circlefill(buffer, x, y, 10, WHITE);
        textprintf(buffer, font, 320, 20, WHITE, "%i'%i", game_time/60000, (game_time/1000)%60);

        for (int i = 0; i < 14; i++)
        {
                hline(buffer, land[i].x - land[i].w, land[i].y, land[i].x + land[i].w, WHITE);
        }

        blit(buffer, screen, 0, 0, 0, 0, WIDTH, HEIGHT);

        game_time += 20;
        while (clock() < start_time + 20)
        {}
    }
    destroy_bitmap(buffer);
    return;
}