Пример #1
0
/*
 * Show players Scores
 */
void NinmanMenu::Score() {
    BITMAP * fundo;
    BITMAP * menu;
    BITMAP * pacman;
    do {
        menu = load_bitmap("Imagens/Score.bmp", NULL);
        fundo = load_bitmap("Imagens/fundo.bmp", NULL);
        pacman = load_bitmap("Imagens/pacman.bmp", NULL);
        textout_centre_ex(menu, font, NinmanConfig::getScore(0), 163, 30, WHITE, -1);
        textout_centre_ex(menu, font, NinmanConfig::getScore(1), 163, 50, WHITE, -1);
        textout_centre_ex(menu, font, NinmanConfig::getScore(2), 163, 70, WHITE, -1);
        textout_centre_ex(menu, font, NinmanConfig::getScore(3), 163, 90, WHITE, -1);
        textout_centre_ex(menu, font, NinmanConfig::getScore(4), 163, 110, WHITE, -1);
        textout_centre_ex(menu, font, NinmanConfig::getScore(5), 163, 130, WHITE, -1);
        textout_centre_ex(menu, font, NinmanConfig::getScore(6), 163, 150, WHITE, -1);
        textout_centre_ex(menu, font, NinmanConfig::getScore(7), 163, 170, WHITE, -1);
        textout_centre_ex(menu, font, NinmanConfig::getScore(8), 163, 190, WHITE, -1);
        textout_centre_ex(menu, font, NinmanConfig::getScore(9), 163, 210, WHITE, -1);
        draw_sprite(fundo, menu, 400 - 164, 350 - 153);
        draw_sprite(fundo, pacman, 215, 440);
        draw_sprite(screen, fundo, 0, 0);
        destroy_bitmap(fundo);
        destroy_bitmap(menu);
        destroy_bitmap(pacman);
        readkey();
    } while (!key[KEY_ESC] && !key[KEY_ENTER]);
}
Пример #2
0
/* let the user input a list of path nodes */
void input_nodes(void)
{
   clear_to_color(screen, makecol(255, 255, 255));

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

   node_count = 1;

   show_mouse(screen);

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

   clear_keybuf();

   for (;;) {
      poll_mouse();

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

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

	    node_count++;
	 }

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

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

   show_mouse(NULL);

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

   clear_keybuf();
}
Пример #3
0
void init_screen_map(screen_t* my_screen){
	my_screen->map.x = 0;
	my_screen->map.y = 0;
	my_screen->map.w = MAP_W;
	my_screen->map.h = MAP_H;
	my_screen->map.background = create_bitmap(my_screen->map.w, my_screen->map.h);
	clear_to_color(my_screen->map.background, makecol(0,0,0));
	textout_centre_ex(my_screen->map.background, font, "--- CAR RACE ----", 400, 200, makecol(204, 0 , 0), makecol(255, 255, 0));
	textout_centre_ex(my_screen->map.background, font, "select your map and go!", 400, 208, makecol(204, 0 , 0), makecol(255, 255, 0));
	textout_ex(my_screen->map.background, font, "City Map", 336, 250, makecol(255, 255, 255), makecol(204, 0 , 0));
	textout_ex(my_screen->map.background, font, "Race Truck", 336, 258, makecol(255, 255, 255), -1);
}
Пример #4
0
void print(int x,int y,Color* col,String s){
    int num=s.leng;
    if(num>6){
        s.remove_char('_');
        String frag;
        for(int i=0;i<num;i+=5){
            frag=s.sub_str(i,((i+4)<(num-1))?i+4:num-1);
            textout_centre_ex(BUFFER,font,frag.str,
                              x,y+i*2,makecol(col->r,col->g,col->b),-1);
        }
    }else{
        textout_centre_ex(BUFFER,font,s.str,x,y,
                          makecol(col->r,col->g,col->b),-1);
    }
}
Пример #5
0
struct optionsinfo goto_options_menu(BITMAP *scrbuffer, DATAFILE *main_data,
                                     DATAFILE *plane_data, struct optionsinfo options,
                                     struct menuinfo options_menu,
                                     struct menuinfo stats_menu)
{
// function controls the options menu

    options_menu.highlight = 0;
    do {
        // reset the selection
        options_menu.selection = -1;

        // draw the options screen
        draw_menu(scrbuffer, main_data, options_menu, options_menu.row, options_menu.col);
        textout_centre_ex(scrbuffer, main_data[FONTLARGE].dat, "Options",
                          SCREEN_W/2, TITLE_ROW*8, GREY+15, -1);
        blit(scrbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

        options_menu = move_menu_cursor(options_menu);

        if (options_menu.selection == 0) {
            // go to the stats menu
            options = goto_stats_menu(scrbuffer, main_data, plane_data, options, stats_menu);
            options_menu.highlight = 0;
        }

    } while (options_menu.selection != options_menu.num_of_options - 1);

    return(options);
}
Пример #6
0
int MainMenu()
{
	clear(screen);

	const char *strings[] = {"PLAY", "OPTIONS", "QUIT"};
	int colorSel = 0xFFFF00;
	int colorNot = 0xFFFFFF;

	int i;
	int y;
	int sel = 0;

	while(true)
	{
		for(i = 0, y = screen->h / 4; i < 3; i++, y += screen->h / 4)
		{
			textout_centre_ex(screen, font, strings[i], 320, y, (i == sel) ? colorSel : colorNot, 0);
		}
		UpdateKeys();
		if(upKey == KeyDown) sel = (sel + 2) % 3;
		if(downKey == KeyDown) sel = (sel + 1) % 3;

		if((aKey == KeyDown) || (sKey == KeyDown) || (xKey == KeyDown) || (cKey == KeyDown)) return sel;
	}
}
Пример #7
0
void ft_button_draw_all(s_drawing *drawing, s_event *event, s_button *buttons)
{
    int i;
    char tmp[1024];

    for (i = 0; i < BUTTON_LAST; ++i)
    {
        s_rect *pos = &buttons[i].pos;

        /* bg */
        if (ft_button_is_vector_in_rect(pos, &event->mousePosPxl))
            rectfill(drawing->g_page, pos->x, pos->y, pos->x+pos->width, pos->y+pos->height, buttons[i].colorBackgroundHover);
        else
            rectfill(drawing->g_page, pos->x, pos->y, pos->x+pos->width, pos->y+pos->height, buttons[i].colorBackgroundDefault);

        rect(drawing->g_page, pos->x, pos->y, pos->x+pos->width, pos->y+pos->height, makecol(128, 128, 128));

        /* text */
        textout_centre_ex(drawing->g_page, font, buttons[i].text, pos->x+pos->width/2, pos->y+pos->height/2-3, makecol(0, 0, 0), -1);

        /* selected */
        if (drawing->actionType == buttons[i].form)
            ft_allegro_line(drawing->g_page, drawing, pos->x+10, pos->y+35, pos->x+90, pos->y+35, makecol(128, 128, 128), FLAG_FAT_LINE);
    }

    /* current color components */
    sprintf(tmp, "Rouge : %d", drawing->color.r);
    textout_right_ex(drawing->g_page, font, tmp, 730, 65-3, makecol(0, 0, 0), -1);
    sprintf(tmp, "Vert : %d", drawing->color.g);
    textout_right_ex(drawing->g_page, font, tmp, 730, 95-3, makecol(0, 0, 0), -1);
    sprintf(tmp, "Bleu : %d", drawing->color.b);
    textout_right_ex(drawing->g_page, font, tmp, 730, 125-3, makecol(0, 0, 0), -1);
}
Пример #8
0
/*
 * Draw player Enter name Scren
 */
void NinmanMenu::DrawStartGame(int y, std::string nome) {
    BITMAP * fundo;
    BITMAP * menu;
    BITMAP * pacman;
    menu = load_bitmap("Imagens/StartGame.bmp", NULL);
    fundo = load_bitmap("Imagens/fundo.bmp", NULL);
    pacman = load_bitmap("Imagens/pacman.bmp", NULL);
    textout_centre_ex(menu, font, "Enter your name:", 163, 30, WHITE, -1);
    textout_centre_ex(menu, font, nome.c_str(), 163, 42, WHITE, -1);
    vline(menu, nome.size() * 4 + 163, 40, 50, WHITE);
    draw_sprite(fundo, menu, 400 - 164, 350 - 153);
    draw_sprite(fundo, pacman, 215, y);
    draw_sprite(screen, fundo, 0, 0);
    destroy_bitmap(fundo);
    destroy_bitmap(menu);
    destroy_bitmap(pacman);
}
Пример #9
0
/*--------------------------------------------------------------*/
void init() {
    allegro_init();
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, XWIN, YWIN, 0, 0);
    clear_to_color(screen, BGC);
    install_keyboard();
    srand(time(NULL));

    rect(screen, XMIN - L - 1, BASE - 1, XMAX + L + 1, TOP + BASE + L + 1, 14);
    textout_centre_ex(screen, font, "SPACE to create a fly", XWIN / 2, YWIN / 2,
                      14, 0);
    textout_centre_ex(screen, font, "ESC exit", XWIN / 2, YWIN / 2 + 30, 14, 0);

    pmux_create_pi(&mxa);
    pmux_create_pi(&mxv);

