Пример #1
0
        public GameState(bool isFirst = false)
        {
            this.Statistics = new GameStatistics();

            this.Level = new Level.Level(this, LevelGenerator.NewDefault.Silent);
            this.Level.GrowCrystals();

            this.Player = new Wisp(this, Vector2.Zero);

            this.Camera = new Camera(this.Player);

            this.musicSettings = new MusicSettingsHud(this);

            this.ChasingEnemies = new HashSet <Monster>();

            foreach (var tile in this.Level.Tilemap)
            {
                if (tile.Radius > 2 && tile.Info.Lightness < Settings.Game.Level.LightnessThreshold && GlobalRandom.NextBool(0.15))
                {
                    foreach (var i in Enumerable.Range(0, GlobalRandom.Next(1, 3)))
                    {
                        new Monster(this, this.Level.GetPosition(tile)
                                    + new Vector2(GlobalRandom.NextFloat(), GlobalRandom.NextFloat()) * 0.1f);
                    }
                }
            }

            this.titleEndTime = isFirst ? 3 : 0;
        }
Пример #2
0
        public override void Draw(SpriteManager sprites)
        {
            if (this.game.DrawDebug)
            {
                var v = this.game.Level.GetPosition(this.Tile);

                var geo = sprites.EmptyHexagon;
                geo.Color = new Color(Color.Green, 0);
                geo.DrawSprite(v, 0, Settings.Game.Level.HexagonDiameter);
            }

            this.particles.Draw(sprites);

            var healthPercentage = this.HealthPercentage;

            var light = GlobalRandom.NextFloat(healthPercentage * healthPercentage, healthPercentage);

            sprites.PointLight.Draw(this.position.WithZ(1.5f), Color.LightYellow, 1f, 5 + 10 * light);


            var blink = sprites.Blink;

            blink.Color = Color.LightYellow.WithAlpha(0.5f) * 0.3f;
            blink.DrawSprite(this.position.WithZ(1.5f), 0, 1 + light * 2);
        }
Пример #3
0
        /// <summary>
        /// Fires the weapon
        /// </summary>
        public override void Fire()
        {
            var facingRightFactor = this.Mech.IsFacingRight ? 1 : -1;

            // Set overriding animation
            this.Animatable.PlayClip("fire", 1, true);
            this.EquippedOnArm.PlayClip(this.ArmAnimationClipName, 1, true);

            // Set shoot pellet count
            int   shootCount = (int)this.PelletCount;
            float diff       = this.PelletCount - shootCount;

            if (GlobalRandom.NextFloat() < diff)
            {
                shootCount++;
            }

            // Camera shake
            MainCamera.CurrentInstance.Shake(this.ScreenShake);

            // Adjust knock back
            var hitX        = this.BaseHit.KnockBack.x * facingRightFactor;
            var adjustedHit = new WeaponHitStat(this.BaseHit);

            adjustedHit.KnockBack = new Vector2(hitX, this.BaseHit.KnockBack.y);

            // Apply recoil
            var recoilX = -this.BaseStats.Recoil * facingRightFactor;

            this.Mech.ApplyKnockback(new Vector2(recoilX, 0), this.BaseStats.Recoil, 0);

            // Fire  all pellets
            for (int shoot = 0; shoot < shootCount; shoot++)
            {
                // Determine inaccuracy
                var inaccuracy = (100 - this.BaseStats.Accuracy) / 200 * GlobalRandom.NextFloat() * Mathf.PI;
                if (GlobalRandom.NextBool())
                {
                    inaccuracy *= -1;
                }

                var shootX = Mathf.Cos(inaccuracy) * facingRightFactor;
                var shootY = Mathf.Sin(inaccuracy);

                var rayCastHits = Physics2D.RaycastAll(this.MuzzleLocation.transform.position, new Vector2(shootX, shootY));
                for (var i = 0; i < rayCastHits.Length; i++)
                {
                    var curHit   = rayCastHits[i];
                    var hittable = curHit.collider.GetComponent <IHittable>();
                    if (hittable != null && hittable.Faction != adjustedHit.Faction)
                    {
                        hittable.OnHit(adjustedHit);
                        var newBullet = Instantiate(this.BulletLinePrefab);
                        newBullet.OnBulletHit(this.MuzzleLocation.transform.position, curHit);
                        break;
                    }
                }
            }
        }
