Example #1
0
void DescriptionBox::Draw(std::string title, std::string description){
	ALLEGRO_COLOR color = al_color_name("white");
	if (title == "Game Over") {
		color = al_color_name("red");
	}
    al_draw_rounded_rectangle(10, ScreenHeight - 190, ScreenWidth - 10, ScreenHeight - 10, 7, 7, al_color_name("white"), 5);
    //std::cout << title << " " << description << std::endl;
    al_draw_text(font, color, 20, ScreenHeight - 190, ALLEGRO_ALIGN_LEFT, title.c_str());
    al_draw_text(font, al_color_name("white"), 20, ScreenHeight - 160, ALLEGRO_ALIGN_LEFT, description.c_str());
}
Example #2
0
static void init(void)
{
   ex.FPS = 60;

   ex.font = al_load_font("data/fixed_font.tga", 0, 0);
   if (!ex.font) {
      abort_example("data/fixed_font.tga not found\n");
   }
   ex.background = al_color_name("beige");
   ex.text = al_color_name("black");
   ex.white = al_color_name("white");
   ex.pattern = example_bitmap(100, 100);
}
 static Profiler *get_instance()
 {
    if (!instance)
    {
       instance = new Profiler;
       bg_color = al_color_name("black");
       bar_color = al_color_name("orange");
       font_color = al_color_name("white");
       limit_bar_color = al_color_name("lightblue");
       font = al_create_builtin_font();
    }
    return instance;
 }
