Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmcvitiesyum

Posted 23 February 2013 - 06:47 PM

Hello gamedev.

I'm currently programming a simple 2d space shooter  in sfml 2.0 .

Does anyone have any idea how will I make the missiles move at the same speed at any direction? (The problem is partially solved for vertical directions only).

Here is my code:

void World::updateMissiles(float refreshRate){
	std::list<Missile*>::iterator it = missiles.begin();
	while(it != missiles.end()){
		Missile* missile = *it;
		sf::Sprite& sprite = missile->getSprite();
		if(collide(missile)){
			it=missiles.erase(it);
			delete missile;
		}
		else{
			if(missile->getType() == Missile::Player){
                                // Missile angle of player is only vertical
				sprite.move(0,-missile->getVelY()*refreshRate); 
			}
			else{
                                // This part needs to change from vertical to angles of 45,90,135 degrees
			        //sprite.move(0,missile->getVelY()*refreshRate); 
			}
			it++;
		}
	}
}

#1mcvitiesyum

Posted 23 February 2013 - 06:45 PM

Hello gamedev.

I'm currently programming a simple 2d space shooter  in sfml 2.0 .

Does anyone have any idea how will I make the missiles move at the same speed at any direction? (The problem is partially solved for vertical directions only).

Here is my code:

void World::updateMissiles(float refreshRate){
	std::list<Missile*>::iterator it = missiles.begin();
	while(it != missiles.end()){
		Missile* missile = *it;
		sf::Sprite& sprite = missile->getSprite();
		if(collide(missile)){
			it=missiles.erase(it);
			delete missile;
		}
		else{
			if(missile->getType() == Missile::Player){
                                // Missiles of player are only vertical
				sprite.move(0,-missile->getVelY()*refreshRate); 
			}
			else{
                                // This part needs to change from vertical to all directions
			        //sprite.move(0,missile->getVelY()*refreshRate); 
			}
			it++;
		}
	}
}

 

 


PARTNERS