    ptask_init(SCHED_FIFO, GLOBAL, PRIO_INHERITANCE);
}
Пример #10
0
int main() 
{	
	allegro_init();
	install_keyboard();
	
	set_color_depth(32);
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, width, height, 0, 0);
	
		bialy=makecol(200,200,200);
	czarny=makecol(0,0,0);//ustawienie kodow kolorow
	
	BITMAP *buffer = create_bitmap(width, height);
	clear_to_color(buffer, bialy);
	
	x=width/2;
	y=height/2;//ustawienie mrowki w centrum
	direction=0;//mrowka zwrocona poczatkowo w gore
	
            while (!keypressed()) {             
                  
                  if(getpixel(buffer,x,y)==bialy)//jesli mrowka znajduje sie na polu bialym
                  {
                  //allegro_message("BIALY"); 
                  direction = (direction+3)%4;//obrot w lewo
                  rectfill(buffer,x-0.5*a,y-0.5*a,x+0.5*a,y+0.5*a,czarny);//zamalowanie pola na czarno                                          
                  }
                  else{
                  direction = (direction+5)%4;//obrot w prawo
                  rectfill(buffer,x-0.5*a,y-0.5*a,x+0.5*a,y+0.5*a,bialy);//zamalowanie pola na bialo
                  }
                  
                   x += a*moves[direction][0];
                  y += a*moves[direction][1];//przesuniecie mrowki w zadanym kierunku
                  
                  strcpy(napis,"X: ");
                  strcat(napis,itoa(x,str,10));
                  strcat(napis," Y: ");
                  strcat(napis,itoa(y,str,10));
                  strcat(napis," D: ");
                  strcat(napis,itoa(direction,str,10));
                   textout_centre_ex(buffer, font, napis,
                        SCREEN_W / 2, 0,
                        makecol(255, 0, 0), makecol(0, 0, 0));
                  
                  if(x<0.5*a || y<0.5*a || x>width-0.5*a || y>height-0.5*a)break;
                  //ochrona przed wyjsciem mrowki poza ramy ekranu
                  
                  blit(buffer, screen, 0, 0, 0, 0, 640, 700);//wklejenie bufora na ekran
                  rest(10);//odczekanie pomiêdzy kolejnym ruchem
            }
	readkey();
	destroy_bitmap(buffer);
	
	return 0;
}
Пример #11
0
void base_title_page(BITMAP *scrbuffer, DATAFILE *main_data, DATAFILE *plane_data,
                     struct menuinfo title_menu)
{
// function draws the base options list (ie - the title page)

    draw_menu(scrbuffer, main_data, title_menu, title_menu.row, title_menu.col);
    textout_centre_ex(scrbuffer, main_data[FONTLARGE].dat, "Dogfight", SCREEN_W/2,
                      TITLE_ROW*8, GREY+15, -1);
    blit(scrbuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

}
Пример #12
0
/* draws the spline paths */
void draw_splines(void)
{
   int i;

   acquire_screen();

   clear_to_color(screen, makecol(255, 255, 255));

   textout_centre_ex(screen, font, "Spline curve path", SCREEN_W/2, 8,
		     palette_color[255], palette_color[0]);
   textprintf_centre_ex(screen, font, SCREEN_W/2, 32, palette_color[255],
			palette_color[0], "Curviness = %.2f",
			fixtof(curviness));
   textout_centre_ex(screen, font, "Up/down keys to alter", SCREEN_W/2, 44,
		     palette_color[255], palette_color[0]);
   textout_centre_ex(screen, font, "Space to walk", SCREEN_W/2, 68,
		     palette_color[255], palette_color[0]);
   textout_centre_ex(screen, font, "C to display control points", SCREEN_W/2,
		     92, palette_color[255], palette_color[0]);
   textout_centre_ex(screen, font, "T to display tangents", SCREEN_W/2, 104,
		     palette_color[255], palette_color[0]);

   for (i=1; i<node_count-2; i++)
      draw_spline(nodes[i], nodes[i+1]);

   for (i=1; i<node_count-1; i++) {
      draw_node(i);

      if (show_tangents) {
	 line(screen, nodes[i].x - fixtoi(fixcos(nodes[i].tangent) * 24),
		      nodes[i].y - fixtoi(fixsin(nodes[i].tangent) * 24),
		      nodes[i].x + fixtoi(fixcos(nodes[i].tangent) * 24),
		      nodes[i].y + fixtoi(fixsin(nodes[i].tangent) * 24),
		      palette_color[1]);
      }
   }

   release_screen();
}
Пример #13
0
void NinmanMenu::DrawOptionMenu(int y) {
    BITMAP * fundo;
    BITMAP * menu;
    BITMAP * pacman;
    BITMAP * sprite = load_bitmap("Imagens/Ninman.bmp", NULL);
    BITMAP * FS = load_bitmap("Imagens/ONOFF.bmp", NULL);
    BITMAP* temp = create_bitmap(100, 26);
    clear_to_color(temp, TRANSPARENTE);
    blit(sprite, temp, 0, 0, 3, 3, 100, 26);
    BITMAP * som;
    fundo = load_bitmap("Imagens/fundo.bmp", NULL);
    som = load_bitmap(GetVolumeString(), NULL);
    menu = load_bitmap("Imagens/OptionMenu.bmp", NULL);
    if (NinmanConfig::getFullScreenOption())
        rect(menu, 199, 30, 200 + 29, 30 + 25, WHITE);

    else
        rect(menu, 199 + 31, 30, 200 + 29 + 30, 30 + 25, WHITE);
    pacman = load_bitmap("Imagens/pacman.bmp", NULL);
    textout_centre_ex(menu, font, "Use Left and Right arrow", 163, 285, 255, -1);
    textout_centre_ex(menu, font, "to change settings.", 163, 295, 255, -1);
    textout_centre_ex(menu, font, NinmanConfig::getLab(), 175, 205, WHITE, -1);
    draw_sprite(menu, FS, 200, 30);
    draw_sprite(menu, som, 120, 76);
    draw_sprite(menu, temp, 180, 73 + 65);
    rect(menu, 180 + NinmanConfig::getNimanColor(), 138, 181 + 25 + NinmanConfig::getNimanColor(), 138 + 25, WHITE);
    draw_sprite(fundo, menu, 400 - 163, 350 - 153);
    draw_sprite(fundo, pacman, 215, y);
    draw_sprite(screen, fundo, 0, 0);
    destroy_bitmap(fundo);
    destroy_bitmap(temp);
    destroy_bitmap(sprite);
    destroy_bitmap(menu);
    destroy_bitmap(pacman);
    destroy_bitmap(som);
}
/* 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;
}
Пример #15
0
void interfaceHighScore::displayHighScore()
{
    // Buffer hsBackground
    BITMAP *buffer;
    buffer = create_bitmap(640, 480);
    draw_sprite(buffer, this->hsBackground, 0, 0);

    // Display highscore title.
    textout_centre_ex(buffer, this->hsFont, "SKOR TERTINGGI", 320, 50, makecol(0,0,0), -1);
    // Iterate highScoreData, display each name and score
    list<score *>::iterator it = this->highScoreData.begin();
    for(int i=0; i < this->highScoreData.size(); i++)
    {
        // Display each name
        textprintf_ex(buffer, this->hsFont, HIGHSCORE_ITEM_START_X, HIGHSCORE_ITEM_START_Y + i * HIGHSCORE_ITEM_HEIGHT, makecol(255,255,255), -1, (*it)->readPlayerName().c_str());
        textprintf_ex(buffer, this->hsFont, HIGHSCORE_ITEM_START_X + HIGHSCORE_SCORENUMBER, HIGHSCORE_ITEM_START_Y + i * HIGHSCORE_ITEM_HEIGHT, makecol(255,255,255), -1, "%05d", (*it)->readScore());
        ++it;
    }

    blit(buffer, screen, 0, 0, 0, 0, 640, 480);

}
// Update internal bitmap
void Panel::draw()
{	
	// Default, base class placholder
	if (!m_background)
	{

#if 0
		rectfill( m_surf, 0, 0, m_w, m_h, 0x550055 );

		rect( m_surf, 0, 0, m_w-1, m_h-1, m_pcol );
		line( m_surf, 0, 0, m_w-1, m_h-1, m_pcol );
		line( m_surf, 0, m_h-1, m_w-1, 0, m_pcol );	

		textout_centre_ex(m_surf, font, m_name.c_str(), 
			m_w/2, m_h/2, m_pcol, -1);
#endif 

	}
	else
	{
		blit( m_background, m_surf, 0, 0, 0, 0, m_background->w, m_background->h );
	}
}
Пример #17
0
void draw_shaded_centered_text(BITMAP *bmp, FONT* f, const char* s,
 int x, int y, int r, int g, int b) {
    textout_centre_ex(bmp, f, s, x+1, y+2, makecol(r/4, g/4, b/4), -1);
    textout_centre_ex(bmp, f, s, x  , y+1, makecol(r/2, g/2, b/2), -1);
    textout_centre_ex(bmp, f, s, x-1, y  , makecol(r  , g  , b  ), -1);
}
Пример #18
0
void print_grid(int prot) {
    int i, x, y, k;
    int lev;
    int at, dl;
    char buf[100];

    /*------------------------------------------------------*/
    /* Draw header						*/
    /*------------------------------------------------------*/

    clear_to_color(screen, BGC);
    rect(screen, XMIN_GRID + 30, YMIN_GRID + 1, XMAX_GRID - 30, 40, 4);
    if (prot == PRIO_INHERITANCE)
        sprintf(buf, "Protocol: PRIO_INHERITANCE");
    if (prot == PRIO_CEILING) {
        sprintf(buf, "Protocol: PRIO_CEILING");
    }
    if (prot == NO_PROTOCOL)
        sprintf(buf, "Protocol: NO_PROTOCOL");

    textout_centre_ex(screen, font, buf, 320, 10, 14, 0);
    textout_ex(screen, font, "Normal Exe", XMIN_GRID + 40, 30, COLOR_NORM_EXE,
               BGC);
    textout_ex(screen, font, "resource A", XMIN_GRID + 40 + 100, 30,
               COLOR_SEZ_A, BGC);
    textout_ex(screen, font, "resource B", XMIN_GRID + 40 + 200, 30,
               COLOR_SEZ_B, BGC);

    textout_centre_ex(screen, font, "(ESC to exit)", 320, YWIN - 20, 3, 0);
    sprintf(buf, "Time scale: %4.1f", scale);
    textout_ex(screen, font, buf, XMIN_GRID + 40, 10, 7, 0);

    /*------------------------------------------------------*/
    /* Draw grid						*/
    /*------------------------------------------------------*/

    for (x = OFFSET; x < XMAX_GRID; x += DXGRID / scale)
        for (y = LEV0; y < LEV0 + DLEV * (num_tasks - 1); y += DYGRID)
            putpixel(screen, x, y, GRIDCOL);

