Java Code Examples for com.watabou.utils.Random#Float

The following examples show how to use com.watabou.utils.Random#Float . 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: BlobEmitter.java    From pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void emit( int index ) {
	
	if (blob.volume <= 0) {
		return;
	}
	
	int[] map = blob.cur;
	float size = DungeonTilemap.SIZE;
	
	for (int i=0; i < LENGTH; i++) {
		if (map[i] > 0 && Dungeon.visible[i]) {
			float x = ((i % WIDTH) + Random.Float()) * size;
			float y = ((i / WIDTH) + Random.Float()) * size;
			factory.emit( this, index, x, y );
		}
	}
}
 
Example 2
Source File: Vampiric.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int proc( Weapon weapon, Char attacker, Char defender, int damage ) {
	
	//chance to heal scales from 5%-30% based on missing HP
	float missingPercent = (attacker.HT - attacker.HP) / (float)attacker.HT;
	float healChance = 0.05f + .25f*missingPercent;
	
	if (Random.Float() < healChance){
		
		//heals for 50% of damage dealt
		int healAmt = Math.round(damage * 0.5f);
		healAmt = Math.min( healAmt, attacker.HT - attacker.HP );
		
		if (healAmt > 0 && attacker.isAlive()) {
			
			attacker.HP += healAmt;
			attacker.sprite.emitter().start( Speck.factory( Speck.HEALING ), 0.4f, 1 );
			attacker.sprite.showStatus( CharSprite.POSITIVE, Integer.toString( healAmt ) );
			
		}
	}

	return damage;
}
 
Example 3
Source File: Vein.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void update() {

    if (setVisible(Dungeon.visible[pos])) {

        super.update();

        if ((delay -= Game.elapsed) <= 0) {

            delay = Random.Float();

            PointF p = DungeonTilemap.tileToWorld( pos );
            ((Sparkle)recycle( Sparkle.class )).reset(
                p.x + Random.Float( DungeonTilemap.SIZE ),
                p.y + Random.Float( DungeonTilemap.SIZE ) );
        }
    }
}
 
Example 4
Source File: Dungeon.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static boolean posNeeded() {
	// adjusted slightly to account for larger dungeon size... still caps out at 9 upgrades by the end
	if (Dungeon.depth < 30) {
		int[] quota = {5, 2, 11, 4, 17, 6, 23, 7, 29, 8};
		return chance(quota, limitedDrops.strengthPotions.count);
	} else {
		if (limitedDrops.strengthPotions.count > 10) {
			return false;
		}
		return Random.Float() < (float)((10) - limitedDrops.strengthPotions.count) / (depth + 1);
	}
}
 
Example 5
Source File: MonkSprite.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void attack( int cell ) {
	super.attack( cell );
	if (Random.Float() < 0.5f) {
		play( kick );
	}
}
 
Example 6
Source File: BadgesScene.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void update() {
	super.update();

	if (Random.Float() < Game.elapsed * 0.1) {
		BadgeBanner.highlight( icon, badge.image );
	}
}
 
Example 7
Source File: WoolParticle.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void reset( float x, float y ) {
	revive();
	
	this.x = x;
	this.y = y;
	
	left = lifespan = Random.Float( 0.6f, 1f );
	size = 5;
	
	speed.set( Random.Float( -10, +10 ), Random.Float( -10, +10 ) );
}
 
