public void TakeDamage(float damage) { Health = Utilities.Clamp(Health - damage, 0f, MaxHealth); if (Health == 0) { int deathAnimID = RandomGen.NextInt(1, 2); ChangeAnimationTo(Animations.BasicEnemy["death0" + deathAnimID], false); Animation.StopOnLastFrame = true; Animation.Played += new Action(StopAttacking); //Create a shower of blood //int bloodAnimID = RandomGen.NextInt(1, 2); GameObject bloodSplash = new GameObject(128.0, 128.0); bloodSplash.Position = Position; //bloodSplash.Animation = Animations.Blood["Blood0" + bloodAnimID]; bloodSplash.Animation = Animations.Blood["Blood01"]; CurrentPlayer.CurrentGame.Add(bloodSplash); bloodSplash.Animation.Start(1); bloodSplash.Animation.StopOnLastFrame = true; //Create an expanding pool of blood int bloodPoolID = RandomGen.NextInt(1, 2); BloodPool blood = new BloodPool(1.0, 1.0); blood.Position = Position + MoveTarget * 48.0; blood.Angle = RandomGen.NextAngle(); blood.Image = Game.LoadImage("Textures/Blood/blood0" + bloodPoolID); CurrentPlayer.CurrentGame.BloodPools.Add(blood); CurrentPlayer.CurrentGame.Add(blood, 0); Died(damage, MaxHealth); } }
/// <summary> /// Kutsutaan, kun tapahtuu törmäys. /// </summary> /// <param name="target">Olio, johon törmätään.</param> public override void OnCollision(IGameObject target) { Vector d = target.Position - Owner.Position; Angle n1 = d.Angle - Angle.RightAngle; Angle n2 = d.Angle + Angle.RightAngle; currentDirection = RandomGen.NextAngle(n1, n2); base.OnCollision(target); }
void Sparkle() { PhysicsObject sparkle = new PhysicsObject(3, 1); sparkle.Position = Mouse.PositionOnWorld; //sparkle.IgnoresCollisionResponse = true; sparkle.IgnoresGravity = true; sparkle.Angle = RandomGen.NextAngle(); sparkle.Color = RandomGen.NextColor(Color.LightYellow, Color.Yellow); sparkle.MaximumLifetime = RandomGen.NextTimeSpan(0.1, 2); Add(sparkle); double force = RandomGen.NextDouble(100, 200); sparkle.Hit(Vector.FromLengthAndAngle(force, sparkle.Angle)); }
int generoi5() { tahtilista = new List <PhysicsObject>(); Vector alkupiste = pallo1.Position; Angle suunta1 = RandomGen.NextAngle(); Vector tp = alkupiste; for (int i = 0; i < 80; i++) { if (i % KAANTOVALI < 6) { Angle känsä = RandomGen.NextAngle( Angle.FromDegrees(-KAANTOKULMA - 45), Angle.FromDegrees(KAANTOKULMA + 45)); suunta1 = känsä; } Vector vp = Vector.FromLengthAndAngle(94, suunta1); tp = tp + vp; Vector newtp = new Vector(tp.X, tp.Y); Timer.SingleShot(1.7 + PALLONTEKONOPEUS * i * 4, () => luotahti(newtp, Color.Red)); } return(80); }
int generoi1() { tahtilista = new List <PhysicsObject>(); Vector alkupiste = pallo1.Position; Angle suunta1 = RandomGen.NextAngle(); Vector tp = alkupiste; for (int i = 0; i < 50; i++) { if (i % KAANTOVALI == 0) { Angle känsä = RandomGen.NextAngle( Angle.FromDegrees(-KAANTOKULMA), Angle.FromDegrees(KAANTOKULMA)); suunta1 = känsä; } Vector vp = Vector.FromLengthAndAngle(70, suunta1); tp = tp + vp; Vector newtp = new Vector(tp.X, tp.Y); Timer.SingleShot(2.0 + PALLONTEKONOPEUS * i, () => luotahti(newtp, RandomGen.NextColor())); } return(50); }
void ChangeDirection() { currentDirection = RandomGen.NextAngle(); }
/// <summary> /// Luodaan peikkoja kentälle satunnaisiin paikkoihin /// </summary> private void LuoPeikko() { for (int i = 0; i < PEIKKOJENMAARA; i++) { double x = RandomGen.NextDouble(Level.Left, Level.Right); double y = RandomGen.NextDouble(Level.Bottom, Level.Top); PhysicsObject peikko = Olio(this, PEIKONLEVEYS, PEIKONKORKEUS, x, y, "peikko", true, true, false, 0, "peikko", Color.Transparent, Shape.Rectangle, true); Add(peikko); //Tehdään ´peikolle polkuaivot PathFollowerBrain peikonAivot = new PathFollowerBrain(200); peikko.Brain = peikonAivot; List <Vector> polku = new List <Vector>(); polku.Add(Vector.FromLengthAndAngle(RandomGen.NextDouble(Screen.Top * 2, Screen.Top * 3), RandomGen.NextAngle())); peikonAivot.Path = polku; peikonAivot.Loop = true; peikonAivot.Speed = 250; } }