Пример #4
0
 private Particle makeParticle()
 {
     return(new Particle(this.game, this.parent,
                         GameMath.Vector3FromRotation(GlobalRandom.Angle(), GlobalRandom.Angle(), this.size)
                         * new Vector3(1, 1, 0.5f),
                         new Vector3(),
                         color, GlobalRandom.NextFloat(0.8f, 1.2f) * this.size));
 }
Пример #5
0
        public Crystal(GameState game, Vector2 position)
            : base(game, position, 0)
        {
            var tileLight = this.Tile.Info.Lightness;

            this.range = (0.5f + tileLight) * GlobalRandom.NextFloat(8, 9);

            this.color = Color.FromHSVA(GlobalRandom.NextFloat(0.6f, 0.8f) * GameMath.TwoPi, 0.1f, 1f);
        }
Пример #6
0
        public Wisp(GameState game, Vector2 position)
            : base(game, position, Settings.Game.Wisp.FrictionCoefficient)
        {
            this.controls = new ControlScheme();

            this.health        = Settings.Game.Wisp.MaxHealth;
            this.healStartTime = -1000;

            this.particles = new ParticleCloud(game, 50, this,
                                               Color.LightYellow.WithAlpha(0.5f) * GlobalRandom.NextFloat(0.03f, 0.1f), 10, 0.6f);
        }
Пример #7
0
        public void Update(GameUpdateEventArgs e)
        {
            var detachCount = randomCount(this.turnOverRate * e.ElapsedTimeF);

            for (int j = 0; j < detachCount; j++)
            {
                var i = GlobalRandom.Next(particles.Count);

                this.particles[i].DetachFromParent();
                this.particles[i].FadeAway(GlobalRandom.NextFloat(0.2f, 1f));

                this.particles[i] = this.makeParticle();
            }
        }
Пример #8
0
        /// <summary>
        /// Called when the weapon is fired
        /// </summary>
        /// <returns>nothing in this case</returns>
        protected override GameObject OnFire()
        {
            var curFacing = this.transform.eulerAngles.z;
            var muzzlePos = this.MuzzleLocation.transform.position;

            // Fire a bunch
            for (int i = 0; i < this.FireCount; i++)
            {
                // Gets the angle diff based on random inaccuracy
                var degAngleDiff = GlobalRandom.NextFloat()
                                   * this.Inaccuracy
                                   * (GlobalRandom.random.Next(2) == 0 ? 1 : -1);

                // Where to fire
                var fireAngleRad = (curFacing + degAngleDiff) * Mathf.Deg2Rad;
                var allValidHits = Physics2D.RaycastAll(
                    muzzlePos,
                    new Vector2(Mathf.Cos(fireAngleRad), Mathf.Sin(fireAngleRad))
                    )
                                   .Where(hit => hit.collider.GetComponent <IHittable>() != null)
                                   .ToList();

                if (!this.DoesPenetrate)
                {
                    allValidHits = new List <RaycastHit2D>()
                    {
                        allValidHits.First()
                    };
                }

                // If we hit anything
                if (allValidHits.Count > 0)
                {
                    // Deal damage
                    foreach (var validHit in allValidHits)
                    {
                        validHit.collider.GetComponent <IHittable>().OnHit(this.Damage, this.EffectImpacts);
                    }

                    // Draw line
                    var newLine = Instantiate(this.BulletLiniePrefab);
                    newLine.DrawHit(muzzlePos, allValidHits);
                }
            }

            return(null);
        }
