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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include <allegro.h>
void init();
void deinit();
volatile bool redraw = true;
bool update=true;
void tick() {
redraw = true;
}
END_OF_FUNCTION(tick);
int main() {
init();
int x,y;
int skott1x,skott1y,skott1dx,fiendx,fiendy,fiendedx;
bool uppdatera=true;
bool skott1aktiv=false;
bool fiende=true;
BITMAP *bakgrund = load_bitmap("image2.bmp", NULL);
BITMAP *gubbe = load_bitmap("bild6.bmp", NULL);
BITMAP *skott = load_bitmap("klot.bmp", NULL);
BITMAP *fienden = load_bitmap("fiende2.bmp", NULL);
BITMAP *bg = create_bitmap(640,480);
install_int_ex(tick, BPS_TO_TIMER(60));
for(x=0; x<20; x++) {
for(y=0; y<16; y++){
blit(bakgrund, bg, 0,0,x*128,y*128,128,128);
}}
int yy=0;
int xx=220;
x=220;
y=420;
skott1dx=8;
fiendedx=5;
while(!key[KEY_ESC]) {
while(redraw==true) {
if(key[KEY_LEFT]) {x-=4; uppdatera=true; if (x<0){x=0;}}
if(key[KEY_RIGHT]) {x+=4; uppdatera=true; if (x>608) {x=608;}}
if(!skott1aktiv && key[KEY_SPACE]) { skott1aktiv=true; skott1x=x+15; skott1y=y; }
if(update=true) { fiendx=xx; fiendy=yy; } //This doesnt work propely
redraw=false;
} // redraw
if (uppdatera){
blit(bg,screen, 0,0,0,0,640,480);
masked_blit(gubbe, screen, 0,0,x,y,64,64);
uppdatera=false;}
if(skott1aktiv) {
masked_blit(skott, screen,0,0,skott1x,skott1y,32,32);
skott1y-=skott1dx;
uppdatera=true;
if(skott1y>639 || skott1y<0) skott1aktiv=false; }
if(update) {
masked_blit(fienden, screen,0,0,fiendx,fiendy,64,64);
fiendy+=fiendedx;
if(yy>639 || xx<0) update=false;
} //This doesnt work propely
rest(10);
}
destroy_bitmap(fienden);
destroy_bitmap(skott);
destroy_bitmap(bg);
destroy_bitmap(gubbe);
destroy_bitmap(bakgrund);
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,640, 480, 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();
/* add other deinitializations here */
}
|