Example #1
0
void drawTile(float x, float y, int tileId){
    switch(tileId){
        case 0:
            //al_draw_filled_rectangle(x*tileSize, y*tileSize, x*tileSize+tileSize, y*tileSize+tileSize, al_map_rgb(150, 150, 150));
            al_draw_rotated_bitmap((mapTileArray[(int)x][(int)y] / 4 >= 1) ? groundImage1 : groundImage2, tileSize/2, tileSize/2, x*tileSize+tileSize/2, y*tileSize+tileSize/2, (mapTileArray[(int)x][(int)y]%4)*90*toRadians, NULL);
            break;

        case 1:
            //al_draw_filled_rectangle(x*tileSize, y*tileSize, x*tileSize+tileSize, y*tileSize+tileSize, al_map_rgb(100, 100, 100));
            al_draw_rotated_bitmap(brokenWallImage, tileSize/2, tileSize/2, x*tileSize+tileSize/2, y*tileSize+tileSize/2, mapTileArray[(int)x][(int)y]*90*toRadians, NULL);
            break;
    }
}
Example #2
0
void gui_river_heart(int lifes)
{
    extern int frame_length;
    int i;
    for(i = lifes; i > 0; i--)
        al_draw_rotated_bitmap(heart, 0, 0, frame_length-20*i, 0, 0,0);
}
Example #3
0
void
ship_draw(SHIP *ship, bool thrusting)
{
  if(ship->explosion != NULL) {
    animation_draw(ship->explosion);
    return;
  }

  ALLEGRO_BITMAP *current_sprite;

  /* this creates a flashing thrust visualization
   * not _exactly_ like the original (too fast), but close. (FIXME) */
  current_sprite = ship->sprite;
  if(thrusting && !ship->thrust_visible)
    current_sprite = ship->thrust_sprite;

  al_draw_rotated_bitmap(
      current_sprite,
      ship->width  / 2,
      ship->height / 2,
      ship->position->x,
      ship->position->y,
      deg2rad(ship->angle),
      DRAWING_FLAGS);

  ship->thrust_visible = (ship->thrust_visible) ? false : true;
}
Example #4
0
void gui_boat_draw(int *x, int *y, int prop)
{
    /* Realiza o movimento */
    int rotate;
    if(mov[LEFT])
    {
       (*x) -= 0.5 * prop;
       rotate = -1;
    }
    else if(mov[RIGHT])
    {
        (*x) += 0.5 * prop;
        rotate = 1;
    }
    else rotate = 0;
    if(mov[DOWN])  (*y) -= 0.5 * prop;
    if(mov[UP])    (*y) += 0.5 * prop;

    al_draw_rotated_bitmap(boat, boat_width/2, boat_height/2, (*x * prop), (*y * prop)-30.0, rotate*ALLEGRO_PI/8, 0);
    /*al_draw_bitmap(boat, (*x*prop), (*y*prop)-60, 0);*/
    /*al_draw_filled_ellipse((*x * prop), (*y * prop)-20.0,
            10.0, 20.0, al_map_rgb(139, 87, 66));*/
      /*rotate_sprite(xcf, "canoa.xcf",25, 5, 45); */

}
Example #5
0
void Bullet::draw(){
    if(!this->playerShot){
        al_draw_filled_rectangle(this->posX, this->posY, this->posX + this->width, this->posY + this->height, al_map_rgb(255, 50, 50));
    }else{
        al_draw_rotated_bitmap(bulletImage, this->width/2, this->height/2, this->posX+width/2, this->posY+height/2, this->angle, NULL);
    }
}
Example #6
0
void ShopState::draw(Engine* engine){

    for(int i = 0; i < MAX_BUTTONS; i++){
        if(buttonList[i] != NULL && buttonList[i]->checkActive()){
            buttonList[i]->draw();
        }
    }

    al_draw_rotated_bitmap(playerImage, playerWidth/2, playerHeight/2, playerX+playerWidth/2, playerY+playerHeight/2, -atan2(playerCenterX - mouseX, playerCenterY - mouseY), NULL);

    for(int i = 0; i < MAX_BULLETS; i++){
        if(bulletList[i] != NULL && bulletList[i]->checkActive()){
            bulletList[i]->draw();
        }
    }

    al_draw_textf(defaultFont, al_map_rgb(50, 150, 50), 0, 400, NULL, "%d$", playerMoney);
    al_draw_textf(defaultFont, al_map_rgb(122, 122, 122), 0, 400+32, NULL, "Health: %f", playerHealth);
    al_draw_textf(defaultFont, al_map_rgb(122, 122, 122), 0, 400+32*2, NULL, "Max Health: %f", playerMaxHealth);
    al_draw_textf(defaultFont, al_map_rgb(122, 122, 122), 0, 400+32*3, NULL, "Speed: %f", playerBulletSpeed);
    al_draw_textf(defaultFont, al_map_rgb(122, 122, 122), 0, 400+32*4, NULL, "Bullets: %d", playerShots);
    al_draw_textf(defaultFont, al_map_rgb(122, 122, 122), 0, 400+32*5, NULL, "Weapon Spread Arc: %f*", playerBulletSpread*360);
    al_draw_textf(defaultFont, al_map_rgb(122, 122, 122), 0, 400+32*6, NULL, "Damage: %d", playerDamage);
    al_draw_textf(defaultFont, al_map_rgb(122, 122, 122), 0, 400+32*7, NULL, "Bullet Speed: %d", playerBulletSpeed);
    al_draw_textf(defaultFont, al_map_rgb(122, 122, 122), 0, 400+32*8, NULL, "Fire Rate: %d", playerFiringSpeed);
}
Example #7
0
	void Graphics::Draw(Texture* source, float destX, float destY, bool flipped, float angle)
	{
		if(!source)
		{
			al_show_native_message_box(TF::engine->display, "Error", "Error", "[TEXTURE DRAW] The texture is NULL!", 
									 NULL, ALLEGRO_MESSAGEBOX_ERROR);
			return;
		}

		if(angle == 0.0f) {
			if(!flipped) al_draw_bitmap(source->tex, destX, destY, 0);
			else al_draw_bitmap(source->tex, destX, destY, ALLEGRO_FLIP_HORIZONTAL);
		} else {
			if(!flipped) al_draw_rotated_bitmap(source->tex, 0.0f, 0.0f, destX, destY, angle, 0);
			else al_draw_rotated_bitmap(source->tex, 0.0f, 0.0f, destX, destY, angle, ALLEGRO_FLIP_HORIZONTAL);
		}
	}
