Tertius

Coquinha

Aug 19th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.62 KB | None | 0 0
  1. #include <allegro.h>
  2.     volatile int exit_program;
  3.     void fecha_programa() { exit_program = TRUE; }
  4.     END_OF_FUNCTION(fecha_programa)
  5.  
  6.     volatile int ticks;
  7.     void tick_counter(){ ticks++; }
  8.     END_OF_FUNCTION(tick_counter)
  9.  
  10.     enum { SPLASHSCREEN, TITLESCREEN, MAINMENU, GAMESCREEN };
  11.     int screen_state;
  12.  
  13. void init(){
  14.     allegro_init();
  15.     set_color_depth(32);
  16.     set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
  17.     install_timer();
  18.     install_keyboard();
  19.     install_mouse();
  20.     set_window_title("Coca-Defense Have Fun");
  21.     exit_program = FALSE;
  22.     LOCK_FUNCTION(fecha_programa);
  23.     set_close_button_callback(fecha_programa);
  24.  
  25.     ticks = 0;
  26.     LOCK_FUNCTION(tick_counter);
  27.     LOCK_VARIABLE(ticks);
  28.     install_int_ex(tick_counter, BPS_TO_TIMER(60));
  29.     screen_state = TITLESCREEN;
  30. }
  31. void game_vitoria(){
  32.     int exit_screen = FALSE;
  33.  
  34.     ///BITMAP
  35.     BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
  36.     BITMAP* win_game = load_bitmap("sprites/telas/vitoria/tela_vitoria.bmp", NULL);
  37.  
  38.     ///GAME LOOP
  39.     while(!exit_program && !exit_screen){
  40.         while(ticks > 0 && !exit_program && !exit_screen){
  41.             if(key[KEY_ESC]){
  42.                 fecha_programa();
  43.             }
  44.         }
  45.         draw_sprite(buffer, win_game, 0, 0);
  46.         draw_sprite(screen, buffer, 0, 0);
  47.         clear_to_color(buffer, makecol(255,255,255));
  48.         ticks --;
  49.     }
  50.     destroy_bitmap(buffer);
  51.     destroy_bitmap(win_game);
  52. }
  53. void game_derrota(){
  54.     int exit_screen = FALSE;
  55.  
  56.     ///BITMAP
  57.     BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
  58.     BITMAP* lose_game = load_bitmap("sprites/telas/derrota/tela_derrota.bmp", NULL);
  59.  
  60.     ///GAME LOOP
  61.     while(!exit_program && !exit_screen){
  62.         while(ticks > 0 && !exit_program && !exit_screen){
  63.             if(key[KEY_ESC]){
  64.                 fecha_programa();
  65.             }
  66.         }
  67.         draw_sprite(buffer, lose_game, 0, 0);
  68.         draw_sprite(screen, buffer, 0, 0);
  69.         clear_to_color(buffer, makecol(255,255,255));
  70.         ticks --;
  71.     }
  72.     destroy_bitmap(buffer);
  73.     destroy_bitmap(lose_game);
  74. }
  75. void start_game(){
  76.     int exit_screen = FALSE;
  77.  
  78.     ///BITMAPS
  79.     BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
  80.     BITMAP* tela_jogo = load_bitmap("sprites/caminho/background.bmp", NULL);
  81.     BITMAP* cursor = load_bitmap("sprites/mouse_2.bmp", NULL);
  82.  
  83.     ///GAME LOOP
  84.     while(!exit_program && !exit_screen){
  85.         while(ticks > 0 && !exit_program && !exit_screen){
  86.             if(key[KEY_ESC]){
  87.                 fecha_programa();
  88.             }
  89.             if(key[KEY_V]){
  90.                 game_vitoria();
  91.             } else if(key[KEY_D]){
  92.                 game_derrota();
  93.             }
  94.         ///DRAW
  95.         draw_sprite(buffer, tela_jogo, 0, 0);
  96.         draw_sprite(buffer, cursor, mouse_x - 1, mouse_y - 1);
  97.         draw_sprite(screen, buffer, 0, 0);
  98.         clear_to_color(buffer, makecol(255,255,255));
  99.         ticks --;
  100.         }
  101.     }
  102.     destroy_bitmap(buffer);
  103.     destroy_bitmap(tela_jogo);
  104.     destroy_bitmap(cursor);
  105. }
  106. void mainmenu(){
  107.     int exit_screen = FALSE;
  108.  
  109.     ///BITMAPS
  110.     BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
  111.     BITMAP* menu_principal = load_bitmap("sprites/telas/menu/menu_principal.bmp", NULL);
  112.     BITMAP* botao_jogar = load_bitmap("sprites//telas/botoes/botao_jogar.bmp", NULL);
  113.     BITMAP* botao_como_jogar = load_bitmap("sprites/telas/botoes/como_jogar.bmp", NULL);
  114.     BITMAP* cursor = load_bitmap("sprites/mouse_2.bmp", NULL);
  115.  
  116.     ///GAME LOOP
  117.     while(!exit_program && !exit_screen){
  118.         while(ticks > 0 && !exit_program && !exit_screen){
  119.             if(key[KEY_ESC]){
  120.                 fecha_programa();
  121.             }
  122.  
  123.         ///DRAW
  124.         draw_sprite(buffer, menu_principal, 0, 0);
  125.         if(mouse_x > 305 && mouse_x < 498 && mouse_y > 405 && mouse_y < 462){ // permite começar o jogo
  126.             draw_sprite(buffer, botao_jogar, 305, 405);  // ao passar o mouse por cima, escurece o botão
  127.             if(mouse_b == 1){
  128.                 mouse_b = 0;
  129.                 start_game();
  130.             }
  131.         }
  132.         draw_sprite(buffer, cursor, mouse_x - 1, mouse_y - 1);
  133.         draw_sprite(screen, buffer, 0, 0);
  134.         clear_to_color(buffer, makecol(255,255,255));
  135.         ticks --;
  136.         }
  137.     }
  138.     destroy_bitmap(buffer);
  139.     destroy_bitmap(menu_principal);
  140.     destroy_bitmap(botao_jogar);
  141.     destroy_bitmap(botao_como_jogar);
  142.     destroy_bitmap(cursor);
  143. }
  144. void titlescreen(){
  145.     int exit_screen = FALSE;
  146.  
  147.     ///BITMAPS
  148.     BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
  149.     BITMAP* tela_inicial = load_bitmap("sprites/telas/inicial/tela_inicial.bmp", NULL);
  150.     BITMAP* cursor = load_bitmap("sprites/mouse_2.bmp", NULL);
  151.  
  152.     ///GAME LOOP
  153.     while(!exit_program && !exit_screen){
  154.         while(ticks > 0 && !exit_program && !exit_screen){
  155.             ///IMPUT
  156.             if(key[KEY_ENTER]){
  157.                 exit_screen = TRUE;
  158.                 screen_state = MAINMENU;
  159.             }
  160.         ///DRAW
  161.         draw_sprite(buffer, tela_inicial, 0, 0);
  162.         draw_sprite(buffer, cursor, mouse_x - 1, mouse_y - 1);
  163.         draw_sprite(screen, buffer, 0, 0);
  164.         clear_to_color(buffer, makecol(255,255,255));
  165.         ticks --;
  166.         }
  167.  
  168.     }
  169.     destroy_bitmap(buffer);
  170.     destroy_bitmap(tela_inicial);
  171.     destroy_bitmap(cursor);
  172. }
  173. int main(){
  174.     init();
  175.  
  176.     ///GAME LOOP
  177.     while (!exit_program){
  178.         if(screen_state == MAINMENU){
  179.             mainmenu();
  180.         } else if(screen_state == TITLESCREEN) {
  181.             titlescreen();
  182.         }
  183.     }
  184. return 0;
  185. }
  186. END_OF_MAIN()
Advertisement
Add Comment
Please, Sign In to add comment