Пример #9
0
        public void Explode(float percentage, Vector3 impulse, float randomImpulse)
        {
            var detachCount = randomCount(this.particles.Count * percentage);

            for (int j = 0; j < detachCount; j++)
            {
                var i = GlobalRandom.Next(particles.Count);

                var oldParticle = this.particles[i];

                oldParticle.DetachFromParent();
                oldParticle.FadeAway(GlobalRandom.NextFloat(0.2f, 0.5f));
                oldParticle.Push(impulse +
                                 GameMath.Vector2FromRotation(GlobalRandom.Angle(),
                                                              GlobalRandom.NextFloat(randomImpulse)).WithZ(0));

                this.particles[i] = this.makeParticle();
            }
        }
Пример #10
0
        public void GrowCrystals()
        {
            foreach (var tile in this.tilemap)
            {
                var tilePosition = this.GetPosition(tile);

                var crystalCount = (int)(tile.Info.Lightness * 2 * GlobalRandom.NextFloat(4, 5.5f));

                for (int i = 0; i < crystalCount; i++)
                {
                    var dir      = GameMath.Vector2FromRotation(GlobalRandom.Angle(), Settings.Game.Level.HexagonSide);
                    var result   = tile.Info.ShootRay(new Ray(Vector2.Zero, dir));
                    var position = result.Hit
                        ? result.Point * GlobalRandom.NextFloat(0.8f, 0.9f)
                        : dir *GlobalRandom.NextFloat(0.3f, 0.8f);

                    new Crystal(game, tilePosition + position);
                }
            }
        }
 public Neuron()
 {
     a = GlobalRandom.NextFloat();
     b = GlobalRandom.NextFloat();
     c = GlobalRandom.NextFloat();
 }
Пример #12
0
 public void FadeAway(float delay)
 {
     this.fadeOutStart  = this.game.Time + delay;
     this.fadeOutFactor = GlobalRandom.NextFloat(1, 3);
 }
Пример #13
0
 public static bool OpenTileWall(this Tile <GeneratingTileInfo> tile, Direction direction, float minOpen, float maxOpen)
 {
     return(tile.OpenTileWall(direction, GlobalRandom.NextFloat(minOpen, maxOpen)));
 }
