// Inisialisasi animasi dan sound disiapkan sefolder dg file .cpp
// Input warna dan ukuran bola dari inputan file
// hanya bisa dijalankan di dev-C++ yg berpackage Allegro
#include <allegro.h>
#include <stdio.h>
void init();
//void deinit();
int main() {
init();
/* Inisialisasi buffer */
BITMAP *buffer = create_bitmap(640,480);
/* Inisialisasi animasi ledakan */
BITMAP *bexplo = load_bitmap (“bexplo2.bmp”,NULL);
/* Inisialisasi sound effect */
SAMPLE *sound = load_wav(“Explosion7.wav”);
/* Posisi bola di awal program berjalan */
int x = 640;
int y = 480;
int cl;
int sz;
/* Memanggil file eksternal */
FILE *col = fopen(“ballcolor.txt”, “r”);
FILE *size = fopen(“ballsize.txt”, “r”);
/* Indikator kondisi bola */
bool normal=true;
bool explosion=false;
/* PROGRAM */
fscanf(col,”%i”, &cl);
fscanf(size,”%i”, &sz);
while (!key[KEY_ESC]) {
if (normal==true){
if (x) // gerak horizontal
x=mouse_x;
if (x < 640) // kalo g dikasi ni, pas bola di pinggir,
x=(mouse_x-sz); // bolanya kecantol g bisa balik
if (y) // gerak vertikal
y=mouse_y;
if (y < 480) // kalo g dikasi ni, pas bola di atas,
y=(mouse_y-sz); // bolanya kecantol g bisa balik
clear(buffer);
circlefill(buffer, x, y, sz, cl);
blit (buffer,screen,0,0,0,0,640,480);
}
/* Animasi ledakan */
if (explosion==true)
{
clear(buffer);
blit (bexplo,buffer,0,0,x-37,y-37,640,480);
draw_sprite(screen,buffer,0,0);
play_sample(sound, 127, 127, 1000, 0);
}
explosion=false; // Untuk menghentikan animasi ledakan
/* Animasi ledakan akan berjalan jika mouse kiri di-klik */
if (mouse_b & 1)
{
explosion=true;
normal=false;
}
/* Jika ditekan tombol spasi, bola akan dimunculkan lagi */
if (key[KEY_SPACE])
{
normal=true;
}
}
//deinit();
fclose(col);
fclose(size);
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();
install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL);
}
//void deinit() {
// clear_keybuf();
//}