Example #4
0
void Brick::UpdateColor() {
	switch(Strength) {
	default:
	case 0:
		Color = al_color_name("darkgray");
		break;
	case 1:
		Color = al_color_name("red");
		break;
	case 2:
		Color = al_color_name("orange");
		break;
	case 3:
		Color = al_color_name("yellow");
		break;
	case 4:
		Color = al_color_name("green");
		break;
	case 5:
		Color = al_color_name("blue");
		break;
	case 6:
		Color = al_color_name("indigo");
		break;
	case 7:
		Color = al_color_name("violet");
		break;
	}
}
Example #5
0
static void init(void)
{
   ex.FPS = 60;

   ex.font = al_load_font("data/fixed_font.tga", 0, 0);
   if (!ex.font) {
      abort_example("data/fixed_font.tga not found.\n");
   }
   ex.background = al_color_name("beige");
   ex.foreground = al_color_name("black");
   ex.outline = al_color_name("red");
   ex.text = al_color_name("blue");
   ex.white = al_color_name("white");
   ex.pattern = al_create_bitmap(32, 32);
   ex.zoom = al_create_bitmap(32, 32);
   draw_pattern(ex.pattern);
}
Example #6
0
void Pause_Menu::draw()
{
  m_rectangle->draw();
  ALLEGRO_COLOR color;
  float x = m_screen_width / 2;
  float y = m_rectangle->get_y() + (m_rectangle->get_height()/4);
  al_draw_text(m_font, al_color_name("black"), x, y, ALLEGRO_ALIGN_CENTER, "Quit?");
  std::string items[2] = { "No", "Yes" };
  y = m_rectangle->get_y() + (m_rectangle->get_height()/2);
  for (int i = 0; i < 2; i++)
  {
    if (m_selection == i)
      color = al_color_name("lawngreen");
    else
      color = al_color_name("black");
    if (i == 0)
      x = m_rectangle->get_x() + (m_rectangle->get_width()/4);
    else
      x = m_rectangle->get_x() + ((m_rectangle->get_width()/4)*3);
    al_draw_text(m_font, color, x, y, ALLEGRO_ALIGN_CENTER, items[i].c_str());
  }
}
Example #7
0
void Pellet::remove()
{
  assert(m_respawn_time == 0);
  m_exists = false;
  m_respawn_time = m_respawn_time_max;
  if (m_collision_table->check_collision(m_rectangle->get_x(), m_rectangle->get_y()) == Collision_Table::PELLET)
  {
    m_collision_table->remove(m_rectangle->get_x(), m_rectangle->get_y());
    ALLEGRO_COLOR tmp_color = m_rectangle->get_color();
    m_rectangle->set_color(al_color_name("black"));
    m_rectangle->draw();
    m_rectangle->set_color(tmp_color);
  }
  m_spawn_countdown = rand() % m_spawn_countdown_max;
}
Example #8
0
Pellet::Pellet(float width, float max_x, float max_y, float volume, int spawn_countdown_max, Scoreboard *scoreboard, Collision_Table *collision_table, bool tron)
{
  assert(collision_table);
  m_scoreboard = scoreboard;
  m_width = width;
  m_max_x = max_x;
  m_max_y = max_y;
  m_volume = volume * 0.1;
  m_tron = tron;
  m_value = 0;
  m_spawn_countdown_max = spawn_countdown_max + 1;
  m_respawn_time_max = 500;
  m_respawn_time = m_respawn_time_max;
  m_spawn_countdown = rand() % (m_spawn_countdown_max / 2);
  m_collision_table = collision_table;
  m_exists = false;
  m_rectangle = new Rectangle(0, 0, m_width, m_width, true, al_color_name("white"));
  m_eat_sound = al_load_sample("./sounds/eat.wav");
}
Example #9
0
void	graphics::draw_at	(const entity_c &obj, var zoom, var x, var y) {

	if (!display) {
		return;
	}

	if (obj.type == ENTITY) {
		al_draw_filled_circle (x, y, obj.radius * zoom, obj.color);
		al_draw_pixel (x, y, obj.color);
		al_draw_text (hud.font, hud.text_col, x, y, ALLEGRO_ALIGN_LEFT, obj.name.c_str());
	}

	else if (obj.type == HAB) {
		hab_c &hab = (hab_c&)obj;
		al_draw_filled_circle (x, y, hab.radius * zoom, hab.color);

		ALLEGRO_COLOR engine_color = al_color_name ("red");
		var engine_radius = (hab.radius / 4);
		var engine_angle = 0.7 * M_PI;


		al_draw_filled_circle (	x + zoom * (hab.radius + engine_radius) * cos (hab.ang_pos + engine_angle),
								y + zoom * (hab.radius + engine_radius) * sin (hab.ang_pos + engine_angle),
								engine_radius * zoom,
								engine_color);
		al_draw_filled_circle (	x + zoom * (hab.radius + engine_radius) * cos (hab.ang_pos - engine_angle),
								y + zoom * (hab.radius + engine_radius) * sin (hab.ang_pos - engine_angle),
								engine_radius * zoom,
								engine_color);
		al_draw_filled_circle (	x + zoom * (hab.radius - engine_radius) * cos (hab.ang_pos + M_PI),
								y + zoom * (hab.radius - engine_radius) * sin (hab.ang_pos + M_PI),
								engine_radius * zoom,
								engine_color);

		al_draw_pixel (x, y, hab.color);
	}
}
Example #10
0
Pause_Menu::Pause_Menu(ALLEGRO_EVENT_QUEUE *event, Controls *controls, float screen_width, float screen_height, float font_large_incrementor, ALLEGRO_FONT *font_large, ALLEGRO_SAMPLE *move_sound_down, ALLEGRO_SAMPLE *move_sound_up, float sound_effects_level, bool *quit, bool *hide_standing, int *rounds, int total_rounds)
{
  assert(event);
  assert(controls);
  assert(move_sound_down);
  assert(move_sound_up);
  m_event = event;
  m_controls = controls;
  m_screen_width = screen_width;
  m_screen_height = screen_height;
  m_selection = 0;
  m_font_large_incrementor = font_large_incrementor;
  m_font = font_large;
  m_move_sound_down = move_sound_down;
  m_move_sound_up = move_sound_up;
  m_sound_effects_level = sound_effects_level;
  m_rectangle = new Simple_Rectangle(m_screen_width/4, m_screen_height/4, m_screen_width/2, m_screen_height/2, true, al_color_name("darkgray"));
  m_quit = quit;
  m_hide_standing = hide_standing;
  m_rounds = rounds;
  m_total_rounds = total_rounds;
}
/****************************
        [Animation]
         readScript
****************************/
void Animation :: readScript(int ID)
{
  char           *aux = (char*)malloc(strlen(path) + strlen(ANIMATION_CONF_FILE) + 5),
                  c,
                  value[100],
                 *snd_path,
                 *path_frame;
  long int        dif_x        = 0, 
                  dif_y        = 0,
                  j_to_ID      = -1,
                  j_to_frame   = -1,
                  sub_animation_ID,
                  print_sub_animation_ID,
                  cont;
  double          snd_vol;
  int             snd_frame,
                  snd_ID;
  bool            terminou       = false,
                  loop           = false,
                  lock           = false,
                  sub_animation  = false,
                  print_sub_animation = false;
                  
  volatile int    i;
  
  strcpy(aux, path);
  strcat(aux, "\\");
  strcat(aux, ANIMATION_CONF_FILE);
  arq = fopen(aux, "r");
  
  if( arq == NULL ) OPEN_ERROR(aux, "Animaton.h");
  
  //al_show_native_message_box(NULL, "Script a ser aberto", "teste", aux, NULL, 0);
  while( !feof(arq) )
  {
    if(feof(arq)) break;
    do c = fgetc(arq); while(c == ' ' || c == ';' || c == '\n' && !feof(arq));
    if(feof(arq)) break;
    
    i = 0;
    value[i++] = c;
    do value[i++] = fgetc(arq); while(value[i-1] != '=' && value[i-1] != '(');
    value[i-1] = '\0';
    
    //al_show_native_message_box(NULL, "Script Atual", "teste", value, NULL, 0);
    
    /*************
      Leio o loop
    *************/
    if( (strcmp(value, ANIMATION_LOOP) == 0) )
    {
      /*Leio o valor(1 ou 0)*/
      do c = fgetc(arq); while(c != '1' && c != '0');/*Leio o caractere de atribuicao*/
      value[0] = c;
      value[1] = '\0';
      if( atoi(value) == 0 )
        loop = false;
      else
        loop = true;
    }
    
    /*************
      Leio o lock
    *************/
    if( (strcmp(value, ANIMATION_LOCK) == 0) )
    {
      /*Leio o valor(1 ou 0)*/
      do c = fgetc(arq); while(c != '1' && c != '0');/*Leio o caractere de atribuicao*/
      value[0] = c;
      value[1] = '\0';
      if( atoi(value) == 0 )
        lock = false;
      else
        lock = true;
    }
    
    /*************************************
      Leio o nome da cor a ser mascarada
    **************************************/
    else if( (strcmp(value, ANIMATION_COLOR) == 0) )
    {
      i = 0;
      do value[i++] = fgetc(arq); while(value[i-1] != ';');
      value[i-1] = '\0';
      masked_color = al_color_name(value);
    }
    
    /*************************************
                 Leio o intervalo
    **************************************/
    else if( (strcmp(value, ANIMATION_INTERVAL) == 0) )
    {
      /*Leio tanto numeros quanto o caractere '.'*/
      i = 0;
      do
      {
        value[i] = fgetc(arq);
        if( ( (int)value[i] >= 48 && (int)value[i] <= 58 ) || value[i] == '.' )
          i++;
      }while(value[i] != ';');
      value[i] = '\0';
      interval = atof(value);
    }
    
    /*************************************
                 Leio o Som
    **************************************/
    else if( (strcmp(value, ANIMATION_SOUND) == 0) )
    {
      do c = fgetc(arq); while(c == ' ');
      /*Leio o caminho*/
      value[0] = c;
      i = 1;
      do value[i++] = fgetc(arq); while(value[i-1] != ',');
      value[i-1] = '\0';
      snd_path = (char *)malloc(strlen(value) + 1);
      strcpy(snd_path, value);
      
      /*Leio o volume*/
      i = 0;
      do
      {
        value[i] = fgetc(arq);
        if( (int)value[i] >= 48 && (int)value[i] <= 58 || value[i] == '.' )
          i++;
      }while(value[i] != ',');
      value[i] = '\0';
      snd_vol = atof(value);
      
      /*Leio a ID do sample*/
      i = 0;
      do
      {
        value[i] = fgetc(arq);
        if( (int)value[i] >= 48 && (int)value[i] <= 58)
          i++;
      }while(value[i] != ',');
      value[i] = '\0';
      snd_ID = atoi(value);
      
      aux = (char *)malloc(strlen(path) + strlen(snd_path) + 5);
      strcpy(aux, path);
      strcat(aux, "\\");
      strcat(aux, snd_path);
      /*Inicio o som*/
      animation_snd.init(aux, snd_vol, snd_ID);
      free(aux);
      
      /*Leio os N frames que tocarao este som*/
      terminou = false;
      while(!terminou)
      {
        i = 0;
        do
        {
          value[i] = fgetc(arq);
          if( (int)value[i] >= 48 && (int)value[i] <= 58 )
            i++;
        }while(value[i] != ';' && value[i] != ',');
        if(value[i] == ';')
          terminou = true;
        value[i] = '\0';
        animation_snd.setNewIndex(atoi(value));
        
        //al_show_native_message_box(NULL, "SND NOVO INDEX", "teste", value, NULL, 0);
        
      }
    }
    
    /*************************************
                 Leio os frames
    **************************************/
    else if( (strcmp(value, ANIMATION_FRAMES) == 0) )
    {
      terminou = false;
      while(!terminou)
      {
        j_to_ID = j_to_frame = -1;
        /*Ignoro espacos em branco e quebra de linha*/
        do c = fgetc(arq); while(c == ' ' || c == '\n');
        /***********************************************
             Comeco a ler os frames e seus atributos
                           [NOME]
        ************************************************/
        i = 0;
        value[i++] = c;
        do value[i++] = fgetc(arq); while(value[i-1] != ',');
        value[i-1] = '\0';
        path_frame = (char *)malloc(strlen(path) + strlen(value) + 5);
        strcpy(path_frame, path);
        strcat(path_frame, "\\");
        strcat(path_frame, value);
        
        /***********************************************
                           [DIF_X]
        ************************************************/
        i = 0;
        do
        {
          value[i] = fgetc(arq);
          if( (int)value[i] >= 48 && (int)value[i] <= 58 )
            i++;
        }while(value[i] != ',');
        value[i] = '\0';
        dif_x = atoi(value);
        
        /***********************************************
                           [DIF_Y]
        ************************************************/
        i = 0;
        do
        {
          value[i] = fgetc(arq);
          if( (int)value[i] >= 48 && (int)value[i] <= 58 )
            i++;
        }while(value[i] != ',' && value[i] != ')');
        if(value[i] == ')')
        {
          terminou = true;
          value[i] = '\0';
          dif_y = atoi(value);
          while( (fgetc(arq)) != ';') { }
        }
        else
        {
          value[i] = '\0';
          dif_y = atoi(value);
          while( (c = fgetc(arq)) == ' '){ }
          if(c == '$')
          {
            i = 0;
            do value[i++] = fgetc(arq); while(value[i-1] != '(');
            value[i-1] = '\0';
            
          /***********************************************
            Continuacao sobre a configuracao do Frame
                   [Salto Incondicional]
          ************************************************/
            if( strcmp(value, ANIMATION_JUMP_TO) == 0)
            {
              /****************************
                  Leio o tipo de destino
              ****************************/
              cont = i = 0;
              do
              {
                value[i] = fgetc(arq);
                if( (int)value[i] >= 48 && (int)value[i] <= 58 ) i++;
                else if(value[i] == ',' && cont == 0)
                {
                  value[i] = '\0';
                  j_to_ID = atoi(value);
                  i = 0;
                  cont++;
                }
                else if(value[i] == ')' && cont == 1)
                {
                  value[i] = '\0';
                  j_to_frame = atoi(value);
                  cont++;
                }
              }while(cont < 2);
              do c = fgetc(arq); while(c != ',' && c != ')');
              if(c == ')')
              {
                terminou = true;
                while( (fgetc(arq)) != ';') { }
              }
            }
            
            /*****************************************************
                            [PRINT_SUB_ANIMACAO]
            *****************************************************/
            else if( strcmp(value, ANIMATION_PRINT_SUB_ANIMATION) == 0)
            {
              i = 0;
              do
              {
                value[i] = fgetc(arq);
                if( (int)value[i] >= 48 && (int)value[i] <= 58 ) i++;
              }while(value[i] != ')');
              value[i] = '\0';
              print_sub_animation    = true;
              print_sub_animation_ID = atoi(value);
              
              do c = fgetc(arq); while(c != ',' && c != ')');
              if(c == ')')
              {
                terminou = true;
                while( (fgetc(arq)) != ';') { }
              }
              
              //al_show_native_message_box(NULL, "Print-Sub-Animacao", "teste", value, NULL, 0);
              
            }
            /*****************************************************
                            [SUB_ANIMACAO]
            *****************************************************/
            else if( strcmp(value, ANIMATION_SUB_ANIMATION) == 0)
            {
              i = 0;
              do
              {
                value[i] = fgetc(arq);
                if( (int)value[i] >= 48 && (int)value[i] <= 58 ) i++;
              }while(value[i] != ')');
              value[i] = '\0';
              sub_animation = true;
              sub_animation_ID = atoi(value);
              
              //al_show_native_message_box(NULL, "Sub-Animacao", "teste", value, NULL, 0);
              
              do c = fgetc(arq); while(c != ',' && c != ')');
              if(c == ')')
              {
                terminou = true;
                while( (fgetc(arq)) != ';') { }
              }
            }
          }
        }
        
        animation_frames.load(path_frame, dif_x, dif_y, ID, loop, lock, masked_color);
        if(j_to_ID != -1 && j_to_frame != -1)
        {
          frames_fim->setFrameJumpTo(j_to_ID, j_to_frame);
          j_to_ID = j_to_frame = -1;
        }
        if(sub_animation)
        {
          sub_animation               = false;
          frames_fim->SUB_ANIMATION   = true;
          frames_fim->ID              = sub_animation_ID;
          animation_timer.New(ID, interval);
          timer_fim->SUB_ANIMATION = true;
        }
        if(print_sub_animation)
        {
          print_sub_animation = false;
          frames_fim->PRINT_SUB_ANIMATION    = true;
          frames_fim->PRINT_SUB_ANIMATION_ID = print_sub_animation_ID;
        }
        free(path_frame);
      }
    }
    
    while( (fgetc(arq)) != '\n' ){ }
  }
  
  fclose(arq);

}
Example #12
0
   static void draw(float x, float y)
   {
      float w = 300;
      float line_height = 25;
      float pad = 20;
      float h = Profiler::get_instance()->timer.size()*line_height + pad*2;
      PROFILE_TIMER_TIME_T duration = 0.0;
      int i=0;
      char time[32];

      al_draw_filled_rounded_rectangle(x, y, x+w, y+h, 8, 8, bg_color);

      //if (!font) return;

      std::vector<profile_timer_class *>::iterator it = Profiler::get_instance()->timer.begin();
      for ( ; it != get_instance()->timer.end(); ++it)
      {
         duration = (*it)->stop_time - (*it)->start_time;
         al_draw_filled_rectangle(x, y+pad+line_height*i+15, x+duration*10000, y+pad+line_height*i+20, al_color_name("orange"));
         al_draw_text(font, font_color, x+pad, y+pad+line_height*i, 0, (*it)->name);
         sprintf(time, "%f", duration*100);
         al_draw_text(font, font_color, x+pad+200, y+pad+line_height*i, 0, time);
         i++;
      }
      al_draw_line(x+ALLEGRO_BPS_TO_SECS(60)*10000, y, x+ALLEGRO_BPS_TO_SECS(60)*10000, y+h, limit_bar_color, 1.0);
      al_draw_line(x+ALLEGRO_BPS_TO_SECS(72)*10000, y, x+ALLEGRO_BPS_TO_SECS(72)*10000, y+h, limit_bar_color, 1.0);
   }