    /*------------------------------------------------------*/
    /* Draw task timelines					*/
    /*------------------------------------------------------*/

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

        lev = LEV0 + DLEV * i;
        at = OFFSET;

        sprintf(buf, "T%d", i);
        textout_ex(screen, font, buf, 10, lev - 8, TLCOL, 0);
        line(screen, OFFSET, lev, XMAX_GRID, lev, TLCOL);

        k = 0;
        do {
            at = k * period[i];
            x = OFFSET + at / scale;
            if (x < XMAX_GRID)
                line(screen, x, lev, x, lev - 20, TLCOL);

            dl = at + dline[i];
            x = OFFSET + dl / scale;
            if (x < XMAX_GRID) {
                line(screen, x, lev - 1, x, lev - 15, DLCOL);
                line(screen, x, lev - 1, x - 1, lev - 5, DLCOL);
                line(screen, x, lev - 1, x + 1, lev - 5, DLCOL);
            }
            k++;

        } while (x < XMAX_GRID);
    }
}
Пример #19
0
void draw_shadow_centered_text(
 Torbit& bmp, FONT* f, const char* s, int x, int y, int c, int sc) {
    textout_centre_ex(bmp.get_al_bitmap(), f, s, x+1, y+1, sc, -1);
    textout_centre_ex(bmp.get_al_bitmap(), f, s, x  , y  , c,  -1);
}
Пример #20
0
int main(void)
{
   BITMAP *dbuf;
   BITMAP *b;
   BITMAP *b2;
   int mode = NORMAL;
   float fangle = 0;
   float fscale = 1;
   float inc = 0.002;
   int dir = -1;

   if (allegro_init() != 0) {
      return 1;
   }
   set_color_depth(32);
   install_keyboard();
   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) {
      allegro_message("Could not set graphics mode\n");
      return 1;
   }

   dbuf = create_bitmap(SCREEN_W, SCREEN_H);
   if (!dbuf) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Could not create double buffer\n");
      return 1;
   }

   /* Load the alpha bitmap. This is used for alpha and normal modes */
   set_color_conversion(COLORCONV_KEEP_ALPHA);
   b = load_bitmap("inkblot.tga", NULL);
   if (!b) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Could not load inkblot.tga\n");
      return 1;
   }

   /* Make a non-alpha copy for drawing lit */
   b2 = create_bitmap(b->w, b->h);
   if (!b2) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error creating bitmap\n");
      return 1;
   }
   clear_to_color(b2, makeacol(255, 255, 255, 255));
   set_alpha_blender();
   draw_trans_sprite(b2, b, 0, 0);

   while (!key[KEY_ESC]) {
      fixed angle = ftofix(fangle);
      fixed scale = ftofix(fscale);
      float x = (SCREEN_W-(b->w*fscale))/2;
      float y = (SCREEN_H-(b->h*fscale))/2;

      /* XXX flickers badly due to no buffering */
      clear_to_color(dbuf, makecol(255, 255, 255));
      textout_centre_ex(dbuf, font, "Press 'n' for next mode", SCREEN_W/2, SCREEN_H-30, makecol(0, 0, 0), -1);
      switch (mode) {
         case NORMAL:
            rotate_scaled_sprite(dbuf, b, x, y, angle, scale);
            textout_centre_ex(dbuf, font, "Normal", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1);
            break;
         case ALPHA:
            set_alpha_blender();
            rotate_scaled_sprite_trans(dbuf, b, x, y, angle, scale);
            textout_centre_ex(dbuf, font, "Alpha", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1);
            break;
         case LIT:
            set_trans_blender(255, 0, 0, 0);
            rotate_scaled_sprite_lit(dbuf, b2, x, y, angle, scale, 128);
            textout_centre_ex(dbuf, font, "Lit", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1);
            break;
      }
      blit(dbuf, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

      fangle += 1;
      fscale += dir*inc;
      if (fscale < 0.5) {
         dir = -dir;
         fscale = 0.5;
      }
      else if (fscale > 1) {
         dir = -dir;
         fscale = 1;
      }

      rest(5);

      if (keypressed()) {
         int k = readkey();
         switch (k >> 8) {
            case KEY_N:
               mode++;
               mode %= 3;
               break;
         }
      }
   }

   destroy_bitmap(b);
   destroy_bitmap(b2);
   destroy_bitmap(dbuf);
   return 0;
}
Пример #21
0
void ending()
{
    /*
      *************************
      * WIN THE GAME SEQUENCE *
      *************************
      0    LINK at ZELDA's side
      288  begin WIPE (8px per side per step, each 5 frames)
      363  WIPE complete, DOT out, A/B items out
      QMisc.colors.link_dot = 255;
      show_subscreen_items = false;
      365  first MESSAGE character in
      371  next character in
      407  last character in
      668  LINK out, ZELDA out
      669  LINK in (TRIFORCE overhead), ZELDA in (TRIFORCE overhead)
      733  BLUE flash bg
      734  RED
      735  GREEN
      736  BLACK
      ...
      860  BLACK, LINK out, ZELDA out
      861  LINK in, ZELDA in
      927  first MSG character in
      935  next character in
      1335 last character in
      1461 LINK out, ZELDA out
      1493 begin SCROLL
      */
    
    //get rid off all sprites but Link and Zelda
    items.clear();
    Ewpns.clear();
    Lwpns.clear();
    Sitems.clear();
    chainlinks.clear();
    decorations.clear();
    
    music_stop();
    kill_sfx();
    sfx(WAV_ZELDA);
    Quit=0;
    
    game->set_cheat(game->get_cheat() | (cheat>1)?1:0);
    
    draw_screen_clip_rect_x1=0;
    draw_screen_clip_rect_x2=255;
    draw_screen_clip_rect_y1=0;
    draw_screen_clip_rect_y2=223;
    //draw_screen_clip_rect_show_link=true;
    //draw_screen_clip_rect_show_guys=false;
    
    for(int f=0; f<365; f++)
    {
        if(f==363)
        {
            //363  WIPE complete, DOT out, A/B items out
            QMisc.colors.link_dot = 255;
            show_subscreen_items = false;
            
            for(int i = guys.Count() - 1; i >= 0; i--)
            {
                if(guys.spr(i)->id > gDUMMY9)
                {
                    guys.del(i);
                }
            }
            
            guys.draw(framebuf,true);
            Link.draw(framebuf);
        }
        
        if(f>=288 && ((f-288)%5 == 0))
        {
            //288  begin WIPE (8px per side per step, each 5 frames)
            //TODO::
            draw_screen_clip_rect_x1+=8;
            draw_screen_clip_rect_x2-=8;
            //draw_screen_clip_rect_show_guys=true;
        }
        
        draw_screen(tmpscr);
        advanceframe(true);
        
        if(Quit) return;
    }
    
    clear_bitmap(msgdisplaybuf);
    draw_screen(tmpscr);
    advanceframe(true);
    
    draw_screen_clip_rect_x1=0;
    draw_screen_clip_rect_x2=255;
    //draw_screen_clip_rect_show_guys=false;
    
    char tmpmsg[6][25];
    
    for(int x=0; x<3; x++)
    {
        sprintf(tmpmsg[x], "%.24s", MsgStrings[QMisc.endstring].s+(24*x));
        //    sprintf(tmpmsg[x], "%.24s", MsgStrings[QMisc.endstring].s+(24*x));
        //    strncpy(tmpmsg[x], MsgStrings[QMisc.endstring].s+(24*x), 24);
    }
    
    for(int x=0; x<3; x++)
    {
        sprintf(tmpmsg[x+3], "%.24s", MsgStrings[QMisc.endstring+1].s+(24*x));
        //    strncpy(tmpmsg[x+3], MsgStrings[QMisc.endstring+1].s+(24*x), 24);
    }
    
    if(QMisc.endstring==0)
    {
        putendmsg("THANKS LINK,YOU'RE",32,96,6,noproc);
        putendmsg("THE HERO OF HYRULE.",32,112,6,noproc);
    }
    else
    {
        putendmsg(tmpmsg[0],32,80,6,noproc);
        putendmsg(tmpmsg[1],32,96,6,noproc);
        putendmsg(tmpmsg[2],32,112,6,noproc);
    }
    
    for(int f=408; f<927; f++)
    {
        /*
          668  LINK out, ZELDA out
          669  LINK in (TRIFORCE overhead), ZELDA in (TRIFORCE overhead)
          733  BLUE flash bg
          734  RED
          735  GREEN
          736  BLACK
          ...
          860  BLACK, LINK out, ZELDA out
          861  LINK in, ZELDA in
          */
        if(f==668)
        {
            rectfill(framebuf,120,129,152,145,0);
            blit(framebuf, tmp_bmp, 120,113, 0,0, 32,32);
        }
        
        if(f==860)
        {
            blit(tmp_bmp, framebuf, 0,0, 120,113, 32,32);
        }
        
        if(f==669 || f==861)
        {
            overtile16(framebuf,36,120,129,6,0);//draw Zelda two-handed overhead
            overtile16(framebuf,BSZ?32:29,136,129,6,0);//draw Link two-handed overhead
        }
        
        if(f==733)
        {
            blit(framebuf,scrollbuf,0,playing_field_offset!=0?168:0,0,0,256,passive_subscreen_height);
            
            for(int y=0; y<224; y++)
            {
                for(int x=0; x<256; x++)
                {
                    if(!(framebuf->line[y][x]&15))
                    {
                        framebuf->line[y][x]=16;
                    }
                }
            }
        }
        
        if(f>=733 && f<861)
        {
            static byte flash[4] = {0x12,0x16,0x2A,0x0F};
            RAMpal[16] = NESpal(flash[(f-733)&3]);
            refreshpal=true;
        }
        
        if(f==861)
        {
            blit(scrollbuf,framebuf,0,0,0,playing_field_offset!=0?168:0,256,passive_subscreen_height);
            try_zcmusic((char*)"zelda.nsf", 1, ZC_MIDI_ENDING);
            
            for(int y=0; y<224; y++)
            {
                for(int x=0; x<256; x++)
                {
                    if(framebuf->line[y][x]==16)
                    {
                        framebuf->line[y][x]=0;
                    }
                }
            }
        }
        
        if(f>668 && f!=860)
        {
            put_triforce();
        }
        
        advanceframe(true);
        
        if(Quit)
        {
            return;
        }
    }
    
    if(QMisc.endstring==0)
    {
        putendmsg("FINALLY,",96,160,8,put_triforce);
        putendmsg("PEACE RETURNS TO HYRULE.",32,176,8,put_triforce);
        putendmsg("THIS ENDS THE STORY.",48,200,8,put_triforce);
    }
    else
    {
        putendmsg(tmpmsg[3],32,160,6,noproc);
        putendmsg(tmpmsg[4],32,176,6,noproc);
        putendmsg(tmpmsg[5],32,200,6,noproc);
    }
    
    for(int f=1336; f<1492; f++)
    {
        if(f<1461)
        {
            put_triforce();
        }
        
        if(f==1461)
        {
            blit(tmp_bmp,framebuf,0,0,120,113,32,32);
        }
        
        advanceframe(true);
        
        if(Quit)
        {
            return;
        }
    }
    
    clear_bitmap(scrollbuf);
    blit(framebuf,scrollbuf,0,0,0,0,256,224);
    endingpal();
    // draw the brick
    puttile16(scrollbuf,3,256,0,csBOSS,0);
    
    int len=600*2;
    
    if(game->get_quest()>1)
    {
        len=720*2;
    }
    
    int creditsLine=0;
    int endTextLine=0;
    
    const EndingTextLine* endText;
    int numEndTextLines=0;
    int deathsYPos=-1;
    int timeYPos=-1;
    
    switch(game->get_quest())
    {
    case 1:
        endText=quest1End;
        numEndTextLines=numQuest1EndLines;
        break;
        
    case 2:
        endText=quest2End;
        numEndTextLines=numQuest2EndLines;
        deathsYPos=792;
        break;
        
    case 3:
    case 4:
        endText=quest34End;
        numEndTextLines=numQuest34EndLines;
        deathsYPos=792;
        break;
        
    default:
        endText=customQuestEnd;
        numEndTextLines=numCustomQuestEndLines;
        deathsYPos=784;
        timeYPos=800;
        break;
    }
    
    for(int f=0; f<len; f++)
    {
        if(!(f&15))
        {
            int y=(f>>1)+224;
            
            if(y>240 && y<584)
            {
                brick(24,224);
                brick(224,224);
            }
            
            if(y==240 || y==584)
            {
                for(int x=24; x<=224; x+=8)
                {
                    brick(x,224);
                }
            }
            
            if(creditsLine<numCreditsLines)
            {
                if(y==credits[creditsLine].yPos)
                {
                    textout_ex(scrollbuf,
                               zfont,
                               credits[creditsLine].text,
                               credits[creditsLine].xPos,
                               224,
                               credits[creditsLine].color,
                               0);
                    creditsLine++;
                }
            }
            else
            {
                if(endTextLine<numEndTextLines &&
                   y==endText[endTextLine].yPos)
                {
                    textout_ex(scrollbuf,
                               zfont,
                               endText[endTextLine].text,
                               endText[endTextLine].xPos,
                               224,
                               endText[endTextLine].color,
                               0);
                    endTextLine++;
                }
                else if(y==deathsYPos)
                    textprintf_ex(scrollbuf, zfont, 72, 224, red, 0,
                                  "%-8s -%3d", game->get_name(), game->get_deaths());
                else if(y==timeYPos)
                {
                    if(game->get_timevalid() && !game->get_cheat())
                        textout_centre_ex(scrollbuf, zfont, time_str_med(game->get_time()), 128, 224, blue, 0);
                }
            }
        }
        
        if(f==112)                                              // after subscreen has scrolled away
        {
            init_NES_mode();
            loadpalset(9,pSprite(spPILE));
            endingpal();
        }
        
        if(f&1)
        {
            blit(scrollbuf,scrollbuf,0,1,0,0,256,232);
        }
        
        blit(scrollbuf,framebuf,0,0,0,0,256,224);
        advanceframe(true);
        
        if(Quit)
        {
            return;
        }
        
        load_control_state();
        rSbtn();
    }
Пример #22
0
struct optionsinfo goto_stats_menu(BITMAP *scrbuffer, DATAFILE *main_data,
                                   DATAFILE *plane_data, struct optionsinfo options,
                                   struct menuinfo stats_menu)
{
// function controls the stats options menu and optionally writes options to a file

    FILE *cfgfile;
    char count;
    float increment;
    char option_str[128] = "";

    stats_menu.highlight = 0;
// reset the selection
    stats_menu.selection = -1;

    do {
        // add or minus a set amount depending on which button was pressed
        increment = 0.05;
        if (stats_menu.selectupdn == -1)
            increment *= -1;
        switch (stats_menu.selection) {
        case 1 :
            stats_menu.optionval[1] += increment;
            break; // turn
        case 2 :
            stats_menu.optionval[2] += increment;
            break; // acceleration
        };

        // add or minus a set amount depending on which button was pressed
        increment = 1;
        if (stats_menu.selectupdn == -1)
            increment *= -1;
        switch (stats_menu.selection) {
        case 0 :
            stats_menu.optionval[0] += increment;
            break; // plane
        case 3 :
            stats_menu.optionval[3] += increment;
            break; // min speed
        case 4 :
            stats_menu.optionval[4] += increment;
            break; // max speed
        case 5 :
            stats_menu.optionval[5] += increment;
            break; // num of shots
        case 6 :
            stats_menu.optionval[6] += increment;
            break; // shot life
        case 7 :
            stats_menu.optionval[7] += increment;
            break; // shot lag
        case 8 :
            stats_menu.optionval[8] += increment;
            break; // shot base speed
        case 9 :
            stats_menu.optionval[9] += increment;
            break; // laser len
        case 10:
            stats_menu = reset_type(cfgfile, stats_menu, stats_menu.optionval[0]);
            break;
        };

        // make sure options are within boundaries (boundaries will be different for
        // each option)
        // vehicle
        if (stats_menu.optionval[0] > NUM_OF_VEHICLES-1)
            stats_menu.optionval[0] = 0;
        if (stats_menu.optionval[0] < 0)
            stats_menu.optionval[0] = NUM_OF_VEHICLES-1;
        // turn
        if (stats_menu.optionval[1] > 3.10)
            stats_menu.optionval[1] = 0;
        if (stats_menu.optionval[1] < 0)
            stats_menu.optionval[1] = 3.10;
        // acceleration
        if (stats_menu.optionval[2] > stats_menu.optionval[4])
            stats_menu.optionval[2] = 0.05;
        if (stats_menu.optionval[2] < 0)
            stats_menu.optionval[2] = stats_menu.optionval[4];
        // min speed
        if (stats_menu.optionval[3] > stats_menu.optionval[4])
            stats_menu.optionval[3] = -1*stats_menu.optionval[4];
        if (stats_menu.optionval[3] < -1*stats_menu.optionval[4])
            stats_menu.optionval[3] = stats_menu.optionval[4];
        // max speed
        if (stats_menu.optionval[4] > 127)
            stats_menu.optionval[4] = 0;
        if (stats_menu.optionval[4] < 0)
            stats_menu.optionval[4] = 127;
        // num of shots
        if (stats_menu.optionval[5] > 255)
            stats_menu.optionval[5] = 1;
        if (stats_menu.optionval[5] < 1)
            stats_menu.optionval[5] = 255;
        // shot life
        if (stats_menu.optionval[6] > 255)
            stats_menu.optionval[6] = 5;
        if (stats_menu.optionval[6] < 0)
            stats_menu.optionval[6] = 255;
        // shot lag
        if (stats_menu.optionval[7] > 255)
            stats_menu.optionval[7] = 0;
        if (stats_menu.optionval[7] < 0)
            stats_menu.optionval[7] = 255;
        // shot base speed
        if (stats_menu.optionval[8] > 255)
            stats_menu.optionval[8] = 0;
        if (stats_menu.optionval[8] < 0)
            stats_menu.optionval[8] = 255;
        // laser len
        if (stats_menu.optionval[9] > 255)
            stats_menu.optionval[9] = 0;
        if (stats_menu.optionval[9] < 0)
            stats_menu.optionval[9] = 255;

        // draw the options menu
        draw_menu(scrbuffer, main_data, stats_menu, stats_menu.row, stats_menu.col);
        textout_centre_ex(scrbuffer, main_data[FONTLARGE].dat, "Player Statistics",
                          SCREEN_W/2, TITLE_ROW*8, GREY+15, -1);

        // draw the current data next to each option
        draw_sprite(scrbuffer, plane_data[((int)stats_menu.optionval[0])].dat,
                    stats_menu.col+18*8, stats_menu.row-2);
        for (count = 1; count <= 9; count++) {
            sprintf(stats_menu.optionval_str[count], "%2.2f", stats_menu.optionval[count]);
            textout_ex(scrbuffer, font, stats_menu.optionval_str[count],
                       stats_menu.col+18*8, stats_menu.row+count*16, YELLOW+15, -1);
        }

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

        // reset the selection
        stats_menu.selection = -1;
        // allow the user to make another selection
        stats_menu = move_menu_cursor(stats_menu);

    } while (stats_menu.selection != stats_menu.num_of_options-1);

// copy the values back into the options structure
    options.vehicle         = stats_menu.optionval[0];
    options.turn_speed      = stats_menu.optionval[1];
    options.acceleration    = stats_menu.optionval[2];
    options.min_speed       = stats_menu.optionval[3];
    options.max_speed       = stats_menu.optionval[4];
    options.num_of_shots    = stats_menu.optionval[5];
    options.shot_life       = stats_menu.optionval[6];
    options.shot_lag        = stats_menu.optionval[7];
    options.shot_base_speed = stats_menu.optionval[8];
    options.laser_length    = stats_menu.optionval[9];

    return(options);
}
Пример #23
0
void show_ending(void)
{
	char *story_text[30] = {"You wake up in an hospital bed.",
							"A nurse stands beside you.",
							"She says there was a forest fire.", 
							"She says you where the only one alive.",
							"",
							"You know that is not true.",
							"",
							"Your master is with you.",
							"You are one with him now.",
							"The cermony brought you two together.",
							"",
							"Suddenly you feel an urge for human flesh.",
							"",
							"Politly you ask the nurse to come closer...",
							"",
							"END"};
	int end=0;
	int time=0;
	
	int i;

	float alpha=0;
	float a_add=1;
	
	int row=0;

	
	speed_counter = 0;

	alpha = 0;
	a_add=2.5;

	clear(virt);
	
	stop_all_sounds();
	stop_fiend_music();
	
	play_menu_sound("heartbeat",0);

	if(fiend_show_intro)
	{
		while(strcmp(story_text[row],"END")!=0)
		{
		
			while(speed_counter>0)
			{
				
				time++;

			
				if(time%240==0)
				{
					play_menu_sound("heartbeat",0);
					row++;
					if(strcmp(story_text[row],"")==0)row++;
					alpha=0;
				}
			
				alpha+=a_add;
				if(alpha>255)alpha=255;
				if(alpha<0)alpha=0;
			
	
				speed_counter--;
			}
		
			clear(virt);

			textout_ex(virt,font_avalon2->dat,story_text[row], 0,row*25,makecol(alpha,alpha,alpha), -1);

			for(i=0;i<row;i++)
			{
				textout_ex(virt,font_avalon2->dat,story_text[i], 0,i*25,makecol(255,255,255), -1);
			}
			//textout(virt,font_avalon2->dat,text, x2,y2,makecol(alpha2,alpha2,alpha2));
	
			blit(virt,screen,0,0,80,0,480,480);
		}
	

		while(time<310 && !key[KEY_ESC])
		{
			
			while(speed_counter>0)
			{
			
				time++;
			
	
				speed_counter--;
			}
		
		}
	}
	
	end =0;

	alpha = 255;
	
	while(!end)
	{
		
		while(speed_counter>0)
		{
			
			time++;

			if(time>200)alpha-=0.5;

			if(alpha==0)end=1;
			
			if(alpha>255)alpha=255;
			if(alpha<0)alpha=0;
		
			
	
			speed_counter--;
		}
		
		clear(virt);

		textout_centre_ex(virt,font_arial->dat,"T H E   E N D",240,220,makecol(alpha,alpha,alpha), -1);

		blit(virt,screen,0,0,80,0,480,480);
	}


}
Пример #24
0
void triple_buffer(BITMAP **page) {
	int i = 0, w, repeat, active_page = 0;
	int time_diff, bar_number, *used_voices = NULL, hw_voices;
	int text_bar_height, half_bar_size;
	unsigned int radius;
	
	coord_t dot[2], dot_old[2], cal[2], cal_tmp[2];
	
	wiimote *wiimote;
	
	char *fonts[NUM_MAX_FONTS] = FONTS;
	FONT *font_msg, *font_notes;
	BITMAP *background;
	bars *bar;
	
	/* dot_old data initialization. dot_old's X coord is not used */
	dot_old[0].y = SCREEN_H;
	dot_old[1].y = SCREEN_H;
	
	/* Wiimote initialization*/
	wiimote = *wiiuse_init(1);
	
	/* Load fonts, size of font is related to SCREEN_W */
	do {
		font_msg = load_font(fonts[i], NULL, NULL);
		__ASSERT(font_msg, ERROR_CANT_LOAD_FONT(fonts[i]));
		w = text_length(font_msg, WIIMOTE_CONNECTION_MSG);
	} while (w >= SCREEN_W && ++i < (NUM_MAX_FONTS-1));
	
	/* Notes' font is smaller than messages' font */
	font_notes = load_font(fonts[i], NULL, NULL);
	__ASSERT(font_notes, ERROR_CANT_LOAD_FONT(fonts[i]));
	
	/* Initialize and calculate bars size, point radius, text bar height, and calculate half bar size for text output under bars */
	bar = bar_create(NUM_BARS);
	radius = RADIUS(bar);
	text_bar_height = TEXT_BAR_HEIGHT;
	half_bar_size = HALF_BAR_SIZE(bar);
	
	/* Control the max number of available hardware voices. Though ALSA driver voices are up to 64, max hardware voices generally are 8-16. Checking the allocated voices after the driver allocation seems to be the only way */
	hw_voices = get_mixer_voices();
	if (hw_voices < NUM_BARS)
		used_voices = reallocate_voices(bar, hw_voices);
	
	/* Install timer, 10 ticks a second */
	LOCK_VARIABLE(timer);
	LOCK_FUNCTION(inc_timer);
	install_int_ex(inc_timer, BPS_TO_TIMER(10));
	
	/* Load background from file */
	background = load_tga("images/back.tga", NULL);
	__ASSERT(background, ERROR_CANT_LOAD_IMAGE("back.tga"));
	
	/* Enables vertical syncronization*/
	vsync();
	
	i = 0;
	/* First frame, this lasts until wiimote is connected, the user is prompted to activate the wiimote by pressing 1 & 2 keys on the wiimote */
	while(i == 0 && !keypressed()) {
		active_page = start_credits3buf(page, active_page);
		
		clear_keybuf();
		
		title3buf(page, active_page, font_msg);
		
		clear_keybuf();
		
		repeat = 0;
		while(repeat++ < 8 && i == 0 && !keypressed()) {
			stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H); // background
			if(repeat%2 == 1)
				textout_centre_ex(page[active_page], font_msg, WIIMOTE_CONNECTION_MSG, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt
			
			release_bitmap(page[active_page]);
			/* make sure the last flip request has actually happened */
			do {
			} while (poll_scroll());
			
			/* post a request to display the page we just drew */
			request_video_bitmap(page[active_page]);

			/* update counters to point to the next page */
			switch (active_page) {
				case 0: active_page = 1; break;
				case 1: active_page = 2; break;
				case 2: active_page = 0; break;
			}

			/* Search for a wiimote */
			i = wiiuse_find(&wiimote, 1, 1);
		}
	}
	
	/* Try to connect to the wiimote */
	__ASSERT(wiiuse_connect(&wiimote, 1) > 0, ERROR_CANT_OPEN_WIIMOTE);
	
	/* Activate the first led on the wiimote */
	wiiuse_set_leds(wiimote, WIIMOTE_LED_1);
	
	/* Activate the ir module on the wiimote */
	wiiuse_set_ir(wiimote, TRUE);
	
	wiiuse_motion_sensing(wiimote, FALSE);
	
	wiiuse_set_ir_sensitivity(wiimote, 1);
	wiiuse_set_flags(wiimote, WIIUSE_CONTINUOUS, 0);
	
	cal[0].x = 0;
	cal[0].y = 0;
	cal[1].x = 1023;
	cal[1].y = 767;
	
	/* CALIBRATION LOOP */
	for(repeat=0;repeat<2;repeat++) {
		clear_keybuf();
		
		while(!keypressed()) {
			if (wiiuse_poll(&wiimote, 1)) // if there are datas pending from/to wiimote or ESC is pressed
				if (key[KEY_ESC] || wiimote->event == WIIUSE_DISCONNECT || wiimote->event == WIIUSE_UNEXPECTED_DISCONNECT || IS_PRESSED(wiimote, WIIMOTE_BUTTON_HOME)) { // if ESC is pressed, if wiimote update fails, or if HOME key on wiimote is pressed
				wiiuse_disconnect(wiimote);
				destroy_bitmap(background);
				destroy_font(font_msg);
				destroy_font(font_notes);
				for (i=0;i<NUM_BARS;i++) {
					deallocate_voice(bar[i].voice);
					destroy_sample(bar[i].sound);
				}
				free(bar); // YO!! :-)
				free(used_voices);
				
				return;
				}
			/* background */
			stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H);
			
			if (wiimote->ir.dot[0].visible) { // if ir source is visible
				/* Read coords from the wiimote's ir*/
				dot[0] = transpose(wiimote->ir.dot[0], cal, 0);
			}
			
			switch(repeat) {
				case 0:
					textout_centre_ex(page[active_page], font_msg, WIIMOTE_CAL_ASX, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt
					rect(page[active_page], dot[0].x, dot[0].y, SCREEN_W+1, SCREEN_H+1, makecol(0, 0, 0));
					break;
				case 1:
					textout_centre_ex(page[active_page], font_msg, WIIMOTE_CAL_BDX, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt
					
					rect(page[active_page], dot[1].x, dot[1].y, SCREEN_W+1, SCREEN_H+1, makecol(0, 0, 0));
					rect(page[active_page], -1, -1, dot[0].x, dot[0].y, makecol(0, 0, 0));
					break;
			}
			circlefill(page[active_page], dot[0].x, dot[0].y, radius, makecol(0, 0, 0));

			release_bitmap(page[active_page]);
			
			/* make sure the last flip request has actually happened */
			do {
			} while (poll_scroll());

			/* post a request to display the page we just drew */
			request_video_bitmap(page[active_page]);

			/* update counters to point to the next page */
			switch (active_page) {
				case 0: active_page = 1; break;
				case 1: active_page = 2; break;
				case 2: active_page = 0; break;
			}
		}
		
		cal_tmp[repeat].x = wiimote->ir.dot[0].x;
		cal_tmp[repeat].y = wiimote->ir.dot[0].y;
		dot[1] = dot[0];
	}
	
	__ASSERT((cal_tmp[0].x < cal_tmp[1].x && cal_tmp[0].y > cal_tmp[1].y), ERROR_WHILE_CALIBRATING);
	
	cal[0].x = cal_tmp[0].x;
	cal[0].y = 767-cal_tmp[0].y;
	cal[1].x = cal_tmp[1].x;
	cal[1].y = 767-cal_tmp[1].y;
	
	/* MAIN LOOP */
	while (TRUE) {
		/* Draw a frame */
		if (wiiuse_poll(&wiimote, 1) || key[KEY_ESC]) // if there are datas pending from/to wiimote or ESC is pressed
			if (key[KEY_ESC] || wiimote->event == WIIUSE_DISCONNECT || wiimote->event == WIIUSE_UNEXPECTED_DISCONNECT || IS_PRESSED(wiimote, WIIMOTE_BUTTON_HOME)) { // if ESC is pressed, if wiimote update fails, or if HOME key on wiimote is pressed
				wiiuse_disconnect(wiimote);
				destroy_bitmap(background);
				destroy_font(font_msg);
				destroy_font(font_notes);
				for (i=0;i<NUM_BARS;i++) {
					deallocate_voice(bar[i].voice);
					destroy_sample(bar[i].sound);
				}
				free(bar); // YO!! :-)
				free(used_voices);
				
				return;
			}
		
		/* background */
		stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H);
		
		/* Xylophone's bars and notes names */
		for(i=0;i<NUM_BARS;i++) {
			if (bar[i].t_start != -1 && (time_diff = timer-bar[i].t_start) > TICKS_TO_BLACK) // if color animation ends
				bar[i].t_start = -1;
			if (bar[i].t_start == -1) // if no color animation
				bar[i].color = 0;
			else	bar[i].color = COLORVAL(time_diff); // if color animation is running
			
			/* Draw bar */
			rectfill(page[active_page], bar[i].min.x, bar[i].min.y, bar[i].max.x, bar[i].max.y, makecol(bar[i].color, bar[i].color, bar[i].color));
			/* Print bar's associated note */
			textout_centre_ex(page[active_page], font_notes, bar[i].note, (bar[i].min.x + half_bar_size), text_bar_height, makecol(0, 0, 0), -1);
		}
		
		// da normalizzare e da contenere nello schermo, ir
		for(i=0;i<MAX_IR_DOTS;i++) {
			if (wiimote->ir.dot[i].visible) { // if ir source is visible
				/* Read coords from the wiimote's ir*/
				dot[i] = transpose(wiimote->ir.dot[i], cal, radius);
				
				/* If the ir source is under the bars and in previous frame it was above the bars, then play the sound and start the animation */
				if (dot[i].y > bar[0].min.y-radius) {
					if(dot_old[i].y <= bar[0].min.y-radius) {
						/* This calculates on which bar the ir source actually is */
						bar_number = is_onbar(bar, dot[i].x, NUM_BARS);
						
						/* play bar_number's sound with specified volume */
						play_bar_voice(bar, bar_number, volume(dot[i].y-dot_old[i].y), used_voices, hw_voices);
					}
					
					/* The dot have not to go under the bars or out of the screen */
					circlefill(page[active_page], dot[i].x, bar[0].min.y-radius, radius, makecol(0, 0, 0));
				}
				else	circlefill(page[active_page], dot[i].x, dot[i].y, radius, makecol(0, 0, 0));
				
				dot_old[i].y = dot[i].y;
			}
			else dot_old[i].y = SCREEN_H;
		}

		release_bitmap(page[active_page]);

		/* make sure the last flip request has actually happened */
		do {
		} while (poll_scroll());

		/* post a request to display the page we just drew */
		request_video_bitmap(page[active_page]);

		/* update counters to point to the next page */
		switch (active_page) {
			case 0: active_page = 1; break;
			case 1: active_page = 2; break;
			case 2: active_page = 0; break;
		}
	}
}
void Tilemap::SetUpMap(int new_tile[], int new_objects[], Player* player)
{
    erlog("Initialising map");
    if (is_map_loaded) {
        erlog("A map is already loaded");
        //ClearMap();
    }
    int x = 0, y = 0;
    for (int i=0; new_tile[i] != -1 && new_objects[i] != -1; ++i) {
        tiles[x][y].SetTileType(new_tile[i]);
        switch (new_objects[i]) {
            case 0:
            default:
                tiles[x][y].SetObject(NULL);
                break;
            case 1: {
                if (player == NULL) {
                    erlog("Creating new player object");
                    player = new Player;
                    tiles[x][y].SetObject(player);
                }
                else
                    tiles[x][y].SetObject(player);
                player->FaceDirection(up);
                player->SetTileOffset(Vector(0, 32));
                movement_blocker.SetTicks(120);
                if (player->died == false) {
                    player->reward_entered_level_with = player->reward;
                    player->ammo_entered_level_with = player->ammo;
                }
                else
                    player->died = false;

                break;
            }
            case 2: {
                tiles[x][y].SetObject(new NextLevelTrigger);
                break;
            }
            // I've skipped out 3 in case I get around to adding a PrevLevelTrigger. Which would be handy so you could go back and get ammo et, but no time for the mo
            case 4:
                tiles[x][y].SetObject(new Enemy1);
                break;
            case 5:
                tiles[x][y].SetObject(new Enemy2);
                break;
            case 6:
                tiles[x][y].SetObject(new Enemy3);
                break;
            case 7: {
                Civilian* civ = new Civilian;
                civ->SetReward(10);
                civ->SetAnimation("civilian");
                tiles[x][y].SetObject(civ);
                break;
            }
            case 8:
                tiles[x][y].SetObject(new AmmoStash);
                break;
        }
        ++x;
        if (x == (int)tiles.size()) {
            x = 0;
            ++y;
        }
    }

    SetAllVisibilities(0);
    erlog("Map initialised");
    if (grid == NULL) {
        erlog("Creating grid");
        grid = create_bitmap(scr_w, scr_h);

        if (!grid) {
            erlog("Failed to allocate memory");
            return;
        }
        clear_to_color(grid, Colour::MagicPink());
        for (int i=1; i<10; ++i) {
            CrayonLine(grid, Vector(i*tile_dim.XInt(), 0), Vector(i*tile_dim.XInt(), scr_h), Colour::Carbon(), 0.02*((float)rand()/(float)RAND_MAX), 1+((float)rand()/(float)RAND_MAX));
        }
        for (int j=1; j<9; ++j) {
            CrayonLine(grid, Vector(0, j*tile_dim.YInt()), Vector(640, j*tile_dim.YInt()), Colour::Carbon(), 0.02*((float)rand()/(float)RAND_MAX), 1+((float)rand()/(float)RAND_MAX));
        }
    }
    if (citizen_saved == NULL) {
        erlog("Creating messages");
        citizen_saved = create_bitmap(640, 400);
        if (!citizen_saved) {
            erlog("Could not allocate citizen message memory", 3);
            return;
        }
        clear_to_color(citizen_saved, Colour::MagicPink());

        extern bool play_as_good;
        if (play_as_good) {
            textout_centre_ex(citizen_saved, (FONT*)global_datafile[GLOBDAT_large_handwriting_font].dat, "Citizen", citizen_saved->w/2, 0, Colour::GUIGold(), -1);
            textout_centre_ex(citizen_saved, (FONT*)global_datafile[GLOBDAT_large_handwriting_font].dat, "Saved", citizen_saved->w/2, 200, Colour::GUIGold(), -1);
        }
        else {
            textout_centre_ex(citizen_saved, (FONT*)global_datafile[GLOBDAT_large_handwriting_font].dat, "Citizen", citizen_saved->w/2, 0, Colour::BloodRed1(), -1);
            textout_centre_ex(citizen_saved, (FONT*)global_datafile[GLOBDAT_large_handwriting_font].dat, "Slaughtered", citizen_saved->w/2, 200, Colour::BloodRed1(), -1);
        }
    }
    if (blood == NULL)
        blood = create_bitmap(640, 480);

    is_map_loaded = true;
    erlog("Everything else initialised");
}
Пример #26
0
int main(void)
{
 BITMAP *scrbuffer;
 DATAFILE *main_data;
 int vmode_error;

 RGB black = { 0,  0,  0 };

 // initialise allegro
 allegro_init();
 install_keyboard();
 install_timer();
 //install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);

 // load main data file into memory
 main_data = load_datafile("dogfight.dat");

 // use the palette stored in the datafile and
 // set the "clear" colour from a working hot pink to an invisible black
 memcpy(&pal, main_data[MAINPAL].dat, sizeof(pal));

 // enter graphics mode -- don't debug from here --
 vmode_error = set_gfx_mode(GFX_AUTODETECT, SET_W, SET_H, 0, 0);
 if (vmode_error) {
   printf("Error setting graphics mode...\n%s\n\n", allegro_error);
   allegro_exit();
   exit(1);
 }

 set_palette(pal);
 set_color(0, &black);

 // build a colour lookup table for translucent drawing
 // NB: 128 translucency = 50%
 textout_centre_ex(screen, main_data[FONTSMALL].dat, "Dogfight by Gregory McIntyre", SCREEN_W/2, SCREEN_H/2-58, GREY+15, -1);
 textout_centre_ex(screen, font, "Loading. Please wait...", SCREEN_W/2, SCREEN_H/2-20, GREY+15, -1);
 callback_count = 0;
 create_trans_table(&trans_table, main_data[MAINPAL].dat, CLOUD_TRANSPARENCY, CLOUD_TRANSPARENCY, CLOUD_TRANSPARENCY, callback_func);

 // allocate memory for screen buffer
 scrbuffer = create_bitmap(SCREEN_W, SCREEN_H); clear(scrbuffer);

 // when everything is ready fade out and go to the title screen
 fade_out(10);
 title_page(scrbuffer, main_data);

 // free allocated memory and exit allegro
 destroy_bitmap(scrbuffer);

 unload_datafile(main_data);
 allegro_exit();

 // print a message that will be displayed at the DOS prompt on leaving
 printf("Thankyou for playing Dogfight.\n");
 printf("Dogfight was created using the Allegro game library.\n");
 printf("It's free so enjoy and distribute at your leasure.\n\n");

 printf("-------------------------------\n");
 printf("The author can be contacted at:\n\n");
 printf("[email protected]*\n\n");
 printf("-------------------------------\n\n");
 printf("Have a nice day!\n");
 printf("\n");
 printf("* Email no longer valid.\n");
 return 0;
}
Пример #27
0
int main(int argc, char *argv[])
{
	int x, y, en, side, depth, score; 

	// true reversi starts with empty board, but that is not implemented yet!
	// therefore, here is the othello starting arrangement.
	int board[100] =
	{
		2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 0, 0, 0,-1, 1, 0, 0, 0, 2,
		2, 0, 0, 0, 1,-1, 0, 0, 0, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
		2, 2, 2, 2, 2, 2, 2, 2, 2, 2
	};

	if (argc > 1)
	{
		side  = atoi(argv[1]); 
	}
	else
	{
		printf("Insufficient arguments\n\n");
		printf("Syntax: %s {computer's side} [difficulty]\n", argv[0]);
		return 0;
	}
	if (argc == 3)
	{
		// side is the color that the computer plays
		// '1' is black, '-1' white
		// depth is the difficulty, the number of plies.
		depth = atoi(argv[2]);
	}
	else
	{
		depth = 4;
	}
	if (depth % 2 == 0) parity = 1; else parity = -1;

	printf("Computer playing as %c\n", pchar(side));
	printf("Difficulty %i\n", depth);
	printf("Right-click to quit\n");

	if (allegro_init() != 0) return 1;

	install_keyboard();
	install_mouse();
	install_timer();
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 440, 440 + 20, 0, 0))
	{
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to enter graphics mode\n%s\n", allegro_error);
		return 1;
	}
	
	set_palette(desktop_palette);
	clear_to_color(screen, makecol(0, 200, 0)); // green background

	textout_centre_ex(screen, font, "REVERSI", SCREEN_W/2, 10, 
						makecol(0, 0, 0), -1);

	printbd(board);
	printst(board, 0);
	show_mouse(screen);

	if (side == 1)
	{
		// make first move
		findmv(side, board, &en, depth);
		move(board, en, side);
		highlight(en, side);

		printbd(board);
		printst(board, 0);
	}
	// game loop
	while (1)
	{
		if (mouse_b & 1)
		{
			// the user has clicked to place a move
			x = mouse_pos >> 16;
			y = mouse_pos & 0x0000ffff;

			readmv(x, y, &en);
			
			// perform user move
			if (move(board, en, -side))
			{
				// highlight user move
				highlight(en, -side);
				printbd(board);
				printst(board, 0);
				
				// find reply
				score = findmv(side, board, &en, depth);
				if (move(board, en, side))
				{
					highlight(en, side);

					printbd(board);
					printst(board, 0);
				}
			}
			else
			{
				// check and see if user CAN move at all
				en = -1;
				score = findmv(-side, board, &en, depth);
				if (en == -1)
				{
					// computer move instead
					score = findmv(side, board, &en, depth);
					if (move(board, en, side))
					{
						highlight(en, side);

						printbd(board);
						printst(board, 0);
					}
					else
					{
						// Game over
						printst(board, 1);
					}
				}
			}
		}

		if (mouse_b & 2) return 0; // exit on right-click
	}
