void CreatureWindowObject::Draw() {
	if (!active)
		return;

	// Drawing thumbnail background
	al_draw_filled_rectangle(thumbnailX-2, thumbnailY-2, thumbnailX+thumbnailSize+2, thumbnailY+thumbnailSize+2, DarkerGray);

	// Drawing thumbnail frame
	al_draw_rectangle(thumbnailX, thumbnailY, thumbnailX+thumbnailSize+1, thumbnailY+thumbnailSize+1, DarkGray, 1.0);

	// Drawing thumbnail
	al_draw_bitmap_region(sprite, 32, 0, 32, 32, thumbnailX, thumbnailY, ALLEGRO_ALIGN_CENTER);

	// Drawing label
	al_draw_text(font, Black, labelX + 1, labelY + 2, ALLEGRO_ALIGN_LEFT, label.c_str());
	al_draw_text(font, White, labelX, labelY, ALLEGRO_ALIGN_LEFT, label.c_str());

	// Drawing life bar
	DrawBar(barY, *HP, *maxHP, barFillColor);
}
void Player::Draw(struct rectangle & window) {
    if (this->pImage != NULL) {
        al_draw_bitmap(this->pImage, this->dimensions.x, this->dimensions.y, 0);

#ifdef __DEBUG__
        al_draw_rectangle(this->dimensions.x, this->dimensions.y,
                this->dimensions.width + this->dimensions.x,
                this->dimensions.height + this->dimensions.y,
                al_map_rgb(0, 0, 0), 1.0f);

        al_draw_line(this->dimensions.x + this->dimensions.width / 2,
                this->dimensions.y + this->dimensions.height / 2,
                this->dimensions.x + this->dimensions.width / 2
                        + (this->forces.x * 25),
                this->dimensions.y + this->dimensions.height / 2
                        + (this->forces.y * 25), al_map_rgb(0, 0, 0), 1.0f);
#endif

    }
}
Beispiel #3
0
void drawHealthBar(int health, ALLEGRO_FONT *font, int pos_x, int pos_y)
{
	//Health bar
	al_draw_rectangle(pos_x - 10, pos_y - 5, pos_x + 41, pos_y - 9, al_map_rgb(0, 0, 0), 1);

	if((health <= 100) && (health > 75))
	{
		al_draw_filled_rectangle(pos_x - 10, pos_y - 6, pos_x - 10 + (health) / 2, pos_y - 9, al_map_rgb(0, 255, 0));
	}

	else if((health <= 75) && (health > 25))
	{
		al_draw_filled_rectangle(pos_x - 10, pos_y - 6, pos_x -10 + (health) / 2, pos_y - 9, al_map_rgb(255, 255, 0));
	}

	else if((health <= 25) && (health >= 0))
	{
		al_draw_filled_rectangle(pos_x - 10 , pos_y - 6, pos_x - 10 + (health) / 2, pos_y - 9, al_map_rgb(255, 0, 0));
	}
}
Beispiel #4
0
static void draw_mouse_button(int but, bool down)
{
   const int offset[NUM_BUTTONS] = {0, 70, 35, 105, 140};
   ALLEGRO_COLOR grey;
   ALLEGRO_COLOR black;
   int x;
   int y;
   
   x = 400 + offset[but];
   y = 130;

   grey = al_map_rgb(0xe0, 0xe0, 0xe0);
   black = al_map_rgb(0, 0, 0);

   al_draw_filled_rectangle(x, y, x + 27, y + 42, grey);
   al_draw_rectangle(x + 0.5, y + 0.5, x + 26.5, y + 41.5, black, 0);
   if (down) {
      al_draw_filled_rectangle(x + 2, y + 2, x + 25, y + 40, black);
   }
}
Beispiel #5
0
void Button::Draw() {
	// if button is being hovered use a different button color
	ALLEGRO_COLOR buttonColor;
	switch (beingHovered) {
	case false:
		buttonColor = White;
		break;
	case true:
		buttonColor = LightBlue;
		break;
	}

	// drawing button background
	al_draw_filled_rectangle(realX - width/2.0, realY, realX + width/2.0, realY + height, buttonColor);

	// drawing button contour
	al_draw_rectangle(realX - width/2.0, realY, realX + width/2.0, realY + height, DarkGray, 1.0);

	// printing label
	al_draw_text(font, Black, realX, realY + 1, ALLEGRO_ALIGN_CENTER, label.c_str());
}
Beispiel #6
0
void Panel::Render()
{
    if( !Visible )
        return;

    float pts[18] = {
        Position.X,																												Position.Y,
        Position.X,																												Position.Y + Size.Y,
        Position.X + Size.X,																							Position.Y + Size.Y,
        Position.X + Size.X,																							min( Position.Y + CornerCut, Position.Y + Size.Y ),
        max( Position.X + Size.X - CornerCut, Position.X ),								Position.Y,
        Position.X + BorderWidth,																					min( Position.Y + max( CornerCut, FontSize + BorderWidth ) + BorderWidth, Position.Y + Size.Y ),
        Position.X + Size.X - BorderWidth,																min( Position.Y + max( CornerCut, FontSize + BorderWidth ) + BorderWidth, Position.Y + Size.Y - BorderWidth ),
        Position.X + Size.X - BorderWidth,																Position.Y + Size.Y - BorderWidth,
        Position.X + BorderWidth,																					Position.Y + Size.Y - BorderWidth
    };
    int holes[2] = { 5, 9 };

    if( CornerCut == 0 )
    {
        al_draw_filled_rectangle( pts[0], pts[1], pts[4], pts[5], Background );
        if( HasTitle )
        {
            al_draw_filled_rectangle( pts[0], pts[1], pts[4], Position.Y + FontSize + BorderWidth, Border );
            al_draw_text( Fonts->GetFont( FontName, FontSize, FontFlags ), Foreground, Position.X + BorderWidth, Position.Y + BorderWidth, 0, Title.c_str() );
        }
        al_draw_rectangle( pts[0], pts[1], pts[4], pts[5], Border, BorderWidth );
    } else {
        if( HasTitle )
        {
            al_draw_filled_polygon_with_holes( (float*)&pts, 9, (int*)&holes, 2, Border );
            al_draw_filled_rectangle( pts[10], pts[11], pts[14], pts[15], Background );
            al_draw_text( Fonts->GetFont( FontName, FontSize, FontFlags ), Foreground, Position.X + (BorderWidth * 2), Position.Y + BorderWidth, 0, Title.c_str() );
        } else {
            al_draw_filled_polygon( (float*)&pts, 5, Background );
            al_draw_polygon( (float*)&pts, 5, ALLEGRO_LINE_JOIN_MITER, Border, BorderWidth, 2 );
        }
    }

}
void Figura_Zawijak_Prawy::DrawNext ()
{
	switch(Position)
	{

		case 0:

			al_draw_filled_rectangle( 625 , 75 , 675 , 125 , Figura[0].color ) ;
			al_draw_rectangle		( 625 , 75 , 675 , 125 , al_map_rgb( 0 , 0 , 0 ) , 5) ;
	
			al_draw_filled_rectangle( 675 , 125 , 725 , 175 , Figura[0].color ) ;
			al_draw_rectangle		( 675 , 125 , 725 , 175 , al_map_rgb( 0 , 0 , 0 ) , 5) ;

			al_draw_filled_rectangle( 675 , 75 , 725 , 125 , Figura[0].color ) ;
			al_draw_rectangle		( 675 , 75 , 725 , 125 , al_map_rgb( 0 , 0 , 0 ) , 5) ;

			al_draw_filled_rectangle( 725 , 125 , 775 , 175 , Figura[0].color ) ;
			al_draw_rectangle		( 725 , 125 , 775 , 175 , al_map_rgb( 0 , 0 , 0 ) , 5) ;
			break ;

		case 1:

			al_draw_filled_rectangle( 700 , 25 , 750 , 75 , Figura[0].color ) ;
			al_draw_rectangle		( 700 , 25 , 750 , 75 , al_map_rgb( 0 , 0 , 0 ) , 5) ;
	
			al_draw_filled_rectangle( 650 , 75 , 700 , 125 , Figura[0].color ) ;
			al_draw_rectangle		( 650 , 75 , 700 , 125 , al_map_rgb( 0 , 0 , 0 ) , 5) ;

			al_draw_filled_rectangle( 700 , 75 , 750 , 125 , Figura[0].color ) ;
			al_draw_rectangle		( 700 , 75 , 750 , 125 , al_map_rgb( 0 , 0 , 0 ) , 5) ;

			al_draw_filled_rectangle( 650 , 125 , 700 , 175 , Figura[0].color ) ;
			al_draw_rectangle		( 650 , 125 , 700 , 175 , al_map_rgb( 0 , 0 , 0 ) , 5) ;
			break ;
	}
}
Beispiel #8
0
void draw_title(void) {
	ALLEGRO_FONT *font = NULL;
	int w;
	int dw = (al_get_display_width(al_get_current_display()))/4;
	int dh = (al_get_display_height(al_get_current_display())) / 4;
    int fonth = dh*0.4;
    
	if (!(font = load_font_mem(text_font_mem, TEXT_FONT_FILE, -fonth))) {
		fprintf(stderr, "Error loading font %s.\n", TEXT_FONT_FILE);
		return;
	}

	al_clear_to_color(BLACK_COLOR);
	for (w = 0; w<150; w++) {
		al_draw_filled_rectangle(w+dw, w / 2 + dh, 2*dw - w+dw, 2*dh - w / 2+dh, al_map_rgba_f(0.03, 0.01, 0.01, 0.04));
	}
    al_draw_rectangle(dw, dh, dw+2*dw, dh+2*dh, al_map_rgba_f(.4, .15, .1, 1), 3);
	w = al_get_text_width(font, "WATSON");
	al_draw_textf(font, al_color_html("#576220"), (2*dw - w) / 2+dw, (2*dh - fonth) / 2+dh, ALLEGRO_ALIGN_LEFT, "WATSON");
	al_draw_textf(font, al_color_html("#F0C010"), (2*dw - w) / 2 - (fonth*1.0/64)+dw, (2*dh - fonth) / 2 - (fonth*3.0/64)+dh, ALLEGRO_ALIGN_LEFT, "WATSON");
	al_destroy_font(font);

}
static void TransformationsPrimitives(int mode)
{
   float t = al_get_time();
   if (mode == INIT) {
   
   } else if (mode == LOGIC) {
      Theta += Speed;
      al_build_transform(&MainTrans, ScreenW / 2, ScreenH / 2, sinf(t / 5), cosf(t / 5), Theta);
   } else if (mode == DRAW) {
      float points[8] = {
         -300, -200,
         700, 200,
         -700, 200,
         300, -200
      };
      
      if (Blend)
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
      else
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
      
      al_use_transform(&MainTrans);
      
      al_draw_line(-300, -200, 300, 200, al_map_rgba_f(0, 0.5, 0.5, 1), Thickness);
      al_draw_triangle(-150, -250, 0, 250, 150, -250, al_map_rgba_f(0.5, 0, 0.5, 1), Thickness);
      al_draw_rectangle(-300, -200, 300, 200, al_map_rgba_f(0.5, 0, 0, 1), Thickness);
      al_draw_rounded_rectangle(-200, -125, 200, 125, 50, 100, al_map_rgba_f(0.2, 0.2, 0, 1), Thickness);
      
      al_draw_ellipse(0, 0, 300, 150, al_map_rgba_f(0, 0.5, 0.5, 1), Thickness);
      al_draw_elliptical_arc(-20, 0, 300, 200, -ALLEGRO_PI / 2, -ALLEGRO_PI, al_map_rgba_f(0.25, 0.25, 0.5, 1), Thickness);
      al_draw_arc(0, 0, 200, -ALLEGRO_PI / 2, ALLEGRO_PI, al_map_rgba_f(0.5, 0.25, 0, 1), Thickness);
      al_draw_spline(points, al_map_rgba_f(0.1, 0.2, 0.5, 1), Thickness);
      al_draw_pieslice(0, 25, 150, ALLEGRO_PI * 3 / 4, -ALLEGRO_PI / 2, al_map_rgba_f(0.4, 0.3, 0.1, 1), Thickness);
      
      al_use_transform(&Identity);
   }
}
Beispiel #10
0
void Size_mode_view::Render(const Widget& widget) const
{
	Vector2 p = widget.Get_position();
	Vector2 s = widget.Get_size();
	bool fw = widget.Has_fixed_width();
	bool fh = widget.Has_fixed_height();
	ALLEGRO_COLOR bg_color = al_map_rgb_f(0.5, 0.5, 0.5);
	ALLEGRO_COLOR edge_color = al_map_rgb_f(0.9, 0.0, 0.0);
	ALLEGRO_COLOR text_color = al_map_rgb_f(1, 1, 1);
	al_draw_filled_rectangle(p.x, p.y+1, p.x+s.x-1, p.y+s.y, bg_color);
	al_draw_rectangle(p.x, p.y+1, p.x+s.x-1, p.y+s.y, edge_color, 0);

	int font_h = al_get_font_line_height(font->Afont());
	int y = p.y + (s.y - font_h)/2;
	int x = p.x + s.x/2;
	if(fw && fh)
		al_draw_text(font->Afont(), text_color, x, y, ALLEGRO_ALIGN_CENTRE, "Fixed");
	else if(fh)
		al_draw_text(font->Afont(), text_color, x, y, ALLEGRO_ALIGN_CENTRE, "Dynamic width");
	else if(fw)
		al_draw_text(font->Afont(), text_color, x, y, ALLEGRO_ALIGN_CENTRE, "Dynamic height");
	else
		al_draw_text(font->Afont(), text_color, x, y, ALLEGRO_ALIGN_CENTRE, "Fully dynamic");
}
Beispiel #11
0
void Button::draw()
{
   const Theme & theme = this->dialog->get_theme();
   ALLEGRO_COLOR fg;
   ALLEGRO_COLOR bg;
   SaveState state;

   if (this->pushed) {
      fg = theme.bg;
      bg = theme.fg;
   }
   else {
      fg = theme.fg;
      bg = theme.bg;
   }

   al_draw_rectangle(this->x1, this->y1, this->x2, this->y2,
      fg, 0);
   al_draw_filled_rectangle(this->x1 + 1, this->y1 + 1, this->x2 - 1, this->y2 - 1,
      bg);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, fg);
   al_draw_text(theme.font, (this->x1 + this->x2 + 1)/2,
      this->y1, ALLEGRO_ALIGN_CENTRE, this->text.c_str());
}
Beispiel #12
0
void TEnterprise::DrawNavigationLegenda(int a_nX, int a_nY)
{
    al_draw_rectangle(a_nX, a_nY,a_nX+300, a_nY+638,m_pEngine->m_clRED,2);

    a_nX +=10;
    a_nY +=20;

    al_draw_filled_circle(a_nX+15,a_nY+5,5,m_pEngine->m_clWHITE);
    al_draw_filled_rectangle(a_nX+3,a_nY+3,a_nX+17,a_nY+7,m_pEngine->m_clWHITE);
    al_draw_filled_rectangle(a_nX,a_nY-3,a_nX+8,a_nY,m_pEngine->m_clWHITE);
    al_draw_filled_rectangle(a_nX,a_nY+10,a_nX+8,a_nY+13,m_pEngine->m_clWHITE);
    al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY-3, 0,"Enterprise is in this sector");

    a_nY +=50;
    int x1= a_nX;
    int y1= a_nY;
    int x2= a_nX+8;
    int y2= a_nY-20;
    int x3= a_nX+16;
    int y3= a_nY;
    al_draw_filled_triangle(x1, y1, x2, y2, x3, y3,m_pEngine->m_clWHITE);
    al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY-18, 0,"Federation starbase");

     a_nY +=40;
     x1= a_nX;
     y1= a_nY;
     x2= a_nX+8;
     y2= a_nY-20;
     x3= a_nX+16;
     y3= a_nY;
     al_draw_filled_triangle(x1, y1, x2, y2, x3, y3,m_pEngine->m_clRED);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY-18, 0,"Klingon starbase");

     a_nY +=40;
     x1= a_nX;
     y1= a_nY;
     x2= a_nX+8;
     y2= a_nY-20;
     x3= a_nX+16;
     y3= a_nY;
     al_draw_filled_triangle(x1, y1, x2, y2, x3, y3,m_pEngine->m_clGREEN);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY-18, 0,"Romulan starbase");

     a_nY +=30;
     al_draw_filled_circle(a_nX+10, a_nY+20,7,m_pEngine->m_clBLUE);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class B star");

     a_nY +=40;
     al_draw_filled_circle(a_nX+10, a_nY+20,6,m_pEngine->m_clWHITE);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class F star");

     a_nY +=40;
     al_draw_filled_circle(a_nX+10, a_nY+20,8,m_pEngine->m_clYELLOW);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class G star");

     a_nY +=40;
     al_draw_filled_circle(a_nX+10, a_nY+20,10,m_pEngine->m_clRED);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class M star");

     a_nY +=50;
     al_draw_filled_circle(a_nX+10, a_nY+20,2,m_pEngine->m_clRED);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class A planet (Hostile)");

     a_nY +=30;
     al_draw_filled_circle(a_nX+10, a_nY+20,3,m_pEngine->m_clMAGENTA);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class B planet (Hostile)");

     a_nY +=30;
     al_draw_filled_circle(a_nX+10, a_nY+20,2,m_pEngine->m_clBROWN);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class L planet (Marginal)");

     a_nY +=30;
     al_draw_filled_circle(a_nX+10, a_nY+20,4,m_pEngine->m_clYELLOW);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class N planet (Gass Gigant)");

     a_nY +=30;
     al_draw_filled_circle(a_nX+10, a_nY+20,2,m_pEngine->m_clAQUA);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class M1 planet (Terrestrial)");

     a_nY +=30;
     al_draw_filled_circle(a_nX+10, a_nY+20,3,m_pEngine->m_clAQUA);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class M2 planet (Terrestrial)");

     a_nY +=30;
     al_draw_filled_circle(a_nX+10, a_nY+20,4,m_pEngine->m_clAQUA);
     al_draw_text(FontManager::GetFont(FONT::TEXT),m_pEngine->m_clWHITE, a_nX+30, a_nY+12, 0,"A class M3 planet (Terrestrial)");

}
Beispiel #13
0
void StartMenu::draw()
{
	al_draw_rectangle(mouseX-5, mouseY-5, mouseX+5, mouseY+5, al_map_rgb(255,0,0), 5);	//testing purposes
	al_draw_text(font36, al_map_rgb(100,0,100), 25,25,0, "Press Space to make game Lobby");
	al_draw_text(font36, al_map_rgb(100,0,100), 25,60,0, "This is the START MENU.");
}
Beispiel #14
0
int update_font_bitmaps(Game *g, Board *b){
    int i, j, s;
    float FONT_FACTOR=1;
    ALLEGRO_FONT *tile_font1, *tile_font2, *tile_font3;
    ALLEGRO_BITMAP *dispbuf = al_get_target_bitmap();
    int bbx, bby, bbw, bbh;
    
    al_set_target_bitmap(NULL);
    
    s=min(b->panel.b[0]->b[0]->w, b->panel.b[0]->b[0]->h);
    tile_font1 = load_font_mem(tile_font_mem, TILE_FONT_FILE, -s*FONT_FACTOR);
    tile_font2 = load_font_mem(tile_font_mem, TILE_FONT_FILE, -b->panel_tile_size*FONT_FACTOR);
    tile_font3 = load_font_mem(tile_font_mem, TILE_FONT_FILE, -b->clue_unit_size*FONT_FACTOR);

    if(!tile_font1 || !tile_font2 || !tile_font3) {
        fprintf(stderr, "Error loading tile font file %s.\n", TILE_FONT_FILE);
        return -1;
    }
    
    for(i=0;i<b->h;i++){
        for(j=0;j<b->n;j++){
            b->guess_bmp[i][j] = al_create_bitmap(b->panel.b[0]->b[0]->w, b->panel.b[0]->b[0]->h);
            b->panel_tile_bmp[i][j] = al_create_bitmap(b->panel_tile_size,b->panel_tile_size);
            b->clue_unit_bmp[i][j] = al_create_bitmap(b->clue_unit_size, b->clue_unit_size);
            if(!b->guess_bmp[i][j] || !b->panel_tile_bmp[i][j] || !b->clue_unit_bmp[i][j]){
                fprintf(stderr, "Error creating bitmap.\n");
                return -1;
            }
            
            // guessed bitmaps
            al_set_target_bitmap(b->guess_bmp[i][j]);
            al_clear_to_color(al_color_html(CLUE_BG_COLOR[i]));
            al_get_glyph_dimensions(tile_font1, CLUE_CODE[i][j][0], &bbx, &bby, &bbw, &bbh);
            if(GLYPH_SHADOWS){
                al_draw_glyph(tile_font1, DARK_GREY_COLOR, (b->panel.b[0]->b[0]->w-bbw)/2 -bbx +1,(b->panel.b[0]->b[0]->h-bbh)/2-bby+1, CLUE_CODE[i][j][0]);
            }
            al_draw_glyph(tile_font1, al_color_html(CLUE_FG_COLOR[i]), (b->panel.b[0]->b[0]->w-bbw)/2 -bbx,(b->panel.b[0]->b[0]->h-bbh)/2-bby, CLUE_CODE[i][j][0]);
            // this draws a border for all tiles, independent of the "bd" setting in b
            if(TILE_SHADOWS)
                draw_shadow(b->panel.b[0]->b[0]->w, b->panel.b[0]->b[0]->h,2);
            else
                al_draw_rectangle(.5,.5,b->panel.b[0]->b[0]->w-.5, b->panel.b[0]->b[0]->h-.5, TILE_GENERAL_BD_COLOR,1);
            
            // panel bitmaps
    
            al_set_target_bitmap(b->panel_tile_bmp[i][j]);
            al_clear_to_color(al_color_html(CLUE_BG_COLOR[i]));
            al_get_glyph_dimensions(tile_font2, CLUE_CODE[i][j][0], &bbx, &bby, &bbw, &bbh);
            if(GLYPH_SHADOWS){
                al_draw_glyph(tile_font2, DARK_GREY_COLOR,(b->panel_tile_size -bbw)/2-bbx+1, (b->panel_tile_size - bbh)/2-bby+1, CLUE_CODE[i][j][0]);
            }
            al_draw_glyph(tile_font2, al_color_html(CLUE_FG_COLOR[i]),(b->panel_tile_size -bbw)/2-bbx, (b->panel_tile_size - bbh)/2-bby, CLUE_CODE[i][j][0]);
            if(TILE_SHADOWS)
                draw_shadow(b->panel_tile_size, b->panel_tile_size,2);
            else
                al_draw_rectangle(.5,.5,b->panel_tile_size-.5,b->panel_tile_size-.5, TILE_GENERAL_BD_COLOR,1);
            
            // clue unit tile bitmaps
            al_set_target_bitmap(b->clue_unit_bmp[i][j]);
            al_clear_to_color(al_color_html(CLUE_BG_COLOR[i]));
            al_get_glyph_dimensions(tile_font3, CLUE_CODE[i][j][0], &bbx, &bby, &bbw, &bbh);
            if(GLYPH_SHADOWS){
                al_draw_glyph(tile_font3, DARK_GREY_COLOR, (b->clue_unit_size-bbw)/2 -bbx +1,(b->clue_unit_size-bbh)/2-bby+1, CLUE_CODE[i][j][0]);
            }
            al_draw_glyph(tile_font3, al_color_html(CLUE_FG_COLOR[i]), (b->clue_unit_size-bbw)/2 -bbx,(b->clue_unit_size-bbh)/2-bby, CLUE_CODE[i][j][0]);
            if(TILE_SHADOWS)
                draw_shadow(b->clue_unit_size,b->clue_unit_size,2);
            else
                al_draw_rectangle(.5,.5,b->clue_unit_size-.5, b->clue_unit_size-.5, TILE_GENERAL_BD_COLOR,1);
        }
    }

    if(draw_symbols(g, b)) return -1;
    
    al_destroy_font(tile_font1);
    al_destroy_font(tile_font2);
    al_destroy_font(tile_font3);
    
    al_set_target_backbuffer(al_get_current_display());
    // create clue tile bmps
    al_set_target_bitmap(dispbuf);
    return make_clue_bitmaps(g, b);
    
}
Beispiel #15
0
int update_bitmaps(Game *g, Board *b){
    int i, j, s;

    ALLEGRO_BITMAP *dispbuf = al_get_target_bitmap();
    al_set_target_bitmap(NULL);
    // reload text fonts
    // estimate font size for panel:
    if(!(b->text_font = load_font_mem(text_font_mem, TEXT_FONT_FILE, -min(b->info_panel.h/2.2, sqrt(b->info_panel.w*b->info_panel.h)/10))) ){
        fprintf(stderr, "Error loading font %s.\n", TEXT_FONT_FILE);
    }
    
    // update buttons and timer bmps
    b->time_bmp = al_create_bitmap(b->time_panel.b[0]->w, b->time_panel.b[0]->h);
	al_set_target_bitmap(b->time_bmp);
	al_clear_to_color(b->time_panel.b[0]->bg_color);
    
    // this should go here, but by android problems we have to recreate the bitmap on every new text drawing:
    // b->info_text_bmp = al_create_bitmap(b->info_panel.w, b->info_panel.h);
    
    for(i=0; i<4; i++){
        b->button_bmp_scaled[i] = scaled_clone_bitmap(b->button_bmp[i], b->time_panel.b[i+1]->w, b->time_panel.b[i+1]->h);
    }
    
	al_set_target_bitmap(dispbuf);

	if (b->type_of_tiles == 0) { // use font bitmaps
		return update_font_bitmaps(g, b);
	}

    // else update normal bitmaps:
    al_set_target_bitmap(NULL);
    s=min(b->panel.b[0]->b[0]->w, b->panel.b[0]->b[0]->h);
    for(i=0;i<b->h;i++){
        for(j=0;j<b->n;j++){
            b->guess_bmp[i][j] = al_create_bitmap(b->panel.b[0]->b[0]->w, b->panel.b[0]->b[0]->h);
            b->panel_tile_bmp[i][j] = al_create_bitmap(b->panel_tile_size,b->panel_tile_size);
            b->clue_unit_bmp[i][j] = al_create_bitmap(b->clue_unit_size, b->clue_unit_size);
            if(!b->guess_bmp[i][j] || !b->panel_tile_bmp[i][j] || !b->clue_unit_bmp[i][j]){
                fprintf(stderr, "Error creating bitmap.\n");
                return -1;
            }
            
            // guessed bitmaps
            al_set_target_bitmap(b->guess_bmp[i][j]);
            if(b->type_of_tiles != 2)  // not classic tiles
                al_clear_to_color(al_color_html(CLUE_BG_COLOR_BMP[i]));
            else
                al_clear_to_color(b->panel.b[0]->b[0]->bg_color);
            
            if(TILE_SHADOWS)
                draw_shadow(b->panel.b[0]->b[0]->w, b->panel.b[0]->b[0]->h,2);
            else
                al_draw_rectangle(.5,.5,b->panel.b[0]->b[0]->w-.5, b->panel.b[0]->b[0]->h-.5, TILE_GENERAL_BD_COLOR,1);
            
            al_draw_scaled_bitmap(basic_bmp[i][j], 0, 0, al_get_bitmap_width(basic_bmp[i][j]), al_get_bitmap_height(basic_bmp[i][j]), (b->panel.b[0]->b[0]->w-s)/2, (b->panel.b[0]->b[0]->h-s)/2, s, s, 0);
            
            // panel bitmaps
            al_set_target_bitmap(b->panel_tile_bmp[i][j]);
            al_clear_to_color(al_color_html(CLUE_BG_COLOR_BMP[i]));
            if(TILE_SHADOWS)
                draw_shadow(b->panel_tile_size, b->panel_tile_size,1);
            else
                al_draw_rectangle(.5,.5,b->panel_tile_size-.5,b->panel_tile_size-.5, TILE_GENERAL_BD_COLOR,1);
            
            
            
            al_draw_scaled_bitmap(basic_bmp[i][j], 0, 0, al_get_bitmap_width(basic_bmp[i][j]), al_get_bitmap_height(basic_bmp[i][j]), 0, 0, b->panel_tile_size, b->panel_tile_size,0);
            
            // clue unit tile bitmaps
            al_set_target_bitmap(b->clue_unit_bmp[i][j]);
            al_clear_to_color(al_color_html(CLUE_BG_COLOR_BMP[i]));
            if(TILE_SHADOWS)
                draw_shadow(b->clue_unit_size,b->clue_unit_size,2);
            else
                al_draw_rectangle(.5,.5,b->clue_unit_size-.5, b->clue_unit_size-.5, TILE_GENERAL_BD_COLOR,1);

            al_draw_scaled_bitmap(basic_bmp[i][j], 0, 0, al_get_bitmap_width(basic_bmp[i][j]), al_get_bitmap_height(basic_bmp[i][j]), 0, 0, b->clue_unit_size, b->clue_unit_size,0);
        }
    }
    
    if(b->type_of_tiles != 2)
    {
        if(draw_symbols(g,b)) return -1;
    }
    else
    {
        if(draw_classic_symbols(g,b)) return -1;
    }

    al_set_target_bitmap(dispbuf);
    
    // create clue tile bmps
    return make_clue_bitmaps(g, b);
}
void DrawingClass::DrawRectangle (float x0, float y0, float x1, float y1, int r, 
    int g, int b, int thick) {
  ALLEGRO_COLOR color = al_map_rgb(r, g, b);
  al_draw_rectangle(x0, y0, x1, y1, color, thick);
}
Beispiel #17
0
void Button::DrawLockedButton() {
	// drawing different button contour
	al_draw_rectangle(realX - width/2.0, realY, realX + width/2.0, realY + height, Green, 1.0);
}
Beispiel #18
0
//u¿ywane do celów debugowania
void Tank::drawHitbox() {
	al_draw_rectangle(this->getX(), this->getY(), this->getX() + 64, this->getY() + 24, this->color, 4.0);
}
Beispiel #19
0
int main()
{          
	const float FPS = 60.0;

	if(!al_init())
	{
		al_show_native_message_box(NULL, "Fatal Error", NULL, "No se pudo inicializar Allegro", NULL, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}
	
	al_set_new_display_flags(ALLEGRO_WINDOWED); // Pone la ventana en modo Windowed
	ALLEGRO_DISPLAY *display = al_create_display(ScreenWidth, ScreenHeight);

	// Pone la posición en la que debe salir l`a ventana
	//al_set_window_position(display, 0, 30);

	// Pone el título de la ventana
	al_set_window_title(display, "Killer Bunny");

	if(!display)	// Si no se pudo crear la ventana, entonces pone un mensaje de error
	{
		al_show_native_message_box(NULL, "Error", NULL, "No se pudo crear la pantalla", NULL, ALLEGRO_MESSAGEBOX_ERROR);
		return -1;
	}

	al_install_keyboard();
	al_install_mouse();
	al_init_image_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	al_init_primitives_addon();

	// -----------------------------------------------------------------

	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	ALLEGRO_TIMER *timer = al_create_timer(1.0/FPS);
	ALLEGRO_KEYBOARD_STATE keyState;

	// Utilizado para debugging
	ALLEGRO_FONT *font = al_load_font("sprites/DroidSans.ttf", 10, 0);

	
	ALLEGRO_BITMAP *fondo1 = al_load_bitmap("sprites/fondo1.png");
	
	
	bool done = false;

	// ---------Estructuras del juego-----------------------------------

	struct Player player;
	player.image = al_load_bitmap("sprites/player.png");
	al_convert_mask_to_alpha(player.image, al_map_rgb(255,255,255));
	player.x = ScreenWidth / 2;
	player.y = ScreenHeight / 2;
	player.w = al_get_bitmap_width(player.image);
	player.h = al_get_bitmap_height(player.image);
	player.moveSpeed = 3;
	player.degrees = -ALLEGRO_PI/2;
   	player.alive = true;
   	player.clip = 6;
   	player.vida = 100;

	
	struct Bala bala;
	
	//~ void Bala::update()
	//~ {
		//~ bala.dx = cosf(player.xmouse - player.x);
		//~ bala.dy = senf(player.ymouse - player.y);
		//~ 
		//~ if(bala.shot){
			//~ 
			//~ bala.x += bala.dx;
			//~ bala.y += bala.dy;
			//~ }
		//~ 
	//~ }
	
	bala.image = al_load_bitmap("sprites/bullet.png");
	bala.x = player.x+50;
	bala.y = player.y+25;
	bala.shot = false;
	
	
	struct Enemigo robot;
	robot.image = al_load_bitmap("sprites/Robot_sprites.png");
	robot.death = al_load_bitmap("sprites/explosiondelrobot.png");
	al_convert_mask_to_alpha(robot.death, al_map_rgb(255, 255, 255));
	//al_convert_mask_to_alpha(robot.image, al_map_rgb(255,255,255));
	robot.x = 50;
	robot.y = 50;
	robot.w = al_get_bitmap_width(robot.image);
	robot.h = al_get_bitmap_height(robot.image);
	robot.velocidad_x = 0.23;
	robot.velocidad_y = 0.23;
	robot.fuerza= 0.5;
	robot.vida=50;
	
	//~ void Weapon::recargar()
	//~ {
		//~ for(int i = 0; i < 6; i++)
		//~ {
			//~ bullets[i] = bala;
		//~ }
	//~ }
	
	// -----------------------------------------------------------------

	// Esta variable guardará los eventos del mouse
	ALLEGRO_MOUSE_STATE mouseState;
	
	// Registro varias fuentes de eventos
	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_display_event_source(display));
	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_mouse_event_source());

	// Inicializo el temporizador principal
	al_start_timer(timer);

	while(!done)
	{
		// La variable de los eventos
		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev); // Y aquí espero por los eventos


		if(ev.type == ALLEGRO_EVENT_TIMER)
		{
			// Dos funciones para pasar eventos del mouse y del teclado
			al_get_keyboard_state(&keyState);
			al_get_mouse_state(&mouseState);
			
			// Esto detecta la posición del mouse y lo guarda a un par de variables
			player.xmouse = al_get_mouse_state_axis(&mouseState, 0);
			player.ymouse = al_get_mouse_state_axis(&mouseState, 1);

			// Si presiono Esc entonces me saca del juego
			if(al_key_down(&keyState, ALLEGRO_KEY_ESCAPE))
			{
				done = true;
			}
			// Si presiono A entonces el valor x se reduce, osea, se va a la izquierda
			if(al_key_down(&keyState, ALLEGRO_KEY_A))
			{
				player.x -= player.moveSpeed;
			}
			// Si... meh, ya sabes lo que sigue
			if(al_key_down(&keyState, ALLEGRO_KEY_D))
			{
				player.x += player.moveSpeed;
			}
			// ...
			if(al_key_down(&keyState, ALLEGRO_KEY_W))
			{
				player.y -= player.moveSpeed;
			}
			// ...
			if(al_key_down(&keyState, ALLEGRO_KEY_S))
			{
				player.y += player.moveSpeed;
			}
			// Mata al robot
			if(al_key_down(&keyState, ALLEGRO_KEY_K))
			{
                robot.vida -= 10;
            }
					
		}
		
		// Esto permite que el jugador se mueva con el mouse
		player.degrees = atan2((player.ymouse-player.y),(player.xmouse-player.x));
					
		// La Inteligencia Artificial del enemigo
		if(robot.alive && player.alive){
			if(robot.x < player.x) robot.x += robot.velocidad_x;
			if(robot.x > player.x) robot.x -= robot.velocidad_x;
			if(robot.y > player.y) robot.y -= robot.velocidad_y;
			if(robot.y < player.y) robot.y += robot.velocidad_y;
		}
		// Uso de las funciones para las colisiones
		//if(Collision(player.x, player.y, 50, 50, robot.x, robot.y, 34, 34)) player.alive = false;
		if(PixelCol(player.image, robot.image, player.x-(player.w/2), player.y-(player.h/2), player.w, player.h, robot.x, robot.y, robot.w/7, robot.h)) player.vida -= robot.fuerza;

		if(player.vida==0) player.alive = false;
		
		if(robot.vida<=0){
			robot.vida = 0;
			robot.alive = false;
		}

		al_clear_to_color(al_map_rgb(255, 255, 255));	// Se pinta todo a negro
		al_draw_scaled_bitmap(fondo1,0, 0, 256, 256, 0, 0, ScreenWidth, ScreenHeight, 0);	// Se dibuja el fondo
		if(player.alive){	// Si el jugador está vivo
			al_draw_rotated_bitmap(player.image, 25, 25, player.x, player.y, player.degrees, 0); // Dibujo el jugador
			al_draw_rotated_bitmap(bala.image, 0, 0, player.x+5, player.y+5, player.degrees, 0); // Dibujo la bala (esto hay que quitarlo)
		}
		if(robot.alive){
			al_draw_bitmap_region(robot.image, 0, 0, 60, 52, robot.x, robot.y, 0); // Dibujo el robot
			}
		else
		{
			robot.w = al_get_bitmap_width(robot.death);
			robot.h = al_get_bitmap_width(robot.death);
			al_draw_bitmap_region(robot.death, 0, 0, robot.w/4, robot.h, robot.x, robot.y, 0);
        }
        
        // Esto es para el debugging
        
        // Dibujo rectángulos para las colisiones
        al_draw_rectangle(player.x-(player.w/2), player.y-(player.h/2), (player.x+player.w)-(player.w/2), (player.y+player.h)-(player.h/2), al_map_rgb(0, 255, 0), 1.0);
        al_draw_rectangle(robot.x, robot.y, robot.x+(robot.w/7), robot.y+robot.h, al_map_rgb(0, 255, 0), 1.0);
        
        // Escribo en una esquina de la pantalla, información respecto al personaje
		al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 2, ALLEGRO_ALIGN_RIGHT, "Player x, y : %.1f %.1f", player.x, player.y);
		al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 12, ALLEGRO_ALIGN_RIGHT, "Rotation (rad): %.5f", player.degrees);
		al_draw_textf(font, al_map_rgb(255,255,255), ScreenWidth-10, 22, ALLEGRO_ALIGN_RIGHT, "Rotation (degrees): %.2f", (player.degrees*180)/ALLEGRO_PI);
		
		// Status bar
		al_draw_filled_rectangle(0,0,player.vida*2,15, al_map_rgb(0,255,0));
		
		// Actualizo la pantalla (flip)
		al_flip_display();
		
		
	}
	
	//-----After party (hay que limpiar)--------------------------------
	
	// A destruirlo todo!! BAM BAM BAM, KABOOM!!
	al_destroy_font(font);
	al_destroy_bitmap(fondo1);
	al_destroy_bitmap(robot.image);
	al_destroy_display(display);
	al_destroy_event_queue(event_queue);
	al_destroy_bitmap(player.image);
	al_destroy_timer(timer);

	return 0;
}
void DrawingInterfaceAllegro5::draw_rectangle(float x1, float y1, float x2, float y2, ALLEGRO_COLOR outline_color, float thickness)
{
   al_draw_rectangle(x1, y1, x2, y2, outline_color, thickness);
}
void Environment::drawGrid(bool showCenter) {

	if (!withGrid) {
		printf(
				"Environment::drawGrid(): do setGrid(true,<slotSize>) to perform grid operations\n");
	}
	// calculate rows and columns of the grid
	int rows = height / slotSize;
	int columns = width / slotSize;

	// top left corner of the grid
	float y = dispHeight - height; // (displayHeight - rows*slotSize) / 2 ;
	float x = dispWidth - width; // (displayWidth  - columns*slotSize) / 2 ;

	int line_size = 3;
	al_draw_rectangle(x, y, x + columns * slotSize, y + rows * slotSize,
			al_map_rgb(0, 255, 0), 5);

	// vertical lines
	for (int i = 1; i <= columns - 1; i++) {
		al_draw_line(x + i * slotSize, y, x + i * slotSize, y + rows * slotSize,
				al_map_rgb(0, 255, 0), line_size);
	}

	// horizontal lines
	for (int i = 1; i <= rows - 1; i++) {
		al_draw_line(x, y + i * slotSize, x + columns * slotSize,
				y + i * slotSize, al_map_rgb(0, 255, 0), line_size);
	}

	if (showCenter) {
		ALLEGRO_FONT* font = al_load_font("arial.ttf", 12, 0);
		if (!font) {
			printf("Environment::drawGrid(): font couldn't be loaded\n");
			return;
		}
		// find slot centre for each row and column
		// and add text there
		for (int i = 0; i < columns; i++) {
			for (int j = 0; j < rows; j++) {
				Point p = getGridSlotCenter(i, j);
				//al_draw_filled_circle(p.x, p.y, 5.0, al_map_rgb(255, 0, 0));
				al_draw_textf(font, al_map_rgb(255, 255, 255), p.x, p.y,
						ALLEGRO_ALIGN_CENTER, "%d,%d", i, j);
			}
		}

		al_destroy_font(font);
	}
	/*
	 //draw slant lines in each slot
	 for(int i = 0; i < rows; i++){
	 for(int j = 0; j < columns; j++){


	 if(!is_obstacle(j, rows - i - 1) && ( (j != target.x) || ((rows - i - 1) != target.y) ) ){
	 // draw leftward slant lines
	 al_draw_line(x + j*slotSize,y + i*slotSize, x + (j+1)*slotSize, y + (i+1)*slotSize,
	 al_map_rgb(255,255,255),line_size);


	 // draw rightward slant lines
	 al_draw_line(x + j*slotSize, y + (i+1)*slotSize, x + (j+1)*slotSize, y + (i)*slotSize,
	 al_map_rgb(255,255,255),line_size);


	 }
	 }

	 }
	 */
}
Beispiel #22
0
/* render routines, passed to T^3 Framework */
void paddle_render(void * data)
{
	/* render switch, render graphics according to which state we are in */
	switch(paddle_state)
	{
		
		case EXAMPLE_STATE_TITLE:
		{
			
			/* draw background */
			al_draw_bitmap(paddle_bitmap[EXAMPLE_BITMAP_BG], 0.0, 0.0, 0);
			
			/* center logo */
			al_draw_bitmap(paddle_bitmap[EXAMPLE_BITMAP_LOGO], al_get_display_width(t3f_display) / 2 - al_get_bitmap_width(paddle_bitmap[EXAMPLE_BITMAP_LOGO]) / 2, 32.0, 0);
			
			/* draw menu */
			t3f_render_gui(paddle_menu);
			
			break;
		}
		
		case EXAMPLE_STATE_GAME:
		{
			int i;
			
			/* draw background */
			al_draw_bitmap(paddle_bitmap[EXAMPLE_BITMAP_BG], 0.0, 0.0, 0);
			
			/* draw game objects */
			for(i = 0; i < 2; i++)
			{
				if(paddle[i].active)
				{
					al_draw_bitmap(paddle_bitmap[EXAMPLE_BITMAP_PADDLE], paddle[i].x, paddle[i].y, 0);
				}
				if(ball.active)
				{
					al_draw_bitmap(paddle_bitmap[EXAMPLE_BITMAP_BALL], ball.x, ball.y, 0);
				}
			}
			
			/* draw scores */
			al_draw_textf(paddle_font[EXAMPLE_FONT_GAME], al_map_rgba(0, 0, 0, 255), 10.0, 0.0, 0, "Player 1: %d", score[0]);
			al_draw_textf(paddle_font[EXAMPLE_FONT_GAME], al_map_rgba(0, 0, 0, 255), 540.0, 0.0, 0, "Player 2: %d", score[1]);
			
			break;
		}
		
		case EXAMPLE_STATE_GAME_OVER:
		{
			
			/* draw background */
			al_draw_bitmap(paddle_bitmap[EXAMPLE_BITMAP_BG], 0.0, 0.0, 0);
			
			/* draw results */
			al_draw_filled_circle(640.0 * t3f_drand(&rng_state), 480.0 * t3f_drand(&rng_state), 10.0 + 32.0 * t3f_drand(&rng_state), al_map_rgba(0, 0, 192, 128));
			al_draw_filled_rectangle(220.0, 192.0, 420.0, 280.0, al_map_rgba(0, 192, 0, 128));
			al_draw_rectangle(220.0, 192.0, 420.0, 280.0, al_map_rgba(0, 0, 0, 255), 2.0);
			al_draw_textf(paddle_font[EXAMPLE_FONT_MENU], al_map_rgba(0, 0, 0, 255), 320.0, 200.0, ALLEGRO_ALIGN_CENTRE, "Player %d Wins!", score[0] > score[1] ? 1 : 2);
			al_draw_textf(paddle_font[EXAMPLE_FONT_GAME], al_map_rgba(0, 0, 0, 255), 320.0, 240.0, ALLEGRO_ALIGN_CENTRE, "Click to continue...");
			
			break;
		}
	}
}
static void draw_clip_rect(void)
{
   al_draw_rectangle(100.5, 100.5, W - 100.5, H - 100.5, black, 0);
}
Beispiel #24
0
void Food::draw()
{
	al_draw_rectangle(adjustX+x+6, adjY+y+50+6, adjustX+x+unit-6, adjY+y+50+unit-6, al_map_rgb(0,0,0), 4);
}
Beispiel #25
0
int main(int argc, char **argv)
{
    ALLEGRO_DISPLAY *display;
    ALLEGRO_TIMER *timer;
    ALLEGRO_EVENT_QUEUE *queue;
    int redraw = 0;
    double t = 0;

    if (!al_init()) {
        abort_example("Could not init Allegro.\n");
    }

    open_log_monospace();

    al_init_primitives_addon();
    al_install_mouse();
    al_init_font_addon();
    al_init_ttf_addon();
    al_init_image_addon();
    init_platform_specific();

#ifdef ALLEGRO_IPHONE
    al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
#endif
    display = al_create_display(640, 480);
    if (!display) {
        abort_example("Could not create display.\n");
    }
    al_install_keyboard();

    if (argc >= 2) {
        font_file = argv[1];
    }

    ex.f1 = al_load_font(font_file, 48, 0);
    ex.f2 = al_load_font(font_file, 48, ALLEGRO_TTF_NO_KERNING);
    ex.f3 = al_load_font(font_file, 12, 0);
    /* Specifying negative values means we specify the glyph height
     * in pixels, not the usual font size.
     */
    ex.f4 = al_load_font(font_file, -140, 0);
    ex.f5 = al_load_font(font_file, 12, ALLEGRO_TTF_MONOCHROME);

    {
        int ranges[] = {0x1F40A, 0x1F40A};
        ALLEGRO_BITMAP *icon = al_load_bitmap("data/icon.png");
		if (!icon) {
			abort_example("Couldn't load data/icon.png.\n");
		}
        ALLEGRO_BITMAP *glyph = al_create_bitmap(50, 50);
        al_set_target_bitmap(glyph);
        al_clear_to_color(al_map_rgba_f(0, 0, 0, 0));
        al_draw_rectangle(0.5, 0.5, 49.5, 49.5, al_map_rgb_f(1, 1, 0),
         1);
        al_draw_bitmap(icon, 1, 1, 0);
        al_set_target_backbuffer(display);
        ex.f_alex = al_grab_font_from_bitmap(glyph, 1, ranges);
    }

    if (!ex.f1 || !ex.f2 || !ex.f3 || !ex.f4 || !ex.f_alex) {
        abort_example("Could not load font: %s\n", font_file);
    }

    al_set_fallback_font(ex.f3, ex.f_alex);

    ex.ranges_count = al_get_font_ranges(ex.f1, 0, NULL);
    print_ranges(ex.f1);

    ex.config = al_load_config_file("data/ex_ttf.ini");
    if (!ex.config) {
        abort_example("Could not data/ex_ttf.ini\n");
    }

    timer = al_create_timer(1.0 / 60);

    queue = al_create_event_queue();
    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));
    al_register_event_source(queue, al_get_timer_event_source(timer));

    al_start_timer(timer);
    while (true) {
        ALLEGRO_EVENT event;
        al_wait_for_event(queue, &event);
        if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
            break;
        if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
                event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
            break;
        }
        if (event.type == ALLEGRO_EVENT_TIMER)
            redraw++;

        while (redraw > 0 && al_is_event_queue_empty(queue)) {
            double dt;
            redraw--;

            dt = al_get_time();
            render();
            dt = al_get_time() - dt;

            t = 0.99 * t + 0.01 * dt;

            ex.fps = 1.0 / t;
            al_flip_display();
        }
    }

    al_destroy_font(ex.f1);
    al_destroy_font(ex.f2);
    al_destroy_font(ex.f3);
    al_destroy_font(ex.f4);
    al_destroy_font(ex.f5);
    al_destroy_config(ex.config);

    close_log(false);

    return 0;
}
void drawMonsters (Monster m[])
{
    for (int i = 0; i < numMonsters; i ++)
    {
        if (m[i].isLive)
        {
            if (abs(m[i].getDx()) > abs(m[i].getDy()))
            {
                if (m[i].getDx() > .01)
                {
                    m[i].setDir(RIGHT);
                }
                else if (m[i].getDx() < -.01)
                {
                    m[i].setDir(LEFT);
                }
                else
                {
                    m[i].setDir(DOWN);
                }
            }
            else
            {
                if (m[i].getDy() > -.01)
                {
                    m[i].setDir(DOWN);
                }
                else
                {
                    m[i].setDir(UP);
                }
            }
            if ( m[i].getDir() == UP)
            {
                //printf("UP\n");
                m[i].setAnimationRow(3);
            }
            if ( m[i].getDir() == DOWN)
            {
                //printf("Down\n");
                m[i].setAnimationRow(0);
            }
            if ( m[i].getDir() == LEFT)
            {
                //printf("LEFT\n");
                m[i].setAnimationRow(1);
            }
            if ( m[i].getDir() == RIGHT)
            {
                //printf("Right\n");
                m[i].setAnimationRow(2);
            }

            int fx = (m[i].getCurFrame() % m[i].getNumFrames()) * m[i].getW();
            int fy = m[i].getAnimationRow() * m[i].getH();

            al_draw_scaled_bitmap(monster1, m[i].sourceX + fx, m[i].sourceY + fy, m[i].getW(), m[i].getH(), m[i].getX(), m[i].getY(), m[i].getW(), m[i].getH(),0);

if (showHitboxes)
            {
                for (int i = 0; i < numMonsters; i ++)
                {
                    if (m[i].isLive)
                    {
            al_draw_rectangle(m[i].getX() + m[i].getBoundOffsetW(), m[i].getY() + m[i].getBoundOffsetH(), m[i].getX() + m[i].getBoundOffsetW() + m[i].getBoundW(), m[i].getY() + m[i].getBoundOffsetH() + m[i].getBoundH(), al_map_rgb(255,0,0),1);
            al_draw_rectangle(m[i].getX() + m[i].getWallOffsetW(), m[i].getY() + m[i].getWallOffsetH(), m[i].getX() + m[i].getWallOffsetW() + m[i].getWallW(), m[i].getY() + m[i].getWallOffsetH() + m[i].getWallH(), al_map_rgb(0,255,0),1);
                    }
                }
            }


            //Animation frame updating
            m[i].setFrameCount(m[i].getFrameCount() + 1);
            if (m[i].getFrameCount() >= m[i].getFrameDelay())
            {
                m[i].setCurFrame(m[i].getCurFrame() + 1);
                if (m[i].getCurFrame() >= m[i].getNumFrames())
                {
                    m[i].setCurFrame(0);
                }
                m[i].setFrameCount(0);
            }

        }
    }
}
Beispiel #27
0
static void render(void)
{
    ALLEGRO_COLOR white = al_map_rgba_f(1, 1, 1, 1);
    ALLEGRO_COLOR black = al_map_rgba_f(0, 0, 0, 1);
    ALLEGRO_COLOR red = al_map_rgba_f(1, 0, 0, 1);
    ALLEGRO_COLOR green = al_map_rgba_f(0, 0.5, 0, 1);
    ALLEGRO_COLOR blue = al_map_rgba_f(0.1, 0.2, 1, 1);
    ALLEGRO_COLOR purple = al_map_rgba_f(0.3, 0.1, 0.2, 1);
    int x, y, w, h, as, de, xpos, ypos;
    unsigned int index;
    int target_w, target_h;
    ALLEGRO_USTR_INFO info, sub_info;
    const ALLEGRO_USTR *u;
    ALLEGRO_USTR *tulip = al_ustr_new("Tulip");
    ALLEGRO_USTR *dimension_text = al_ustr_new("Tulip");
    ALLEGRO_USTR *vertical_text  = al_ustr_new("Rose.");

    al_clear_to_color(white);

    al_hold_bitmap_drawing(true);

    al_draw_textf(ex.f1, black, 50,  20, 0, "Tulip (kerning)");
    al_draw_textf(ex.f2, black, 50,  80, 0, "Tulip (no kerning)");

    x = 50;
    y = 140;
    for (index = 0; index < al_ustr_length(dimension_text); index ++) {
       int cp  = ustr_at(dimension_text, index);
       int bbx, bby, bbw, bbh;
       al_get_glyph_dimensions(ex.f2, cp, &bbx, &bby, &bbw, &bbh);
       al_draw_rectangle(x + bbx + 0.5, y + bby + 0.5, x + bbx + bbw - 0.5, y + bby + bbh - 0.5, blue, 1);
       al_draw_rectangle(x + 0.5, y + 0.5, x + bbx + bbw - 0.5, y + bby + bbh - 0.5, green, 1);
       al_draw_glyph(ex.f2, purple, x, y, cp);
       x += al_get_glyph_advance(ex.f2, cp, ALLEGRO_NO_KERNING);
    }
    al_draw_line(50.5, y+0.5, x+0.5, y+0.5, red, 1);
    al_draw_textf(ex.f2, black, x + 10, y, 0, "(dimensions)");

    al_draw_textf(ex.f3, black, 50, 200, 0, "This font has a size of 12 pixels, "
        "the one above has 48 pixels.");

    al_hold_bitmap_drawing(false);
    al_hold_bitmap_drawing(true);

    al_draw_textf(ex.f3, red, 50, 220, 0, "The color can simply be changed.🐊← fallback glyph");

    al_hold_bitmap_drawing(false);
    al_hold_bitmap_drawing(true);

    al_draw_textf(ex.f3, green, 50, 240, 0, "Some unicode symbols:");
    al_draw_textf(ex.f3, green, 50, 260, 0, "%s", get_string("symbols1"));
    al_draw_textf(ex.f3, green, 50, 280, 0, "%s", get_string("symbols2"));
    al_draw_textf(ex.f3, green, 50, 300, 0, "%s", get_string("symbols3"));

   #define OFF(x) al_ustr_offset(u, x)
   #define SUB(x, y) al_ref_ustr(&sub_info, u, OFF(x), OFF(y))
    u = al_ref_cstr(&info, get_string("substr1"));
    al_draw_ustr(ex.f3, green, 50, 320, 0, SUB(0, 6));
    u = al_ref_cstr(&info, get_string("substr2"));
    al_draw_ustr(ex.f3, green, 50, 340, 0, SUB(7, 11));
    u = al_ref_cstr(&info, get_string("substr3"));
    al_draw_ustr(ex.f3, green, 50, 360, 0, SUB(4, 11));
    u = al_ref_cstr(&info, get_string("substr4"));
    al_draw_ustr(ex.f3, green, 50, 380, 0, SUB(0, 11));

    al_draw_textf(ex.f5, black, 50, 395, 0, "forced monochrome");

    /* Glyph rendering tests. */
    al_draw_textf(ex.f3, red, 50, 410, 0, "Glyph adv Tu: %d, draw: ",
                        al_get_glyph_advance(ex.f3, 'T', 'u'));
    x = 50;
    y = 425;
    for (index = 0; index < al_ustr_length(tulip); index ++) {
       int cp  = ustr_at(tulip, index);
       /* Use al_get_glyph_advance for the stride, with no kerning. */
       al_draw_glyph(ex.f3, red, x, y, cp);
       x += al_get_glyph_advance(ex.f3, cp, ALLEGRO_NO_KERNING);
    }

    x = 50;
    y = 440;
    /* First draw a red string using al_draw_text, that should be hidden
     * completely by the same text drawing in green per glyph
     * using al_draw_glyph and al_get_glyph_advance below. */
    al_draw_ustr(ex.f3, red, x, y, 0, tulip);
    for (index = 0; index < al_ustr_length(tulip); index ++) {
      int cp  = ustr_at(tulip, index);
      int ncp = (index < (al_ustr_length(tulip) - 1)) ?
         ustr_at(tulip, index + 1) : ALLEGRO_NO_KERNING;
      /* Use al_get_glyph_advance for the stride and apply kerning. */
      al_draw_glyph(ex.f3, green, x, y, cp);
      x += al_get_glyph_advance(ex.f3, cp, ncp);
    }

    x = 50;
    y = 466;
    al_draw_ustr(ex.f3, red, x, y, 0, tulip);
    for (index = 0; index < al_ustr_length(tulip); index ++) {
      int cp  = ustr_at(tulip, index);
      int bbx, bby, bbw, bbh;
      al_get_glyph_dimensions(ex.f3, cp, &bbx, &bby, &bbw, &bbh);
      al_draw_glyph(ex.f3, blue, x, y, cp);
      x += bbx + bbw;
    }


    x = 10;
    y = 30;
    for (index = 0; index < al_ustr_length(vertical_text); index ++) {
      int bbx, bby, bbw, bbh;
      int cp  = ustr_at(vertical_text, index);
      /* Use al_get_glyph_dimensions for the height to apply. */
      al_get_glyph_dimensions(ex.f3, cp, &bbx, &bby, &bbw, &bbh);
      al_draw_glyph(ex.f3, green, x, y, cp);
      y += bby;
      y += bbh;
    }


    x = 30;
    y = 30;
    for (index = 0; index < al_ustr_length(vertical_text); index ++) {
      int bbx, bby, bbw, bbh;
      int cp  = ustr_at(vertical_text, index);
      /* Use al_get_glyph_dimensions for the height to apply, here bby is
       * omited for the wrong result. */
      al_get_glyph_dimensions(ex.f3, cp, &bbx, &bby, &bbw, &bbh);
      al_draw_glyph(ex.f3, red, x, y, cp);
      y += bbh;
    }


    al_hold_bitmap_drawing(false);

    target_w = al_get_bitmap_width(al_get_target_bitmap());
    target_h = al_get_bitmap_height(al_get_target_bitmap());

    xpos = target_w - 10;
    ypos = target_h - 10;
    al_get_text_dimensions(ex.f4, "Allegro", &x, &y, &w, &h);
    as = al_get_font_ascent(ex.f4);
    de = al_get_font_descent(ex.f4);
    xpos -= w;
    ypos -= h;
    x += xpos;
    y += ypos;

    al_draw_rectangle(x, y, x + w - 0.5, y + h - 0.5, black, 0);
    al_draw_line(x+0.5, y + as + 0.5, x + w - 0.5, y + as + 0.5, black, 0);
    al_draw_line(x + 0.5, y + as + de + 0.5, x + w - 0.5, y + as + de + 0.5, black, 0);

    al_hold_bitmap_drawing(true);
    al_draw_textf(ex.f4, blue, xpos, ypos, 0, "Allegro");
    al_hold_bitmap_drawing(false);

    al_hold_bitmap_drawing(true);

    al_draw_textf(ex.f3, black, target_w, 0, ALLEGRO_ALIGN_RIGHT,
       "%.1f FPS", ex.fps);

    al_draw_textf(ex.f3, black, 0, 0, 0, "%s: %d unicode ranges", font_file,
       ex.ranges_count);

    al_hold_bitmap_drawing(false);
}
Beispiel #28
0
int main(int argc, char **argv) {
	A.x = 0;
	A.y = 0;
	B.x = 400;
	B.y = 0;
	C.x = 400;
	C.y = 350;
	D.x = 0;
	D.y = 350;

	if (!al_install_system(ALLEGRO_VERSION_INT, NULL)) {
		printf("could not init Allegro\n");
		return 1;
	}

	ALLEGRO_DISPLAY *display = al_create_display(800, 600);

	if (!display) {
		printf("could not create display\n");
		return 1;
	}

	if (!al_init_primitives_addon()) {
		printf("could not init primitives\n");
		return 1;
	}

	if (!al_install_keyboard()) {
		printf("could not install keybaord\n");
		return 1;
	}

	if (!al_install_mouse()) {
		printf("could not install mouse\n");
		return 1;
	}

	ALLEGRO_BITMAP *bitmap = al_create_bitmap(800, 600);

	if (bitmap == NULL) {
		printf("could not create bitmap\n");
		return 1;
	}

	al_set_target_bitmap(bitmap);
	al_clear_to_color(al_map_rgb(255, 255, 255));
	al_draw_rectangle(A.x + xOfs, A.y + yOfs, C.x + xOfs, C.y + yOfs, al_map_rgb(0, 0, 0), 2.0);

	al_set_target_backbuffer(display);
	al_draw_bitmap(bitmap, 0, 0, 0);
	al_flip_display();

	int pair1 = 0;
	int pair2 = 0;

	ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
	ALLEGRO_EVENT event;
	al_register_event_source(queue, al_get_mouse_event_source());
	al_register_event_source(queue, al_get_keyboard_event_source());
	al_register_event_source(queue, al_get_display_event_source(display));

	while (input_counter < 4) {
		al_wait_for_event(queue, &event);
		if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN && event.mouse.button == 1) {
			input_points[input_counter].x = event.mouse.x;
			input_points[input_counter].y = event.mouse.y;

			input_counter++;

			if (input_counter > 1) {
				pair1 = input_counter - 2;
				pair2 = input_counter - 1;

				al_set_target_bitmap(bitmap);
				al_draw_line(input_points[pair1].x, input_points[pair1].y, input_points[pair2].x, input_points[pair2].y, al_map_rgb(0, 150, 0), 3.0);
				al_set_target_backbuffer(display);
				al_draw_bitmap(bitmap, 0, 0, 0);
				al_flip_display();
			}

			if (input_counter == 4) {
				pair1 = 3;
				pair2 = 0;

				al_set_target_bitmap(bitmap);
				al_draw_line(input_points[pair1].x, input_points[pair1].y, input_points[pair2].x, input_points[pair2].y, al_map_rgb(0, 150, 0), 3.0);
				al_set_target_backbuffer(display);
				al_draw_bitmap(bitmap, 0, 0, 0);
				al_flip_display();
			}
		}
	}

	VECTOR AAPrime = getCornerOffset(input_points[0], A);
	VECTOR BBPrime = getCornerOffset(input_points[1], B);
	VECTOR CCPrime = getCornerOffset(input_points[2], C);
	VECTOR DDPrime = getCornerOffset(input_points[3], D);

	VECTOR AAPrimeS, BBPrimeS, CCPrimeS, DDPrimeS;

	ALLEGRO_MOUSE_STATE state;

	POINT p;
	POINT PPPrime;

	POINT center;
	center.x = 0;
	center.y = 0;

	for (int i = 0; i < 4; i++) {
		center.x += input_points[i].x;
		center.y += input_points[i].y;
	}

	center.x /= 4;
	center.y /= 4;

	float total;

	al_flush_event_queue(queue);

	while (1) {
		al_wait_for_event(queue, &event);

		if (event.type != ALLEGRO_EVENT_MOUSE_AXES) {
			if (event.type == ALLEGRO_EVENT_KEY_DOWN || event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
				break;
			}

			continue;
		}

		al_draw_bitmap(bitmap, 0, 0, 0);

		// get the input point

		al_get_mouse_state(&state);

		p.x = state.x;
		p.y = state.y;

		// calculate the distances
		float ADistance = distance(p, input_points[0]);
		float BDistance = distance(p, input_points[1]);
		float CDistance = distance(p, input_points[2]);
		float DDistance = distance(p, input_points[3]);

		float AB = ADistance / BDistance;
		float BA = BDistance / ADistance;
		total = AB + BA;
		AB /= total;
		BA /= total;

		float topVec = AAPrime.y * BA + BBPrime.y * AB;

		float ACurs = fabs(p.y - input_points[0].y);
		float BCurs = fabs(p.y - input_points[1].y);
		float topCurs = ACurs * BA + BCurs * AB;

		al_draw_line(p.x, p.y, p.x, p.y + topVec, al_map_rgb(0, 255, 0), 4.0);
		al_draw_circle(p.x, p.y + topVec, 5, al_map_rgb(0, 0, 0), 2.0);

		float CD = CDistance / DDistance;
		float DC = DDistance / CDistance;
		total = DC + CD;
		CD /= total;
		DC /= total;

		float bottomVec = CCPrime.y * DC + DDPrime.y * CD;

		float DCurs = fabs(p.y - input_points[3].y);
		float CCurs = fabs(p.y - input_points[2].y);
		float bottomCurs = DCurs * CD + CCurs * DC;

		al_draw_line(p.x, p.y, p.x, p.y + bottomVec, al_map_rgb(0, 255, 0), 4.0);
		al_draw_circle(p.x, p.y + bottomVec, 5, al_map_rgb(0, 0, 0), 2.0);

		float topBottom = topCurs / bottomCurs;
		float bottomTop = bottomCurs / topCurs;
		total = topBottom + bottomTop;
		topBottom /= total;
		bottomTop /= total;

		float BC = BDistance / CDistance;
		float CB = CDistance / BDistance;
		total = BC + CB;
		BC /= total;
		CB /= total;

		float rightVec = BBPrime.x * CB + CCPrime.x * BC;

		BCurs = fabs(p.x - input_points[1].x);
		CCurs = fabs(p.x - input_points[2].x);
		float rightCurs= BCurs * CB + CCurs * BC;

		al_draw_line(p.x, p.y, p.x + rightVec, p.y, al_map_rgb(0, 255, 0), 4.0);
		al_draw_circle(p.x + rightVec, p.y, 5, al_map_rgb(0, 0, 0), 2.0);

		float DA = DDistance / ADistance;
		float AD = ADistance / DDistance;
		total = DA + AD;
		DA /= total;
		AD /= total;

		float leftVec = DDPrime.x * AD + AAPrime.x * DA;

		ACurs = fabs(p.x - input_points[0].x);
		DCurs = fabs(p.x - input_points[3].x);
		float leftCurs = ACurs * DA + DCurs * AD;

		al_draw_line(p.x, p.y, p.x + leftVec, p.y, al_map_rgb(0, 255, 0), 4.0);
		al_draw_circle(p.x + leftVec, p.y, 5, al_map_rgb(0, 0, 0), 2.0);

		float leftRight = leftCurs / rightCurs;
		float rightLeft = rightCurs / leftCurs;
		total = leftRight + rightLeft;
		leftRight /= total;
		rightLeft /= total;

		// draw the main corner vectors
/*		al_draw_line(input_points[0].x, input_points[0].y, input_points[0].x + AAPrime.x, input_points[0].y + AAPrime.y, al_map_rgb(0, 0, 0), 2.0);*/
/*		al_draw_line(input_points[1].x, input_points[1].y, input_points[1].x + BBPrime.x, input_points[1].y + BBPrime.y, al_map_rgb(0, 0, 0), 2.0);*/
/*		al_draw_line(input_points[2].x, input_points[2].y, input_points[2].x + CCPrime.x, input_points[2].y + CCPrime.y, al_map_rgb(0, 0, 0), 2.0);*/
/*		al_draw_line(input_points[3].x, input_points[3].y, input_points[3].x + DDPrime.x, input_points[3].y + DDPrime.y, al_map_rgb(0, 0, 0), 2.0);*/

		// draw the corner vector components
/*		al_draw_line(input_points[0].x, input_points[0].y, input_points[0].x + AAPrime.x, input_points[0].y, al_map_rgb(255, 0, 0), 1.0);*/
/*		al_draw_line(input_points[0].x, input_points[0].y, input_points[0].x, input_points[0].y + AAPrime.y, al_map_rgb(255, 0, 0), 1.0);*/

/*		al_draw_line(input_points[1].x, input_points[1].y, input_points[1].x + BBPrime.x, input_points[1].y, al_map_rgb(255, 0, 0), 1.0);*/
/*		al_draw_line(input_points[1].x, input_points[1].y, input_points[1].x, input_points[1].y + BBPrime.y, al_map_rgb(255, 0, 0), 1.0);*/

/*		al_draw_line(input_points[2].x, input_points[2].y, input_points[2].x + CCPrime.x, input_points[2].y, al_map_rgb(255, 0, 0), 1.0);*/
/*		al_draw_line(input_points[2].x, input_points[2].y, input_points[2].x, input_points[2].y + CCPrime.y, al_map_rgb(255, 0, 0), 1.0);*/

/*		al_draw_line(input_points[3].x, input_points[3].y, input_points[3].x + DDPrime.x, input_points[3].y, al_map_rgb(255, 0, 0), 1.0);*/
/*		al_draw_line(input_points[3].x, input_points[3].y, input_points[3].x, input_points[3].y + DDPrime.y, al_map_rgb(255, 0, 0), 1.0);*/

		// draw the processed point

		PPPrime.y = topVec * bottomTop + bottomVec * topBottom;
		PPPrime.x = rightVec * leftRight + leftVec * rightLeft;

		al_draw_line(p.x, p.y, p.x + PPPrime.x, p.y, al_map_rgb(0, 0, 255), 2.0);
		al_draw_line(p.x, p.y, p.x, p.y + PPPrime.y, al_map_rgb(0, 0, 255), 2.0);

		al_draw_circle(p.x + xOfs + PPPrime.x, p.y + yOfs + PPPrime.y, 5, al_map_rgb(0, 255, 0), 2.0);
		al_draw_circle(p.x + xOfs + PPPrime.x, p.y + yOfs + PPPrime.y, 1, al_map_rgb(0, 0, 0), 1.0);

		al_flip_display();
	}

	return 0;
}
Beispiel #29
0
void draw_tile(al_defs *al, int i, int j, level* lvl) {
  int y_offset = 50;
  int wx = 0.8f * al->width;
  int wy = 0.8f * al->height - y_offset;
  int th = wy/lvl->h;
  int tw = wx/lvl->w;

  int t = (th>tw)?tw:th;
  t=(t>40)?40:t;
  int x_offset = (al->width - lvl->w*t)/2;
  //god will hate me.
  ALLEGRO_COLOR color;
  switch(lvl->map[i][j]) {
    case '#': 
      color = al_map_rgb(20,20,20);
      break;
    default:
      color = al_map_rgb(0,0,0);
  }

  int x1=x_offset+(j*t), 
      y1=y_offset+(i*t), 
      x2=x_offset+((j+1)*t), 
      y2=y_offset+((i+1)*t);
  
  al_draw_filled_rectangle(x1,y1,x2,y2,color);
  al_draw_rectangle(x1,y1,x2,y2, al_map_rgb(30,30,30), 1.0); //bounding 

  switch(lvl->map[i][j]) {
    case 'P': // player! will be replaced by sprite.
      //al_draw_filled_rectangle(x1+(t/3), y1+(t/3), x2-(t/3), y2-(t/3),
      //    al_map_rgb(255,0,0));
      al_draw_filled_circle(x1+(t/2), y1+(t/2), t/4, al_map_rgb(0,0,120));
      break;

    case 'S': // chest not in correct place
      al_draw_filled_rectangle(x1+(t/4), y1+(t/4), x2-(t/4), y2-(t/4),
          al_map_rgb(255,255,0));
      break;

    case 'X': //destination
      //al_draw_filled_rectangle(x1+(t/3), y1+(t/3), x2-(t/3), y2-(t/3),
      //    al_map_rgb(0,255,255));
      al_draw_line(x1,y1,x2,y2,al_map_rgb(255,0,0),1.0);
      al_draw_line(x1,y1+t,x2,y2-t,al_map_rgb(255,0,0),1.0);
      break;
      
    case 'Z': //chest in correct place 
      al_draw_line(x1,y1,x2,y2,al_map_rgb(0,255,0),1.0);
      al_draw_line(x1,y1+t,x2,y2-t,al_map_rgb(0,255,0),1.0);

      al_draw_filled_rectangle(x1+(t/4), y1+(t/4), x2-(t/4), y2-(t/4),
          al_map_rgb(255,255,0));
      break;

    case 'C': //player on destination point
      al_draw_line(x1,y1,x2,y2,al_map_rgb(255,0,0),1.0);
      al_draw_line(x1,y1+t,x2,y2-t,al_map_rgb(255,0,0),1.0);
      al_draw_filled_circle(x1+(t/2), y1+(t/2), t/4, al_map_rgb(0,0,120));
      break;
  }
  return;
}
Beispiel #30
0
int main()
{
    const int SCREEN_W = 1280, SCREEN_H = 768;

    ALLEGRO_DISPLAY *display = NULL;

    ALLEGRO_EVENT_QUEUE* queue;

    ALLEGRO_FONT* century_gothic40;
    ALLEGRO_FONT* century_gothic24;

    ALLEGRO_BITMAP* MenuBackground;
    ALLEGRO_BITMAP* ArenaBackground;
    ALLEGRO_BITMAP* Ball;

    //ALLEGRO_SAMPLE* BackgroundMusic;
    //ALLEGRO_SAMPLE* Boop;
    //ALLEGRO_SAMPLE* Score;
    //ALLEGRO_SAMPLE* Intro;

    ALLEGRO_TIMER* timer;

    Gamemode gamemode = Menu;

    std::string player_text = "PLAYER : 0", ai_text = "BOT : 0";
    unsigned int player_score = 0, ai_score = 0;

    if(!al_init())
    {
        printf("al_init Failed!\n");
        return -1;
    }
    //if(!al_install_audio())
    //{
        //fprintf(stderr, "Failed to initialize audio!\n");
        //return -1;
    //}

    //if(!al_init_acodec_addon())
    //{
        //fprintf(stderr, "Failed to initialize audio codecs!\n");
        //return -1;
    //}

    //if (!al_reserve_samples(1))
    //{
        //fprintf(stderr, "Failed to reserve samples!\n");
        //return -1;
    //}
    if(!al_install_mouse())
    {
        fprintf(stderr, "Failed to initialize the mouse!\n");
        return -1;
    }
    if(!al_init_primitives_addon())
    {
        printf("al_init_primitives_addon Failed!\n");
        return -1;
    }
    display = al_create_display(SCREEN_W, SCREEN_H);

    if(!display)
    {
        printf("al_create_display Failed!\n");
        return -1;
    }

    srand(time(NULL));

    al_init_font_addon();
    al_init_ttf_addon();
    al_install_keyboard();
    al_init_image_addon();

    queue = al_create_event_queue();
    timer = al_create_timer(1.0 / 60);

    al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_mouse_event_source());
    al_register_event_source(queue, al_get_display_event_source(display));
    al_register_event_source(queue, al_get_timer_event_source(timer));

    al_start_timer(timer);

    century_gothic40  = al_load_ttf_font("C:\\Windows\\Fonts\\GOTHIC.TTF" , 40, ALLEGRO_ALIGN_CENTRE);
    century_gothic24  = al_load_ttf_font("C:\\Windows\\Fonts\\GOTHIC.TTF" , 24, ALLEGRO_ALIGN_CENTRE);

    MenuBackground = LoadB("res\\menu.png");
    ArenaBackground = LoadB("res\\arena.png");
    Ball = LoadB("res\\ball.png");

    //BackgroundMusic = LoadS("res\\rain.wav");
    //Boop = LoadS("res\\boop.ogg");
    //Score = LoadS("res\\score.wav");
    //Intro = LoadS("res\\intro.ogg");

    //ALLEGRO_VOICE *audioDevice = al_create_voice(44100,  ALLEGRO_AUDIO_DEPTH_FLOAT32 , ALLEGRO_CHANNEL_CONF_2);
    //ALLEGRO_MIXER *mixerMaster = al_create_mixer(44100,  ALLEGRO_AUDIO_DEPTH_FLOAT32 , ALLEGRO_CHANNEL_CONF_2);
    //ALLEGRO_MIXER *mixerMusic = al_create_mixer(44100,  ALLEGRO_AUDIO_DEPTH_FLOAT32 , ALLEGRO_CHANNEL_CONF_2);
    //ALLEGRO_MIXER *mixerSounds = al_create_mixer(44100,  ALLEGRO_AUDIO_DEPTH_FLOAT32 , ALLEGRO_CHANNEL_CONF_2);

    //if (audioDevice == NULL || mixerMaster == NULL || mixerMusic == NULL || mixerSounds == NULL)
    //{
        //printf("Failed to start audio devices");
    //}

