示例#1
0
void
state_menu_event(void *ptr)
{
	SDL_Event *e = (SDL_Event *)ptr;
	interface_event_detect(ui, e);

	if(e->type == INTERFACE_MOUSECLICKEVENT)
	{
		if(e->user.code == ui_play)
			state_queue_push(WORLD_NEW, 0);
		if(e->user.code == ui_load)
			state_queue_push(WORLD_LOAD, 0);
		if(e->user.code == ui_quit)
			state_queue_pop();
	}
	if(e->type == INTERFACE_MOUSEOVEREVENT)
	{
		if(e->user.code == ui_play)
			textbox_set_color(textbox_play, TEXTBOX_COLOR_WHITE);
		if(e->user.code == ui_load)
			textbox_set_color(textbox_load, TEXTBOX_COLOR_WHITE);
		if(e->user.code == ui_quit)
			textbox_set_color(textbox_quit, TEXTBOX_COLOR_WHITE);
	}
	if(e->type == INTERFACE_MOUSEOVEREXITEVENT)
	{
		if(e->user.code == ui_play)
			textbox_set_color(textbox_play, TEXTBOX_COLOR_BLUE);
		if(e->user.code == ui_load)
			textbox_set_color(textbox_load, TEXTBOX_COLOR_BLUE);
		if(e->user.code == ui_quit)
			textbox_set_color(textbox_quit, TEXTBOX_COLOR_BLUE);
	}
}
示例#2
0
void
state_game_event(void *ptr)
{
	SDL_Event e = ((SDL_Event *)ptr)[0];

	if(e.type == SDL_KEYDOWN)
	{
		switch(e.key.keysym.sym)
		{
			case SDLK_ESCAPE:
				state_queue_pop();
			break;
			case SDLK_SPACE:
				entity_jump(pos, PLAYER_JUMPSPEED);
			break;
			case SDLK_i:
				state_queue_push(INVENTORY, 0);
			break;
			case SDLK_v:
				lines = !lines;
			break;
			case SDLK_m:
				takeinput = !takeinput;
			break;
			case SDLK_c:
				info("Coords x: %f y: %f z: %f \n", posptr->x, posptr->y, posptr->z);
			break;
			case SDLK_t:
			{
				vec3_t top = *posptr;
				top.y = worldgen_get_height_of_pos(0, posptr->x, posptr->z)+1;
				entity_pos_set(pos, top);
			break;
			}
			case SDLK_f:
				flying = !flying;
			break;
			case SDLK_u:
				updating = !updating;
				info("UPDATING: %i\n", updating);
			break;
			case SDLK_p:
				pp = !pp;
				if(!pp)
				{
					glBindFramebuffer(GL_FRAMEBUFFER, 0);
					glEnable(GL_DEPTH_TEST);
					glUseProgram(drawprogram);
				}
			break;
		}
	}

	else if(e.type == SDL_CONTROLLERBUTTONDOWN)
	{
		switch(e.cbutton.button)
		{
			case SDL_CONTROLLER_BUTTON_A:
				entity_jump(pos, PLAYER_JUMPSPEED);
				break;
		}
	}

	else if(e.type == SDL_CONTROLLERAXISMOTION)
	{
		switch(e.caxis.axis)
		{
			case SDL_CONTROLLER_AXIS_LEFTX:
				leftstick.x = deadzone(e.caxis.value / 32768.0);
				break;
			case SDL_CONTROLLER_AXIS_LEFTY:
				leftstick.y = deadzone(e.caxis.value / 32768.0);
				break;
			case SDL_CONTROLLER_AXIS_RIGHTX:
				rightstick.x = deadzone(e.caxis.value / 32768.0);
				break;
			case SDL_CONTROLLER_AXIS_RIGHTY:
				rightstick.y = deadzone(e.caxis.value / 32768.0);
				break;
		}
	}

	else if(e.type == SDL_MOUSEBUTTONDOWN)
	{
		if(e.button.button == SDL_BUTTON_LEFT)
		{
			block_t b;
			b.id = WATER_GEN;
			world_ray_set(&headpos, &forwardcamera, b, 1, 1, 1000);
		}
		else if(e.button.button == SDL_BUTTON_RIGHT)
		{
			world_ray_del(&headpos, &forwardcamera, 1, 1000);
		}
	}
	else if(e.type == SDL_WINDOWEVENT)
	{
		if(e.window.event == SDL_WINDOWEVENT_RESIZED)
			state_game_window_resize();
	}
}