Quantcast
Channel: Últimos conteúdos
Viewing all articles
Browse latest Browse all 14190

como fazer para a imagem do fundo ficar atras da imagem do personagem

$
0
0

O código

 

#include <allegro5\allegro.h>
#include <allegro5\allegro_native_dialog.h>
#include <allegro5\allegro_image.h>
#include <time.h>
 
const float FPS = 60;
const int SCREEN_W = 640;
const int SCREEN_H = 480;
const int BLUE = 34;
const int COORENDO = 34;
 
enum TECLADO { KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT };
 
int main()
{
//_______VARIAVEIS DO JOGO________
 
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_BITMAP *Blue = NULL;
ALLEGRO_BITMAP *Fundo = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
ALLEGRO_TIMER *timer = NULL;
 
float bouncer_x = SCREEN_W / 2.0 - BLUE / 2.0;
float bouncer_y = SCREEN_H / 2.0 - BLUE / 2.0;
bool key[4] = { false, false, false, false };
bool redraw = true;
bool doexit = false;
 
//________INICIALIZAÇÃO DO ALLEGRO 5__________
if (!al_init()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize allegro!",
NULL, ALLEGRO_MESSAGEBOX_ERROR);
return 0;
}
 
if (!al_init_image_addon()) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_image_addon!",
NULL, ALLEGRO_MESSAGEBOX_ERROR);
return 0;
}
 
display = al_create_display(800, 600);
 
if (!display) {
al_show_native_message_box(display, "Error", "Error", "Failed to initialize display!",
NULL, ALLEGRO_MESSAGEBOX_ERROR);
return 0;
}
 
Blue = al_load_bitmap("Blue.bmp");
 
if (!Blue) {
al_show_native_message_box(display, "Error", "Error", "Failed to load image!",
NULL, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return 0;
}
 
Teste = al_load_bitmap("teste.png");
 
if (!Teste) {
al_show_native_message_box(display, "Error", "Error", "Failed to load image!",
NULL, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return 0;
}
 
event_queue = al_create_event_queue();
 
if (!event_queue) {
al_show_native_message_box(display, "Error", "Error", "Failed to create event_queue!",
NULL, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return 0;
}
 
timer = al_create_timer(1.0 / FPS);
 
if (!timer) {
al_show_native_message_box(display, "Error", "Error", "failed to create timer!",
NULL, ALLEGRO_MESSAGEBOX_ERROR);
al_destroy_display(display);
return 0;
}
 
al_set_target_bitmap(al_get_backbuffer(display));
 
//______INSTALAÇÃO________
al_install_keyboard();
 
//________REGISTRO___________
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_flip_display();
 
al_start_timer(timer);
 
//_________LOOP PRINCIPAL__________
 
while (!doexit)
{
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev);
 
if (ev.type == ALLEGRO_EVENT_TIMER) {
if (key[KEY_UP] && bouncer_y >= 4.0) {
bouncer_y -= 4.0;
}
 
if (key[KEY_DOWN] && bouncer_y <= SCREEN_H - BLUE - 4.0) {
bouncer_y += 4.0;
}
 
if (key[KEY_LEFT] && bouncer_x >= 4.0) {
bouncer_x -= 4.0;
}
 
if (key[KEY_RIGHT] && bouncer_x <= SCREEN_W - BLUE - 4.0) {
bouncer_x += 4.0;
}
 
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_W:
key[KEY_UP] = true;
break;
 
case ALLEGRO_KEY_S:
key[KEY_DOWN] = true;
break;
 
case ALLEGRO_KEY_A:
key[KEY_LEFT] = true;
break;
 
case ALLEGRO_KEY_D:
key[KEY_RIGHT] = true;
break;
}
}
else if (ev.type == ALLEGRO_EVENT_KEY_UP) {
switch (ev.keyboard.keycode) {
case ALLEGRO_KEY_W:
key[KEY_UP] = false;
break;
 
case ALLEGRO_KEY_S:
key[KEY_DOWN] = false;
break;
 
case ALLEGRO_KEY_A:
key[KEY_LEFT] = false;
break;
 
case ALLEGRO_KEY_D:
key[KEY_RIGHT] = 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(255, 255, 255));
 
al_draw_bitmap(Blue, bouncer_x, bouncer_y, 0);
 
al_flip_display();
 
al_draw_bitmap(Fundo, 0, 0, 0);
 
al_flip_display();
}
}
 
while (1);
 
//________DESTRUIR_________
al_destroy_display(display);
al_destroy_bitmap(Blue);
al_destroy_bitmap(Fundo);
al_destroy_event_queue(event_queue);
al_destroy_timer(timer);
 
return 0;
}

Viewing all articles
Browse latest Browse all 14190

Trending Articles