void OurHero::drawProjectile(Projectiles projectile[], int size) {
    for (int i = 0; i < size; i++) {
        if (projectile[i].isLive()) {
            al_draw_circle(projectile[i].getX(), projectile[i].getY(), 2, al_map_rgb(255, 255, 255), 2);
        }
    }
}
Beispiel #2
0
void draw_config(game *g) {
    ALLEGRO_TRANSFORM trans;
    al_identity_transform(&trans);
    al_use_transform(&trans);
    
    int x, y;
    x = (g->Size->x - 150) / 2;
    y = 0;
    al_draw_text(ttf_font, al_map_rgb(200, 200, 200), x, y, ALLEGRO_ALIGN_LEFT, "CONFIGURATION");
    
    if(get_config("display_width") == NULL) return;
    
    x = 100;
    y = 100;
    char msg[22];
    sprintf(msg, "DISPLAY WIDTH: %d", atoi(get_config("display_width")));
    al_draw_text(ttf_font, al_map_rgb(200, 200, 200), x, y, ALLEGRO_ALIGN_LEFT, msg);
    
    x = 100;
    y = 125;
    sprintf(msg, "DISPLAY HEIGHT: %d", atoi(get_config("display_height")));
    al_draw_text(ttf_font, al_map_rgb(200, 200, 200), x, y, ALLEGRO_ALIGN_LEFT, msg);
    
    al_draw_circle(80, 110 + config_pos * 25, 3.0, SHOOT_COLOR, 1.5);    
}
Beispiel #3
0
void Draw_body(b2Body* body, b2Vec2 camera)
{
	float scale = 10;
	b2Vec2 position = scale*body->GetPosition() - camera;
	float32 angle = body->GetAngle();

	al_draw_pixel(position.x, position.y, al_map_rgb_f(1, 0, 0));

	for (b2Fixture* f = body->GetFixtureList(); f; f = f->GetNext())
	{
		b2Shape* shape_base = f->GetShape();
		if(shape_base->GetType() == b2Shape::e_polygon)
		{
			b2PolygonShape& shape = dynamic_cast<b2PolygonShape&>(*shape_base);
			int np = shape.GetVertexCount ();
			b2Vec2 pn = scale*shape.GetVertex(np-1);
			b2Vec2 ps, pe;
			ps.x = cos(angle)*pn.x - sin(angle)*pn.y;
			ps.y = sin(angle)*pn.x + cos(angle)*pn.y;
			for(int i=0; i<np; ++i)
			{
				pn = scale*shape.GetVertex(i);
				pe.x = cos(angle)*pn.x - sin(angle)*pn.y;
				pe.y = sin(angle)*pn.x + cos(angle)*pn.y;
				al_draw_line(position.x+ps.x, position.y+ps.y, position.x+pe.x, position.y+pe.y, al_map_rgb_f(1, 0, 0), 0);
				ps = pe;
			}
		}
		if(shape_base->GetType() == b2Shape::e_circle)
		{
			b2CircleShape& shape = dynamic_cast<b2CircleShape&>(*shape_base);
			al_draw_circle(position.x, position.y, shape.m_radius * scale, al_map_rgb_f(1, 0, 0), 0);
		}
	}
}
Beispiel #4
0
void show_tower_information(Torre torre[], int t, ALLEGRO_FONT *fonte) //Monstra as informaçoes da torre selecionada
{
    al_draw_circle(torre[t].x, torre[t].y, torre[t].range, al_map_rgb(10, 110, 10), 0);
    al_draw_textf(fonte, al_map_rgb(0, 0, 0), 5 * l_celula, 19 * a_celula, ALLEGRO_ALIGN_LEFT, "Tower type: %i", torre[t].n);
    al_draw_textf(fonte, al_map_rgb(0, 0, 0), 5 * l_celula, 20 * a_celula, ALLEGRO_ALIGN_LEFT, "Tower fire power: %i", torre[t].fire_power);
    al_draw_textf(fonte, al_map_rgb(0, 0, 0), 5 * l_celula, 21 * a_celula, ALLEGRO_ALIGN_LEFT, "Tower range: %i", torre[t].range);
    al_draw_textf(fonte, al_map_rgb(0, 0, 0), 5 * l_celula, 22 * a_celula, ALLEGRO_ALIGN_LEFT, "Tower fire rate: %.2fs", torre[t].fire_rate);
    al_draw_textf(fonte, al_map_rgb(0, 0, 0), 5 * l_celula, 23 * a_celula, ALLEGRO_ALIGN_LEFT, "Upgrade: %i", torre[t].upgrade);
}
Beispiel #5
0
/**< Função Desenha um circulo na Janela */
void Des_Circulo(int desenha_circulo, ALLEGRO_FONT *fonte, int x1, int y1, int x2, int y2)
{
    if (desenha_circulo == 1)
    {
        float r = sqrt(pow(x1 - x2,2) + pow(y1 - y2,2));
        al_draw_text(fonte, al_map_rgb(255, 255, 255), 320, 70, ALLEGRO_ALIGN_CENTRE, "Precione em 2 pontos:");
        al_draw_circle(x1, y1, r, al_map_rgb(255, 255, 255), 2);
    }
}
Beispiel #6
0
void m_draw_circle(int x, int y, int radius, MCOLOR color,
	int flags)
{
	if (flags & M_FILLED) {
		al_draw_filled_circle(x, y, radius, color);
	}
	else {
		al_draw_circle(x, y, radius, color, 1);
	}
}
static void draw_touches(int num, TOUCH touches[])
{
   int i;

   for (i = 0; i < num; i++) {
      int x = touches[i].x;
      int y = touches[i].y;
      al_draw_circle(x, y, 50, al_map_rgb(255, 0, 0), 4);
   }
}
Beispiel #8
0
// Draw
void particle::draw(){
  if( type == PIXEL){
    al_put_pixel( x, y, color);
  }
  else if( type == SQUARE){
    al_draw_rectangle( x, y, x + size, y + size, color, 1);
  }
  else if( type == CIRCLE){
    al_draw_circle( x, y, size, color, 1);
  }
}
Beispiel #9
0
		void ShapeRenderer::drawCircleOutline(float x, float y, float rad, float lineW, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
		{
			ALLEGRO_COLOR color;
			if (a != UINT8_MAX)
				color = al_map_rgba(r, g, b, a);
			else
				color = al_map_rgb(r, g, b);
			float adjustedX = (x + xOff) * xScale;
			float adjustedY = (y + yOff) * yScale;
			al_draw_circle(adjustedX, adjustedY, rad * ((xScale + yScale) / 2), color, lineW);
		}
Beispiel #10
0
void RenderTarget::drawCircle(float cx, float cy, float r, bool fill, const ALLEGRO_COLOR &color) {
	convertCoords(cx, cy);
	if (r <= 0) {
		return;
	}
	setAsCurrent();
	if (fill) {
		al_draw_filled_circle(cx, cy, r, color);
	}
	else {
		al_draw_circle(cx, cy, r, color, CBEnchanted::instance()->gfxInterface->getLineWidth());
	}
}
Beispiel #11
0
int main()
{
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_FONT* century_gothic24;

    if(!al_init())
    {
        printf("al_init Failed!\n");
        return -1;
    }
    if(!al_init_primitives_addon())
    {
        printf("al_init_primitives_addon Failed!\n");
        return -1;
    }
    display = al_create_display(640, 480);
    if(!display)
    {
        printf("al_create_display Failed!\n");
        return -1;
    }
    al_init_font_addon();
    al_init_ttf_addon();
    century_gothic24  = al_load_ttf_font("C:\\Windows\\Fonts\\GOTHIC.TTF" , 24, ALLEGRO_ALIGN_CENTRE);
    // Paint a hidden screen (a buffer), that we'll apply later.
    al_clear_to_color(al_map_rgb(0,0,0));
    // Draw an ugly red triangle to the buffer.
    al_draw_filled_triangle(10, 10, 200, 200, 350, 230, al_map_rgb(255,0,0));
    // Draw text to the buffer
    al_draw_text(century_gothic24, al_map_rgb(255,255,255), 550, 440, ALLEGRO_ALIGN_CENTRE, "Hello World!");
    // Draw a line to the buffer
    al_draw_line(400,400,500,34,al_map_rgb(255,255,255), 5);
    // Draw a circle
    al_draw_circle(300,300, 50, al_map_rgb(255,255,0), 5);
    // Draw Eclipse
    al_draw_filled_ellipse(500, 300, 40, 56, al_map_rgb(255,0,255));
    // Draw a rectangle
    al_draw_rectangle(100,200,200,300,al_map_rgb(0,255,0), 6);s
    // Draw a polygon
    al_draw_filled_rectangle(0,480,50,400,al_map_rgb(25,185,35));
    al_draw_filled_rectangle(0,480,200,450,al_map_rgb(25,185,35));
    // Apply the buffer to the front.
    al_flip_display();
    // Wait for 3 secs.
    al_rest(10.0);
    // Destroying the display we created, to avoid memory leaking.
    al_destroy_display(display);

    return 0;
}
Beispiel #12
0
void bn_desenhaBola(const BN_BOLA *b)
{
    if(b->efeito == 'c')
    {
        al_draw_circle(b->x, b->y, b->raio, b->cor, 2);
    }
    else if(b->efeito == 't')
    {
        al_draw_filled_circle(b->x, b->y, b->raio, al_map_rgba(255, 255, 255, 128));
    }
    else
    {
        al_draw_filled_circle(b->x, b->y, b->raio, b->cor);
    }
}
Beispiel #13
0
void shal_draw_circle(float cx,
                      float cy,
                      float r,
                      float color_r,
                      float color_g,
                      float color_b,
                      float color_a,
                      float thickness)
{
    ALLEGRO_COLOR color;
    color.r = color_r;
    color.g = color_g;
    color.b = color_b;
    color.a = color_a;
    return al_draw_circle(cx, cy, r, color, thickness);
}
Beispiel #14
0
static duk_ret_t
js_OutlinedCircle(duk_context* ctx)
{
	bool    antialiased = false;
	color_t color;
	int     n_args;
	int     x, y, radius;

	n_args = duk_get_top(ctx);
	x = duk_to_int(ctx, 0);
	y = duk_to_int(ctx, 1);
	radius = duk_to_int(ctx, 2);
	color = duk_require_sphere_color(ctx, 3);
	if (n_args >= 5) antialiased = duk_require_boolean(ctx, 4);
	if (!is_skipped_frame()) al_draw_circle(x, y, radius, nativecolor(color), 1);
	return 0;
}
Beispiel #15
0
void AIMap::draw() {
  for(int i = 0; i < map_obstacles.size(); i++) {
    drawObstacle(map_obstacles[i]);
  }
  
  for(int i = 0; i < graphNodes.size(); i++) {
    for(int j = 0; j < graphNodes[i]->neighbours.size(); j++) {
      al_draw_line(graphNodes[i]->position.x, graphNodes[i]->position.y, 
		   graphNodes[i]->neighbours[j]->position.x, graphNodes[i]->neighbours[j]->position.y,
		   al_map_rgb(150,150,150), 1.0f);      
    }
    al_draw_circle(graphNodes[i]->position.x, graphNodes[i]->position.y, 1, al_map_rgb(0,255,0), 2.0f);
    
    if(Keyboard::getInstance().key[Keyboard::KEY_1]) {
      
    }
  }
}
Steering* WanderAndSeekOrFlee::getSteering()
{
	Vector2D direction = mpTarget->getPosition() - mpMover->getPosition();
	float distance = direction.getLength();

	ALLEGRO_COLOR color;
	if (mShouldFlee)
		color = al_map_rgb(0, 0, 0);
	else
		color = al_map_rgb(0, 191, 255);

	if (debugOn)
		al_draw_circle(mpMover->getPosition().getX(), mpMover->getPosition().getY(), mRadius, color, 2.0f);

	if (distance > mRadius)
		return mpDynamicWanderSteering->getSteering();
	else
		return mpDynamicSeekSteering->getSteering();
}
Beispiel #17
0
void ship_draw(const ship *s) {
  // draw the bullets
  bullet_draw(s->bullets);

  // draw the ship
  const uint32_t bitmap_width = al_get_bitmap_width(s->bitmap);
  const uint32_t bitmap_height = al_get_bitmap_height(s->bitmap);

  if (s->attr.is_immune) {
    const double time_passed = al_get_time() - s->attr.time_stamp;
    if (time_passed - floor(time_passed) < 0.5) {
      al_draw_tinted_scaled_rotated_bitmap(s->bitmap, color_gray(),
                                           bitmap_width / 2,
                                           bitmap_height / 2,
                                           s->center.x, s->center.y,
                                           SHIP_SIZE / bitmap_width,
                                           SHIP_SIZE / bitmap_height,
                                           s->direction, 0);
    } else {
      al_draw_scaled_rotated_bitmap(s->bitmap,
                                    bitmap_width / 2,
                                    bitmap_height / 2,
                                    s->center.x, s->center.y,
                                    SHIP_SIZE / bitmap_width,
                                    SHIP_SIZE / bitmap_height,
                                    s->direction, 0);
    }
  } else {
    al_draw_scaled_rotated_bitmap(s->bitmap,
                                  bitmap_width / 2,
                                  bitmap_height / 2,
                                  s->center.x, s->center.y,
                                  SHIP_SIZE / bitmap_width,
                                  SHIP_SIZE / bitmap_height,
                                  s->direction, 0);
  }

#ifdef DEBUG
  al_draw_circle(s->center.x, s->center.y, 5, al_map_rgb(255, 0, 0), 3);
#endif
}
Beispiel #18
0
void FlareManager::Flare::__default_draw(Flare *flare)
{
	float inverse_counter = 1.0 - flare->counter;
	if (flare->bitmap)
	{
		if (flare->blending_mode == BLENDER_ADDITIVE)
			al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);

		al_draw_tinted_scaled_rotated_bitmap(flare->bitmap, al_map_rgba_f(flare->opacity,flare->opacity,flare->opacity,flare->opacity),
			al_get_bitmap_width(flare->bitmap)*flare->align_x, al_get_bitmap_height(flare->bitmap)*flare->align_y,
			flare->x, flare->y, flare->scale, flare->scale, flare->rotation, 0);

		if (flare->blending_mode == BLENDER_ADDITIVE)
			al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
	}
	else
	{
		al_draw_circle(flare->x, flare->y, 30*inverse_counter,
			al_map_rgba_f(flare->counter, flare->counter, flare->counter, flare->counter), 2);
	}
}
int main() {
  //inicialização
  camera *cam = camera_inicializa(0);
  if(!cam)
    erro("erro na inicializacao da camera\n");

  int largura = cam->largura;
  int altura = cam->altura;

  if(!al_init())
    erro("erro na inicializacao do allegro\n");

  if(!al_init_image_addon())
    erro("erro na inicializacao do adicional de imagem\n");

  if(!al_init_primitives_addon())
    erro("erro na inicializacao do adicional de primitivas\n");

  ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS);
  if(!timer)
    erro("erro na criacao do relogio\n");

  ALLEGRO_DISPLAY *display = al_create_display(largura, altura);
  if(!display)
    erro("erro na criacao da janela\n");

  ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
  if(!queue)
    erro("erro na criacao da fila\n");

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

  al_start_timer(timer);

  /**********/

  unsigned char ***matriz = camera_aloca_matriz(cam);
  int ***background = alocaHsvMatriz(cam->largura, cam->altura);

  fila *f = aloca();

  //cor para desenhar o círculo
  ALLEGRO_COLOR cor = al_map_rgb_f(0, 0, 1);

  ALLEGRO_BITMAP *buffer = al_get_backbuffer(display);

  //tela exibindo img normal
  ALLEGRO_BITMAP *esquerda = al_create_sub_bitmap(buffer, 0, 0, largura, altura);

  //tela mostrando como o computador enxerga
  //ALLEGRO_BITMAP *direita = al_create_sub_bitmap(buffer, largura/2, 0, largura/2, altura/2);
  ALLEGRO_BITMAP *silhueta = al_create_bitmap(largura, altura);

  /**********/
  srand(time(NULL));
  int desenhar = 0;
  int terminar = 0;

  int cycle = 0;
  int hitx = rand() % (largura);
  int hity = rand() % (altura);

  int x, y;

  float cyr, cxr, cnr, lastCx, lastCy;

  int r, g, b, r2, g2, b2;

  int h, s, v, h2, s2, v2;
  int fh, fs, fv;

  int dh, ds, dv;
  int tempH;

  int token;

  double value;
  int dist;

  al_rest(1);

  for(y = 0; y < altura; y++)
    for(x = 0; x < largura; x++){
      rgbToHsv(cam->quadro[y][x][0], cam->quadro[y][x][1], cam->quadro[y][x][2], 
        &background[y][x][0], &background[y][x][1], &background[y][x][2]);

      if(background[y][x][0] > 180){
        background[y][x][0] -= 360;
        background[y][x][0] = -background[y][x][0];
      }
        
    }

  al_rest(1);

  for(y = 0; y < altura; y++)
    for(x = 0; x < largura; x++){
      rgbToHsv(cam->quadro[y][x][0], cam->quadro[y][x][1], cam->quadro[y][x][2], 
        &fh, &fs, &fv);

      if(fh > 180){
        fh -= 360;
        fh = -fh;
      }

      background[y][x][0] += fh;
      background[y][x][0] /=2;

      background[y][x][1] += fs;
      background[y][x][1] /=2;
      
      background[y][x][2] += fv;
      background[y][x][2] /=2;  
    }

  //gameloop
  while(1) {
    ALLEGRO_EVENT event;

    al_wait_for_event(queue, &event);

    switch(event.type) {
    case ALLEGRO_EVENT_TIMER:
      desenhar = 1;

      break;

    case ALLEGRO_EVENT_DISPLAY_CLOSE:
      terminar = 1;
      break;

    default:
      printf("evento desconhecido\n");
    }

    if(terminar)
      break;

    //interpretar img e realizar transformações
    printf("%d\n", al_is_event_queue_empty(queue));
    if(desenhar && al_is_event_queue_empty(queue)) {
      desenhar = 0;
      camera_atualiza(cam);

      /**********/

      int bx, by, bn;

      cyr = 0;
      cxr = 0;
      cnr = 0;

      for(y = 0; y < altura; y++){
        for(x = 0; x < largura; x++){
          //Espada
          r = cam->quadro[y][x][0];
          g = cam->quadro[y][x][1];
          b = cam->quadro[y][x][2];

          rgbToHsv(r, g, b, &h, &s, &v);

          if(h < 15 || h > 345)
            if(s > 75 && v > 75){
              cyr += y;
              cxr += x;
              cnr++;
            }

          //Silhueta (REFINAR!!!)
          if(h > 180)
            tempH = -(h - 360);

          else
            tempH = h;

          dh = tempH - background[y][x][0];
          if(dh < 0)
            dh = -dh;

          ds = s - background[y][x][1];
          if(ds < 0)
            ds = -ds;

          dv = v - background[y][x][2];
          if(dv < 0)
            dv = -dv;

          //dh > 15 && ds > 10 para tirar a interfencia de iluminacao, mas gera mtuiro ruido
          //ds > 25 é o mais preciso, mas sofre de interferencia de iluminacao
          if(dv > 25){
            //valores para teste!
            matriz[y][x][0] = 37;
            matriz[y][x][1] = 50;
            matriz[y][x][2] = 248;
          }

          else{
            matriz[y][x][0] = 0;
            matriz[y][x][1] = 0;
            matriz[y][x][2] = 0;
          }

          //Escudo
          if(h < 135 && h > 105 && s > 50 && v > 75){
            by += y;
            bx += x;
            bn++;

            matriz[y][x][0] = 0;
            matriz[y][x][1] = 255;
            matriz[y][x][2] = 0;
          }
        }
      }

     /*for(y = 1; y < altura-1; y++)
        for(x = 1; x < largura-1; x++){
          token = 4;

          if(255 != matriz[y+1][x][0])
            token--;
          if(255 != matriz[y-1][x][0])
            token--;
          if(255 != matriz[y][x+1][0])
            token--;
          if(255 != matriz[y][x-1][0])
            token--;

          if(token == 0){
            matriz[y][x][0] = 0;
            matriz[y][x][1] = 0;
            matriz[y][x][2] = 0;
          }*/

      cycle++;
      if(cycle > 50 && bn > 0){
        value = (pow(hitx - (bx / 2 /bn), 2) + pow(hity - (by / 2 / bn), 2));
        dist = sqrt(value) - 7;

        if(dist < 100 && dist > -100 && bn > 0)
          printf("block!\n");

        else{
          if(matriz[hity][hitx][0] == 255)
            printf("hit\n");

          else
            printf("miss\n");
        }

        cycle = 0;
        hitx = rand() % (largura/2);
        hity = rand() % (altura/2);
      }

      /**********/
      camera_copia(cam, cam->quadro, esquerda);

      //Copia img editada na img direita
      camera_copia(cam, matriz, silhueta);
      //cor para teste!
      al_convert_mask_to_alpha(silhueta, al_map_rgb(37, 50, 248));
      al_draw_bitmap(silhueta, 0, 0, 0);
      /**********/

      if(bn > 0)
        al_draw_circle(bx / bn, by / bn, 100, al_map_rgb(0, 0, 255), 1);

      if(cycle >= 40){
        if(cycle < 48){
          al_draw_circle(hitx, hity, 15, al_map_rgb(0, 0, 255), 30);
          al_draw_circle(hitx + largura, hity, 6, al_map_rgb(0, 0, 255), 3);
        }

        else
          al_draw_circle(hitx, hity, 15, al_map_rgb(255, 0, 0), 30);
      }

      if(cnr > 10){
        lastCx = cxr / cnr;
        lastCy = cyr / cnr;

        al_draw_circle(lastCx, lastCy, 100, al_map_rgb(255, 0, 0), 1);

        insere(f, lastCx, lastCy);
      }

      else
        insere(f, lastCx, lastCy);

      if(f->count > 10)
          retira(f);

      drawAtk(f);

      al_flip_display();
    }
  }

  /**********/

  libera(f);

  al_destroy_bitmap(silhueta);

  al_destroy_bitmap(esquerda);

  camera_libera_matriz(cam, matriz);
  liberaHsvMatriz(background, cam->largura, cam->altura);

  /**********/

  al_stop_timer(timer);

  al_unregister_event_source(queue, al_get_display_event_source(display));
  al_unregister_event_source(queue, al_get_timer_event_source(timer));

  al_destroy_event_queue(queue);
  al_destroy_display(display);
  al_destroy_timer(timer);

  al_shutdown_primitives_addon();
  al_shutdown_image_addon();
  al_uninstall_system();

  camera_finaliza(cam);

  return EXIT_SUCCESS;
}
Beispiel #20
0
static void draw_the_controls(bool draw_controls, ALLEGRO_COLOR tint)
{
#if defined ALLEGRO_IPHONE || defined ALLEGRO_ANDROID
	if (use_dpad && dpad_buttons && draw_controls && global_draw_controls) {
		if ((dpad_type == DPAD_TOTAL_2 || dpad_type == DPAD_HYBRID_2)) {
			ALLEGRO_COLOR light = al_map_rgba(100*tint.r, 200*tint.g, 100*tint.b, 255*tint.a);
			ALLEGRO_COLOR dark = al_map_rgba(150*tint.r, 250*tint.g, 150*tint.b, 255*tint.a);
			int x = BUTTON_SIZE+10;
			int y = dpad_at_top ? 5 : BH-5-BUTTON_SIZE;

			if (!config.getSwapButtons()) {
				al_draw_circle(BW-20-BUTTON_SIZE/2, y+BUTTON_SIZE/2, 
					BUTTON_SIZE/2, light, 2);
				al_draw_circle(BW-20-BUTTON_SIZE/2, y+BUTTON_SIZE/2, 
					BUTTON_SIZE/2+1, dark, 1);

				al_draw_filled_circle(BW-25-BUTTON_SIZE*1.5, y+BUTTON_SIZE/2, BUTTON_SIZE/2, light);
				al_draw_circle(BW-25-BUTTON_SIZE*1.5, y+BUTTON_SIZE/2, BUTTON_SIZE/2, dark, 1);
			}
			else {
				al_draw_circle(BW-25-BUTTON_SIZE*1.5, y+BUTTON_SIZE/2, 
					BUTTON_SIZE/2, light, 2);
				al_draw_circle(BW-25-BUTTON_SIZE*1.5, y+BUTTON_SIZE/2, 
					BUTTON_SIZE/2+1, dark, 1);

				al_draw_filled_circle(BW-20-BUTTON_SIZE/2, y+BUTTON_SIZE/2, BUTTON_SIZE/2, light);
				al_draw_circle(BW-20-BUTTON_SIZE/2, y+BUTTON_SIZE/2, BUTTON_SIZE/2, dark, 1);
			}

			y = dpad_at_top ? 5 : BH-BUTTON_SIZE*3-5;

			int l = BUTTON_SIZE*1.5-10;

			al_draw_rounded_rectangle(10, y, 10+BUTTON_SIZE*3, y+BUTTON_SIZE*3, 5, 5, light, 2);
			al_draw_rounded_rectangle(9, y-1, 10+BUTTON_SIZE*3+1, y+BUTTON_SIZE*3+1, 5, 5, dark, 1);
			m_draw_line(17, y+7, 17+l, y+7+l, dark);
			m_draw_line(10+BUTTON_SIZE*3-8, y+7, 10+BUTTON_SIZE*3-8-l, y+7+l, dark);
			m_draw_line(17, y+BUTTON_SIZE*3-7, 17+l, y+BUTTON_SIZE*3-7-l, dark);
			m_draw_line(10+BUTTON_SIZE*3-7, y+BUTTON_SIZE*3-7, 10+BUTTON_SIZE*3-7-l, y+BUTTON_SIZE*3-7-l, dark);

			al_draw_filled_triangle(x+4, y+BUTTON_SIZE-4, x+BUTTON_SIZE/2, y+4, x+BUTTON_SIZE-4, y+BUTTON_SIZE-4, light/*, 1*/);
			al_draw_triangle(x+4, y+BUTTON_SIZE-4, x+BUTTON_SIZE/2, y+4, x+BUTTON_SIZE-4, y+BUTTON_SIZE-4, dark, 1);
			
			x = 10;
			y += BUTTON_SIZE;
		
			al_draw_filled_triangle(x+4, y+BUTTON_SIZE/2, x+BUTTON_SIZE-4, y+4, x+BUTTON_SIZE-4, y+BUTTON_SIZE-4, light/*, 1*/);
			al_draw_triangle(x+4, y+BUTTON_SIZE/2, x+BUTTON_SIZE-4, y+4, x+BUTTON_SIZE-4, y+BUTTON_SIZE-4, dark, 1);

			x = 10+BUTTON_SIZE*2;
			
			al_draw_filled_triangle(x+BUTTON_SIZE-4, y+BUTTON_SIZE/2, x+4, y+BUTTON_SIZE-4, x+4, y+4, light/*, 1*/);
			al_draw_triangle(x+BUTTON_SIZE-4, y+BUTTON_SIZE/2, x+4, y+BUTTON_SIZE-4, x+4, y+4, dark, 1);

			x = 10+BUTTON_SIZE;
			y += BUTTON_SIZE;
		
			al_draw_filled_triangle(x+4, y+4,
				x+BUTTON_SIZE/2, y+BUTTON_SIZE-4,
				x+BUTTON_SIZE-4, y+4, light/*, 1*/);
			al_draw_triangle(x+4, y+4,
				x+BUTTON_SIZE/2, y+BUTTON_SIZE-4,
				x+BUTTON_SIZE-4, y+4, dark, 1);
		}
		else {
			ALLEGRO_VERTEX verts[36];

			InputDescriptor ie = getInput()->getDescriptor();

			int x = BUTTON_SIZE+10;
			int y = dpad_at_top ? 5 : BH-5-BUTTON_SIZE;
			const int s = 20; // bitmap size
			const int o = (BUTTON_SIZE-s)/2; // offset to draw

			int nv = 0;
			int vx, vy;
			int vu, vv;

			#define SETXY \
				verts[nv].x = vx; \
				verts[nv].y = vy; \
				verts[nv].z = 0; \
				verts[nv+1].x = vx+20; \
				verts[nv+1].y = vy; \
				verts[nv+1].z = 0; \
				verts[nv+2].x = vx; \
				verts[nv+2].y = vy+20; \
				verts[nv+2].z = 0; \
				verts[nv+3].x = vx+20; \
				verts[nv+3].y = vy; \
				verts[nv+3].z = 0; \
				verts[nv+4].x = vx+20; \
				verts[nv+4].y = vy+20; \
				verts[nv+4].z = 0; \
				verts[nv+5].x = vx; \
				verts[nv+5].y = vy+20; \
				verts[nv+5].z = 0;

			#define SETUV \
				verts[nv].u = vu; \
				verts[nv].v = vv; \
				verts[nv+1].u = vu+20; \
				verts[nv+1].v = vv; \
				verts[nv+2].u = vu; \
				verts[nv+2].v = vv+20; \
				verts[nv+3].u = vu+20; \
				verts[nv+3].v = vv; \
				verts[nv+4].u = vu+20; \
				verts[nv+4].v = vv+20; \
				verts[nv+5].u = vu; \
				verts[nv+5].v = vv+20; \
				nv += 6;

			if (config.getSwapButtons()) {
				vx = BW-20-BUTTON_SIZE+o;
				vy = y+o;
			}
			else {
				vx = BW-25-BUTTON_SIZE*2;
				vy = y+o;
			}

			SETXY

			if (ie.button1) {
				vu = 20;
				vv = 40;

				SETUV
			}
			else {
				vu = 0;
				vv = 40;

				SETUV
			}

			if (config.getSwapButtons()) {
				vx = BW-25-BUTTON_SIZE*2;
				vy = y+o;
			}
			else {
				vx = BW-20-BUTTON_SIZE+o;
				vy = y+o;
			}

			SETXY

			if (ie.button2) {
				vu = 60;
				vv = 40;

				SETUV
			}
 void Circle::draw_in_another_target()
 {
     if(get_filled_status())
         al_draw_filled_circle(_V_pos_x,_V_pos_y,_V_radius,_V_color);
     al_draw_circle(_V_pos_x,_V_pos_y,_V_radius,_V_color,_V_thickness);
 }
Beispiel #22
0
void TEnterprise::DrawPlanetInfo(const Sector & a_sector,int a_nX, int a_nY)
{
    size_t n = a_sector.m_Planet.size();

    a_nX -= 22;

    if (a_sector.m_blHasAsteroidField)
    {
        al_draw_circle(a_nX, a_nY,15, m_pEngine->m_clYELLOW,2);
    }

    if (n>0)
    {
       // plot starbases
       ALLEGRO_COLOR col;
       int nSize =10;
       int nShift =0;

       for ( size_t i=0; i<n; i++)
       {
            switch(a_sector.m_Planet[i].m_PlanetType)
            {

                case ID_STAR_BLUE:
                    col =  m_pEngine->m_clBLUE;
                    nSize = 7;
                    nShift= 11;
                break;

                case ID_STAR_WHITE:
                    col =  m_pEngine->m_clWHITE;
                    nSize =6;
                    nShift= 10;
                break;

                case ID_STAR_YELLOW:
                    col =  m_pEngine->m_clYELLOW;
                    nSize =8;
                    nShift= 12;
                break;

                case ID_STAR_RED:
                    col =  m_pEngine->m_clRED;
                    nSize =10;
                    nShift= 14;
                break;


                case ID_CLASS_A:
                     col = m_pEngine->m_clRED;
                     nSize = 2;
                     nShift= 5;
                break;

                case ID_CLASS_B:
                     col = m_pEngine->m_clMAGENTA;
                     nSize = 3;
                     nShift= 7;
                break;

                case ID_CLASS_L:
                    col = m_pEngine->m_clBROWN;
                     nSize = 2;
                     nShift= 5;
                break;

                case ID_CLASS_N:
                     col = m_pEngine->m_clYELLOW;
                     nSize = 4;
                     nShift= 9;
                break;

                case ID_CLASS_M1:
                    col = m_pEngine->m_clAQUA;
                    nSize = 2;
                    nShift= 5;
                break;

                case ID_CLASS_M2:
                    col = m_pEngine->m_clAQUA;
                    nSize = 3;
                    nShift= 7;
                break;

                case ID_CLASS_M3:
                    col = m_pEngine->m_clAQUA;
                    nSize = 4;
                    nShift= 9;
                break;

                default:
                     col = m_pEngine->m_clBLACK;
                     nSize = 10;
                     nShift= 14;
                break;

           }

           al_draw_filled_circle(a_nX, a_nY,nSize,col);
           a_nX += nShift;

        }
    }


}
void DrawingClass::DrawCircle (float cx, float cy, float radius, int r, int g,
    int b, int thick) {
  ALLEGRO_COLOR color = al_map_rgb(r, g, b);
  al_draw_circle(cx, cy, radius, color, thick);
}
Beispiel #24
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;
}
Beispiel #25
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 #26
0
int main(int argc, char **argv)
{
	
	ALLEGRO_KEYBOARD_STATE estadoTeclado;
	
	bool figuras = al_init_primitives_addon();
	bool inicio_allegro = al_init();
	bool teclado = al_install_keyboard();
	bool imagenes = al_init_image_addon();
	
	
	if(!figuras)
	{
		fprintf(stderr, "Error: No pudo cargar figuras.\n");
		return -1;
	}
	if(!imagenes)
	{
		fprintf(stderr, "Error: No pudo cargar imagenes.\n");
		return -1;
	}
	if(!inicio_allegro) 
	{
		fprintf(stderr, "Error: Allegro no pudo iniciar.\n");
		return -1;
	}
	
	if(!teclado) 
	{
		fprintf(stderr, "Error: El teclado no se detecto.\n");
		return -1;
	}
	
	ALLEGRO_BITMAP *perro[4];
	perro[0] = al_load_bitmap("0.png");
	perro[1] = al_load_bitmap("1.png");
	perro[2] = al_load_bitmap("2.png");
	perro[3] = al_load_bitmap("3.png");
	
	ALLEGRO_BITMAP *arbol[3];
	arbol[0] = al_load_bitmap("arbol1.png");
	arbol[1] = al_load_bitmap("arbol2.png");
	arbol[2] = al_load_bitmap("arbol3.png");
	
	ALLEGRO_BITMAP *cerca;
	cerca = al_load_bitmap("Cerca.png");
	
	ALLEGRO_BITMAP *Perder;
	Perder = al_load_bitmap("Perder.png");
	
	const int Mx = 600;
	const int My = 600;
	al_create_display(Mx,My);
	int cielo=0;
	int DegradCielo=0;
	int DegradSol=0;
	int Tierra=0;
	
	int perroX = 0;
	int perroY = 500;
	int perroE = 0;
	int tiempoE = 0;
	bool salta=false;
	bool arriba=false;
	bool perder=false;
	
	int arbolX1=Mx;
	int arbolX2=Mx+rand() % 600;
	int arbolX3=Mx+rand() % 600;
	int ArbolE1=rand() % 3;
	int ArbolE2=rand() % 3;
	int ArbolE3=rand() % 3;
	
	int cercaX=Mx;
	int cercaY=520;
	int nivel=1;
	while(true)
	{
		cielo=0;
		DegradCielo=0;
		DegradSol=0;
		Tierra=0;
		
		al_get_keyboard_state(&estadoTeclado);
		if (al_key_down(&estadoTeclado, ALLEGRO_KEY_ESCAPE)) 
		{
			break;
		}
		
		while(DegradCielo<155)
		{
			al_draw_line(0,cielo,Mx,cielo,al_map_rgb(50+(cielo/3),50+(cielo/3),100+DegradCielo),3);
			DegradCielo++;
			cielo+=3;
		}
		
		
		while(DegradSol<75)
		{
			al_draw_circle(Mx/2, 400, DegradSol*2, al_map_rgb(255-DegradSol,255-DegradSol,DegradSol*-2.5),3);
			DegradSol++;
		}
		
		while(Tierra<155)
		{
			al_draw_line(0,445+Tierra,Mx,445+Tierra,al_map_rgb(70,100+Tierra,100),1);
			Tierra++;
		}
		if(perder==false)
		{
			if(salta==false)
			{
				tiempoE++;
				if(tiempoE==15)
				{
					perroE++;
					if(perroE>2)
					{
						perroE=1;
					}
					tiempoE=0;
				}
				
				if(al_key_down(&estadoTeclado,ALLEGRO_KEY_RIGHT) && perroX<Mx-100 )
				{
					//al_clear_to_color(al_map_rgb(0,0,0));
					perroX++;
				}
				if(al_key_down(&estadoTeclado,ALLEGRO_KEY_LEFT) && perroX>0)
				{
					//al_clear_to_color(al_map_rgb(0,0,0));
					perroX--;
				}
				if(al_key_down(&estadoTeclado,ALLEGRO_KEY_SPACE))
				{
					//al_clear_to_color(al_map_rgb(0,0,0));
					perroE=3;
					arriba=true;
					salta=true;
				}
			}
			else
			{
				if(arriba==true)
				{
					perroY-=1;
					if(perroY<=420)
					{
						arriba=false;
					}
				}
				else
				{
					perroY+=1;
					if(perroY==500)
					{
						salta=false;
						perroE=0;
					}
				}
			}
			
			al_draw_bitmap(arbol[ArbolE1],arbolX1,400,0);
			arbolX1-=nivel;
			if(arbolX1<=-60)
			{
				arbolX1=Mx;
				ArbolE1=rand() % 3;
			}
			
			al_draw_bitmap(arbol[ArbolE2],arbolX2,400,0);
			arbolX2-=nivel;
			if(arbolX2<=-60)
			{
				arbolX2=Mx+rand() % 500;
				ArbolE2=rand() % 3;
			}

			al_draw_bitmap(arbol[ArbolE3],arbolX3,400,0);
			arbolX3-=nivel;
			if(arbolX3<=-60)
			{
				arbolX3=Mx+rand() % 500;
				ArbolE3=rand() % 3;
			}
			
			al_draw_bitmap(cerca,cercaX,cercaY,0);
			cercaX-=nivel;
			if(cercaX<=-60)
			{
				cercaX=Mx;
				nivel+=1;
			}
			
			al_draw_bitmap(perro[perroE],perroX,perroY,0);
			
	//		if( (perroX)>cercaX && (perroX+100)<cercaX && cercaY-20==perroY)
	//		{
	//			printf("Pierdes");
	//		}
			
			if( ((perroX+30)<cercaX && (perroX+60)>cercaX) && perroY+20<=cercaY && perroY+30>=cercaY )
			{
				perder=true;
			}
		}
		else
		{
			al_draw_bitmap(Perder,(Mx/2)-150,My/2,0);
			if(al_key_down(&estadoTeclado,ALLEGRO_KEY_ENTER) )
			{
				perroX = 0;
				perroY = 500;
				perroE = 0;
				tiempoE = 0;
				salta=false;
				arriba=false;
				cercaX=Mx;
				cercaY=520;
				nivel=1;
				perder=false;
			}
		}
		//printf("Perro: x=%d y=%d\nCerca: x=%d y=%d\n",perroX,perroY,cercaX,cercaY);
		al_flip_display();
		al_rest(0.001);
	}
	al_destroy_display(ventana);
	return 0;
} 
Beispiel #27
0
int main(int argc, char *argv[])
{
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *evqueue = NULL;
	ALLEGRO_TIMER *timer = NULL;
	ALLEGRO_KEYBOARD_STATE keyboard_state;
    ALLEGRO_EVENT event;
    ALLEGRO_FONT *font;
    ALLEGRO_BITMAP *clock_hand, *clock_quadrant, *bow, *sword;
    float clock_ray = 0, clock_angle = 0;
    int clock_ray_alpha;
    float soul_interval = SOUL_TIME_INTERVAL;
    FuzzyPlayer *player, *cpu;
    FuzzyGame * game;

	bool running = true;
	bool redraw = true;

	int map_x = 13*16, map_y = 5*16;
	int screen_width = WINDOW_WIDTH;
	int screen_height = WINDOW_HEIGHT;
    double curtime;

	/* Initialization */
    fuzzy_iz_error(al_init(), "Failed to initialize allegro");
    fuzzy_load_addon("image", al_init_image_addon());
    fuzzy_load_addon("primitives", al_init_primitives_addon());
    fuzzy_load_addon("keyboard", al_install_keyboard());
    fuzzy_load_addon("mouse", al_install_mouse());
    al_init_font_addon();

	fuzzy_iz_error(timer = al_create_timer(1.0 / FPS), "Cannot create FPS timer");
    fuzzy_iz_error(evqueue = al_create_event_queue(), "Cannot create event queue");
	fuzzy_iz_error(display = al_create_display(screen_width, screen_height),
      "Cannot initialize display");
    al_set_window_title(display, WINDOW_TITLE);
    fuzzy_iz_error(font = al_load_font(fuzzy_res(FONT_FOLDER, "fixed_font.tga"), 0, 0), "Cannot load 'fixed_font.tga'");
    clock_hand = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "clock_hand.png"));
    fuzzy_iz_error(clock_hand, "Cannot load clock handle");
    clock_quadrant = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "clock_quadrant.png"));
    fuzzy_iz_error(clock_hand, "Cannot load clock quadrant");
    bow = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "bow.png"));
    fuzzy_iz_error(clock_hand, "Cannot load bow image");
    sword = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "sword.png"));
    fuzzy_iz_error(clock_hand, "Cannot load sword image");

	/* Queue setup */
	al_register_event_source(evqueue, al_get_display_event_source(display));
	al_register_event_source(evqueue, al_get_timer_event_source(timer));
	al_register_event_source(evqueue, al_get_keyboard_event_source());
    al_register_event_source(evqueue, al_get_mouse_event_source());

    /* Game setup */
    game = fuzzy_game_new("level000.tmx");
    player = fuzzy_player_new(game, FUZZY_PLAYER_LOCAL, "Dolly");
    cpu = fuzzy_player_new(game, FUZZY_PLAYER_CPU, "CPU_0");

    fuzzy_chess_add(game, player, FUZZY_FOO_LINK, 34, 30);
    fuzzy_chess_add(game, player, FUZZY_FOO_LINK, 33, 30);
    fuzzy_chess_add(game, cpu, FUZZY_FOO_LINK, 40, 30);
    bool showing_area = false;
    FuzzyChess *chess, *focus = NULL;

	al_clear_to_color(al_map_rgb(0, 0, 0));
    al_draw_bitmap(game->map->bitmap, -map_x, -map_y, 0);
	al_flip_display();

