示例#1
0
CPanel::CPanel()
  : CComponent()
{
	font = alfont_load_font(GUI_FONT_FILENAME);
	alfont_set_font_size(font,45);
	caption = "";
	color = caption_color = 0;
}
示例#2
0
CPlayer::CPlayer(int x,int y,char *key_bindings_file,int solid)
{	
	set_config_file(key_bindings_file);
	key_left = get_config_int(NULL,"LEFT",0);
	key_right = get_config_int(NULL,"RIGHT",0);
	key_fire  = get_config_int(NULL,"FIRE",0);
	
	this->x = x;
	this->y = y;
	set_config_file(DEFAULT_PLAYER_CONFIG_FILE);
	bonus_frequency = default_bonus_frequency = get_config_int(NULL,"bonus_rate",5);
	more_bonuses_modifier = get_config_int(NULL,"more_bonuses_modifier",1);
	more_bonuses_duration = get_config_int(NULL,"more_bonuses_duration",10);
	
	move_speed = default_move_speed = get_config_int(NULL,"pad_speed",100);
	speed_modifier = get_config_int(NULL,"player_speed_modifier",5);
	
	set_color_conversion(COLORCONV_TOTAL);
	model = load_bitmap("/home/valo/Projects/breakin/graphics/batata.bmp",NULL);
	width = model->w;
	height = model->h;
	
	score = 0;
	last_scored = -30;
	bonus_points = 0;
	
	solid_walls = solid;
	
	immortal_time = get_config_int(NULL,"immortal_time",10);
	
	penetrating = false;
	penetration_time = get_config_int(NULL,"penetration_duration",10);
	
	ball_speed = default_ball_speed = get_config_int(NULL,"ball_speed",5);
	ball_speed_modifier = get_config_int(NULL,"ball_speed_modifier",10);
	
	fast_hit_max_time = get_config_float(NULL,"fast_hit_max_time",0.5);
	
	status_font1 = alfont_load_font(STATUS_FONT1_FILENAME);
	status_font2 = alfont_load_font(STATUS_FONT2_FILENAME);
	alfont_set_font_size(status_font1,50);
	alfont_set_font_size(status_font2,20);
}
示例#3
0
/***
  Function : install()
  Returns  : TRUE on succes, FALSE on failure
  Purpose  : Will install game variables, sets up the entire game.
***/
bool install()
{
    // Each time we run the game, we clear out the logbook
    FILE *fp;
    fp = fopen("log.txt", "wt");

    if (fp)
    {
        fprintf(fp, "Counter-Strike 2D Logbook\n");
        fprintf(fp, "-------------------------\n\n"); // print head of logbook
        fclose(fp);
    }

    logbook("--------------");
    logbook("Initialization");
    logbook("--------------");

    // init game
    map.init();
    game.init();
    steam.init();

    logbook("Creating entity types.");
    game.install_entities();

    // Logbook notification
    logbook("\n-------");
    logbook("Allegro");
    logbook("-------");


    // ALLEGRO - INIT
    if (allegro_init() != 0)
        return false;

    logbook(allegro_id);
    yield_timeslice();
    logbook("yield_timeslice()");

    int r = install_timer();
    if (r > -1) logbook("install_timer()");
    else
    {
        logbook("FAILED");
        return false;
    }

    alfont_init();
    logbook("alfont_init()");
    install_keyboard();
    logbook("install_keyboard()");
    install_mouse();
    logbook("install_mouse()");

    logbook("setting up timer functions / locking functions & memory");
    /* set up the interrupt routines... */
    LOCK_VARIABLE(RUNNING_TIMER_tenth);
    LOCK_VARIABLE(RUNNING_TIMER_fps);
    LOCK_FUNCTION(timer_tenth);
    LOCK_FUNCTION(fps_proc);

    install_int(timer_tenth, 10);
    install_int(fps_proc, 1000);

    logbook("Timers installed");

    frame_count = fps = 0;


    // set window title
    char title[80];
    sprintf(title, "Counter-Strike 2D");

    // Set window title
    set_window_title(title);
    char window_title[256];
    sprintf(window_title, "Window title set: [%s]", title);
    logbook(window_title);

    set_color_depth(16);      // run in 16 bit mode
    if (game.windowed)
    {
        int r = set_gfx_mode(GFX_AUTODETECT_WINDOWED, game.screen_x, game.screen_y, game.screen_x, game.screen_y);
        if (r > -1)
        {
            // Succes
        }
        else
        {
            // GFX_DIRECTX_ACCEL / GFX_AUTODETECT
            r = set_gfx_mode(GFX_DIRECTX_ACCEL, game.screen_x, game.screen_y, game.screen_x, game.screen_y);
            if (r > -1)
            {
                game.windowed = false;
                logbook("Could not enter windowed-mode; settings.d3 adjusted");
            }
            else
            {
                logbook("ERROR - !");
                return false;
            }
        }
    }
    else
    {
        int r = set_gfx_mode(GFX_AUTODETECT, game.screen_x, game.screen_y, game.screen_x, game.screen_y);

        // succes
        if (r > -1)
        {

        }
        else
        {
            logbook("ERROR - !!");
            return false;
        }

    }


    text_mode(0);

    logbook("Loading font data");
    // loading font

    game_font = alfont_load_font("gfx\\font\\tahoma.ttf");

    if (game_font != NULL)
    {
        alfont_set_font_size(game_font, 20); // set size
    }
    else
        allegro_message("Error loading tahoma.ttf!");

    // CS Font
    cs_font = alfont_load_font("gfx\\font\\cs.ttf");

    if (cs_font != NULL)
    {
        alfont_set_font_size(cs_font, 20); // set size
    }
    else
        allegro_message("Error loading cs.ttf");

    alfont_text_mode(-1);

    if (set_display_switch_mode(SWITCH_BACKGROUND) < 0)
    {
        set_display_switch_mode(SWITCH_PAUSE);
        logbook("Display 'switch and pause' mode set");
    }
    else
        logbook("Display 'switch to background' mode set");

    // sound
    logbook("Initializing sound");
    int s = install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);

    /***
     Bitmap Creation
     ***/

    bmp_screen = create_bitmap(game.screen_x, game.screen_y);

    if (bmp_screen == NULL)
    {
        logbook("ERROR: Could not create bitmap: bmp_screen");
        return false;
    }
    else
        logbook("Bitmap created: bmp_screen");

    bmp_collide = create_bitmap(game.screen_x, game.screen_y);

    if (bmp_collide == NULL)
    {
        logbook("ERROR: Could not create bitmap: bmp_collide");
        return false;
    }
    else
        logbook("Bitmap created: bmp_collide");

    /*** End of Bitmap Creation ***/

    // load datafiles
    graphics = load_datafile("graphics.dat");
    if (graphics == NULL)
    {
        logbook("ERROR: Could not load datafile: graphics.dat");
        return false;
    }
    else
        logbook("Datafile loaded: graphics.dat");

    // Shadows
    shadows = load_datafile("shadows.dat");
    if (shadows == NULL)
    {
        logbook("ERROR: Could not load datafile: shadows.dat");
        return false;
    }
    else
        logbook("Datafile loaded: shadows.dat");

    // HUD
    hud = load_datafile("hud.dat");
    if (hud == NULL)
    {
        logbook("ERROR: Could not load datafile: hud.dat");
        return false;
    }
    else
        logbook("Datafile loaded: hud.dat");

    //set_color_conversion(COLORCONV_NONE);
    set_color_conversion(COLORCONV_MOST);
    logbook("Color conversion method set");

    // setup mouse speed
    set_mouse_speed(2,2);

    logbook("Mouse speed set");

    logbook("");
    logbook("----");
    logbook("GAME ");
    logbook("----");

    game.LOAD_TexturesFromDataFile("data//de_aztec.dat");
