From: <per...@eb...> - 1998-11-30 03:07:19
|
Ok, here's the code: #include <stdlib.h> #include <stdio.h> #include <dir.h> #include <pc.h> #include <math.h> #include "komet.h" #include "allegro.h" /*******************************************************************/ #define BACK_GROUND 0 #define SHIP_PAL 1 #define SHIP_FRAME 2 BITMAP *buffer; BITMAP *player; DATAFILE *komet_datafile; double radian_angle; #define SHIP_WIDTH 24 #define SHIP_HEIGHT 28 #define SHIP_THRUST_SPEED 2 #define SHIP_ACCEL_SPEED 1 #define SHIP_ROTATE_SPEED 2=20 int SCREEN_WIDTH =3D 640; int SCREEN_HEIGHT =3D 480; struct ship { int dead; int width, height; float x, y; int state; int frame; float vel_x, vel_y; int angle; }; struct ship Sh; volatile int frame_count, fps; volatile int game_time; void game_timer() { game_time++; } END_OF_FUNCTION(game_timer); void fps_proc() { fps =3D frame_count; frame_count =3D 0; } END_OF_FUNCTION(fps_proc); void init_program (void); void menu (void); void game_loop (void); void shut_down (void); void init_game (void); void get_input (void); void update_screen (void); void Dump_Screen(void); /*******************************************************************/ int main () { init_program(); menu(); shut_down(); } /*******************************************************************/ void init_program () { allegro_init(); install_timer(); install_keyboard(); install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); komet_datafile =3D load_datafile("Komet.dat"); set_gfx_mode(GFX_AUTODETECT, SCREEN_WIDTH, SCREEN_HEIGHT,0,0); set_pallete(komet_datafile[SHIP_PAL].dat); buffer =3D create_bitmap(SCREEN_WIDTH, SCREEN_HEIGHT); clear(buffer); LOCK_VARIABLE(game_time); LOCK_FUNCTION(game_timer); //line 100 LOCK_VARIABLE(frame_count); LOCK_VARIABLE(fps); LOCK_FUNCTION(fps_proc); install_int(fps_proc, 1000); install_int(game_timer, 6400/SCREEN_WIDTH); } /*******************************************************************/ void menu () { game_loop(); } /*******************************************************************/ void game_loop () { init_game(); while (!Sh.dead) { while (game_time > 0)=20 { get_input(); game_time--; } update_screen(); frame_count++; if (key[KEY_ESC]) Sh.dead =3D TRUE; } } /*******************************************************************/ void shut_down () { unload_datafile(komet_datafile); destroy_bitmap(buffer); printf("Kometoids by Per Arvidsson. \n\nHttp://user.tninet.se/~owr636o = \npe...@eb...");=09 allegro_exit(); exit(0); } /*******************************************************************/ void init_game () { Sh.dead =3D FALSE; Sh.width =3D 24; Sh.height =3D 28; Sh.x =3D (SCREEN_WIDTH / 2) - (SHIP_WIDTH/2); Sh.y =3D (SCREEN_HEIGHT / 2) - (SHIP_HEIGHT/2); Sh.vel_x =3D (rand() % 10) * .01; Sh.vel_y =3D (rand() % 10) * .01; if ((rand() % 100) > 50) Sh.vel_x *=3D -1; if ((rand() % 100) > 50) Sh.vel_y *=3D -1; Sh.angle =3D(rand() % 256); } /*******************************************************************/ void get_input () { if (key[KEY_UP]) { radian_angle =3D ((1.40625 * Sh.angle) * -1) + 450; radian_angle *=3D 0.017453277; Sh.vel_x +=3D cos(radian_angle) * SHIP_ACCEL_SPEED * .05; Sh.vel_y -=3D sin(radian_angle) * SHIP_ACCEL_SPEED * .05; if (Sh.vel_x > SHIP_THRUST_SPEED) Sh.vel_x =3D SHIP_THRUST_SPEED; if (Sh.vel_y > SHIP_THRUST_SPEED) Sh.vel_y =3D SHIP_THRUST_SPEED; if (Sh.vel_x < (-1 * SHIP_THRUST_SPEED)) Sh.vel_x =3D -1 * = SHIP_THRUST_SPEED; if (Sh.vel_y < (-1 * SHIP_THRUST_SPEED)) Sh.vel_y =3D -1 * = SHIP_THRUST_SPEED; } =09 if (key[KEY_LEFT]) { Sh.angle -=3D SHIP_ROTATE_SPEED; if (Sh.angle < 0) Sh.angle +=3D 256; } if (key[KEY_RIGHT]) { Sh.angle +=3D SHIP_ROTATE_SPEED; if (Sh.angle > 256) Sh.angle -=3D 256; } if (key[KEY_D]) Dump_Screen(); } /*******************************************************************/ void update_screen () { clear(player); rotate_sprite (player, komet_datafile[SHIP_FRAME].dat, 0, 0,itofix = (Sh.angle)); draw_sprite (buffer, player, Sh.x, Sh.y); Sh.x +=3D Sh.vel_x; Sh.y +=3D Sh.vel_y; if (Sh.x > SCREEN_WIDTH) { Sh.x =3D -SHIP_WIDTH; } else { if (Sh.x < -SHIP_WIDTH) { Sh.x =3D SCREEN_WIDTH; } } if (Sh.y > SCREEN_HEIGHT) { Sh.y =3D -SHIP_HEIGHT; } else { if (Sh.y < -SHIP_HEIGHT) { Sh.y =3D SCREEN_HEIGHT; } } vsync(); blit (buffer, screen, 0, 0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); clear(buffer); } /*******************************************************************/ void Dump_Screen() { save_bitmap("dump.bmp", screen, komet_datafile[SHIP_PAL].dat); } And here's the symified output: Shutting down Allegro Exiting due to signal SIGSEGV General Protection Fault at eip=3D0000cb7e eax=3D00000000 ebx=3D000af100 ecx=3D005d5692 edx=3Dca8941ee = esi=3D00000054 edi=3D0006e55c ebp=3D000ae518 esp=3D000ae4f8 = program=3DC:\WINDOWS\SKRIVB~1\KOMETOID\KOMET.EXE cs: sel=3D00af base=3D82f20000 limit=3D005c0fff ds: sel=3D00b7 base=3D82f20000 limit=3D005c0fff es: sel=3D00b7 base=3D82f20000 limit=3D005c0fff fs: sel=3D00c7 base=3D00000000 limit=3Dffffffff gs: sel=3D00c7 base=3D00000000 limit=3Dffffffff ss: sel=3D00b7 base=3D82f20000 limit=3D005c0fff Call frame traceback EIPs: 0x0000cb7e _clear+10 0x0000173d _game_loop+61, line 126 of komet.c 0x000016fc _menu+8, line 109 of komet.c 0x000015c5 _main+13, line 72 of komet.c 0x0003d8f2 ___crt1_startup+138 Hope some of you guys can fix it! I really need som help! -------------------------------------------------------------------------= --- Per Arvidsson E-mail: per...@eb... Web: http://user.tninet.se/~owr636o or http://fly.to/pelle84 ICQ: 13651133 Current Project: Kometoids! -------------------------------------------------------------------------= ------------------ |