Пример #28
0
void    print_grid(int policy, int prot)
{
int	i, x, y, k;
int	lev;
int	at, dl;
char	buf[50];

	/*------------------------------------------------------*/
	/* Draw header						*/
	/*------------------------------------------------------*/

	clear_to_color(screen, BGC);
	rect(screen, XMIN+30, YMIN+1, XMAX-30, 40, 4);

	if (policy == SCHED_FIFO)
		sprintf(buf, "TASK schedule produced by SCHED_FIFO");
	if (policy == SCHED_RR)
		sprintf(buf, "TASK schedule produced by SCHED_RR");
	if (policy == SCHED_OTHER)
		sprintf(buf, "TASK schedule produced by SCHED_OTHER");
	textout_centre_ex(screen, font, buf, 320, 10, 14, 0);

	if (prot == PIP) sprintf(buf, "+ PIP");
	if (prot == PCP) sprintf(buf, "+ PCP");
	if (prot != NOP) textout_centre_ex(screen, font, buf, 488, 10, 14, 0);

	textout_centre_ex(screen, font, "(ESC to exit)", 320, 30, 3, 0);
	sprintf(buf, "Time scale: %4.1f", scale);
	textout_ex(screen, font, buf, XMIN+40, 30, 7, 0);

	/*------------------------------------------------------*/
	/* Draw grid						*/
	/*------------------------------------------------------*/

	for (x=OFFSET; x<XMAX; x+=DXGRID/scale)
		for (y=LEV0; y<LEV0+DLEV*(nt-1); y+=DYGRID)
			putpixel(screen, x, y, GRIDCOL);

	/*------------------------------------------------------*/
	/* Draw task timelines					*/
	/*------------------------------------------------------*/

	textout_ex(screen, font, "MAIN", 10, LEV0+5, MAINCOL, 0);
	line(screen, OFFSET, LEV0, XMAX, LEV0, TLCOL);
	line(screen, OFFSET, LEV0, OFFSET, LEV0-10, TLCOL);

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

		lev = LEV0 + DLEV*i;
		at = OFFSET;

		sprintf(buf, "T%d", i);
		textout_ex(screen, font, buf, 10, lev-8, TLCOL, 0);
		line(screen, OFFSET, lev, XMAX, lev, TLCOL);

		k = 0;
		do {
			at = k * period[i];
			x = OFFSET + at/scale;
			if (x < XMAX) line(screen, x, lev, x, lev-20, TLCOL);

			dl = at + dline[i];
			x = OFFSET + dl/scale;
			if (x < XMAX) {
				line(screen, x, lev-1, x, lev-15, DLCOL);
				line(screen, x, lev-1, x-1, lev-5, DLCOL);
				line(screen, x, lev-1, x+1, lev-5, DLCOL);
			}
			k++;

		} while (x < XMAX);
	}
}
int main( int argc, char *argv[] )
{
    BITMAP *lobuf;
    BITMAP *backbuf;    

#ifndef NDEBUG
    // Create a win32 console for printfing
	AllocConsole();

	freopen("CONIN$","rb",stdin);   // reopen stdin handle as console window input
	freopen("CONOUT$","wb",stdout);  // reopen stout handle as console window output
	freopen("CONOUT$","wb",stderr); // reopen stderr handle as console window output
#endif

    //----- Game stuff ---------------

	// the map of the world
    TileMap map( 300 );

	// the chunks of land
	std::vector<TileMap*> landChunks;

    set_color_depth( 32 );

    if (allegro_init() != 0) return 1;
    
    install_keyboard();
    install_timer();
	install_mouse();	

	// install ticker
	LOCK_VARIABLE( ticks );
	LOCK_FUNCTION( ticker );
	install_int_ex( ticker, BPS_TO_TIMER( UPDATES_PER_SEC ) );
    
    if (set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 ) != 0)
    {
        set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
        allegro_message( "Unable to set graphics mode:\n%s\n", 
                         allegro_error );
        return 1;
    }

	enable_hardware_cursor();
	select_mouse_cursor( MOUSE_CURSOR_ARROW );
	

    lobuf = create_bitmap( 320, 240 );    
    backbuf = create_bitmap( SCREEN_W, SCREEN_H );
	show_mouse( backbuf );