Example #13
0
void MapGrid::DrawPath()
{
	for (int i = 0; i < pathx.size(); i++)
	{
		//std::cout << grid[GridHeight - 1][finishx].GetGridX() << " " << grid[GridHeight - 1][finishx].Getx() << std::endl;
		//std::cout << grid[GridHeight - 1][finishx].GetParent()->GetGridX() << " " << grid[GridHeight - 1][finishx].GetParent()->Getx() << std::endl;
		//std::cout << "drawing path circle" << std::endl;
		//std::cout << pathx.size() << " " << pathy.size() << std::endl;
		//std::cout << pathy.at(i) << std::endl;
		//std::cout << pathx.at(i) << std::endl;
		//std::cout << grid[pathy[i]][pathx[i]].Getx() << std::endl;
		al_draw_filled_circle(grid[pathy[i]][pathx[i]].Getx() + (SideLength/2), grid[pathy[i]][pathx[i]].Gety() + (SideLength /2), SideLength / 8, al_color_name("red"));
		//std::cout << "drawed path circle" << std::endl;
	}
}
Example #14
0
void	graphics::hud_c::draw () {

	if (!nav::ship || !nav::ref || !nav::targ) return;

	column_w	= graphics::camera->size[0] / columns;
	text_start_x= padding;
	text_start_y= graphics::camera->size[1] - 9 * 17;

	al_draw_filled_rectangle
		(0, text_start_y - padding,
			graphics::camera->size[0], graphics::camera->size[1],
			al_color_name("black"));
	al_draw_line
		(0, text_start_y - padding,
			graphics::camera->size[0], text_start_y - padding,
			al_color_name("white"), 1);

	std::stringstream text("");
	text << std::setprecision(2) << std::uppercase << std::fixed;
	line = 0;
	column = 0;


	text << "Speed (" << nav::ref->name << "): "
		<< calc::velocity(*nav::ship, *nav::ref).norm();
	add_line(text);
	text << "Speed (" << nav::targ->name << "): "
		<< calc::velocity(*nav::ship, *nav::targ).norm();
	add_line(text);
	text << "Orbital Speed (" << nav::ref->name << "): "
		<< calc::v_orbit(*nav::ship, *nav::ref);
	add_line(text);
	text << "Centrifugal Speed (" << nav::ref->name << "): "
		<< calc::v_cen(*nav::ship, *nav::ref);
	add_line(text);
	text << "Tangential Speed (" << nav::ref->name << "): "
		<< calc::v_tan(*nav::ship, *nav::ref);
	add_line(text);
	text << "Acceleration (" << nav::ship->name << "): "
		<< nav::ship->acc.norm();
	add_line(text);
	text << "Stopping Acceleration (" << nav::ref->name << "): "
		<< calc::stopping_acc(*nav::ship, *nav::ref);
	add_line(text);
	text << "Periapsis (" << nav::ref->name << "): "
		<< calc::periapsis(*nav::ship, *nav::ref);
	add_line(text);
	text << "Apoapsis (" << nav::ref->name << "): "
		<< calc::apoapsis(*nav::ship, *nav::ref);
	add_line(text);


	new_column();

	if (nav::ship->type == HAB) {
		hab_c *hab = (hab_c*) nav::ship;
		text << "Fuel (" << hab->name << "): "
			<< hab->fuel;
		add_line(text);

		text << "Throttle (" << hab->name << "): "
			<< hab->throttle * 100 << '%';
		add_line(text);
	}

	add_line(text);

	add_line(text);
	add_line(text);
	add_line(text);
	add_line(text);
	add_line(text);


	graphics::draw_at(*nav::ship,
					25/nav::ship->radius,
					graphics::camera->size[0]/2,
					text_start_y + padding + 56);


	text << "Turn rate (" << nav::ship->name << "): "
		<< nav::ship->ang_v/M_PI*180 << " \u00B0/s";
	add_line(text);


	new_column();


	text << "Altitude (" << nav::ref->name << "): "
		<< calc::distance(*nav::ship, *nav::ref) - (nav::ship->radius + nav::ref->radius);
	add_line(text);
	text << "Time Dilation: "
		<< tidi << "x";
	add_line(text);

	text << "\u03B8 (\u2220" << nav::ship->name<<'/'<<nav::ref->name<<'/'<<nav::targ->name<< "): "
		<< calc::theta(*nav::ship, *nav::ref, *nav::targ);
	add_line(text);
	text << "Pitch (" << nav::ref->name << "): "
		<< calc::pitch(*nav::ship, *nav::ref);
	add_line(text);
	text << "Center: "
		<< graphics::camera->center->name;
	add_line(text);
	text << "Ship: "
		<< nav::ship->name;
	add_line(text);
	text << "Target: "
		<< nav::targ->name;
	add_line(text);
	text << "Reference: "
		<< nav::ref->name;
	add_line(text);
	text << "Navigation: "
		<< "Manual";
	add_line(text);
}
Example #15
0
namespace	graphics {
	camera_c	*camera = &default_camera;
	hud_c		hud (al_color_name ("grey"));
}
Example #16
0
Creature::Creature(std::string name) : Entity(name)
{
	drawable_components.push_back(new GUI::StatusBar(x, y, hp, 100, al_color_name("red")));
}
Example #17
0
File: Color.cpp Project: ArekX/RAGE
		void Color::from_name(char *name)
		{
			RAGE_CHECK_DISPOSED(disposed);
			
			color = al_color_name(name);
		}
