Beispiel #1
0
int dgreed_main(int argc, const char** argv) {
	params_init(argc, argv);
	rand_init(time(NULL));
	layouts_init();
	layouts_set("dvorak");

	bool fullscreen = true;
	if(params_find("-windowed") != ~0)
		fullscreen = false;

	video_init_ex(SCREEN_WIDTH, SCREEN_HEIGHT, 
		SCREEN_WIDTH, SCREEN_HEIGHT, "KeyMingler", fullscreen);
	font = font_load(FONT_FILE);	
	float text_width = font_width(font, LOADING_TEXT);
	float text_height = font_height(font);
	Vector2 pos = vec2((SCREEN_WIDTH - text_width) / 2.0f,
		(SCREEN_HEIGHT - text_height) / 2.0f);
	font_draw(font, LOADING_TEXT, 0, &pos, COLOR_WHITE);	
	video_present();
	system_update();

	game_init();
	sounds_init();
	music = sound_load_stream(MUSIC_FILE);
	sound_play(music);

	while(system_update()) {
		game_update();
		game_render();
		video_present();
		sound_update();

		if(key_up(KEY_QUIT))
			break;
	}
	
	font_free(font);
	sound_free(music);
	sounds_close();
	game_close();
	video_close();
	layouts_close();

	return 0;
}
Beispiel #2
0
int main(int argc, char* argv[])
{

	// SDL Event handler
	SDL_Event    event;
	int key_press;

	int game_over, score;
	int game_grid[CELLS] = {0};
	int row_test, last_row, drop_count, lock_in, key_count;
	int first_hold = 1;

	tetromino * falling;
	tetromino * next;
	tetromino * hold;
	tetromino * temp;

	set_rand();
	lock_in = 0;
	drop_count = 1;
	game_over = 0;
	key_count = 0;
	score     = 0;

	falling = tetromino_new(ACTIVE);
	next    = tetromino_new(INACTIVE);
	hold    = tetromino_new(INACTIVE);
	temp    = NULL;
	
	//log = fopen("Log.txt","w");
	//fprintf(log, "Begin Main\n");

	if(init() == 0)
	{//printf(log, "SDL did not initialize.\n" );
		return 0;
	}

	if(load_media() == 0)
	{//printf(log, "Media Loading failed\n" );
		return 0;
	}


	gridRect.x = 0;
	gridRect.y = 0;

	fallingRect.x = 0;
	fallingRect.y = 0;

	prevRect.x = (BLOCK_SIZE*MAXCOL) + PREVIEW_OFFSET;
	prevRect.y = 100;

	scoreRect.x = SCORE_X;
	scoreRect.y = SCORE_Y;

//	Preview = PreviewSurfaces[SQUARE_BLOCK]; // set a dummy default

	//anim = 0;
	//fprintf(log, "Game Loop entry\n" );

	while(game_over == 0)
	{
		/*if(anim ==  0)
			tetromino_drop(falling, game_grid);

		anim = (anim == 200)? 0: anim+1;*/

		drop_count = auto_drop(falling, game_grid, drop_count, score);

		key_press = 100;

		if(SDL_PollEvent(&event) != 0)
		{
			switch(event.type)
			{
				case SDL_QUIT:
					game_over = 1;
				break;

				case SDL_KEYDOWN:
					switch(event.key.keysym.sym)
					{
						case SDLK_UP:
							key_press = UP;
						break;

						case SDLK_DOWN:
							key_press = DOWN;
						break;

						case SDLK_LEFT:
							key_press = LEFT;
						break;

						case SDLK_RIGHT:
							key_press = RIGHT;
						break;

						case SDLK_ESCAPE:
							key_press = ESC;
						break;
						
						case SDLK_SPACE:
							key_press = SPACE;
						break;
					}
				break;
			}
		}

		//if(key_count == 0)
		//{
			switch(key_press)
				{
					case UP:
						tetromino_rotate(falling, game_grid);
					break;
	
					case DOWN:
						tetromino_drop(falling, game_grid);
					break;
	
					case RIGHT:
						tetromino_shift_right(falling, game_grid);
					break;
	
					case LEFT:
						tetromino_shift_left(falling, game_grid);
					break;
	
					case ESC:
					game_over = 1;
					break;
					
					case SPACE: // this still would be nice with visuals...
						if(first_hold == 1)
						{
							temp = hold;
							tetromino_mod(temp);
							hold = falling;
							falling = next;
							tetromino_activate(falling);
							next = temp;
							temp = NULL;
							first_hold = 0;
						}
						else
						{
							temp = falling;
							falling = hold;
							tetromino_activate(falling);
							hold = temp;
							temp = NULL;
						}
					break;
			}
		//}

		key_count = (key_count < KEY_RATE) ? key_count + 1: 0;

		lock_in = (tetromino_lock(falling, game_grid) == 1)? lock_in+1:0;
		
		if(lock_in == 200)
		{
			tetromino_into_grid(falling, game_grid);
			score += falling->shape + 2 * 3;
			score += row_check(game_grid);
			// manage the tetrominos
			temp = falling;
			falling = next;
			tetromino_activate(falling);
			tetromino_mod(temp);
			next = temp;
			temp = NULL;
			lock_in = 0;
		}

		if(grid_row_any(game_grid,0) == 1)
			game_over = 1;

		//blit to screen
		SDL_FillRect(ScreenSurface, 0, 0); // so the images don't trail
		blit_preview(next->shape);	
		blit_grid(game_grid);
		blit_tetromino(falling);
		blit_score(score);
		SDL_UpdateWindowSurface(MainWin);
	}

	game_close();
	free(falling);
	free(next);
	free(hold);
	return 0;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    byte keypress;

    client_init();

    if( argc > 1 )    /* Command line arguments */
	handle_cl_args(argc, argv);

    srand( time(NULL) );
    calc_lookup_tables(DEGREES);
    win_init();
    entity_init();
    if( (ent_img_loaded = (char *)malloc(num_entity_types)) == NULL ) {
	perror("Malloc");
	ERR_QUIT("Error allocating ent_img_loaded array", 1);
    } else {
	memset(ent_img_loaded, 0, num_entity_types);
    }

    /* Load client preferences from file */
    read_config_file( &client );
    /* Set view dimensions, which are calculated by tile width & heights */
    client.view_w = client.x_tiles * TILE_W;
    client.view_h = client.y_tiles * TILE_H;
    /* What the client WISHES their dimensions were (this may not be what
       it actually is, ie in demo's etc */
    client.desired_w = client.view_w;
    client.desired_h = client.view_h;

    weapon_type_init();
    particle_init();
    menu_init();

    cl_network_init();

    client.state = MENU;

    if( client.demo == DEMO_PLAY ) {
	cl_network_connect(NULL, 42);
	client.state = GAME_LOAD;
    }

    for( ; ; ) {
	switch( client.state ) {
	case MENU:
	    win_ungrab_pointer();
	    menu_driver();
	    break;

	case GAME_LOAD:
	    win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H);
	    wait_till_expose(5);

	    /* Finished loading, we are ready to play */
	    cl_change_map(client.map, client.gamemode);
	    break;

	case GAME_RESUME: /* Resume game from menu */
	    win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H);
	    wait_till_expose(5);
	    input_clear();
	    draw_status_bar();
	    cl_netmsg_send_ready(); /* Tell server new details */
	    cl_net_finish(); /* Send the NETMSG_READY to the server */
	    client.state = GAME_JOIN;

	    break;

	case GAME_JOIN:

        win_set_cursor( client.mousemode!=MOUSEMODE_ROTATE );
        win_set_cursor( 1 );


	    if( client.mousemode ) {
		win_grab_pointer();
	    }

	    text_buf_clear();
	    particle_clear();

	case GAME_PLAY:
	    cl_net_update();

	    if( client.state == GAME_PLAY ) { /* Maybe changed in net_update */
		draw_crosshair( my_entity );
		if( client.map_target_active )
		    draw_map_target( my_entity );

		text_buf_update();
		if( client.netstats )
		    cl_net_stats();

		win_update();

		/* Keyboard Input */
		client.dir = my_entity.dir;
		keypress = get_input();
		cl_netmsg_send_cl_update(keypress, client.dir);
	    }

	    cl_net_finish(); /* Send things that need sending */
	    cap_fps(client.fps);
	    break;

	case QUIT:
	    game_close();
	    image_close(); /* Free all the images */
	    win_close();
	    write_config_file(&client);
	    if( ent_img_loaded != NULL )
		free(ent_img_loaded);
	    exit(EXIT_SUCCESS);
	    break;
	}

    }

    return EXIT_SUCCESS;

}