Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <allegro.h>
- volatile int exit_program;
- void fecha_programa() { exit_program = TRUE; }
- END_OF_FUNCTION(fecha_programa)
- volatile int ticks;
- void tick_counter(){ ticks++; }
- END_OF_FUNCTION(tick_counter)
- enum { SPLASHSCREEN, TITLESCREEN, MAINMENU, GAMESCREEN };
- int screen_state;
- void init(){
- allegro_init();
- set_color_depth(32);
- set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
- install_timer();
- install_keyboard();
- install_mouse();
- set_window_title("Coca-Defense Have Fun");
- exit_program = FALSE;
- LOCK_FUNCTION(fecha_programa);
- set_close_button_callback(fecha_programa);
- ticks = 0;
- LOCK_FUNCTION(tick_counter);
- LOCK_VARIABLE(ticks);
- install_int_ex(tick_counter, BPS_TO_TIMER(60));
- screen_state = TITLESCREEN;
- }
- void game_vitoria(){
- int exit_screen = FALSE;
- ///BITMAP
- BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
- BITMAP* win_game = load_bitmap("sprites/telas/vitoria/tela_vitoria.bmp", NULL);
- ///GAME LOOP
- while(!exit_program && !exit_screen){
- while(ticks > 0 && !exit_program && !exit_screen){
- if(key[KEY_ESC]){
- fecha_programa();
- }
- }
- draw_sprite(buffer, win_game, 0, 0);
- draw_sprite(screen, buffer, 0, 0);
- clear_to_color(buffer, makecol(255,255,255));
- ticks --;
- }
- destroy_bitmap(buffer);
- destroy_bitmap(win_game);
- }
- void game_derrota(){
- int exit_screen = FALSE;
- ///BITMAP
- BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
- BITMAP* lose_game = load_bitmap("sprites/telas/derrota/tela_derrota.bmp", NULL);
- ///GAME LOOP
- while(!exit_program && !exit_screen){
- while(ticks > 0 && !exit_program && !exit_screen){
- if(key[KEY_ESC]){
- fecha_programa();
- }
- }
- draw_sprite(buffer, lose_game, 0, 0);
- draw_sprite(screen, buffer, 0, 0);
- clear_to_color(buffer, makecol(255,255,255));
- ticks --;
- }
- destroy_bitmap(buffer);
- destroy_bitmap(lose_game);
- }
- void start_game(){
- int exit_screen = FALSE;
- ///BITMAPS
- BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
- BITMAP* tela_jogo = load_bitmap("sprites/caminho/background.bmp", NULL);
- BITMAP* cursor = load_bitmap("sprites/mouse_2.bmp", NULL);
- ///GAME LOOP
- while(!exit_program && !exit_screen){
- while(ticks > 0 && !exit_program && !exit_screen){
- if(key[KEY_ESC]){
- fecha_programa();
- }
- if(key[KEY_V]){
- game_vitoria();
- } else if(key[KEY_D]){
- game_derrota();
- }
- ///DRAW
- draw_sprite(buffer, tela_jogo, 0, 0);
- draw_sprite(buffer, cursor, mouse_x - 1, mouse_y - 1);
- draw_sprite(screen, buffer, 0, 0);
- clear_to_color(buffer, makecol(255,255,255));
- ticks --;
- }
- }
- destroy_bitmap(buffer);
- destroy_bitmap(tela_jogo);
- destroy_bitmap(cursor);
- }
- void mainmenu(){
- int exit_screen = FALSE;
- ///BITMAPS
- BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
- BITMAP* menu_principal = load_bitmap("sprites/telas/menu/menu_principal.bmp", NULL);
- BITMAP* botao_jogar = load_bitmap("sprites//telas/botoes/botao_jogar.bmp", NULL);
- BITMAP* botao_como_jogar = load_bitmap("sprites/telas/botoes/como_jogar.bmp", NULL);
- BITMAP* cursor = load_bitmap("sprites/mouse_2.bmp", NULL);
- ///GAME LOOP
- while(!exit_program && !exit_screen){
- while(ticks > 0 && !exit_program && !exit_screen){
- if(key[KEY_ESC]){
- fecha_programa();
- }
- ///DRAW
- draw_sprite(buffer, menu_principal, 0, 0);
- if(mouse_x > 305 && mouse_x < 498 && mouse_y > 405 && mouse_y < 462){ // permite começar o jogo
- draw_sprite(buffer, botao_jogar, 305, 405); // ao passar o mouse por cima, escurece o botão
- if(mouse_b == 1){
- mouse_b = 0;
- start_game();
- }
- }
- draw_sprite(buffer, cursor, mouse_x - 1, mouse_y - 1);
- draw_sprite(screen, buffer, 0, 0);
- clear_to_color(buffer, makecol(255,255,255));
- ticks --;
- }
- }
- destroy_bitmap(buffer);
- destroy_bitmap(menu_principal);
- destroy_bitmap(botao_jogar);
- destroy_bitmap(botao_como_jogar);
- destroy_bitmap(cursor);
- }
- void titlescreen(){
- int exit_screen = FALSE;
- ///BITMAPS
- BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H);
- BITMAP* tela_inicial = load_bitmap("sprites/telas/inicial/tela_inicial.bmp", NULL);
- BITMAP* cursor = load_bitmap("sprites/mouse_2.bmp", NULL);
- ///GAME LOOP
- while(!exit_program && !exit_screen){
- while(ticks > 0 && !exit_program && !exit_screen){
- ///IMPUT
- if(key[KEY_ENTER]){
- exit_screen = TRUE;
- screen_state = MAINMENU;
- }
- ///DRAW
- draw_sprite(buffer, tela_inicial, 0, 0);
- draw_sprite(buffer, cursor, mouse_x - 1, mouse_y - 1);
- draw_sprite(screen, buffer, 0, 0);
- clear_to_color(buffer, makecol(255,255,255));
- ticks --;
- }
- }
- destroy_bitmap(buffer);
- destroy_bitmap(tela_inicial);
- destroy_bitmap(cursor);
- }
- int main(){
- init();
- ///GAME LOOP
- while (!exit_program){
- if(screen_state == MAINMENU){
- mainmenu();
- } else if(screen_state == TITLESCREEN) {
- titlescreen();
- }
- }
- return 0;
- }
- END_OF_MAIN()
Advertisement
Add Comment
Please, Sign In to add comment