// returns true when clicked on it bool cSteam::ButtonDraw(BITMAP *dest, int x, int y, int width, int height, char *title) { bool result=false; if (width < 12) width = 12; if (height < 12) height = 12; rectfill(dest, x, y, x+width, y+height, makecol(76,88,68)); // now draw lines line(dest, x, y, x+(width), y, makecol(136,145,128)); line(dest, x, y, x, y+(height), makecol(136,145,128)); line(dest, x+(width), y, x+(width), y+(height), makecol(40,46,34)); line(dest, x, y+(height), x+(width), y+(height), makecol(40,46,34)); // now draw text alfont_set_font_size(game_font, 14); // set size int color = COLOR_GREY; if ((mouse_x > x && mouse_x < (x+width)) && (mouse_y > y && mouse_y < (y+height))) { color = COLOR_WHITE; if (game.MOUSE_PRESSED_LEFT()) result = true; } alfont_textprintf(dest, game_font, x+2, y+2,color, title); return result; }
CPanel::CPanel() : CComponent() { font = alfont_load_font(GUI_FONT_FILENAME); alfont_set_font_size(font,45); caption = ""; color = caption_color = 0; }
// draw a nice steam colored window void cSteam::WindowDraw(BITMAP *dest, int x, int y, int width, int height, char *title) { // Draw a neat looking window. // Minimum sizes are: 32x32 if (width < 32) width=32; if (height < 32) height=32; // first draw 'the 4' (corners) // UP LEFT draw_sprite(dest, (BITMAP *)graphics[STEAM_UPLEFT].dat, x, y); // UP RIGHT draw_sprite(dest, (BITMAP *)graphics[STEAM_UPRIGHT].dat, x+(width-16), y); // DOWN LEFT draw_sprite(dest, (BITMAP *)graphics[STEAM_DOWNLEFT].dat, x, y+(height-16)); // DOWN RIGHT draw_sprite(dest, (BITMAP *)graphics[STEAM_DOWNRIGHT].dat, x+(width-16), y+(height-16)); // draw the 'bars' line(dest, x+16, y, x+(width-16), y, makecol(136,145,128)); line(dest, x, y+16, x, y+(height-16), makecol(136,145,128)); line(dest, x+(width), y+16, x+(width), y+(height-16), makecol(40,46,34)); line(dest, x+16, y+(height), x+(width-16), y+(height), makecol(40,46,34)); // Fill it // middle rectfill(dest, x+16, y+16, x+(width-16), y+(height-16), makecol(76,88,68)); // up rectfill(dest, x+16, y+1, x+(width-16), y+16, makecol(76,88,68)); // down rectfill(dest, x+16, y+(height-16), x+(width-16), y+(height-1), makecol(76,88,68)); // left rectfill(dest, x+1, y+16, x+16, y+(height-16), makecol(76,88,68)); // right rectfill(dest, x+(width-16), y+16, x+(width-1), y+(height-16), makecol(76,88,68)); // title: // size of text = 12 alfont_set_font_size(game_font, 14); // set size alfont_textprintf(dest, game_font, x+17, y+2,makecol(255,255,255), title); // devide bar line(dest, x+17, y+17, x+(width-17), y+17, makecol(40,46,34)); line(dest, x+17, y+18, x+(width-17), y+18, makecol(136,145,128)); // ... }
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); }
/*** 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; }
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; }
void WireNews::update( float dt ) { Panel::update( dt ); if (m_nextHeadlineTime > dt) { m_nextHeadlineTime -= dt; } else { // time for a new headline (if we're not already full if (m_heads.size() < 5 ) { Headline *h = new Headline(); // copy the headline info over *h = m_hpool->m_headlines[ rand() % m_hpool->m_headlines.size() ]; // make a headling image h->m_wirePic = create_bitmap( 250, 50 ); //rectfill( h->m_wirePic, 0, 0, 250, 50, makecol32( 0, 0, 200 ) ); blit( m_hblank, h->m_wirePic, 0, 0, 0, 0, 250, 50 ); h->m_currY =-50; std::string hs = h->m_text; int txty = 5; alfont_set_font_size( g_fontWireHeadline, 12 ); std::vector<std::string> sline; boost::algorithm::split( sline, h->m_text, boost::algorithm::is_any_of(" \t"), boost::algorithm::token_compress_on ); for (int i = 0; i < sline.size(); i++ ) { std::cout << i << " -- " << sline[i] << std::endl; } int sndx = 0; bool firstline = true; while( sndx < sline.size() ) { std::string ln; std::string sWord = sline[ sndx ]; while ( alfont_text_length( g_fontWireHeadline, (ln + " " + sWord).c_str() ) < ( 240 - (firstline?15:0) ) ) { ln += " "; ln += sWord; sndx++; if (sndx < sline.size() ) { sWord = sline[ sndx ]; } } firstline = false; alfont_textout( h->m_wirePic, g_fontWireHeadline, ln.c_str(), 7, txty +2, makecol( 44, 122, 176 ) ); alfont_textout( h->m_wirePic, g_fontWireHeadline, ln.c_str(), 5, txty, makecol( 255, 255, 255 ) ); txty += 12; } alfont_set_font_size( g_fontWireTiny, 10 ); alfont_textout( h->m_wirePic, g_fontWireTiny, h->m_src.c_str(), 8, 35, makecol32( 158, 210, 244 ) ); alfont_textout_right( h->m_wirePic, g_fontWireTiny, h->m_mediaSrc.c_str(), 250-8, 35, makecol32( 158, 210, 244 ) ); //rect( h->m_wirePic, 0, 0, 249, 49, makecol32( 0, 255, 255 ) ); // add to list m_heads.push_back( h ); m_nextHeadlineTime = 10.0f; } } // update yvals for (int i=0; i < m_heads.size(); i++) { int targY = 200-(i*50); if (m_heads[i]->m_currY > targY) m_heads[i]->m_currY--; if (m_heads[i]->m_currY < targY) m_heads[i]->m_currY++; } }
void cSteam::DrawMenuItems(int x, int y, int iMenu, bool bActive) { tMenuItem MENU_Items[10]; // max of 10 options unsigned int iWidth=0; // initialize menu stuff for (int i=0; i < 10; i++) { MENU_Items[i].iMainState = -1; MENU_Items[i].iSubState = -1; memset(MENU_Items[i].text, 0, sizeof(MENU_Items[i].text)); } // Main Menu if (iMenu == 0) { // copy the menu items for (int i=0; i < 6; i++) { MENU_Items[i].iMainState = MENU_MainMenu[i].iMainState; MENU_Items[i].iSubState = MENU_MainMenu[i].iSubState; memcpy(MENU_Items[i].text, MENU_MainMenu[i].text, sizeof(MENU_MainMenu[i].text)); if (strlen(MENU_Items[i].text) > iWidth) iWidth = strlen(MENU_Items[i].text); } } // any other menu else if (iMenu == 1) { // copy the menu items for (int i=0; i < 6; i++) { MENU_Items[i].iMainState = MENU_OptionsMenu[i].iMainState; MENU_Items[i].iSubState = MENU_OptionsMenu[i].iSubState; memcpy(MENU_Items[i].text, MENU_OptionsMenu[i].text, sizeof(MENU_OptionsMenu[i].text)); if (strlen(MENU_Items[i].text) > iWidth) iWidth = strlen(MENU_Items[i].text); } } else if (iMenu == 2) { // copy the menu items for (int i=0; i < 6; i++) { MENU_Items[i].iMainState = MENU_IngameMenu[i].iMainState; MENU_Items[i].iSubState = MENU_IngameMenu[i].iSubState; memcpy(MENU_Items[i].text, MENU_IngameMenu[i].text, sizeof(MENU_IngameMenu[i].text)); if (strlen(MENU_Items[i].text) > iWidth) iWidth = strlen(MENU_Items[i].text); } } else if (iMenu == 3) { // copy the menu items for (int i=0; i < 10; i++) { MENU_Items[i].iMainState = EDITOR_MainMenu[i].iMainState; MENU_Items[i].iSubState = EDITOR_MainMenu[i].iSubState; memcpy(MENU_Items[i].text, EDITOR_MainMenu[i].text, sizeof(EDITOR_MainMenu[i].text)); if (strlen(MENU_Items[i].text) > iWidth) iWidth = strlen(MENU_Items[i].text); } } alfont_set_font_size(game_font, 14); // set size int iTextY=y; // Now draw / print / react etc for (int id=0; id < 10; id++) { // valid if (strlen(MENU_Items[id].text) > 0) { // draw this thing on the screen int iColor=COLOR_GREY; if (strcmp(MENU_Items[id].text, "-") == 0) { // devide bar line(bmp_screen, x, iTextY+7, x+(iWidth*8), iTextY+7, makecol(40,46,34)); line(bmp_screen, x, iTextY+8, x+(iWidth*8), iTextY+8, makecol(136,145,128)); iTextY += 14; } else { if (bActive) { // determine if mouse is over this one int iWidth = strlen(MENU_Items[id].text) * 8; if ((mouse_x > x && mouse_x < (x+iWidth)) && (mouse_y > iTextY && mouse_y < (iTextY+12))) iColor = COLOR_WHITE; } alfont_textprintf(bmp_screen, game_font, x, iTextY, iColor, MENU_Items[id].text); iTextY += 14; if (iColor == COLOR_WHITE) if (game.MOUSE_PRESSED_LEFT()) { iMainState = MENU_Items[id].iMainState; iSubState = MENU_Items[id].iSubState; } } // its not a devider } } }
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; }