Java Code Examples for com.watabou.utils.PointF#diff()

The following examples show how to use com.watabou.utils.PointF#diff() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MagicMissile.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 6 votes vote down vote up
public void reset( int from, int to, Callback callback ) {
	this.callback = callback;
	
	revive();
	
	PointF pf = DungeonTilemap.tileCenterToWorld( from );
	PointF pt = DungeonTilemap.tileCenterToWorld( to );
	
	x = pf.x;
	y = pf.y;
	width = 0;
	height = 0;
	
	PointF d = PointF.diff( pt, pf ); 
	PointF speed = new PointF( d ).normalize().scale( SPEED );
	sx = speed.x;
	sy = speed.y;
	time = d.length() / SPEED;
}
 
Example 2
Source File: MagicMissile.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void reset( int from, int to, Callback callback ) {
	this.callback = callback;
	
	revive();
	
	PointF pf = DungeonTilemap.tileCenterToWorld( from );
	PointF pt = DungeonTilemap.tileCenterToWorld( to );
	
	x = pf.x;
	y = pf.y;
	width = 0;
	height = 0;
	
	PointF d = PointF.diff( pt, pf );
	PointF speed = new PointF( d ).normalize().scale( SPEED );
	sx = speed.x;
	sy = speed.y;
	time = d.length() / SPEED;
}
 
Example 3
Source File: MagicMissile.java    From pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void reset( int from, int to, float velocity, Callback callback ) {
	this.callback = callback;
	
	revive();
	
	PointF pf = DungeonTilemap.tileCenterToWorld( from );
	PointF pt = DungeonTilemap.tileCenterToWorld( to );
	
	x = pf.x;
	y = pf.y;
	width = 0;
	height = 0;
	
	PointF d = PointF.diff( pt, pf ); 
	PointF speed = new PointF( d ).normalize().scale( velocity );
	sx = speed.x;
	sy = speed.y;
	time = d.length() / velocity;
}
 
Example 4
Source File: MagicMissile.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void reset( int from, int to, @Nullable Callback callback ) {
	this.callback = callback;
	
	revive();
	
	PointF pf = DungeonTilemap.tileCenterToWorld( from );
	PointF pt = DungeonTilemap.tileCenterToWorld( to );
	
	x = pf.x;
	y = pf.y;
	width = 0;
	height = 0;
	
	PointF d = PointF.diff( pt, pf ); 
	PointF speed = new PointF( d ).normalize().scale( SPEED );
	sx = speed.x;
	sy = speed.y;
	time = d.length() / SPEED;
}
 
Example 5
Source File: Pushing.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean act() {

	if (sprite != null) {

               PointF dest = sprite.worldToCamera( to );
               PointF d = PointF.diff( sprite.worldToCamera( from ), dest );

               PosTweener tweener = new PosTweener( sprite, dest, d.length() / SPEED );

               tweener.listener = new Tweener.Listener() {
                   @Override
                   public void onComplete( Tweener tweener ){
                       Actor.remove( Pushing.this );

                       if( callback != null ){
                           callback.call();
                       }

                       next();
                   }
               };

               sprite.parent.add( tweener );

		return false;

	} else {

		Actor.remove( Pushing.this );
		return true;
	}
}
 
Example 6
Source File: MagicMissile.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void setSpeed( float newSpeed ){
	PointF d = PointF.diff( to, new PointF(x, y) );
	PointF speed = new PointF( d ).normalize().scale( newSpeed );
	sx = speed.x;
	sy = speed.y;
	time = d.length() / newSpeed;
}
 
Example 7
Source File: ZapEffect.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private static void attachMissileTeenier(Visual target, int from, int to) {

        target.point( DungeonTilemap.tileToWorld( from ) );
        PointF dest = DungeonTilemap.tileToWorld( to );

        PointF d = PointF.diff( dest, target.point() );
        target.speed.set( d ).normalize().scale(SPEED );

        target.angularSpeed = 0;
        target.angle = (float) (135 - Math.toDegrees(Math.atan2( d.x, d.y )));

        PosTweener tweener = new PosTweener( target, dest, d.length() / SPEED );
        tweener.listener = tweener1 -> target.killAndErase();
        target.getParent().add( tweener );
    }
 
