rendered paste body#include "game.hpp"Game::Game() : ply(NULL){}/*** Initiates allegro etc.*/void Game::init(){ // Basic if(allegro_init() != 0); if(install_keyboard() != 0); // Install graphics set_color_depth(16); if(set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) { // Try windowed set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); } // Initialize the game running = true; _gs = MENU; // Init objects scr = new triple_buffer(); scr->init(); // Load datafile char path[200]; get_executable_name(path, sizeof(path)); replace_filename(path, path, "media.dat", sizeof(path)); data = load_datafile(path); if(!data) { // Something wrong } // Player ply = new Player(); ply->set_speed(6); ply->set_gravity(this->gravity); ply->set_wind(this->winds); ply->init(data);}void Game::deinit(){ // Deinit everything ... if(scr) { scr->deinit(); scr = NULL; } if(data) { unload_datafile(data); data = NULL; } if(ply) { ply = NULL; }}/*** Main loop and the rest*/void Game::run_game(){ init(); start_timer(); // Enter main loop while(running) { if(check_timer(fps) > 0) { while(check_timer(fps) > 0) { /* Logic */ /* Handle game states */ if(_gs == MENU) { // Menu // Shortcuts? if(key[KEY_S]) _gs = PLAYING; if(key[KEY_ESC]) _gs = EXIT; } else if(_gs == PLAYING) { // Game running // Process player ply->process(); } else if(_gs == PAUSE) { // Game paused } /* Misc. */ // F9 means a forced exit if(key[KEY_F9]) running = false; // Timer tick reset_timer(); } /* Drawing */ clear_to_color(scr->get_buffer(), makecol(99, 184, 255)); /* Check for game states */ if(_gs == MENU) { draw_sprite(scr->get_buffer(), (BITMAP*)data[background].dat, 0, 0); } else if(_gs == PLAYING) { // Draw the player line(scr->get_buffer(), 0, SCREEN_H-10, SCREEN_W, SCREEN_H-230, makecol(255,0,0)); ply->draw(scr->get_buffer()); } else if(_gs == PAUSE) { } // Print buffer to screen scr->update(); } else { // Give some CPU to the system rest(1); } } deinit();}