Exemplo n.º 1
0
void level_editor()
{
    int i,j;
    BITMAP* buffer;
    BITMAP* ecran_noir;
    char mot[50];
    mot[0]='c';
    mot[1]='\0';
    allegro_init();
    install_keyboard();
    install_mouse();
    set_color_depth(8);
    enable_hardware_cursor();
    BITMAP* affiche[15][19]={{load_bitmap("mur.bmp", NULL)}};
    ecran_noir= create_bitmap(192+5*32, 160);
    clear_to_color(ecran_noir, makecol(255, 255, 0));
    buffer= create_bitmap(TSPRITE*19, TSPRITE*15);
    if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, TSPRITE*19, TSPRITE*15, 0, 0)==0)
    {
    affiche[0][0]=load_bitmap("mur.bmp", NULL);
    for (i=0; i<15; i++)
    {
        for(j=0; j<19; j++){
                affiche[i][j]=affiche[0][0];
                if (affiche[i][j]!=NULL) draw_sprite(buffer, affiche[i][j], TSPRITE*j, TSPRITE*i);
        }
    }
    textprintf_ex(ecran_noir, font, 0, LIGNE, makecol(255,255,255),-1, "bienvenue sur l'editeur de niveau");
    draw_sprite(buffer, ecran_noir, 192-2*32, 160);
    blit(buffer, screen,0,0,0,0, 19*TSPRITE, 15*TSPRITE);
    rest(1100);
    menu(buffer, affiche, mot);
    destroy_bitmap(buffer);
    }
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
    allegro_init();
    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, SCRW, SCRH, 0, 0);
    install_keyboard();
    install_mouse();
    install_timer();

    LOCK_VARIABLE(timer);
    LOCK_FUNCTION(timerupdate);
    install_int_ex(timerupdate, BPS_TO_TIMER(TIMER_BPS));

    srand((unsigned)time(NULL));
    set_window_title("Skat");

    LOCK_FUNCTION(close_handler);
    set_close_button_callback(close_handler);

    cards = load_bitmap("images/cards.tga", NULL);
    game.p[0] = &human;
    game.p[1] = &cpu1;
    game.p[2] = &cpu2;
    human.choose_card = human_choose_card;
    cpu1.choose_card = cpu_choose_card;
    cpu2.choose_card = cpu_choose_card;
    human.choose_game = human_choose_game;
    cpu1.choose_game = cpu_choose_game;
    cpu2.choose_game = cpu_choose_game;
    human.reizen = human_reizen;
    cpu1.reizen = cpu_reizen;
    cpu2.reizen = cpu_reizen;
    human.schieben = human_schieben;
    cpu1.schieben = cpu_schieben;
    cpu2.schieben = cpu_schieben;
    human.kontra = human_kontra;
    cpu1.kontra = cpu_kontra;
    cpu2.kontra = cpu_kontra;
    human.name = "Stefan";
    cpu1.name = "Robert";
    cpu2.name = "Thomas";
    human.rtext = cpu1.rtext = cpu2.rtext = NULL;
    human.total_points = 0;
    cpu1.total_points = 0;
    cpu2.total_points = 0;

    enable_hardware_cursor();
    show_mouse(screen);

    buffered_do_dialog(main_dlg, -1);

    destroy_bitmap(cards);
}
Exemplo n.º 3
0
static bool CreateMainSurface(uint w, uint h)
{
	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
	if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
	set_color_depth(bpp);

	GetAvailableVideoMode(&w, &h);
	if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) {
		DEBUG(driver, 0, "Allegro: Couldn't allocate a window to draw on '%s'", allegro_error);
		return false;
	}

	/* The size of the screen might be bigger than the part we can actually draw on!
	 * So calculate the size based on the top, bottom, left and right */
	_allegro_screen = create_bitmap_ex(bpp, screen->cr - screen->cl, screen->cb - screen->ct);
	_screen.width = _allegro_screen->w;
	_screen.height = _allegro_screen->h;
	_screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bpp / 8);
	_screen.dst_ptr = _allegro_screen->line[0];

	/* Initialise the screen so we don't blit garbage to the screen */
	memset(_screen.dst_ptr, 0, _screen.height * _screen.pitch);

	/* Set the mouse at the place where we expect it */
	poll_mouse();
	_cursor.pos.x = mouse_x;
	_cursor.pos.y = mouse_y;

	BlitterFactoryBase::GetCurrentBlitter()->PostResize();

	InitPalette();

	char caption[32];
	snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision);
	set_window_title(caption);

	enable_hardware_cursor();
	select_mouse_cursor(MOUSE_CURSOR_ARROW);
	show_mouse(_allegro_screen);

	GameSizeChanged();

	return true;
}
optionsScreen::optionsScreen() 
{
	caret  = 0;
	insert = true;
	iter = edittext.begin();
	enable_hardware_cursor();

	menu = new menu_class();
	menu->addMenuOption("toggle path info",(int)MainApp::Instance()->viewPathInfo);
	menu->addMenuOption("toggle clock",(int)MainApp::Instance()->viewClock);
	menu->addMenuOption("toggle workout timer",(int) MainApp::Instance()->viewWorkoutTimer);
	menu->addMenuOption("toggle image memory",(int)MainApp::Instance()->useImageMemory);
	menu->addMenuOption("image selection type", MainApp::Instance()->dirSelectionForDisplay);
	menu->addMenuOption("image display timer", MainApp::Instance()->imageDisplayTimeLength);
	menu->addMenuOption("num image to remember", MainApp::Instance()->imageMemAmt);

	menu->set_menu_positions(GraphicsProxy::getScreenWidth()/2, GraphicsProxy::getScreenHeight()/3, 25, makecol(255, 255, 255), makecol(0, 255, 0));

	infoImg = new RenderObject(0,0,900,30);

	renderer.init(GraphicsProxy::getScreenWidth(), GraphicsProxy::getScreenHeight());
	//renderer.addToRenderList(infoImg);
	renderer.addToRenderList(menu);
}
int main( int argc, char *argv[] )
{
    BITMAP *lobuf;
    BITMAP *backbuf;    

#ifndef NDEBUG
    // Create a win32 console for printfing
	AllocConsole();

	freopen("CONIN$","rb",stdin);   // reopen stdin handle as console window input
	freopen("CONOUT$","wb",stdout);  // reopen stout handle as console window output
	freopen("CONOUT$","wb",stderr); // reopen stderr handle as console window output
#endif

    //----- Game stuff ---------------

	// the map of the world
    TileMap map( 300 );

	// the chunks of land
	std::vector<TileMap*> landChunks;

    set_color_depth( 32 );

    if (allegro_init() != 0) return 1;
    
    install_keyboard();
    install_timer();
	install_mouse();	

	// install ticker
	LOCK_VARIABLE( ticks );
	LOCK_FUNCTION( ticker );
	install_int_ex( ticker, BPS_TO_TIMER( UPDATES_PER_SEC ) );
    
    if (set_gfx_mode( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 ) != 0)
    {
        set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
        allegro_message( "Unable to set graphics mode:\n%s\n", 
                         allegro_error );
        return 1;
    }

	enable_hardware_cursor();
	select_mouse_cursor( MOUSE_CURSOR_ARROW );
	

    lobuf = create_bitmap( 320, 240 );    
    backbuf = create_bitmap( SCREEN_W, SCREEN_H );
	show_mouse( backbuf );

//    printf("lobuf %p backbuf %p\n", lobuf, backbuf );    
        
	

    // init gameplay stuff
	srand( time(0));

    //printf("init map...\n" );    
    map.init();
    map.reset();    
	map.do_water = true;

	message( "I woke near the ocean. I didn't even know my own name." );
	message( "So I started exploring (drag RMB to scroll)");

	// load chunks
	loadLandChunks( "gamedata/land.txt", landChunks );
	map.paste( landChunks[0], 148, 148 );

    map.enableSelect( lobuf );   

	// make player
	BITMAP *npcCodeMask = load_bitmap( "gamedata/code_npc.bmp", NULL );
	BITMAP *critterCodeMask = load_bitmap( "gamedata/code_critter.bmp", NULL );
	BITMAP *playerBmp = make_pixbot( npcCodeMask );		

	// Init game objects
	std::vector<GameObj*> gameObjs;

	Player *player = new Player();
	player->m_bmp = playerBmp;
	player->m_x = 150;
	player->m_y = 148;
	gameObjs.push_back( player );
	int currTool = Tool_WALK;	

    //printf("--- mainloop\n" );   
    bool done = false;
	bool dbgShowSelects = false;

	// near center on a 300x300 map
	int view_x = -1644, 
		view_y = -800;
	bool dragging = false;
	int drag_x, drag_y; 	
	int view_drag_x, view_drag_y; 
	int mouse_x2, mouse_y2; // in lobuf coords	
	int last_b = 0;
	int px, py;
	bool doGenerate = true;

    while (!done)
    {
		// handle ticks -- give the ticker a chance to start
		while( ticks==0)
		{
			rest(100 / UPDATES_PER_SEC );
		}
		while ( ticks > 0)
		{
			int old_ticks = ticks;			
			
			//=== Update ====
			map.m_wave_offs++;
						
			if (messageTime>0)
			{
				messageTime--;
				if (messageTime==0)
				{
					strcpy( messageText, "" );					
				}
			} else {
				if (!messageQueue.empty())
				{
					strcpy( messageText, messageQueue.front().c_str() );
					messageQueue.pop_front();
					messageTime = MSG_TIME;
				}
			}

			for (int i=0; i < gameObjs.size(); ++i )
			{
				if (gameObjs[i])
				{
					gameObjs[i]->update( map, gameObjs );				
				}
			}

			// update may have NULL'd objects
			std::vector<GameObj*>::iterator removed;
			removed = std::remove( gameObjs.begin(), gameObjs.end(), (GameObj*)NULL );
			gameObjs.erase( removed, gameObjs.end() );
			

			// update bubbles
			for (int i=0; i < bubbles.size(); i++)
			{
				bubbles[i]->bub_age += 1.0 / (float)UPDATES_PER_SEC;
			}

			ticks--;
			if (old_ticks <= ticks) break;
		}

		int dropBubble = -1;

		// keyboard input
        if (keypressed())
        {
			int k = readkey();
			
			if (cheatsEnabled)
			{
				switch(k>>8) 
				{
					//---- debug keys
					case KEY_F5:
						dbgShowSelects = !dbgShowSelects;
						break;
					case KEY_F6:
						playerBmp = make_pixbot( npcCodeMask );	
						player->m_bmp = playerBmp;
						break;
					case KEY_F7:
						bubbles.push_back( create_bubble( landChunks ) );
						break;
				}				
			}

			switch(k>>8) {			            
				
				case KEY_F11:
					cheatsEnabled = true;
					message("Cheats enabled.");
					break;
				
				//---- game keys
				case KEY_1: dropBubble = 0; break;				
				case KEY_2: dropBubble = 1; break;
				case KEY_3: dropBubble = 2; break;
				case KEY_4: dropBubble = 3; break;
				case KEY_5: dropBubble = 4; break;

				// hack -- on keydown, clear walk wait counter
				case KEY_LEFT:
				case KEY_RIGHT:
				case KEY_UP:
				case KEY_DOWN:
					player->walk_c = 0;
					break;

			}
        }

		if ((dropBubble >= 0) && (dropBubble < bubbles.size()) )
		{
			TileMap *bub = bubbles[dropBubble];
			bubbles[dropBubble] = bubbles[ bubbles.size() -1 ];
			bubbles.pop_back();

			map.paste( bub, 
					   player->m_x - bub->m_size/2, 
					   player->m_y - bub->m_size/2 );
			doGenerate = true;
			delete bub;
		}

		// generate entities
		if (doGenerate)
		{
			doGenerate = false;			

			for (int i=0; i < map.m_size; i++)
			{
				for (int j=0; j < map.m_size; j++)
				{
					if (map.map(i,j).m_gen != Gen_NONE )
					{						
						if (map.map(i,j).m_gen == Gen_BUBBLE)
						{							
							BubbleObj *bubObj = new BubbleObj();
							bubObj->m_x = i;
							bubObj->m_y = j;
							bubObj->m_bub = create_bubble( landChunks );
							bubObj->m_bmp = create_bitmap( 15, 15 );
							BITMAP *bubBmp = bubObj->m_bub->bub_bmp;
							stretch_blit( bubBmp, bubObj->m_bmp, 0,0, bubBmp->w, bubBmp->h, 0,0, 15, 15 );

							gameObjs.push_back( bubObj );
						} else if (map.map(i,j).m_gen == Gen_CRITTER) {
							CritterObj *critObj = new CritterObj();
							critObj->m_x = i;
							critObj->m_y = j;				

							BITMAP *critpic;
							int critNdx = rand() % (critterBmps.size()+1);
							if (critNdx == critterBmps.size())
							{
								// yay new critter
								critpic = make_pixbot( critterCodeMask );
								critterBmps.push_back( critpic );
							}
							else
							{
								critpic = critterBmps[ critNdx ];
							}

							critObj->m_bmp = critpic;

							gameObjs.push_back( critObj );

						} else if (map.map(i,j).m_gen == Gen_NPC) {
							NpcObj *npc = new NpcObj();
							npc->m_x = i;
							npc->m_y = j;							
							npc->m_bmp = make_pixbot( npcCodeMask );							

							gameObjs.push_back( npc );
						}

						map.map(i,j).m_gen = Gen_NONE;
					}
				}
			}
		}
		
		// check for quit
		if (key[KEY_ESC]) {
			exit(0);
			break;
		}

		player->walk_x = 0; player->walk_y = 0;
		if (key[KEY_UP] && !key[KEY_DOWN])
		{
			player->walk_x = 0; player->walk_y = 1;
		}
		else if (!key[KEY_UP] && key[KEY_DOWN])
		{
			player->walk_x = 0; player->walk_y = -1;
		}
		else if (!key[KEY_LEFT] && key[KEY_RIGHT])
		{
			player->walk_x = -1; player->walk_y = 0;
		}
		else if (key[KEY_LEFT] && !key[KEY_RIGHT])
		{
			player->walk_x = 1; player->walk_y = 0;
		}
				
        // Map cursor
		char buff[246];
		int mapX, mapY;
		map.clearSelected();

		mouse_x2 = mouse_x/2;
		mouse_y2 = mouse_y/2;
		if (map.screenToMap( mouse_x2, mouse_y2, mapX, mapY ))
		{
			sprintf( buff, "V %d %d x y %d %d [%d]  -- map %d %d", 
					view_x, view_y, mouse_x, mouse_y, mouse_b, mapX, mapY );

			// NOTE: Don't use mouse selection anymore -- just use selection
			// to mark player
			//map.map( mapX, mapY ).m_selected = true;
		}
		else
		{
			sprintf( buff, "V %d %d x y %d %d  NO TILE", 
					view_x, view_y, mouse_x, mouse_y );
		}

		map.map( player->m_x, player->m_y ).m_selected = true;

		

		// Mouse button 2 -- drag
		if (mouse_b & 0x2)
		{
			if (!dragging)
			{
				dragging = true;
				drag_x = mouse_x2;
				drag_y = mouse_y2;
				view_drag_x = view_x;
				view_drag_y = view_y;
			}
			else
			{
				int dx = mouse_x2 - drag_x;
				int dy = mouse_y2 - drag_y;
				view_x = view_drag_x + dx;
				view_y = view_drag_y + dy;

			}
		}
		else
		{
			dragging = false;
		}

		// button 1 -- use tool (or walk)		
		if (mouse_b & 0x1)
		{
			switch( currTool)
			{
			case Tool_WALK:
				{
					MapCell &cell = map.map(player->m_x, player->m_y );					
					px = cell.sx + 4;
					py = cell.sy + 10;
					
					if ((px < mouse_x2) && (py < mouse_y2 ))
					{
						player->walk_x = -1; player->walk_y = 0;
					}
					else if ((px > mouse_x2) && (py > mouse_y2 ))
					{
						player->walk_x = 1; player->walk_y = 0;
					}
					else if ((px > mouse_x2) && (py < mouse_y2 ))
					{
						player->walk_x = 0; player->walk_y = -1;
					}
					else if ((px < mouse_x2) && (py > mouse_y2 ))
					{
						player->walk_x = 0; player->walk_y = 1;
					}
				}
				break;
			}
		}
		else
		{
			switch( currTool )
			{
			case Tool_WALK:
				if (last_b & 0x01)
				{
					player->walk_x = 0;
					player->walk_y = 0;
				}
				break;
			}
		}
		last_b = mouse_b;

		// ==== draw =====
		rectfill( lobuf, 0, 0, 320, 240, makecol( 135, 171, 189 ) );
        //map.draw( lobuf, 10, 30 );
        map.draw( lobuf, view_x, view_y, gameObjs );        

		// draw bubbles
		int bx = 160 - (bubbles.size() * 12);
		char buf[10];
		for (int i=0; i < bubbles.size(); i++)
		{
			TileMap *b = bubbles[i];
			draw_sprite( lobuf, b->bub_bmp, 
				bx,  215 - (int)(sin(b->bub_age * M_PI)*3) );

			sprintf( buf,"%d", i+1 );
			textout_centre_ex( lobuf, font, buf, bx + 13, 231, makecol( 0x44, 0x66, 0x77 ), -1);
			textout_centre_ex( lobuf, font, buf, bx + 12, 230, makecol( 0xff, 0xff, 0xff ), -1);

			bx += 24;
		}

		//DBG draw player
		//masked_stretch_blit( playerBmp, lobuf, 0, 0, playerBmp->w, playerBmp->h,
		//								10, 20, playerBmp->w * 4, playerBmp->h * 4 );				

        // scale buffer to screen
		stretch_blit( dbgShowSelects?map.m_selectMap:lobuf, backbuf, 
                      0, 0, lobuf->w, lobuf->h,
                      0, 0, SCREEN_W, SCREEN_H );        
        
        
		// Draw text and stuff at full res
		//masked_blit( bubbles[0]->bub_bmp, backbuf, 0, 0, 50, 20, 
		//			 bubbles[0]->bub_bmp->w, bubbles[0]->bub_bmp->h );

		//textout( backbuf, font, buff, 10, 10, makecol( 0xff, 0xff, 0xff ) );

		drawing_mode( DRAW_MODE_TRANS, NULL, 0, 0 );
		set_trans_blender( 0, 0, 0, 128 );
		rectfill( backbuf, 0, 7, 640, 75, makecol( 0xff, 0xff, 0xff ) );
		solid_mode();
		hline( backbuf, 0, 7, 640, makecol( 0, 0, 0x77 ) );
		hline( backbuf, 0, 75, 640, makecol( 0, 0, 0x77 ) );

		// player icon
		masked_stretch_blit( playerBmp, backbuf, 0, 0, playerBmp->w, playerBmp->h,
												10, 10, playerBmp->w * 4, playerBmp->h * 4 );

		//party icons
		for (int i=0; i < npcs.size(); i++)
		{
			BITMAP *npcBmp = npcs[i]->m_bmp;
			masked_stretch_blit( npcBmp, backbuf, 0, 0, npcBmp->w, npcBmp->h,
													70 + 45*i, 10, npcBmp->w * 4, npcBmp->h * 4 );
		}

		if (strlen(messageText))
		{
			float t = (float)messageTime / MSG_TIME;			

			//textout_centre_ex( backbuf, font, messageText, 322, 62, makecol( 0x44, 0x66, 0x77 ), -1 );
			textout_centre_ex( backbuf, font, messageText, 320, 60, 
									makecol( lerp( t, 0x00, 0xcc ), 
											 lerp( t, 0x00, 0xcc ), 
											 lerp( t, 0x00, 0xcc ) ), -1 );
				//makecol( 0x44, 0x66, 0x77 ),
				//makecol( 0xff, 0xff, 0xff ), -1 );
		}

        // flip screen
		vsync();
		acquire_screen();		
        blit( backbuf, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H );        
		release_screen();

		yield_timeslice();
    }

    return 0;
    
}