Example 8
Source File: MissileSprite.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void reset(int from, int to, Item item, Callback listener) {
	revive();

	float scale = item.heapScale();
	setScale(scale, scale);
	view(item);

	this.callback = listener;

	point( DungeonTilemap.tileToWorld( from ) );

	PointF dest = DungeonTilemap.tileToWorld( to );

	PointF d = PointF.diff( dest, point() ); 
	speed.set( d ).normalize().scale( ZapEffect.SPEED );

	if (item.isFliesStraight()) {
		angularSpeed = 0;
		angle = 135 - (float)(Math.atan2( d.x, d.y ) / Math.PI * 180);
	} else {
		angularSpeed = item.isFliesFastRotating() ? 1440 : 720;
	}

	PosTweener tweener = new PosTweener( this, dest, d.length() / ZapEffect.SPEED );
	tweener.listener = this;
	getParent().add( tweener );
}
 
Example 9
Source File: MagicMissile.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public void setSpeed( float newSpeed ){
	PointF d = PointF.diff( to, new PointF(x, y) );
	PointF speed = new PointF( d ).normalize().scale( newSpeed );
	sx = speed.x;
	sy = speed.y;
	time = d.length() / newSpeed;
}
 
Example 10
Source File: MissileSprite.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
public void reset( int from, int to, int image, float speed_modifier, Glowing glowing, Callback listener ) {
		revive();
		
		view( image, glowing );
		
		this.callback = listener;

		point( DungeonTilemap.tileToWorld( from ) );
		PointF dest = DungeonTilemap.tileToWorld( to );
		
		PointF d = PointF.diff( dest, point() );

		speed.set( d ).normalize().scale( SPEED * speed_modifier );

        scale.x = 0.8f;
        scale.y = 0.8f;

        // FIXME

		if (
            image == ItemSpriteSheet.THROWING_DART
            || image == ItemSpriteSheet.THROWING_KNIFE
            || image == ItemSpriteSheet.JAVELIN
//            || image == ItemSpriteSheet.HARPOON
            || image == ItemSpriteSheet.HARPOON_THROWN
            || image == ItemSpriteSheet.HARPOON_RETURN
            || image == ItemSpriteSheet.ARROW
            || image == ItemSpriteSheet.QUARREL
        ) {

			angularSpeed = 0;
			angle = ( image != ItemSpriteSheet.HARPOON_RETURN ? 135 : -45 ) - (float)(Math.atan2( d.x, d.y ) / 3.1415926 * 180);
			
		} else {
			
			angularSpeed = 720;
			
		}
		
		PosTweener tweener = new PosTweener( this, dest, d.length() / SPEED );
		tweener.listener = this;
		parent.add( tweener );
	}
 
Example 11
Source File: MagicMissile.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public void reset( int type, PointF from, PointF to, Callback callback ) {
	this.callback = callback;
	
	this.to = to;
	
	x = from.x;
	y = from.y;
	width = 0;
	height = 0;
	
	PointF d = PointF.diff( to, from );
	PointF speed = new PointF( d ).normalize().scale( SPEED );
	sx = speed.x;
	sy = speed.y;
	time = d.length() / SPEED;

	switch(type){
		case MAGIC_MISSILE: default:
			size( 4 );
			pour( WhiteParticle.FACTORY, 0.01f );
			break;
		case FROST:
			pour( MagicParticle.FACTORY, 0.01f );
			break;
		case FIRE:
			size( 4 );
			pour( FlameParticle.FACTORY, 0.01f );
			break;
		case CORROSION:
			size( 3 );
			pour( CorrosionParticle.MISSILE, 0.01f );
			break;
		case FOLIAGE:
			size( 4 );
			pour( LeafParticle.GENERAL, 0.01f );
			break;
		case FORCE:
			pour( SlowParticle.FACTORY, 0.01f );
			break;
		case BEACON:
			pour( ForceParticle.FACTORY, 0.01f );
			break;
		case SHADOW:
			size( 4 );
			pour( ShadowParticle.MISSILE, 0.01f );
			break;
		case RAINBOW:
			size( 4 );
			pour( RainbowParticle.BURST, 0.01f );
			break;
		case EARTH:
			size( 4 );
			pour( EarthParticle.FACTORY, 0.01f );
			break;
		case WARD:
			size( 4 );
			pour( WardParticle.FACTORY, 0.01f );
			break;
			
		case SHAMAN_RED:
			size( 2 );
			pour( ShamanParticle.RED, 0.01f );
			break;
		case SHAMAN_BLUE:
			size( 2 );
			pour( ShamanParticle.BLUE, 0.01f );
			break;
		case SHAMAN_PURPLE:
			size( 2 );
			pour( ShamanParticle.PURPLE, 0.01f );
			break;
		case TOXIC_VENT:
			size( 10 );
			pour( Speck.factory(Speck.TOXIC), 0.02f );
			break;
		case ELMO:
			size( 5 );
			pour( ElmoParticle.FACTORY, 0.01f );
			break;

		case FIRE_CONE:
			size( 10 );
			pour( FlameParticle.FACTORY, 0.03f );
			break;
		case FOLIAGE_CONE:
			size( 10 );
			pour( LeafParticle.GENERAL, 0.03f );
			break;
	}

	revive();
}
 
