当前位置: 首页>>代码示例>>C++>>正文


C++ Input::KeyUp方法代码示例

本文整理汇总了C++中Input::KeyUp方法的典型用法代码示例。如果您正苦于以下问题:C++ Input::KeyUp方法的具体用法?C++ Input::KeyUp怎么用?C++ Input::KeyUp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Input的用法示例。


在下文中一共展示了Input::KeyUp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char* argv) {
	SDL_Init(SDL_INIT_EVERYTHING);


	SDL_Window* window = nullptr;

	SDL_Renderer* gRenderer = NULL;

	window = SDL_CreateWindow("Hi", 50, 50, 1000, 500, SDL_WINDOW_SHOWN);
	gRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);


	Uint32 tick;
	bool pauseReset = true;
	bool running = true;
	float frame = 0.0f;


	//Initialize renderer color
	SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);

	//Initialize PNG loading
	int imgFlags = IMG_INIT_PNG;
	if (!(IMG_Init(imgFlags) & imgFlags))
	{
		printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
	}

	Game game;
	Entity entity;
	
	game.LoadMobList(gRenderer);
	game.LoadPlayerAnims(gRenderer, &entity);
	game.InitSpawnManager();


	//IDENFITY A MOB
	//Entity mush = *game.IdentifyMob("mush");

	Input PlayerInput;

	GameMap map;
	SDL_Rect mapPos;
	mapPos.w = 1387;
	mapPos.h = 907;
	mapPos.x = 0;
	mapPos.y = -407;
	map.InitMap("content\\maps\\hennesys\\map01.png", mapPos, gRenderer);
	entity.SetPositionY(190);
	while (running) {

		tick = SDL_GetTicks();
		SDL_Event event;

		while (SDL_PollEvent(&event)) {
			switch (event.type) {
			case SDL_QUIT:
				break;
			case SDL_KEYDOWN:
				PlayerInput.KeyDown(event.key.keysym.scancode);
				break;
			case SDL_KEYUP:
				PlayerInput.KeyUp(event.key.keysym.scancode);
				break;
			}
		}

		//Clear screen
		SDL_RenderClear(gRenderer);

		if (PlayerInput.IsKeyPressed(SDL_SCANCODE_LEFT)) {
			entity.Walk(Left);
		}
		else if (PlayerInput.IsKeyPressed(SDL_SCANCODE_RIGHT)) {
			entity.Walk(Right);
		}
		else {
			entity.Station();
		}

		map.DrawMap(mapPos);
		entity.Draw();
		game.ManageMobPool();

		//Update screen
		SDL_RenderPresent(gRenderer);

		//SpawnManager
		game.spawn_manager.ManagePool(tick);

		//LIMIT FPS
		frame += 0.1f;
		unsigned int fps = 60;
		if ((1000 / fps) > SDL_GetTicks() - tick) {
			SDL_Delay(1000 / fps - (SDL_GetTicks() - tick));
		}
	}

	SDL_DestroyWindow(window);
	return 1;
//.........这里部分代码省略.........
开发者ID:zqz981,项目名称:MapleStorySDLCPP,代码行数:101,代码来源:main.cpp


注:本文中的Input::KeyUp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。