Shooting the Opposite Way? - AndEngine classic tutorial
Ok, this should be simple enough, but I'm tripping myself up on the math.  Using AndEngine BTW>

I'm using some of the tutorials out there... hero on the left of the screen (landscape) shooting right.  Everything works wonderfully.  Now I'd like to have the hero on the right side of the screen shooting left.  I'm going in circles and would great appreciate some help.  Here is the code I'm using for left hero, shooting right.


[syntax="java"]

/** shoots a projectile from the player's position along the touched area */
	private void shootProjectile(final float pX, final float pY) {

		int offX = (int) (pX - (hero.getX()));
		int offY = (int) (pY - (hero.getY() + hero.getHeight()/2));
		if (offX <= 0)
			return;

		
		// position the projectile on the player and set up path
		projectile = pPool.obtainPoolItem();
		
		int realX = (int) (mCamera.getWidth() - (hero.getX()  ) );
		float ratio = (float) realX / (float) offX;
		int realY = (int) ((offY * ratio));

		float length = (float) Math.sqrt((realX * realX) + (realY * realY));
		float velocity = 280.0f / .5f; // 480 pixels per (sec)f on screen
		float realMoveDuration = length / velocity;
	
		// defining a moveBymodifier from the projectile's position to the
		// calculated one
		
		//this code angles the projectile sprite
		double PI = 3.14159265;
                float  dx = pX -  hero.getX();
                float  dy = pY -  hero.getY()-50;
       
                double  Radius = Math.atan2(dy,dx);
                double Angle = Radius * 180 / PI;
             
                 projectile.setRotation((float)Angle); // sets the angle of the projectile
       
		
                //Move modifier for projectile
		MoveByModifier movMByod = new MoveByModifier(realMoveDuration, realX, realY);
		
		final ParallelEntityModifier par = new ParallelEntityModifier(movMByod);

		DelayModifier dMod = new DelayModifier(0.001f);
		dMod.addModifierListener(new IModifierListener<IEntity>() {

			@Override
			public void onModifierStarted(IModifier<IEntity> arg0, IEntity arg1) {
			}

			@Override
			public void onModifierFinished(IModifier<IEntity> arg0, IEntity arg1) {
				// TODO Auto-generated method stub
				shootingSound.play();
				projectile.setVisible(true);
				projectile.setPosition(hero.getX(), hero.getY() + hero.getHeight() / 2);
				projectilesToBeAdded.add(projectile);
				projectile.animate(50);
				
			}
		});

		SequenceEntityModifier seq = new SequenceEntityModifier(dMod, par);
		projectile.registerEntityModifier(seq);
		projectile.setVisible(false);
		mMainScene.attachChild(projectile, 1);


[/syntax]


I've got the hero positioned fine on the right side.  What do I need to do to get the projectile to move to the left correctly?

Thanks a ton for any help.

MWM
Shooting the Opposite Way? - AndEngine classic tutorial
===

Ok, this should be simple enough, but I'm tripping myself up on the math.  Using AndEngine BTW>

I'm using some of the tutorials out there... hero on the left of the screen (landscape) shooting right.  Everything works wonderfully.  Now I'd like to have the hero on the right side of the screen shooting left.  I'm going in circles and would great appreciate some help.  Here is the code I'm using for left hero, shooting right.


[syntax="java"]

/** shoots a projectile from the player's position along the touched area */
	private void shootProjectile(final float pX, final float pY) {

		int offX = (int) (pX - (hero.getX()));
		int offY = (int) (pY - (hero.getY() + hero.getHeight()/2));
		if (offX <= 0)
			return;

		
		// position the projectile on the player and set up path
		projectile = pPool.obtainPoolItem();
		
		int realX = (int) (mCamera.getWidth() - (hero.getX()  ) );
		float ratio = (float) realX / (float) offX;
		int realY = (int) ((offY * ratio));

		float length = (float) Math.sqrt((realX * realX) + (realY * realY));
		float velocity = 280.0f / .5f; // 480 pixels per (sec)f on screen
		float realMoveDuration = length / velocity;
	
		// defining a moveBymodifier from the projectile's position to the
		// calculated one
		
		//this code angles the projectile sprite
		double PI = 3.14159265;
                float  dx = pX -  hero.getX();
                float  dy = pY -  hero.getY()-50;
       
                double  Radius = Math.atan2(dy,dx);
                double Angle = Radius * 180 / PI;
             
                 projectile.setRotation((float)Angle); // sets the angle of the projectile
       
		
                //Move modifier for projectile
		MoveByModifier movMByod = new MoveByModifier(realMoveDuration, realX, realY);
		
		final ParallelEntityModifier par = new ParallelEntityModifier(movMByod);

		DelayModifier dMod = new DelayModifier(0.001f);
		dMod.addModifierListener(new IModifierListener<IEntity>() {

			@Override
			public void onModifierStarted(IModifier<IEntity> arg0, IEntity arg1) {
			}

			@Override
			public void onModifierFinished(IModifier<IEntity> arg0, IEntity arg1) {
				// TODO Auto-generated method stub
				shootingSound.play();
				projectile.setVisible(true);
				projectile.setPosition(hero.getX(), hero.getY() + hero.getHeight() / 2);
				projectilesToBeAdded.add(projectile);
				projectile.animate(50);
				
			}
		});

		SequenceEntityModifier seq = new SequenceEntityModifier(dMod, par);
		projectile.registerEntityModifier(seq);
		projectile.setVisible(false);
		mMainScene.attachChild(projectile, 1);


[/syntax]


I've got the hero positioned fine on the right side.  What do I need to do to get the projectile to move to the left correctly?

Thanks a ton for any help.

MWM