Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
![]() |
C-/C++-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
#include <allegro.h> #include <string> using std::string; volatile int timerCounter = 0; static void timerCounterUpdater() { timerCounter++; } END_OF_STATIC_FUNCTION(timerCounterUpdater); void init() { allegro_init(); install_keyboard(); LOCK_FUNCTION(timerCounterUpdater); LOCK_VARIABLE(timerCounter); install_int_ex(timerCounterUpdater, BPS_TO_TIMER(60)); } int main(int argc, char **argv) { init(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 800, 0, 0); BITMAP * logo = load_bitmap("allegro.tga", NULL); BITMAP * doublebuffer = create_bitmap(800, 800); int x = 0; int y = 0; int dx = 1; int dy = 1; int maxSkip = 4; int curSkip = 0; bool needRefresh = false; while (!keypressed()) { curSkip = 0; if (timerCounter > 0) { do { if ((x + dx) < 0) { dx *= -1; } else if ((x + dx + logo->w) >= SCREEN_W) { dx *= -1; } if ((y + dy) < 0) { dy *= -1; } else if ((y + dy + logo->h) >= SCREEN_H) { dy *= -1; } x += dx; y += dy; timerCounter--; curSkip++; if (curSkip >= maxSkip) { timerCounter = 0; break; } } while(timerCounter > 0); needRefresh = true; } if (needRefresh) { acquire_bitmap(doublebuffer); clear(doublebuffer); blit( logo, doublebuffer, x, y, (SCREEN_W - logo->w) / 2, (SCREEN_H - logo->h) / 2, logo->w, logo->h ); release_bitmap(doublebuffer); blit( doublebuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H ); needRefresh = false; } } } END_OF_MAIN(); |
![]() |
C-/C++-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
blit( logo, doublebuffer, x, y, (SCREEN_W - logo->w) / 2, (SCREEN_H - logo->h) / 2, logo->w, logo->h ); release_bitmap(doublebuffer); blit( doublebuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H ); |
![]() |
C-/C++-Quelltext |
1 2 3 4 5 6 7 |
blit( logo, doublebuffer, 0, 0, 0, 0, logo->w, logo->h ); |
![]() |
C-/C++-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
#include <allegro.h> #include <string> using std::string; volatile int timerCounter = 0; static void timerCounterUpdater() { timerCounter++; } END_OF_STATIC_FUNCTION(timerCounterUpdater); void init() { allegro_init(); install_keyboard(); LOCK_FUNCTION(timerCounterUpdater); LOCK_VARIABLE(timerCounter); install_int_ex(timerCounterUpdater, BPS_TO_TIMER(60)); } int main(int argc, char **argv) { init(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 800, 0, 0); BITMAP * logo = load_bitmap("allegro.tga", NULL); BITMAP * doublebuffer = create_bitmap(800, 800); int x = 0; int y = 0; int dx = 1; int dy = 1; int maxSkip = 4; int curSkip = 0; bool needRefresh = false; while (!keypressed()) { curSkip = 0; if (timerCounter > 0) { do { if ((x + dx) < 0) { dx *= -1; } else if ((x + dx + logo->w) >= SCREEN_W) { dx *= -1; } if ((y + dy) < 0) { dy *= -1; } else if ((y + dy + logo->h) >= SCREEN_H) { dy *= -1; } x += dx; y += dy; timerCounter--; curSkip++; if (curSkip >= maxSkip) { timerCounter = 0; break; } } while(timerCounter > 0); needRefresh = true; } if (needRefresh) { acquire_bitmap(doublebuffer); clear(doublebuffer); blit( logo, doublebuffer, x, y, (SCREEN_W - logo->w) / 2, (SCREEN_H - logo->h) / 2, logo->w, logo->h ); release_bitmap(doublebuffer); blit( doublebuffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H ); needRefresh = false; } } } END_OF_MAIN(); |
Werbeanzeige