public Particle(Texture2D texture, Vector2 position, float rotation, float directionInRadians) { _texture = texture; _position = position; _rotation = rotation; State = ParticleState.Entering; const float movementDelta = 100f; var dX = (float)(movementDelta * Math.Cos(directionInRadians)); var dY = (float)(movementDelta * Math.Sin(directionInRadians)); _movementAnimators = new[] { new Animator(Easing.Linear, position.X, val => _position.X = val, dX, 6), new Animator(Easing.Linear, position.Y, val => _position.Y = val, dY, 6) }; _enteringAnimators = new [] { new Animator(Easing.CubicInOut, 0, val => _opacity = val, 1f, 2), new Animator(Easing.CircularInOut, 0, val => _scale = val, 1f, 2), }; _exitingAnimators = new [] { new Animator(Easing.CubicInOut, 1, val => _opacity = val, -1f, 2), new Animator(Easing.CircularInOut, 1, val => _scale = val, -1f, 2), }; _hangingOutTimer = new EasyTimer(TimeSpan.FromSeconds(1)); }
public virtual void Init(ParticleState particleState, double[] velocity, DimensionBound[] bounds = null) { CurrentState = particleState; PersonalBest = particleState; Velocity = velocity; Bounds = bounds; }
/// <summary> /// Handles input for quitting the game and cycling /// through the different particle effects. /// </summary> void HandleInput() { lastKeyboardState = currentKeyboardState; lastGamePadState = currentGamePadState; currentKeyboardState = Keyboard.GetState(); currentGamePadState = GamePad.GetState(PlayerIndex.One); // Check for exit. if (currentKeyboardState.IsKeyDown(Keys.Escape) || currentGamePadState.Buttons.Back == ButtonState.Pressed) { Exit(); } // Check for changing the active particle effect. if (((currentKeyboardState.IsKeyDown(Keys.Space) && (lastKeyboardState.IsKeyUp(Keys.Space))) || ((currentGamePadState.Buttons.A == ButtonState.Pressed)) && (lastGamePadState.Buttons.A == ButtonState.Released))) { currentState++; if (currentState > ParticleState.RingOfFire) { currentState = 0; } } }
public virtual void Transpose(IFitnessFunction <double[], double[]> function) { double[] newLocation; var restart = _sinceLastImprovement == _iterationsToRestart; if (restart) { newLocation = RandomGenerator.GetInstance().RandomVector(CurrentState.Location.Length, Bounds); _sinceLastImprovement = 0; } else { newLocation = GetClampedLocation(CurrentState.Location.Select((x, i) => x + Velocity[i]).ToArray()); } var newVal = function.Evaluate(newLocation); var oldBest = PersonalBest; CurrentState = new ParticleState(newLocation, newVal); if (Optimization.IsBetter(newVal, PersonalBest.FitnessValue) < 0) { PersonalBest = CurrentState; _sinceLastImprovement = 0; } else { _sinceLastImprovement++; } }
public void StopAll() { switch (_state) { case ParticleState.Start: Start.Stop(); break; case ParticleState.Follow: StartCoroutine(FlyBack(startObjPos)); _state = ParticleState.FlyBack; break; case ParticleState.End: break; case ParticleState.None: break; case ParticleState.FlyBack: Follow.Stop(); End.Stop(); break; default: break; } _state = ParticleState.None; }
public void Hit() { if (!IsInvincible) { _lives--; _deadSound.Play(); var yellow = new Color(0.8f, 0.8f, 0.4f); for (int i = 0; i < 1200; i++) { float speed = 18f * (1f - 1 / GameRef.Rand.NextFloat(1f, 10f)); Color color = Color.Lerp(Color.White, yellow, GameRef.Rand.NextFloat(0, 1)); var state = new ParticleState() { Velocity = GameRef.Rand.NextVector2(speed, speed), Type = ParticleType.None, LengthMultiplier = 1 }; GameRef.ParticleManager.CreateParticle(GameRef.LineParticle, Position, color, 190, 1.5f, state); } _timeBeforeRespawn = Config.PlayerTimeBeforeRespawn; IsInvincible = true; CollisionBoxes.Add(_shieldCollisionCircle); } }
public override void CreateGroundImpactParticles() { if (!_wheelMode) { base.CreateGroundImpactParticles(); return; } for (var i = 0; i < 6; i++) { var position = new Vector2(BoundingRectangle.Center.X, BoundingRectangle.Bottom); position.X += _rand.Next(-5, 5); var velocity = new Vector2(_rand.NextFloat(-5f, 5f), _rand.NextFloat(-1f, -3f)) * 3f; var size = new Vector2(_rand.NextFloat(5f, 7f), _rand.NextFloat(4f, 6f)); var state = new ParticleState() { Velocity = velocity, AlphaBase = _rand.NextFloat(0.2f, 0.6f), Type = ParticleType.Smoke }; SceneManager.Instance.ParticleManager.CreateParticle(ImageManager.loadParticle("Smoke"), position, Color.White, 1000f, size, state); } }
void Start () { rigidbody = gameObject.GetComponent<Rigidbody> (); state_ = new StaticState (); floatingAcceleration = new Vector3 (0, Random.Range(0.05f, 0.50f), 0); }
public void BroadcastCalculationsFinished(ParticleState result) { foreach (var client in NodeServiceClients) { client.CalculationsFinished(NodeService.Info,result); } }
private IEnumerator SwapParticleCoroutine(GameObject from, GameObject to) { _state = ParticleState.None; startObj = from; SetParticleColor(from); var col = from.GetComponent <PolygonCollider2D>(); Vector3 size = col.bounds.extents * from.transform.localScale.x; size *= 0.25f; transform.localScale = size; startObjPos = col.bounds.center; transform.position = startObjPos; col = to.GetComponent <PolygonCollider2D>(); Vector3 toPos = col.bounds.center; PlayParticle(Start); while (Start.isPlaying) { yield return(null); } PlayParticle(Follow); float t = 0; while (Vector3.Distance(transform.position, toPos) > 0.5f) { t += 2.0f * Time.deltaTime; transform.position = Vector3.Lerp(startObjPos, toPos, t); yield return(null); } Follow.Stop(); transform.position = toPos; PlayParticle(End); }
public virtual void Init(ParticleState particleState, double[] velocity, DimensionBound[] bounds = null) { CurrentState = particleState; PersonalBest = particleState; Velocity = velocity; Bounds = bounds; }
internal void AvClose(Vector3D endPos, bool detonateFakeExp = false) { if (Vector3D.IsZero(TracerFront)) { TracerFront = endPos; } DetonateFakeExp = detonateFakeExp; Dirty = true; if (DetonateFakeExp) { HitParticle = ParticleState.Dirty; if (Ai.Session.Av.ExplosionReady) { if (OnScreen != Screen.None) { if (DetonateFakeExp) { SUtils.CreateFakeExplosion(Ai.Session, AmmoDef.AreaEffect.Detonation.DetonationRadius, TracerFront, AmmoDef); } else { SUtils.CreateFakeExplosion(Ai.Session, AmmoDef.AreaEffect.AreaEffectRadius, TracerFront, AmmoDef); } } } } if (!Active) { Ai.Session.Av.AvShotPool.Return(this); } }
internal void RegisterCamera(AmplifyMotionCamera camera) { Camera component = camera.GetComponent <Camera>(); if ((component.cullingMask & 1 << base.gameObject.layer) != 0 && !this.m_states.ContainsKey(component)) { MotionState value; switch (this.m_type) { case ObjectType.Solid: value = new SolidState(camera, this); break; case ObjectType.Skinned: value = new SkinnedState(camera, this); break; case ObjectType.Cloth: value = new ClothState(camera, this); break; case ObjectType.Particle: value = new ParticleState(camera, this); break; default: throw new Exception("[AmplifyMotion] Invalid object type."); } camera.RegisterObject(this); this.m_states.Add(component, value); } }
public void WasShot() { IsExpired = true; var hue1 = Random.NextFloat(0, 6); var hue2 = (hue1 + Random.Next(0, 2)) % 6f; var color1 = ColorUtil.HsvToColor(hue1, 0.5f, 1); var color2 = ColorUtil.HsvToColor(hue2, 0.5f, 1); for (var i = 0; i < 120; i++) { var speed = 18f * (1f - 1 / Random.NextFloat(1, 10)); var state = new ParticleState { Velocity = Random.NextVector(speed, speed), Type = ParticleType.Enemy, LengthMultiplier = 1 }; var color = Color.Lerp(color1, color2, Random.NextFloat(0, 1)); GameRoot.ParticleManager.CreateParticle(Art.LineParticle, Position, color, 190, 1.5f, state); } PlayerStatus.AddPoints(PointValue); PlayerStatus.IncreaseMultiplier(); Sound.Explosion.Play(0.5f, Random.NextFloat(-0.2f, 0.2f), 0); }
public void TakeDamage(float damage) { _health -= damage; if (_health < 0) { float hue1 = GameRef.Rand.NextFloat(0, 6); float hue2 = (hue1 + GameRef.Rand.NextFloat(0, 2)) % 6f; Color color1 = ColorUtil.HSVToColor(hue1, 0.5f, 1); Color color2 = ColorUtil.HSVToColor(hue2, 0.5f, 1); for (int i = 0; i < 5000; i++) { float speed = 18f * (1f - 1 / GameRef.Rand.NextFloat(1f, 10f)); var state = new ParticleState() { Velocity = GameRef.Rand.NextVector2(speed, speed), Type = ParticleType.Enemy, LengthMultiplier = 1f }; Color color = Color.Lerp(color1, color2, GameRef.Rand.NextFloat(0, 1)); GameRef.ParticleManager.CreateParticle(GameRef.LineParticle, new Vector2(Position.X, Position.Y - Size.Y / 2f), color, 190, 1.5f, state); } IsAlive = false; } }
public void BroadcastCalculationsFinished(ParticleState result) { foreach (var client in NodeServiceClients) { client.CalculationsFinished(NodeService.Info, result); } }
public void CalculationsFinished(NetworkNodeInfo source, ParticleState result) { Debug.WriteLine("{0}: received calculations finish from {1}", Info.Id, source.Id); if (RemoteCalculationsFinished != null) { RemoteCalculationsFinished(new RemoteCalculationsFinishedHandlerArgs(source, result)); } }
internal StateProxy(CudaParams parameters) { var rand = RandomGenerator.GetInstance(); var x = parameters.Bounds != null?rand.RandomVector(parameters.LocationDimensions, parameters.Bounds) : rand.RandomVector(parameters.LocationDimensions); CpuState = new ParticleState(x, parameters.FitnessFunction.Evaluate(x)); GpuState = new ParticleState(x, parameters.FitnessFunction.Evaluate(x)); }
internal StateProxy(CudaParams parameters) { var rand = RandomGenerator.GetInstance(); var x = parameters.Bounds != null ? rand.RandomVector(parameters.LocationDimensions, parameters.Bounds) : rand.RandomVector(parameters.LocationDimensions); CpuState = new ParticleState(x, parameters.FitnessFunction.Evaluate(x)); GpuState = new ParticleState(x, parameters.FitnessFunction.Evaluate(x)); }
public void CalculationsFinished(NetworkNodeInfo source, ParticleState result) { Debug.WriteLine("{0}: received calculations finish from {1}",Info.Id, source.Id); if (RemoteCalculationsFinished != null) { RemoteCalculationsFinished(new RemoteCalculationsFinishedHandlerArgs(source, result)); } }
public void EndDrag(GameObject go) { var col = go.GetComponent <PolygonCollider2D>(); Vector3 destination = col.bounds.center; _state = ParticleState.FlyBack; StartCoroutine(FlyBack(destination)); }
void OnCatch(GameObject catcher) { Debug.Log(catcher.name + " has catched paricle " + GetInstanceID()); state = ParticleState.Catched; this.catcher = catcher; transform.parent = catcher.transform; rb.velocity = Vector2.zero; }
public override bool Intersects(Entity entity) { foreach (var collisionBox in CollisionBoxes) { var collisionConvexPolygon = collisionBox as CollisionConvexPolygon; if (collisionConvexPolygon == null) { return(base.Intersects(entity)); } foreach (var entityCollisionBox in entity.CollisionBoxes) { if (entityCollisionBox.Intersects(collisionBox)) { var bullet = entity as BaseBullet; if (bullet != null) { _collisionBoxesHp[collisionConvexPolygon] -= bullet.Power; if (_collisionBoxesHp[collisionConvexPolygon] <= 0) { float hue1 = GameRef.Rand.NextFloat(0, 6); float hue2 = (hue1 + GameRef.Rand.NextFloat(0, 2)) % 6f; Color color1 = ColorUtil.HSVToColor(hue1, 0.5f, 1); Color color2 = ColorUtil.HSVToColor(hue2, 0.5f, 1); for (int i = 0; i < 120; i++) { float speed = 18f * (1f - 1 / GameRef.Rand.NextFloat(1f, 10f)); var state = new ParticleState() { Velocity = GameRef.Rand.NextVector2(speed, speed), Type = ParticleType.Enemy, LengthMultiplier = 1f }; Color color = Color.Lerp(color1, color2, GameRef.Rand.NextFloat(0, 1)); GameRef.ParticleManager.CreateParticle(GameRef.LineParticle, bullet.Position, color, 190, 1.5f, state); } Split(collisionConvexPolygon); } } _color = HitColor; _changeColorTimer = new TimeSpan(0, 0, 0, 0, 40); return(true); } } } return(false); }
public double[] Evaluate(double[] x) { var newState = new ParticleState(x, _evaluate(x)); if (BestEvaluation == null || _optimization.IsBetter(newState.FitnessValue, BestEvaluation.FitnessValue) < 0) { BestEvaluation = newState; } EvaluationsCount++; return(newState.FitnessValue); }
public ParticleEngineBase(Texture2D tex, ushort number) { Texture = tex; Vertex = new ParticleVertex[number]; for (int i = 0; i < Vertex.Length; i++) { Vertex[i].Alpha.X = 0; } Time = 0; state = ParticleState.Suspend; }
internal void Close() { // Reset only vars that are not always set Hit = new Hit(); if (AmmoSound) { TravelEmitter.StopSound(true); AmmoSound = false; } HitVelocity = Vector3D.Zero; TracerBack = Vector3D.Zero; TracerFront = Vector3D.Zero; ClosestPointOnLine = Vector3D.Zero; Color = Vector4.Zero; OnScreen = Screen.None; Tracer = TracerState.Off; Trail = TrailState.Off; LifeTime = 0; TracerSteps = 0; TracerStep = 0; DistanceToLine = 0; TracerWidth = 0; TrailWidth = 0; TrailScaler = 0; MaxTrajectory = 0; ShotFade = 0; ParentId = ulong.MaxValue; Dirty = false; AmmoSound = false; HitSoundActive = false; StartSoundActived = false; IsShrapnel = false; HasTravelSound = false; HitParticle = ParticleState.None; Triggered = false; Cloaked = false; Active = false; TrailActivated = false; ShrinkInited = false; Hitting = false; Back = false; LastStep = false; DetonateFakeExp = false; TracerShrinks.Clear(); GlowSteps.Clear(); Offsets.Clear(); // FiringWeapon = null; PrimeEntity = null; TriggerEntity = null; Ai = null; AmmoDef = null; System = null; }
private void CreateExplosionParticle() { var state = new ParticleState { Velocity = Random.NextVector(0, 9), Type = ParticleType.Bullet, LengthMultiplier = 1 }; GameRoot.ParticleManager.CreateParticle(Art.LineParticle, Position, Color.LightBlue, 50, 1, state); }
public void CalculationsFinished(NetworkNodeInfo source, ParticleState result) { try { Proxy.CalculationsFinished(source, result); } catch { // ignored } }
public void CalculationsFinished(NetworkNodeInfo source, ParticleState result) { try { Proxy.CalculationsFinished(source, result); } catch { // ignored } }
private void Finish(ParticleState result) { if (_mainNodeInfo == NetworkNodeManager.NodeService.Info) { var bestFromNodes = NetworkNodeManager.StopCalculations(); _psoController.UpdateResultWithOtherNodes(bestFromNodes); } else { NetworkNodeManager.BroadcastCalculationsFinished(result); } }
// Update is called once per frame void Update () { if (Input.anyKeyDown) { Debug.Log("key down"); ParticleState state = state_.changeState(this); if (state != null){ state_ = state; state_.enter(this); } } state_.update (this); }
private IState <double[], double[]> GetCurrentBest() { var currentBest = _particles[0].PersonalBest; foreach (var particle in _particles) { if (_optimizer.IsBetter(currentBest.FitnessValue, particle.PersonalBest.FitnessValue) > 0) { currentBest = new ParticleState(particle.PersonalBest.Location, particle.PersonalBest.FitnessValue); } } return(currentBest); }
public void StartDrag(GameObject go) { startObj = go; SetParticleColor(go); var col = go.GetComponent <PolygonCollider2D>(); Vector3 size = col.bounds.extents * go.transform.localScale.x; startObjPos = col.bounds.center; transform.position = startObjPos; size *= 0.25f; transform.localScale = size; PlayParticle(Start); _state = ParticleState.Start; }
private ParticleState BestNeighborState() { ParticleState best = Neighborhood[0].PersonalBest; foreach (var particle in Neighborhood) { if (Optimization.IsBetter(particle.PersonalBest.FitnessValue, best.FitnessValue) < 0) { best = particle.PersonalBest; } } return(best); }
public void BeginSlowing() { beganSlowing = Time.time; state = ParticleState.Slowing; var emission = sys.emission; emission.enabled = false; velocities = new Vector3[sys.particleCount]; InitializeParticleArray(); sys.GetParticles(particles); for (int i = 0; i < particles.Length; i++) { velocities[i] = particles[i].velocity; } }
private void SprayOrbitingParticles() { var velocity = MathUtil.FromPolar(sprayAngle, Random.NextFloat(12, 15)); var color = ColorUtil.HsvToColor(5, 0.5f, 0.8f); var position = Position + 2f * new Vector2(velocity.Y, -velocity.X) + Random.NextVector(4, 8); var state = new ParticleState { Velocity = velocity, LengthMultiplier = 1, Type = ParticleType.Enemy }; GameRoot.ParticleManager.CreateParticle(Art.LineParticle, position, color, 190, 1.5f, state); sprayAngle -= MathHelper.TwoPi / 50f; }
public void Detach() { if (catcher == null) { Debug.LogError("Remove called but catcher is null!"); return; } Debug.Log("Detaching particle " + GetInstanceID()); state = ParticleState.Detached; transform.parent = null; if (rb.velocity.magnitude < 0.1) { // Avoid divide by 0 rb.velocity = Vector2.down; } rb.velocity *= detachMagnitude / rb.velocity.magnitude; }
public PartSysEmitter(IPartSysExternal external, PartSysEmitterSpec spec) { External = external; _spec = spec; _particleAges = new float[spec.GetMaxParticles()]; _paramState = new PartSysParamState[(int)PartSysParamId.PARTICLE_PARAM_COUNT]; _particleState = new ParticleState(spec.GetMaxParticles()); for (var i = 0; i < _paramState.Length; ++i) { var param = _spec.GetParam((PartSysParamId)i); if (param != null) { _paramState[i] = param.CreateState(_particleAges.Length); } } }
private IState<double[], double[]> GetCurrentBest() { var currentBest = _particles[0].PersonalBest; foreach (var particle in _particles) { if (_optimizer.IsBetter(currentBest.FitnessValue, particle.PersonalBest.FitnessValue) > 0) { currentBest = new ParticleState(particle.PersonalBest.Location, particle.PersonalBest.FitnessValue); } } return currentBest; }
private void Finish(ParticleState result) { if (_mainNodeInfo == NetworkNodeManager.NodeService.Info) { var bestFromNodes = NetworkNodeManager.StopCalculations(); _psoController.UpdateResultWithOtherNodes(bestFromNodes); } else { NetworkNodeManager.BroadcastCalculationsFinished(result); } }
public void CreateSparkParticle(Vector2 position, int number = 4) { var texture = ImageManager.loadParticle("Spark"); for (var i = 0; i < number; i++) { var velocity = new Vector2(_rand.NextFloat(-100f, 100f), _rand.NextFloat(-100f, 100f)); var scale = new Vector2(_rand.Next(7, 12), _rand.Next(1, 2)); var color = ColorUtil.HSVToColor(MathHelper.ToRadians(51f), 0.5f, 0.91f); var state = new ParticleState() { Velocity = velocity, Type = ParticleType.Spark, UseCustomVelocity = true, VelocityMultiplier = 1f, Width = (int)scale.X, H = 57f }; SceneManager.Instance.ParticleManager.CreateParticle(texture, position, color, 200f, scale, state); } }
private void CreateParticle() { var texture = ImageManager.loadParticle("WhitePoint"); for (var i = 0; i < 20; i++) { var position = new Vector2(100, 100); var velocity = new Vector2(_rand.NextFloat(-100f, 100f), _rand.NextFloat(-500f, -300f)); var color = ColorUtil.HSVToColor(MathHelper.ToRadians(_rand.NextFloat(0, 359)), 0.6f, 1f); var scale = _rand.Next(0, 2) == 0 ? new Vector2(2, 2) : new Vector2(3, 3); var state = new ParticleState() { Velocity = velocity, Type = ParticleType.Confetti, Gravity = 1.8f, UseCustomVelocity = true, VelocityMultiplier = 0.95f }; SceneManager.Instance.ParticleManager.CreateParticle(texture, position, color, 1000f, scale, state); } }
// // Initialization function for a given simulation // parameters will be passed from the UI // public void Initialize(int width, int height, uint set_steps, uint set_num_walkers, double set_up_prob, double set_down_prob, double set_left_prob, double set_right_prob, int set_y_line, int set_x_line, int set_deposition_rate) { // Initializes the DLA grid. This is the same size as the display panel, // which is all we care about for the simulation. pixels = new bool[width, height]; // This initializes the list of random walkers // A list is used because we want to be able to delete a random walker // when it travels too far from the simulation, or attaches to the DLA // cluster (at which point we add a new one, so we could use an array, // but this seemed appropriate, since we never do random access.) walkers = new List<Walker>(); // Initialize the random number generator // (should move this into the constructor) rnd = new Random(); // parameters will be passed from the application UI panel_height = height; panel_width = width; number_of_steps = set_steps; // Set the current cluster state cluster_state = ParticleState.ALIVE; // Reset function handles the walker and other initialization Reset(set_num_walkers, set_up_prob, set_down_prob, set_left_prob, set_right_prob, set_y_line, set_x_line, set_deposition_rate); }
public void UpdateResultWithOtherNodes(ParticleState[] bestFrmOtherNodes) { foreach (var particleState in bestFrmOtherNodes) { if (particleState.Location == null) continue; _function.Evaluate(particleState.Location); } }
/// <summary> /// Updates the state of the game. This method checks the GameScreen.IsActive /// property, so the game will stop updating when the pause menu is active, /// or if you tab away to a different application. /// </summary> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, false); // Gradually fade in or out depending on whether we are covered by the pause screen. if (coveredByOtherScreen) pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1); else pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0); if (IsActive) { mouse = Mouse.GetState(); // bloom bloom.Visible = true; bloom.Settings = BloomSettings.PresetSettings[bloomSettingsIndex]; // update entites playerBody.update(gameTime); Grid.Update(); ParticleManager.Update(); Grid.ApplyExplosiveForce(5f, playerBody.playerBody.Position * 64, 80); foreach (playerLaser laser in playerBody.getLasers) { // Grid.ApplyExplosiveForce(5f, laser.laserBody.Position * 64, 50); // Grid.ApplyImplosiveForce(5f, laser.laserBody.Position * 64, 50); Grid.ApplyExplosiveForce(5f, laser.laserBody.Position * 64, 50); } if (playerBody.isAlive == false) { playerBody.isAlive = true; } foreach (SeekerDrone drone in Drones) { drone.setTarget(playerBody.playerBody.Position * 64); drone.update(gameTime); if (drone.getIsDead) { // if(!cam2D.getShake) cam2D.Shake(300f, 1000f); Grid.ApplyExplosiveForce(20f, drone.getBody.Position * 64, 1000); Random randP = new Random(); float hue1 = randP.NextFloat(0, 6); float hue2 = (hue1 + randP.NextFloat(0, 2)) % 6f; Color color1 = ColorUtil.HSVToColor(hue1, 0.5f, 1); Color color2 = ColorUtil.HSVToColor(hue2, 0.5f, 1); for (int i = 0; i < 120; i++) { float speed = 18f * (1f - 1 / randP.NextFloat(1f, 10f)); var state = new ParticleState() { Velocity = randP.NextVector2(speed, speed), Type = ParticleType.Enemy, LengthMultiplier = 1f }; Color color = Color.Lerp(color1, color2, randP.NextFloat(0, 1)); ParticleManager.CreateParticle(particleArt, drone.getBody.Position * 64f, color, 190, new Vector2(1.5f), state); } world.RemoveBody(drone.getBody); playerBody.updateScore(2); /// update this to a getter and setter!!! } } for (int k = 0; k < Drones.Count; ++k) { if (Drones[k].getIsDead) { Drones.RemoveAt(k); } } //game script foreach (Pickupable pickupable in Pickupables) { if (pickupable.getSetIsTouchingPlayer && playerBody.getSetWantsToPickUp && !playerBody.getSetHasPickedUp) { // joints.Add ( JointFactory.CreateRevoluteJoint(world,playerBody.playerBody, // pickupable.getBody, new Vector2(0,0))); Random randP = new Random(); float hue1 = randP.NextFloat(0, 6); float hue2 = (hue1 + randP.NextFloat(0, 2)) % 6f; Color color1 = ColorUtil.HSVToColor(hue1, 0.5f, 1); Color color2 = ColorUtil.HSVToColor(hue2, 0.5f, 1); for (int i = 0; i < 30; i++) { float speed = 18f * (1f - 1 / randP.NextFloat(1f, 10f)); var state = new ParticleState() { Velocity = randP.NextVector2(speed, speed), Type = ParticleType.Enemy, LengthMultiplier = 0.4f }; Color color = Color.Lerp(color1, color2, randP.NextFloat(0, 1)); ParticleManager.CreateParticle(particleArt, pickupable.getBody.Position * 64f, color, 190, new Vector2(1.5f), state); } joints.Add( JointFactory.CreateDistanceJoint(world, playerBody.playerBody, pickupable.getBody, new Vector2(0, 0), new Vector2(0, 0))); playerBody.getSetWantsToPickUp = false; pickupable.getSetIsAttachedToPlayer = true; playerBody.getSetHasPickedUp = true; } if (joints.Count > 0 && playerBody.getSetWantsTodrop && playerBody.getSetHasPickedUp && pickupable.getSetIsAttachedToPlayer ) { // for some reason the on seperation dosn't work when removing a joint. world.RemoveJoint(joints[0]); joints.RemoveAt(0); playerBody.getSetHasPickedUp = false; pickupable.getSetIsAttachedToPlayer = false; pickupable.getSetIsTouchingPlayer = false; } } // limts on the cam. cam2D.MaxRotation = 0.001f; cam2D.MinRotation = -0.001f; cam2D.MaxPosition = new Vector2(((playerBody.playerBody.Position.X) * 64 + 1), ((playerBody.playerBody.Position.Y) * 64) + 1); cam2D.MinPosition = new Vector2(((playerBody.playerBody.Position.X) * 64) + 2, ((playerBody.playerBody.Position.Y) * 64) + 1); cam2D.Update(gameTime); world.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f); } }
/// <summary> /// Handles input for quitting the game and cycling /// through the different particle effects. /// </summary> void HandleInput() { lastKeyboardState = currentKeyboardState; lastGamePadState = currentGamePadState; currentKeyboardState = Keyboard.GetState(); currentGamePadState = GamePad.GetState(PlayerIndex.One); // Check for exit. if (currentKeyboardState.IsKeyDown(Keys.Escape) || currentGamePadState.Buttons.Back == ButtonState.Pressed) { Exit(); } // Check for changing the active particle effect. if (((currentKeyboardState.IsKeyDown(Keys.Space) && (lastKeyboardState.IsKeyUp(Keys.Space))) || ((currentGamePadState.Buttons.A == ButtonState.Pressed)) && (lastGamePadState.Buttons.A == ButtonState.Released))) { currentState++; if (currentState > ParticleState.RingOfFire) currentState = 0; } }
public override void Init(ParticleState state, double[] velocity, DimensionBound[] bounds = null) { }
public void RestartState() { _bestKnownState = new ParticleState(new double[1], PsoServiceLocator.Instance.GetService<IOptimization<double[]>>().WorstValue(1)); }
public void UpdateBestState(ParticleState state) { BestKnownState = state; }
private void CreateGroundParticles(int num = 30) { var texture = ImageManager.loadParticle("GroundPiece"); for (var i = 0; i < num; i++) { var holeX = _holePoint.X + 16; var position = new Vector2(_rand.NextFloat(holeX - 5, holeX + 5), _holePoint.Y - GameMap.Instance.TileSize.Y); var velocity = new Vector2(_rand.NextFloat(-100f, 100f), _rand.NextFloat(-300f, -200f)); var scale = _rand.Next(0, 2) == 0 ? new Vector2(2, 2) : new Vector2(3, 3); var state = new ParticleState() { Velocity = velocity, Type = ParticleType.GroundPieces, Gravity = 3.3f }; SceneManager.Instance.ParticleManager.CreateParticle(texture, position, Color.White, 700f, scale, state); } }
public override void CreateGroundImpactParticles() { if (!_wheelMode) { base.CreateGroundImpactParticles(); return; } for (var i = 0; i < 6; i++) { var position = new Vector2(BoundingRectangle.Center.X, BoundingRectangle.Bottom); position.X += _rand.Next(-5, 5); var velocity = new Vector2(_rand.NextFloat(-5f, 5f), _rand.NextFloat(-1f, -3f)) * 3f; var size = new Vector2(_rand.NextFloat(5f, 7f), _rand.NextFloat(4f, 6f)); var state = new ParticleState() { Velocity = velocity, AlphaBase = _rand.NextFloat(0.2f, 0.6f), Type = ParticleType.Smoke }; SceneManager.Instance.ParticleManager.CreateParticle(ImageManager.loadParticle("Smoke"), position, Color.White, 1000f, size, state); } }
protected bool CheckMake() { if (state == ParticleState.Suspend) { state = ParticleState.Active; } return state != ParticleState.Inactive; }
public override void Init(ParticleState state, double[] velocity, DimensionBound[] bounds = null) { CurrentState = _proxy.GpuState; }
public Walker(int set_x, int set_y) { x = set_x; y = set_y; state = ParticleState.ALIVE; }
public void UpdateBestState(ParticleState state) { _particleService.UpdateBestState(state); }
public ParticleState StopCalculation() { var pState = new ParticleState(); Debug.WriteLine("{0}: received stop calculations", Info.Id); try { if (StopCalculations != null) pState = StopCalculations(); } catch (InvalidProgramException e) { Debug.WriteLine("{0}: received stop calculations but {1}", e.Message); return pState; } return pState; }
// Step function is called every timer tic // This function moves each walker randomly according // to the probabilities specified by the UI, if a // walker "bumps into" the DLA cluster that has // already been grown, that cell on the DLA cluser // becomes activated, and the walker is reinitialized public void Step() { // Test if the cluster method has returned as done, // and if so, tell the program the simulation is done if (cluster_state == ParticleState.COMPLETE) { current_state = ProgramState.DONE; } else { bool deposit = false; // If we haven't advanced far enough (according to whatever // ruleset we are using), then perform a standard walker step if (deposit_count < deposit_rate) { deposit = StepRandom(); } // Otherwise we need to update according to some ruleset else { deposit_count = 0; // This ruleset moves the genrating line upward once a certain // particle height has been achieved. if (step_method == StepMode.ADVANCE_Y) { generate_y -= 10; // If we've reached the top of the simulation, the cluster is done. if (generate_y < 50) { cluster_state = ParticleState.COMPLETE; SaveData(); } // Otherwise, move the walkers upwards else { for (int i = 0; i < number_of_walkers; i++) { InitializeWalker(walkers[i]); } } } // This ruleset moves the walkers on a vertical line from the right end // of the simulated region to the left else if (step_method == StepMode.ADVANCE_X) { generate_x -= 10; // if we're at the left edge, then the simulation is done if (generate_x < 50) { cluster_state = ParticleState.COMPLETE; SaveData(); } // otherwise, move left else { for (int i = 0; i < number_of_walkers; i++) { InitializeWalker(walkers[i]); } } } } // This boolean is true if the last step deposited a // particle onto the DLA cluster. Each ruleset has a // specific way of updating accordingly. if (deposit) { // If we're doing a horizontal line advancement, then // any deposition counts towards the total. if (step_method == StepMode.ADVANCE_X) { deposit_count++; last_deposit_x = deposit_x; } // If we're doing a vertical line advancement, then // we only update the deposition count if we achieve // a new maximum height. else if(step_method == StepMode.ADVANCE_Y) { if(deposit_y < last_deposit_y) { deposit_count++; last_deposit_y = deposit_y; } } // If we're depositing a horizontal line, then we're // done when the DLA cluster reaches the line (otherwise // we will end up with a solid line else if (step_method == StepMode.RANDOM_X_LINE) { if (deposit_y == (generate_y)) { cluster_state = ParticleState.COMPLETE; SaveData(); } } } } }
public virtual void Transpose(IFitnessFunction<double[], double[]> function) { double[] newLocation; var restart = _sinceLastImprovement == _iterationsToRestart; if (restart) { newLocation = RandomGenerator.GetInstance().RandomVector(CurrentState.Location.Length, Bounds); _sinceLastImprovement = 0; } else { newLocation = GetClampedLocation(CurrentState.Location.Select((x, i) => x + Velocity[i]).ToArray()); } var newVal = function.Evaluate(newLocation); var oldBest = PersonalBest; CurrentState = new ParticleState(newLocation, newVal); if (Optimization.IsBetter(newVal, PersonalBest.FitnessValue) < 0) { PersonalBest = CurrentState; _sinceLastImprovement = 0; } else { _sinceLastImprovement++; } }
private void CreateTileCrashParticles() { var texture = ImageManager.loadParticle("GroundPiece"); for (var i = 0; i < _rand.Next(4, 7); i++) { var position = new Vector2(_position.X, _position.Y); position.Y += _rand.NextFloat(0f, 3f); var velocity = new Vector2(_rand.NextFloat(130f, 150f) * -Math.Sign(_acceleration.X), _rand.NextFloat(-300f, 50f)); var scale = new Vector2(_rand.NextFloat(1f, 3f), _rand.NextFloat(1f, 3f)); var state = new ParticleState() { Velocity = velocity, Type = ParticleType.GroundPieces, Gravity = 3f }; SceneManager.Instance.ParticleManager.CreateParticle(texture, position, Color.White, 500f, scale, state); } }
/// <summary> /// Updates the state of the game. This method checks the GameScreen.IsActive /// property, so the game will stop updating when the pause menu is active, /// or if you tab away to a different application. /// </summary> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, false); // Gradually fade in or out depending on whether we are covered by the pause screen. if (coveredByOtherScreen) pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1); else pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0); if (IsActive) { mouse = Mouse.GetState(); // bloom bloom.Visible = true; bloom.Settings = BloomSettings.PresetSettings[bloomSettingsIndex]; // particles ParticleManager.Update(); // update entites playerBody.update(gameTime); foreach (Collectable star in Collectables) { if (star.collected) { playerBody.updateScore(2); world.RemoveBody(star.collectableBody); } } for (int k = 0; k < Collectables.Count; ++ k) { if (Collectables[k].collected) { Collectables.RemoveAt(k); } } foreach (SeekerDrone drone in Drones) { drone.setTarget(playerBody.playerBody.Position * 64); drone.update(gameTime); if (drone.getIsDead) { // if(!cam2D.getShake) cam2D.Shake(300f, 1000f); float hue1 = randP.NextFloat(0, 6); float hue2 = (hue1 + randP.NextFloat(0, 2)) % 6f; Color color1 = ColorUtil.HSVToColor(hue1, 0.5f, 1); Color color2 = ColorUtil.HSVToColor(hue2, 0.5f, 1); for (int i = 0; i < 120; i++) { float speed = 18f * (1f - 1 / randP.NextFloat(1f, 10f)); var state = new ParticleState() { Velocity = randP.NextVector2(speed, speed), Type = ParticleType.Enemy, LengthMultiplier = 1f }; Color color = Color.Lerp(color1, color2, randP.NextFloat(0, 1)); ParticleManager.CreateParticle(particleArt, drone.getBody.Position * 64f, color, 190, new Vector2( 1.5f), state); } world.RemoveBody(drone.getBody); playerBody.updateScore(2); /// update this to a getter and setter!!! } } for (int k = 0; k < Drones.Count; ++k) { if (Drones[k].getIsDead) { Drones.RemoveAt(k); } } foreach (Square square in Squares) { square.Update(); if (square.isTouching) { playerBody.isAlive = false; } } if (playerBody.isAlive == false) { bloom.Visible = false; world.Clear(); this.ExitScreen(); bloom.Visible = false; LoadingScreen.Load(ScreenManager, false, PlayerIndex.One, new DeadScreen(2)); } //game script if (playerBody.getScore() == 12 && Collectables.Count == 0) { Collectables.Add(new Collectable(content.Load<Texture2D>("redStar"), new Vector2(400, 400),world)); } if (playerBody.getScore() == 14) { ExitScreen(); bloom.Visible = false; LoadingScreen.Load(ScreenManager, false, PlayerIndex.One, new level3Screen()); } // limts on the cam. cam2D.MaxRotation = 0.001f; cam2D.MinRotation = -0.001f; cam2D.MaxPosition = new Vector2(((playerBody.playerBody.Position.X) * 64 + 1), ((playerBody.playerBody.Position.Y) * 64) + 1); cam2D.MinPosition = new Vector2(((playerBody.playerBody.Position.X) * 64) + 2, ((playerBody.playerBody.Position.Y) * 64) + 1); cam2D.Update(gameTime); world.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f); } }