Beispiel #1
0
void AmmoView::loadRessources()
{	
	if(textures.size() > 0)
		return;

	/* === TEXTURES === */
	Texture* tex;

	/* BULLET */
	tex = new Texture();
    tex->loadFromFile("res/tex/ammo/bullet.png");
    textures.push_back(tex);

    textures.push_back(NULL);
    textures.push_back(NULL);

    /* FLAME */
	tex = new Texture();
    tex->loadFromFile("res/tex/ammo/flame.png");
    textures.push_back(tex);
    
    textures.push_back(NULL);
    
    /* GRENADE */
	tex = new Texture();
    tex->loadFromFile("res/tex/ammo/grenade.png");
    textures.push_back(tex);
    
	
    /* === ANIMATIONS ===*/
    animations_list[BULLET] = loadAnimationsFromFile("res/xml/ammo/bullet.xml");
    animations_list[FLAME] = loadAnimationsFromFile("res/xml/ammo/flame.xml");
    animations_list[GRENADE] = loadAnimationsFromFile("res/xml/ammo/grenade.xml");
    

   
    /* === SONS === */

    /* BULLET */
	SoundBuffer* buffer = new SoundBuffer();
	buffer->loadFromFile("res/snd/ammo/bullet.wav");
    Sound* s = new Sound();
    s->setBuffer(*buffer);
    sounds.push_back(s);

    /* HEAVY_BULLET */
    buffer = new SoundBuffer();
	buffer->loadFromFile("res/snd/ammo/shotgun.wav");
    s = new Sound();
    s->setBuffer(*buffer);
    sounds.push_back(s);

    /* LIGHT_BULLET */
    sounds.push_back(NULL);

    /* FLAME */
    buffer = new SoundBuffer();
	buffer->loadFromFile("res/snd/ammo/flame.wav");
    s = new Sound();
    s->setBuffer(*buffer);
    sounds.push_back(s);

    /* ROCKET */
    sounds.push_back(NULL);

    /* GRENADE */
    buffer = new SoundBuffer();
	buffer->loadFromFile("res/snd/ammo/grenade.wav");
    s = new Sound();
    s->setBuffer(*buffer);
    sounds.push_back(s);

}
bool startGame (int & startLevel, RenderWindow & window, int & lives) {

    view.reset(FloatRect(0, 0, 700, 600));


    Level lvl;

    switch (startLevel) {
    case 1:
        lvl.LoadFromFile("level1.tmx");
        break;
    case 2:
        lvl.LoadFromFile("level2.tmx");
        break;
    case 3:
        lvl.LoadFromFile("level3.tmx");
        break;
    }
    //lvl.LoadFromFile("level1.tmx");

    SoundBuffer coinBuffer;
    coinBuffer.loadFromFile("sounds/coin.wav");
    Sound coinSound;
    coinSound.setBuffer(coinBuffer);
    SoundBuffer deathBuffer;
    deathBuffer.loadFromFile("sounds/mariodie.wav");
    Sound deathSound;
    deathSound.setBuffer(deathBuffer);
    SoundBuffer stageBuffer;
    stageBuffer.loadFromFile("sounds/stage.wav");
    Sound stageSound;
    stageSound.setBuffer(stageBuffer);

    Image heroImage;
    heroImage.loadFromFile("images/mario.png");
    heroImage.createMaskFromColor(Color(255, 255, 255));
    Image easyEnemyImage;
    easyEnemyImage.loadFromFile("images/EasyEnemy.png");
    easyEnemyImage.createMaskFromColor(Color(255, 255, 255));
    Image coinImage;
    coinImage.loadFromFile("images/coin.png");
    coinImage.createMaskFromColor(Color(255, 255, 255));
    Image mediumEnemyImage;
    mediumEnemyImage.loadFromFile("images/MediumEnemy.png");
    mediumEnemyImage.createMaskFromColor(Color(255, 255, 255));
    Image movePlatformImage;
    movePlatformImage.loadFromFile("images/MovingPlatform.png");

    std::list<Entity*> entities;
    std::list<Entity*>::iterator it;
    std::list<Entity*>::iterator it2;

    std::vector<Object> e = lvl.GetObjects("EasyEnemy");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Enemy(easyEnemyImage, "EasyEnemy", lvl, e[i].rect.left, e[i].rect.top, 15, 25));
    }
    e = lvl.GetObjects("coin");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Coin(coinImage, "coin", lvl, e[i].rect.left, e[i].rect.top, 15, 15));
    }
    e = lvl.GetObjects("MediumEnemy");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Enemy(mediumEnemyImage, "MediumEnemy", lvl, e[i].rect.left, e[i].rect.top, 16, 24));
    }
    e = lvl.GetObjects("exit");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Exit(mediumEnemyImage, "exit", lvl, e[i].rect.left, e[i].rect.top, 16, 24));
    }
    e = lvl.GetObjects("fire");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Fire(mediumEnemyImage, "fire", lvl, e[i].rect.left, e[i].rect.top, 16, 24));
    }
    e = lvl.GetObjects("MovingPlatform");
    for (int i = 0; i < e.size(); i++)
        entities.push_back(new MovingPlatform(movePlatformImage, "MovingPlatform", lvl, e[i].rect.left, e[i].rect.top, 95, 22));

    Object player = lvl.GetObject("player");
    Player p(heroImage, "Player", lvl, player.rect.left, player.rect.top, 22, 38);

    Clock clock;

    while (window.isOpen())
    {

        float time = clock.getElapsedTime().asMicroseconds();

        clock.restart();
        time = time / 800;

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        for (it = entities.begin(); it != entities.end();) {
            Entity *b = *it;
            b->update(time);
            if (b->life == false) {
                it = entities.erase(it);
                delete b;
            }
            else it++;
        }

        for (it = entities.begin(); it != entities.end(); it++) {
            if (((*it)->name == "MovingPlatform") && ((*it)->getRect().intersects(p.getRect())))
            {
                Entity *movPlat = *it;
                if (p.dy>0)
                    if (p.y + p.height < movPlat->y + movPlat->height)
                    {
                        p.y = movPlat->y - p.height + 3;
                        p.x += movPlat->dx*time;
                        p.dy = 0;
                        p.onGround = true;
                    }
            }
            if ((*it)->getRect().intersects(p.getRect())) {
                if ((*it)->name == "EasyEnemy" || (*it)->name == "MediumEnemy") {
                    if ((p.dy>0) && (p.onGround == false) && (p.y + p.height < (*it)->y + (*it)->height)) {
                        p.dy = -0.3;
                        (*it)->lives--;
                        if ((*it)->name == "EasyEnemy")
                            (*it)->sprite.setTextureRect(IntRect(60, 8, 16, 8));
                        p.Score++;
                    }
                    else {
                        if (((*it)->lives != 0)) {
                            deathSound.play();
                            p.lives--;
                            lives--;
                            return false;
                        }
                    }
                }
                if ((*it)->name == "fire") {
                    deathSound.play();
                    p.lives--;
                    lives--;
                    return false;
                }
                if ((*it)->name == "coin") {
                    p.Score++;
                    coinSound.play();
                    (*it)->life = false;
                }
                if ((*it)->name == "exit") {
                    stageSound.play();
                    startLevel++;
                    return false;
                }
            }
            for (it2 = entities.begin(); it2 != entities.end(); it2++) {
                if ((*it)->getRect() != (*it2)->getRect())
                    if (((*it)->getRect().intersects((*it2)->getRect())) && ((*it)->name == "EasyEnemy")) {
                        (*it)->dx *= -1;
                        (*it)->sprite.scale(-1.5, 1.5);
                    }
            }
        }
        p.update(time);



        if (Keyboard::isKeyPressed(Keyboard::Escape)) {
            lives = 0;
            return false;
        }

        window.setView(view);
        window.clear(Color(167, 207, 218));
        lvl.Draw(window);


        for (it = entities.begin(); it != entities.end(); it++) {
            window.draw((*it)->sprite);
        }

        window.draw(p.sprite);
        window.display();
    }

    return 0;

}
Beispiel #3
0
int main()
{  
    RenderWindow window(VideoMode(800, 250), "Mario v0.1 Alpha");
	Texture tileSet;
	tileSet.loadFromFile("Mario_Tileset.png");

	//===========================
	PLAYER Mario(tileSet);
	//==========[Bot]============
	ENEMY  enemy[3];
	enemy[0].set(tileSet,48*16,13*16);//1lvl
	enemy[1].set(tileSet,110*16,13*16);
	enemy[2].set(tileSet,48*16,30*16);//2lvl
	/*enemy[3].set(tileSet,110*16,13*16);
	enemy[4].set(tileSet,48*16,13*16);//3lvl
	enemy[5].set(tileSet,110*16,13*16);*/
	//===========================
	Sprite tile(tileSet);
	SoundBuffer buffer;
	//==========[«вук]============
	buffer.loadFromFile("Jump.ogg");
	Sound sound(buffer);
	//==========[Ўрифты]==========
	sf::Font font;
	font.loadFromFile("arial.ttf");
	//==========[ћеню]============
	Texture menu_texture1,menu_texture2,menu_texture3,about_texture;
	menu_texture1.loadFromFile("111.png");
	menu_texture2.loadFromFile("222.png");
    menu_texture3.loadFromFile("333.png");
	about_texture.loadFromFile("about.png");
	Sprite menu1(menu_texture1),menu2(menu_texture2),menu3(menu_texture3),about(about_texture);
	if(NewGm==true) {
		NewGame:
		GameOver=false;
		Mario.rect.left=100; Mario.rect.top=180;
		Mario.sprite.setPosition(100, 180);  
		offsetX = Mario.rect.left-100; 
		enemy[0].life=true; enemy[1].life=true;
		offsetY = Mario.rect.top-180; 
		std::cout<<Mario.rect.left<<"   "<< Mario.rect.top<<std::endl;
		NewGm=false;
	}

	bool Menu=1;
	int MenuNum=0;
	menu1.setPosition(100,30);
	menu2.setPosition(100,90);
    menu3.setPosition(100,150);

	while(Menu)
	{	   
	   menu1.setColor(Color::White);
	   menu2.setColor(Color::White);
	   menu3.setColor(Color::White);
	   MenuNum=0;
	   window.clear(Color(0,0,0));

	   if (IntRect(100,30,300,50).contains(Mouse::getPosition(window))) {menu1.setColor(Color::Yellow); MenuNum=1;}
       if (IntRect(100,90,300,50).contains(Mouse::getPosition(window))) {menu2.setColor(Color::Yellow); MenuNum=2;}
       if (IntRect(100,150,300,50).contains(Mouse::getPosition(window))) {menu3.setColor(Color::Yellow); MenuNum=3;}

	   if (Mouse::isButtonPressed(Mouse::Left))
	     {
			 if (MenuNum==1) Menu=false;
			 if (MenuNum==2) {window.draw(about); window.display(); while(!Keyboard::isKeyPressed(Keyboard::Escape)) ;}
			 if (MenuNum==3)  {window.close();Menu=false;}

	     }
		window.draw(menu1);
        window.draw(menu2);
		window.draw(menu3);
		window.display();
	}
	//==========[¬рубаем музыку в игру]============
	Music music;
    music.openFromFile("Mario_Theme.ogg");
    music.play();
	//==================[»гра]=====================
	Clock clock;

    while (GameOver==false)
    { 
		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();
		time = time/500;
		if (time > 20) time = 20; 

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)      
                window.close();
		}
		if (Keyboard::isKeyPressed(Keyboard::Left)) Mario.dx=-0.1; 
	    if (Keyboard::isKeyPressed(Keyboard::Right)) Mario.dx=0.1;
	    if (Keyboard::isKeyPressed(Keyboard::Up)) if (Mario.onGround) { Mario.dy=-0.27; Mario.onGround=false;  sound.play(); }
	 
		 Mario.update(time);
		 enemy[0].update(time);
		 enemy[1].update(time);
		 enemy[2].update(time);

		 if  (Mario.rect.intersects(enemy[0].rect))
		 {
			 if (enemy[0].life) {
				 if (Mario.dy>0) { enemy[0].dx=0; Mario.dy=-0.2; enemy[0].life=false;}
				 else { Mario.dy=-0.27; GameOver=true; }
			 }
		 }
		 if  (Mario.rect.intersects(enemy[1].rect))
		 {
			 if (enemy[1].life) {
				 if (Mario.dy>0) { enemy[1].dx=0; Mario.dy=-0.2; enemy[1].life=false;}
				 else { Mario.dy=-0.27; GameOver=true; }
			 }
		 }
		 if  (Mario.rect.intersects(enemy[2].rect))
		 {
			 if (enemy[2].life) {
				 if (Mario.dy>0) { enemy[2].dx=0; Mario.dy=-0.2; enemy[2].life=false;}
				 else { Mario.dy=-0.27; GameOver=true; }
			 }
		 }
		 if (Mario.rect.left>200) offsetX = Mario.rect.left-200;
		 window.clear(Color(107,140,255));
		 for (int i=0; i<H; i++)
			 for (int j=0; j<W; j++)
			 { 
				switch(TileMap[i][j]) {
					case 'P':  tile.setTextureRect( IntRect(143-16*3,112,16,16)); break; 
					case 'k': tile.setTextureRect( IntRect(143,112,16,16)); break; 
					case 'c': tile.setTextureRect( IntRect(143-16,112,16,16)); break; 
					case 't': tile.setTextureRect( IntRect(0,47,32,95-47)); break; 
					case 'm': tile.setTextureRect( IntRect(96,6,202-47,111)); break; 
					case 'g': tile.setTextureRect( IntRect(0,16*9-5,3*16,16*2+5)); break; 
					case 'G': tile.setTextureRect( IntRect(145,222,222-145,255-222)); break; 
					case 'd': tile.setTextureRect( IntRect(0,106,74,127-106)); break; 
					case 'w': tile.setTextureRect( IntRect(99,224,140-99,255-224)); break; 
					case 'r': tile.setTextureRect( IntRect(143-32,112,16,16)); break; 
					default: continue;
				}

  			    tile.setPosition(j*16-offsetX,i*16 - offsetY) ; 
		        window.draw(tile);
			}
		window.draw(Mario.sprite);
	    window.draw(enemy[0].sprite);
		window.draw(enemy[1].sprite);
		window.draw(enemy[2].sprite);
		window.display();
    }
	while(Win)
	{	
		GameOver=false;
		window.clear(Color(0,0,0));
		sf::Text text("You Win! :3", font); 
		text.setPosition(100,30);
		text.setCharacterSize(30);
		text.setStyle(sf::Text::Bold);
		text.setColor(sf::Color::Yellow);
		window.draw(text);	
		sf::Text text1("Press ESC", font); 
		text1.setPosition(100,60);
		text1.setCharacterSize(30);
		text1.setStyle(sf::Text::Bold);
		text1.setColor(sf::Color::Red);
		window.draw(text1);	
		window.display();
		if (Keyboard::isKeyPressed(Keyboard::Escape)) { goto NewGame; NewGm=true; }
	}
	while(GameOver)
	{	   
		window.clear(Color(0,0,0));
		sf::Text text("Game Over :c", font); 
		text.setPosition(100,30);
		text.setCharacterSize(30);
		text.setStyle(sf::Text::Bold);
		text.setColor(sf::Color::Red);
		window.draw(text);	
		sf::Text text1("Press ESC", font); 
		text1.setPosition(100,60);
		text1.setCharacterSize(30);
		text1.setStyle(sf::Text::Bold);
		text1.setColor(sf::Color::Red);
		window.draw(text1);	
		window.display();
		if (Keyboard::isKeyPressed(Keyboard::Escape)) { goto NewGame; NewGm=true; }
	}
    return 0;
}
void game::run()
{
	//MissileDesc projectile(*this);
	towerDesc towr(this);

	std::string txt;

	std::string txt2 = "Life:";

	std::string txt3 = "Money:";

	std::string main = "Cam Pos";

	std::string txt4 = "Game Over";

	std::list<SceneObject *> troll;

	endgame = false;
	mouseUp = false;

	float dir = 0.0f;

	float spot_dir = 45.0f;
    float aspect_time = 0.0f;

	towerCount = 0;
	cost = 0;

	life = 20;
	money = 10;
	quit = false;
	cameraRestricted = false;
	
	selected_tower = "";

	std::stringstream ss2 (std::stringstream::in | std::stringstream::out);
	std::stringstream ss3 (std::stringstream::in | std::stringstream::out);

	/*GUI app;
	int retval = app.main(args);

	if (retval == 0)
	{
		return retval;
	}*/


	Quaternionf camera_orientation(55.0f, 0.0f, 0.0f, angle_degrees, order_YXZ);
		
	clan::OpenGLWindowDescription opengl_desc;
	opengl_desc.set_version(3, 2, false);
	clan::OpenGLTarget::set_description(opengl_desc);

	//Scene test;
	//clan::SceneCamera camera(test);
	//DisplayWindowDescription innerwindow("Hello World", Size(640, 480), true);
	//innerwindow.set_allow_resize(true);
	//innerwindow.set_fullscreen(true);

	clan::DisplayWindowDescription win_desc;
	win_desc.set_allow_resize(true);
	win_desc.set_title("Main");
	win_desc.set_size(clan::Size( 1100, 900 ), false);
	DisplayWindow window(win_desc);	
	//DisplayWindow window("main", 1200, 900, false, true);	
	//window.maximize();
	//DisplayWindow window(innerwindow);

	Rect viewport = window.get_viewport();

	GraphicContext gc = window.get_gc();

	ResourceManager resources;
	SceneCache::set(resources, std::shared_ptr<SceneCache>(new AppSceneCache()));

	ResourceManager sound_resources = XMLResourceManager::create(XMLResourceDocument("../Resources/resources.xml"));
	sound_resources_=&sound_resources;

	std::string shader_path = "../Resources/Scene3D";

	Scene scene(gc, resources, shader_path);

	sceneHolder = &scene;

	SceneCamera camera(scene);
	scene.set_camera(camera);
	scene.set_viewport(gc.get_size());

	camera.set_orientation(camera_orientation);
	camera.set_position(Vec3f(0.0f, 40.0f, down));

	Canvas canvas(window);

	image_hp = Image(canvas, "../Resources/Images/heart.png");
	image_hp.set_alignment(origin_center);
	image_hp.set_scale(0.07, 0.07);

	image_coin = Image(canvas, "../Resources/Images/coin.png");
	image_coin.set_alignment(origin_center);
	image_coin.set_scale(0.3, 0.3);


	GUIWindowManagerDirect direct(window, canvas);

	GUIManager maingui(direct, "../Resources");

	GUIComponent *win_comp = new GUIComponent(&maingui, win_desc, "");

	radial_menu = new RadialMenu(win_comp);

	radial_menu->func_selected.set(this, &game::on_radial_menu_itemselected);

	//GameComponent game_component(viewport, &maingui);

	/*Rect toolbar_rect = Rect((viewport.get_width() - 448) / 2, viewport.bottom - 56, (viewport.get_width() - 448) / 2 + 448, viewport.bottom);
	Toolbar toolbar(toolbar_rect, &game_component);	// GameComponent is the "desktop" that the toolbar sits on, as an owner

	toolbar.add_item(Sprite(canvas, "../Resources/Images/spell1.png"), Sprite(canvas, "../Resources/Images/spell1_selected.png"), Sprite(canvas, "../Resources/Images/spell1_clicked.png"));
	toolbar.add_item(Sprite(canvas, "../Resources/Images/spell2.png"), Sprite(canvas, "../Resources/Images/spell2_selected.png"), Sprite(canvas, "../Resources/Images/spell2_clicked.png"));
	toolbar.add_item(Sprite(canvas, "../Resources/Images/spell3.png"), Sprite(canvas, "../Resources/Images/spell3_selected.png"), Sprite(canvas, "../Resources/Images/spell3_clicked.png"));
	toolbar.add_item(Sprite(canvas, "../Resources/Images/spell4.png"), Sprite(canvas, "../Resources/Images/spell4_selected.png"), Sprite(canvas, "../Resources/Images/spell4_clicked.png"));
	toolbar.add_item(Sprite(canvas, "../Resources/Images/spell5.png"), Sprite(canvas, "../Resources/Images/spell5_selected.png"), Sprite(canvas, "../Resources/Images/spell5_clicked.png"));
	toolbar.add_item(Sprite(canvas, "../Resources/Images/spell6.png"), Sprite(canvas, "../Resources/Images/spell6_selected.png"), Sprite(canvas, "../Resources/Images/spell6_clicked.png"));
	toolbar.add_item(Sprite(canvas, "../Resources/Images/spell7.png"), Sprite(canvas, "../Resources/Images/spell7_selected.png"), Sprite(canvas, "../Resources/Images/spell7_clicked.png"));
	*/

	InputDevice keyboard = window.get_ic().get_keyboard();
	InputDevice mouse = window.get_ic().get_mouse();
	clan::Font font(canvas, "Tahoma", 30); // The clan prefix is required on linux due to a namespace conflict

	SceneModel plane(gc, scene, "plane");
	SceneModel box(gc, scene, "box");
	SceneModel tower(gc, scene, "tower");
	SceneModel gate(gc,scene,"gate");

	SceneObject object(scene, plane, Vec3f(0.0f, 0.0f, 0.0f));
	
	object.rotate(180.0f, 0.0f, 0.0f);

	scene.show_skybox_stars(false);

	/*SceneObject box0(scene, tower, Vec3f(20.0f, 5.0f, 0.0f), Quaternionf(0.0f, 0.0f, 0.0f, angle_degrees, order_YXZ));
	SceneObject box1(scene, tower, Vec3f(-20.0f, 5.0f, 0.0f), Quaternionf(0.0f, 0.0f, 0.0f, angle_degrees, order_YXZ));
	SceneObject box2(scene, tower, Vec3f(0.0f, 5.0f, 20.0f), Quaternionf(0.0f, 0.0f, 0.0f, angle_degrees, order_YXZ));
	SceneObject box3(scene, tower, Vec3f(0.0f, 5.0f, -20.0f), Quaternionf(0.0f, 0.0f, 0.0f, angle_degrees, order_YXZ));
	SceneObject tower[10];*/

	SceneObject theGate(scene, gate, Vec3f(-75.0f,5.0f,60.0f), Quaternionf(0.0f,0.0f,0.0f,angle_degrees,order_YXZ));
	theGate.set_scale(Vec3f(1.0f,2.0f,2.0f));

	std::vector<SceneLight> omni_lights;
	for (int i = 0; i < 4; i++)
	{
		SceneLight omni(scene);
		omni.set_type(SceneLight::type_omni);
		omni.set_color(Vec3f(0.05f));
		omni.set_position(Quaternionf(45.0f, 45.0f + i * 90.0f, 0.0f, angle_degrees, order_YXZ).rotate_vector(Vec3f(0.0f, 0.0f, -100.0f)));
		omni.set_attenuation_end(200.0f);
		omni.set_ambient_illumination(0.025f);

		omni_lights.push_back(omni);
	}

	SceneLight spot(scene);
    spot.set_type(SceneLight::type_spot);
    spot.set_orientation(Quaternionf(45.0f, 45.0f, 0.0f, angle_degrees, order_YXZ));
    spot.set_position(spot.get_orientation().rotate_vector(Vec3f(-55.0f, 90.0f, -550.0f)));
	//spot.set_position(Vec3f(-250, 100, -430));
    spot.set_color(Vec3f(1.0f, 1.0f, 0.8f));
    spot.set_falloff(45.0f);
    spot.set_hotspot(15.0f);
    spot.set_attenuation_start(150.0f);
    spot.set_attenuation_end(1500.0f);
    spot.set_shadow_caster(true);
    spot.set_rectangle_shape(false);
	//spot.set_ambient_illumination(true);
    spot.set_aspect_ratio(1.0f);

	/*SceneLight spot(scene);
    spot.set_type(SceneLight::type_spot);
    spot.set_orientation(Quaternionf(30.0f, 30.0f, 0.0f, angle_degrees, order_YXZ));
    spot.set_position(spot.get_orientation().rotate_vector(Vec3f(0.0f, 0.0f, -100.0f)));
    spot.set_color(Vec3f(1.0f, 1.0f, 0.8f));
    spot.set_falloff(45.0f);
    spot.set_hotspot(15.0f);
    spot.set_attenuation_start(20.0f);
    spot.set_attenuation_end(200.0f);
    spot.set_shadow_caster(true);
    spot.set_rectangle_shape(false);
    spot.set_aspect_ratio(1.0f);*/

    /*SceneLight spot2(scene);
    spot2.set_type(SceneLight::type_spot);
    spot2.set_position(Vec3f(0.0f, 100.0f, 0.0f));
    spot2.set_color(Vec3f(1.0f, 1.0f, 1.0f) * 3.0f);
    spot2.set_falloff(35.0f);
    spot2.set_hotspot(30.0f);
    spot2.set_attenuation_start(20.0f);
    spot2.set_attenuation_end(130.0f);
    spot2.set_shadow_caster(true);
    spot2.set_rectangle_shape(false);
    spot2.set_ambient_illumination(0.025f);*/

	wm.NodeArray[0].setPos(75.0f,1.25f,0.0f);
	wm.NodeArray[1].setPos(-60.0f,1.25f,0.0f);
	wm.NodeArray[2].setPos(-55.0f,1.25f,-65.0f);
	wm.NodeArray[3].setPos(60.0f,1.25f,-60.0f);
	wm.NodeArray[4].setPos(55.0f,1.25f,65.0f);
	wm.NodeArray[5].setPos(-80.0f,1.25f,60.0f);
	
	Physics3DShape box_shape = Physics3DShape::box(Vec3f(5.0f));
	Physics3DShape plane_shape = Physics3DShape::box(Vec3f(75.0f, 1.0f, 75.0f));
	Physics3DShape sphere_shape = Physics3DShape::sphere(2.0f);

	Physics3DObject phys_plane(physics_world, plane_shape, Vec3f(0.0f, -0.5f, 0.0f));

	/*Physics3DObject phys_box0(physics_world, box_shape, Vec3f(20.0f, 5.0f, 0.0f), box0.get_orientation());
	Physics3DObject phys_box1(physics_world, box_shape, Vec3f(-20.0f, 5.0f, 0.0f), box1.get_orientation());
	Physics3DObject phys_box2(physics_world, box_shape, Vec3f(0.0f, 5.0f, 20.0f), box2.get_orientation());
	Physics3DObject phys_box3(physics_world, box_shape, Vec3f(0.0f, 5.0f, -20.0f), box3.get_orientation());
	Physics3DObject phys_box[10];*/

	Physics3DSweepTest sweep_test(physics_world);

	Physics3DRayTest raycast(physics_world);

	Slot slot_keyboard_key_down	= (window.get_ic().get_keyboard()).sig_key_down()	.connect(this,&game::on_key_down);
	Slot slot_keyboard_key_up	= (window.get_ic().get_keyboard()).sig_key_up()		.connect(this,&game::on_key_up);
	Slot slot_mouse_moved		= (window.get_ic().get_mouse()).sig_pointer_move()	.connect(this,&game::on_pointer_move);
	Slot slot_mouse_down			= (window.get_ic().get_mouse()).sig_key_down()		.connect(this,&game::on_pointer_down);
	Slot slot_mouse_up			= (window.get_ic().get_mouse()).sig_key_up()		.connect(this,&game::on_pointer_up);

	//________________________________________________________________
	//											           S O U N D S

	total_channels=3;
	current_channel=1;
	SoundBuffer music = SoundBuffer::resource("Music1",sound_resources);
	music.set_volume(0.3f);

	sound_session1.play();
	sound_session2.play();
	sound_session3.play();

	total_samples = 6;
	samples.resize(total_samples);
	samples[0] = SoundBuffer::resource("Explosion1",sound_resources);
	samples[1] = SoundBuffer::resource("Explosion2",sound_resources);
	samples[2] = SoundBuffer::resource("Hurt1",sound_resources);
	samples[3] = SoundBuffer::resource("Hurt2",sound_resources);
	samples[4] = SoundBuffer::resource("Powerup1",sound_resources);
	samples[5] = SoundBuffer::resource("Shoot1",sound_resources);
	
	for(int i = 0; i<total_samples; i++)
	{
		samples[i].set_volume(0.3f);
	}
	
	SoundBuffer_Session music_session = music.prepare();
	music_session_ = &music_session;

	music_session.set_looping(true);
	music_session.play();
	is_music_muted = false;

	/********Enemies(Jasper)************************/
	SceneObject enemyobj[30];
	wm.spawnCreeps();
	for(int i = 0; i < 30; i ++)
	{
		enemyobj[i] = SceneObject(scene, box);
		enemyobj[i].set_scale(Vec3f(0.25f));
		wm.enemyArray[i].setEnemyObject(&enemyobj[i]);
	}
	/***************************************/

	ElapsedTimer elapsed_timer;

	while (!quit)
	{
		float time_elapsed = elapsed_timer.seconds_elapsed();

		/*spot_dir = std::fmod(spot_dir + time_elapsed * 30.0f, 90.0f);
		aspect_time = std::fmod(aspect_time + time_elapsed * 0.2f, 2.0f);

		spot2.set_aspect_ratio(clamp(aspect_time >= 1.0f ? 2.0f - aspect_time : aspect_time, 0.1f, 1.0f));
		spot2.set_orientation(Quaternionf(65.0f + (spot_dir >= 45.0f ? 90.0f - spot_dir : spot_dir), 60.0f, dir * 4.0f, angle_degrees, order_YXZ));
		*/
		// Draw with the canvas:
		/*canvas.clear(Colorf::cadetblue);
		canvas.draw_line(0, 110, 640, 110, Colorf::yellow);
		font.draw_text(canvas, 100, 100, "Hello World!", Colorf::lightseagreen);
		// Draw any remaining queued-up drawing commands oQAn canvas:
		canvas.flush();*/

		if (!endgame)
		{
			if (mouse.get_x() <= 0 && !cameraRestricted)
			{
				mouse.set_position(0, mouse.get_y());
				camera.set_position(camera.get_position()+Vec3f(-mouse_move_speed, 0.0f, 0.0f));
				/*canvas.clear();
				font.draw_text(canvas, 100, 100, "x=0", Colorf::lightseagreen);
				canvas.flush();*/
				//window.flip();
			}
			if (mouse.get_y() <= 0 && !cameraRestricted)
			{
				mouse.set_position(mouse.get_x(), 0);
				camera.set_position(camera.get_position()+Vec3f(0.0f, 0.0f, mouse_move_speed));
				/*canvas.clear();
				font.draw_text(canvas, 100, 100, "y=0", Colorf::lightseagreen);
				canvas.flush();*/
				//window.flip();
			}
			if (mouse.get_x() >= window.get_gc().get_width()-1 && !cameraRestricted)
			{
				mouse.set_position(window.get_gc().get_width()-1, mouse.get_y());
				camera.set_position(camera.get_position()+Vec3f(mouse_move_speed, 0.0f, 0.0f));
				/*canvas.clear();
				font.draw_text(canvas, 100, 100, "x=windowRight", Colorf::lightseagreen);
				canvas.flush();*/
				//window.flip();
			}
			if (mouse.get_y() >= window.get_gc().get_height()-1 && !cameraRestricted)
			{
				mouse.set_position(mouse.get_x(), window.get_gc().get_height()-1);
				camera.set_position(camera.get_position()+Vec3f(0.0f, 0.0f, -mouse_move_speed));
				/*canvas.clear();
				font.draw_text(canvas, 100, 100, "y=windowBottom", Colorf::lightseagreen);
				canvas.flush();*/
				//window.flip();
			}

			if (mouseUp)
			{
				if (selected_tower == "Tower 1")
				{
					towr.set_type(towr.t_bullet);
					cost = 10;
				}
				else if (selected_tower == "Tower 2")
				{
					towr.set_type(towr.t_energy);
					cost = 15;
				}
				else if (selected_tower == "Tower 3")
				{
					towr.set_type(towr.t_rocket);
					cost = 20;
				}

				scene.unproject(mouse_pos, start, end);
				end *= 151;
				test = start + end;

				if (raycast.test(start, test))
				{
					if (towerCount < 10 && money >= cost)
					{
						towr.set_pos(Vec3f(raycast.get_hit_position().x, 5.0f, raycast.get_hit_position().z));
						towr.create(scene, tower, physics_world);

						money -= cost;
						towerCount++;
						cost = 0;
					}
				}
				mouseUp = false;
				//float x = mouse.get_x() - scene.world_to_projection().get_origin_x();
				//tower[0] = SceneObject(scene, box, Vec3f(camera.get_position().x, 5.0f, camera.get_position().z));
				//tower[0].set_position(Vec3f(0.0f, 5.0f, 0.0f));
				//window.flip();
				//canvas.clear(Colorf::cadetblue);
				/*canvas.draw_line(0, 110, 640, 110, Colorf::yellow);
				font.draw_text(canvas, 100, 100, "Hello World!", Colorf::lightseagreen);
				// Draw any remaining queued-up drawing commands oQAn canvas:
				canvas.flush();
				// Present the frame buffer content to the user:
				window.flip();*/
			}

			if (mouse.get_keycode(0))
			{
				
				//maingui.process_messages(0);
				//test.update();
				//show_radial_menu(mouse.get_position());
			}

			/*if (mouse.get_keycode(1))
			{
				scene.unproject(mouse.get_position(), start, end);
				end *= 151;
				Vec3f test = start + end;
				if (raycast.test(start, test))
				{
					Physics3DObject hit = raycast.get_hit_object();
					font.draw_text(canvas, 400, 100, "hit", Colorf::lightseagreen);
					//hit.set_position(Vec3f(0.0f, -10.0f, 0.0f));
					std::stringstream ss3 (std::stringstream::in | std::stringstream::out);
					ss3 << hit.get_position().y;
					txt3 = ss3.str();

					font.draw_text(canvas, 550, 100, txt3, Colorf::lightseagreen);
				}
				
				//projectile.set_pos(Vec3f(raycast.get_hit_position().x, 5.0f, raycast.get_hit_position().z));
				//projectile.fire(scene, box, physics_world);
			
				//canvas.clear(Colorf::white);
				//window.flip();
			}*/
			if (keyboard.get_keycode(keycode_control))
			{
				if (window.is_fullscreen())
				{
					//innerwindow.set_fullscreen(false);
					window.set_size(640, 480, true);
					window.restore();
				}
				else
					window.set_size(640, 480, false);
			}

			if (camera.get_position().x <= left)
			{
				camera.set_position(Vec3f(left, camera.get_position().y, camera.get_position().z));
			}
		
			if (camera.get_position().x >= right)
			{
				camera.set_position(Vec3f(right, camera.get_position().y, camera.get_position().z));
			}
		
			if (camera.get_position().z >= top)
			{
				camera.set_position(Vec3f(camera.get_position().x, camera.get_position().y, top));
			}

			if (camera.get_position().z <= down)
			{
				camera.set_position(Vec3f(camera.get_position().x, camera.get_position().y, down));
			}

			/*if(objects_for_deletion.size()>0)
			{
				std::list<Gameobject *>::iterator it;
				for(it=objects_for_deletion.begin(); it!= objects_for_deletion.end(); ++it)
				{
					delete (*it);
					//towerCount--;
				}

				objects_for_deletion.clear();
			}*/

			if(towerObjects.size()>0)
			{
				std::vector<Gameobject *>::iterator it;
				int counter = 0;
				for(it=towerObjects.begin(); it!= towerObjects.end(); ++it)
				{
					towerObjects.at(counter)->update(time_elapsed, wm.enemyArray, 30);
					counter++;
				}
			}

			if(missileObjects.size()>0)
			{
				std::list<Gameobject *>::iterator it;
				for(it=missileObjects.begin(); it!= missileObjects.end();)
				{
					//if (!(*it)->checkActive())
					(*it)->update(time_elapsed, wm.enemyArray);

					if ((*it)->checkActive())
					{
						delete(*it);
						it = missileObjects.erase(it);						
					}
					else
						it++;
				}
			}

			/*******Enemies(Updates)************************/
			wm.Update(1);
			//time_lasttime = time_elapsed;

			if(wm.life > 0)
			{
				// Put a screen here
				life -= wm.life;
				wm.life = 0;
			}

			if (wm.currLevel == 3)
			{
				endgame = true;
			}
			/***********************************************/

			//scene.update(gc, time_elapsed);

			txt3 = ":";
			ss3.str("");
			ss3.clear();
			ss3 << money;
			txt3 += ss3.str();

			font.draw_text(canvas, 550, 50, txt3, Colorf::lightseagreen);

			if (life < 0)
			{
				endgame = true;
			}

			scene.render(gc);

			/*canvas.clear(clan::Colorf(0.0f,0.0f,0.0f));
			std::stringstream ss (std::stringstream::in | std::stringstream::out);
			ss << game_time.get_time_elapsed();
			std::string troll = ss.str();
			font.draw_text(canvas, 100, 100, troll, Colorf::lightseagreen);*/
			//canvas.clear(clan::Colorf(0.0f,0.0f,0.0f));
			std::stringstream ss (std::stringstream::in | std::stringstream::out);
			ss << scene.world_to_projection().get_origin_x();
			txt = ss.str();

			txt2 = ":";
			ss2.str("");
			ss2.clear();
			ss2 << life;
			txt2 += ss2.str();

			font.draw_text(canvas, 150, 50, txt2, Colorf::lightseagreen);

			//maingui.process_messages(0);

			/*font.draw_text(canvas, 0, 100, main, Colorf::lightseagreen);
			font.draw_text(canvas, 150, 100, txt, Colorf::lightseagreen);
			font.draw_text(canvas, 250, 100, txt2, Colorf::lightseagreen);
			canvas.draw_line(0, 110, 640, 110, Colorf::yellow);*/

			maingui.render_windows();
			
			image_hp.draw(canvas, 100, 45); 
			image_coin.draw(canvas, 500, 45);
			
			window.flip();

			// Read messages from the windowing system message queue, if any are available:
			KeepAlive::process();
		}

		else
		{
			//maingui.render_windows();
			canvas.clear(Colorf::black);

			font.draw_text(canvas, 450, 400, txt4, Colorf::lightseagreen);

			window.flip();

			// Read messages from the windowing system message queue, if any are available:
			KeepAlive::process();
		}
	}
}
Beispiel #5
0
void mainLevel(RenderWindow &window)
{
	//>>>>>>>>>>>>>>>---Level---<<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Level lvl;
	 lvl.LoadFromFile("map.tmx");

	//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
	Texture texture;
	texture.loadFromFile("images/level1empty.jpg");
	Sprite level(texture);

	Texture texture2; 
	texture2.loadFromFile("images/levelShad.png");
	Sprite level2(texture2);

	Texture texture3;
	texture3.loadFromFile("images/level12.png");
	Sprite level3(texture3);
	//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Music mainSong;
	 mainSong.openFromFile("music/level1.ogg");
	 mainSong.play();
	 mainSong.setLoop(true);
	 mainSong.setVolume(75);

	 //>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
	 Object player = lvl.GetObject("cat");
	 Player cat("cat.png", lvl, player.rect.left, player.rect.top, 60, 120, 55, 25);
	 Clock clock;

	 //>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
	SoundBuffer buf1, buf2;
	buf1.loadFromFile("music/meow1.ogg");
	buf2.loadFromFile("music/meow2.ogg");
	Sound meow1, meow2;
	meow1.setBuffer(buf1);
	meow2.setBuffer(buf2);

	SoundBuffer buf;
	buf.loadFromFile("music/steklo.ogg");
	Sound glass;
	glass.setBuffer(buf); glass.setVolume(100);

	 //Objects
	 Furniture posters("tayles1.png",  160, 660, 210, 250, 280, 215);
	 Furniture bed("tayles1.png", 420, 80, 280, 310, 250, 440);
	 Furniture toys("tayles1.png", 120, 470, 180, 150, 220, 545);
	 Furniture upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83);
	 Furniture cabinet("tayles1.png", 75, 40, 250, 350, 605, 305);
	 Furniture mop("tayles1.png", 515, 785, 165, 241, 587, 385);
	 Furniture flower("tayles1.png",780, 65, 170, 330, 147, 285);
	 Furniture ball("tayles1.png", 905, 615, 40, 55, 357, 190);
	 Furniture books("tayles1.png", 860, 735, 125, 80, 290, 187);
	 Furniture brokenBall("tayles1.png",920, 540, 90, 42, 430, 430);
	 
	 Furniture door("tayles2.png", 0, 560, 80, 340, 870, 350);
	 Furniture brokenLight("tayles2.png", 10, 110, 50, 70, 795, 430);
	 Furniture light("tayles2.png", 20, 20, 35, 70, 220, 565);
	 Furniture bath("tayles2.png", 80, 50, 320, 380, 1010, 330);
	 Furniture carpet("tayles2.png", 100, 500, 100, 140, 870, 530);
	 Furniture mirror("tayles2.png", 90, 700, 110, 290, 1200, 300);
	 Furniture sink("tayles2.png", 290, 440, 150, 240, 1190, 450);
	 int cntMeow = 0;
	 Object ob = lvl.GetObject("catPlace");
	  while (window.isOpen())
    {
		
		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();
		time = time/500;
		Vector2i pos = Mouse::getPosition(window);

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

			if (event.type == Event::MouseButtonPressed){
					if (event.key.code == Mouse::Left)
					{
						int cntMeow = meow(meow1, meow2, cat, pos);
						//>>>>>>BALL<<<<<<<<<<<<<<
						if(cat.sprite.getGlobalBounds().intersects(ob.rect))
						{
							if(cntMeow == -1)
							{
								ball.falling(event, window, pos, lvl, time);
								glass.play();
								ball.moving(event, window, pos, "ball", lvl);
							}
						}
						cat.clickedThings(window, light);
						//BOOKS>>>>----<<<<<<
						if(books.isPlayed == false)
						{
							if (books.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								MiniGame_Books();
								books.isPlayed = true;
								mainSong.play();
							}
						}

					}
			}		
					
					toys.moving(event, window, pos, "toys", lvl);
					if(light.isPlayed == false)
						light.moving(event, window, pos, "light", lvl);
					

	
        }
		
		

		cat.Update(time);

		window.clear(Color::Black);
		lvl.Draw(window);
		if(cat.room == 0)
			window.draw(level);
		if(cat.room == 1)
			window.draw(level2); 
		if(cat.room == 2)
			window.draw(level3);
			
		window.draw(posters.sprite);
		window.draw(bed.sprite);
		window.draw(light.sprite);
		window.draw(toys.sprite);
		window.draw(upShelf.sprite);
		window.draw(cabinet.sprite);
		window.draw(mop.sprite);
		window.draw(flower.sprite);
		if(ball.isPlayed == false)
			window.draw(ball.sprite);
		else
			window.draw(brokenBall.sprite);
		window.draw(books.sprite);



		if(cat.room == 2){
			window.draw(bath.sprite);
			window.draw(mirror.sprite);
			window.draw(sink.sprite);
		}

		if(cat.room == 1 || cat.room == 2){
			if(light.isPlayed == false)
			window.draw(brokenLight.sprite);
			window.draw(carpet.sprite);
			window.draw(door.sprite);
		}
		

		window.draw(cat.sprite);
		
		window.display();
    }

}
Beispiel #6
0
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;
}
Beispiel #7
0
void SoundHandler::initializeSounds()
{
	criticalTimer = new Clock();
	messageTimer = new Clock();
	soundTimer = new Clock();
	spellTimer = new Clock();
	urgentTimer = new Clock();
	
	criticalSound = new Sound();
	genericSound = new Sound();
	message = new Sound();
	spellSound = new Sound();
	urgentSound = new Sound();


	SoundBuffer* buffer;
	Music* music;
	string name;

	sounds.push_back("gold_drop_1");
	sounds.push_back("gold_drop_2");
	sounds.push_back("gold_drop_3");
	sounds.push_back("imp_mine_1");
	sounds.push_back("imp_mine_2");
	sounds.push_back("imp_mine_3");
	sounds.push_back("imp_mine_4");
	sounds.push_back("imp_mine_5");
	sounds.push_back("imp_mine_6");
	sounds.push_back("imp_spawn");
	sounds.push_back("imp_step_1");
	sounds.push_back("imp_step_2");
	sounds.push_back("imp_step_3");
	sounds.push_back("imp_step_4");
	sounds.push_back("option_failure");
	sounds.push_back("option_select_1");
	sounds.push_back("option_select_2");
	sounds.push_back("tile_build");
	sounds.push_back("tile_cave-in_1");
	sounds.push_back("tile_cave-in_2");
	sounds.push_back("tile_cave-in_3");
	sounds.push_back("tile_select");
	sounds.push_back("tile_sell");
	sounds.push_back("voice_bigger_treasury");
	sounds.push_back("voice_game_saved");
	sounds.push_back("voice_game_loaded");
	sounds.push_back("voice_need_treasury");
	sounds.push_back("voice_tunneled_new_area");

	int length = sounds.size();

	for (int i = 0; i < length; i++)
	{
		buffer = new SoundBuffer();
		name = sounds[i];
		buffer->loadFromFile("Resources/" + name + ".ogg");
		soundMap[name] = buffer;
	}

	songs.push_back("game_music");
	songs.push_back("menu_music");
	length = songs.size();

	for (int i = 0; i < length; i++)
	{
		music = new Music();
		name = songs[i];
		music->openFromFile("Resources/" + name + ".ogg");
		musicMap[name] = music;
	}
}
Beispiel #8
0
void EnemyView::loadRessources(TypeEnemy t)
{
	if(textures[t] != NULL)
		return;

	/* REBEL */
	if(t == REBEL)
	{
		// TEXTURE
		Texture* tex = new Texture();
	    tex->loadFromFile("res/tex/enemy/rebel.png");
	    textures[REBEL] = tex;

	    // ANIMATION
	    animations_list[REBEL] = loadAnimationsFromFile("res/xml/enemy/rebel.xml");

	    // SOUNDS
	    SoundBuffer* buffer;

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/rebel/death1.wav"); // DEATH
	    sounds_buffers[REBEL].push_back(buffer);

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/rebel/death2.wav"); // DEATH2
	    sounds_buffers[REBEL].push_back(buffer); 

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/rebel/death3.wav"); // DEATH3
	    sounds_buffers[REBEL].push_back(buffer); 
	}

	/* BOWSER */
	else if(t == BOWSER)
	{
		// TEXTURE
		Texture* tex = new Texture();
	    tex->loadFromFile("res/tex/enemy/bowser.png");
	    textures[BOWSER] = tex;

	    // ANIMATION
	    animations_list[BOWSER] = loadAnimationsFromFile("res/xml/enemy/bowser.xml");

	    // SOUNDS
	    SoundBuffer* buffer;

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/bowser/death.wav"); // DEATH
	    sounds_buffers[BOWSER].push_back(buffer);

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/bowser/death2.wav"); // DEATH2
	    sounds_buffers[BOWSER].push_back(buffer);
	}

	/* FLYING */
	else if(t == FLYING)
	{
		// TEXTURE
		Texture* tex = new Texture();
	    tex->loadFromFile("res/tex/enemy/flying.png");
	    textures[FLYING] = tex;

	    // ANIMATION
	    animations_list[FLYING] = loadAnimationsFromFile("res/xml/enemy/flying.xml");

	    // SOUNDS
	    SoundBuffer* buffer;

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/flying/death.wav"); // DEATH
	    sounds_buffers[FLYING].push_back(buffer);
	}
}
Beispiel #9
0
 void Weapon::LoadSound(string file, SoundBuffer& buffer, Sound& sound){
     buffer.LoadFromFile(file.c_str());
     sound.SetBuffer(buffer);
 }