/** Draws part of this bitmap onto the target bitmap. @param sx source x position. @param sy source y position. @param sw source width. @param sh source height. @param dx target horizontal position. @param dy target vertical position. @param flags flags. */ void draw(float sx, float sy, float sw, float sh, float dx, float dy, int flags = 0) const { al_draw_bitmap_region(get(), sx, sy, sw, sh, dx, dy, flags); }
static void draw(void) { float x, y; int cx, cy, cw, ch; int w = al_get_bitmap_width(ex.zoom); int h = al_get_bitmap_height(ex.zoom); ALLEGRO_BITMAP *screen = al_get_target_bitmap(); ALLEGRO_BITMAP *mem; int rects_num = 16, i, j; float rects[16 * 4]; for (j = 0; j < 4; j++) { for (i = 0; i < 4; i++) { rects[(j * 4 + i) * 4 + 0] = 2 + i * 0.25 + i * 7; rects[(j * 4 + i) * 4 + 1] = 2 + j * 0.25 + j * 7; rects[(j * 4 + i) * 4 + 2] = 2 + i * 0.25 + i * 7 + 5; rects[(j * 4 + i) * 4 + 3] = 2 + j * 0.25 + j * 7 + 5; } } al_get_clipping_rectangle(&cx, &cy, &cw, &ch); al_clear_to_color(ex.background); set_xy(8, 0); print("Drawing %s (press SPACE to change)", names[ex.what]); set_xy(8, 16); print("Original"); set_xy(80, 16); print("Enlarged x 16"); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); if (ex.software) { al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); al_set_new_bitmap_format(al_get_bitmap_format(al_get_target_bitmap())); mem = al_create_bitmap(w, h); al_set_target_bitmap(mem); x = 0; y = 0; } else { mem = NULL; x = 8; y = 40; } al_draw_bitmap(ex.pattern, x, y, 0); /* Draw the test scene. */ al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); for (i = 0; i < rects_num; i++) { ALLEGRO_COLOR rgba = ex.foreground; rgba.a *= 0.5; primitive( x + rects[i * 4 + 0], y + rects[i * 4 + 1], x + rects[i * 4 + 2], y + rects[i * 4 + 3], rgba, false); } al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); if (ex.software) { al_set_target_bitmap(screen); x = 8; y = 40; al_draw_bitmap(mem, x, y, 0); al_destroy_bitmap(mem); } /* Grab screen contents into our bitmap. */ al_set_target_bitmap(ex.zoom); al_draw_bitmap_region(screen, x, y, w, h, 0, 0, 0); al_set_target_bitmap(screen); /* Draw it enlarged. */ x = 80; y = 40; al_draw_scaled_bitmap(ex.zoom, 0, 0, w, h, x, y, w * 16, h * 16, 0); /* Draw outlines. */ for (i = 0; i < rects_num; i++) { primitive( x + rects[i * 4 + 0] * 16, y + rects[i * 4 + 1] * 16, x + rects[i * 4 + 2] * 16, y + rects[i * 4 + 3] * 16, ex.outline, true); } set_xy(8, 640 - 48); print("Thickness: %d (press T to change)", ex.thickness); print("Drawing with: %s (press S to change)", ex.software ? "software" : "hardware"); print("Supersampling: %dx (edit ex_draw.ini to change)", ex.samples); // FIXME: doesn't work // al_get_display_option(ALLEGRO_SAMPLE_BUFFERS)); }
void Level::draw() { al_draw_bitmap(background_, 0, 0, 0); //drawing hearts int i = 0; while(i < 2 * bunny_->hearts_) { if (bunny_->hp_-i >= 2) { al_draw_bitmap_region(hearts_,39,0,39,35,525+i*45/2,8,0); } else if (bunny_->hp_-i == 1) { al_draw_bitmap_region(hearts_,0,0,39,35,525+i*45/2,8,0); } else { al_draw_bitmap_region(hearts_,78,0,39,35,525+i*45/2,8,0); } i+=2; } // drawing numbers if (bunny_->coins_>=10) { al_draw_bitmap_region(numbers_,(bunny_->coins_/10)*25,0,25,35,160,10,0); al_draw_bitmap_region(numbers_,(bunny_->coins_ % 10)*25,0,25,35,185,10,0); } else al_draw_bitmap_region(numbers_,(bunny_->coins_ % 10)*25,0,25,35,160,10,0); if (bunny_->bombs_>=10) { al_draw_bitmap_region(numbers_,(bunny_->bombs_/10)*25,0,25,35,260,10,0); al_draw_bitmap_region(numbers_,(bunny_->bombs_ % 10)*25,0,25,35,285,10,0); } else al_draw_bitmap_region(numbers_,(bunny_->bombs_ % 10)*25,0,25,35,260,10,0); if (bunny_->keys_>=10) { al_draw_bitmap_region(numbers_,(bunny_->keys_/10)*25,0,25,35,360,10,0); al_draw_bitmap_region(numbers_,(bunny_->keys_ % 10)*25,0,25,35,385,10,0); } else al_draw_bitmap_region(numbers_,(bunny_->keys_ % 10)*25,0,25,35,360,10,0); currentRoom_->draw(); }
void gui_draw() { // If we were asked to redraw everything, redraw the background as well if (gui.info.must_redraw == TRUE) gui_draw_background(); al_set_target_bitmap(gui_buffer); for (int i = gui.boxes_count - 1; i >= 0; i--) { t_gui_box* b = gui.boxes_z_ordered[i]; const t_frame bb = b->frame; const v2i bb_min = bb.GetMin(); const v2i bb_max = bb.GetMax(); if (!(b->flags & GUI_BOX_FLAGS_ACTIVE)) continue; // Draw widgets for (t_list* widgets = b->widgets; widgets != NULL; widgets = widgets->next) { t_widget *w = (t_widget *)widgets->elem; if (w->enabled && w->type != WIDGET_TYPE_CLOSEBOX) if (w->redraw_func != NULL) w->redraw_func(w); } // Blit content switch (b->type) { case GUI_BOX_TYPE_STANDARD: al_set_target_bitmap(gui_buffer); al_draw_bitmap_region(b->gfx_buffer, 0, 0, bb.size.x + 1, bb.size.y + 1, bb.pos.x, bb.pos.y, 0x0000); break; case GUI_BOX_TYPE_GAME: gamebox_draw(b, screenbuffer); break; } // Draw borders al_set_target_bitmap(gui_buffer); gui_rect(LOOK_ROUND, bb.pos.x - 2, bb.pos.y - 20, bb.pos.x + bb.size.x + 2, bb.pos.y + bb.size.y + 2, COLOR_SKIN_WINDOW_BORDER); al_draw_line(bb.pos.x, bb.pos.y - 1.5f, bb.pos.x + bb.size.x + 1, bb.pos.y - 1.5f, COLOR_SKIN_WINDOW_BORDER, 0); al_draw_line(bb.pos.x, bb.pos.y - 0.5f, bb.pos.x + bb.size.x + 1, bb.pos.y - 0.5f, COLOR_SKIN_WINDOW_BORDER, 0); // Draw resize widget (invisible for game window) if (b->flags & GUI_BOX_FLAGS_ALLOW_RESIZE) { const bool is_resizing = (gui.mouse.focus == GUI_FOCUS_BOX && gui.mouse.focus_box == b && gui.mouse.focus_is_resizing); if (b->type != GUI_BOX_TYPE_GAME || is_resizing) { const int sz = 9; // display size is 9, interaction is 12 const ALLEGRO_COLOR color = is_resizing ? COLOR_SKIN_WINDOW_TEXT_HIGHLIGHT : COLOR_SKIN_WINDOW_TITLEBAR_TEXT_UNACTIVE; al_draw_filled_triangle(bb_max.x+2, bb_max.y+2, bb_max.x+2-sz, bb_max.y+2, bb_max.x+2, bb_max.y+2-sz, color); } } // Draw title bar { t_frame titlebar_frame; titlebar_frame.pos.x = bb.pos.x; titlebar_frame.pos.y = bb.pos.y - 18; titlebar_frame.size.x = bb.size.x; titlebar_frame.size.y = 15; SkinGradient_DrawHorizontal(&Skins_GetCurrentSkin()->gradient_window_titlebar, gui_buffer, &titlebar_frame); // Draw title bar text, with wrapping // Is window the focused one? const ALLEGRO_COLOR color = (i == 0) ? COLOR_SKIN_WINDOW_TITLEBAR_TEXT : COLOR_SKIN_WINDOW_TITLEBAR_TEXT_UNACTIVE; Font_SetCurrent(FONTID_LARGE); if (Font_TextWidth(FONTID_CUR, b->title) <= (bb.size.x - 8)) { Font_Print (FONTID_CUR, b->title, bb.pos.x + 4, bb.pos.y - 17, color); } else { // FIXME-OPT: shit code. char title[256]; int len = strlen(b->title); strcpy(title, b->title); while (Font_TextWidth(FONTID_CUR, title) > (bb.size.x - 17)) title[--len] = EOSTR; strcat(title, ".."); Font_Print(FONTID_CUR, title, bb.pos.x + 4, bb.pos.y - 17, color); } // Draw widgets for (t_list* widgets = b->widgets; widgets != NULL; widgets = widgets->next) { t_widget *w = (t_widget *)widgets->elem; if (w->enabled && w->type == WIDGET_TYPE_CLOSEBOX) if (w->redraw_func != NULL) w->redraw_func(w); } } } // Redraw menus on top of the desktop gui_redraw_menus(); // Update applets that comes after the redraw gui_update_applets_after_redraw(); // Clear global redrawing flag and makes mouse reappear gui.info.must_redraw = FALSE; }
int main(void){ // don't forget to put allegro-5.0.10-monolith-md-debug.lib int width = 640; int height = 480; bool done = false; Sprite dragon; dragon.x = width/2; dragon.y = height/2; dragon.velX = 5; dragon.velY = 0; dragon.dirX = -1; //will move from the right end of screen to left end of screen dragon.dirY = 0; dragon.maxFrame = 8; dragon.curFrame = 0; dragon.frameCount = 0; dragon.frameDelay = 5; dragon.frameWidth=128; dragon.frameHeight =128; dragon.animationColumns = 8; dragon.animationDirection = 1; //allegro variable ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *eventQueue = NULL; ALLEGRO_TIMER *timer; ALLEGRO_BITMAP *image; //check if allegro is initialised <allegro_native_dialog.h> if(!al_init()){ return -1; } display = al_create_display(width,height); //check if display was created if(!display){ return -1; } al_install_keyboard();// will initialize keyboard events al_init_image_addon(); image = al_load_bitmap("spritesheet_demo.bmp"); al_convert_mask_to_alpha(image, al_map_rgb(106,76,48)); dragon.image = image; eventQueue = al_create_event_queue(); timer = al_create_timer(1.0 / 60); al_register_event_source(eventQueue, al_get_timer_event_source(timer)); al_register_event_source(eventQueue, al_get_keyboard_event_source()); al_start_timer(timer); while(!done){ ALLEGRO_EVENT ev; al_wait_for_event(eventQueue, &ev); // tells the eventQueue wait for an input if (ev.type==ALLEGRO_EVENT_KEY_DOWN){ switch(ev.keyboard.keycode){ case ALLEGRO_KEY_ESCAPE: done = true; break; case ALLEGRO_KEY_LEFT: dragon.animationDirection = 1; // dragon.dirX = - 1; break; case ALLEGRO_KEY_RIGHT: dragon.animationDirection = -1; // dragon.dirX = 1; break; case ALLEGRO_KEY_DOWN: break; case ALLEGRO_KEY_UP: break; } } else if (ev.type == ALLEGRO_EVENT_TIMER){ if(++dragon.frameCount >= dragon.frameDelay){ dragon.curFrame += dragon.animationDirection; if(dragon.curFrame >= dragon.maxFrame){ dragon.curFrame = 0; } else if (dragon.curFrame <= 0){ dragon.curFrame = dragon.maxFrame - 1; } dragon.frameCount=0; } dragon.x += dragon.velX * dragon.dirX; if (dragon.x <= 0 - dragon.frameWidth){ dragon.x = width; } else if (dragon.x > width){ dragon.x = 0 - dragon.frameWidth; } } //make sure when exiting the program exit with esc button /* else if (ev.type == ALLEGRO_EVENT_KEY_UP){ if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE){ done = true; break; } } */ /* the below will create the sprite sheet image = the sprite sheet sx = the size x starting point of sprite sheet i.3 0 to 128 pixels, so that's why we're multipliyng it by curFrame which will add ++ each frame sy = the size y starting point of sprite sheet sw = how width is the image sh = how tall is the image dx = where it is gonna put x dy = where it is gonna put y */ al_draw_bitmap_region(dragon.image, dragon.curFrame * dragon.frameWidth,0, dragon.frameWidth, dragon.frameHeight, dragon.x,dragon.y,0); al_flip_display(); al_clear_to_color(al_map_rgb(0,0,0)); //that prevents the filled rectangle draw imga just like snake style } //al_rest(5.0); /* for (int i = 0; i < maxFrame; i++) { al_destroy_bitmap(image[i]); } */ al_destroy_bitmap(image); al_destroy_event_queue(eventQueue); al_destroy_display(display); al_destroy_timer(timer); //hey return 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; }
//lecture10 slide30 void Sprite::Display(Bitmap dest) { Rect visibleArea; al_draw_bitmap_region(currFilm->GetBitmap(), frameBox.GetX(), frameBox.GetY(), frameBox.GetWidth(), frameBox.GetHeight(), x, y, NULL); }
int main(void) { int X_ROOMS=13; int Y_ROOMS=16; int X_ROOM_SIZE=256; int Y_ROOM_SIZE=128; int SCALE_FACTOR=4; int X_TILE_SIZE=8; int Y_TILE_SIZE=8; int LAST_OBJECT=0; int actid=0; int error=0; ALLEGRO_CONFIG *cfg; ALLEGRO_BITMAP *bmp,*virt,*tmp=NULL; ALLEGRO_DISPLAY *display; ALLEGRO_KEYBOARD_STATE key; ALLEGRO_FONT *font; signed int xcursor=0; signed int ycursor=0; signed char x=0; signed char y=0; signed char finex=0; signed char finey=0; char finish=0; ALLEGRO_COLOR black,white,red,color; int scale_cursor_x=0; int scale_cursor_y=0; int i=0; int a=0; unsigned char r,g,b=0; char pngfilename[20]; char *tmpbuf; char buf[5]; char buf2[5]; /* Iniciar el rollo */ tmpbuf=(char *)malloc(sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE); memset(tmpbuf,0,sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE); al_init(); al_init_image_addon(); al_init_primitives_addon(); al_init_font_addon(); al_init_ttf_addon(); cfg=al_load_config_file("sacagraf.cfg"); if (cfg==NULL) { cfg=al_create_config(); al_add_config_section(cfg,"Ajustes"); al_add_config_section(cfg,"Objetos"); al_set_config_value(cfg,"Ajustes","Habitaciones en horizontal","13"); al_set_config_value(cfg,"Ajustes","Habitaciones en vertical","16"); al_set_config_value(cfg,"Ajustes","Ancho de la habitacion original en pixels","256"); al_set_config_value(cfg,"Ajustes","Alto de la habitacion original en pixels","128"); al_set_config_value(cfg,"Ajustes","Ancho minimo del caracter original","8"); al_set_config_value(cfg,"Ajustes","Alto minimo del caracter original","8"); al_set_config_value(cfg,"Ajustes","Factor de escalado","4"); al_set_config_value(cfg,"Objetos","Ultimo","0"); al_save_config_file("sacagraf.cfg",cfg); } X_ROOMS=atoi(al_get_config_value(cfg,"Ajustes","Habitaciones en horizontal")); Y_ROOMS=atoi(al_get_config_value(cfg,"Ajustes","Habitaciones en vertical")); X_ROOM_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Ancho de la habitacion original en pixels")); Y_ROOM_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Alto de la habitacion original en pixels")); SCALE_FACTOR=atoi(al_get_config_value(cfg,"Ajustes","Factor de escalado")); X_TILE_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Alto minimo del caracter original")); Y_TILE_SIZE=atoi(al_get_config_value(cfg,"Ajustes","Ancho minimo del caracter original")); LAST_OBJECT=atoi(al_get_config_value(cfg,"Objetos","Ultimo")); actid=LAST_OBJECT; al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED); display=al_create_display(X_ROOM_SIZE*SCALE_FACTOR,192*SCALE_FACTOR); bmp=al_load_bitmap("map.png"); virt=al_create_bitmap(X_ROOM_SIZE*SCALE_FACTOR,Y_ROOM_SIZE*SCALE_FACTOR); font=al_load_ttf_font("proggy.ttf",6*SCALE_FACTOR,0); al_install_keyboard(); black=al_map_rgb(0,0,0); white=al_map_rgba_f(1,1,1,1); red=al_map_rgba_f(1,0,0,0.7); /* Que empiece la fiesta */ while(!finish) { al_get_keyboard_state(&key); if (al_key_down(&key,ALLEGRO_KEY_ESCAPE)) { finish=1; } if (al_key_down(&key,ALLEGRO_KEY_LCTRL)) { finex=0; finey=0; if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { x++; if (x==X_ROOMS) x=X_ROOMS-1; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { x--; if (x<0) x=0; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { y--; if (y<0) y=0; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { y++; if (y>Y_ROOMS-1) y=Y_ROOMS-1; } } else if (al_key_down(&key,ALLEGRO_KEY_LSHIFT)) { if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { finex++; if (finex>X_TILE_SIZE) finex=X_TILE_SIZE; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { finex--; if (finex<-X_TILE_SIZE) finex=-X_TILE_SIZE; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { finey--; if (finey<-Y_TILE_SIZE) finey=-Y_TILE_SIZE; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { finey++; if (finey>Y_TILE_SIZE) finey=Y_TILE_SIZE; } } else if (al_key_down(&key,ALLEGRO_KEY_ALT)) { if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { scale_cursor_x++; //if (finex>8) finex=8; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { scale_cursor_x--; //if (finex<0) finex=0; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { scale_cursor_y--; //if (finey<0) finey=0; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { scale_cursor_y++; //if (finey>8) finey=8; } } else { if (al_key_down(&key,ALLEGRO_KEY_RIGHT)) { xcursor+=X_TILE_SIZE*SCALE_FACTOR; } if (al_key_down(&key,ALLEGRO_KEY_LEFT)) { xcursor-=X_TILE_SIZE*SCALE_FACTOR; } if (al_key_down(&key,ALLEGRO_KEY_UP)) { ycursor-=Y_TILE_SIZE*SCALE_FACTOR; } if (al_key_down(&key,ALLEGRO_KEY_DOWN)) { ycursor+=Y_TILE_SIZE*SCALE_FACTOR; } } al_clear_to_color(black); al_set_target_bitmap(virt); //al_set_blender(ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA,white); al_draw_bitmap_region(bmp,0+(x*X_ROOM_SIZE)+finex,0+(y*Y_ROOM_SIZE)+finey,X_ROOM_SIZE,Y_ROOM_SIZE,0,0,0); al_set_target_bitmap(al_get_backbuffer(display)); al_draw_scaled_bitmap(virt,0,0,X_ROOM_SIZE,Y_ROOM_SIZE,0,0,X_ROOM_SIZE*SCALE_FACTOR,Y_ROOM_SIZE*SCALE_FACTOR,0); al_draw_line(0,512,1024,512,white,0); al_draw_textf(font,al_map_rgba(200,200,200,200),0,520,0,"mapa x: %d mapa y: %d habitacion nº: %d ajuste fino x: %d ajuste fijo y: %d",x,y,x+(y*13),finex,finey); if (error) { al_draw_textf(font,al_map_rgba(200,200,200,200),0,540,0,"Patron repetido"); al_flip_display(); al_rest(1); error=0; } if (al_key_down(&key,ALLEGRO_KEY_ENTER)) { tmp=al_create_bitmap((X_TILE_SIZE*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x),(Y_TILE_SIZE*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)); al_set_target_bitmap(tmp); al_draw_bitmap_region(al_get_backbuffer(display),xcursor,ycursor,(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x)+(X_TILE_SIZE*SCALE_FACTOR),(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)+(Y_TILE_SIZE*SCALE_FACTOR),0,0,0); memset(tmpbuf,0,sizeof(char)*X_ROOM_SIZE*Y_ROOM_SIZE); memset(buf,0,5); for (i=0;i<(Y_TILE_SIZE*scale_cursor_y*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR);i+=SCALE_FACTOR) { for (a=0;a<(X_TILE_SIZE*scale_cursor_x*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR);a+=SCALE_FACTOR) { color=al_get_pixel(tmp,a,i); al_unmap_rgb(color,&r,&g,&b); if (!r && !g && !b) { strcat(tmpbuf,"0"); } else { strcat(tmpbuf,"1"); } } } /* Ya está la secuencia del gráfico en tmpbuf, examinamos todas las secuencias anteriores */ error=0; for (i=0;i<actid;i++) { memset(buf2,0,5); sprintf(buf2,"%d",i); if (!strcmp(al_get_config_value(cfg,"Objetos",buf2),tmpbuf)) { error=i; } } /* Si no hay secuencias repetidas lo grabamos */ if (!error) { sprintf(buf,"%d",actid); al_set_config_value(cfg,"Objetos",buf,tmpbuf); memset(pngfilename,0,20); sprintf(pngfilename,"dec%d.png",actid); al_save_bitmap(pngfilename,tmp); actid++; } al_destroy_bitmap(tmp); } al_set_target_bitmap(al_get_backbuffer(display)); //al_set_blender(ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA,red); al_draw_filled_rectangle(xcursor,ycursor,xcursor+((X_TILE_SIZE*SCALE_FACTOR)+(X_TILE_SIZE*SCALE_FACTOR*scale_cursor_x)),ycursor+((Y_TILE_SIZE*SCALE_FACTOR)+(Y_TILE_SIZE*SCALE_FACTOR*scale_cursor_y)),red); al_flip_display(); al_rest(0.1); } memset(buf,0,5); sprintf(buf,"%d",actid); al_set_config_value(cfg,"Objetos","Ultimo",buf); al_save_config_file("sacagraf.cfg",cfg); al_destroy_font(font); al_uninstall_keyboard(); al_destroy_bitmap(bmp); al_destroy_bitmap(virt); al_destroy_display(display); al_destroy_config(cfg); al_shutdown_ttf_addon(); al_shutdown_font_addon(); al_shutdown_image_addon(); al_shutdown_primitives_addon(); free(tmpbuf); return 0; }
int main(int argc, char **argv) { al_init(); al_init_image_addon(); al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP | ALLEGRO_NO_PREMULTIPLIED_ALPHA); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); ALLEGRO_BITMAP *tilemap = al_load_bitmap(argv[1]); ALLEGRO_BITMAP *result = al_create_bitmap(1024, 1024); al_set_target_bitmap(result); al_clear_to_color(al_map_rgba(0, 0, 0, 0)); int tx = 0, ty = 0; int mx = 0, my = 0; int mapping[(512/16)*(2048/16)]; memset(mapping, 0, sizeof(mapping)); int i = 0; mapping[i++] = 0; mx = 16; for (int y = 0; y < 2048/16; y++) { int x; if (y == 0) x = 1; else x = 0; for (; x < 512/16; x++) { // 1 == skip first alpha img int ox = x * 16; int oy = y * 16; bool all_alpha = true; // FIXME: tile index 96 is all alpha and still in the packed.png. keep for legacy reasons. if (i == 96) { all_alpha = false; } else { for (int py = 0; py < 16; py++) { for (int px = 0; px < 16; px++) { ALLEGRO_COLOR pix = al_get_pixel(tilemap, px+ox, py+oy); unsigned char r, g, b, a; al_unmap_rgba(pix, &r, &g, &b, &a); if (!(a == 0)) { all_alpha = false; break; } } if (!all_alpha) break; } } if (!all_alpha) { mapping[(y*32)+x] = i++; if (ox == 0 && oy == (3*16)) { } else { al_draw_bitmap_region(tilemap, ox, oy, 16, 16, mx, my, 0); } mx += 16; if (mx == 1024) { mx = 0; my += 16; } } } } printf("int mapping[4096] = {\n\t"); for (int i = 0; i < 4096; i++) { if ((i % 10) == 0) printf(",\n\t"); else printf(", "); printf("%4d", mapping[i]); } printf("\n};\n"); al_save_bitmap("packed.png", result); }
void Tile::draw(float posx,float posy) { //const enum TILETYPE{FLOOR,WALL,DOOR,WATER,POT,CHEST,TORCH}; switch (type) { case FLOOR: al_draw_bitmap_region(myimg,mystate * 32.0f, 0, 32.0f, 32.0f,posx,posy,0); break; case WALL: al_draw_bitmap_region(myimg,mystate * 32.0f,32.0f,32.0f,32.0f,posx,posy,0); break; case DOOR: if(gridy == 12) { if(gridx == 0) { if(mystate2 == 0) { al_draw_tinted_scaled_rotated_bitmap_region(myimg,0,64.0f,32.0f,32.0f,al_map_rgb(255,255,255),16.0f,16.0f,posx + 16.0f,posy + 16.0f,1.0f,1.0f,3.14 * 0.0f / 180.0f,0); } else { al_draw_tinted_scaled_rotated_bitmap_region(myimg,32.0f,64.0f,32.0f,32.0f,al_map_rgb(255,255,255),16.0f,16.0f,posx + 16.0f,posy + 16.0f,1.0f,1.0f,3.14 * 0.0f / 180.0f,0); } } else { if(mystate2 == 0) { al_draw_tinted_scaled_rotated_bitmap_region(myimg,0,64.0f,32.0f,32.0f,al_map_rgb(255,255,255),16.0f,16.0f,posx + 16.0f,posy + 16.0f,1.0f,1.0f,3.14 * 180.0f / 180.0f,0); } else { al_draw_tinted_scaled_rotated_bitmap_region(myimg,32.0f,64.0f,32.0f,32.0f,al_map_rgb(255,255,255),16.0f,16.0f,posx + 16.0f,posy + 16.0f,1.0f,1.0f,3.14 * 180.0f/ 180.0f,0); } } } else { if(gridy == 0) { if(mystate2 == 0) { al_draw_tinted_scaled_rotated_bitmap_region(myimg,0,64.0f,32.0f,32.0f,al_map_rgb(255,255,255),16.0f,16.0f,posx + 16.0f,posy + 16.0f,1.0f,1.0f,3.14 * 270.0f/ 180.0f,0); } else { al_draw_tinted_scaled_rotated_bitmap_region(myimg,32.0f,64.0f,32.0f,32.0f,al_map_rgb(255,255,255),16.0f,16.0f,posx + 16.0f,posy + 16.0f,1.0f,1.0f,3.14 * 270.0f/ 180.0f,0); } } else { if(mystate2 == 0) { al_draw_tinted_scaled_rotated_bitmap_region(myimg,0,64.0f,32.0f,32.0f,al_map_rgb(255,255,255),16.0f,16.0f,posx + 16.0f,posy + 16.0f,1.0f,1.0f,3.14 * 90.0f / 180.0f,0); } else { al_draw_tinted_scaled_rotated_bitmap_region(myimg,32.0f,64.0f,32.0f,32.0f,al_map_rgb(255,255,255),16.0f,16.0f,posx + 16.0f,posy + 16.0f,1.0f,1.0f,3.14 * 90.0f / 180.0f,0); } } } break; case WATER: if(mystate > 32) { mystate = 0; } al_draw_bitmap_region(myimg,mystate++, 160, 32.0f, 32.0f,posx,posy,0); break; case POT: al_draw_bitmap_region(myimg,0, 0, 32.0f, 32.0f,posx,posy,0); al_draw_bitmap_region(myimg,mystate * 32.0 + 64, 64, 32.0f, 32.0f,posx,posy,0); break; case CHEST: al_draw_bitmap_region(myimg,0, 0, 32.0f, 32.0f,posx,posy,0); al_draw_bitmap_region(myimg,mystate * 32.0 + 64, 96, 32.0f, 32.0f,posx,posy,0); break; case TORCH: break; default: break; //al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); } }
void DrawPage(int p) { switch (p) { case 1: al_hold_bitmap_drawing(true); al_draw_bitmap(game->intro.table_bitmap, 0, 0, 0); al_hold_bitmap_drawing(true); draw_text(1, "Ever since Twilight Sparkle and her"); draw_text(1, "friends imprisoned Discord in stone,"); draw_text(1, "Equestria had been peaceful for"); draw_text(1, "a long time."); al_hold_bitmap_drawing(false); break; case 2: al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0, 0, 0); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0.5, 0, 0); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); draw_text(2, "Until one day a reckless pony caused"); draw_text(2, "a tiny bit of chaos near Discord’s"); draw_text(2, "statue."); al_hold_bitmap_drawing(false); break; case 3: al_hold_bitmap_drawing(true); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0, 0, 0); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0.5, 0, 0); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); draw_text(3, "This small amount of chaos was not"); draw_text(3, "enough to free Discord, but enough"); draw_text(3, "to turn discarded muffins into"); draw_text(3, "vicious muffinzombies, with aim to"); draw_text(3, "destroy all harmony in Equestria."); al_hold_bitmap_drawing(false); break; case 4: al_hold_bitmap_drawing(true); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0, 0, 0); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0.5, 0, 0); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); draw_text(4, "Discord, learning from his last failure,"); draw_text(4, "turned his muffinzombies against Twilight"); draw_text(4, "and her friends, trapping them in their"); draw_text(4, "own homes. With the bearers of the"); draw_text(4, "Elements out of the way, he now waits"); draw_text(4, "until chaos takes hold of the world,"); draw_text(4, "so he can rule Equestria once again."); al_hold_bitmap_drawing(false); break; case 5: al_hold_bitmap_drawing(true); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0, 0, 0); al_draw_bitmap_region(game->intro.table_bitmap, al_get_bitmap_width(game->intro.table_bitmap)/2, 0, al_get_bitmap_width(game->intro.table_bitmap)/2, al_get_bitmap_height(game->intro.table_bitmap), game->viewportWidth*0.5, 0, 0); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); draw_text(5, "Who can defeat Discord without"); draw_text(5, "the Elements of Harmony?"); draw_text(5, ""); draw_text(5, "Well... There is somepony who knows"); draw_text(5, "all about muffins..."); al_hold_bitmap_drawing(false); break; } }
void Player::render() { al_draw_bitmap_region(playerSprite,sourceX*width,spriteCurrRow*height,width,height,x,y,0); }
int main(int argc, char **argv){ if(argc==3){ if(strcmp(argv[1],"rand")==0 && strcmp(argv[1],"map/maps.txt")!=0){ map_aleatoire(argv[2], 1000,100); printf("map cree\n"); return 0; } } /* Creation de l ecran */ ALLEGRO_DISPLAY *display = NULL; /* Creation du timer */ ALLEGRO_TIMER *timer; /* Creation de la liste d'evenement */ ALLEGRO_EVENT_QUEUE *queue; bool redraw = true; /*bool boucle_jeu=true;*/ /* Initialisation d allegro */ if(!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; } if(!al_init_image_addon()) { fprintf(stderr, "failed to initialize allegro image addon!\n"); return -1; } if(!al_init_primitives_addon()) { fprintf(stderr, "failed to initialize allegro primitive addon!\n"); return -1; } if(!al_install_mouse()) { fprintf(stderr, "failed to initialize allegro mouse !\n"); return -1; } if(!al_install_keyboard()) { fprintf(stderr, "failed to initialize allegro keyboard!\n"); return -1; } if(!al_install_joystick()){ fprintf(stderr, "failed to initialize allegro joystick!\n"); return -1; } if(!al_install_audio()) { fprintf(stderr, "failed to initialize allegro audio!\n"); /*return -1;*/ } if(!al_init_acodec_addon()){ fprintf(stderr, "failed to initialize allegro audio codec!\n"); /*return -1;*/ } if (!al_reserve_samples(2)){ fprintf(stderr, "failed to initialize allegro reserve sample 1!\n"); /*return -1;*/ } al_init_font_addon(); if(!al_init_ttf_addon()){ fprintf(stderr, "failed to initialize allegro ttf addon!\n"); return -1; } Game* game; /* Instantiation de l ecran */ display = al_create_display(DISPLAY_W,DISPLAY_H); if(!display) { fprintf(stderr, "failed to create display!\n"); return -1; } bool recommencer = true; while(recommencer){ recommencer = false; game = game_init(); al_hide_mouse_cursor(display); /* Instantiation de la liste d evenement */ queue = al_create_event_queue(); /* Instantiation du timer de jeu */ timer = al_create_timer(1.0/FPS); al_start_timer(timer); /* Enregistrement des evenement */ 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_joystick_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); /* ECRAN TITRE */ al_clear_to_color(al_map_rgb(0,0,0)); al_draw_bitmap_region(game->jeu->map->background,250,200,game->jeu->map->w*LENGTH_SPRITE,game->jeu->map->h*LENGTH_SPRITE,0,0,0); al_draw_text(game->jeu->font_jeu,al_map_rgb(0,0,0),280,150,ALLEGRO_ALIGN_LEFT,"Titre du jeu"); al_draw_text(game->jeu->font_jeu,al_map_rgb(0,0,0),280,190,ALLEGRO_ALIGN_LEFT,"Press enter"); if(al_is_audio_installed()){ ALLEGRO_SAMPLE* main_musique; main_musique = al_load_sample("musique/musique_titre.ogg"); if (!main_musique){ fprintf(stderr, "Erreur lors du chargement musique d'intro\n"); } al_play_sample(main_musique, 0.1, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,NULL); } al_flip_display(); bool debut = false; Event* event_titre; ALLEGRO_EVENT event_titre_event; event_titre = event_init(EVENT_PERIPH_XBOX); while(debut != true){ al_wait_for_event(queue, &event_titre_event); if(event_get_ok_court(event_titre)){ debut = true; } event_update(event_titre,&event_titre_event); } if(al_is_audio_installed()){ al_stop_samples(); } /* Ecran de chargement du premier niveau */ char num_niveau[4]; sprintf(num_niveau,"%d",game->current_map_i); al_clear_to_color(al_map_rgb(0,0,0)); if(game->size == game->current_map_i){ al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),280,190,ALLEGRO_ALIGN_LEFT,"Loading final stage"); }else{ al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),300,190,ALLEGRO_ALIGN_LEFT,"Loading level "); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),440,190,ALLEGRO_ALIGN_LEFT,num_niveau); } al_flip_display(); sleep(2); al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); /* Début de la boucle de jeu */ game->jeu->ev->son = true; map_set_frame(game->jeu->map,DISPLAY_W/2-200,100,200,DISPLAY_H-300); while(game->jeu->boucle_jeu){ game_next_map_test(game); ALLEGRO_EVENT event; al_wait_for_event(queue, &event); /* On demande a quitter le jeu */ if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE ){ game->jeu->boucle_jeu=false; } event_update(game->jeu->ev,&event); /* Evenement timer */ if(event.type == ALLEGRO_EVENT_TIMER){ redraw=true; } /* if(event.type == ALLEGRO_EVENT_DISPLAY_RESIZE){ al_acknowledge_resize(display); redraw = true; } */ /* affichage */ if(redraw && al_is_event_queue_empty(queue)){ redraw=false; game->jeu->boucle_jeu = jeu_update_event(game->jeu); jeu_draw(game->jeu); } } /* Ecran de fin du jeu */ if(game->success == true){ al_clear_to_color(al_map_rgb(0,0,0)); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,100,ALLEGRO_ALIGN_CENTER,"Félicitation, vous avez terminés les premiers niveaux du jeu !"); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,120,ALLEGRO_ALIGN_CENTER,"Ce jeu à été créé à l'occasion du premier projet de C de"); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,140,ALLEGRO_ALIGN_CENTER,"la promotion 2016 de Télécom Nancy"); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,160,ALLEGRO_ALIGN_CENTER,"par"); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,180,ALLEGRO_ALIGN_CENTER,"Giannini Valentin et Eric Perlinski"); al_flip_display(); sleep(5); al_clear_to_color(al_map_rgb(0,0,0)); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,150,ALLEGRO_ALIGN_CENTER,"Appuyez sur [ESC] pour quitter, ou sur [Entrer] pour recommencer"); al_flip_display(); }else{ al_clear_to_color(al_map_rgb(0,0,0)); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,100,ALLEGRO_ALIGN_CENTER,"Vous avez épuisés toutes les vies de votre personnage !"); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,120,ALLEGRO_ALIGN_CENTER,"Ce jeu à été créé à l'occasion du premier projet de C de"); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,140,ALLEGRO_ALIGN_CENTER,"la promotion 2016 de Télécom Nancy"); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,160,ALLEGRO_ALIGN_CENTER,"par"); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,180,ALLEGRO_ALIGN_CENTER,"Gianini Valentin et Eric Perlinski"); al_flip_display(); sleep(5); al_clear_to_color(al_map_rgb(0,0,0)); al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,150,ALLEGRO_ALIGN_CENTER,"Appuyez sur [ESC] pour quitter, ou sur [Entrer] pour recommencer"); al_flip_display(); } /* TODO Chargement écran de fin */ bool action = false; Event* event_credits; ALLEGRO_EVENT event_credits_event; event_credits = event_init(EVENT_PERIPH_XBOX); while(action != true){ al_wait_for_event(queue, &event_credits_event); if(event_get_ok_court(event_credits)){ action = true; recommencer = true; }else if (event_get_menu(event_credits)){ action = true; recommencer = false; } event_update(event_credits,&event_credits_event); } } jeu_dest(game->jeu); al_destroy_display(display); return 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); } } }
static void draw(void) { float x, y; int iw = al_get_bitmap_width(ex.pattern); int ih = al_get_bitmap_height(ex.pattern); ALLEGRO_BITMAP *screen, *temp; ALLEGRO_LOCKED_REGION *lock; void *data; int size, i, format; al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); al_clear_to_color(ex.background); screen = al_get_target_bitmap(); set_xy(8, 8); /* Test 1. */ /* Disabled: drawing to same bitmap is not supported. */ /* print("Screen -> Screen (%.1f fps)", get_fps(0)); get_xy(&x, &y); al_draw_bitmap(ex.pattern, x, y, 0); start_timer(0); al_draw_bitmap_region(screen, x, y, iw, ih, x + 8 + iw, y, 0); stop_timer(0); set_xy(x, y + ih); */ /* Test 2. */ print("Screen -> Bitmap -> Screen (%.1f fps)", get_fps(1)); get_xy(&x, &y); al_draw_bitmap(ex.pattern, x, y, 0); temp = al_create_bitmap(iw, ih); al_set_target_bitmap(temp); al_clear_to_color(al_map_rgba_f(1, 0, 0, 1)); start_timer(1); al_draw_bitmap_region(screen, x, y, iw, ih, 0, 0, 0); al_set_target_bitmap(screen); al_draw_bitmap(temp, x + 8 + iw, y, 0); stop_timer(1); set_xy(x, y + ih); al_destroy_bitmap(temp); /* Test 3. */ print("Screen -> Memory -> Screen (%.1f fps)", get_fps(2)); get_xy(&x, &y); al_draw_bitmap(ex.pattern, x, y, 0); al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); temp = al_create_bitmap(iw, ih); al_set_target_bitmap(temp); al_clear_to_color(al_map_rgba_f(1, 0, 0, 1)); start_timer(2); al_draw_bitmap_region(screen, x, y, iw, ih, 0, 0, 0); al_set_target_bitmap(screen); al_draw_bitmap(temp, x + 8 + iw, y, 0); stop_timer(2); set_xy(x, y + ih); al_destroy_bitmap(temp); al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP); /* Test 4. */ print("Screen -> Locked -> Screen (%.1f fps)", get_fps(3)); get_xy(&x, &y); al_draw_bitmap(ex.pattern, x, y, 0); start_timer(3); lock = al_lock_bitmap_region(screen, x, y, iw, ih, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY); format = lock->format; size = lock->pixel_size; data = malloc(size * iw * ih); for (i = 0; i < ih; i++) memcpy((char*)data + i * size * iw, (char*)lock->data + i * lock->pitch, size * iw); al_unlock_bitmap(screen); lock = al_lock_bitmap_region(screen, x + 8 + iw, y, iw, ih, format, ALLEGRO_LOCK_WRITEONLY); for (i = 0; i < ih; i++) memcpy((char*)lock->data + i * lock->pitch, (char*)data + i * size * iw, size * iw); al_unlock_bitmap(screen); free(data); stop_timer(3); set_xy(x, y + ih); }
void Object::Draw(ALLEGRO_BITMAP *image) { al_draw_bitmap_region(image, currFrame*frameWidth, currAni*frameHeight, frameWidth, frameHeight, _x, _y, 0); }
void Arena::Render() { // Fix background drawing // al_draw_bitmap( Background, -Camera.X, DISPLAY->GetHeight() - al_get_bitmap_height(Background) + Camera.Y, 0 ); al_draw_bitmap_region( Background, Camera.X, al_get_bitmap_height(Background) - Camera.Y - DISPLAY->GetHeight(), DISPLAY->GetWidth(), DISPLAY->GetHeight(), 0, 0, 0 ); // Draw Fighters switch( Player2->Fighter_GetState() ) { case Fighter::FighterStates::Knockdown: case Fighter::FighterStates::Loser: case Fighter::FighterStates::Floored: Player2->Fighter_Render( Camera.X, Camera.Y ); Player1->Fighter_Render( Camera.X, Camera.Y ); break; default: Player1->Fighter_Render( Camera.X, Camera.Y ); Player2->Fighter_Render( Camera.X, Camera.Y ); break; } // Draw collision graphics for( int i = 0; i < 2; i++ ) { if( CollisionsAt[i] != nullptr ) { CollisionAnimation->DrawFrame( CollisionsAt[i]->X - 36 - Camera.X, CollisionsAt[i]->Y - 36 + Camera.Y ); } } if( !DemoMode ) { al_hold_bitmap_drawing( true ); for( int r = 0; r < 4; r++ ) { RoundMarkers->DrawSprite( ( Player1Wins > r ? 1 : 0 ), 10 + (r * 52), 10 ); RoundMarkers->DrawSprite( ( Player2Wins > r ? 1 : 0 ), 790 - (r * 52) - 48, 10 ); } al_hold_bitmap_drawing( false ); } else { al_draw_text( fntName, al_map_rgb( 0, 0, 0 ), 14, 14, ALLEGRO_ALIGN_LEFT, "DEMO" ); al_draw_text( fntName, al_map_rgb( 255, 255, 0 ), 10, 10, ALLEGRO_ALIGN_LEFT, "DEMO" ); al_draw_text( fntName, al_map_rgb( 0, 0, 0 ), 794, 14, ALLEGRO_ALIGN_RIGHT, "DEMO" ); al_draw_text( fntName, al_map_rgb( 255, 255, 0 ), 790, 10, ALLEGRO_ALIGN_RIGHT, "DEMO" ); } // Draw timer al_draw_textf( fntTimer, al_map_rgb( 0, 0, 0 ), (DISPLAY->GetWidth() / 2) + 4, 14, ALLEGRO_ALIGN_CENTRE, "%d", CountdownTimer ); al_draw_textf( fntTimer, al_map_rgb( 255, 255, 0 ), DISPLAY->GetWidth() / 2, 10, ALLEGRO_ALIGN_CENTRE, "%d", CountdownTimer ); Player1->CharSelect_RenderProfileIcon( 30, 450 ); for( int ty = -2; ty <= 2; ty++ ) { for( int tx = -2; tx <= 2; tx++ ) { al_draw_textf( fntName, al_map_rgb( 0, 0, 0 ), 90 + tx, 450 + ty, ALLEGRO_ALIGN_LEFT, Player1->PlayerName.c_str() ); } } al_draw_textf( fntName, al_map_rgb( 128, 192, 64 ), 90, 450, ALLEGRO_ALIGN_LEFT, Player1->PlayerName.c_str() ); Player2->CharSelect_RenderProfileIcon( 770, 450 ); for( int ty = -2; ty <= 2; ty++ ) { for( int tx = -2; tx <= 2; tx++ ) { al_draw_textf( fntName, al_map_rgb( 0, 0, 0 ), 710 + tx, 450 + ty, ALLEGRO_ALIGN_RIGHT, Player2->PlayerName.c_str() ); } } al_draw_textf( fntName, al_map_rgb( 128, 192, 64 ), 710, 450, ALLEGRO_ALIGN_RIGHT, Player2->PlayerName.c_str() ); }
void Enemy::render() { al_draw_bitmap_region(enemySprite, sourceX*width, spriteCurrRow*height, width, height, x, y, 0); }
void Map::draw(int xpos, int ypos, int w, int h) { al_draw_bitmap_region(bm_, xpos, ypos, w, h, 0, 0, 0); }
int main() { bool quit = false; int gamestate = 0; srand(time(NULL)); int change_bkg = 0; int stopwatch = 120; bool iddle = false; int bulletID=0; int bulletCount=0; ALLEGRO_DISPLAY* display; ALLEGRO_TIMER* timer_0p2; ALLEGRO_TIMER* timer_1; ALLEGRO_TIMER* timer_60; ALLEGRO_EVENT_QUEUE* event_queue; ALLEGRO_EVENT ev; ALLEGRO_BITMAP* img_home_screen; ALLEGRO_BITMAP* img_dica_h1n1; ALLEGRO_BITMAP* img_background0; ALLEGRO_BITMAP* img_game_over; ALLEGRO_BITMAP* img_you_win; ALLEGRO_BITMAP* img_heart; ALLEGRO_BITMAP* img_medal; ALLEGRO_BITMAP* img_clock; ALLEGRO_BITMAP* img_block1; ALLEGRO_BITMAP* img_block2; ALLEGRO_BITMAP* img_player_walking; ALLEGRO_BITMAP* img_player_walking_shoot; ALLEGRO_BITMAP* img_player_immobile; ALLEGRO_BITMAP* img_player_immobile_shoot; ALLEGRO_BITMAP* img_player_jump; ALLEGRO_BITMAP* img_player_jump_shoot; ALLEGRO_BITMAP* img_player_bullet; ALLEGRO_BITMAP* img_enemy1; ALLEGRO_BITMAP* img_boss1; ALLEGRO_BITMAP* img_enemy_bullet; ALLEGRO_SAMPLE* spl_theme; ALLEGRO_SAMPLE* spl_playerShoot; ALLEGRO_SAMPLE* spl_mlk; ALLEGRO_SAMPLE_INSTANCE* instance_theme; ALLEGRO_SAMPLE_INSTANCE* instance_playerShoot; ALLEGRO_SAMPLE_INSTANCE* instance_mlk; ALLEGRO_FONT* fonte16; /* Estruturas */ s_object player; s_object block[LINHA_MAX][COLUNA_MAX]; s_object enemy1[LINHA_MAX][COLUNA_MAX]; for (i=0; i<LINHA_MAX; i++) { for(j=0; j<COLUNA_MAX; j++) { /* Cria o player */ if(mapa[i][j] == 1) { player.y = i*16 - 24; player.x = j*64 + 24; player.speed = 3; player.direction = 1; player.live = true; player.life = 100; block[i][j].live = false; } /* Cria os Blocos */ if(mapa[i][j] == 2) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = true; } if(mapa[i][j] == 3) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = true; } if(mapa[i][j] == 4) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = true; } if(mapa[i][j] == 5) { block[i][j].y = i*16; block[i][j].x = j*64; block[i][j].live = false; } /* Cria os Inimigos */ if(mapa[i][j] == 6) { enemy1[i][j].y = i*16 - 24; enemy1[i][j].x = j*64; enemy1[i][j].speed = 2; enemy1[i][j].direction = -1; enemy1[i][j].life = 3; enemy1[i][j].live = true; block[i][j].live = false; } if(mapa[i][j] == 7 || mapa[i][j] == 8) { enemy1[i][j].y = i*16 - 24; enemy1[i][j].x = j*64; enemy1[i][j].speed = 2; enemy1[i][j].direction = 1; enemy1[i][j].life = 3; enemy1[i][j].live = false; block[i][j].live = false; } if(mapa[i][j] == 9) { enemy1[i][j].y = i*16 - 24; enemy1[i][j].x = j*64; enemy1[i][j].speed = 2; enemy1[i][j].direction = -1; enemy1[i][j].life = 25; enemy1[i][j].live = false; block[i][j].live = false; } } } s_bullet playerBullet[NUM_BULLET]; s_bullet enemyBullet[NUM_BULLET]; for(i=0; i<NUM_BULLET; i++) { playerBullet[i].x = 0; playerBullet[i].y = 0; playerBullet[i].speed = 5; playerBullet[i].direction = 1; playerBullet[i].live = false; enemyBullet[i].x = 0; enemyBullet[i].y = 0; enemyBullet[i].speed = 5; enemyBullet[i].direction = 0; enemyBullet[i].live = false; } s_animation walking; walking.maxFrame = 8; walking.frameDelay = 5; walking.frameCount = 0; walking.curFrame = 0; walking.frameHeight = 40; walking.frameWidth = 40; s_animation jumping; jumping.maxFrame = 7; jumping.frameDelay = 5; jumping.frameCount = 0; jumping.curFrame = 0; jumping.frameHeight = 52; jumping.frameWidth = 40; s_animation immobile; immobile.maxFrame = 7; immobile.frameDelay = 15; immobile.frameCount = 0; immobile.curFrame = 0; immobile.frameHeight = 40; immobile.frameWidth = 40; s_animation anim_enemy1; anim_enemy1.maxFrame = 3; anim_enemy1.frameDelay = 15; anim_enemy1.frameCount = 0; anim_enemy1.curFrame = 0; anim_enemy1.frameHeight = 40; anim_enemy1.frameWidth = 40; /* Faz com que as teclas comecem em false */ for(i=0; i<KEY_MAX; i++) { keys[i] = false; } /* Carrega as configuracoes (teclado, audio, etc) */ al_init(); al_install_keyboard(); al_init_image_addon(); al_install_audio(); al_init_acodec_addon(); al_init_font_addon(); al_init_ttf_addon(); /* Erros ao criar algo */ display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { printf("Erro ao criar o display"); exit(-1); } timer_0p2 = al_create_timer(5.0); timer_1 = al_create_timer(1.0); timer_60 = al_create_timer(1/60.0); if(!timer_0p2) { printf("Erro ao criar o timer de 0.2 FPS"); exit(-1); } if(!timer_1) { printf("Erro ao criar o timer de 1 FPS"); exit(-1); } if(!timer_60) { printf("Erro ao criar o timer de 60 FPS"); exit(-1); } event_queue = al_create_event_queue(); if(!event_queue) { printf("Erro ao criar o event_queue"); exit(-1); } /* Carregando as Imagens */ img_home_screen = al_load_bitmap("Sprites/Background/home_screen.png"); img_dica_h1n1 = al_load_bitmap("Sprites/Background/dica_h1n1.png"); img_background0 = al_load_bitmap("Sprites/Background/background_h1n1.png"); img_you_win = al_load_bitmap("Sprites/Background/you_win.png"); img_game_over = al_load_bitmap("Sprites/Background/game_over.png"); img_heart = al_load_bitmap("Sprites/heart.png"); img_medal = al_load_bitmap("Sprites/medal.png"); img_clock = al_load_bitmap("Sprites/clock.png"); img_block1 = al_load_bitmap("Sprites/block1.png"); img_block2 = al_load_bitmap("Sprites/block2.png"); img_player_walking = al_load_bitmap("Sprites/Player/player_walking.png"); img_player_walking_shoot = al_load_bitmap("Sprites/Player/player_walking_shoot.png"); img_player_immobile = al_load_bitmap("Sprites/Player/player_immobile.png"); img_player_immobile_shoot = al_load_bitmap("Sprites/Player/player_immobile_shoot.png"); img_player_jump = al_load_bitmap("Sprites/Player/player_jump.png"); img_player_jump_shoot = al_load_bitmap("Sprites/Player/player_jump_shoot.png"); img_player_bullet = al_load_bitmap("Sprites/Player/player_bullet.png"); img_enemy1 = al_load_bitmap("Sprites/Enemies/enemy_h1n1.png"); img_boss1 = al_load_bitmap("Sprites/Enemies/boss_h1n1.png"); img_enemy_bullet = al_load_bitmap("Sprites/Enemies/enemy_bullet.png"); /* Carregando os Samples */ al_reserve_samples(10); spl_theme = al_load_sample("Sounds/theme.wav"); spl_playerShoot = al_load_sample("Sounds/shoot.wav"); spl_mlk = al_load_sample("Sounds/mlk.wav"); instance_theme = al_create_sample_instance(spl_theme); instance_playerShoot = al_create_sample_instance(spl_playerShoot); instance_mlk = al_create_sample_instance(spl_mlk); al_set_sample_instance_gain(instance_playerShoot, 0.5); al_attach_sample_instance_to_mixer(instance_theme, al_get_default_mixer()); al_attach_sample_instance_to_mixer(instance_playerShoot, al_get_default_mixer()); al_attach_sample_instance_to_mixer(instance_mlk, al_get_default_mixer()); /* Registra os Eventos */ al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer_0p2)); al_register_event_source(event_queue, al_get_timer_event_source(timer_1)); al_register_event_source(event_queue, al_get_timer_event_source(timer_60)); al_register_event_source(event_queue, al_get_keyboard_event_source()); /* Carregando os timers */ al_start_timer(timer_0p2); al_start_timer(timer_1); al_start_timer(timer_60); /* Carregando a fonte */ fonte16 = al_load_ttf_font("Joystix.TTF", 16, 0); if (!fonte16) { printf("Erro ao carregar Joystix.TTF\n"); exit(1); } while(!quit) { switch(gamestate) { case 0: al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) /* Faz com que o jogo feche ao clicar no botao "X" do display */ { quit = true; } if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) /* Faz com que o jogo feche ao pressionar esc */ { quit = true; } if(ev.keyboard.keycode == ALLEGRO_KEY_SPACE) /* Faz com que o jogo inicie ao pressionar space */ { change_bkg++; if(change_bkg >= 2) { gamestate = 1; } } } if(ev.type == ALLEGRO_EVENT_TIMER) /* Mostrar mensagens na tela */ { if(ev.timer.source == timer_60) { al_clear_to_color(al_map_rgb(0,0,0)); if(change_bkg == 0) { al_draw_bitmap(img_home_screen, 0, 0, 0); } if(change_bkg == 1) { al_draw_bitmap(img_dica_h1n1, 0, 0, 0); if(++anim_enemy1.frameCount >= anim_enemy1.frameDelay) { if(++anim_enemy1.curFrame >= anim_enemy1.maxFrame) { anim_enemy1.curFrame = 0; } anim_enemy1.frameCount = 0; } al_draw_bitmap_region(img_enemy1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, 330, 320, 0); al_draw_bitmap_region(img_boss1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, 450, 320, 0); } al_flip_display(); } } break; case 1: if(force>= -7.5) { force-=0.5; /* Queda */ } /* Toca a música de fundo */ if(!al_get_sample_instance_playing(instance_theme) && !al_get_sample_instance_playing(instance_mlk)) { al_play_sample_instance(instance_theme); } /* Fechar o display */ al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { quit = true; } /* Evento de quando a tecla eh pressionada */ if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: quit = true; break; case ALLEGRO_KEY_SPACE: keys[KEY_SPACE]=true; break; case ALLEGRO_KEY_UP: keys[KEY_UP] = true; if(jump == false) { jump = true; force = gravity; } break; case ALLEGRO_KEY_LEFT: keys[KEY_RIGHT]=false; keys[KEY_LEFT]=true; break; case ALLEGRO_KEY_RIGHT: keys[KEY_LEFT]=false; keys[KEY_RIGHT]=true; break; case ALLEGRO_KEY_F1: if(!al_get_sample_instance_playing(instance_mlk)) { al_play_sample_instance(instance_mlk); al_stop_sample_instance(instance_theme); } break; case ALLEGRO_KEY_M: if(al_get_sample_instance_playing(instance_mlk)) { al_stop_sample_instance(instance_mlk); } break; } } /* Evento de quando a tecla eh solta */ if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_SPACE: keys[KEY_SPACE]=false; break; case ALLEGRO_KEY_UP: keys[KEY_UP] = false; break; case ALLEGRO_KEY_LEFT: keys[KEY_LEFT]=false; break; case ALLEGRO_KEY_RIGHT: keys[KEY_RIGHT]=false; break; } } if(ev.type == ALLEGRO_EVENT_TIMER) { if(ev.timer.source == timer_0p2) { if((iddle == false) && (keys[KEY_RIGHT] == false) && (keys[KEY_LEFT] == false) && (jump == false)) { iddle = true; } } if(ev.timer.source == timer_1) { stopwatch--; } if(ev.timer.source == timer_60) { /* Posicionamento do player*/ player.y-=force; if(keys[KEY_RIGHT]) { player.direction = 1; player.x+=player.speed; } if(keys[KEY_LEFT]) { player.direction = -1; player.x-=player.speed; } if(keys[KEY_SPACE]) { for(i=0; i<NUM_BULLET; i++) { if(!al_get_sample_instance_playing(instance_playerShoot)) { playerShoot(&player, &playerBullet[i], instance_playerShoot); } } } /*Posicionamento do Inimigo */ for (i=0; i<LINHA_MAX; i++) { for(j=0; j<COLUNA_MAX; j++) { if(player.x > enemy1[i][j].x + 40) { enemy1[i][j].direction = 1; } else if(player.x + 40 <= enemy1[i][j].x) { enemy1[i][j].direction = -1; } } } /* ~~Posicionamento do projetil~~ */ /* Chance do Inimigo Atirar */ chance_enemy_shoot = rand() % 40; for (i=0; i<LINHA_MAX; i++) { for(j=0; j<COLUNA_MAX; j++) { enemyShoot(&player, &enemy1[i][j], enemyBullet, &bulletID, &bulletCount); } } for(i=0; i<NUM_BULLET; i++) { if(!playerBullet[i].live) { playerBullet[i].direction = player.direction; } if(playerBullet[i].live) { if(playerBullet[i].direction == -1) { playerBullet[i].x-=playerBullet[i].speed; } else if(playerBullet[i].direction == 1) { playerBullet[i].x+=playerBullet[i].speed; } } if(enemyBullet[i].live) { if(enemyBullet[i].direction == -1) { enemyBullet[i].x-=enemyBullet[i].speed; } if(enemyBullet[i].direction == 1) { enemyBullet[i].x+=enemyBullet[i].speed; } } } /* Prende a Camera no Personagem */ cameraX = player.x-(SCREEN_W/2); cameraY = player.y-(SCREEN_H/2); /* Fazer com que a camera nao passe dos limites do mapa */ if (cameraX < 0) cameraX = 0; if (cameraY < 0) cameraY = 0; if (cameraX > WORLD_W - SCREEN_W) cameraX = WORLD_W - SCREEN_W; if (cameraY > WORLD_H - SCREEN_H) cameraY = WORLD_H - SCREEN_H; /* Colisoes + check trap */ for (i = 0; i<LINHA_MAX; i++) { for(j = 0; j<COLUNA_MAX; j++) { for(k=0; k<NUM_BULLET; k++) { collision_bullet_player(&player, &enemyBullet[k], img_enemy_bullet, &bulletCount, 40, 40); } if(block[i][j].live == true) { if(mapa[i][j] == 2) { collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } if(mapa[i][j] == 3) { collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } if(mapa[i][j] == 4) { check_trap(&player, &block[i][j], &enemy1[i][j], 4); collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } if(mapa[i][j] == 5) { collision_player_tiles(&player, &block[i][j], &jumping, img_block2); } for(k=0; k<NUM_BULLET; k++) { collision_bullet_tiles(&playerBullet[k], &block[i][j], img_player_bullet, img_block2, 0, &bulletCount); collision_bullet_tiles(&enemyBullet[k], &block[i][j], img_player_bullet, img_block2, 1, &bulletCount); } } if(block[i][j].live == false) { if(mapa[i][j] == 5) { check_trap(&player, &block[i][j], &enemy1[i][j], 5); } if(mapa[i][j] == 6) { collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } if(mapa[i][j] == 7) { check_trap(&player, &block[i][j], &enemy1[i][j], 7); collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } if(mapa[i][j] == 8) { check_trap(&player, &block[i][j], &enemy1[i][j], 8); collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } if(mapa[i][j] == 9) { check_trap(&player, &block[i][j], &enemy1[i][j], 9); collision_player_enemy(&player, &enemy1[i][j], 40, 40); for(k=0; k<NUM_BULLET; k++) { collision_bullet_enemy(&playerBullet[k], &enemy1[i][j], img_player_bullet, 40, 40); } } } } } collision_player_wall(&player, &jumping, img_block1); /* ~~Desenha o Background~~ */ al_draw_bitmap(img_background0, 0 - cameraX, 0 - cameraY, 0); /* ~~Animação dos inimigos~~ */ if(++anim_enemy1.frameCount >= anim_enemy1.frameDelay) { if(++anim_enemy1.curFrame >= anim_enemy1.maxFrame) { anim_enemy1.curFrame = 0; } anim_enemy1.frameCount = 0; } /* ~~Desenha os Blocos/Inimigos~~ */ for (i = 0; i<LINHA_MAX; i++) { for(j = 0; j<COLUNA_MAX; j++) { if(mapa[i][j] == 2 && block[i][j].live == true) { al_draw_bitmap(img_block1, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if(mapa[i][j] == 3 && block[i][j].live == true) { al_draw_bitmap(img_block2, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if(mapa[i][j] == 4 && block[i][j].live == true) { al_draw_bitmap(img_block2, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if(mapa[i][j] == 5 && block[i][j].live == true) { al_draw_bitmap(img_block2, block[i][j].x - cameraX, block[i][j].y - cameraY, 0); } if((mapa[i][j] == 6 || mapa[i][j] == 7 || mapa[i][j] == 8) && (enemy1[i][j].direction == -1) && (enemy1[i][j].live == true)) { al_draw_bitmap_region(img_enemy1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, enemy1[i][j].x - cameraX, enemy1[i][j].y - cameraY, 0); } if((mapa[i][j] == 6 || mapa[i][j] == 7 || mapa[i][j] == 8) && (enemy1[i][j].direction == 1) && (enemy1[i][j].live == true)) { al_draw_bitmap_region(img_enemy1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, enemy1[i][j].x - cameraX, enemy1[i][j].y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(mapa[i][j] == 9 && enemy1[i][j].live == true) { al_draw_bitmap_region(img_boss1, anim_enemy1.curFrame * anim_enemy1.frameWidth, 0, anim_enemy1.frameWidth, anim_enemy1.frameHeight, enemy1[i][j].x - cameraX, enemy1[i][j].y - cameraY, 0); } } } /* ~~Desenho do player~~ */ /* Player parado */ if(iddle == true) { if(++immobile.frameCount >= immobile.frameDelay) { if(++immobile.curFrame >= immobile.maxFrame) { immobile.curFrame = 0; iddle = false; } immobile.frameCount = 0; } } if((keys[KEY_SPACE] == false) && (jump == false) && ((!keys[KEY_LEFT] && player.direction == -1) || player.x == 64)) { al_draw_bitmap_region(img_player_immobile, immobile.curFrame * immobile.frameWidth, 0, immobile.frameWidth, immobile.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if((keys[KEY_SPACE] == false) && (jump == false) && ((!keys[KEY_RIGHT] && player.direction == 1) || player.x == WORLD_W - (64-immobile.frameWidth))) { al_draw_bitmap_region(img_player_immobile, immobile.curFrame * immobile.frameWidth, 0, immobile.frameWidth, immobile.frameHeight, player.x - cameraX, player.y - cameraY, 0); } if((keys[KEY_SPACE] == true) && (jump == false) && ((!keys[KEY_LEFT] && player.direction == -1))) { al_draw_bitmap(img_player_immobile_shoot, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if((keys[KEY_SPACE] == true) && (jump == false) && ((!keys[KEY_RIGHT] && player.direction == 1))) { al_draw_bitmap(img_player_immobile_shoot, player.x - cameraX, player.y - cameraY, 0); } /* Player andando */ if(++walking.frameCount >= walking.frameDelay) { if(++walking.curFrame >= walking.maxFrame) { walking.curFrame = 0; } walking.frameCount = 0; } if(keys[KEY_SPACE] == false) { if(jump == false && keys[KEY_LEFT] && player.direction == -1) { al_draw_bitmap_region(img_player_walking, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(jump == false && keys[KEY_RIGHT] && player.direction == 1) { al_draw_bitmap_region(img_player_walking, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } if(keys[KEY_SPACE] == true) { if(jump == false && keys[KEY_LEFT] && player.direction == -1) { al_draw_bitmap_region(img_player_walking_shoot, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(jump == false && keys[KEY_RIGHT] && player.direction == 1) { al_draw_bitmap_region(img_player_walking_shoot, walking.curFrame * walking.frameWidth, 0, walking.frameWidth, walking.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } /* Player pulando */ if(jump == true) { if(++jumping.frameCount >= jumping.frameDelay) { if(++jumping.curFrame >= jumping.maxFrame) { jumping.curFrame = 0; } jumping.frameCount = 0; } if(keys[KEY_SPACE] == false) { if(player.direction == -1) { al_draw_bitmap_region(img_player_jump, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(player.direction == 1) { al_draw_bitmap_region(img_player_jump, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } else if(keys[KEY_SPACE] == true) { if(player.direction == -1) { al_draw_bitmap_region(img_player_jump_shoot, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, ALLEGRO_FLIP_HORIZONTAL); } if(player.direction == 1) { al_draw_bitmap_region(img_player_jump_shoot, jumping.curFrame * jumping.frameWidth, 0, jumping.frameWidth, jumping.frameHeight, player.x - cameraX, player.y - cameraY, 0); } } } /* ~~Desenho dos projeteis~~ */ for(i=0; i<NUM_BULLET; i++) { if(playerBullet[i].live) { al_draw_bitmap(img_player_bullet, playerBullet[i].x - cameraX, playerBullet[i].y - cameraY, 0); } if(enemyBullet[i].live) { al_draw_bitmap(img_enemy_bullet, enemyBullet[i].x - cameraX, enemyBullet[i].y - cameraY, 0); } } /* Pontuacao e Porcentagem de Vida */ al_draw_bitmap(img_heart, 0, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 255, 255), 20, 0, ALLEGRO_ALIGN_LEFT, ("%03d"), player.life); al_draw_bitmap(img_medal, 64, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 255, 255), 80, 0, ALLEGRO_ALIGN_LEFT, ("%04d"), scores); al_draw_bitmap(img_clock, 144, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 255, 255), 160, 0, ALLEGRO_ALIGN_LEFT, ("%03d"), stopwatch); } /* Termino da Fase */ if(enemyKilled == ENEMY_MAX) /* You Win! */ { scores = scores + (25 * stopwatch) + (10*player.life); gamestate = 2; } if(player.life <= 0 || stopwatch == 0) /* Game Over! */ { gamestate = 3; } /* Troca o display */ al_flip_display(); } break; case 2: al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) /* Faz com que o jogo feche ao clicar no botao "X" do display */ { quit = true; } if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) /* Faz com que o jogo feche ao pressionar esc */ { quit = true; } } if(ev.type == ALLEGRO_EVENT_TIMER) /* Mostrar mensagens na tela */ { if(ev.timer.source == timer_60) { al_clear_to_color(al_map_rgb(0,0,0)); al_draw_bitmap(img_you_win, 0, 0, 0); al_draw_textf(fonte16, al_map_rgb(0, 0, 0), SCREEN_W/2, SCREEN_H - 48, ALLEGRO_ALIGN_CENTRE, "Seus pontos: %d", scores); al_draw_textf(fonte16, al_map_rgb(0, 0, 0), SCREEN_W/2, SCREEN_H - 32, ALLEGRO_ALIGN_CENTRE, "Pressione Esc para sair"); al_flip_display(); } } break; case 3: al_wait_for_event(event_queue, &ev); if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) /* Faz com que o jogo feche ao clicar no botao "X" do display */ { quit = true; } if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) /* Faz com que o jogo feche ao pressionar esc */ { quit = true; } } if(ev.type == ALLEGRO_EVENT_TIMER) /* Mostrar mensagens na tela */ { if(ev.timer.source == timer_60) { al_clear_to_color(al_map_rgb(0,0,0)); al_draw_bitmap(img_game_over, 0, 0, 0); al_draw_textf(fonte16, al_map_rgb(255, 0, 0), SCREEN_W/2, SCREEN_H - 48, ALLEGRO_ALIGN_CENTRE, "Seus pontos: %d", scores); al_draw_textf(fonte16, al_map_rgb(255, 0, 0), SCREEN_W/2, SCREEN_H - 32, ALLEGRO_ALIGN_CENTRE, "Pressione Esc para sair"); al_flip_display(); } } break; } } /* Destruindo as variaveis */ al_destroy_display(display); al_destroy_event_queue(event_queue); al_destroy_timer(timer_0p2); al_destroy_timer(timer_1); al_destroy_timer(timer_60); al_destroy_bitmap(img_home_screen); al_destroy_bitmap(img_dica_h1n1); al_destroy_bitmap(img_background0); al_destroy_bitmap(img_heart); al_destroy_bitmap(img_medal); al_destroy_bitmap(img_clock); al_destroy_bitmap(img_block1); al_destroy_bitmap(img_block2); al_destroy_bitmap(img_player_walking); al_destroy_bitmap(img_player_walking_shoot); al_destroy_bitmap(img_player_immobile); al_destroy_bitmap(img_player_immobile_shoot); al_destroy_bitmap(img_player_jump); al_destroy_bitmap(img_player_jump_shoot); al_destroy_bitmap(img_player_bullet); al_destroy_bitmap(img_enemy1); al_destroy_bitmap(img_boss1); al_destroy_bitmap(img_enemy_bullet); al_destroy_sample(spl_theme); al_destroy_sample(spl_playerShoot); al_destroy_sample(spl_mlk); return 0; }
/* Draw our example scene. */ static void draw(void) { ALLEGRO_COLOR test[5]; ALLEGRO_BITMAP *target = al_get_target_bitmap(); char const *blend_names[] = {"ZERO", "ONE", "ALPHA", "INVERSE"}; char const *blend_vnames[] = {"ZERO", "ONE", "ALPHA", "INVER"}; int blend_modes[] = {ALLEGRO_ZERO, ALLEGRO_ONE, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA }; float x = 40, y = 40; int i, j; al_clear_to_color(al_map_rgb_f(0.5, 0.5, 0.5)); test[0] = al_map_rgba_f(1, 1, 1, 1); test[1] = al_map_rgba_f(1, 1, 1, 0.5); test[2] = al_map_rgba_f(1, 1, 1, 0.25); test[3] = al_map_rgba_f(1, 0, 0, 0.75); test[4] = al_map_rgba_f(0, 0, 0, 0); print(x, 0, false, "D E S T I N A T I O N (%0.2f fps)", ex.fps); print(0, y, true, "S O U R C E"); for (i = 0; i < 4; i++) { print(x + i * 110, 20, false, blend_names[i]); print(20, y + i * 110, true, blend_vnames[i]); } al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); if (ex.mode >= 1 && ex.mode <= 5) { al_set_target_bitmap(ex.offscreen); al_clear_to_color(test[ex.mode - 1]); } if (ex.mode >= 6 && ex.mode <= 10) { al_set_target_bitmap(ex.memory); al_clear_to_color(test[ex.mode - 6]); } for (j = 0; j < 4; j++) { for (i = 0; i < 4; i++) { al_set_blender(ALLEGRO_ADD, blend_modes[j], blend_modes[i]); if (ex.image == 0) al_draw_bitmap(ex.example, x + i * 110, y + j * 110, 0); else if (ex.image >= 1 && ex.image <= 6) { al_draw_filled_rectangle(x + i * 110, y + j * 110, x + i * 110 + 100, y + j * 110 + 100, test[ex.image - 1]); } } } if (ex.mode >= 1 && ex.mode <= 5) { al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); al_set_target_bitmap(target); al_draw_bitmap_region(ex.offscreen, x, y, 430, 430, x, y, 0); } if (ex.mode >= 6 && ex.mode <= 10) { al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); al_set_target_bitmap(target); al_draw_bitmap_region(ex.memory, x, y, 430, 430, x, y, 0); } #define IS(x) ((ex.image == x) ? "*" : " ") print(ex.BUTTONS_X, 20 * 1, false, "What to draw"); print(ex.BUTTONS_X, 20 * 2, false, "%s Picture", IS(0)); print(ex.BUTTONS_X, 20 * 3, false, "%s Rec1 (1/1/1/1)", IS(1)); print(ex.BUTTONS_X, 20 * 4, false, "%s Rec2 (1/1/1/.5)", IS(2)); print(ex.BUTTONS_X, 20 * 5, false, "%s Rec3 (1/1/1/.25)", IS(3)); print(ex.BUTTONS_X, 20 * 6, false, "%s Rec4 (1/0/0/.75)", IS(4)); print(ex.BUTTONS_X, 20 * 7, false, "%s Rec5 (0/0/0/0)", IS(5)); #undef IS #define IS(x) ((ex.mode == x) ? "*" : " ") print(ex.BUTTONS_X, 20 * 9, false, "Where to draw"); print(ex.BUTTONS_X, 20 * 10, false, "%s screen", IS(0)); print(ex.BUTTONS_X, 20 * 11, false, "%s offscreen1", IS(1)); print(ex.BUTTONS_X, 20 * 12, false, "%s offscreen2", IS(2)); print(ex.BUTTONS_X, 20 * 13, false, "%s offscreen3", IS(3)); print(ex.BUTTONS_X, 20 * 14, false, "%s offscreen4", IS(4)); print(ex.BUTTONS_X, 20 * 15, false, "%s offscreen5", IS(5)); print(ex.BUTTONS_X, 20 * 16, false, "%s memory1", IS(6)); print(ex.BUTTONS_X, 20 * 17, false, "%s memory2", IS(7)); print(ex.BUTTONS_X, 20 * 18, false, "%s memory3", IS(8)); print(ex.BUTTONS_X, 20 * 19, false, "%s memory4", IS(9)); print(ex.BUTTONS_X, 20 * 20, false, "%s memory5", IS(10)); #undef IS }
void Sprite::draw() { int row = current%columns*width; int col = current/columns*height; al_draw_bitmap_region(icon, row, col, width, height, x, y, NULL); }
void Player::DrawPlayer() { if (moving) al_draw_bitmap_region(player[direction], curFrame * frameWidth, 0, frameWidth, frameHeight, posx, posy, 0); else al_draw_bitmap_region(player[4], direction * frameWidth, 0, frameWidth, frameHeight, posx, posy, 0); }
int main (int argc, char *argv[]) { ALLEGRO_BITMAP *background = NULL; ALLEGRO_BITMAP *title = NULL; ALLEGRO_BITMAP *terrain = NULL; ALLEGRO_BITMAP *play = NULL; ALLEGRO_BITMAP *ranking = NULL; ALLEGRO_BITMAP *footer = NULL; ALLEGRO_BITMAP *playstart = NULL; int pos_x; int pos_y; srand (time (NULL)); iniciar_allegro (); al_install_mouse (); background = al_load_bitmap (SPRITESHEET); title = al_load_bitmap (SPRITESHEET); terrain = al_load_bitmap (SPRITESHEET); play = al_load_bitmap (SPRITESHEET); ranking = al_load_bitmap (SPRITESHEET); footer = al_load_bitmap (SPRITESHEET); playstart = al_load_bitmap (SPRITESHEET); if (!playstart) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del play start n***a", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!background) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del background", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!title) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del titulo", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!terrain) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del terreno", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!play) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del play", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!ranking) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del ranking", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } if (!footer) { al_show_native_message_box (display, "Error", "Error", "No se ha podido crear el bitmap del footer", NULL, ALLEGRO_MESSAGEBOX_ERROR); al_destroy_timer (timer); al_destroy_display (display); exit (EXIT_FAILURE); } while(1){ ALLEGRO_EVENT ev; ALLEGRO_TIMEOUT timeout; al_init_timeout (&timeout, 0.00); bool get_event = al_wait_for_event_until (event_queue, &ev, &timeout); if (get_event){ if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES){ pos_x = ev.mouse.x; pos_y = ev.mouse.y; } if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN){ if(ev.mouse.button & 1) break; } } if(redraw && al_is_event_queue_empty (event_queue)) { al_clear_to_color (al_map_rgb (0, 0, 0)); al_draw_bitmap_region(background, 0, 0, 288, 512, 0, 0, 0); al_draw_bitmap_region(title, 702, 182, 178, 48, 50, 110, 0); al_draw_bitmap_region(terrain, 584, 0 , 288, 112 , 0, 400, 0); al_draw_bitmap_region(playstart, 709, 314, 104, 56, 30, 344, 0); al_draw_bitmap_region(play, 708, 235, 104, 56, 30, 344, 0); al_draw_bitmap_region(ranking, 829, 235, 104, 56, 150, 344, 0); al_draw_bitmap_region(footer, 885, 182, 140, 20, 80, 418, 0); al_flip_display(); redraw = false; } } al_destroy_bitmap (background); al_destroy_bitmap (title); al_destroy_bitmap (terrain); al_destroy_bitmap (play); al_destroy_bitmap (playstart); al_destroy_bitmap (ranking); al_destroy_bitmap (footer); destruir_allegro (); return 0; }
void Sprite::draw(){ al_draw_bitmap_region(image, pixel_intervals * current_frame, 0, pixel_intervals, al_get_bitmap_height(image), pos_x, pos_y, 0); }
void Player::render(){ int fx = (cf%ac)*fw; int fy = ar*fh; al_draw_bitmap_region(image,fx,fy,fw,fh,x,y,0); }
void RenderTarget::drawBitmapRegion(ALLEGRO_BITMAP *r, float rx, float ry, float rw, float rh, float x, float y) { setAsCurrent(); convertCoords(x, y); al_draw_bitmap_region(r, rx, ry, rw, rh, x, y, 0); }
//!Overloaded draw function from Sprite class //In - // int DrawXCoordinate - DrawXCoordinate - the x coordinate to draw the weapon at // int DrawYCoordinate - DrawXCoordinate - the y coordinate to draw the weapon at // int XDirection - the x direction relative to the player/AI using the weapon to draw at (use graph coordinates to calculate (Ex. 0, 1 is North or Up)) // int YDirection - the y direction relative to the player/AI using the weapon to draw at (use graph coordinates to calculate (Ex. 0, 1 is North or Up)) void AIMeleeTile::Draw(int DrawXCoordinate, int DrawYCoordinate, int XDirection, int YDirection, bool IsWeaponActive) { //if there is a player tile image draw it at the specified input location if (m_Image != NULL) { //if the weapon is active draw this if(IsWeaponActive) { //draw sprite up if(XDirection == 0 && YDirection == -1) { Set_CurRow(3, false); al_draw_bitmap_region(m_Image, m_CurColumn * m_FrameWidth, m_CurRow * m_FrameHeight, m_FrameWidth, m_FrameHeight, (DrawXCoordinate - m_FrameWidth / 2), (DrawYCoordinate - m_FrameHeight / 2), 0); } //draw sprite down else if(XDirection == 0 && YDirection == 1) { Set_CurRow(0, false); al_draw_bitmap_region(m_Image, m_CurColumn * m_FrameWidth, m_CurRow * m_FrameHeight, m_FrameWidth, m_FrameHeight, (DrawXCoordinate - m_FrameWidth / 2), (DrawYCoordinate - m_FrameHeight / 2), 0); } //draw sprite left else if(XDirection == -1 && YDirection == 0) { Set_CurRow(1, false); al_draw_bitmap_region(m_Image, m_CurColumn * m_FrameWidth, m_CurRow * m_FrameHeight, m_FrameWidth, m_FrameHeight, (DrawXCoordinate - m_FrameWidth / 2), (DrawYCoordinate - m_FrameHeight / 2), 0); } //draw sprite right else if(XDirection == 1 && YDirection == 0) { Set_CurRow(2, false); al_draw_bitmap_region(m_Image, m_CurColumn * m_FrameWidth, m_CurRow * m_FrameHeight, m_FrameWidth, m_FrameHeight, (DrawXCoordinate - m_FrameWidth / 2), (DrawYCoordinate - m_FrameHeight / 2), 0); } //else draw a default direction else { Set_CurRow(1, false); al_draw_bitmap_region(m_Image, m_CurColumn * m_FrameWidth, m_CurRow * m_FrameHeight, m_FrameWidth, m_FrameHeight, (DrawXCoordinate - m_FrameWidth / 2), (DrawYCoordinate - m_FrameHeight / 2), 0); } } //else if the weapon is not active draw this else { //draw sprite up if(XDirection == 0 && YDirection == -1) { Set_CurRow(3, true); al_draw_bitmap_region(m_Image, m_CurColumn * m_FrameWidth, m_CurRow * m_FrameHeight, m_FrameWidth, m_FrameHeight, (DrawXCoordinate - m_FrameWidth / 2), (DrawYCoordinate - m_FrameHeight / 2), 0); } //draw sprite down else if(XDirection == 0 && YDirection == 1) { Set_CurRow(0, true); al_draw_bitmap_region(m_Image, m_CurColumn * m_FrameWidth, m_CurRow * m_FrameHeight, m_FrameWidth, m_FrameHeight, (DrawXCoordinate - m_FrameWidth / 2), (DrawYCoordinate - m_FrameHeight / 2), 0); } //draw sprite left else if(XDirection == -1 && YDirection == 0) { Set_CurRow(1, true); al_draw_bitmap_region(m_Image, m_CurColumn * m_FrameWidth, m_CurRow * m_FrameHeight, m_FrameWidth, m_FrameHeight, (DrawXCoordinate - m_FrameWidth / 2), (DrawYCoordinate - m_FrameHeight / 2), 0); } //draw sprite right else if(XDirection == 1 && YDirection == 0) { Set_CurRow(2, true); al_draw_bitmap_region(m_Image, m_CurColumn * m_FrameWidth, m_CurRow * m_FrameHeight, m_FrameWidth, m_FrameHeight, (DrawXCoordinate - m_FrameWidth / 2), (DrawYCoordinate - m_FrameHeight / 2), 0); } //else draw a default direction else { Set_CurRow(0, true); al_draw_bitmap_region(m_Image, m_CurColumn * m_FrameWidth, m_CurRow * m_FrameHeight, m_FrameWidth, m_FrameHeight, (DrawXCoordinate - m_FrameWidth / 2), (DrawYCoordinate - m_FrameHeight / 2), 0); } } } }
void obj_Treadmill_Left::Draw() { al_draw_bitmap_region(image, currentFrame*32, 0, 32, 32, x -_camX, y -_camY, 0); }
void Weapon::DrawAttackAnim() { al_draw_bitmap_region(sprite, spriteX1, spriteY1, width, height, x + xCorrection, y + yCorrection, NULL); }