//  DATA_Init();

    // randomize timer
    srand( (unsigned)time( NULL ) );

    //srand(time(NULL));

    // normal sounds are loud, the music is lower (its background music, so it should not be disturbing)
    set_volume(255, 200);

    set_trans_blender(128, 128, 128, 128);

    logbook("");
    logbook("--------------");
    logbook("BATTLE CONTROL");
    logbook("--------------");
    logbook("\n3...2...1... GO!\n");
    return true;
}
示例#4
0
bool Application::Init()
{
    // logfile
    if (ENABLE_LOGFILE)
    {
        logFile = fopen(LOGFILE,"w");
    }

    log("starting game\n");

    srand(time(NULL));

    // allegro
    log("initializing Allegro\n");

    if (allegro_init() != 0)
        return false;

    //
    // graphics
    //

    log("initializing graphics\n");

    set_color_depth(COLOR_DEPTH);

    int card;
    if (FULL_SCREEN)
        card = GFX_AUTODETECT_FULLSCREEN;
    else
        card = GFX_AUTODETECT_WINDOWED;

    if (set_gfx_mode(card,SCREEN_WIDTH,SCREEN_HEIGHT,0,0) != 0)
        return false;

    canvas = create_bitmap_ex(COLOR_DEPTH,screen->w,screen->h);
    if (canvas == NULL)
        return false;

    loadingImg = load_bitmap("data/loading.bmp",NULL);
    if (loadingImg == NULL)
        return false;
    blit(loadingImg,screen,0,0,0,0,screen->w,screen->h);

    //
    // font system
    //

    log("initializing font system\n");
    if (alfont_init() != ALFONT_OK)
        return false;

    font = alfont_load_font(FONT_FILE);
    if (font == NULL)
        return false;

    //
    // keyboard
    //

    log("initializing keyboard\n");

    if (install_keyboard() != 0)
        return false;

    memset(prevKeyState,0,256);

    //
    // mouse
    //

    log("initializing mouse\n");

    numMouseButtons = install_mouse();
    if (numMouseButtons < 0)
        return false;
    mouseButtons = new bool[numMouseButtons+1];
    prevMouseButtons = new bool[numMouseButtons+1];
    mousePressedLocs = new MousePos[numMouseButtons+1];

    for (int button = 0; button < numMouseButtons+1; button++)
    {
        mouseButtons[button] = false;
        prevMouseButtons[button] = false;
        mousePressedLocs[button].x = -1;
        mousePressedLocs[button].y = -1;
    }

    // timer
    log("initializing timer\n");

    if (install_timer() != 0)
        return false;

    //
    // sound
    //

    log("initializing base sound\n");

    if (install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL) != 0)
        return false;

    set_volume(ALLEGRO_SOUND_VOLUME,ALLEGRO_SOUND_VOLUME);

    // initialized successfully!
    log("initialization completed successfully\n");
    KeepRunning = true;
    return true;
}
int main( int argc, char *argv[] ) 
{
	int screenMode = GFX_AUTODETECT_WINDOWED;
	BITMAP *backbuf;
	
	TitleScreen *mode_titlescreen;
	CityMode *mode_city;

	bool showConsole = false;

	//args
	for (int i=1; i < argc; i++) {
		if (!strcmp(argv[i],"-fullscreen") ) {
			screenMode = GFX_AUTODETECT_FULLSCREEN;
		}
	}

	// Init alleg
	allegro_init();
	install_keyboard();
	install_mouse();
	set_color_depth( 16 );
	
	
	

	// Turn on the screeny goodness
	if (set_gfx_mode(screenMode, 640,480, 0, 0) != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set 640x480 graphic mode\n%s\n", allegro_error);
      return 1;
   }

	alfont_init();

	//set_color_conversion(COLORCONV_TOTAL);
	//drawing_mode(DRAW_MODE_TRANS, NULL,0,0);


	// fonts
	font_console = alfont_load_font("Graphics/fonts/ProFontWindows.ttf");
	alfont_set_font_size(font_console, 12);

	font_title = alfont_load_font("Graphics/fonts/AbductionIII.ttf");
	alfont_set_font_size( font_title, 24 );

	font_game = alfont_load_font("Graphics/fonts/archtura.ttf" );
	alfont_set_font_size( font_game, 24 );


	// screen 
	backbuf = create_bitmap( 640, 480 );
	rectfill( backbuf, 0,0, 640, 480, 0x0 );	
	
	SpriteGraphic *testgfx = new SpriteGraphic( "testship" );
	Sprite *test = new Sprite( testgfx );
	test->m_x = 10;
	test->m_y = 70;

	// game mode
	mode_titlescreen = new TitleScreen();
	mode_city = new CityMode();
	g_mode = mode_titlescreen;

	// init scripts
	script_init( font_console );

	// The main loop
	while (1) {

		if (g_mode) {
			g_mode->update();
		}

		g_mode->draw( backbuf );

#if 0
		// draw the game
		if (Map::g_activeMap) {
			Map::g_activeMap->draw( backbuf );
			
			// DBG: Map scrolling
			Map::g_activeMap->m_scroll = ((float)mouse_y / 480.0) * ((Map::g_activeMap->m_maphite-15)*32);

		} else {
			rectfill( backbuf, 0,0, 640, 480, 0x0 );
			alfont_textout_centre( backbuf, font_game, "Infection",  320, 200, makecol(200, 0, 0) );
		}

		// draw the sprites
		test->draw( backbuf );

		char buff[200];
		sprintf( buff, "testy %d m2s %d scroll %d", test->m_y, Map::mapYtoScreenY( test->m_y ), Map::getScroll() );
		alfont_textout( backbuf, font_console, buff,  320, 200, makecol(255,255,255) );
#endif

		// draw the console
		if (showConsole) {
			draw_console( backbuf );
		}

		// event handler
		if (keypressed()) {			

			int k = readkey();
			int kk = k >>8;

			// mode specific keypress
			g_mode->key_pressed( k );
			
			// global keypress
			if (kk==KEY_TILDE) {
				showConsole = !showConsole;
			} else if (showConsole) {
				// send key to console
				console_key( k );

			} else {
				switch(k>>8) {			
				
				case KEY_DOWN:
					test->m_y += 10;
					break;
				case KEY_UP:
					test->m_y -= 10;
					break;
				}

			}
		}

		

		if (key[KEY_ESC]) {
			//exit(0);
			break;
		}

		// Blit the screen
		vsync();
		acquire_screen();
		blit( backbuf, screen, 0, 0, 0, 0, 640, 480 );
		release_screen();

		yield_timeslice();
	}
	

	return 0;
}
示例#6
0
int main() {
	init();

    BITMAP *Buffer = create_bitmap(SCREEN_WIDTH ,SCREEN_HEIGHT);
    BITMAP *Tile_Set0 = load_bitmap("tiles0.bmp", NULL);
    
    BITMAP *p = load_bitmap("p1.bmp", NULL);
    
    
    ALFONT_FONT *fnt = alfont_load_font("dr.ttf");
    alfont_set_font_size(fnt, 40);
    
    Play P1;
    
    Fill_Mapa d,f;
    
    BITMAP *till_0[400];//imagens do tileset_0

  
 
    P_map(-48,0);//posicao do mapa na tela quando e desenhado
	T_Tile();//tamanho do tile padrao(16x16)  


  
	  	  d.C_Tiles(till_0,20,20,400,Tile_Set0,Buffer);//carega o tile_set
 
	while (!key[KEY_ESC]) {
		
		
		//----------------------------------------------------------------------
		 		  
		  Longit_Lat();//latitude e longitude do mapa em relacao ao ponto 0x0 da tela
          
		  d.Imp_Map(till_0,400,0,0,60,32,Buffer,map_1f,X_MAP*0.2,Y_MAP*0.2);//plano de fundo//'X_MAP*0.2' e 'Y_MAP*0.2' taixa de delocamento do mapa
          
		  d.Imp_Map(till_0,400,0,0,60,32,Buffer,map_1,X_MAP,Y_MAP);//mapa dos objetos a tras do pesonagem
          
	
	 
		  P1.Personagen(Buffer,p);
		  P1.Mov_Play(); 
		  //gravidade(4);       
		  
		  //d.Imp_Map(till_0,400,16,16,0,0,60,32,Buffer,map_1,X_MAP,Y_MAP);//mapa dos objetos a frente do pesonagem
          
		  d.Scoll_Map(320,240,58,32); //tacha de movimento do mapa   
		  
		  if(key[KEY_T])//testa o tile_set caregado
             d.Tile_test(till_0,20,20,Buffer);
		  
        //----------------------------------------------------------------------  
		
		 EnqPlay_Scrull(Buffer,makecol(255,0,0),208,0,480,448,0,480,0,160,640,0,448,640,1);
		 
		 textprintf_ex(Buffer,font,100,100,makecol(0,255,0),-1,"x_Mi: %d /y_Mi: %d",X_MAP,Y_MAP);
		 textprintf_ex(Buffer,font,100,120,makecol(0,255,0),-1,"Lon_Xi: %d /Lon_Yi: %d",Lon_Xi_MAP,Lon_Yi_MAP); 
		  textprintf_ex(Buffer,font,100,140,makecol(0,255,0),-1,"Lon_Xf: %d /Lon_Yf: %d",Lon_Xf_MAP,Lon_Yf_MAP); 
         //textprintf_ex(Buffer,font,100,140,makecol(0,255,0),-1,"PM_X: %d /PM_Y: %d",	mouse_x,mouse_y); 
		  //alfont_textprintf_ex(Buffer, fnt, 300, 90, makecol(255,0,0), -1, "Mario!");
		  //alfont_textprintf_centre_ex(Buffer, fnt, 300, 150, makecol(255,0,0), -1, "Mario!");
	
		//show_mouse(screen);//mostra o malse na tela
		//position_mouse(300,100);
        
        //rotate_sprite(Buffer,Buffer,0,0,DEGREES(450));
		
	//muda a escala da a imagem
	//stretch_blit(Buffer,screen,0,0,SCREEN_WIDTH ,SCREEN_HEIGHT,0,0,SCREEN_WIDTH_Z ,SCREEN_HEIGHT_Z);
	
	
        rest(60);//paralisa o programa por 'x' mile segundos       
        blit(Buffer,screen,0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT);//fixa o Buffer no screen
		clear(Buffer); 
	}
	
 	alfont_destroy_font(fnt);
    destroy_bitmap(Tile_Set0);
  
    for(int i=0;i<400;i++)
	     destroy_bitmap(till_0[i]);
   
    destroy_bitmap(Buffer);
    
	deinit();
	return 0;
}