Example #1
0
//Método principal para atualização do game em tempo real
void Game::gameUpdate(){
	//Limite de Frame Rate
	gameWindow.setFramerateLimit(60);

	//Checa se algum dos players completou as 3 voltas
	isRaceOver();

	//Verifica se a tecla ESC é pressionada, abrindo o menuPause
	renderPause();
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
		menuPause.abrirMenu();

	//Toca a música que será reproduzida durante a corrida
	raceBGM.playMusic();
	raceBGM.setVolume(100);

	//Ativa os métodos de entrada de keyboard para os controles de ambos os players
	player[0].ativarMovimentos(0);
	player[1].ativarMovimentos(1);

	//Checa todas as colisões possíveis dentro da partida para cada Player
	checkCollision(0);
	checkCollision(1);

	//Checa se os players estão no sentido correto da pista (caso eles percorram ao contrário), seus
	//carros explodirão
	player[0].checarSentido();
	player[1].checarSentido();

	//Checa durante a partida quando a linha de chegada é ultrapassada
	checkLap();
	
	//Centralizando cada câmera em seu respectivo player
	player[0].centralizarCamera();
	player[1].centralizarCamera();

	//Renderizações na tela do Player1
	gameWindow.setView(player[0].getCamera());
	renderMap();
	gameWindow.draw(player[0].getSprite());
	gameWindow.draw(player[1].getSprite());
	renderProjeteis();
	renderGUI(0);
	
	//Renderizações na tela do Player 2
	gameWindow.setView(player[1].getCamera());
	renderMap();
	gameWindow.draw(player[1].getSprite());
	gameWindow.draw(player[0].getSprite());
	renderProjeteis();
	renderGUI(1);

	gameWindow.display();
	gameWindow.clear();
}
Example #2
0
/*
 * Start the aim screen.
 */
