本文整理汇总了C++中Render::AddSurfaceToRenderer方法的典型用法代码示例。如果您正苦于以下问题:C++ Render::AddSurfaceToRenderer方法的具体用法?C++ Render::AddSurfaceToRenderer怎么用?C++ Render::AddSurfaceToRenderer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Render
的用法示例。
在下文中一共展示了Render::AddSurfaceToRenderer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int, char**) {
//initialise SDL system and the video subsystem
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
QuitWithError("SDL_Init Error: ");
}
//Create a Window
SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (win == nullptr) {
QuitWithError("SDL_CreateWindow Error: ");
}
//SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN);
Mix_Music *music = NULL;
Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1;
std::string basepath(SDL_GetBasePath());
music = Mix_LoadMUS((basepath + "background.wav").c_str());
Mix_PlayMusic(music, -1);
Render* renderer = new Render(win);
//Main loop flag
bool quit = false;
b2Vec2 Gravity(0.f, 0.0098f);
b2World World(Gravity);
string bgPath = basepath + "background22.bmp";
SDL_Surface* back = SDL_LoadBMP(bgPath.c_str());
SDL_Rect* backGroundRect = renderer->AddSurfaceToRenderer(back, 0, -600, 1.0f);
Button button = Button(-200, -50, World, renderer);
Door door = Door(600, -100, renderer);
Level level = Level(World, renderer);
Player player = Player(100, 500, World, renderer);
vector<Cannon*> cannons;
cannons.push_back(new Cannon(170, 350, World, renderer, 1));
cannons.push_back(new Cannon(1010, 50, World, renderer, 2));
cannons.push_back(new Cannon(170, 450, World, renderer, 1));
cannons.push_back(new Cannon(1010, 150, World, renderer, 2));
cannons.push_back(new Cannon(170, 550, World, renderer, 1));
cannons.push_back(new Cannon(1010, 250, World, renderer, 2));
MenuScene* menu = new MenuScene(1200, 100, renderer);
SDL_Event e;
//thread t1(&Process::run, Process((*(game)))); //Passing references
//t1.detach(); //detaches from SDL mainline
float prevTicks = SDL_GetTicks();
float currentTicks = SDL_GetTicks();
float FPS = 0;
int fpsTimer = 0;
SDL_Init(0);
//game loop
while (!quit) {
World.Step(1 / 60.f, 6, 2);
while (SDL_PollEvent(&e) != 0) {
if (inputHandler.CheckInput(SDLK_ESCAPE, e)) {
quit = true;
}
}
if (menu->playBool == false && menu->quitBool == false) {
renderer->DrawMenuScene();
menu->Update(renderer);
}
if (menu->playBool == true)
{
//PLAY GAME STATE
int dir = player.Move(inputHandler, e);
for (int i = 0; i < cannons.size(); i++)
{
cannons.at(i)->Update();
}
SDL_Rect rec(player.spriteRect);
rec.y = player.GetY();
for (int j = 0; j < cannons.size(); j++)
{
for (int i = 0; i < cannons.at(j)->fireballs.size(); i++)
{
if (cannons.at(j)->fireballs.at(i)->CheckCollision(&rec) == true)
{
std::cout << "Collision Detected!" << std::endl;
player.Respawn();
button.setOnce(false);
button.buttonBody->SetTransform(b2Vec2(880 / SCALE, 39 / SCALE), 0);
//.........这里部分代码省略.........