Example #18
0
void ship::draw(ALLEGRO_MOUSE_STATE state){
    al_draw_filled_rectangle(xPos,yPos,xPos + (35 * ssize), yPos + 35, al_color_name("gray"));
    if(state.x > xPos && state.x < xPos + (35* ssize) && state.y > yPos && state.y < yPos + 35){
        al_draw_rectangle(xPos,yPos,xPos + (35 * ssize), yPos + 35, al_color_name("cyan"), 1);
    }
}
Example #19
0
int main(int argc, char **argv)
{
    if (!al_init())
    {
        printf("failed to initialize allegro!\n");
        return -1;
    }

    if (!al_init_image_addon())
    {
        printf("failed to initialize image I/O addon!\n");
        return -1;
    }

    if (!al_init_primitives_addon())
    {
        printf("failed to initialize primitives addon!\n");
        return -1;
    }

    ALLEGRO_DISPLAY *display = al_create_display(arena_width, arena_height);
    if (!display)
    {
        printf("failed to create display!\n");
        return -1;
    }

    if (!al_install_keyboard())
    {
        printf("failed to install keyboard!\n");
        return -1;
    }

    bad_guy_timer = al_create_timer(ALLEGRO_BPS_TO_SECS(100));
    if (!bad_guy_timer)
    {
        printf("failed to create timer!\n");
        return -1;
    }
    al_start_timer(bad_guy_timer);

    black = al_color_name("black");

    hero_x = arena_width / 4;
    hero_y = arena_height / 4;
    hero_bitmap = al_load_bitmap("hero.png");

    bad_guy_x = bad_guy_starting_x;
    bad_guy_y = bad_guy_starting_y;
    bad_guy_color = al_color_name("red");

    while (!al_key_down(keyboard_state, ALLEGRO_KEY_ESCAPE))
    {
        al_get_keyboard_state(keyboard_state);

        while (al_get_timer_count(bad_guy_timer) > bad_guy_count)
        {
            if (al_key_down(keyboard_state, ALLEGRO_KEY_LEFT) && hero_x > hero_half_size)
            {
                hero_x -= hero_speed;
            }
            if (al_key_down(keyboard_state, ALLEGRO_KEY_RIGHT) && hero_x < arena_width - hero_half_size)
            {
                hero_x += hero_speed;
            }
            if (al_key_down(keyboard_state, ALLEGRO_KEY_UP) && hero_y > hero_half_size)
            {
                hero_y -= hero_speed;
            }
            if (al_key_down(keyboard_state, ALLEGRO_KEY_DOWN) && hero_y < arena_height - hero_half_size)
            {
                hero_y += hero_speed;
            }

            // Some trigonometry to move toward the hero
            double bad_guy_angle = atan2(hero_y - bad_guy_y, hero_x - bad_guy_x);
            bad_guy_x += bad_guy_speed * cos(bad_guy_angle);
            bad_guy_y += bad_guy_speed * sin(bad_guy_angle);
            bad_guy_speed += bad_guy_acceleration;

            // Reset bad guy when he hits the hero
            if (abs(hero_x - bad_guy_x) < bad_guy_half_size && abs(hero_y - bad_guy_y) < bad_guy_half_size)
            {
                bad_guy_x = bad_guy_starting_x;
                bad_guy_y = bad_guy_starting_y;
                bad_guy_speed = bad_guy_starting_speed;
            }

            al_add_timer_count(bad_guy_timer, -1);
        }

        al_clear_to_color(black);

        al_draw_bitmap(hero_bitmap,
                       hero_x - hero_half_size,
                       hero_y - hero_half_size,
                       0);
        al_draw_filled_circle(bad_guy_x,
                              bad_guy_y,
                              bad_guy_half_size,
                              bad_guy_color);

        al_flip_display();
    }

    return 0;
}
Example #20
0
int Enemy::Draw()
{
    if (pathx.size() == 0)
    {
        enabled = false;
        return 2;
    }
    if (health <= 0)
    {
        return 3;
    }
    if(enabled)
    {
		bool left = false;
		bool right = false;
		bool up = false;
		bool down = false;
		std::cout << "current xy: " << x << ", " << y << " " << pathx[pathx.size() - 1] << ", " << pathy[pathy.size() - 1] << std::endl;
		if (x < pathx[pathx.size() - 1])
		{
			x += speed;
			right = true;
			std::cout << "moving right" << std::endl;
		}
		else if (x > pathx[pathx.size() - 1])
		{
			x -= speed;
			left = true;
			std::cout << "moving left" << std::endl;
		}
		if (y < pathy[pathy.size() - 1])
		{
			y += speed;
			down = true;
			std::cout << "moving down" << std::endl;
		}
		else if (y > pathy[pathy.size() - 1])
		{
			y -= speed;
			up = true;
			std::cout << "moving up" << std::endl;
		}
            
        al_draw_filled_circle(x + (70/2), y + (70 /2), 70 / 4, al_color_name("blue"));
        
		//if(x == pathx[pathx.size() - 1] && y == pathy[pathx.size() - 1])
        //{
        //    pathx.pop_back();
        //    pathy.pop_back();
        //    //return 1;
        //}
		if ((right && x >= pathx[pathx.size() - 1]) || (left && x <= pathx[pathx.size() - 1]) || (x == pathx[pathx.size() -1] && y == pathy[pathy.size()-1]))
		{
			x = pathx[pathx.size() - 1];
			pathx.pop_back();
			pathy.pop_back();
			return 1;
		}
		else if (up && y <= pathy[pathy.size() - 1])
		{
			y = pathy[pathy.size() - 1];
			pathx.pop_back();
			pathy.pop_back();
			return 1;
		}
		else if (down && y >= pathy[pathy.size() - 1])
		{
			y = pathy[pathy.size() - 1];
			pathx.pop_back();
			pathy.pop_back();
			return 1;
		}


        
    }
    return 0;
}
Example #21
0
void Text::drawToScreen(){
	al_draw_text(this->_font, al_color_name(this->_color), this->_position->x(), this->_position->y(), 0, this->_text);
}
Example #22
0
void al_color_name_w(char const *name, ALLEGRO_COLOR *color)
{
	*color = al_color_name(name);
}