Example 8
Source File: PlatformRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
private void splitPlatforms( Rect curPlatform, ArrayList<Rect> allPlatforms ){
	int curArea = (curPlatform.width()+1) * (curPlatform.height()+1);
	
	//chance to split scales between 0% and 100% between areas of 25 and 36
	if (Random.Float() < (curArea-25)/11f){
		if (curPlatform.width() > curPlatform.height() ||
				(curPlatform.width() == curPlatform.height() && Random.Int(2) == 0)){
			
			//split the platform
			int splitX = Random.IntRange( curPlatform.left+2, curPlatform.right-2);
			splitPlatforms( new Rect( curPlatform.left, curPlatform.top, splitX-1, curPlatform.bottom) , allPlatforms);
			splitPlatforms( new Rect( splitX+1, curPlatform.top, curPlatform.right, curPlatform.bottom) , allPlatforms);
			
			//add a bridge between
			int bridgeY = Random.NormalIntRange(curPlatform.top, curPlatform.bottom);
			allPlatforms.add( new Rect( splitX - 1, bridgeY, splitX + 1, bridgeY));
			
		} else {
			
			//split the platform
			int splitY = Random.IntRange( curPlatform.top+2, curPlatform.bottom-2);
			splitPlatforms( new Rect( curPlatform.left, curPlatform.top, curPlatform.right, splitY-1) , allPlatforms);
			splitPlatforms( new Rect( curPlatform.left, splitY+1, curPlatform.right, curPlatform.bottom) , allPlatforms);
			
			//add a bridge between
			int bridgeX = Random.NormalIntRange(curPlatform.left, curPlatform.right);
			allPlatforms.add( new Rect( bridgeX, splitY-1, bridgeX, splitY+1));
			
		}
	} else {
		allPlatforms.add(curPlatform);
	}
}
 
Example 9
Source File: SurfaceScene.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public Cloud( float y, boolean dayTime ) {
	super( Assets.SURFACE );
	
	int index;
	do {
		index = Random.Int( 3 );
	} while (index == lastIndex);
	
	switch (index) {
	case 0:
		frame( 88, 0, 49, 20 );
		break;
	case 1:
		frame( 88, 20, 49, 22 );
		break;
	case 2:
		frame( 88, 42, 50, 18 );
		break;
	}
	
	lastIndex = index;
	
	this.y = y;

	scale.set( 1 - y / SKY_HEIGHT );
	x = Random.Float( SKY_WIDTH + width() ) - width();
	speed.x = scale.x * (dayTime ? +8 : -8);
	
	if (dayTime) {
		tint( 0xCCEEFF, 1 - scale.y );
	} else {
		rm = gm = bm = +3.0f;
		ra = ga = ba = -2.1f;
	}
}
 
Example 10
Source File: Heap.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public Heap setHauntedIfCursed( float chance ){
	for (Item item : items) {
		if (item.cursed && Random.Float() < chance) {
			haunted = true;
			item.cursedKnown = true;
			break;
		}
	}
	return this;
}
 
Example 11
Source File: WebParticle.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void reset( float x, float y ) {
	revive();
	
	this.x = x;
	this.y = y;
	
	left = lifespan;
	angle = Random.Float( 360 );
}
 
Example 12
Source File: Arrow.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
protected boolean activateSpecial(Char attacker, Char defender, int damage) {
	if (firedFrom != null) {
		return true;
	}

	return Random.Float(1f) < 0.25f;
}
 
Example 13
Source File: WandOfRegrowth.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void staffFx(MagesStaff.StaffParticle particle) {
	particle.color( ColorMath.random(0x004400, 0x88CC44) );
	particle.am = 1f;
	particle.setLifespan(1f);
	particle.setSize( 1f, 1.5f);
	particle.shuffleXY(0.5f);
	float dst = Random.Float(11f);
	particle.x -= dst;
	particle.y += dst;
}
 
Example 14
Source File: EarthParticle.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public EarthParticle() {
	super();
	
	color( ColorMath.random( 0x444444, 0x777766 ) );
	angle = Random.Float( -30, 30 );
}
 