Example 12
Source File: MagicMissile.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
public void reset( int type, PointF from, PointF to, Callback callback ) {
	this.callback = callback;
	
	revive();
	
	this.to = to;
	
	x = from.x;
	y = from.y;
	width = 0;
	height = 0;
	
	PointF d = PointF.diff( to, from );
	PointF speed = new PointF( d ).normalize().scale( SPEED );
	sx = speed.x;
	sy = speed.y;
	time = d.length() / SPEED;

	switch(type){
		case MAGIC_MISSILE: default:
			size( 4 );
			pour( WhiteParticle.FACTORY, 0.01f );
			break;
		case FROST:
			pour( MagicParticle.FACTORY, 0.01f );
			break;
		case FIRE:
			size( 4 );
			pour( FlameParticle.FACTORY, 0.01f );
			break;
		case CORROSION:
			size( 3 );
			pour( CorrosionParticle.MISSILE, 0.01f );
			break;
		case FOLIAGE:
			size( 4 );
			pour( LeafParticle.GENERAL, 0.01f );
			break;
		case FORCE:
			pour( SlowParticle.FACTORY, 0.01f );
			break;
		case BEACON:
			pour( ForceParticle.FACTORY, 0.01f );
			break;
		case SHADOW:
			size( 4 );
			pour( ShadowParticle.MISSILE, 0.01f );
			break;
		case RAINBOW:
			size( 4 );
			pour( RainbowParticle.BURST, 0.01f );
			break;
		case EARTH:
			size( 4 );
			pour( EarthParticle.FACTORY, 0.01f );
			break;
		case WARD:
			size( 4 );
			pour( WardParticle.FACTORY, 0.01f );
			break;

		case FIRE_CONE:
			size( 10 );
			pour( FlameParticle.FACTORY, 0.03f );
			break;
		case FOLIAGE_CONE:
			size( 10 );
			pour( LeafParticle.GENERAL, 0.03f );
			break;
	}
}
 
Example 13
Source File: MissileSprite.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 3 votes vote down vote up
public void reset( int from, int to, int image, Glowing glowing, Callback listener ) {
	revive();
	
	view( image, glowing );
	
	this.callback = listener;

	point( DungeonTilemap.tileToWorld( from ) );
	PointF dest = DungeonTilemap.tileToWorld( to );
	
	PointF d = PointF.diff( dest, point() );
	speed.set( d ).normalize().scale( SPEED );

	if (image == ItemSpriteSheet.DART || image == ItemSpriteSheet.INCENDIARY_DART
			|| image == ItemSpriteSheet.CURARE_DART  || image == ItemSpriteSheet.JAVELIN) {

		angularSpeed = 0;
		angle = 135 - (float)(Math.atan2( d.x, d.y ) / 3.1415926 * 180);

	} else {

		angularSpeed = image == 15 || image == 106 ? 1440 : 720;

	}
	
	PosTweener tweener = new PosTweener( this, dest, d.length() / SPEED );
	tweener.listener = this;
	parent.add( tweener );
}
 
Example 14
Source File: MissileSprite.java    From pixel-dungeon with GNU General Public License v3.0 3 votes vote down vote up
public void reset( int from, int to, int image, Glowing glowing, Callback listener ) {
	revive();
	
	view( image, glowing );
	
	this.callback = listener;

	point( DungeonTilemap.tileToWorld( from ) );
	PointF dest = DungeonTilemap.tileToWorld( to );
	
	PointF d = PointF.diff( dest, point() ); 
	speed.set( d ).normalize().scale( SPEED );
	
	if (image == 31 || image == 108 || image == 109 || image == 110) {

		angularSpeed = 0;
		angle = 135 - (float)(Math.atan2( d.x, d.y ) / 3.1415926 * 180);
		
	} else {
		
		angularSpeed = image == 15 || image == 106 ? 1440 : 720;
		
	}
	
	PosTweener tweener = new PosTweener( this, dest, d.length() / SPEED );
	tweener.listener = this;
	parent.add( tweener );
}