#if DEBUG
	ALLEGRO_BITMAP *icon;
    int fps, fps_accum;
    double fps_time;

    icon = al_load_bitmap(fuzzy_res(PICTURE_FOLDER, "icon.tga"));
    if (icon)
        al_set_display_icon(display, icon);
    fps_accum = fps_time = 0;
    fps = FPS;
#endif
    /* Server connection */
    int svsock;
    //~ FuzzyMessage * sendmsg = fuzzy_message_new();
    svsock = fuzzy_server_connect(FUZZY_DEFAULT_SERVER_ADDRESS, FUZZY_DEFAULT_SERVER_PORT);

    _aaa_menu(game, svsock);

	/* MAIN loop */
    player->soul_time = al_get_time();
    al_start_timer(timer);
	while (running) {
        /* wait until an event happens */
		al_wait_for_event(evqueue, &event);

        switch (event.type) {
        case ALLEGRO_EVENT_TIMER:
            /* check soul ticks */
            curtime = al_get_time();
            while (curtime - player->soul_time >= soul_interval) {
                //~ fuzzy_debug("Soul tick!");
                player->soul_time += soul_interval;
                player->soul_points += SOUL_POINTS_BOOST;

                clock_ray = 1;
            }
            clock_angle = (curtime - player->soul_time)/soul_interval * FUZZY_2PI;
            if (clock_ray) {
                clock_ray = (curtime - player->soul_time)/RAY_TIME_INTERVAL * 50 + 40;
                clock_ray_alpha = (curtime - player->soul_time)/RAY_TIME_INTERVAL*(55) + 200;
                if (clock_ray >= 90)
                    clock_ray = 0;
            }

            al_get_keyboard_state(&keyboard_state);
            if (al_key_down(&keyboard_state, ALLEGRO_KEY_RIGHT)) {
                map_x += 5;
                if (map_x > (game->map->tot_width - screen_width))
                    map_x = game->map->tot_width - screen_width;
            }
            else if (al_key_down(&keyboard_state, ALLEGRO_KEY_LEFT)) {
                map_x -= 5;
                if (map_x < 0)
                    map_x = 0;
            }
            else if (al_key_down(&keyboard_state, ALLEGRO_KEY_UP)) {
                map_y -= 5;
                if (map_y < 0)
                    map_y = 0;
            }
            else if (al_key_down(&keyboard_state, ALLEGRO_KEY_DOWN)) {
                map_y += 5;
                if (map_y > (game->map->tot_height - screen_height))
                    map_y = game->map->tot_height - screen_height;
            } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_O)) {
                soul_interval = fuzzy_max(0.1, soul_interval - 0.05);
            } else if (al_key_down(&keyboard_state, ALLEGRO_KEY_P)) {
                soul_interval += 0.05;
            }
            redraw = true;
            break;
        case ALLEGRO_EVENT_KEY_DOWN:
            if(! focus)
                break;

            _attack_area_off();

            switch(event.keyboard.keycode) {
                case ALLEGRO_KEY_W:
                    _chess_move(game, player, focus, focus->x, focus->y-1);
                    break;
                case ALLEGRO_KEY_A:
                    _chess_move(game, player, focus, focus->x-1, focus->y);
                    break;
                case ALLEGRO_KEY_S:
                    _chess_move(game, player, focus, focus->x, focus->y+1);
                    break;
                case ALLEGRO_KEY_D:
                    _chess_move(game, player, focus, focus->x+1, focus->y);
                    break;

                case ALLEGRO_KEY_K:
                    _attack_area_on();
                    break;
                case ALLEGRO_KEY_SPACE:
                    /* switch attack type */
                    if (! focus)
                        break;
                    if (focus->atkarea == &FuzzyMeleeMan)
                        focus->atkarea = &FuzzyRangedMan;
                    else
                        focus->atkarea = &FuzzyMeleeMan;
                    break;
            }
            break;
        case ALLEGRO_EVENT_DISPLAY_CLOSE:
            running = false;
            break;
        case ALLEGRO_EVENT_KEY_UP:
            break;
        case ALLEGRO_EVENT_KEY_CHAR:
            break;
        case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
            if(event.mouse.button == RIGHT_BUTTON) {
                _attack_area_on();
            } else if(event.mouse.button == LEFT_BUTTON) {
                /* world to tile coords */
                int tx = (event.mouse.x+map_x) / game->map->tile_width;
                int ty = (event.mouse.y+map_y) / game->map->tile_height;
#ifdef DEBUG
                printf("SELECT %d %d\n", tx, ty);
#endif
                if(showing_area && fuzzy_chess_inside_target_area(game, focus, tx, ty)) {
                    /* select attack target */
                    if (fuzzy_map_spy(game->map, FUZZY_LAYER_SPRITES, tx, ty) == FUZZY_CELL_SPRITE) {
                        if (fuzzy_chess_local_attack(game, player, focus, tx, ty))
                            _attack_area_off();
                    }
                } else {
                    /* select chess */
                    chess = fuzzy_chess_at(game, player, tx, ty);
                    if (chess && focus != chess) {
                        _attack_area_off();

                        if (focus != NULL) {
                            // already has a focus effect, just move it
                            fuzzy_sprite_move(game->map, FUZZY_LAYER_BELOW, focus->x, focus->y, tx, ty);
                        } else {
                            fuzzy_sprite_create(game->map, FUZZY_LAYER_BELOW, GID_TARGET, tx, ty);
                        }
                        focus = chess;
                    } else if (! chess) {
                        if (showing_area) {
                            // just hide the attack area
                            _attack_area_off();
                        } else if(focus) {
                            // remove the focus
                            fuzzy_sprite_destroy(game->map, FUZZY_LAYER_BELOW, focus->x, focus->y);
                            focus = NULL;
                        }
                    }
                }
            }
            break;
        default:
