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
|
#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 + logo->w >= SCREEN_W) {
dx *= -1;
}
// Oberer und unterer Rand
if (y + dy < 0) {
dy *= -1;
} else if (y + 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,
0, 0,
logo->w,
logo->h
);
release_bitmap(doublebuffer);
blit(
doublebuffer, screen,
0, 0, 0, 0,
SCREEN_W, SCREEN_H
);
needRefresh = false;
}
}
} END_OF_MAIN();
|