Beispiel #1
0
        protected override void Update(GameTime gameTime)
        {
            KeyboardState kb = Keyboard.GetState();

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || kb.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (kb.IsKeyDown(Keys.F11))
            {
                ToggleFullscreen();
            }

            if (gameTime.TotalGameTime.Subtract(_previousMove).TotalMilliseconds > 200 &&
                (kb.IsKeyDown(Keys.Left) || kb.IsKeyDown(Keys.Right) || kb.IsKeyDown(Keys.Up) || kb.IsKeyDown(Keys.Down)))
            {
                _player.Move(kb, _currentLevel);
                _previousMove = gameTime.TotalGameTime;
            }

            if (kb.IsKeyDown(Keys.Space) && gameTime.TotalGameTime.Subtract(_previousPress).TotalMilliseconds > 200)
            {
                LevelUpdater.ButtonUpdateLevel(_player, _currentLevel);
                _previousPress = gameTime.TotalGameTime;
            }
            base.Update(gameTime);
        }
        public virtual void Initialize()
        {
            this.castPointUpdate = new LevelUpdater <IAbilitySkill, double>(
                this.Skill,
                () => this.Skill.SourceAbility.FindCastPoint());
            this.speedUpdate = new LevelUpdater <IAbilitySkill, float>(
                this.Skill,
                () => this.Skill.SourceAbility.GetProjectileSpeed());
            this.castRangeUpdate = new LevelUpdater <IAbilitySkill, float>(
                this.Skill,
                () => this.Skill.SourceAbility.GetCastRange());

            this.manaObserver =
                new DataObserver <IMana>(
                    mana => { this.EnoughMana = mana.Current >= this.Skill.SourceAbility.ManaCost; });
            this.manaObserver.Subscribe(this.Skill.Owner.Mana);

            if (this.Skill.Cooldown != null)
            {
                this.cooldownObserver = new DataObserver <ICooldown>(
                    cooldown =>
                {
                    this.Cooldown     = cooldown.Current;
                    this.IsOnCooldown = this.Cooldown > 0;
                });
                this.cooldownObserver.Subscribe(this.Skill.Cooldown);
            }
        }
Beispiel #3
0
        public virtual void Initialize()
        {
            this.castPointUpdate = new LevelUpdater <IAbilitySkill, double>(
                this.Skill,
                () => Math.Max(this.Skill.SourceAbility.FindCastPoint(), 0.1));
            this.speedUpdate = new LevelUpdater <IAbilitySkill, float>(
                this.Skill,
                () => this.Skill.SourceAbility.GetProjectileSpeed());
            var manaSub = false;

            if (this.Skill.SourceAbility.ManaCost > 0)
            {
                manaSub           = true;
                this.manaObserver = new DataObserver <IMana>(
                    mana =>
                {
                    if (this.Skill.SourceAbility.IsValid)
                    {
                        this.EnoughMana = mana.Current > this.Skill.SourceAbility.ManaCost;
                    }
                    else
                    {
                        Console.WriteLine(
                            "SkillCastData: receiving mana data for invalid skill " + this.Skill.Name);
                    }
                });
                this.manaObserver.Subscribe(this.Skill.Owner.Mana);
            }
            else
            {
                DataObserver <ISkillLevel> levelObserver = null;
                levelObserver = new DataObserver <ISkillLevel>(
                    level =>
                {
                    if (manaSub)
                    {
                        return;
                    }

                    if (this.Skill.SourceAbility.ManaCost > 0)
                    {
                        manaSub           = true;
                        this.manaObserver = new DataObserver <IMana>(
                            mana =>
                        {
                            if (this.Skill.SourceAbility.IsValid)
                            {
                                this.EnoughMana = mana.Current > this.Skill.SourceAbility.ManaCost;
                            }
                            else
                            {
                                Console.WriteLine(
                                    "SkillCastData: receiving mana data for invalid skill "
                                    + this.Skill.Name);
                            }
                        });
                        this.manaObserver.Subscribe(this.Skill.Owner.Mana);
                    }
                });
                levelObserver.Subscribe(this.Skill.Level);
            }

            if (this.Skill.Cooldown != null)
            {
                this.cooldownObserver = new DataObserver <ICooldown>(
                    cooldown =>
                {
                    this.Cooldown     = cooldown.Current;
                    this.IsOnCooldown = this.Cooldown > 0;
                });
                this.cooldownObserver.Subscribe(this.Skill.Cooldown);
            }
        }
Beispiel #4
0
 private void Awake()
 {
     INSTANCE = this;
 }