bool DefaultHandleEvent(RenderWindow& win, Event& event) { switch (event.Type) { case Event::Closed: win.Close(); return true; case Event::KeyPressed: if (event.Key.Code == Key::Escape) { win.Close(); return true; } default: return false; } }
void noyau::run() { //------------------------------------------------------------------------------------------------------ // Ensemble des gestionnaires de sprites/sons/musiques spriteHandler *instSpriteHandler = spriteHandler::getInstance(); soundHandler *instSoundHandler = soundHandler::getInstance(); musicHandler *instMusicHandler = musicHandler::getInstance(); //Instanciation du gestionnaire de la BDD interne bddInternalHandler *instBddInternalHandler = bddInternalHandler::getInstance(); //Gestionnaire des maps mapHandler *instMapHandler = mapHandler::getInstance(); //------------------------------------------------------------------------------------------------------ //Test de musique //instMusicHandler->getMusic("SkinnyLove")->Play(); //Test de son Sound soundActivate; soundActivate.SetBuffer(*instSoundHandler->getSound("activated")); soundActivate.Play(); //------------------------------------------------------------------------------------------------------ /* //Test d'affichage d'un sprite Sprite spriteIn; spriteIn.SetImage(*instSpriteHandler->getImage("scientifiqueFront")); spriteIn.SetPosition(200, 100); spriteIn.SetScale(2, 2); */ animation firstAnim = animation("1",true); //firstAnim.play(); firstAnim.stop(); // Start game loop while (fenetrePrincipal.IsOpened()) { // Process events Event Event; while (fenetrePrincipal.GetEvent(Event)) { // Close window : exit if (Event.Type == Event::Closed || fenetrePrincipal.GetInput().IsKeyDown(Key::Escape)) fenetrePrincipal.Close(); } // Get elapsed time float ElapsedTime = fenetrePrincipal.GetFrameTime(); if (Event.Key.Code == Key::F12) { fenetrePrincipal.Capture().SaveToFile("Screenshot\\screenshot1.jpg"); cout<<"screen effectué"<<endl; } // Move the sprite if (fenetrePrincipal.GetInput().IsKeyDown(sf::Key::Left)) firstAnim.move(-100 * ElapsedTime, 0); if (fenetrePrincipal.GetInput().IsKeyDown(sf::Key::Right)) firstAnim.move( 100 * ElapsedTime, 0); if (fenetrePrincipal.GetInput().IsKeyDown(sf::Key::Up)) firstAnim.move(0, -100 * ElapsedTime); if (fenetrePrincipal.GetInput().IsKeyDown(sf::Key::Down)) { firstAnim.move(0, 100 * ElapsedTime); firstAnim.play(); } // Rotate the sprite //if (fenetrePrincipal.GetInput().IsKeyDown(sf::Key::Add)) Sprite.Rotate(- 100 * ElapsedTime); /*if (fenetrePrincipal.GetInput().IsKeyDown(sf::Key::R)) firstAnim.Rotate(+ 100 * ElapsedTime);*/ if (fenetrePrincipal.GetInput().IsKeyDown(sf::Key::T)) cout<<"Phase : "<<timerC.GetElapsedTime()<<endl; // Clear screen fenetrePrincipal.Clear(); // Display sprite of the map in our window instMapHandler->afficherAll(fenetrePrincipal); //few test on the Animation classe firstAnim.afficher(fenetrePrincipal); board titi = board(); titi.init(300,300,330,330,sf::Color(255,255,255),"coucou",30,sf::Color(0,0,0),3,sf::Color(0,0,0)); titi.affiche(fenetrePrincipal); /* if(timerC.GetElapsedTime()>=10) { if(timerC.GetElapsedTime()<=20) firstAnim.stop(); else firstAnim.play(); } */ /* */ /* sf::Shape Line = sf::Shape::Line(30,30,60,60,3,sf::Color(255,255,255)); sf::Shape Circle = sf::Shape::Circle(90,90,20,sf::Color(255,255,255),1,sf::Color(0,0,0)); sf::Shape Rect = sf::Shape::Rectangle(200,200,220,220,sf::Color(255,255,255)); fenetrePrincipal.Draw(Line); fenetrePrincipal.Draw(Circle); fenetrePrincipal.Draw(Rect); */ //fenetrePrincipal.Draw(spriteIn); // Display window contents on screen fenetrePrincipal.Display(); //fenetrePrincipal.SetView(View); firstAnim.stop(); } }
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; }
int Game::Run(RenderWindow &win, VideoMode &vMode) { Music m; SoundBuffer playerShootBuffer; SoundBuffer meteorBuffer; meteorBuffer.LoadFromFile("..\\Resources\\meteorexplosion.ogg"); playerShootBuffer.LoadFromFile("..\\Resources\\playerShoot.ogg"); Sound playerSound; Sound meteorSound; meteorSound.SetBuffer(meteorBuffer); playerSound.SetBuffer(playerShootBuffer); playerSound.SetLoop(false); meteorSound.SetLoop(false); m.OpenFromFile("..\\Resources\\asteroid.ogg"); m.SetLoop(true); m.SetVolume(100); PlayerShip ship(player_ship, 2, vMode); EnemyShip enemy(enemy_ship, vMode); Collision col; Event events; Image bg1; Image bg2; Image bg3; bg1.LoadFromFile("..\\Resources\\bg.jpg"); Image stars; string abc = "..\\Resources\\star.png"; stars.LoadFromFile(abc); Sprite sp(bg1); Sprite sp2(bg1); Sprite sp3(bg1); Sprite spStar[10]; Clock clock; srand((unsigned)time(0)); for(int i = 0; i<10; i++) { spStar[i].SetImage(stars); //spStar[i].SetPosition } spStar[0].SetPosition(0,100); spStar[1].SetPosition(70,200); spStar[2].SetPosition(200,300); spStar[3].SetPosition(320,400); spStar[4].SetPosition(460,500); spStar[5].SetPosition(260,300); spStar[6].SetPosition(160,400); spStar[7].SetPosition(400,200); spStar[8].SetPosition(760,100); spStar[9].SetPosition(800,600); int lowestx, highestx, lowesty, highesty, rangex, rangey, random_integerx, random_integery; float time1 = 0; float time2 = 0; bool start = false; //Sprite spStar1(stars); //spStar1.SetPosition(spStar.GetPosition().x, spStar.GetPosition().y - spStar.GetSize().y); sp.Resize((float)vMode.Width, (float)vMode.Height); sp2.Resize((float)vMode.Width, (float)vMode.Height); sp2.SetPosition(sp.GetPosition().x, sp.GetPosition().y - sp.GetSize().y); sp3.SetPosition(sp2.GetPosition().x, sp2.GetPosition().y - sp2.GetSize().y); //spStar.Resize((float)vMode.Width, (float)vMode.Height); bool key = false; bool down = false; Bullet *bul; Meteor* met[METEORCOUNT]; for(int i = 0; i<METEORCOUNT; i++) { met[i] = new Meteor(meteor, vMode); } met[0]->SetPosition(200,-400); met[1]->SetPosition(420,-200); met[2]->SetPosition(720,-400); met[3]->SetPosition(520,-600); met[4]->SetPosition(320,-400); /*met[5]->SetPosition(620,-400); met[6]->SetPosition(100,-400); */ int bulletCount = 0; vector<Bullet*> bulletVector; vector<Meteor*> meteorVector; for(int i = 0; i<METEORCOUNT; i++) { meteorVector.push_back(met[i]); } bool fired = false; bool pressed = false; int count; bool change = false; //win.UseVerticalSync(true); //win.SetFramerateLimit(60); int type = pistol; Image sunImg; sunImg.LoadFromFile("..\\Resources\\Sun.png"); Sprite sunSp(sunImg); sunSp.SetPosition(500,2000); //void* user; //int score = 0; // enemys e(vMode); //Thread thread(Thread::FuncType Move,void* enemy, void* &win, void* ship); m.Play(); while(win.IsOpened()) { while(win.GetEvent(events)) { if(events.Type == Event::Closed) { win.Close(); return -1; } if((events.Type == Event::KeyPressed) && (events.Key.Code == Key::Escape)) { return 0; } if(ship.IsDestroyed() && ((events.Type == Event::KeyPressed) && (events.Key.Code == Key::Return))) { return 0; } } if(win.GetInput().IsKeyDown(Key::Up) && !ship.IsDestroyed()) { ship.Throttled(); } if(!win.GetInput().IsKeyDown(Key::Up)&& !ship.IsDestroyed()) { ship.NoThrottle(); key = false; } if(!win.GetInput().IsKeyDown(Key::Right) && !win.GetInput().IsKeyDown(Key::Up) && !ship.IsDestroyed()) { ship.NoThrottle(); } if(!win.GetInput().IsKeyDown(Key::Left)&& !win.GetInput().IsKeyDown(Key::Up) && !ship.IsDestroyed()) { ship.NoThrottle(); } if(win.GetInput().IsKeyDown(Key::Right) && !ship.IsDestroyed()) { ship.Right(); if(ship.GetPositionX()<=vMode.Width) { //ship.SetSpeed(100); ship.AddVelocity(300,0); ship.MoveSide(win.GetFrameTime()); } } if(win.GetInput().IsKeyDown(Key::Left) && !ship.IsDestroyed()) { ship.Left(); if(ship.GetPositionX()>=0) { ship.AddVelocity(-300,0); //ship.SetSpeed(-100); ship.MoveSide(win.GetFrameTime()); } } if(win.GetInput().IsKeyDown(Key::LShift)) { ship.TellDestroyed(); //ship.Destroyed(); //win.Close(); } if(win.GetInput().IsKeyDown(Key::B)) { } if(win.GetInput().IsKeyDown(Key::Space) && !ship.IsDestroyed()&&!pressed) { playerSound.Play(); bul = new Bullet(bullets, vMode, &ship, type); //bul->ChangeType(type); //bul->ChangeType(pistol); bulletVector.push_back(bul); count = bulletVector.size(); //cout<<count; pressed = true; } if(!win.GetInput().IsKeyDown(Key::Space)) { pressed = false; } if(win.GetInput().IsKeyDown(Key::N)) { type = laser; for(int i = 0; i< METEORCOUNT; i++) { met[i]->SetDestroyed(); } } win.Clear(); ship.MoveUp(win.GetFrameTime()); if(enemy.GetPositionY()>ship.GetPositionY()-500) { enemy.MoveUp(&win, ship); //enemy.NavigatorUp(&win, ship); } //ship.Simulate(win.GetFrameTime(), key, down); for(int i = 0; i<10; i++) { if(spStar[i].GetPosition().y>ship.GetPositionY() + 50) { lowesty=(int)ship.GetPositionY(), highesty=(int)ship.GetPositionY()-600; rangey=(highesty-lowesty)+1; random_integery; random_integery = lowesty+int(rangey*rand()/(RAND_MAX + 1.0)); //cout << random_integery << endl; lowestx=0, highestx=800; rangex=(highestx-lowestx)+1; random_integerx; random_integerx = lowestx+int(rangex*rand()/(RAND_MAX + 1.0)); //cout << random_integerx << endl; spStar[i].SetPosition((float)random_integerx, (float)random_integery); } } for(int i = 0; i<METEORCOUNT; i++) { if(ship.GetPositionY()<=-2000)//Score compare { met[i]->ChangeSpeed(); } met[i]->Update(win.GetFrameTime()); if(met[i]->GetPositionY()>ship.GetPositionY() + 50) { lowesty=(int)ship.GetPositionY() - 600, highesty=(int)ship.GetPositionY()-1200; rangey=(highesty-lowesty)+1; random_integery; random_integery = lowesty+int(rangey*rand()/(RAND_MAX + 1.0)); //cout << random_integery << endl; lowestx=0, highestx=720; rangex=(highestx-lowestx)+1; random_integerx; random_integerx = lowestx+int(rangex*rand()/(RAND_MAX + 1.0)); // cout << random_integerx << endl; if(met[i]->IsDestroyed()) { met[i]->SetAlive(); } met[i]->SetPosition(random_integerx, random_integery); if(!ship.IsDestroyed()) { ship.IncreaseScore(); ship.UpdateScore(); } } met[i]->UpdateAI(); } if(enemy.IsFired()) { if(col.PixelPerfectTest(enemy.GetBullet(), ship.GetSprite())) { //ship.TellDestroyed(); ship.DecreaseHealth(); if(ship.GetHealth()<=0) { ship.TellDestroyed(); } enemy.BulletReset(); enemy.NotAttacking(); } } if(!meteorVector.empty()) { for(int i = 0; i<METEORCOUNT; i++) { if(col.CircleTest(enemy.GetBullet(), meteorVector[i]->GetSprite())) { //win.Close(); //ship.TellDestroyed(); met[i]->SetDestroyed(); meteorSound.Play(); enemy.BulletReset(); } if(col.CircleTest(ship.GetSprite(), meteorVector[i]->GetSprite())) { //win.Close(); ship.TellDestroyed(); met[i]->SetDestroyed(); } if(col.CircleTest(ship.GetSprite(), sunSp)) { //win.Close(); ship.TellDestroyed(); //met[i]->SetDestroyed(); } if(col.PixelPerfectTest(enemy.GetSprite(), meteorVector[i]->GetSprite())) { //win.Close(); enemy.DecreaseHealth(10); met[i]->SetDestroyed(); meteorSound.Play(); } if(col.PixelPerfectTest(enemy.GetSprite(), sunSp)) { //win.Close(); enemy.DecreaseHealth(20); //met[i]->SetDestroyed(); } // if(col.PixelPerfectTest(meteorVector[i]->GetSprite(), enemy.GetNavigator2())||(col.PixelPerfectTest(meteorVector[i]->GetSprite(), enemy.GetNavigator3())||(col.PixelPerfectTest(sunSp, enemy.GetNavigator3()) ))) { //win.Close(); enemy.MoveLeft(1, &win, ship); } else if(col.PixelPerfectTest(meteorVector[i]->GetSprite(), enemy.GetNavigator1())||(col.PixelPerfectTest(meteorVector[i]->GetSprite(), enemy.GetNavigator4())||(col.PixelPerfectTest(sunSp, enemy.GetNavigator4()) ))) { //win.Close(); enemy.MoveRight(&win, ship); } else { enemy.Attacking(); enemy.UpdatePlayerPosition(ship.GetSprite().GetPosition(), &win); } if(!bulletVector.empty()) { for(int j = 0; j< (int)bulletVector.size(); j++) { //if((bulletVector[j]->GetSprite().GetPosition().x >= meteorVector[i]->GetSprite().GetPosition().x && bulletVector[j]->GetSprite().GetPosition().x < meteorVector[i]->GetSprite().GetPosition().x +meteorVector[i]->GetSprite().GetSize().x ) && (bulletVector[j]->GetSprite().GetPosition().y >= meteorVector[i]->GetSprite().GetPosition().y && bulletVector[j]->GetSprite().GetPosition().y < meteorVector[i]->GetSprite().GetPosition().y + meteorVector[i]->GetSprite().GetSize().x)) //{ // //win.Close(); // bulletVector[j]->Hit(); // meteorVector[i]->SetDestroyed(); // delete bulletVector[j]; // bulletVector.erase(bulletVector.begin() + j); //} if(col.PixelPerfectTest(enemy.GetBullet(), ship.GetSprite())) { //ship.TellDestroyed(); /*ship.DecreaseHealth(); if(ship.GetHealth()<=0) { ship.TellDestroyed(); }*/ } if(col.PixelPerfectTest(bulletVector[j]->GetSprite(), enemy.GetSprite())) { enemy.DecreaseHealth(); meteorSound.Play(); bulletVector[j]->Hit(); delete bulletVector[j]; bulletVector.erase(bulletVector.begin() + j); } else if(col.PixelPerfectTest(bulletVector[j]->GetSprite(), meteorVector[i]->GetSprite())) { bulletVector[j]->Hit(); meteorVector[i]->SetDestroyed(); meteorSound.Play(); delete bulletVector[j]; bulletVector.erase(bulletVector.begin() + j); } //if(col.BoundingBoxTest(bulletVector[j]->GetBulletSprite(), meteorVector[i]->GetSprite()))//collision condition should be checked here bullet and other ships //{ // cout<<i<<"T"; // cout<<j<<"T"; // win.Close(); // bulletVector[j]->Hit(); //} } } } } ship.UpdateAI(); if(enemy.GetPositionY()>ship.GetPositionY()-700) enemy.UpdateAI(); if(enemy.IsDestroyed()) { lowestx=200, highestx=620; rangex=(highestx-lowestx)+1; random_integerx; random_integerx = lowestx+int(rangex*rand()/(RAND_MAX + 1.0)); enemy.EnemyReset(random_integerx, ship); if(!ship.IsDestroyed()) { ship.IncreaseScore(10); ship.UpdateScore(); } } //win.Draw(sp); //win.Draw(sp2); //win.Draw(sp3); ship.UpdateHealth(); Drawing drawing; drawing.win = &win; drawing.ship = &ship; drawing.enemy = &enemy; drawing.Bulletvectors = bulletVector; drawing.MeteorCounts = METEORCOUNT; for(int i = 0; i<5; i++) drawing.met[i] = met[i]; win.Draw(sunSp); for(int i = 0; i< 10; i++) win.Draw(spStar[i]); //win.Draw(spStar1); //ship.UpdateScore(); // DrawingTHread(drawing); ship.Draw(&win); //score.SetPosition(100,100); //win.Draw(score); if(enemy.GetPositionY()>ship.GetPositionY()-700) enemy.Draw(&win, ship); for(int i = 0; i<METEORCOUNT; i++) { met[i]->Draw(&win); } if(!bulletVector.empty()) { for(int i = 0; i<(int)bulletVector.size();i++) { //d.Bulletvectors[i]->ChangeType(type); bulletVector[i]->Fired(); bulletVector[i]->Draw(&win, &ship); bulletVector[i]->UpdateBullet(win.GetFrameTime()); bulletVector[i]->UpdateAI(); //if(d.Bulletvectors[i]->GetPositiony()<=ship.GetPositionY()-500) win.Close(); if(bulletVector[i]->GetPositiony()<ship.GetPositionY()-600) { delete bulletVector[i]; bulletVector.erase(bulletVector.begin()+i); //count = d.Bulletvectors.size(); //cout<<count<<"\n"; } } } win.SetView(ship.GetView()); win.Display(); } return 1; }