#ifdef DEBUG
            //~ fprintf(stderr, "Unknown event received: %d\n", event.type);
#endif
            break;
        }

        if (redraw && al_is_event_queue_empty(evqueue)) {
            curtime = al_get_time();
            fuzzy_map_update(game->map, curtime);

            // Clear the screen
            al_clear_to_color(al_map_rgb(0, 0, 0));
            al_draw_bitmap(game->map->bitmap, -map_x, -map_y, 0);

#ifdef GRID_ON
            /* Draw the grid */
            int tw = game->map->tile_width;
            int ty = game->map->tile_height;
            int x, y;
            for (x=(tw-map_x)%tw; x<screen_width; x+=tw)
                al_draw_line(x, 0, x, screen_height, al_map_rgba(7,7,7,100), 1);
            for (y=(ty-map_y)%ty; y<screen_height; y+=ty)
                al_draw_line(0, y, screen_width, y, al_map_rgba(7,7,7,100), 1);
#endif
#if DEBUG
            al_draw_filled_rounded_rectangle(screen_width-100, 4, screen_width, 30,
                8, 8, al_map_rgba(0, 0, 0, 200));
            al_draw_textf(font, al_map_rgb(255, 255, 255),
                screen_width-50, 8, ALLEGRO_ALIGN_CENTRE, "FPS: %d", fps);
#endif
            /* draw SP count */
            al_draw_filled_rounded_rectangle(4, screen_height-170, 175, screen_height-4,
                8, 8, al_map_rgba(0, 0, 0, 200));
            al_draw_textf(font, al_map_rgb(255, 255, 255),
                15, screen_height-163, ALLEGRO_ALIGN_LEFT, "SP: %d", player->soul_points);

            /* draw Soul Clock */
            al_draw_scaled_bitmap(clock_quadrant, 0, 0, 301, 301, 20, screen_height-80-139/2, 139, 139, 0);
            al_draw_scaled_rotated_bitmap(clock_hand, 160, 607, 90, screen_height-80, 0.11, 0.11, clock_angle, 0);
            al_draw_circle(90, screen_height-80, clock_ray, al_map_rgb(80, clock_ray_alpha, 80), 2.0);

            /* draw weapon */
            if (focus) {
                ALLEGRO_BITMAP * weapon;

                if (focus->atkarea == &FuzzyMeleeMan)
                    weapon = sword;
                else
                    weapon = bow;
                al_draw_scaled_bitmap(weapon, 0, 0, 90, 90, 20, 20, 60, 60, 0);
            }

            al_flip_display();
#if DEBUG
            fps_accum++;
            if (curtime - fps_time >= 1) {
                fps = fps_accum;
                fps_accum = 0;
                fps_time = curtime;
            }
#endif
            redraw = false;
        }
    }

	/* Cleanup */
    //~ void * retval;
    //~ char srvkey[FUZZY_SERVERKEY_LEN];
    //~ fuzzy_protocol_server_shutdown(svsock, sendmsg, srvkey);
    //~ fuzzy_message_del(sendmsg);
    fuzzy_game_free(game);

    al_destroy_event_queue(evqueue);
	al_destroy_display(display);
    al_destroy_timer(timer);
	return 0;
}
Beispiel #28
0
void StateControl::start_radio ()
{
	Initialize();

	states.push_back(new LoginState());
	states.push_back(new SignUpState());
	states.push_back(new AdminAccState());
	states.push_back(new RegularAccState());
	states.push_back(new ManageMusicsState());
	states.push_back(new AddMusicState());
	states.push_back(new EditMusicState());
	states.push_back(new TopTenState());
	states.push_back(new MyPlaylistState());
	states.push_back(new SearchState());
	states.push_back(new CompetitionState());
	state = -1;
	ChangeState(Login);

	cout << "Starting control cycle..." << endl;
	done = false;
	draw = true;
	while (!done)
	{
		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, & ev);

		/* --- controlling left mouse button double press --- */
		if (possible_double_press && double_press_counter < 15)
		{ double_press_counter++; }
		else if (possible_double_press)
		{ possible_double_press = false; double_press_counter = 0; }
		
		/* --- advancing through music --- */
		if (ev.timer.source == timer && playing_music && music_time_counter < 130)
		{ music_time_counter++; }
		else if (ev.timer.source == timer && playing_music)
		{ playing_music = false; music_time_counter = 0; }
		
		/* --- tracking mouse --- */
		if (ev.type == ALLEGRO_EVENT_MOUSE_AXES)
		{
			mouse_x = ev.mouse.x;
			mouse_y = ev.mouse.y;

			draw = true;
		}
		if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
		{
			if (ev.mouse.button & 1)
			{
				left_mouse_button_pressed = true;
				left_mouse_button_released = false;
				draw = true;
			}
			if (ev.mouse.button & 2)
			{
				right_mouse_button_pressed = true;
				right_mouse_button_released = false;
				draw = true;
			}
		}
		if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
		{
			if (ev.mouse.button & 1)
			{
				if (possible_double_press)
				{ cout << "* Left mouse button pressed twice *" << endl; left_mouse_button_pressed_twice = true; }
				else { cout << "* Left mouse button pressed *" << endl; }

				possible_double_press = true;
				left_mouse_button_pressed = false;
				left_mouse_button_released = true;
				draw = true;
			}
			if (ev.mouse.button & 2)
			{
				cout << "* Right mouse button pressed *" << endl;
				right_mouse_button_pressed = false;
				right_mouse_button_released = true;
				draw = true;
			}
		}

		/* --- UPDATING --- */
		if (states[state]->Update(& ev) || ev.type == ALLEGRO_EVENT_TIMER || draw)
		{
			StateControl::GetInstance()->left_mouse_button_released = false;
			StateControl::GetInstance()->left_mouse_button_pressed_twice = false;
			StateControl::GetInstance()->right_mouse_button_released = false;
			draw = true;
		}

		/* --- now drawing --- */
		if (draw && al_event_queue_is_empty(event_queue))
		{
			states[state]->Draw();

			/* player active UI */
			if (state != Login && state != SignUp && state != AddMusic &&
				state != EditMusic && state != ManageMusics && state != Competition)
			{
				al_draw_text(musics_font, DarkGray, 10, player_interface_y_coord, NULL, "Playing:");
				al_draw_line(10, 420, 140, 420, DarkGray, 2.0);
				switch (playing_music)
				{
				case 0:
					{
						al_draw_text(tiny_font, DarkGray, 10, player_interface_y_coord + 20, NULL, "<Double-click a music>");
						al_draw_circle(10, player_interface_y_coord + 40, 5, LightGray, 1.0);
						al_draw_filled_circle(10, player_interface_y_coord + 40, 4, White);
						break;
					}
				case 1: 
					{
						al_draw_text(tiny_font, DarkGray, 10, player_interface_y_coord + 20, NULL, music_playing_title.c_str());
						al_draw_circle(10 + music_time_counter, player_interface_y_coord + 40, 5, LightGray, 1.0);
						al_draw_filled_circle(10 + music_time_counter, player_interface_y_coord + 40, 4, White);
						break;
					}
				}
			}
			
			/*
			// mouse temp coords
			stringstream ss;
			ss << mouse_x << " " << mouse_y;
			al_draw_text(forms_font, Yellow, 0, 0, NULL, ss.str().c_str());
			// -----------------
			*/

			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));
			draw = false;
		}

		/* if window is closed */
		if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			cout << "Close button pressed..." << endl;
			done = true;
		}
	}

	Terminate();
}
Beispiel #29
0
int main(){

	int SCREEN_W = 400;
	int SCREEN_H = 400;
	ALLEGRO_DISPLAY *display = NULL;

	if(!al_init()) {
      	fprintf(stderr, "failed to initialize allegro!\n");
      	return 0;
   	}
	
 	display = al_create_display(SCREEN_W, SCREEN_H);
	if(!display) {
		fprintf(stderr, "failed to create display!\n");
		return 0;
	}
	if(!al_install_keyboard()) {
	fprintf(stderr, "failed to initialize the keyboard!\n");
	return 0;
	}

	ALLEGRO_COLOR  negro = al_map_rgb(0,0,0);
	ALLEGRO_COLOR  rojo = al_map_rgb(255,0,0);
	ALLEGRO_COLOR  azul = al_map_rgb(0,0,255);
   	
   	al_clear_to_color(negro);
	al_flip_display();

	int i,j,n,nl;
	scanf("%d",&n);//cantidad de puntos.
	nl = n*(n-1)/2;//cantidad de lineas.
	_linea * l =  (_linea *)malloc(sizeof(_linea)*nl);
	int puntos[n][2];//matriz para almacenar los puntos.
	for(i=0;i<n;i++){
		scanf("%d",&puntos[i][0]);
		scanf("%d",&puntos[i][1]);
		al_draw_circle(puntos[i][0],SCREEN_H - puntos[i][1], 1, rojo,2);//dibujo de los puntos en la pantalla.
		al_flip_display();
    }

    ALLEGRO_EVENT_QUEUE *queue = NULL;
	queue = al_create_event_queue();
	if(!queue) {
	return 0;
	}
	ALLEGRO_EVENT event;
	al_register_event_source(queue, al_get_keyboard_event_source());
	do{
	al_wait_for_event(queue, &event);
	}
	while (event.type != ALLEGRO_EVENT_KEY_DOWN); //espera para que el usuario aprete una tecla para que el programa siga.

    int a=0;
    for(i=0;i<n;i++){ //creación de todas las lineas.
		for(j=i+1;j<n;j++){
				l[a].x0=puntos[i][0];
				l[a].y0=puntos[i][1];
				l[a].x1=puntos[j][0];
				l[a].y1=puntos[j][1];
				a++;
		}
	}
	quicksort(l,0,nl-1); // ordenamiento de las lineas para que queden primero las con menor longitud.


	_linea *sol = (_linea *)malloc(sizeof(_linea)*nl); // conjunto de líneas que forman la solución.

	int sol_size = 0;
	for (i=0;i<nl;i++){ //comprobar si cada linea existente se intersecta con las lineas que pertenecen a la solución
		int flag=1;
		for(j=0;j<sol_size;j++){
			if(inter(l[i],sol[j])==1){ 
				flag=0;
				j=sol_size;
			}
		}
		if(flag==1){ // si no se intersecta con ninguna linea que sea parte de la solución se guarda como parte de la solución
				sol[sol_size]=l[i];
				al_draw_line(sol[sol_size].x0,SCREEN_H-sol[sol_size].y0, sol[sol_size].x1,SCREEN_H-sol[sol_size].y1, azul, 1);
				al_flip_display();
				sol_size++;
			}
	}

	al_rest(3);
	al_destroy_display(display);
	return 0;
}
Beispiel #30
0
void Map::redrawRegions()
{
    if(playerTurn == NULL)
        return;

    int screenW = Base::instance()->getEngine()->getWindowSize().x;
    int screenH = Base::instance()->getEngine()->getWindowSize().y;

    int worldx = Base::instance()->getCoords()->first;
    int worldy = Base::instance()->getCoords()->second;

    al_clear_to_color(al_map_rgb(0, 0, 255));
    al_draw_bitmap_region(mapaPtr,-worldx,-worldy,screenW, screenH,0,0,0);

    std::list<Region>::iterator it0;
    for(it0=regions.begin(); it0!=regions.end(); it0++)
    {
        std::vector<Region*>::iterator it2;
        for(it2=it0->regionsConnected.begin(); it2!=it0->regionsConnected.end(); it2++)
        {
            ALLEGRO_COLOR color = al_map_rgb(0,0,0);
            Region *region2 = *it2;

            if(selectedRegion!=NULL)
            {

                if(movType==MOVE &&
                ((it0->regionname==selectedRegion->regionname ||
                    region2->regionname==selectedRegion->regionname) && //BREAKS SOMETIMES
                    (it0->owner->name == region2->owner->name)) &&
                    (it0->owner->name == playerTurn->realm->name))
                        color = al_map_rgb(0,255,0);
                else if(movType==ATTACK&&
                    ((it0->regionname==selectedRegion->regionname ||
                    region2->regionname==selectedRegion->regionname) &&
                    (it0->owner->name != region2->owner->name)) &&
                    (it0->owner->name != playerTurn->realm->name))
                        color = al_map_rgb(255,0,0);
            }

            al_draw_line(it0->x+worldx+5, it0->y+worldy+5,(*it2)->x+worldx+5, (*it2)->y+worldy+5,color,2);
        }
    }


    std::list<Region>::iterator it;
    for(it=regions.begin(); it!=regions.end(); it++)
    {
        std::list<DiplomaticState>::iterator stateIt;
        for(stateIt=playerTurn->realm->diplomacy.begin(); stateIt!=playerTurn->realm->diplomacy.end(); stateIt++)
        {
            if(playerTurn->realm->name == it->owner->name)
            {
                al_draw_rectangle(it->x+worldx-1, it->y+worldy-1,
                                  it->x+it->w+worldx+1, it->y+it->h+worldy+1, al_map_rgb(255, 255, 0), 3);
                break;
            }

            else if(stateIt->realm->name == it->owner->name)
            {
                if(stateIt->state == WAR)
                    al_draw_rectangle(it->x+worldx-1, it->y+worldy-1,
                                      it->x+it->w+worldx+1, it->y+it->h+worldy+1, al_map_rgb(255, 0, 0), 3);
                else if(stateIt->state == ALLIANCE)
                    al_draw_rectangle(it->x+worldx-1, it->y+worldy-1,
                                      it->x+it->w+worldx+1, it->y+it->h+worldy+1, al_map_rgb(0, 255, 0), 3);
                else if(stateIt->state == TRADE_AGREEMENT)
                    al_draw_rectangle(it->x+worldx-1, it->y+worldy-1,
                                      it->x+it->w+worldx+1, it->y+it->h+worldy+1, al_map_rgb(0, 0, 255), 3);
                else
                    al_draw_rectangle(it->x+worldx-1, it->y+worldy-1,
                                      it->x+it->w+worldx+1, it->y+it->h+worldy+1, al_map_rgb(255, 255, 255), 3);
            }
        }

        al_draw_filled_rectangle(it->x+worldx, it->y+worldy, it->x+it->w+worldx, it->y+it->h+worldy, it->owner->color);
        al_draw_rectangle(it->x+worldx, it->y+worldy, it->x+it->w+worldx, it->y+it->h+worldy, al_map_rgb(0, 0, 0), 2);

        if(&*it==selectedRegion)
        {
            al_draw_circle(it->x+worldx+5, it->y+worldy+5, 10, al_map_rgb(0,0,0), 4);
        }
    }
}