Example #8
0
void OurHero::update() {
	float posX = OurEntity::getPosX(); // Get private data of derived class OurEntity's position X
	float posY = OurEntity::getPosY(); // get private data of derived class OurEntity's position Y
																	
	al_draw_rotated_bitmap(heroBitmap, al_get_bitmap_width(heroBitmap) / 2, al_get_bitmap_height(heroBitmap) / 2, posX, posY,
		OurEntity::getAngle(), ALLEGRO_VIDEO_BITMAP);	// Update hero's position with OurEntity's position
														// Enable hardware acceleration for this sprite
	updateHeroLights(); // Move hero light to hero position (so light follows our hero)
}
void PeacemakerBullet::render(Renderer *renderer, Gamestate *state)
{
    std::string mainsprite = getsprite(state, false);
    ALLEGRO_BITMAP *sprite = renderer->spriteloader.requestsprite(mainsprite);
    double direction = std::atan2(vspeed, hspeed);

    al_set_target_bitmap(renderer->background);
    al_draw_rotated_bitmap(sprite, 0, 0, x - renderer->cam_x, y - renderer->cam_y, direction, 0);
}
Example #10
0
void Prog::draw_bitmap(const std::string & str,
   const std::string &how,
   bool memory,
   bool destination)
{
   int i = destination ? 1 : 0;
   int rv = r[i].get_cur_value();
   int gv = g[i].get_cur_value();
   int bv = b[i].get_cur_value();
   int av = a[i].get_cur_value();
   ALLEGRO_COLOR color = makecol(rv, gv, bv, av);
   ALLEGRO_BITMAP *bmp;

   if (contains(str, "Mysha"))
      bmp = (memory ? mysha_bmp : mysha);
   else
      bmp = (memory ? allegro_bmp : allegro);

   if (how == "original") {
      if (str == "Color")
         al_draw_filled_rectangle(0, 0, 320, 200, color);
      else if (contains(str, "tint"))
         al_draw_tinted_bitmap(bmp, color, 0, 0, 0);
      else
         al_draw_bitmap(bmp, 0, 0, 0);
   }
   else if (how == "scaled") {
      int w = al_get_bitmap_width(bmp);
      int h = al_get_bitmap_height(bmp);
      float s = 200.0 / h * 0.9;
      if (str == "Color") {
         al_draw_filled_rectangle(10, 10, 300, 180, color);
      }
      else if (contains(str, "tint")) {
         al_draw_tinted_scaled_bitmap(bmp, color, 0, 0, w, h,
            160 - w * s / 2, 100 - h * s / 2, w * s, h * s, 0);
      }
      else {
         al_draw_scaled_bitmap(bmp, 0, 0, w, h,
            160 - w * s / 2, 100 - h * s / 2, w * s, h * s, 0);
      }
   }
   else if (how == "rotated") {
      if (str == "Color") {
         al_draw_filled_circle(160, 100, 100, color);
      }
      else if (contains(str, "tint")) {
         al_draw_tinted_rotated_bitmap(bmp, color, 160, 100,
            160, 100, ALLEGRO_PI / 8, 0);
      }
      else {
         al_draw_rotated_bitmap(bmp, 160, 100,
            160, 100, ALLEGRO_PI / 8, 0);
      }
   }
}
static void renderWave(void)
{
   int w = al_get_bitmap_width(waveBitmap);
   int h = al_get_bitmap_height(waveBitmap);

   float a = waveAngle + ALLEGRO_PI/2;

   int x = (int)(BB_W/2 + 64*cos(a));
   int y = (int)(BB_H/2 + 64*sin(a));

   al_draw_rotated_bitmap(waveBitmap, w/2, h,
      x, y, waveAngle, 0);
}
Example #12
0
static int allua_Bitmap_draw_rotated(lua_State * L)
{
   ALLUA_bitmap bitmap = allua_check_bitmap(L, 1);
   float cx = luaL_checknumber(L, 2);
   float cy = luaL_checknumber(L, 3);
   float dx = luaL_checknumber(L, 4);
   float dy = luaL_checknumber(L, 5);
   float angle = luaL_checknumber(L, 6);
   int flags = luaL_checkint(L, 7);

   al_draw_rotated_bitmap(bitmap, cx, cy, dx, dy, angle, flags);
   return 0;
}
Example #13
0
void Bullet::Render()
{
	if( ForRemoval )
	{
		return;
	}

	ALLEGRO_BITMAP* tileset = Game->GetGameScaledImage();
	int tileX = (64 + (Animation_CurrentFrame * 16)) * Game->graphicsMultiplier;
	int tileY = 16 * Game->graphicsMultiplier;

	ALLEGRO_BITMAP* tmp = al_create_sub_bitmap( tileset, tileX, tileY, 16 * Game->graphicsMultiplier, 16 * Game->graphicsMultiplier );
	al_draw_rotated_bitmap( tmp, 8 * Game->graphicsMultiplier, 8 * Game->graphicsMultiplier, Position->X * Game->graphicsMultiplier, Position->Y * Game->graphicsMultiplier, Angle * (M_PI / 180), 0 );
	al_destroy_bitmap( tmp );
	
}
Example #14
0
void Resistor::updateResistor(ALLEGRO_BITMAP* resistorImage, vector<Resistor> &resistorArray, ALLEGRO_FONT *font, bool diagonally) {
	if (horizontal) {
		al_draw_bitmap(resistorImage, rPos.x, rPos.y - al_get_bitmap_height(resistorImage) / 2, 0);
		al_draw_textf(font, al_map_rgb(BLACK), rPos.x + al_get_bitmap_width(resistorImage) / 2, rPos.y - al_get_bitmap_height(resistorImage) / 2, ALLEGRO_ALIGN_CENTER, "%.0f Ohm", value);
	}
	else {
		al_draw_rotated_bitmap(resistorImage, al_get_bitmap_width(resistorImage) / 2, al_get_bitmap_width(resistorImage) / 2, rPos.x - al_get_bitmap_height(resistorImage), rPos.y + al_get_bitmap_width(resistorImage) / 2, PI / 2, 0);
		al_draw_textf(font, al_map_rgb(BLACK), rPos.x + 10, rPos.y + 20, ALLEGRO_ALIGN_LEFT, "%.0f Ohm", value);
	}
	//Draw lines.
	if (ptr2son != -1 ) { 
		if (ptr2son < resistorArray.size()) {	//Normally this should always be true. But just in case, to know where it exploded
			pos sonPos = resistorArray[ptr2son].getCoords();
			if (horizontal) {
				draw_line(rPos.x + al_get_bitmap_width(resistorImage), rPos.y, sonPos.x, sonPos.y, al_map_rgb(LINECOLOUR), LINEWIDTH, diagonally);
			}
			else {
				draw_line(rPos.x, rPos.y + al_get_bitmap_width(resistorImage), sonPos.x, sonPos.y, al_map_rgb(LINECOLOUR), LINEWIDTH, diagonally);
			}
		}
		else { cout << "Son of a resistor was out of bounds" << endl; }
	}
	if (ptr2brother != -1) {
		if (ptr2brother < resistorArray.size()) {
			pos broPos = resistorArray[ptr2brother].getCoords();
			draw_line(rPos.x, rPos.y, broPos.x, broPos.y, al_map_rgb(LINECOLOUR), LINEWIDTH, diagonally);
		}
		else { cout << "Brother out of bounds" << endl; }
	}
	if (ptr2stepBro != -1) {
		if (ptr2stepBro < resistorArray.size()) {
			pos broPos = resistorArray[ptr2stepBro].getCoords();
			bool broHorizontal = resistorArray[ptr2stepBro].getHoriz();
			if (horizontal) {
				if (broHorizontal) { draw_line(rPos.x + al_get_bitmap_width(resistorImage), rPos.y, broPos.x + al_get_bitmap_width(resistorImage), broPos.y, al_map_rgb(LINECOLOUR), LINEWIDTH, diagonally); }
				else { draw_line_inverted(rPos.x + al_get_bitmap_width(resistorImage), rPos.y, broPos.x, broPos.y + al_get_bitmap_width(resistorImage), al_map_rgb(LINECOLOUR), LINEWIDTH, diagonally); }
			}
			else {
				if (broHorizontal) { draw_line_inverted(rPos.x, rPos.y + al_get_bitmap_width(resistorImage), broPos.x + al_get_bitmap_width(resistorImage), broPos.y, al_map_rgb(LINECOLOUR), LINEWIDTH, diagonally); }
				else { draw_line_inverted(rPos.x, rPos.y + al_get_bitmap_width(resistorImage), broPos.x,  broPos.y + al_get_bitmap_width(resistorImage), al_map_rgb(LINECOLOUR), LINEWIDTH, diagonally); }
			}
		}
		else { cout << "StepBro out of bounds" << endl; }
	}
}
Example #15
0
static mrb_value
bitmap_draw_rotated(mrb_state *mrb, mrb_value self)
{
  ALLEGRO_BITMAP *b;
  mrb_float cx;
  mrb_float cy;
  mrb_float dx;
  mrb_float dy;
  mrb_float angle;
  mrb_sym flag1;
  mrb_sym flag2;
  int argc;
  int flags;
  Check_Destroyed(mrb, self, bitmap, b);
  argc = mrb_get_args(mrb, "fffff|nn", &cx, &cy, &dx, &dy, &angle, &flag1, &flag2);
  flags = argc > 5 ? mrbal_bitmap_get_flags(mrb, argc, flag1, flag2) : 0;
  al_draw_rotated_bitmap(b, cx, cy, dx, dy, angle, flags);
  return mrb_nil_value();
}
Example #16
0
static void draw(ALLEGRO_BITMAP *bitmap, int y, char const *text)
{
    int i;

    al_draw_text(font_ms, al_map_rgb(0, 0, 0), 0, y, 0, text);

    for (i = 0; i < 16; i++) {
        float a = 2 * ALLEGRO_PI * i / 16;
        ALLEGRO_COLOR c = al_color_hsv(i * 360 / 16, 1, 1);
        al_draw_line(150 + cos(a) * 10, y + 100 + sin(a) * 10,
                     150 + cos(a) * 90, y + 100 + sin(a) * 90, c, 3);
    }

    for (i = 0; i < 8; i++) {
        float a = 2 * ALLEGRO_PI * i / 16;
        int s = al_get_bitmap_width(bitmap);
        al_draw_rotated_bitmap(bitmap, s / 2, s / 2,
                               50 + bitmap_x[i], y + bitmap_y[i], a, 0);
    }
}
Example #17
0
void Peacemaker::render(Renderer *renderer, Gamestate *state)
{
    std::string mainsprite;
    double dir = aimdirection;
    Mccree *c = state->get<Mccree>(state->get<Player>(owner)->character);
    if (firinganim.active())
    {
        mainsprite = firinganim.getframepath();
    }
    else if (reloadanim.active())
    {
        mainsprite = reloadanim.getframepath();
        dir = 3.1415*c->isflipped;
    }
    else if (fthanim.active())
    {
        mainsprite = fthanim.getframepath();
    }
    else
    {
        mainsprite = c->getcharacterfolder()+"arm/1";
    }
    ALLEGRO_BITMAP *sprite = renderer->spriteloader.requestsprite(mainsprite);
    int spriteoffset_x = renderer->spriteloader.get_spriteoffset_x(mainsprite);
    int spriteoffset_y = renderer->spriteloader.get_spriteoffset_y(mainsprite);
    Rect spritedimensions = renderer->spriteloader.get_rect(mainsprite);

    al_set_target_bitmap(renderer->midground);
    if (c->weaponvisible(state))
    {
        if (c->isflipped)
        {
            al_draw_scaled_rotated_bitmap(sprite, getattachpoint_x()+spriteoffset_x, getattachpoint_y()+spriteoffset_y, x - renderer->cam_x, y - renderer->cam_y, 1, -1, dir, 0);
        }
        else
        {
            al_draw_rotated_bitmap(sprite, getattachpoint_x()+spriteoffset_x, getattachpoint_y()+spriteoffset_y, x - renderer->cam_x, y - renderer->cam_y, dir, 0);
        }
    }
}
void AnimatedComp::update(double dt)
{
	if(visible){
		if(current_time>frame_interval)
		{
			current_time = 0;

			current_frame.x++;

			if(current_frame.x>=number_frames.x)
				current_frame.x= 0;
		}

		current_time+=dt;

		al_draw_rotated_bitmap(	bitmap_2Dvector[current_frame.x][current_frame.y],
			offset.x,offset.y,
			positionComp->getPosition().x,-positionComp->getPosition().y,
			Radian::convertToGame(positionComp->getRotation()), 
			0);	
	}
}
Example #19
0
// |----------------------------------------------------------------------------|
// |							     draw()										|
// |----------------------------------------------------------------------------|
void Image::draw() {
	if (graphic) {
		if (angle) {
			if (alpha != 1) {
				al_draw_tinted_rotated_bitmap(graphic, 
					al_map_rgba_f(1, 1, 1, alpha), size.x/2, size.y/2, 
					anchor.x + size.x/2, anchor.y + size.y/2, angle, 0);
			}
			else {
				al_draw_rotated_bitmap(graphic, size.x/2, size.y/2, 
					anchor.x + size.x/2, anchor.y + size.y/2, angle, 0);
			}
		}
		else {
			if (alpha != 1) {
				al_draw_tinted_bitmap(graphic, al_map_rgba_f(1, 1, 1, alpha), anchor.x, anchor.y, 0);
			}
			else {
				al_draw_bitmap(graphic, anchor.x, anchor.y, 0);
			}
		}
	}
}
Example #20
0
void obj_Saw_Bar::Draw()
{
	al_draw_rotated_bitmap(image, 4, 4, x+16, y+16, direction, 0);
}
void LargeBullet::render(int offx, int offy)
{
   al_draw_rotated_bitmap(bitmap, radius, radius, offx + x, offy + y,
      angle+(ALLEGRO_PI/2), 0);
}
Example #22
0
int main()
{          
	const float FPS = 60.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

	// Inicializo el temporizador principal
	al_start_timer(timer);

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


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

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

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

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

	return 0;
}
Example #23
0
void Blood_Torso::Draw()
{
	//al_draw_rotated_bitmap(image,1,4,TranslateCameraX(x), TranslateCameraY(y),direction*PI/180.0,0);
	al_draw_rotated_bitmap(image,1,4,x, y,direction*PI/180.0,0);
}
Example #24
0
	// Method to handle drawing logic of the Character Object
	void DrawObj(ALLEGRO_DISPLAY *screen)
	{
		// X coordinate calculation of selected frame/region
		int PresentFrameX = PresentFrame * F_W;
		// Y coordinate of selected frame/region
		int PresentFrameY = 0;
		// Empty bitmap to store rotated image
		ALLEGRO_BITMAP *rotated = NULL;
		// Creating the new bitmap with width and height same as the selected frame/region
		rotated = al_create_bitmap(F_W, F_H);
		// New bitmap selected for drawing instead of backbuffer
		al_set_target_bitmap(rotated);
		// Particular region/frame is selected and drawn on to the new bitmap
		al_draw_bitmap_region(image, PresentFrameX, PresentFrameY, F_W, F_H, 0, 0, 0);
		// Drawing target changed back to backbuffer of the screen
		al_set_target_bitmap(al_get_backbuffer(screen));


		/* Logic to handle the rotation of the sprite as per Direct
		0 degree is 0 radian
		90 degree is pi / 2
		180 degree is pi
		270 degree is 1.5 * pi
		360 degree is 2 * pi
		Check radian and degree conversion chart
		*/
		switch (Direct)
		{
		case STAND:
			angle = angle; // No rotation
			break;
		case RIGHT:
			angle = 0; // 0 degree rotation
			break;
		case LEFT:
			angle = ALLEGRO_PI; // 180 degree rotation
			break;
		case DOWN:
			angle = ALLEGRO_PI / 2; // 90 degree rotation
			break;
		case UP:
			angle = ALLEGRO_PI * 1.5; // 270 degree rotation
			break;

		}
		// Rotate the new bitmap 'rotated' holding our selected region of the sprite sheet
		// Draw it on to the backbuffer
		al_draw_rotated_bitmap(rotated, F_W / 2, F_H / 2, X, Y, angle, 0);
		// Free resoruce after using ALLEGRO_BITMAP 'rotated'
		al_destroy_bitmap(rotated);
		// Logic to handle frame delay in animation sequence
		if (++DelayCount >= frameDelay)
		{
			// Frame animation sequence logic
			// Increment frame & reset frame counter to 0 after traversing through all frames
			if (++PresentFrame >= NumbOfFrames)PresentFrame = 0;
			// If Character Object is standing, only draw the first frame of the sprite sheet
			if (Direct == STAND){ PresentFrame = 0; DelayCount = frameDelay; }
			// Reset frame delay counter to 0, after it has completed its delay cycle
			DelayCount = 0;
		}
	}