void initAim() {
    aimX = 0;
    aimY = 0;
    renderMap(&enemyMap);
    renderCursor(aimX, aimY);
    renderAimInfo();
}
Example #3
0
void render()
{
    clearScreen();      // clears the current screen and draw from scratch
    renderMap();        // renders the map to the buffer first
    renderCharacter();  // renders the character into the buffer
    renderFramerate();  // renders debug information, frame rate, elapsed time, etc
    renderToScreen();   // dump the contents of the buffer to the screen, one frame worth of game
} 
Example #4
0
int main (int argc, char* argv[])
{


	if (!loadMapFromFile ("maps/level1.map"))
	{
		printf ("Can't locate map!");
	}

	initGUI();
	initMap();
	initPlayer();

	SDL_Event e;
	int quit = 0;

	int start_time;
	int urd_time;
	int wait_time;
	int target_time = 1000/FPS;

	while (!quit)
	{
		start_time = SDL_GetTicks();

		while (SDL_PollEvent (&e))
		{
			if (e.type == SDL_QUIT)
			{
				quit = 1;
			}
			else
			{
				player->left = 0;
				player->right = 0;
			}
			processInput ();
		}

		clearScreen();
		updatePlayer (player);
		renderBackground();
		renderMap();
		renderPlayer (player);
		draw();

		urd_time = (SDL_GetTicks() - start_time);
		wait_time = target_time - urd_time;

		SDL_Delay (wait_time);
	}

	destroyGUI();
	deletePlayer (player);

	return 0;
}
void gameScreen(gameState &game)
{
    vector<vector<char>> processedMap;

    processMap("testing.map", processedMap);

    renderMap(processedMap);

    game = QUIT_MENU;
}
Example #6
0
void Client::beforeUI() {
	UIApp::beforeUI();

	_drawCallsWorld = 0;
	_drawCallsEntities = 0;

	if (_world->isCreated())
		renderMap();
	else
		renderBackground();
}
/*This is the render loop
At this point, you should know exactly what to draw onto the screen, so just draw it!
To get an idea of the values for colours, look at console.h and the URL listed there*/
void render() {
    
	//Clears the current screen and draw from scratch.
	clearScreen();
    renderMap();
	renderShooter();
	renderCharacter(mummy.charDirection);
	renderBoxes();
	renderMonsters();
	renderMessages();

	//Dump the contents of the buffer to the screen. One frame worth of the game.
    renderToScreen();

}
Example #8
0
int checkEncountGauge(Frame* frame, Frame* inventoryFrame, Frame* statusFrame) {
	encountGauge += 1;

	if (encountGauge > 8) {
		int eob = battleSequence(frame);
		encountGauge = 0;
		renderMap(*frame, area, &player);
		frame->update();
		renderInventory(inventoryFrame, &player);
		renderStatus(statusFrame, &player);
		return eob;
	}

	return -1;
}
Example #9
0
//Método ferramenta para auxiliar a delimitação das pistas de colisão
void Game::ferramentaMapaConstrutor(){
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
		cameraGenerica.move(0, -5);
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
		cameraGenerica.move(0, 5);
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
		cameraGenerica.move(-5, 0);
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
		cameraGenerica.move(5, 0);

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
		rectTeste.move(0, -2);
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
		rectTeste.move(0, 2);
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
		rectTeste.move(-2, 0);
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
		rectTeste.move(2, 0);
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
		x -= 0.1;
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::E))
		x += 0.1;
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad4))
		y += 0.1;
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad6))
		y -= 0.1;
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad8))
		z += 0.1;
	else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad2))
		z -= 0.1;

	rectTeste.setRotation(x);
	rectTeste.setSize(sf::Vector2f(y, z));

	std::cout << "Rotacao = " << rectTeste.getRotation() << " - Posicao: X = " << rectTeste.getPosition().x
		<< ", Y = " << rectTeste.getPosition().y << " - Tamanho: X = " << rectTeste.getSize().x <<
		", Y = " << rectTeste.getSize().y << std::endl;

	gameWindow.setView(cameraGenerica);
	renderMap();
	gameWindow.draw(rectTeste);
	gameWindow.display();
	gameWindow.clear();
}
Example #10
0
void Renderer::render() {
  Clock::startSection("render");

  startRender();

  renderMap();

  for (auto &it : entities_) {
    renderEntity(it.second);
  }
  // render overlay second for z ordering issues
  if (entityOverlayRenderer_) {
    for (auto &it : entities_) {
      renderEntityOverlay(it.second);
    }
  }
  effectManager_->render(getRenderTime());

  endRender();
}
Example #11
0
void MinimapGui::presentMap(const CreatureView* creature, Rectangle bounds, Renderer& r,
    function<void(double, double)> clickFun) {
  const Level* level = creature->getLevel();
  double scale = min(double(bounds.getW()) / level->getBounds().getW(),
      double(bounds.getH()) / level->getBounds().getH());
  while (1) {
    update(level, level->getBounds(), creature, true);
    renderMap(r, Rectangle(Vec2(0, 0), embed(level->getBounds().getBottomRight(), bounds.getBottomRight())));
    r.drawAndClearBuffer();
    Event event;
    while (r.pollEvent(event)) {
      if (event.type == Event::KeyPressed)
        return;
      if (event.type == Event::MouseButtonPressed) {
        clickFun(double(event.mouseButton.x) / scale, double(event.mouseButton.y) / scale);
        return;
      }
    }
  }
}
Example #12
0
void renderGame() {
	renderMap();                // renders the character into the buffer
	renderCharacter();          // renders the character into the buffer
    renderMonster();            // renders Ghost
    renderGuards();             // renders guards
	projectile();               // projectile function
    bomb();                     // bomb function
    Ultimate();                 // ultimate skills function
	if (fight == BATTLE){
        BossAttack();
        if (elapsedTime > bossFightTime){
            bossSpeed();                        // Seeding
            bossFightTime = elapsedTime + 30;   // map and boss pattern refreshes every 30 seconds
            for (int i = 0; i < MAP_HEIGHT; i++){
                for (int j = 0; j < MAP_WIDTH; j++){
                    printMap[i][j] = BossMap[i][j];
                }
            }
        }
	}
}
Example #13
0
bool MapViewUpdate() {

	// Clear the screen
    IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F);

	renderMap();
	renderMapPlayer();
	renderMapXpBar();
	renderMapHealth();

	Player* player = getGameState()->getPlayer();
	IntroState introState = getGameState()->getIntroState();

	if (lastLoses < player->getLoseCount() ||
		lastWins < player->getWinCount()) {
		lastLoses = player->getLoseCount();
		lastWins = player->getWinCount();

		mapGhost2->setCentre(CIwFVec2(IwGxGetScreenWidth()*0.80f, IwGxGetScreenHeight()*0.70f));
		mapGhost2->setNotice(false);

		if (introState == INTRO_DEFEND) {
			mapGhost2->moveGhost(CIwFVec2(IwGxGetScreenWidth()/2, IwGxGetScreenHeight()/2), arrivalCallback);
		}
	}
	if (introState == INTRO_ATTACK) {
		mapGhost->Update();
		mapGhost->Render();
	}

	mapGhost2->Update();
	mapGhost2->Render();

	IwGxFlush();
    IwGxSwapBuffers();

	return true;
}
Example #14
0
void HudManager::render()
{
  renderMap();
  renderLife();
  renderFire();
}
Example #15
0
void Minimap::render(const Minimap::CarVector & cars, const Race & race)
{
    renderMap();

    renderMarkers(cars, race);
}
Example #16
0
void MinimapGui::render(Renderer& r) {
  renderMap(r, getBounds());
}
Example #17
0
int main(int argc, char **argv)
{

    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError());
        return 1;
    }
    if (TTF_Init() != 0) {
        fprintf(stderr, "Failed to initialize TTF: %s\n", SDL_GetError());
        return 1;
    }
    if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096)) {
        fprintf(stderr, "Failed to load Mixer: %s", SDL_GetError());
    }
    int imgFlags = IMG_INIT_JPG|IMG_INIT_PNG;
    if(!(IMG_Init(imgFlags) & imgFlags)) {
        fprintf(stderr,"Failed to initialize Image: %s",SDL_GetError());
    }

    screen = SDL_CreateWindow(WINDOW_TITLE,
                              SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                              WINDOW_WIDTH, WINDOW_HEIGHT,
                              SDL_WINDOW_BORDERLESS);
    if (screen == NULL) {
        fprintf(stderr, "Failed to create window: %s\n", SDL_GetError());
        return 1;
    }

    renderer = SDL_CreateRenderer(screen, -1, 0);
    if (renderer == NULL) {
        fprintf(stderr, "Failed to create renderer: %s\n", SDL_GetError());
        return 1;
    }

    char* path = buildPath(ASSETS,"fonts/FONT.TTF");
    font = TTF_OpenFont(path, 12);
    if (font == NULL) {
        fprintf(stderr, "Failed to load font: %s\n",TTF_GetError());
        return 1;
    }
    free(path);

    /*Mix_Music* music = loadMusic(buildPath(ASSETS,"music/song.mp3"));*/
    /*playMusic(music);*/

    // Black backround
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);

    game_init();

    if (buffers_init(renderer) != 0) {
        fprintf(stderr, "Failed to craete buffers: %s", SDL_GetError());
        return 1;
    }

    curr_buffer = buffer;
    SDL_Event e;
    SDL_Rect render_rect;
    render_rect.x = 0;
    render_rect.y = 0;
    render_rect.w = WINDOW_WIDTH;
    render_rect.h = WINDOW_HEIGHT;
    bool quit = false;
    int deltaTime = 0;
    int currentFrame = SDL_GetTicks();
    int lastFrame;
    int fpsMs = 1000 / MAX_FPS;

    map_tex = renderMap(renderer, map);

    camera.x = 0;
    camera.y = 0;
    camera.w = WINDOW_WIDTH;
    camera.h = WINDOW_HEIGHT;

    while (!quit) {
        lastFrame = currentFrame;
        currentFrame = SDL_GetTicks();
        deltaTime = currentFrame - lastFrame;
        renderClear(renderer);

        update(deltaTime);
        draw(deltaTime);

        while (SDL_PollEvent(&e)) {
            if (e.type == SDL_QUIT)
                quit = true;
            else
                event(e, deltaTime);
        }

        // Reset the target
        SDL_SetRenderTarget(renderer, NULL);
        // Copy the buffer
        SDL_RenderCopy(renderer, curr_buffer, &camera, &render_rect);
        // Draw the buffer to window
        SDL_RenderPresent(renderer);

        // Delay if we are drawing more that 100 fps
        float delay = fpsMs - deltaTime / 1000;
        if (delay > 0) SDL_Delay(delay);
    }

    SDL_Quit();
    return 0;
}
Example #18
0
void Game::render() {
	renderMap();
	drawHealth();

	SDL_Flip(m_background);
}
Example #19
0
// Print the canvas contents to a bitmap:
void gateImage::generateImage() {
//WARNING!!! Heavily platform-dependent code ahead! This only works in MS Windows because of the
// DIB Section OpenGL rendering.

	wxSize sz = GetClientSize();

	// Create a DIB section.
	// (The Windows wxBitmap implementation will create a DIB section for a bitmap if you set
	// a color depth of 24 or greater.)
	wxBitmap theBM( GATEIMAGESIZE, GATEIMAGESIZE, 32 );
	
	// Get a memory hardware device context for writing to the bitmap DIB Section:
	wxMemoryDC myDC;
	myDC.SelectObject(theBM);
	WXHDC theHDC = myDC.GetHDC();

	// The basics of setting up OpenGL to render to the bitmap are found at:
	// http://www.nullterminator.net/opengl32.html
	// http://www.codeguru.com/cpp/g-m/opengl/article.php/c5587/

    PIXELFORMATDESCRIPTOR pfd;
    int iFormat;

    // set the pixel format for the DC
    ::ZeroMemory( &pfd, sizeof( pfd ) );
    pfd.nSize = sizeof( pfd );
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 32;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;
    iFormat = ::ChoosePixelFormat( (HDC) theHDC, &pfd );
    ::SetPixelFormat( (HDC) theHDC, iFormat, &pfd );

    // create and enable the render context (RC)
    HGLRC hRC = ::wglCreateContext( (HDC) theHDC );
    HGLRC oldhRC = ::wglGetCurrentContext();
    HDC oldDC = ::wglGetCurrentDC();
    ::wglMakeCurrent( (HDC) theHDC, hRC );

	// Setup the viewport for rendering:
	setViewport();
	// Reset the glViewport to the size of the bitmap:
	glViewport(0, 0, GATEIMAGESIZE, GATEIMAGESIZE);
	
	// Set the bitmap clear color:
	glClearColor (1.0, 1.0, 1.0, 0.0);
	glColor3b(0, 0, 0);

	glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
		
	//TODO: Check if alpha is hardware supported, and
	// don't enable it if not!
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);

	glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
	
	//*********************************
	//Edit by Joshua Lansford 4/09/07
	//anti-alis ing is nice
	//glEnable( GL_LINE_SMOOTH );
	//End of edit

	// Load the font texture
	guiText::loadFont(wxGetApp().appSettings.textFontFile);
	
	// Do the rendering here.
	renderMap();

	// Flush the OpenGL buffer to make sure the rendering has happened:	
	glFlush();
	
	// Destroy the OpenGL rendering context, release the memDC, and
	// convert the DIB Section into a wxImage to return to the caller:
    ::wglMakeCurrent( oldDC, oldhRC );
    //::wglMakeCurrent( NULL, NULL );
    ::wglDeleteContext( hRC );
	myDC.SelectObject(wxNullBitmap);
	gImage = theBM.ConvertToImage();
}
Example #20
0
// Game loop
void gameLoop() {
	int c; // char

	// Init frames
	Frame viewFrame(COLS-2, LINES-2, RFOrientation::TOP_LEFT);
	Frame textFrame(COLS-2, 4, RFOrientation::BOTTOM_LEFT);
	Frame inventoryFrame(18, 4, RFOrientation::BOTTOM_RIGHT);
	Frame statusFrame(15, 4, RFOrientation::TOP_RIGHT);

	int hasText = 0;
	int showedHint = 0;
	int showedNothingMessage = 0;
	plA = player.c_area;
	plX = player.x;
	plY = player.y;

	renderMap(viewFrame, area, &player);
	viewFrame.update();
	renderInventory(&inventoryFrame, &player);
	renderStatus(&statusFrame, &player);

	while(1) {
		c = getch();
		if (c == KEY_UP){
			if (isValid(area, player.c_area, player.x, player.y - 1) &&
					area[player.c_area][player.x][player.y].doorInfo[D_UP] == DC_OPEN &&
					player.direction == D_UP) {
				player.y = player.y - 1;
			}
			player.direction = D_UP;
		} else if (c == KEY_RIGHT){
			if (isValid(area, player.c_area, player.x + 1, player.y) &&
					area[player.c_area][player.x][player.y].doorInfo[D_RIGHT] == DC_OPEN &&
					player.direction == D_RIGHT) {
				player.x = player.x + 1;
			} else if (isValid(area, player.c_area, player.x + 1, player.y) &&
								 area[player.c_area][player.x][player.y].doorInfo[D_RIGHT] == DC_LOCKED &&
								 player.hasKey) {
				area[player.c_area][player.x][player.y].doorInfo[D_RIGHT] = DC_OPEN;
				player.hasKey = 0;
			}
			player.direction = D_RIGHT;
		}else if (c == KEY_DOWN){
			if ( isValid(area, player.c_area, player.x, player.y + 1) && area[player.c_area][player.x][player.y].doorInfo[D_DOWN] == DC_OPEN ) {
				if (player.direction == D_DOWN) {
					player.y = player.y + 1;
				}
			} else if (isValid(area, player.c_area, player.y + 1, player.y) &&
								 area[player.c_area][player.x][player.y].doorInfo[D_DOWN] == DC_LOCKED &&
								 player.hasKey) {
				area[player.c_area][player.x][player.y].doorInfo[D_DOWN] = DC_OPEN;
				player.hasKey = 0;
			}
			player.direction = D_DOWN;
		} else if (c == KEY_LEFT){
			if ( isValid(area, player.c_area, player.x - 1, player.y) && area[player.c_area][player.x][player.y].doorInfo[D_LEFT] == DC_OPEN ) {
				if (player.direction == D_LEFT) {
					player.x = player.x - 1;
				}
			}
			player.direction = D_LEFT;
		}

		hasText = 0;

		// Render view
		if (c == 'z') {
			textFrame.clear();
			if (area[player.c_area][player.x][player.y].hasKey) {
				textFrame.println("キーを見つけた...!");
				hasText = 1;
				player.hasKey = 1;
				area[player.c_area][player.x][player.y].hasKey = 0;
			} else if (area[player.c_area][player.x][player.y].hint != "" && !showedHint) {
				textFrame.println("ヒントを見つけた...\n");
				textFrame.println(area[player.c_area][player.x][player.y].hint.c_str());
				showedHint = 1;
				showedNothingMessage = 1;
				hasText = 1;
			} else if (area[player.c_area][player.x][player.y].hasPotion && player.hasPotion) {
				textFrame.println("ポーション見つけたが、持てない...");
				hasText = 1;
			} else if (area[player.c_area][player.x][player.y].hasPotion) {
				textFrame.println("ポーション見つけた...!");
				hasText = 1;
				player.hasPotion = 1;
				area[player.c_area][player.x][player.y].hasPotion = 0;
			} else if (area[player.c_area][player.x][player.y].canJump) {
				viewFrame.move(0, 0);
				viewFrame.print(filledWith(viewFrame, "□"), 10);
				player.c_area = 1;
				player.x = 7;
				player.y = 2;
			} else if (!showedNothingMessage) {
				textFrame.println("何も無いようだ...");
				showedNothingMessage = 1;
				hasText = 1;
			} else {
				showedNothingMessage = 0;
				hasText = 0;
				showedHint = 0;
			}
		} else if (c == 's') {
			textFrame.clear();
			if (player.hasPotion) {
				textFrame.println("ポーション使う...?");
				textFrame.println("z = はい");
				textFrame.println("x = いいえ");
				while(1) {
					c = getch();
					if (c == 'z') {
						textFrame.clear();
						textFrame.println("ポーション使いました...");
						textFrame.println("HP全回しました");
						player.hp = 15;
						hasText = 1;
						player.hasPotion = 0;
						break;
					} else if (c == 'x'){
						textFrame.clear();
						textFrame.println("ポーション使うのをやめた...");
						textFrame.println("HP全回しました、なんてウソです");
						hasText = 1;
						break;
					}
				}
			} else if (!player.hasPotion) {
				textFrame.println("ポーションない...");
				hasText = 1;
			}
		}

		area[player.c_area][player.x][player.y].playerVisited = 1;

		renderMap(viewFrame, area, &player);
		viewFrame.update();
		if (hasText) textFrame.update();

		renderInventory(&inventoryFrame, &player);
		renderStatus(&statusFrame, &player);

		// 前回描画した時からプレイヤーは移動したか?
		if (isPlayerMoved(plA, plX, plY, player.c_area, player.x, player.y)) {
			// Zakoがいるなら戦闘
			int eob = checkEncountGauge(&viewFrame, &inventoryFrame, &statusFrame);
			if (eob == EOB_PLAYER_LOST) {
				gameOver(&viewFrame);
				return;
			}
		}

		// 特殊ボス会敵
		if (area[player.c_area][player.x][player.y].uniqueBossId == 1 && !player.beatenHBoss) {
			int eob = battleSequence(&viewFrame);
			if (eob == EOB_PLAYER_LOST) {
				gameOver(&viewFrame);
				return;
			} else if (eob == EOB_PLAYER_BEATEN_BOSS) {
				gameWon(&viewFrame);
				return;
			}
		} else if (area[player.c_area][player.x][player.y].uniqueBossId == 0) {
			int eob = battleSequence(&viewFrame);
			if (eob == EOB_PLAYER_LOST) {
				gameOver(&viewFrame);
				return;
			} else if (eob == EOB_PLAYER_BEATEN_BOSS) {
				gameWon(&viewFrame);
				return;
			}
		}

		plA = player.c_area;
		plX = player.x;
		plY = player.y;
	}
}
Example #21
0
void Main()
{
	ResourceLoader resources;

	auto sampler = SamplerState(SamplerState::Default2D);
	sampler.filter = TextureFilter::MinMagMipPoint;
	Graphics2D::SetSamplerState(sampler);

	Window::Resize(320 * 2, 240 * 2);
	Window::SetTitle(L"まちへかえろう(仮)");

	Array<HurdleObject> hurdles;
	Array<BuildingLayer> buildingLayers;
	Array<BuildingLayer2> buildingLayers2;

	Map::instance().init(40, 15);

	for (int i = 0; i < 40; i++)
	{
		Map::instance().set(i, 14, 5);
		Map::instance().set(i, 13, 5);
		Map::instance().set(i, 12, 4);
		Map::instance().set(i, 11, 3);
		Map::instance().set(i, 10, 3);
		Map::instance().set(i, 9, 2);
		Map::instance().set(i, 8, 1);
	}
	auto viewLeft = 0.0;
	auto mycharDead = false;
	ScreenState currentState = ScreenState::InTitle, prevState = currentState;
	bool prevSpacePressed = false;

	auto TitleTimer = TimerMillisec();

	ScriptEngine asEngine;
	asEngine.RegisterMethod(L"int getAt(double x, double y)", &Map::getAt, Map::instance());
	asEngine.RegisterProperty(L"double _viewX", &viewLeft);
	asEngine.RegisterProperty(L"bool _isGameOvered", &mycharDead);
	asEngine.RegisterFunction(L"void playJumpSound()", PlayJumpSound);
	auto context_mychar = asEngine.CreateContextFromScript(L"res/scripts/Mychar.as");

	Record::instance().init();

	int fc = 0;
	while (System::Update())
	{
		bool spacePressedInFrame = !prevSpacePressed && Input::KeySpace.pressed;
		prevSpacePressed = Input::KeySpace.pressed;

		asEngine.setFrameCount(fc);

		switch (currentState)
		{
		case ScreenState::InTitle:
			if (!TitleTimer.isActive) TitleTimer.start();
			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			renderTitle(TitleTimer.elapsed(), resources);
			renderCurrentMax();

			if (spacePressedInFrame)
			{
				// GameInit
				SoundAsset(SoundResourceLoader::decide).play();
				viewLeft = 0.0;
				mycharDead = false;
				context_mychar.Reenter();
				buildingLayers.clear();
				buildingLayers2.clear();
				hurdles.clear();
				currentState = ScreenState::Gaming;
			}
			break;
		case ScreenState::Gaming:
			// appear hurdles at random
			if (RandomBool(0.02))
			{
				if (hurdles.empty() || hurdles.back().getPos().x - (viewLeft + 320.0f) < -48.0f)
				{
					// allocate space least 48 logical-pixels
					hurdles.emplace_back(HurdleObject(Vec2(viewLeft + 320.0f, 8.0f * 16.0f + 8.0f)));
				}
			}
			// appear building at random
			if (RandomBool(0.02 / 30.0))
			{
				if (buildingLayers.empty() || buildingLayers.back().getPos().x < 0.0f)
				{
					buildingLayers.emplace_back(BuildingLayer(Vec2(320.0f, -60.0f)));
				}
			}
			if (RandomBool(0.01 / 30.0))
			{
				if (buildingLayers2.empty() || buildingLayers2.back().getPos().x < 0.0f)
				{
					buildingLayers2.emplace_back(BuildingLayer2(Vec2(320.0f, -60.0f)));
				}
			}

			asEngine.setFrameCount(fc);
			context_mychar.Execute();

			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			if (renderHurdlesAndHitTest(viewLeft, context_mychar.GetGlobalDoubleVec2(L"x", L"y"), hurdles, resources))
			{
				if (!mycharDead) SoundAsset(SoundResourceLoader::died).play();
				mycharDead = true;
			}
			renderPlayer(viewLeft, context_mychar.GetGlobalDouble(L"angle"), context_mychar.GetGlobalDoubleVec2(L"x", L"y"), resources);
			renderInfo(toScore(context_mychar.GetGlobalDouble(L"x")));

			// Host Processes
			if (mycharDead && context_mychar.GetGlobalDouble(L"x") < viewLeft - 120.0f)
			{
				// update record
				Record::instance().recordScore(toScore(context_mychar.GetGlobalDouble(L"x")));
				currentState = ScreenState::Result;
			}
			break;
		case ScreenState::Result:
			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			renderHurdlesAndHitTest(viewLeft, context_mychar.GetGlobalDoubleVec2(L"x", L"y"), hurdles, resources);
			renderResult(toScore(context_mychar.GetGlobalDouble(L"x")), Record::instance().isUpdated(), fc);

			if (spacePressedInFrame)
			{
				// GameInit
				SoundAsset(SoundResourceLoader::decide).play();
				TitleTimer.reset();
				currentState = ScreenState::InTitle;
			}
			break;
		}
		if (prevState != currentState)
		{
			fc = 0;
		}
		prevState = currentState;

		// Common Postprocesses
		fc++;
		viewLeft += 2.5f;
	}

	Map::instance().clean();
}
Example #22
0
void fullCommandMode(char * fileName, char * authorName, char * mapDescription, int * rows, int * cols, char * mapArray, int * isQuit){
	int h,w;
	getmaxyx(stdscr,h,w);
	//clean the last row and move curse to the h-1,0
	move(h-1,0);
	for (int i = 0; i < w; i++) {
		addch(' ');
	}
	move(h-1,0);
	echo();
	addch(':');
//take input from user
	char buffer[100]= " ";
	for (int i = 0 ; i < 100; i++) {
		buffer[i] = getch();
		if(buffer[i] == '\n'){
			printw("%s", buffer);
			char delimeter[] = " ";
			char *token1, *token2, *token3, *token4;
			buffer[i] = ' ';
			char *cp = strdup(buffer);		
			token1 = strtok(cp, delimeter);
			token2 = strtok(NULL, delimeter);
			token3 = strtok(NULL, delimeter);
			token4 = strtok(NULL, delimeter);
					
			if(strcmp(token1, "q") == 0){
				isQuit[0] = 1;
				break;
			} else if (strcmp(token1,"r") == 0 && token2 != NULL){
				char bufferauthorName[100] = " ";
				char bufferlevel[100] = " ";
				int c = 0;
				int r = 0;
				char * pointerAuthor = &bufferauthorName[0];
				char * pointerlevel = &bufferlevel[0];
				int * pointerCols = &c;
				int * pointerRows = &r;
				char * buff = readFile(token2, pointerAuthor, pointerlevel, pointerCols, pointerRows);
				if (buff == NULL){
					getmaxyx(stdscr,h,w);
					//clean the last row and move curse to the h-1,0
					move(h-1,0);
					for (int i = 0; i < w; i++) {
						addch(' ');
					}
					move(h-1,0);
					printw("File not found!");
				} else {
					//fileName
					for (int i = 0;; i++) {
						fileName[i] = token2[i];
						if(fileName[i] == '\0')break;
					}
					//push bask to name and level variable
					for (int i = 0;i < 100 ; i++) {
						authorName[i] = pointerAuthor[i];
						if(authorName[i] == '\0')break;
					}
					//level description
					for (int i = 0;i < 100 ; i++) {
						mapDescription[i] = pointerlevel[i];
						if(mapDescription[i] == '\0')break;
					}
					//rows and cols
					rows[0] = pointerRows[0];
					cols[0] = pointerCols[0];
					for (int i = 0; i < cols[0] * rows[0]; i++) {
						mapArray[i] = buff[i];
						if(i == rows[0] * cols[0] -1){
							mapArray[i + 1] = '\0';
						}
					}		
					clear();
					move(0,0);
					printw("File name: %s\n", fileName);
					printw("AuthorName: %s\n", authorName);
					printw("Map level: %s\n", mapDescription);
					printw("Number of Rows: %d\n", rows[0]);
					printw("Number of Cols: %d\n", cols[0]);
					renderMap(mapArray, rows[0], cols[0]);
					move(5,0);
				}
				break;
			} else if (strcmp(token1, "w") == 0 && token2 != NULL){
				for (int i = 0;; i++) {
					fileName[i] = token2[i];
					if(fileName[i] == '\0')break;
				}
				writeFile(fileName , authorName, mapDescription, cols[0], rows[0], mapArray);
				clear();
				move(0,0);
				printw("File name: %s\n", fileName);
				printw("AuthorName: %s\n", authorName);
				printw("Map level: %s\n", mapDescription);
				printw("Number of Rows: %d\n", rows[0]);
				printw("Number of Cols: %d\n", cols[0]);
				renderMap(mapArray, rows[0], cols[0]);
				cleanLastRow();
				move(h-1,0);
				printw("Printed to file named %s", fileName);
				move(5,0);
				break;
			} else if (strcmp(token1, "wq") == 0){
				writeFile(fileName, authorName, mapDescription, cols[0], rows[0], mapArray);
				getmaxyx(stdscr,h,w);
				move(h-1,0);
				for (int i = 0 ; i < w; i++) {
					addch(' ');
				}
				move(h-1,0);
				printw("Printed to file named %s", fileName);
						
				isQuit[0] = 1;
				break;
			} else if (strcmp(token1, "w")== 0 && token2 == NULL){
				writeFile(fileName , authorName, mapDescription, cols[0], rows[0], mapArray);
				getmaxyx(stdscr,h,w);
				move(h-1,0);
				printw("Printed to file named %s", fileName);
				move(0,0);
				break;
			}else if(strcmp(token1, "n") == 0 && token2 != NULL && token3 != NULL && token4 != NULL){
				for (int i = 0;;i++) {
					fileName[i] = token2[i];
					if(fileName[i] == '\0')break;
				}
				rows[0] = atoi(token3);
				cols[0] = atoi(token4);
				if(atoi(token3) >= 30 || atoi(token4) >= 65 || rows[0] == 0 || cols[0] == 0){
					cleanLastRow();
					getmaxyx(stdscr,h,w);
					move(h-1,0);					
					printw("Invalid rows and cols, 0 < rows <= 30, 0< cols <= 65");
					move(5,0);
					break;
				}
				for (int i = 0; i < rows[0] * cols[0]; i++) {
					mapArray[i] = 's';
				}
				clear();
				move(0,0);
				printw("File name: %s\n", fileName);
				printw("AuthorName: %s\n", authorName);
				printw("Map level: %s\n", mapDescription);
				printw("Number of Rows: %d\n", rows[0]);
				printw("Number of Cols: %d\n", cols[0]);
				renderMap(mapArray, rows[0], cols[0]);
				cleanLastRow();
				isQuit[0] = 0;
				move(5,0);
				break;
			} else if (strcmp(token1, "ca") == 0 && token2 != NULL){
				//change the author information
				for (int i = 0; ; i++) {
					authorName[i] = buffer[i+3];
					if(authorName[i] == '\0')break;
				}
				clear();
				move(0,0);
				printw("File name: %s\n", fileName);
				printw("AuthorName: %s\n", authorName);
				printw("Map level: %s\n", mapDescription);
				printw("Number of Rows: %d\n", rows[0]);
				printw("Number of Cols: %d\n", cols[0]);
				renderMap(mapArray, rows[0], cols[0]);
				break;
			}else if (strcmp(token1, "cm")== 0 && token2 != NULL){
				//change the map description
				for (int i = 0; ; i++) {
					mapDescription[i] = buffer[i+3];
					if(mapDescription[i] == '\0')break;
				}
				clear();
				move(0,0);
				printw("File name: %s\n", fileName);
				printw("AuthorName: %s\n", authorName);
				printw("Map level: %s\n", mapDescription);
				printw("Number of Rows: %d\n", rows[0]);
				printw("Number of Cols: %d\n", cols[0]);
				renderMap(mapArray, rows[0], cols[0]);
				break;
			} else {
				getmaxyx(stdscr,h,w);
				move(h-1,0);
				printw("Invalid command!");
				move(5,0);
				break;
			}
		} else if (buffer[i] == 27){
			getmaxyx(stdscr,h,w);
			move(h-1,0);
			for (int i = 0 ; i < w; i++) {
				addch(' ');
			}
			move(5,0);
			break;									  
		}
	}
}
Example #23
0
/**
 * Update the aim screen.
 * @returns	bool true if the player has fired, false otherwise
 */
