Example #1
0
        /// <summary>
        /// Expose the main entry point of the rendering loop of the game.
        /// </summary>
        /// <param name="dt">Time passed since the last call of the rendering loop (in ms)</param>
        public override void enterFrame(double dt)
        {
            base.enterFrame(dt);

            /// if the player object is in movement, shift its position accordingly until it reaches its destination
            if (_currState == HunterActionStates.ISMOVING)
            {
                if (_moveTo.X > 0)
                {
                    Point pt = new Point(SPEED * dt, Position.Y);
                    pt.X      = Math.Min(_moveTo.X, pt.X);
                    Position  = new Point(Position.X + pt.X * _moveTo.Y, Position.Y);
                    _moveTo.X = _moveTo.X - pt.X;
                }
                else
                {
                    _currState = HunterActionStates.ISRESTING;
                    _moveTo    = new Point(0, 0);
                    // TreasureApplicationManager.Instance;

                    (TreasureApplicationManager.Instance as TreasureApplicationManager).changeExposure();
                    (TreasureApplicationManager.Instance as TreasureApplicationManager).UpdateSound(-1);
                }
            }

            if (!StateManager.Instance.CurrentState.Equals(TreasureStates.LEVEL_STATE))
            {
                return;
            }
            if (TreasureApplicationManager.PREVENT_AUDIO_CHANGES)
            {
                KeyHandler.Instance.clearKeyPresses();
                return;
            }

            //timeSinceLastShot -= dt;
            if (KeyHandler.Instance.isKeyPressed(Key.Space) && timeSinceLastShot <= 0 && _currState == HunterActionStates.ISRESTING)
            {
                TreasureApplicationManager.PREVENT_AUDIO_CHANGES = true;
                TreasureOptions.Instance.User.Actions++;
                TreasureOptions.Instance.User.CurrentLife--;
                (TreasureApplicationManager.Instance as TreasureApplicationManager)._scorePanel.Life = TreasureOptions.Instance.User.CurrentLife;
                timeSinceLastShot = TIME_BETWEEN_SHOTS;
                HunterWeapon weapon = HunterWeapon.UnusedWeapon.startupPlayerBasicWeapon(this);
                weapon.Position = new Point(Position.X + dimensions.X / 2 - weapon.Dimensions.X / 2, Position.Y + dimensions.Y - weapon.Dimensions.Y);
            }

            else if (KeyHandler.Instance.isKeyPressed(Key.Left))
            {
                if (_currState == HunterActionStates.ISRESTING)
                {
                    this.CurrentZone--;
                    TreasureOptions.Instance.User.Actions++;
                    if (this.CurrentZone < 0)
                    {
                        this.CurrentZone = 0;
                    }
                    else
                    {
                        _moveTo    = new Point(TreasureOptions.Instance.Game._sizeZones, -1);
                        _currState = HunterActionStates.ISMOVING;
                        (TreasureApplicationManager.Instance as TreasureApplicationManager)._synthEx.Stop();
                    }
                }
            }
            else if (KeyHandler.Instance.isKeyPressed(Key.Right))
            {
                if (_currState == HunterActionStates.ISRESTING)
                {
                    this.CurrentZone++;
                    TreasureOptions.Instance.User.Actions++;
                    if (this.CurrentZone > (TreasureOptions.Instance.Game.Zones - 1))
                    {
                        this.CurrentZone = (TreasureOptions.Instance.Game.Zones - 1);
                    }
                    else
                    {
                        _moveTo    = new Point(TreasureOptions.Instance.Game._sizeZones, 1);
                        _currState = HunterActionStates.ISMOVING;
                        (TreasureApplicationManager.Instance as TreasureApplicationManager)._synthEx.Stop();
                    }
                }
            }

            else if (KeyHandler.Instance.isKeyPressed(Key.Down))
            {
                TreasureOptions.Instance.User.Actions++;
                (TreasureApplicationManager.Instance as TreasureApplicationManager).UpdateSound(-1);
                (TreasureApplicationManager.Instance as TreasureApplicationManager).myLogger.logRequestStimuli();
            }
        }
        public override void collision(GameObject other)
        {
            base.collision(other);

            int oldScore = 0;

            double l = (TreasureApplicationManager.Instance as TreasureApplicationManager)._synthEx.Left;
            double m = (TreasureApplicationManager.Instance as TreasureApplicationManager)._synthEx.Middle;
            double r = (TreasureApplicationManager.Instance as TreasureApplicationManager)._synthEx.Right;

            (TreasureApplicationManager.Instance as TreasureApplicationManager).myLogger.logHitNugget((int)this.Type, this.Depth, this.Score, l, m, r);

            if (this.Type != TreasureType.TREASURE_NONE)
            {
                // Show explosion animation
                AnimatedGameObject.UnusedAnimatedGameObject.startupAnimatedGameObject(
                    new Point(55, 55),
                    new AnimationData(
                        new string[] {
                    "Media/Explosion1.png",
                    "Media/Explosion2.png",
                    "Media/Explosion3.png",
                    "Media/Explosion4.png",
                    "Media/Explosion5.png",
                    "Media/Explosion6.png",
                    "Media/Explosion7.png"
                },
                        20),
                    ZLayers.PLAYER_Z,
                    true).Position = new Point(
                    Position.X + Dimensions.X / 2 - 55 / 2,
                    Position.Y + Dimensions.Y / 2 - 55 / 2);

                TreasureApplicationManager.Instance.Score += Score;
                string newString = TreasureOptions.Instance.Game._curSetup.Substring(0, this.Index) + "0" + TreasureOptions.Instance.Game._curSetup.Substring(this.Index + 1);
                TreasureOptions.Instance.Game._curSetup = newString;
                if (this.Type == TreasureType.TREASURE_GOLD)
                {
                    TreasureOptions.Instance.Game._curGold--;
                    TreasureOptions.Instance.User.CurrentGold++;
                    TreasureOptions.Instance.User.CurrentScore += this.Score;
                    (TreasureApplicationManager.Instance as TreasureApplicationManager)._scorePanel.Gold  = TreasureOptions.Instance.Game._curGold;
                    (TreasureApplicationManager.Instance as TreasureApplicationManager)._scorePanel.Score = TreasureOptions.Instance.User.CurrentScore;
                }

                // Change visibility and initiate exposure animation
                this.Visibility        = System.Windows.Visibility.Visible;
                this.timeSinceExposure = TreasureNugget.TIME_EXPOSURE;
                animationData.fps      = 5;
                animationData.frames   = new string[] {
                    "Media/hole1.png",
                    this.Type == TreasureType.TREASURE_GOLD ? "Media/gold1.png" : "Media/metal1.png"
                };
                currentFrame = 0;
                oldScore     = this.Score;
                this.Score   = 0;
                prepareImage(animationData.frames[currentFrame]);
                // (TreasureApplicationManager.Instance as TreasureApplicationManager).changeExposure();
            }
            HunterWeapon tt   = other as HunterWeapon;
            ScoreObject  tttt = ScoreObject.UnusedScore.startupGameObject((tt != null) ? tt._player : null, oldScore);

            tttt.Position = new Point(
                Position.X + Dimensions.X / 2 - 55 / 2,
                Position.Y + Dimensions.Y / 2 - 55 / 2);


            if (TreasureOptions.Instance.Game._curGold == 0 || TreasureOptions.Instance.User.CurrentLife == 0)
            {
                StateManager.Instance.setState(TreasureStates.SCORE_STATE);
            }
            else
            {
                (TreasureApplicationManager.Instance as TreasureApplicationManager).UpdateSound(this.Index);
                TreasureApplicationManager.PREVENT_AUDIO_CHANGES = false;
            }
            // this.shutdown();
        }