//    printf("lobuf %p backbuf %p\n", lobuf, backbuf );    
        
	

    // init gameplay stuff
	srand( time(0));

    //printf("init map...\n" );    
    map.init();
    map.reset();    
	map.do_water = true;

	message( "I woke near the ocean. I didn't even know my own name." );
	message( "So I started exploring (drag RMB to scroll)");

	// load chunks
	loadLandChunks( "gamedata/land.txt", landChunks );
	map.paste( landChunks[0], 148, 148 );

    map.enableSelect( lobuf );   

	// make player
	BITMAP *npcCodeMask = load_bitmap( "gamedata/code_npc.bmp", NULL );
	BITMAP *critterCodeMask = load_bitmap( "gamedata/code_critter.bmp", NULL );
	BITMAP *playerBmp = make_pixbot( npcCodeMask );		

	// Init game objects
	std::vector<GameObj*> gameObjs;

	Player *player = new Player();
	player->m_bmp = playerBmp;
	player->m_x = 150;
	player->m_y = 148;
	gameObjs.push_back( player );
	int currTool = Tool_WALK;	

    //printf("--- mainloop\n" );   
    bool done = false;
	bool dbgShowSelects = false;

	// near center on a 300x300 map
	int view_x = -1644, 
		view_y = -800;
	bool dragging = false;
	int drag_x, drag_y; 	
	int view_drag_x, view_drag_y; 
	int mouse_x2, mouse_y2; // in lobuf coords	
	int last_b = 0;
	int px, py;
	bool doGenerate = true;

    while (!done)
    {
		// handle ticks -- give the ticker a chance to start
		while( ticks==0)
		{
			rest(100 / UPDATES_PER_SEC );
		}
		while ( ticks > 0)
		{
			int old_ticks = ticks;			
			
			//=== Update ====
			map.m_wave_offs++;
						
			if (messageTime>0)
			{
				messageTime--;
				if (messageTime==0)
				{
					strcpy( messageText, "" );					
				}
			} else {
				if (!messageQueue.empty())
				{
					strcpy( messageText, messageQueue.front().c_str() );
					messageQueue.pop_front();
					messageTime = MSG_TIME;
				}
			}

			for (int i=0; i < gameObjs.size(); ++i )
			{
				if (gameObjs[i])
				{
					gameObjs[i]->update( map, gameObjs );				
				}
			}

			// update may have NULL'd objects
			std::vector<GameObj*>::iterator removed;
			removed = std::remove( gameObjs.begin(), gameObjs.end(), (GameObj*)NULL );
			gameObjs.erase( removed, gameObjs.end() );
			

			// update bubbles
			for (int i=0; i < bubbles.size(); i++)
			{
				bubbles[i]->bub_age += 1.0 / (float)UPDATES_PER_SEC;
			}

			ticks--;
			if (old_ticks <= ticks) break;
		}

		int dropBubble = -1;

		// keyboard input
        if (keypressed())
        {
			int k = readkey();
			
			if (cheatsEnabled)
			{
				switch(k>>8) 
				{
					//---- debug keys
					case KEY_F5:
						dbgShowSelects = !dbgShowSelects;
						break;
					case KEY_F6:
						playerBmp = make_pixbot( npcCodeMask );	
						player->m_bmp = playerBmp;
						break;
					case KEY_F7:
						bubbles.push_back( create_bubble( landChunks ) );
						break;
				}				
			}

			switch(k>>8) {			            
				
				case KEY_F11:
					cheatsEnabled = true;
					message("Cheats enabled.");
					break;
				
				//---- game keys
				case KEY_1: dropBubble = 0; break;				
				case KEY_2: dropBubble = 1; break;
				case KEY_3: dropBubble = 2; break;
				case KEY_4: dropBubble = 3; break;
				case KEY_5: dropBubble = 4; break;

				// hack -- on keydown, clear walk wait counter
				case KEY_LEFT:
				case KEY_RIGHT:
				case KEY_UP:
				case KEY_DOWN:
					player->walk_c = 0;
					break;

			}
        }

		if ((dropBubble >= 0) && (dropBubble < bubbles.size()) )
		{
			TileMap *bub = bubbles[dropBubble];
			bubbles[dropBubble] = bubbles[ bubbles.size() -1 ];
			bubbles.pop_back();

			map.paste( bub, 
					   player->m_x - bub->m_size/2, 
					   player->m_y - bub->m_size/2 );
			doGenerate = true;
			delete bub;
		}

		// generate entities
		if (doGenerate)
		{
			doGenerate = false;			

			for (int i=0; i < map.m_size; i++)
			{
				for (int j=0; j < map.m_size; j++)
				{
					if (map.map(i,j).m_gen != Gen_NONE )
					{						
						if (map.map(i,j).m_gen == Gen_BUBBLE)
						{							
							BubbleObj *bubObj = new BubbleObj();
							bubObj->m_x = i;
							bubObj->m_y = j;
							bubObj->m_bub = create_bubble( landChunks );
							bubObj->m_bmp = create_bitmap( 15, 15 );
							BITMAP *bubBmp = bubObj->m_bub->bub_bmp;
							stretch_blit( bubBmp, bubObj->m_bmp, 0,0, bubBmp->w, bubBmp->h, 0,0, 15, 15 );

							gameObjs.push_back( bubObj );
						} else if (map.map(i,j).m_gen == Gen_CRITTER) {
							CritterObj *critObj = new CritterObj();
							critObj->m_x = i;
							critObj->m_y = j;				

							BITMAP *critpic;
							int critNdx = rand() % (critterBmps.size()+1);
							if (critNdx == critterBmps.size())
							{
								// yay new critter
								critpic = make_pixbot( critterCodeMask );
								critterBmps.push_back( critpic );
							}
							else
							{
								critpic = critterBmps[ critNdx ];
							}

							critObj->m_bmp = critpic;

							gameObjs.push_back( critObj );

						} else if (map.map(i,j).m_gen == Gen_NPC) {
							NpcObj *npc = new NpcObj();
							npc->m_x = i;
							npc->m_y = j;							
							npc->m_bmp = make_pixbot( npcCodeMask );							

							gameObjs.push_back( npc );
						}

						map.map(i,j).m_gen = Gen_NONE;
					}
				}
			}
		}
		
		// check for quit
		if (key[KEY_ESC]) {
			exit(0);
			break;
		}

		player->walk_x = 0; player->walk_y = 0;
		if (key[KEY_UP] && !key[KEY_DOWN])
		{
			player->walk_x = 0; player->walk_y = 1;
		}
		else if (!key[KEY_UP] && key[KEY_DOWN])
		{
			player->walk_x = 0; player->walk_y = -1;
		}
		else if (!key[KEY_LEFT] && key[KEY_RIGHT])
		{
			player->walk_x = -1; player->walk_y = 0;
		}
		else if (key[KEY_LEFT] && !key[KEY_RIGHT])
		{
			player->walk_x = 1; player->walk_y = 0;
		}
				
        // Map cursor
		char buff[246];
		int mapX, mapY;
		map.clearSelected();

		mouse_x2 = mouse_x/2;
		mouse_y2 = mouse_y/2;
		if (map.screenToMap( mouse_x2, mouse_y2, mapX, mapY ))
		{
			sprintf( buff, "V %d %d x y %d %d [%d]  -- map %d %d", 
					view_x, view_y, mouse_x, mouse_y, mouse_b, mapX, mapY );

			// NOTE: Don't use mouse selection anymore -- just use selection
			// to mark player
			//map.map( mapX, mapY ).m_selected = true;
		}
		else
		{
			sprintf( buff, "V %d %d x y %d %d  NO TILE", 
					view_x, view_y, mouse_x, mouse_y );
		}

		map.map( player->m_x, player->m_y ).m_selected = true;

		

		// Mouse button 2 -- drag
		if (mouse_b & 0x2)
		{
			if (!dragging)
			{
				dragging = true;
				drag_x = mouse_x2;
				drag_y = mouse_y2;
				view_drag_x = view_x;
				view_drag_y = view_y;
			}
			else
			{
				int dx = mouse_x2 - drag_x;
				int dy = mouse_y2 - drag_y;
				view_x = view_drag_x + dx;
				view_y = view_drag_y + dy;

			}
		}
		else
		{
			dragging = false;
		}

		// button 1 -- use tool (or walk)		
		if (mouse_b & 0x1)
		{
			switch( currTool)
			{
			case Tool_WALK:
				{
					MapCell &cell = map.map(player->m_x, player->m_y );					
					px = cell.sx + 4;
					py = cell.sy + 10;
					
					if ((px < mouse_x2) && (py < mouse_y2 ))
					{
						player->walk_x = -1; player->walk_y = 0;
					}
					else if ((px > mouse_x2) && (py > mouse_y2 ))
					{
						player->walk_x = 1; player->walk_y = 0;
					}
					else if ((px > mouse_x2) && (py < mouse_y2 ))
					{
						player->walk_x = 0; player->walk_y = -1;
					}
					else if ((px < mouse_x2) && (py > mouse_y2 ))
					{
						player->walk_x = 0; player->walk_y = 1;
					}
				}
				break;
			}
		}
		else
		{
			switch( currTool )
			{
			case Tool_WALK:
				if (last_b & 0x01)
				{
					player->walk_x = 0;
					player->walk_y = 0;
				}
				break;
			}
		}
		last_b = mouse_b;

		// ==== draw =====
		rectfill( lobuf, 0, 0, 320, 240, makecol( 135, 171, 189 ) );
        //map.draw( lobuf, 10, 30 );
        map.draw( lobuf, view_x, view_y, gameObjs );        

		// draw bubbles
		int bx = 160 - (bubbles.size() * 12);
		char buf[10];
		for (int i=0; i < bubbles.size(); i++)
		{
			TileMap *b = bubbles[i];
			draw_sprite( lobuf, b->bub_bmp, 
				bx,  215 - (int)(sin(b->bub_age * M_PI)*3) );

			sprintf( buf,"%d", i+1 );
			textout_centre_ex( lobuf, font, buf, bx + 13, 231, makecol( 0x44, 0x66, 0x77 ), -1);
			textout_centre_ex( lobuf, font, buf, bx + 12, 230, makecol( 0xff, 0xff, 0xff ), -1);

			bx += 24;
		}

		//DBG draw player
		//masked_stretch_blit( playerBmp, lobuf, 0, 0, playerBmp->w, playerBmp->h,
		//								10, 20, playerBmp->w * 4, playerBmp->h * 4 );				

        // scale buffer to screen
		stretch_blit( dbgShowSelects?map.m_selectMap:lobuf, backbuf, 
                      0, 0, lobuf->w, lobuf->h,
                      0, 0, SCREEN_W, SCREEN_H );        
        
        
		// Draw text and stuff at full res
		//masked_blit( bubbles[0]->bub_bmp, backbuf, 0, 0, 50, 20, 
		//			 bubbles[0]->bub_bmp->w, bubbles[0]->bub_bmp->h );

		//textout( backbuf, font, buff, 10, 10, makecol( 0xff, 0xff, 0xff ) );

		drawing_mode( DRAW_MODE_TRANS, NULL, 0, 0 );
		set_trans_blender( 0, 0, 0, 128 );
		rectfill( backbuf, 0, 7, 640, 75, makecol( 0xff, 0xff, 0xff ) );
		solid_mode();
		hline( backbuf, 0, 7, 640, makecol( 0, 0, 0x77 ) );
		hline( backbuf, 0, 75, 640, makecol( 0, 0, 0x77 ) );

		// player icon
		masked_stretch_blit( playerBmp, backbuf, 0, 0, playerBmp->w, playerBmp->h,
												10, 10, playerBmp->w * 4, playerBmp->h * 4 );

		//party icons
		for (int i=0; i < npcs.size(); i++)
		{
			BITMAP *npcBmp = npcs[i]->m_bmp;
			masked_stretch_blit( npcBmp, backbuf, 0, 0, npcBmp->w, npcBmp->h,
													70 + 45*i, 10, npcBmp->w * 4, npcBmp->h * 4 );
		}

		if (strlen(messageText))
		{
			float t = (float)messageTime / MSG_TIME;			

			//textout_centre_ex( backbuf, font, messageText, 322, 62, makecol( 0x44, 0x66, 0x77 ), -1 );
			textout_centre_ex( backbuf, font, messageText, 320, 60, 
									makecol( lerp( t, 0x00, 0xcc ), 
											 lerp( t, 0x00, 0xcc ), 
											 lerp( t, 0x00, 0xcc ) ), -1 );
				//makecol( 0x44, 0x66, 0x77 ),
				//makecol( 0xff, 0xff, 0xff ), -1 );
		}

        // flip screen
		vsync();
		acquire_screen();		
        blit( backbuf, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H );        
		release_screen();

		yield_timeslice();
    }

    return 0;
    
}
Пример #30
0
//-----------------------------------------------------------------------------
// Font_PrintCentered (int font_id, BITMAP *dst, const char *text, int x_center, int y, int color)
// Print given string, centered around a given x position
//-----------------------------------------------------------------------------
void    Font_PrintCentered (int font_id, BITMAP *dst, const char *text, int x_center, int y, int color)
{
    if (font_id == -1)
        font_id = FontCurrent->id;
    textout_centre_ex (dst, Fonts[font_id].library_data, text, x_center, y, color, -1);
}