Пример #1
0
void handle_evbl(void){
	static long last=0;
	static int rest_cnt=0;
	int i;

	#ifndef ALLEGRO_DOS
	yield_timeslice();
	#endif
	i = (15*app_data.speed/100);
	rest_cnt = (rest_cnt+1)%(i<5?5:i);
	#ifdef ALLEGRO_WINDOWS
	if (rest_cnt==0) rest(1);
	#endif
	last_line=0;
	master_clk -= evblclk;
	frame++;
	if (!app_data.debug) {
		finish_display();
	}

    if (app_data.crc == 0xA7344D1F)
                      {for (i=0; i<140; i++)
                           {
		                   ColorVector[i] = (VDCwrite[0xA3] & 0x7f) | (p1 & 0x80);
		                   AudioVector[i] = VDCwrite[0xAA];
                           }      
                      }/*Atlantis*/
                      else
                      for (i=0; i<MAXLINES; i++)  {
                      ColorVector[i] = (VDCwrite[0xA3] & 0x7f) | (p1 & 0x80);
	                  AudioVector[i] = VDCwrite[0xAA];
                      }

                      
    if (key2vcnt++ > 10) {
		key2vcnt=0;
		for (i=0; i<128; i++) key2[i] = 0;
		dbstick1 = dbstick2 = 0;
	}
	if (app_data.limit) {
		long d,f;
		d = (TICKSPERSEC*100)/(app_data.speed*fps);
		f = ((d-gettimeticks()+last)*1000)/TICKSPERSEC;
		if (f>0) {
			#ifdef ALLEGRO_WINDOWS
				f = f-(f%10);					
				if (f>5) rest(f-5);
			#else
				#ifndef ALLEGRO_DOS
					yield_timeslice();
				#endif
			#endif
		}
		while (gettimeticks() - last < d);
		last = gettimeticks();
	}
	mstate=0;
    
}
Пример #2
0
void handle_evbll(void){
	static long last=0;
	static int rest_cnt=0;
	int i;

	#ifndef ALLEGRO_DOS
	yield_timeslice();
	#endif
	i = (15*app_data.speed/100);
	rest_cnt = (rest_cnt+1)%(i<5?5:i);
	#ifdef ALLEGRO_WINDOWS
	if (rest_cnt==0) rest(1);
	#endif

/******************* 150 */

    for (i=150; i<MAXLINES; i++)  {
		ColorVector[i] = (VDCwrite[0xA3] & 0x7f) | (p1 & 0x80);
		AudioVector[i] = VDCwrite[0xAA];
	}

	if (key2vcnt++ > 10) {
		key2vcnt=0;
		for (i=0; i<128; i++) key2[i] = 0;
		dbstick1 = dbstick2 = 0;
	}
	if (app_data.limit) {
		long d,f;
		d = (TICKSPERSEC*100)/(app_data.speed*fps);
		f = ((d-gettimeticks()+last)*1000)/TICKSPERSEC;
		if (f>0) {
			#ifdef ALLEGRO_WINDOWS
				f = f-(f%10);					
				if (f>5) rest(f-5);
			#else
				#ifndef ALLEGRO_DOS
					yield_timeslice();
				#endif
			#endif
		}
		while (gettimeticks() - last < d);
		last = gettimeticks();
	}
	mstate=0;	
}
Пример #3
0
// waits for x millis or ESC
void esc_rest(int millis) {
	int clicks = millis / 20;
	int count = 0;
	while(count < clicks && !key[KEY_ESC]) {
		cycle_count = 0;
		poll_music();
		count ++;
		while(!cycle_count);
		yield_timeslice();
	}
    if (key[KEY_ESC]) script_done = -1;
}
Пример #4
0
void cmd_run(Ttoken *t) {
	Tscript_object *o;
	int loops;
	static int i = 0;

	loops = atoi(t->word);

	cycle_count = 0;
	while(loops && !script_done) {

		while(cycle_count > 0 && loops && !script_done) {
			logic_count ++;

			poll_music();

			// update objects
			o = objects;
			while(o != NULL) {
				if (!o->line) {
					o->x += o->vx;
					o->y += o->vy;
				}
				o = (Tscript_object *) o->next;
			}

			if (key[KEY_ESC]) script_done = -1;

			i ++;
			loops --;
			cycle_count --;
		}

		// let other processes play
		yield_timeslice();

		// blit buffer to swap buffer
		blit(buffer, swap_buffer, 0, 0, 0, 0, 160, 120);
		
		// draw objects
		o = objects;
		while(o != NULL) {
			if (o->bmp[0] != NULL) {
				int frame = (o->frames ? logic_count % o->frames : 0);
				if (o->dir == 1)
					draw_sprite_h_flip(swap_buffer, o->bmp[frame], o->x, o->y);
				else if (o->dir == 0)
					draw_sprite(swap_buffer, o->bmp[frame], o->x, o->y);
				else // rotate
					rotate_sprite(swap_buffer, o->bmp[frame], o->x, o->y, itofix(-8*i));
			}
			else if (o->line) {
				line(swap_buffer, ((Tscript_object *)o->line_from)->x + o->x,
					((Tscript_object *)o->line_from)->y + o->y,
					((Tscript_object *)o->line_to)->x + o->vx,
					((Tscript_object *)o->line_to)->y + o->vy,
					1);
			}
			o = (Tscript_object *) o->next;
		}
		
		// blit to screen
		blit_to_screen(swap_buffer);
	}
	
}
Пример #5
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;
}
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;
    
}
Пример #7
0
void AGSDOS::YieldCPU() {
  yield_timeslice();
}
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;
}
Пример #9
0
int main (void) {
    allegro_init();
    install_keyboard();
    install_timer();

    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, SCREENX*SCALE, SCREENY*SCALE, 0, 0);
    set_window_title("Ultra Tank Destruction Battle Game");
    BITMAP * buffer = create_bitmap(SCREEN_W, SCREEN_H);

    install_int_ex(ticker, BPS_TO_TIMER(30));


    int tankx = 0, tanky = 0;
    int speed = 1;
    int tanksizex = 16, tanksizey = 16;
    int tankframe = 0, tankdir = 0;
    int walking = 0, shooting = 0;

    int xoffset = 0, yoffset = 0;

    int bullet = 0, bulletspeed = 3;
    int bulleton[BULLETS], bulletx[BULLETS], bullety[BULLETS], bulletspeedx[BULLETS], bulletspeedy[BULLETS];
    int shot = 0;

    int level[LEVELSIZEX*LEVELSIZEY] =
        {   2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,3,2,2,2,2,2,2,5,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            3,3,3,3,3,3,3,3,3,3,3,2,4,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,5,2,2,2,2,3,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,

            2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,3,2,2,2,2,2,2,5,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            3,3,3,3,3,3,3,3,3,3,3,2,4,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,5,2,2,2,2,3,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,

            2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,3,2,2,2,2,2,2,5,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            3,3,3,3,3,3,3,3,3,3,3,2,4,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,5,2,2,2,2,3,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,

            2,2,2,2,5,4,2,2,2,2,3,2,2,5,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            5,2,2,2,4,2,2,2,2,2,3,2,2,4,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            4,2,2,2,2,2,2,2,5,2,3,3,3,3,3,3,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,
            2,2,2,2,2,2,2,2,4,2,3,2,2,2,2,2,    2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,     };

    for (int i = 0; i < BULLETS; i++) {
        bulleton[i] = 0;
        bulletx[i] = 0;
        bullety[i] = 0;
        bulletspeedx[i] = 0;
        bulletspeedy[i] = 0;
    }


    BITMAP * tank = load_bitmap("mechtest/extremetankn.bmp", NULL);
    BITMAP * bulletimg = load_bitmap("mechtest/bullet.bmp", NULL);
    BITMAP * tilemap = load_bitmap("mechtest/tilemap.bmp", NULL);


    int running = 1;
    while (running) {

        rectfill(buffer, 0, 0, SCREEN_W-1, SCREEN_H-1, WHITE);

        poll_keyboard();
        if (key[KEY_ESC]) running = 0;

// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
        walking = 0;
        if (key[KEY_LEFT])  {tankdir = 0;   tankx-=speed;   walking=1;}
        if (key[KEY_RIGHT]) {tankdir = 1;   tankx+=speed;   walking=1;}
        if (key[KEY_UP])    {tankdir = 2;   tanky-=speed;   walking=1;}
        if (key[KEY_DOWN])  {tankdir = 3;   tanky+=speed;   walking=1;}

        if (key[KEY_S]) {
            if (!shot) {
                shot = 1;
                shooting = 1;
                bulleton[bullet] = 1;

                bulletspeedx[bullet] = 0;
                bulletspeedy[bullet] = 0;


                if (tankdir == 0) {
                    bulletx[bullet] = tankx - bulletimg->w;
                    bullety[bullet] = tanky + tanksizey/2 - bulletimg->h/2;
                    bulletspeedx[bullet] -= bulletspeed;

                }
                if (tankdir == 1) {
                    bulletx[bullet] = tankx + tanksizex;
                    bullety[bullet] = tanky + tanksizey/2 - bulletimg->h/2;
                    bulletspeedx[bullet] += bulletspeed;
                }
                if (tankdir == 2) {
                    bulletx[bullet] = tankx + tanksizex/2 - bulletimg->w/2;
                    bullety[bullet] = tanky - bulletimg->w/2;
                    bulletspeedy[bullet] -= bulletspeed;
                }
                if (tankdir == 3) {
                    bulletx[bullet] = tankx + tanksizex/2 - bulletimg->w/2;
                    bullety[bullet] = tanky + tanksizey;
                    bulletspeedy[bullet] += bulletspeed;
                }

                bullet++;
                if (bullet >= BULLETS) bullet = 0;
            }
        } else {
            shot = 0;
            shooting = 0;
        }


        xoffset = tankx - SCREENX/2 + tanksizex/2;
        yoffset = tanky - SCREENY/2 + tanksizey/2;

        if (xoffset > LEVELSIZEX*TILESIZE - SCREENX - 1) xoffset = LEVELSIZEX*TILESIZE - SCREENX - 1;
        if (yoffset > LEVELSIZEY*TILESIZE - SCREENY - 1) yoffset = LEVELSIZEY*TILESIZE - SCREENY - 1;

        if (xoffset < 0) xoffset = 0;
        if (yoffset < 0) yoffset = 0;




        int tilenum = 0;
        int destx1 = (xoffset)/TILESIZE, destx2 = (xoffset + SCREENX)/TILESIZE + 1;
        int desty1 = (yoffset)/TILESIZE, desty2 = (yoffset + SCREENY)/TILESIZE + 1;

        if (destx1 < 0) destx1 = 0;
        if (desty1 < 0) desty1 = 0;
        if (destx2 > LEVELSIZEX) destx2 = LEVELSIZEX;
        if (desty2 > LEVELSIZEY) desty2 = LEVELSIZEY;


        for (int y = desty1; y < desty2; y++) {
            for (int x = destx1; x < destx2; x++) {

                tilenum = level[y*LEVELSIZEX + x];
                stretch_blit(tilemap, buffer, (tilenum%MAPSIZEX)*TILESIZE, (tilenum/MAPSIZEX)*TILESIZE, TILESIZE, TILESIZE, (x*TILESIZE-xoffset)*SCALE, (y*TILESIZE-yoffset)*SCALE, TILESIZE*SCALE, TILESIZE*SCALE);


            }
        }



        if (walking) {
            if (tankframe == 1) {
                tankframe = 0;
            } else {
                tankframe = 1;
            }
        }
        masked_stretch_blit(tank, buffer, tankframe*tanksizex, tankdir*tanksizey, tanksizex, tanksizey, (tankx-xoffset)*SCALE, (tanky-yoffset)*SCALE, tanksizex*SCALE, tanksizey*SCALE);


        for (int i = 0; i < BULLETS; i++) {
            if (bulleton[i]) {
                bulletx[i] += bulletspeedx[i];
                bullety[i] += bulletspeedy[i];

                masked_stretch_blit(bulletimg, buffer, 0, 0, bulletimg->w, bulletimg->h, (bulletx[i]-xoffset)*SCALE, (bullety[i]-yoffset)*SCALE, bulletimg->w*SCALE, bulletimg->h*SCALE);
            }
        }




        //vsync();
        blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);

        while (ticks<1) {
            yield_timeslice();
            rest(10);
        }
        ticks=0;
    }

// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
    destroy_bitmap(tank);
    destroy_bitmap(bulletimg);
    destroy_bitmap(tilemap);

    destroy_bitmap(buffer);
    allegro_exit();
    return 0;
}