Exemple #1
0
int solo(sf::RenderWindow* p_window)
{
    p_window->setSize(sf::Vector2u(800, 900));
    p_window->setFramerateLimit(60);
    p_window->setMouseCursorVisible(false);

    sf::Clock clock;
    int frames = 0;

    mapping backgroung;
    HUD scores;

    sf::Font font;
    std::vector<vaisseau*> entity_tab;
    std::vector<missile*> missile_tab;
    std::vector<Bonus*> bonus_tab;


    entity_tab.push_back(new player(&missile_tab, &entity_tab));
    player* p =  (player*) (entity_tab[0]);


    float spawnBonus(0);

    Spawn basicSpawn(200, &entity_tab, &missile_tab);

    while (p_window->isOpen())
    {
        basicSpawn.create();

        sf::Event event;
        while (p_window->pollEvent(event))

        {
            //int RandomBonus;
            //RandomBonus = rand()%1001;
            if (event.type == sf::Event::Closed)
                p_window->close();
            else if((event.type == sf::Event::MouseButtonPressed) and (event.mouseButton.button == sf::Mouse::Left))
                p->shooting(1);
            else if((event.type == sf::Event::MouseButtonPressed) and (event.mouseButton.button == sf::Mouse::Right))
                p->shooting(2);
            else if((event.type == sf::Event::MouseButtonReleased) and (event.mouseButton.button == sf::Mouse::Right or event.mouseButton.button == sf::Mouse::Left))
            {
                if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
                    p->shooting(1);
                else if(sf::Mouse::isButtonPressed(sf::Mouse::Right))
                    p->shooting(2);
                else
                    p->shooting(0);
            }
            else if (event.type == sf::Event::LostFocus and !pause(p_window, false))
            {
                if(!pause(p_window, false))
                    p_window->close();
                else
                {
                    //TODO reset des timers entity, missiles, bonus
                }
            }
            else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
            {
                if(!pause(p_window, true))
                    p_window->close();
                else
                {
                    //TODO reset des timers entity, missiles, bonus
                }
            }
        }

        //if(sf::Mouse::getPosition(*p_window).x-10 > 0 and sf::Mouse::getPosition(*p_window).y-10 > 0 and sf::Mouse::getPosition(*p_window).y < (float) p_window->getSize().y and sf::Mouse::getPosition(*p_window).x < (float) p_window->getSize().x)
        //    p->setPosition(sf::Mouse::getPosition(*p_window).x-10, sf::Mouse::getPosition(*p_window).y-10);
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up) or sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
            p->acceleration(2);
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) or sf::Keyboard::isKeyPressed(sf::Keyboard::S))
            p->acceleration(3);
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left) or sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
            p->acceleration(0);
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) or sf::Keyboard::isKeyPressed(sf::Keyboard::D))
            p->acceleration(1);

        if(clock.getElapsedTime() > sf::seconds(1.f))
        {
            std::stringstream ss;//create a stringstream
            ss << frames;//add number to the stream
            p_window->setTitle("SFMl window FPS="+ss.str());
            clock.restart();
            frames = 0;
        }
        frames += 1;

        p_window->clear();

        backgroung.Draw(p_window);

        for(std::vector<Bonus*>::size_type u = 0 ; u < bonus_tab.size() ; u++)
        {
            bonus_tab.at(u)->Draw(p_window);
        }

        for(std::vector<missile*>::size_type i = 0 ; i < missile_tab.size() ; i++)//parcour de tous les missiles
        {
            sf::Vector2f missilPos = missile_tab[i]->getPosition();
            missile_tab[i]->Draw(p_window);//on le dessine
            if(missilPos.y < 0 or missilPos.y > p_window->getSize().y or missilPos.x < 0 or missilPos.x > p_window->getSize().x)//si or de la fenetre
                missile_tab.erase(missile_tab.begin()+i);//on le suprime
            else//sinon on regarde les colisions
            {
                for(std::vector<vaisseau*>::size_type j = 0 ; j < entity_tab.size() ; j++)
                {
                    sf::FloatRect entityBound = entity_tab[j]->getGlobalBound();//recupération des donnée du vaisseau

                    if(entityBound.left < -50 or entityBound.top < -50 or entityBound.top > p_window->getSize().y+50 or entityBound.left > p_window->getSize().x+50)//on en profite pour regarder si il est bien dans la fenetre
                    {
                        entity_tab.erase(entity_tab.begin()+j);
                    }
                    else if(
                        !(missilPos.y < entityBound.top or missilPos.y > entityBound.top+entityBound.height or
                        missilPos.x < entityBound.left or missilPos.x > entityBound.left+entityBound.width))//le missile touche-il l'entité?
                    {
                        missile_tab.erase(missile_tab.begin()+i);//supression du missile
                        entity_tab[j]->onHit(1.f);//on inflige 1 de degat a l'entité


                        if(entity_tab[j]->isAlive()==false)
                        {
                           spawnBonus=spawnBonus+0.8;
                            if(spawnBonus>2 && spawnBonus!= 2.2)
                            {
                                 bonus_tab.push_back(new Bonus(entity_tab[j]->getPosition(),sf::Color(200, 0 ,0),sf::Color(250, 0 ,0), 0.5));
                                 spawnBonus = spawnBonus-2;

                            }
                            else if(spawnBonus==2)
                            {
                                 bonus_tab.push_back(new Bonus(entity_tab[j]->getPosition(),sf::Color(0, 200 ,0), sf::Color(0, 250 ,0), 0.5));
                                 spawnBonus = spawnBonus-2;

                            }
                        }


                    }

                }
            }
        }

        sf::FloatRect playerBound = entity_tab[0]->getGlobalBound();

        for(std::vector<Bonus*>::size_type a = 0 ; a < bonus_tab.size() ; a++)
        {
            sf::FloatRect bonusBound = bonus_tab[a]->getGlobalBound();

            if(bonusBound.left+bonusBound.width<0 or bonusBound.left>(float) p_window->getSize().x or bonusBound.top+bonusBound.height<0 or bonusBound.top > (float) p_window->getSize().y)
            {
                bonus_tab.erase(bonus_tab.begin()+a);
            }
            else if(!(bonusBound.left<playerBound.left or bonusBound.left>playerBound.left+playerBound.width or bonusBound.top<playerBound.top or bonusBound.top>playerBound.top+playerBound.height)
                or !(bonusBound.left+bonusBound.width<playerBound.left or bonusBound.left+bonusBound.width>playerBound.left+playerBound.width or bonusBound.top<playerBound.top or bonusBound.top>playerBound.top+playerBound.height)
                or !(bonusBound.left<playerBound.left or bonusBound.left>playerBound.left+playerBound.width or bonusBound.top+bonusBound.height<playerBound.top or bonusBound.top+bonusBound.height>playerBound.top+playerBound.height)
                or !(bonusBound.left+bonusBound.width<playerBound.left or bonusBound.left+bonusBound.width>playerBound.left+playerBound.width or bonusBound.top+bonusBound.height<playerBound.top or bonusBound.top+bonusBound.height>playerBound.top+playerBound.height))
            {
                scores.changeScore(bonus_tab[a]->getFillColor(), bonus_tab[a]->getOutlineColor(), bonus_tab[a]->bonusVal());
                bonus_tab.erase(bonus_tab.begin()+a);

            }

        }
        for(std::vector<vaisseau*>::size_type u = 0 ; u < entity_tab.size() ; u++)
        {
            entity_tab.at(u)->Draw(p_window);
        }

        scores.Draw(p_window);

        p_window->display();
    }

    return 0;
}
int Game::Run(RenderWindow &win, VideoMode &vMode)
{
	lua_State *luaState = luaL_newstate();
	luaL_openlibs(luaState);
	luabind::open(luaState);
	Map map;
	Player player(luaState, e_player,0);// 0 should be loaded from file
	player.RegisterClassToLua();
	battle_system battle;

	Object *object;
	object = new Object(luaState);
	Event Event;
	NPC npc(e_npc_random, luaState, -1);
	npc.SetPosition(200,200);
	
	bool collisionUp = false;
	bool collisionDown = false;
	bool collisionLeft = false;
	bool collisionRight = false;
	bool change = true;
	bool running = false;
	bool gameOver = false;
	bool load = false;
	bool load2 = false;


	Image gameOverImg;
	gameOverImg.LoadFromFile("../data/Images//presents.png");
	Sprite gameOverSp(gameOverImg);
	
	vector<string> mapList;
	vector<string> objectList;
	mapList.push_back("..\\data\\Levels\\Map1.txt");
	mapList.push_back("..\\data\\Levels\\Map2.txt");
	mapList.push_back("..\\data\\Levels\\Map3.txt");
	mapList.push_back("..\\data\\Levels\\Map2.txt");
	mapList.push_back("..\\data\\Levels\\Map1.txt");
	mapList.push_back("..\\data\\Levels\\Map2.txt");
	mapList.push_back("..\\data\\Levels\\Map3.txt");
	mapList.push_back("..\\data\\Levels\\Map3.txt");
	mapList.push_back("..\\data\\Levels\\Map1.txt");
	mapList.push_back("..\\data\\Levels\\Map2.txt");






	objectList.push_back("..\\data\\Levels\\Object1.txt");
	objectList.push_back("..\\data\\Levels\\Object2.txt");
	objectList.push_back("..\\data\\Levels\\Object3.txt");
	objectList.push_back("..\\data\\Levels\\Object4.txt");
	objectList.push_back("..\\data\\Levels\\Object5.txt");
	objectList.push_back("..\\data\\Levels\\Object6.txt");
	objectList.push_back("..\\data\\Levels\\Object7.txt");
	objectList.push_back("..\\data\\Levels\\Object8.txt");
	objectList.push_back("..\\data\\Levels\\Object9.txt");
	objectList.push_back("..\\data\\Levels\\Object10.txt");


	string level = mapList[0];//Load from file
	string levelObject = objectList[0];
	
	HUD hud;
	Enemy enemy;
	while(win.IsOpened())
	{
		while(win.GetEvent(Event))
		{
			if(Event.Type == Event::Closed)
			{
				win.Close();
			}
		}
		if(win.GetInput().IsKeyDown(Key::Space))
		{
			level = mapList[1];
			change = true;
			load2 = true;
			if(!object->LoadObjects(vMode, &win, levelObject, &player, luaState))
			{
				win.Close();
			}
		}

		if(!win.GetInput().IsKeyDown(Key::Space) && load2 == true)
		{
			load2 = false;
			change = false;
		}
		if(win.GetInput().IsKeyDown(Key::T))
		{
			player.RunGoldScript();
		}
		if(win.GetInput().IsKeyDown(Key::LShift))
		{
			level = mapList[0];
			change = true;
			load = true;
			player.ChangeMap(0);
			/*if(!map.LoadMap(vMode, &win, "..\\data\\Levels\\Map1.txt"))
			{
				win.Close();
			}*/
			if(!object->LoadObjects(vMode, &win, "..\\data\\Levels\\Object1.txt", &player, luaState))
			{
				win.Close();
			}
		}

		if(!win.GetInput().IsKeyDown(Key::LShift) && load == true)
		{
			load = false;
			change = false;
		}
		
		if(!object->IsDisabled())
		{
		if(win.GetInput().IsKeyDown(Key::Up)&& !win.GetInput().IsKeyDown(Key::Left) && !win.GetInput().IsKeyDown(Key::Right))
		{
				if(object->HasCollidedWithObject(player, &win) == exitsensor)
				{
					cout<<"collided"<<object->GetCollidedExitSensor(player)->GetDestinationID();
					if(object->GetCollidedExitSensor(player)->GetDestinationID() == 1)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 2)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 3)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 4)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}

					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 5)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}

					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 7)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 8)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 9)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 10)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}

					
				}

				else
					{
					if(object->HasCollidedWithObject(player, &win) == -1 )
					{	
						player.MoveUp(&win);
						if(player.GetView().GetCenter().y - player.GetView().GetHalfSize().y > -160)
						{
							hud.MoveUp(&win);
						}
				
					}
					else
					{
					player.SetPosition(player.GetSprite().GetPosition().x , player.GetSprite().GetPosition().y + 10);
					}
			
				}
				}

		if(win.GetInput().IsKeyDown(Key::Down)&& !win.GetInput().IsKeyDown(Key::Left) && !win.GetInput().IsKeyDown(Key::Right))
		{
			if(player.GetSprite().GetPosition().y + player.GetSprite().GetSize().y<600)
			{
				if(object->HasCollidedWithObject(player, &win) == exitsensor)
				{
					cout<<"collided"<<object->GetCollidedExitSensor(player)->GetDestinationID();
					if(object->GetCollidedExitSensor(player)->GetDestinationID() == 1)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 2)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 3)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 4)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}

					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 5)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}

					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 7)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 8)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 9)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}
					else if(object->GetCollidedExitSensor(player)->GetDestinationID() == 110)
					{
						cout<<"dest:";
						if(object->GetCollidedExitSensor(player)->IsObjectiveComplete())
						{
							cout<<"Exit";
							level = mapList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							levelObject = objectList[object->GetCollidedExitSensor(player)->GetDestinationID()];
							change = true;
							player.ChangeMap(object->GetCollidedExitSensor(player)->GetDestinationID());
							object->ClearSensors();
						}
						else
						{
						}
					}

					
				}
				else
				{
				if(object->HasCollidedWithObject(player, &win) == -1)
				{	
				player.MoveDown(&win);
				if(player.GetView().GetCenter().y <= 300)
				{
					hud.MoveDown(&win);
				}
				}
				else
				{
				player.SetPosition(player.GetSprite().GetPosition().x , player.GetSprite().GetPosition().y - 10);
				}
				}
			}
		
		}
		if(win.GetInput().IsKeyDown(Key::Left) && !win.GetInput().IsKeyDown(Key::Up) && !win.GetInput().IsKeyDown(Key::Down)&& !win.GetInput().IsKeyDown(Key::Right))
		{	
			if(object->HasCollidedWithObject(player, &win) == -1)
			{
				player.MoveLeft(&win);
				
			}
			else
			{
				player.SetPosition(player.GetSprite().GetPosition().x + 10, player.GetSprite().GetPosition().y);
			}
		}
		if(win.GetInput().IsKeyDown(Key::Right)&& !win.GetInput().IsKeyDown(Key::Up) && !win.GetInput().IsKeyDown(Key::Down)&& !win.GetInput().IsKeyDown(Key::Left))
		{
			if(object->HasCollidedWithObject(player, &win) == -1)
			{
				player.MoveRight(&win);
				
			}
			else
			{
				player.SetPosition(player.GetSprite().GetPosition().x - 10, player.GetSprite().GetPosition().y);
			}
		}
		}
		if(win.GetInput().IsKeyDown(Key::A))
		{
		}
		if(object->HasCollidedWithObject(player, &win) == noncollectible)
		{
			if(player.m_up) player.SetPosition(player.GetSprite().GetPosition().x , player.GetSprite().GetPosition().y + 10);
			if(player.m_down) player.SetPosition(player.GetSprite().GetPosition().x , player.GetSprite().GetPosition().y - 10);
			if(player.m_right) player.SetPosition(player.GetSprite().GetPosition().x - 10, player.GetSprite().GetPosition().y);
			if(player.m_left) player.SetPosition(player.GetSprite().GetPosition().x + 10, player.GetSprite().GetPosition().y);
		}
		
		

		hud.Update(&player);
		object->Update(player);
		if(!object->IsBattling())
		{
		win.Clear();
		if(change)
		{
			if(!map.LoadMap(vMode, &win, level))
			{
				win.Close();
			}
			if(!object->LoadObjects(vMode, &win, levelObject, &player, luaState))
			{
				win.Close();
			}
			
			change = false;
		}
		map.RenderMap(vMode, &win);
		player.Draw(vMode, &win);
		if(object->RenderObjects(vMode, &win, &player, luaState) == false) return 0;
		hud.Draw(&win);
		}
		else
		{
			win.Clear();
			NPC* npc;
			npc = object->GetCollidedNPC();
			battle.Initialize((player.GetView().GetCenter().x-player.GetView().GetHalfSize().x),(player.GetView().GetCenter().y-player.GetView().GetHalfSize().y));
			if(battle.Run(vMode, win, &enemy, player) == "Exits")
			{
				object->StopBattle();
			}
			else if(battle.Run(vMode, win, &enemy, player) == "Player Win")
			{
				object->StopBattle();
				object->RemoveNPC(object->GetCollidingIndex(), &win, &player);
			}
			else if(battle.Run(vMode, win, &enemy, player) == "Enemy Win")
			{
				object->StopBattle();
				object->NotDisabled();
				player.Default();
				enemy.Default();

				if(!map.LoadMap(vMode, &win, "..\\data\\Levels\\Map1.txt"))
				{
					win.Close();
				}
				if(!object->LoadObjects(vMode, &win, "..\\data\\Levels\\Object1.txt", &player, luaState))
				{
					win.Close();
				}
			}
			player.SetView(400,300);
		}
		object->DrawCommentSystem();
		win.SetView(player.GetView());
		win.Display();
	}
	lua_close(luaState);
	return -1;
}