Пример #14
0
        public override void Update(GameUpdateEventArgs e)
        {
            var toPlayer         = this.game.Player.Position - this.position;
            var toPlayerDSquared = toPlayer.LengthSquared;

            #region check player visibility
            if (this.nextVisibleCheck == 0)
            {
                this.nextVisibleCheck = this.game.Time +
                                        GlobalRandom.NextFloat(Settings.Game.Enemy.MinScanInterval, Settings.Game.Enemy.MaxScanInterval);
            }
            if (this.nextVisibleCheck < this.game.Time)
            {
                this.nextVisibleCheck = 0;
                if (toPlayerDSquared < Settings.Game.Enemy.ViewDistanceSquared)
                {
                    var result = this.game.Level.ShootRay(new Ray(this.position, toPlayer), this.Tile);
                    this.seesPlayer = !result.Results.Hit;

                    if (game.DrawDebug)
                    {
                        var lines = SpriteManager.Instance.Lines;
                        lines.Color     = result.Results.Hit ? Color.Red : Color.Green;
                        lines.LineWidth = 0.2f;
                        lines.DrawLine(this.position, result.GlobalPoint);
                    }
                }
                else
                {
                    this.seesPlayer = false;
                }
            }

            if (this.seesPlayer)
            {
                if (!this.chasing)
                {
                    this.game.ChasingEnemies.Add(this);
                    this.chasing = true;
                }
                this.lastKnownPlayerPosition = this.game.Player.Position;
                this.losePlayerTime          = this.game.Time + 1;
            }

            if (this.chasing && this.losePlayerTime < this.game.Time)
            {
                this.game.ChasingEnemies.Remove(this);
                this.chasing = false;
            }
            #endregion

            #region chase
            if (this.chasing)
            {
                var toKnownPlayerPosition = this.lastKnownPlayerPosition - this.position;
                this.velocity += toKnownPlayerPosition.Normalized()
                                 * Settings.Game.Enemy.Acceleration * e.ElapsedTimeF;
            }
            #endregion

            #region monster-monster collision
            foreach (var monster in this.Tile.Info.Monsters)
            {
                if (monster == this)
                {
                    continue;
                }
                var diff     = monster.position - this.position;
                var dSquared = diff.LengthSquared;
                if (dSquared == 0)
                {
                    continue;
                }
                const float radius = 1f;
                if (dSquared < radius * radius)
                {
                    var d          = (float)Math.Sqrt(dSquared);
                    var normalDiff = diff / d;
                    var f          = radius - d;
                    f             *= f;
                    this.velocity -= 100 * normalDiff * f * e.ElapsedTimeF;

                    if (this.game.DrawDebug)
                    {
                        var lines = SpriteManager.Instance.Lines;
                        lines.Color     = Color.Red;
                        lines.LineWidth = 0.1f;
                        lines.DrawLine(this.position, this.position + diff / d);
                    }
                }
            }
            #endregion

            #region fear of light
            foreach (var tile in this.Tile.Info.OpenSides.Enumerate()
                     .Select(d => this.Tile.Neighbour(d)).Append(this.Tile))
            {
                var info = tile.Info;

                if (info.Lightness > 0.2)
                {
                    var tilePosition = this.game.Level.GetPosition(tile);

                    var         diff   = tilePosition - this.position;
                    var         d      = diff.Length;
                    const float radius = Settings.Game.Level.HexagonSide * 1.1f;
                    if (d < radius)
                    {
                        var normalDiff = diff / d;
                        var f          = radius - d;
                        f             *= f;
                        this.velocity -= 100 * normalDiff * f * e.ElapsedTimeF;
                    }
                }
            }
            #endregion

            #region bite
            if (this.waitingToBite)
            {
                if (this.biteNextFrame)
                {
                    var toPlayerNormal = toPlayer.Normalized();

                    this.game.Player.Damage(Settings.Game.Enemy.HitDamage, toPlayerNormal);

                    this.velocity *= 0.1f;
                    this.velocity += toPlayerNormal * 5;
                    this.particles.Explode(0.6f, toPlayerNormal.WithZ(0) * 10, 1);


                    this.nextHitTime   = this.game.Time + Settings.Game.Enemy.HitInterval;
                    this.biteNextFrame = false;
                    this.waitingToBite = false;
                }
                else
                {
                    if (toPlayerDSquared > Settings.Game.Enemy.HitDistanceSquared)
                    {
                        this.waitingToBite = false;
                    }
                }
            }

            if (!this.waitingToBite &&
                this.nextHitTime <= this.game.Time &&
                toPlayerDSquared < Settings.Game.Enemy.HitDistanceSquared)
            {
                //this.game.Player.Damage(Settings.Game.Enemy.HitDamage);
                //this.nextHitTime = this.game.Time + Settings.Game.Enemy.HitInterval;
                this.scheduleBite();
            }
            #endregion

            #region blinking
            if (this.nextBlinkToggle < this.game.Time)
            {
                this.blinking = !this.blinking;
                if (this.blinking)
                {
                    this.nextBlinkToggle = this.game.Time +
                                           (GlobalRandom.NextBool(0.1f) ? GlobalRandom.NextFloat(0.1f, 1f) :
                                            GlobalRandom.NextFloat(0.1f, 0.2f));
                }
                else
                {
                    this.nextBlinkToggle = this.game.Time +
                                           (GlobalRandom.NextBool(0.2f) ? GlobalRandom.NextFloat(0.2f, 0.4f) :
                                            GlobalRandom.NextFloat(1, 10));
                }
            }
            #endregion

            if (toPlayerDSquared < Settings.Game.Enemy.ContributeToTensionDistanceSquared)
            {
                this.game.MonstersCloseToPlayer++;
            }

            base.Update(e);

            this.particles.Update(e);
        }