public static Color Color(float alpha) { return(new Color(RXRandom.Float(), RXRandom.Float(), RXRandom.Float(), alpha)); }
//this isn't really perfectly randomized, but good enough for most purposes public static Vector2 Vector2Normalized() { return(new Vector2(RXRandom.Range(-1.0f, 1.0f), RXRandom.Range(-1.0f, 1.0f)).normalized); }
private void ResetBall() { _ball.x = 0; _ball.y = 0; // Ensure that the ball starts at a random angle that is never greater than 45 degrees from 0 in either direction _ball.yVelocity = (_ball.defaultVelocity / 2) - (RXRandom.Float() * _ball.defaultVelocity); // Make sure that the defaultVelocity (hypotenuse) is honored by setting the xVelocity accordingly, then choose a random horizontal direction _ball.xVelocity = Mathf.Sqrt((_ball.defaultVelocity * _ball.defaultVelocity) - (_ball.yVelocity * _ball.yVelocity)) * (RXRandom.Int(2) * 2 - 1); }
public Neuron(bool fast, Opacity opacity) : base("NeuronSlow40") { ListenForUpdate(HandleUpdate); scale = RXRandom.Range(0.1f, 0.25f); rotation = RXRandom.Range(-180.0f, 180.0f); int[] frames; string anim_name; if (fast) { frames = new int[10]; for (int i = 0; i < 10; i++) { frames[i] = i + 1; } switch (opacity) { case Opacity.PERCENT_40: anim_name = "NeuronFast40"; break; case Opacity.PERCENT_60: anim_name = "NeuronFast60"; break; case Opacity.PERCENT_80: anim_name = "NeuronFast80"; break; default: anim_name = "NeuronFast40"; break; } } else { frames = new int[15]; for (int i = 0; i < 15; i++) { frames[i] = i + 1; } switch (opacity) { case Opacity.PERCENT_40: anim_name = "NeuronSlow40"; break; case Opacity.PERCENT_60: anim_name = "NeuronSlow60"; break; case Opacity.PERCENT_80: anim_name = "NeuronSlow80"; break; default: anim_name = "NeuronFast40"; break; } } FAnimation animation = new FAnimation("spark", anim_name, frames, 100, false); base.addAnimation(animation); }
public static Color ColorHSL(float sat = 1f, float lum = 0.5f, float alpha = 1f) { return(RXColor.ColorFromHSL(RXRandom.Float(), sat, lum, alpha)); }
public override void Update() { if (isControllable) { xMove = 0; yMove = 0; if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { yMove = controlSpeed * UnityEngine.Time.deltaTime; } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { yMove = -(controlSpeed * UnityEngine.Time.deltaTime); } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { xMove = -(controlSpeed * UnityEngine.Time.deltaTime); } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { xMove = controlSpeed * UnityEngine.Time.deltaTime; } if (Input.GetMouseButton(0)) { state = State.SHOOTING; } else { state = State.IDLE; } rotation = 0; rotation = this.GetLocalMousePosition().GetAngle() + 90; } else { if (RXRandom.Double() < .03) { xMove = (RXRandom.Float() * speed * 2 - speed) * UnityEngine.Time.deltaTime; yMove = (RXRandom.Float() * speed * 2 - speed) * UnityEngine.Time.deltaTime; rotation = new Vector2(xMove, yMove).GetAngle() + 90; } else if (RXRandom.Double() < .01) { xMove = 0; yMove = 0; } } tryMove(); if (this.powerupClock.percentage <= 0 && this.powerUpType != Powerup.PowerupType.NONE) { collectPowerUp(Powerup.PowerupType.NONE); } if (lastShoot < minShoot) { lastShoot += UnityEngine.Time.deltaTime; } switch (state) { case State.IDLE: break; case State.SHOOTING: if (lastShoot >= minShoot || (powerUpType == Powerup.PowerupType.MACHINEGUN && lastShoot >= minShoot * .05f)) { lastShoot = 0; foreach (Bullet b in shootBullet()) { world.addBullet(b); } } break; } if (isControllable) { switch (this.powerUpType) { case Powerup.PowerupType.NONE: play("pistol"); break; case Powerup.PowerupType.SHOTGUN: play("shotgun"); break; case Powerup.PowerupType.MACHINEGUN: play("machinegun"); break; } } shadow.rotation = this.rotation; shadow.SetPosition(this.GetPosition()); shadow.y -= 3; hair.SetPosition(this.GetPosition()); hair.rotation = this.rotation; playerBlip.SetPosition(GetPosition() * Minimap.BLIP_POS_MULT); playerBlip.rotation = this.rotation; playerBlip.scale = this.scale * .5f; base.Update(); }
void StartHeartShower() { heartShowerHasStarted = true; foreach (FSprite heart in heartShowerHearts) { heart.x = Random.Range(0, Futile.screen.width); heart.y = Futile.screen.height + heart.height + Random.Range(0, 500); heart.isVisible = true; Go.to(heart, Random.Range(1.0f, 4.0f), new TweenConfig().setIterations(-1).floatProp("rotation", 360 * (RXRandom.Float() < 0.5 ? 1 : -1), true)); } }
public void PlaySoundPitched(String resourcePath, float volume, float pitchRange) { PlaySound(resourcePath, volume, 0, 1.0f + RXRandom.Range(-pitchRange * 0.5f, pitchRange * 0.5f), 0); }
public override void Update() { float forwardStep = 5f; float angle = 0; passedTime += 1; float dist = Vector2.Distance(InGamePage.CurrentInGamePage.getPlayer().GetPosition(), Position); if (dist < 100f) { Shoot(); } if (InGamePage.CurrentInGamePage.getPlayer().GetPosition().y < Position.y) { angle -= 0.5f; } else if (InGamePage.CurrentInGamePage.getPlayer().GetPosition().y > Position.y) { angle += 0.5f; } if (hInput > 0) { sprite.scaleX = 1f; FacingRight = 1; } else if (hInput < 0) { sprite.scaleX = -1f; FacingRight = -1; } setRotationalAngle(getRotationalAngle() + angle); if (getRotationalAngle() > 45) { setRotationalAngle(45); } else if (getRotationalAngle() < -45) { setRotationalAngle(-45); } if (FacingRight > 0) { rotation = -getRotationalAngle(); } else { rotation = getRotationalAngle(); } if (Position.x > Futile.screen.width / 2) { Position.x = -Futile.screen.width / 2 + sprite.width / 2; } if (Position.x < -Futile.screen.width / 2) { Position.x = Futile.screen.width / 2 + sprite.width / 2; } velocity.x += Mathf.Cos(getRotationalAngle() * Mathf.Deg2Rad) * Time.deltaTime * forwardStep * hInput; velocity.y += Mathf.Sin(getRotationalAngle() * Mathf.Deg2Rad) * Time.deltaTime * forwardStep; velocity.x *= 0.9f; velocity.y *= 0.8f; Position += velocity; SetPosition(Position); if (Mathf.Abs(velocity.x) > 1) { pd = new FParticleDefinition("bubble"); pd.startScale = 1.5f; pd.startColor = new Color(255, 255, 255, 0.8f); pd.endColor = new Color(255, 255, 255, 0.1f); pd.x = Position.x; pd.y = Position.y; Vector2 speed = RXRandom.Vector2Normalized() * RXRandom.Range(20.0f, 80.0f); pd.speedX = speed.x; pd.speedY = speed.y; pd.lifetime = RXRandom.Range(0.2f, 0.5f); InGamePage.CurrentInGamePage.projectilesParticles.AddParticle(pd); } curretTimer += 1f * Time.deltaTime; }