Riki94 (Normal User)
Pro
Messaggi: 93
Iscritto: 30/07/2009
|
Ciao a tutti... sono agli inizi con allegro e sono riuscito a far muovere tramite i tasti wasd una bitmap...
adesso vorrei fare la stessa cosa su una seconda bitmap con i tasti freccia. Il codice funziona, le due bitmap si muovono, solamente che compaiono sullo schermo "a linee", come se il computer non riuscisse a processare gli spostamenti delle immagini insieme... purtroppo in una immagine non si vede questo fenomeno ma appare normale... se lo ritenete utile posso linkarvi un video per dimostrarvi cosa succede.. intanto questo è il codice...
Codice sorgente - presumibilmente C |
#include <allegro.h> void init(); void deinit(); int main() { init(); BITMAP *im1 = NULL; BITMAP *buffer = NULL; BITMAP *buffer2 = NULL; BITMAP *im2 = NULL; double im1_x=0,im1_y=0; double im2_x=0,im2_y=0; buffer = create_bitmap(320,200); buffer2 = create_bitmap(320,200); im1 = load_bitmap("bit1.bmp",NULL); im2 = load_bitmap("bit2.bmp",NULL); while (!key[KEY_ESC]) { if(im1==NULL) { allegro_message("Errore. File non trovato."); return 0; } if(key[KEY_A]) { im1_x = im1_x - 0.1; if(im1_x <=0) im1_x=0; } if(key[KEY_D]) { im1_x = im1_x + 0.1; if(im1_x >=270) im1_x=270; } if(key[KEY_W]) { im1_y = im1_y - 0.1; if(im1_y <=0) im1_y=0; } if(key[KEY_S]) { im1_y = im1_y + 0.1; if(im1_y >=150) im1_y=150; } if(im2==NULL) { allegro_message("Errore. File non trovato."); return 0; } if(key[KEY_LEFT]) { im2_x = im2_x - 0.1; if(im2_x <=0) im2_x=0; } if(key[KEY_RIGHT]) { im2_x = im2_x + 0.1; if(im2_x >=270) im2_x=270; } if(key[KEY_UP]) { im2_y = im2_y - 0.1; if(im2_y <=0) im2_y=0; } if(key[KEY_DOWN]) { im2_y = im2_y + 0.1; if(im2_y >=150) im2_y=150; } draw_sprite(buffer2,im2,im2_x,im2_y); blit(buffer2,screen,0,0,0,0,320,200); draw_sprite(buffer,im1,im1_x,im1_y); blit(buffer,screen,0,0,0,0,320,200); clear_bitmap(buffer2); clear_bitmap(buffer); } destroy_bitmap(im1); destroy_bitmap(im2); destroy_bitmap(buffer); destroy_bitmap(buffer2); deinit(); return 0; } END_OF_MAIN() void init() { int depth, res; allegro_init(); depth = desktop_color_depth(); if (depth == 0) depth = 32; set_color_depth(depth); res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320,200, 0, 0); if (res != 0) { allegro_message(allegro_error); exit(-1); } install_timer(); install_keyboard(); install_mouse(); /* add other initializations here */ } void deinit() { clear_keybuf(); }
|
|