Example #1
0
        public void PlayerShoots(MapEntity target)
        {
            var damage = DamageCalculator.CalculateDamage(this.Player, target);

            this.HarmAlien(target, damage);
            this.OnPlayerMoved();
        }
Example #2
0
        private void HarmAlien(MapEntity target, int damage)
        {
            target.CurrentHealth -= damage;
            this.eventBus.Broadcast(SpaceMarineEvent.ShowMessage, $"{target.Name} take(s) {damage} damage! {(target.CurrentHealth <= 0 ? "It dies!" : "")}");

            if (target.CurrentHealth <= 0)
            {
                this.OnAlienDied(target);
            }
        }
Example #3
0
 private void OnAlienDied(MapEntity alien)
 {
     if (this.Aliens.Contains(alien))
     {
         this.Aliens.Remove(alien);
         SaveData.Instance.Currency++;
         if (!this.Aliens.Any())
         {
             this.IncrementWave();
         }
     }
 }
Example #4
0
        public void TryToMove(MapEntity entity, int deltaX, int deltaY)
        {
            if (gameOver)
            {
                return;
            }

            var destinationX = entity.TileX + deltaX;
            var destinationY = entity.TileY + deltaY;

            if (destinationX < 0 || destinationX >= this.width || destinationY < 0 || destinationY >= this.height ||
                !this.isWalkable[destinationX, destinationY])
            {
                return;
            }

            if (this.Plasma[new Tuple <int, int>(destinationX, destinationY)] > 0)
            {
                this.PlasmaDamage(entity);
            }

            if (this.Aliens.Any(m => m.TileX == destinationX && m.TileY == destinationY))
            {
                var target = this.Aliens.Single(m => m.TileX == destinationX && m.TileY == destinationY);
                var damage = DamageCalculator.CalculateDamage(entity, target);
                this.HarmAlien(target, damage);
            }
            else if (this.Player.TileX == destinationX && this.Player.TileY == destinationY)
            {
                var damage = DamageCalculator.CalculateDamage(entity, this.Player);
                this.Player.CurrentHealth -= damage;
                this.eventBus.Broadcast(SpaceMarineEvent.ShowMessage, $"Alien hits you for {damage} damage! {(this.Player.CurrentHealth <= 0 ? "YOU DIE!" : "")}");

                if (this.Player.CurrentHealth <= 0)
                {
                    this.gameOver = true;
                }
            }
            else
            {
                // It's clear, so move.
                entity.TileX = destinationX;
                entity.TileY = destinationY;
            }

            if (entity == Player)
            {
                this.OnPlayerMoved();
            }
        }
Example #5
0
 private void PlasmaDamage(MapEntity entity)
 {
     // Only applies to player, sorry bruh
     if (entity == this.Player)
     {
         var damage = (int)(PLASMA_DAMAGE_PERCENT * entity.TotalHealth);
         entity.CurrentHealth -= damage;
         this.eventBus.Broadcast(SpaceMarineEvent.ShowMessage, $"{entity.Name} burn on plasma!");
         if (entity.CurrentHealth <= 0)
         {
             this.gameOver = true;
         }
     }
 }
Example #6
0
        public PlanetoidMap(EventBus eventBus)
        {
            this.eventBus   = eventBus;
            this.width      = Constants.MAP_TILES_WIDE;
            this.height     = Constants.MAP_TILES_HIGH;
            this.isWalkable = new ArrayMap <bool>(Constants.MAP_TILES_WIDE, Constants.MAP_TILES_HIGH);
            this.Player     = new MapEntity("You", PLAYER_STARTING_HEALTH, PLAYER_STRENGTH, PLAYER_DEFENSE, this.width / 2, this.height / 2);

            this.GenerateMap();

            for (var y = 0; y < this.height; y++)
            {
                for (var x = 0; x < this.width; x++)
                {
                    this.Plasma[new Tuple <int, int>(x, y)] = 0;
                }
            }

            this.IncrementWave();
        }
Example #7
0
        // For aliens: figure out how to move toward target
        public Tuple <int, int> Stalk(MapEntity target)
        {
            var dx             = target.TileX - this.TileX;
            var dy             = target.TileY - this.TileY;
            var potentialMoves = new List <Tuple <int, int> >();

            if (dx != 0)
            {
                potentialMoves.Add(new Tuple <int, int>(Math.Sign(dx), 0));
            }
            if (dy != 0)
            {
                potentialMoves.Add(new Tuple <int, int>(0, Math.Sign(dy)));
            }

            if (potentialMoves.Any())
            {
                return(potentialMoves[random.Next(potentialMoves.Count)]);
            }
            else
            {
                return(new Tuple <int, int>(0, 0));
            }
        }