Example 15
Source File: NecroLevel.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void decorate() {

	for (int i=getWidth() + 1; i < getLength() - getWidth() - 1; i++) {
		if (map[i] == Terrain.EMPTY) {

			float c = 0.05f;
			if (map[i + 1] == Terrain.WALL && map[i + getWidth()] == Terrain.WALL) {
				c += 0.2f;
			}
			if (map[i - 1] == Terrain.WALL && map[i + getWidth()] == Terrain.WALL) {
				c += 0.2f;
			}
			if (map[i + 1] == Terrain.WALL && map[i - getWidth()] == Terrain.WALL) {
				c += 0.2f;
			}
			if (map[i - 1] == Terrain.WALL && map[i - getWidth()] == Terrain.WALL) {
				c += 0.2f;
			}

			if (Random.Float() < c) {
				map[i] = Terrain.EMPTY_DECO;
			}
		}
	}

	for (int i=0; i < getWidth(); i++) {
		if (map[i] == Terrain.WALL &&
				(map[i + getWidth()] == Terrain.EMPTY || map[i + getWidth()] == Terrain.EMPTY_SP) &&
				Random.Int( 6 ) == 0) {

			map[i] = Terrain.WALL_DECO;
		}
	}

	for (int i=getWidth(); i < getLength() - getWidth(); i++) {
		if (map[i] == Terrain.WALL &&
				map[i - getWidth()] == Terrain.WALL &&
				(map[i + getWidth()] == Terrain.EMPTY || map[i + getWidth()] == Terrain.EMPTY_SP) &&
				Random.Int( 3 ) == 0) {

			map[i] = Terrain.WALL_DECO;
		}
	}
}
 
Example 16
Source File: Element.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
public static boolean checkIfAmplified( float resistance ) {
    return resistance < VULNERABLE || resistance < Random.Float( VULNERABLE, DEFAULT );
}
 
Example 17
Source File: WindParticle.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public WindParticle() {
	super();
	
	lifespan = Random.Float( 1, 2 );
	scale.set( size = Random.Float( 3 ) );
}
 
Example 18
Source File: PrisonLevel.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void decorate() {
	
	for (int i=getWidth() + 1; i < getLength() - getWidth() - 1; i++) {
		if (map[i] == Terrain.EMPTY) { 
			
			float c = 0.05f;
			if (map[i + 1] == Terrain.WALL && map[i + getWidth()] == Terrain.WALL) {
				c += 0.2f;
			}
			if (map[i - 1] == Terrain.WALL && map[i + getWidth()] == Terrain.WALL) {
				c += 0.2f;
			}
			if (map[i + 1] == Terrain.WALL && map[i - getWidth()] == Terrain.WALL) {
				c += 0.2f;
			}
			if (map[i - 1] == Terrain.WALL && map[i - getWidth()] == Terrain.WALL) {
				c += 0.2f;
			}
			
			if (Random.Float() < c) {
				map[i] = Terrain.EMPTY_DECO;
			}
		}
	}
	
	for (int i=0; i < getWidth(); i++) {
		if (map[i] == Terrain.WALL &&  
			(map[i + getWidth()] == Terrain.EMPTY || map[i + getWidth()] == Terrain.EMPTY_SP) &&
			Random.Int( 6 ) == 0) {
			
			map[i] = Terrain.WALL_DECO;
		}
	}
	
	for (int i=getWidth(); i < getLength() - getWidth(); i++) {
		if (map[i] == Terrain.WALL && 
			map[i - getWidth()] == Terrain.WALL && 
			(map[i + getWidth()] == Terrain.EMPTY || map[i + getWidth()] == Terrain.EMPTY_SP) &&
			Random.Int( 3 ) == 0) {
			
			map[i] = Terrain.WALL_DECO;
		}
	}

	placeEntranceSign();

	if(Dungeon.depth == 7 && hasExit(1)) {
		Room NecroExit = exitRoom(1);
		if(NecroExit!=null) {
			NecroExitPainter.paint(this, NecroExit);
		}
	}
	placeBarrels(Random.Int(5));
}
 
Example 19
Source File: Emitter.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 3 votes vote down vote up
public void start( Factory factory, float interval, int quantity ) {
	
	this.factory = factory;
	this.lightMode = factory.lightMode();
	
	this.interval = interval;
	this.quantity = quantity;
	
	count = 0;
	time = Random.Float( interval );

	on = true;
}
 
Example 20
Source File: HallsLevel.java    From shattered-pixel-dungeon with GNU General Public License v3.0 3 votes vote down vote up
public Stream( int pos ) {
	super();
	
	this.pos = pos;
	
	delay = Random.Float( 2 );
}