bool updateAim() {
    float vert = joyReadF(true), horiz = joyReadF(false);
    bool updated = false;
    if(vert < -joyThreshold && aimY > 0) {
        aimY--;
        updated = true;
    }
    else if(vert > joyThreshold && aimY < MAP_SIZE - 1) {
        aimY++;
        updated = true;
    }

    if(horiz < -joyThreshold && aimX > 0) {
        aimX--;
        updated = true;
    }
    else if(horiz > joyThreshold && aimX < MAP_SIZE - 1) {
        aimX++;
        updated = true;
    }

    if (updated) {
        renderMap(&enemyMap);
        renderCursor(aimX, aimY);
    }

    if(buttonAPressed() && getState(enemyMap.squares[indexFromPos(aimX, aimY)]) == Map::UNKNOWN) {
        // Fire the shot!
        listenUntil(ENQ);
        sendPosition(aimX, aimY);

        // Get back a response
        bool hit = false;
        Ship::TYPES type = Ship::NONE;
        getResponse(&hit, &type);
        Serial.print("Hit: ");//DEBUG
        Serial.println(hit);//DEBUG
        Serial.print("Type: ");//DEBUG
        Serial.println(getTypeName(type));//DEBUG

        if (hit) {
            if (type != Ship::NONE) {
                String name = getTypeName(type);
                enemyMap.ships[getShipIndex(type)].health = 0;
                String message[] = {"You sunk the enemy's", name + "!"};
                renderMessage(message, 2);
            } else {
                String message[] = {"You hit!"};

                renderMessage(message, 1);
            }
        } else {
            String message[] = {"You missed!"};
            renderMessage(message, 1);
        }

        setState(&enemyMap.squares[indexFromPos(aimX, aimY)], hit ? Map::HIT : Map::MISS);
        renderMap(&enemyMap);
        renderCursor(aimX, aimY);

        while (!buttonAPressed()) {}

        return true;
    }
    return false;
}
Example #24
0
void renderGame()
{
    renderMap();        // renders the map to the buffer first
    renderCharacter();  // renders the character into the buffer
}
Example #25
0
int main(int argc, char** argv) {
	std::cout << "*homework 15*" << std::endl;

	std::ifstream inputFile(SOURCE_DIR "/sources/15/input.txt");
	std::ofstream outputFile(SOURCE_DIR "/sources/15/output.txt");

	if ( !inputFile.is_open() || !outputFile.is_open()){
		std::cout << "cannot open files" << std::endl;
		return 1;
	}

	size_t linesCount = 0;
	size_t lineLength = 0;
	std::string strBuff;
	landmap_t landmap;
	const std::string marks =
			"01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	while (std::getline(inputFile, strBuff)) {
		landmap.push_back(strBuff);
	}
	linesCount = landmap.size();
	lineLength = landmap[0].length();

	renderMap(landmap);

	unsigned int landCount = 0;
	unsigned int correction = 0;
	char currMark = marks[0];

	//jump over lines
	for (unsigned int y = 0; y < linesCount; y++) {

		//jump inside line
		for (unsigned int x = 0; x < lineLength; x++) {

			if (isLand(landmap, x, y)) {

				currMark = marks[landCount];

				while (isLand(landmap, x + 1, y)) {

					if (isLand(landmap, x, y - 1)
							&& getLandChar(landmap, x, y - 1) != currMark) {
						correction++;
					}

					if (isLand(landmap, x, y - 1)) {
						currMark = getLandChar(landmap, x, y - 1);
					}

					setLandChar(landmap, x, y, currMark);
					x++;
				}

				if (isLand(landmap, x, y - 1)
						&& getLandChar(landmap, x, y - 1) != currMark) {
					correction++;
				}

				setLandChar(landmap, x, y, currMark);

				if (!isLand(landmap, x + 1, y)) {
					landCount++;
				}
			}
		}

		//normalize line
		for (unsigned int x = 0; x < lineLength; x++) {
			if (isLand(landmap, x, y)) {
				currMark = getLandChar(landmap, x, y);

				while (isLand(landmap, x + 1, y)) {
					setLandChar(landmap, x + 1, y, currMark);
					x++;
				}
			}
		}
	}

	renderMap(landmap);

	std::cout << " l:" << landCount << " c:" << correction << " rez:"
			<< landCount - correction << std::endl;

	outputFile << landCount - correction << std::endl;

	inputFile.close();
	outputFile.close();

	return 0;
}
Example #26
0
int main(int argc, char * argv[]){
	//init curses context
	(void) initscr();
	keypad(stdscr, TRUE);
	(void) cbreak();
	(void) noecho();
	//finished initing curses context
	char file[100] = "demofile.pac";
	char name[100] = "unknown author";
	char level[100] = "unknown level desciption";
	
	char * fileName = &file[0];  
	char * authorName = &name[0];
	char * mapLevel = &level[0];
	int * rows = malloc(sizeof(int)* 1);
	int * cols = malloc(sizeof(int)*1);	
	char * mapArray = malloc(sizeof(char)* 2000);
	rows[0] = 0;
	cols[0] = 0;
	int quit = 0;
	int *  isQuit = &quit;

	//if argc == 2, the argument is fileName
	if(argc == 2){
		int h,w;
		char bufferauthorName[100] = " ";
		char bufferlevel[100] = " ";
		int c = 0;
		int r = 0;
		char * pointerAuthor = &bufferauthorName[0];
		char * pointerlevel = &bufferlevel[0];
		int * pointerCols = &c;
		int * pointerRows = &r;
		char * buff = readFile(argv[1], pointerAuthor, pointerlevel, pointerCols, pointerRows);
		if (buff == NULL){
			getmaxyx(stdscr,h,w);
			//clean the last row and move curse to the h-1,0
			move(h-1,0);
			for (int i = 0; i < w; i++) {
				addch(' ');
			}
			move(h-1,0);
			printw("File not found!");
		} else {
			//fileName
			for (int i = 0;; i++) {
				fileName[i] = argv[1][i];
				if(fileName[i] == '\0')break;
			}
			//push bask to name and level variable
			for (int i = 0;i < 100 ; i++) {
				authorName[i] = pointerAuthor[i];
				if(authorName[i] == '\0')break;
			}
			//level description
			for (int i = 0;i < 100 ; i++) {
				mapLevel[i] = pointerlevel[i];
				if(mapLevel[i] == '\0')break;
			}
			//rows and cols
			rows[0] = pointerRows[0];
			cols[0] = pointerCols[0];

			for (int i = 0; i < cols[0] * rows[0]; i++) {
				mapArray[i] = buff[i];
				if(i == rows[0] * cols[0] -1){
					mapArray[i + 1] = '\0';
				}
			}		
			clear();
			move(0,0);
			attrset(COLOR_PAIR(1));
			printw("File name: %s\n", fileName);
			printw("AuthorName: %s\n", authorName);
			printw("Map level: %s\n", mapLevel);
			printw("Number of Rows: %d\n", rows[0]);
			printw("Number of Cols: %d\n", cols[0]);
			attrset(COLOR_PAIR(2));
			renderMap(mapArray, rows[0], cols[0]);
			move(5,0);
		}
	}
	editMode(fileName,authorName,mapLevel,rows,cols,mapArray);
    
	free(rows);
	free(cols);
	free(mapArray);
	endwin();

	return 0;
}
Example #27
0
int main(void)
{
//    int good = 0;
//    int numeroMap = 0;
//    do{
//        printf("Quelle map?\n");
//        printf("1 - Original\n");
//        printf("2 - Hard\n");
//        printf("3 - Lol\n");
//        printf("4 - Rez De chaussez Aile Sud Telecom Nancy\n");
//        scanf("%d", &numeroMap);
//        switch(numeroMap){
//            case 1:
//                loadMap("../projec/map/original.map");
//                good = 1;
//                break;
//            case 2:
//                loadMap("../projec/map/hard.map");
//                good = 1;
//                break;

//            case 3:
//                loadMap("../projec/map/maplol.map");
//                good = 1;
//                break;
//            case 4:
//                loadMap("../projec/map/rdastn.map");
//                good = 1;
//                break;

//            case 42:
//                loadMap("../projec/map/rdastn.map");
//                good = 1;
//                setQ();
//                break;
//        }
//    }while(!good);
    //Create SDL objects
    SDL_Window *window = 0;
    SDL_Event event;
    SDL_Renderer *renderer = 0;
    int terminate = 0;

    //Initialise SDL
    if(SDL_Init(SDL_INIT_VIDEO) < 0){
        printf("Error with SDL : %s\n", SDL_GetError());
        SDL_Quit();
        return EXIT_FAILURE;
    }

    window = SDL_CreateWindow("Pacman", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 544, 344, SDL_WINDOW_SHOWN);
    terminate = 0;
    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    SDL_Surface *menu = IMG_Load("../projec/texture/menu/menu.jpg");

    SDL_Texture *menuTexture = SDL_CreateTextureFromSurface(renderer, menu);

    SDL_FreeSurface(menu);
    SDL_RenderClear(renderer);
    int x, y;
    while(!terminate){
        SDL_Rect dest = {0, 0, 544, 344};
        SDL_RenderCopy(renderer, menuTexture, NULL, &dest);
        SDL_RenderPresent(renderer);
        SDL_WaitEvent(&event);
        switch(event.type){
            case SDL_MOUSEBUTTONDOWN:
                x = event.motion.x;
                y = event.motion.y;
                if(x >= 57 && x <= (57+54) && y >=  94 && y <= (94 + 74)){
                    loadMap("../projec/map/original.map");
                    terminate = 1;
                }
                if(x >= 124 && x <= (124+53) && y >=  208 && y <= (208 + 73)){
                    loadMap("../projec/map/hard.map");
                    terminate = 1;
                }
                if(x >= 221 && x <= (221+59) && y >=  95 && y <= (95 + 80)){
                    loadMap("../projec/map/maplol.map");
                    terminate = 1;
                }
                if(x >= 311 && x <= (311+63) && y >=  208 && y <= (208 + 76)){
                    loadMap("../projec/map/rdastn.map");
                    terminate = 1;
                }
                if(x >= 350 && x <= (350+124) && y >=  73 && y <= (73 + 109)){
                    loadMap("../projec/map/rdastn.map");
                    terminate = 1;
                    setQ();
                }
                break;
        }

        SDL_Delay(1000 / FPS);
    }
    SDL_DestroyTexture(menuTexture);

    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);

    //Search the pacman on the map and create him
    Pacman *pacman = getPacmanInstance();
    unsigned int initialX = pacman->x;
    unsigned int initialY = pacman->y;
    Map *map = getMapInstance();
    //If the pacman is not found
    if(!pacman){
        printf("Pacman not found on map\n");
        freeMap(map);
        exit(EXIT_FAILURE);
    }
    printf("Pacman found !\n");

    Ghost *clyde = searchAndCreateGhost(CLYDE);
    if(!clyde){
        printf("Clyde not found on map\n");
        freeMap(map);
        exit(EXIT_FAILURE);
    }
    printf("Clyde found !\n");

    Ghost *blinky = searchAndCreateGhost(BLINKY);
    if(!blinky){
        printf("Blinky not found on map\n");
        freeMap(map);
        freeGhost(clyde);
        exit(EXIT_FAILURE);
    }
    printf("Blinky found !\n");

    Ghost *inky = searchAndCreateGhost(INKY);
    if(!inky){
        printf("Inky not found on map\n");
        freeMap(map);
        freeGhost(clyde);
        freeGhost(blinky);
        exit(EXIT_FAILURE);
    }
    printf("Inky found !\n");

    Ghost *pinky = searchAndCreateGhost(PINKY);
    if(!pinky){
        printf("Pinky not found on map\n");
        freeMap(map);
        freeGhost(clyde);
        freeGhost(blinky);
        freeGhost(inky);
        exit(EXIT_FAILURE);
    }
    printf("Pinky found !\n");
    printf("SDL initialisation\n");



    if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) == -1){
        printf("%s", Mix_GetError());
    }

    Mix_Music *music = NULL;
    music = Mix_LoadMUS("../projec/pacman.wav");
    if(!music){
        printf("Erreur de chargement de la musique %s \n", Mix_GetError());
    }else{
        Mix_VolumeMusic(MIX_MAX_VOLUME);
        Mix_PlayMusic(music, -1);
    }

    if(TTF_Init() == -1){
        printf("Error during TTF initialization : %s\n", TTF_GetError());
    }

    TTF_Font *police = NULL;

    police = TTF_OpenFont("../projec/monof.ttf", 65);
    if(!police){
        printf("Error during font load : %s\n", TTF_GetError());
    }
    SDL_Color color = { 255, 255, 255, 255};



    //Create the window
    window = SDL_CreateWindow("Pacman", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, TILE_SIZE * map->col, TILE_SIZE * map->row + TILE_SIZE, SDL_WINDOW_SHOWN);

    //If there is an error
    if(window == 0){
        printf("Error during window creation : %s \n", SDL_GetError());
        SDL_Quit();
        freeMap(map);
        return EXIT_FAILURE;
    }
    int j;
    printf("SDL init success\n");
    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);

    //NEED gerer erreurs

    loadTextures(renderer);

    SDL_Surface *score = TTF_RenderText_Solid(police, "Score : ", color);
    SDL_Texture *scoreT = SDL_CreateTextureFromSurface(renderer, score);
    SDL_FreeSurface(score);
    char scoreString[15];

    SDL_Rect dest = {0, map->row * TILE_SIZE , map->row * TILE_SIZE / 6, 20};
    SDL_RenderCopy(renderer, scoreT, NULL, &dest);
    SDL_Surface *scoreN;
    SDL_Texture *scoreTN;
    int open = 0;
    int konami[10] = {0,0,0,0,0,0,0,0,0,0};
    //Infinite loop until we want to stop the game
    terminate = 0;
    while(!terminate){
        SDL_Rect dest2 = {map->row * TILE_SIZE / 6, map->row * TILE_SIZE, map->row * TILE_SIZE / 15, 20};
        sprintf(scoreString, "%d", pacman->point);
        scoreN = TTF_RenderText_Solid(police, scoreString, color);
        scoreTN = SDL_CreateTextureFromSurface(renderer, score);
        renderMap(renderer);
        open = renderPacman(open, renderer);
        renderClyde(clyde, renderer);
        renderBlinky(blinky, renderer);
        renderPinky(pinky, renderer);
        renderInky(inky, renderer);

        changeDirectionGhost(blinky);
        changeDirectionGhost(clyde);
        changeDirectionGhost(inky);
        changeDirectionGhost(pinky);
        SDL_Rect dest = {0, map->row * TILE_SIZE , map->row * TILE_SIZE / 6, 20};
        SDL_RenderCopy(renderer, scoreT, NULL, &dest);



        SDL_RenderCopy(renderer, scoreTN, NULL, &dest2);

        SDL_RenderPresent(renderer);
        //Event handling

        SDL_PollEvent(&event);
        switch(event.type){
            case SDL_KEYDOWN:
                switch(event.key.keysym.scancode){
                    case SDL_SCANCODE_UP:
                        setPacmanDirection(NORTH);
                        if(konami[0]){
                            if(konami[1]){
                                for(j = 0 ; j < 10 ; j++){
                                    konami[j] = 0;
                                }
//                                printf("Déjà deux\n");
                            }else{
                                konami[1] = 1;
                            }
                        }else{
                            konami[0] = 1;
                        }
                        break;
                    case SDL_SCANCODE_DOWN:
                        setPacmanDirection(SOUTH);
                        break;
                    case SDL_SCANCODE_RIGHT:
                        setPacmanDirection(EAST);
                        break;
                    case SDL_SCANCODE_LEFT:
                        setPacmanDirection(WEST);
                        break;
                    default:
                        break;
                }
                break;
        }
        terminate = update(clyde, blinky, inky, pinky);
        if(terminate){
            if(pacman->life > 0 ){
                pacman->life--;
                terminate = 0;
                pacman->x = initialX;
                pacman->y = initialY;
            }
        }
        if(event.window.event == SDL_WINDOWEVENT_CLOSE){
            terminate = 1;
        }
        SDL_Delay(1000 / FPS);
        SDL_DestroyTexture(scoreTN);
        SDL_FreeSurface(scoreN);
    }
    printf("Score final : %d\n", pacman->point);
    Mix_FreeMusic(music);
    Mix_CloseAudio();
    freeTextures();
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    SDL_DestroyTexture(scoreT);
    freePacman();
    freeGhost(clyde);
    freeGhost(blinky);
    freeGhost(inky);
    freeGhost(pinky);
    freeMap();
    TTF_CloseFont(police);
    TTF_Quit();
    return EXIT_SUCCESS;
}