/*  Attempt of Audio
    al_attach_sample_instance_to_mixer(Boop, mixerSounds);
    al_attach_sample_instance_to_mixer(BackgroundMusic, mixerMusic);
    al_attach_sample_instance_to_mixer(Score, mixerSounds);
    al_attach_sample_instance_to_mixer(Intro, mixerSounds);

    al_attach_mixer_to_mixer(mixerMusic, mixerMaster);
    al_attach_mixer_to_mixer(mixerSounds, mixerMaster);
    al_attach_mixer_to_voice(mixerMaster, audioDevice);

    //ALLEGRO_SAMPLE_INSTANCE BoopI = al_create_sample_instance(Boop);
    //ALLEGRO_SAMPLE_INSTANCE ScoreI = al_create_sample_instance(Score);
    //al_play_sample(BackgroundMusic, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,NULL);*/

    float player_y = 0, player_y_vel = 0,
          ai_y_vel = 0, ai_y = 0,
          ball_x = (SCREEN_W/2)-12, ball_x_vel = (rand() % 2) ? 5 : -5,
          ball_y = (SCREEN_H/2)-15, ball_y_vel = 0,
          multiplier = 1;

    bool render , scored, executing = true;
    //al_play_sample(Intro, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_ONCE,NULL);
    while (executing)
    {
        ALLEGRO_EVENT event;
        al_wait_for_event(queue, &event);
        switch(event.type)
        {
        case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
            switch (gamemode)
            {
            case Menu:
                if ((event.mouse.x >= (SCREEN_W / 2) - 150) && (event.mouse.x <= (SCREEN_W / 2) + 150))
                {
                    if ((event.mouse.y >= 205) && (event.mouse.y <= 280))
                    {
                        gamemode = Game;
                    }
                    else if ((event.mouse.y >= 305) && (event.mouse.y <= 380))
                    {
                        gamemode = Description;
                    }
                    else if ((event.mouse.y >= 405) && (event.mouse.y <= 480))
                    {
                        executing = false;
                    }
                }
                break;
            case Description:

                break;
            case Conclusion:
                if ((event.mouse.x >= (SCREEN_W/2)-150) && (event.mouse.x <= (SCREEN_W/2)+150))
                {
                    if ((event.mouse.y >= 305) && (event.mouse.y <= 380))
                    {
                        player_score = ai_score = player_y = player_y_vel = ai_y_vel = ai_y = ball_y_vel = 0;
                        ball_x_vel = (rand() % 2) ? 5 : -5;
                        ball_x = (SCREEN_W / 2) - 12;
                        ball_y = (SCREEN_H / 2) - 15;
                        multiplier = 1;
                        player_text = "PLAYER : 0";
                        ai_text = "BOT : 0";
                        gamemode = Menu;
                    }
                    else if ((event.mouse.y >= 405) && (event.mouse.y <= 480))
                    {
                        executing = false;
                    }
                }
                break;
            }
            break;
        case ALLEGRO_EVENT_DISPLAY_CLOSE:
            executing = false;
            break;
        case ALLEGRO_EVENT_KEY_DOWN:
            switch(event.keyboard.keycode)
            {
            case ALLEGRO_KEY_ESCAPE:
                switch (gamemode)
                {
                case Game:
                    executing = false;
                    break;
                }
                break;
            case ALLEGRO_KEY_UP:
            case ALLEGRO_KEY_W:
                player_y_vel = -10;
                break;
            case ALLEGRO_KEY_DOWN:
            case ALLEGRO_KEY_S:
                player_y_vel = 10;
                break;
            case ALLEGRO_KEY_ENTER:
                executing = false;
                break;
            }
            gamemode = Game;
            break;
        case ALLEGRO_EVENT_KEY_UP:
            player_y_vel = 0;
            break;
        case ALLEGRO_EVENT_TIMER:
            render = true;
            switch(gamemode)
            {
            case Game:
                // Scoring
                bool scored = false;
                if (ball_x >= SCREEN_W)
                {
                    player_score++;
                    scored = true;
                    std::stringstream ss;
                    ss << "PLAYER : " << player_score;
                    player_text = ss.str();
                }
                if (ball_x <= 0)
                {
                    ai_score++;
                    scored = true;
                    std::stringstream ss;
                    ss << "BOT : " << ai_score;
                    ai_text = ss.str();
                }
                if (scored)
                {
                    //al_play_sample(Score, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_ONCE,NULL);
                    //al_play_sample_instance(ScoreI);
                    ball_x = (SCREEN_W/2)-12;
                    ball_y = (SCREEN_H/2)-15;
                    ball_x_vel = (rand() % 2) ? 5.75 : -5.75;
                    ball_y_vel = 0;
                    ai_y = 0;
                    player_y = 0;
                    multiplier = 1;
                }
                // Collision
                if (((((SCREEN_H/2)-50)+player_y)<=0)&&(player_y_vel<0)) player_y_vel = 0;
                if (((((SCREEN_H/2)+50)+player_y)>=SCREEN_H)&&(player_y_vel>0)) player_y_vel = 0;
                if ((ball_y <= 0) || (ball_y >= SCREEN_H)) ball_y_vel = -ball_y_vel;
                if (((ball_y <= (((SCREEN_H / 2) + 50) + player_y) && (ball_y >= (((SCREEN_H / 2) - 50) + player_y))) && ((ball_x <= 90) && (ball_x >= 75))) || (((ball_y <= (((SCREEN_H / 2) + 50) + ai_y)) && (ball_y >= (((SCREEN_H / 2) - 50) + ai_y))) && (((ball_x >= SCREEN_W - 110)) && (ball_x <= SCREEN_W - 75))))
                {
                    //al_play_sample(Boop, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_ONCE,NULL);
                    //al_play_sample_instance(BoopI);
                    ball_x_vel = -ball_x_vel * multiplier;
                    multiplier += 0.005f;
                    ball_y_vel = (rand() % 10) - 5;
                }
                // AI
                if (ball_x_vel > 0)                                                 // Ball comming towards AI
                {
                    if ((ai_y <= 340) && (ai_y >= -340))                              // AI is in game bounds
                    {
                        if ((SCREEN_H/2)+ai_y < ball_y) ai_y_vel = abs(ball_y_vel) < 3 ? abs(ball_y_vel) : 5;
                        else if ((SCREEN_H/2)+ai_y == ball_y) ai_y_vel = 0;
                        else ai_y_vel = abs(ball_y_vel) < 3 ? -abs(ball_y_vel) : -5;
                    }
                    else if (ai_y >  340) ai_y_vel = -3;
                    else if (ai_y < -340) ai_y_vel = 3;
                    else ai_y_vel = 0;
                }
                else                                                                 // Go towards center
                {
                    if (ai_y > 10) ai_y_vel = -1;
                    else if (ai_y < 10) ai_y_vel = 1;
                    else ai_y_vel = 0;
                }
                // Movement
                player_y += player_y_vel;
                ai_y += ai_y_vel;
                ball_x += ball_x_vel;
                ball_y += ball_y_vel;
                if (player_score >= 10 || ai_score >= 10) gamemode = Conclusion;
                break;
            }
            break;
        }

        if (al_is_event_queue_empty(queue) && render)
        {
            al_clear_to_color(al_map_rgb(0,0,0));
            al_set_target_bitmap(al_get_backbuffer(display));
            ////////////////////////////////////////////////////////////////////

            switch(gamemode)
            {
            case Menu:
                al_draw_bitmap(MenuBackground, 0, 0, 0);
                al_draw_text(century_gothic40, al_map_rgb(250,250,250), SCREEN_W/2, 40, ALLEGRO_ALIGN_CENTRE, "Ultimate Pong");
                al_draw_rectangle((SCREEN_W / 2) - 150, 205, (SCREEN_W / 2) + 150, 280, al_map_rgb(255, 255, 255), 3);
                al_draw_text(century_gothic40, al_map_rgb(250, 250, 250), SCREEN_W / 2, 220, ALLEGRO_ALIGN_CENTRE, "Play");
                al_draw_rectangle((SCREEN_W / 2) - 150, 305, (SCREEN_W / 2) + 150, 380, al_map_rgb(255, 255, 255), 3);
                al_draw_text(century_gothic40, al_map_rgb(250, 250, 250), SCREEN_W / 2, 320, ALLEGRO_ALIGN_CENTRE, "About");
                al_draw_rectangle((SCREEN_W / 2) - 150, 405, (SCREEN_W / 2) + 150, 480, al_map_rgb(255, 255, 255), 3);
                al_draw_text(century_gothic40, al_map_rgb(250, 250, 250), SCREEN_W / 2, 420, ALLEGRO_ALIGN_CENTRE, "Quit");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 200, SCREEN_H - 50, ALLEGRO_ALIGN_CENTRE, "Game by Thomas Steinholz");

                break;
            case Description:
                al_draw_bitmap(MenuBackground, 0, 0, 0);
                al_draw_text(century_gothic40, al_map_rgb(250, 250, 250), SCREEN_W / 2, 40, ALLEGRO_ALIGN_CENTRE, "About Ultimate Pong");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 100, 240, ALLEGRO_ALIGN_LEFT, "This is the game of Ultimate Pong! The game consists of 2 paddles knocking a ball back and");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 100, 260, ALLEGRO_ALIGN_LEFT, "forth until one misses it and it goes into the goal. The point of the game is to score 10 ");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 100, 280, ALLEGRO_ALIGN_LEFT, "points. You can score a point by getting the ball in the other player's goal (right behind");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 100, 300, ALLEGRO_ALIGN_LEFT, "the enemy paddle). You control the game by using either the UP and DOWN arrow or the W and");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 100, 320, ALLEGRO_ALIGN_LEFT, "S key. As you can guess, the up arrow brings your player up while the down arrow brings   ");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 100, 340, ALLEGRO_ALIGN_LEFT, "your player down. The W key functions the same as the UP arrow as the S key functions the");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 100, 360, ALLEGRO_ALIGN_LEFT, "same as the DOWN key. The game ends once either the player of AI has reached a point value");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 100, 380, ALLEGRO_ALIGN_LEFT, "of 10. You play as the left paddle and the AI plays as the right paddle. You can see the  ");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 100, 400, ALLEGRO_ALIGN_LEFT, "corresponding scores above the side you play as if you get lost or confused. To get       ");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 100, 420, ALLEGRO_ALIGN_LEFT, "started, hit the ESC button. DISCLAIMER : IF YOU GET HURT, ITS NOT PONGS FAULT SO DONT SUE");
                al_draw_text(century_gothic24, al_map_rgb(250,250,250), 200, SCREEN_H - 50, ALLEGRO_ALIGN_CENTRE, "PRESS sESC TO PLAY");

                break;
            case Game:
                al_draw_bitmap(ArenaBackground, 0, 0, 0);
                al_draw_line((SCREEN_W/2)-3,0,(SCREEN_W/2)-3,SCREEN_H,al_map_rgb(255,255,255), 2);
                al_draw_circle((SCREEN_W/2)-5,(SCREEN_H/2)-5, 150, al_map_rgb(255,255,255), 2);
                al_draw_filled_rectangle(75,((SCREEN_H/2)-50)+player_y,90,((SCREEN_H/2)+50)+player_y,al_map_rgb(255,255,255));              //Player
                al_draw_filled_rectangle(SCREEN_W-75,((SCREEN_H/2)-50)+ai_y,SCREEN_W-90,((SCREEN_H/2)+50)+ai_y,al_map_rgb(255,255,255));    //AI
                al_draw_scaled_bitmap(
                    Ball,
                    0, 0,
                    al_get_bitmap_width(Ball), al_get_bitmap_height(Ball),
                    ball_x, ball_y,
                    15, 15,
                    0);
                al_draw_text(century_gothic40, al_map_rgb(250,250,250), 140, 40, ALLEGRO_ALIGN_CENTRE, player_text.c_str());
                al_draw_text(century_gothic40, al_map_rgb(250,250,250), SCREEN_W-100, 40, ALLEGRO_ALIGN_CENTRE, ai_text.c_str());
                break;
            case Conclusion:
                al_draw_bitmap(MenuBackground, 0, 0, 0);
                al_draw_text(century_gothic40, al_map_rgb(250, 250, 250), SCREEN_W / 2, 40, ALLEGRO_ALIGN_CENTRE, "Game Over!");
                al_draw_text(century_gothic40, al_map_rgb(250, 250, 250), SCREEN_W / 2, 80, ALLEGRO_ALIGN_CENTRE, ai_score < player_score ? "You Win!" : "You Lose!");
                al_draw_textf(century_gothic40, al_map_rgb(250, 250, 250), SCREEN_W / 2, 120, ALLEGRO_ALIGN_CENTRE, "%d : %d", player_score, ai_score);
                al_draw_rectangle((SCREEN_W/2)-150, 305, (SCREEN_W/2)+150, 380, al_map_rgb(255, 255, 255), 3);
                al_draw_text(century_gothic40, al_map_rgb(250, 250, 250), SCREEN_W / 2, 320, ALLEGRO_ALIGN_CENTRE, "Restart");
                al_draw_rectangle((SCREEN_W / 2) - 150, 405, (SCREEN_W / 2) + 150, 480, al_map_rgb(255, 255, 255), 3);
                al_draw_text(century_gothic40, al_map_rgb(250, 250, 250), SCREEN_W / 2, 420, ALLEGRO_ALIGN_CENTRE, "Quit");
                break;
            }

            ////////////////////////////////////////////////////////////////////
            al_flip_display();
        }
        render = false;
    }

    al_destroy_bitmap(MenuBackground);
    al_destroy_bitmap(ArenaBackground);
    al_destroy_bitmap(Ball);
    //al_destroy_sample(BackgroundMusic);
    //al_destroy_sample(Boop);
    //al_destroy_sample(Score);
    al_destroy_display(display);

    return 0;
}