Example #25
0
int main(int argc, char **argv)
{
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;
    ALLEGRO_BITMAP *bouncer = NULL;
    float angle = 0;
    float length = 0;
    float vel_x, vel_y;
    float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE_Y / 2.0;
    float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE_Y / 2.0;
    bool key[5] = { false, false, false, false, false };
    bool redraw = true;
    bool doexit = false;



    if(!al_init()) {
        fprintf(stderr, "failed to initialize allegro!\n");
        return -1;
    }


    if(!al_install_keyboard()) {
        fprintf(stderr, "failed to initialize the keyboard!\n");
        return -1;
    }

    timer = al_create_timer(1.0 / FPS);
    if(!timer) {
        fprintf(stderr, "failed to create timer!\n");
        return -1;
    }

    display = al_create_display(SCREEN_W, SCREEN_H);
    if(!display) {
        fprintf(stderr, "failed to create display!\n");
        al_destroy_timer(timer);
        return -1;
    }

    bouncer = al_create_bitmap(BOUNCER_SIZE_X,BOUNCER_SIZE_Y);

    if(!bouncer) {
        fprintf(stderr, "failed to create bouncer bitmap!\n");
        al_destroy_display(display);
        al_destroy_timer(timer);
        return -1;
    }

    al_set_target_bitmap(bouncer);

    al_clear_to_color(al_map_rgb(0, 0, 0));

    al_set_target_bitmap(al_get_backbuffer(display));

    event_queue = al_create_event_queue();
    if(!event_queue) {
        fprintf(stderr, "failed to create event_queue!\n");
        al_destroy_bitmap(bouncer);
        al_destroy_display(display);
        al_destroy_timer(timer);
        return -1;
    }

    al_register_event_source(event_queue, al_get_display_event_source(display));

    al_register_event_source(event_queue, al_get_timer_event_source(timer));

    al_register_event_source(event_queue, al_get_keyboard_event_source());

    al_clear_to_color(al_map_rgb(0,0,0));

    al_flip_display();

    al_start_timer(timer);

    while(!doexit)
    {
        ALLEGRO_EVENT ev;
        al_wait_for_event(event_queue, &ev);

        if(ev.type == ALLEGRO_EVENT_TIMER) {
            if(key[KEY_UP] && length < 15) {
                length += 1;

            }
            else if(length > 0) {
                length -= 0.1;
            }

            if(key[KEY_DOWN] && length > 0) {
                length -= 1;
            }

            if(key[KEY_LEFT]) {
                angle = (angle - 0.1);
            }

            if(key[KEY_RIGHT]) {
                angle = (angle + 0.1);
            }

            if(key[KEY_SPACE]) {



            }

            vel_x = length * cos(angle);
            vel_y = length * sin(angle);
            bouncer_x += vel_x;
            bouncer_y += vel_y;

            redraw = true;
        }


        else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
            break;
        }
        else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) {
            switch(ev.keyboard.keycode) {
            case ALLEGRO_KEY_UP:
                key[KEY_UP] = true;
                break;

            case ALLEGRO_KEY_DOWN:
                key[KEY_DOWN] = true;
                break;

            case ALLEGRO_KEY_LEFT:
                key[KEY_LEFT] = true;
                break;

            case ALLEGRO_KEY_RIGHT:
                key[KEY_RIGHT] = true;
                break;
            case ALLEGRO_KEY_SPACE:
                key[KEY_SPACE] = true;
                break;
            }
        }
        else if(ev.type == ALLEGRO_EVENT_KEY_UP) {
            switch(ev.keyboard.keycode) {
            case ALLEGRO_KEY_UP:
                key[KEY_UP] = false;
                break;

            case ALLEGRO_KEY_DOWN:
                key[KEY_DOWN] = false;
                break;

            case ALLEGRO_KEY_LEFT:
                key[KEY_LEFT] = false;
                break;

            case ALLEGRO_KEY_RIGHT:
                key[KEY_RIGHT] = false;
                break;

            case ALLEGRO_KEY_SPACE:
                key[KEY_SPACE] = false;
                break;

            case ALLEGRO_KEY_ESCAPE:
                doexit = true;
                break;
            }
        }

        if(redraw && al_is_event_queue_empty(event_queue)) {
            redraw = false;

            al_clear_to_color(al_map_rgb(240,240,240));

            al_draw_rotated_bitmap(bouncer, BOUNCER_SIZE_X / 2, BOUNCER_SIZE_Y / 2, bouncer_x, bouncer_y, angle, angle);




            al_flip_display();
        }
    }

    al_destroy_bitmap(bouncer);
    al_destroy_timer(timer);
    al_destroy_display(display);
    al_destroy_event_queue(event_queue);

    return 0;
}
Example #26
0
void RenderTarget::drawBitmap(ALLEGRO_BITMAP *r, float x, float y, float rot) {
	setAsCurrent();
	convertCoords(x, y);
	al_draw_rotated_bitmap(r, al_get_bitmap_width(r) * 0.5f, al_get_bitmap_height(r) * 0.5f, x, y, rot, 0);
}
Example #27
0
void DebugClass::draw(){
    al_draw_rotated_bitmap(this->frameImage, this->width/2, this->height/2, this->posX+this->width/2+cameraOffsetX, this->posY+this->height/2+cameraOffsetY, this->angle, NULL);
}
Example #28
0
void Blood_Head::Draw()
{
	//al_draw_rotated_bitmap(image,5,8,Transformer::TranslateCameraX(x), Transformer::TranslateCameraY(y),direction*PI/180.0,0);
	al_draw_rotated_bitmap(image,5,8,x,y,direction*PI/180.0,0);
}
Example #29
0
void Asteroid::render(int offx, int offy)
{
    al_draw_rotated_bitmap(bitmap, radius, radius, offx + x, offy + y, angle, 0);
}
Example #30
0
void RallyX::run_game()
{
	int player_x = 25;		// player co-ords on the map
	int player_y = 5;


	bool done = false;
	bool redraw = false;
	bool keys[4] = {false, false, false, false};
	bool player_movement[4] = {false, false, false, false};

	bitset<4> next_move ("0001");			// for movement; needs refinement...almost there tho...couple of hours...
	bitset<4> current_move ("0000");
	//keys = player_movement;

	int pos_x = 0;		// allows movement pixel wise, before changing position on the grid
	bitset<4> surrounding ("0000");

	int pos_y = 0;		// so movement is not jumpy by tile size

	int speed = 5;		// speed of movement between grid change



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

	// try to create checkpoints at random points, with a total num of 10
	// 10 is declared at the top of this file
	// this for-loop instantiate checkpoints and put them into a vector of checkpoints
	// while updating tiled_map1 by modifying _game_map to

	// still need to do: 
	// 1. destructors are called more than it's supposed to i.e. 9 times???
	// 2. try figure out a way to not let vector go out of bounds when destroying the last element
	// 3. _although make tiled_map1 = _game_map.get_map() in the end, map is still not updated??? i.e. still have checkpoint everywhere

	

	while (all_checkpoints.size() < num_of_checkpoints)							//to make sure always generate num_of_checkpoints
	{
		int col = rand()%(tiled_map1.size()-1);
		int row = rand()%(tiled_map1[col].size()-1);

		if (tiled_map1[col][row] == 1)
		{
			Checkpoint newCheckpoint(col, row);
			all_checkpoints.push_back(newCheckpoint);
			_game_map.add_checkpoints(col, row);
			//_game_map.delete_checkpoints(col,row);
		}
	}
	
	int added_rocks = 0;

	while (num_of_rocks > added_rocks)										
	{
		int col = rand()%(tiled_map1.size()-1);
		int row = rand()%(tiled_map1[col].size()-1);
		cout << "add rock!" << endl;

		if (tiled_map1[col][row] == 1)
		{
			Rock newRock(col, row);
			_game_map.add_rocks(col, row);
			//_game_map.delete_rocks(col,row);
			added_rocks ++;
		}
		
	}

	tiled_map1 = _game_map.get_map();									// HAVE TO KEEP ON UPDATING tiled_map1 otherwise new info cannot be loaded

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


	while(!done)
	{

		ALLEGRO_EVENT ev;
		al_wait_for_event(resources.event_queue, &ev);

		if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			next_move.reset();
			switch(ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_UP:
				next_move[UP] = true;
				break;
			case ALLEGRO_KEY_RIGHT:
				next_move[RIGHT] = true;
				break;
			case ALLEGRO_KEY_DOWN:
				next_move[DOWN] = true;
				break;
			case ALLEGRO_KEY_LEFT:
				next_move[LEFT] = true;
				break;
			}
		}

		surrounding[UP] =  tiled_map1[player_y - 1][player_x];		// must change so that a implementation of a 2d vector is unknown
		surrounding[RIGHT] =  tiled_map1[player_y][player_x + 1];
		surrounding[DOWN] =  tiled_map1[player_y + 1][player_x];
		surrounding[LEFT] =  tiled_map1[player_y][player_x - 1];

		if (pos_y == 0 && pos_x == 0)
		{
			/*if (next_move.none())
			{
				if ((current_move & ~(surrounding)).none())
					current_move >>=1;

			}
			else*/
			{
				current_move = next_move & surrounding; 
				//next_move.reset();
			}
		}


		if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			done = true;
		}
		else if(ev.type == ALLEGRO_EVENT_TIMER)
		{
			pos_y += current_move[UP] * speed;		// if no movement will equal 0
			pos_y -= current_move[DOWN]  * speed;
			pos_x += current_move[LEFT]   * speed;
			pos_x -= current_move[RIGHT]  * speed;

			if (pos_y <= -(tile_size))		
			{
				pos_y = 0;
				player_y++;		// increase player on grid if movement between is the distance of the grid
			}
			else if (pos_y >= (tile_size))
			{
				pos_y = 0;
				player_y--;
			} 

			if (pos_x <= -(tile_size))
			{
				pos_x = 0;
				player_x++;
			}
			else if (pos_x >= (tile_size))
			{
				pos_x = 0;
				player_x--;
			} 

			redraw = true;
		}

		if(redraw && al_is_event_queue_empty(resources.event_queue))
		{
			redraw = false;

			al_clear_to_color(al_map_rgb(0,0,0));
			

			for (int irow = -1; irow != tiles_per_display + 1; irow++)		// always 17; due to viewport size and one extra on either side
			{
				for (int icol = -1; icol != tiles_per_display + 1; icol++) 
				{
					if ((player_y - 7 + irow < out_of_bounds_map) || (player_x - 7 + icol < out_of_bounds_map) ) 
					{
						al_draw_bitmap(_bitmaps.out_of_bounds, (icol * tile_size) + pos_x , (irow * tile_size) + pos_y, 0);		// draw bitmap with co-ordintes locked to the grid co-ords as well as distance traveled
					}
					else if (tiled_map1[player_y - 7 + irow][player_x - 7 + icol] == road_map)
					{
						al_draw_bitmap(_bitmaps.road, (icol * tile_size) + pos_x , (irow * tile_size) + pos_y, 0);
					}
					////////////////////////////////I PUT STUFF HERE///////////////////////////////////////////////////////
					else if(tiled_map1[player_y - 7 + irow][player_x - 7 + icol] == checkpoint_map)
					{
						al_draw_bitmap(_bitmaps.checkpoint, (icol * tile_size) + pos_x , (irow * tile_size) + pos_y, 0);
					}
					else if(tiled_map1[player_y - 7 + irow][player_x - 7 + icol] == rock_map)
					{
						al_draw_bitmap(_bitmaps.rock, (icol * tile_size) + pos_x , (irow * tile_size) + pos_y, 0);
					}
					
					////////////////////////////////I PUT STUFF HERE///////////////////////////////////////////////////////
					else
						al_draw_bitmap(_bitmaps.wall,(icol * tile_size) + pos_x, (irow * tile_size) + pos_y, 0);

				}

			}

			float pi = 3.1415926;
			al_draw_bitmap(_bitmaps.player, (7 * tile_size) , (7 * tile_size), 0);		// draw player car ( always in this position due to centered)
			al_draw_rotated_bitmap(_bitmaps.player, tile_size/2, tile_size/2, (7 * tile_size) , (7 * tile_size), pi, 0);		// draw player car ( always in this position due to centered)


			// if checkpoint is at the middle of the screen, call destroy_checkpoint
			// which calls the destructor, update the map and let player go one step closer to winning the game
			//for (int i = 0; i<Map::all_checkpoints.size(); i++)
			//{
			//	if (Map::all_checkpoints.)
			//}

			draw_info_board();

			al_flip_display();
		}
	}


}