Ejemplo n.º 1
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            border = GetTemplateChild("Border") as Border;

            (GetTemplateChild("PART_LEFT_BTN") as Border).PointerPressed += (sender, e) => {
                mode = UIControls.ManipulationMode.ScaleLeft;
            };

            (GetTemplateChild("PART_RIGHT_BTN") as Border).PointerPressed += (sender, e) => {
                mode = UIControls.ManipulationMode.ScaleRight;
            };

            context          = DataContext as ISequenceElement;
            context.OnScale += (scale) =>
            {
                frameScale = scale;
                SetBeginFrame(frame);
                SetFrameSize(frameSize);
            };

            frameScale = context.FrameScale;
            frame      = context.StartFrame;
            frameSize  = context.FramesDuration;

            SetBeginFrame(frame);
            SetFrameSize(frameSize);
        }
Ejemplo n.º 2
0
        void AddNote(ISequenceElement seqElem)
        {
            //load and prepare image
            string imagePath = seqElem.IsBomb ? GameUIConstants.BombImage : GameUIConstants.P1ArrowImage;
            var    bitmap    = new BitmapImage(new Uri(imagePath));
            Image  img       = new Image()
            {
                Width = GameUIConstants.ArrowWidthHeight, Height = GameUIConstants.ArrowWidthHeight, Source = bitmap
            };

            //set top position of arrow according to time
            double top = seqElem.Time.TotalSeconds * GameUIConstants.PixelsPerSecond;

            Canvas.SetTop(img, top);

            //rotate arrow and set in proper place
            switch (seqElem.Type)
            {
            case SeqElemType.LeftArrow:
                if (!seqElem.IsBomb)
                {
                    img.RenderTransform = new RotateTransform(90, GameUIConstants.ArrowWidthHeight / 2.0, GameUIConstants.ArrowWidthHeight / 2.0);
                }
                Canvas.SetLeft(img, GameUIConstants.LeftArrowX);
                break;

            case SeqElemType.DownArrow:
                Canvas.SetLeft(img, GameUIConstants.DownArrowX);
                break;

            case SeqElemType.UpArrow:
                if (!seqElem.IsBomb)
                {
                    img.RenderTransform = new RotateTransform(180, GameUIConstants.ArrowWidthHeight / 2.0, GameUIConstants.ArrowWidthHeight / 2.0);
                }
                Canvas.SetLeft(img, GameUIConstants.UpArrowX);
                break;

            case SeqElemType.RightArrow:
                if (!seqElem.IsBomb)
                {
                    img.RenderTransform = new RotateTransform(-90, GameUIConstants.ArrowWidthHeight / 2.0, GameUIConstants.ArrowWidthHeight / 2.0);
                }
                Canvas.SetLeft(img, GameUIConstants.RightArrowX);
                break;
            }

            //add image to the canvas
            _view.notes.Children.Add(img);

            //add element to sequence
            (Song.Sequences[Difficulty] as IEditableSequence).AddElement(seqElem);
        }
Ejemplo n.º 3
0
        public void Handle(GameKeyEvent message)
        {
            if (!IsRunning)
            {
                return;
            }

            IPlayer player = message.PlayerId == PlayerID.Player1 ? Player1 : Player2;

            if (player == null ||
                (player.PlayerID == PlayerID.Player2 && !IsMultiplayer) ||
                message.PlayerAction == PlayerAction.Enter || message.PlayerAction == PlayerAction.Back)
            {
                return;
            }

            ISequenceElement hitElem = SetPoints(player, GetSongCurrentTime(), message.PlayerAction);

            if (hitElem != null)
            {
                _eventAggregator.Publish(new PlayerHitEvent()
                {
                    PlayerID        = player.PlayerID,
                    Life            = player.Life,
                    Points          = player.Points,
                    IsBomb          = hitElem.IsBomb,
                    SequenceElement = hitElem
                });
            }
            else
            {
                _eventAggregator.Publish(new PlayerMissedEvent()
                {
                    PlayerID = player.PlayerID,
                    Points   = player.Points,
                    Life     = player.Life,
                    Reason   = MissReason.WrongMomentOrAction
                });
            }
        }
Ejemplo n.º 4
0
        //returns null if nothing hit
        //synchronized with UI (if animation time attached to GetSongCurrentTime)
        private ISequenceElement SetPoints(IPlayer player, TimeSpan hitTime, PlayerAction playerAction)
        {
            var alreadyHit = player.PlayerID == PlayerID.Player1 ? _p1AlreadyHit : _p2AlreadyHit;

            SeqElemType      type       = GameHelper.PlayerActionToSeqElemType(playerAction);
            ISequenceElement hitElement = Song.GetClosestTo(player.Difficulty, hitTime, type, alreadyHit);

            if (hitElement == null)
            {
                SetLifePoints(player, -GameConstants.WrongMomentOrActionLifePoints);
                return(null);
            }

            if (!hitElement.IsBomb)
            {
                double diff = Math.Abs(hitElement.Time.TotalSeconds - hitTime.TotalSeconds);

                if (diff <= GameConstants.BestHitTime)
                {
                    player.Points += GameConstants.BestHitPoints;
                }
                else if (diff <= GameConstants.MediumHitTime)
                {
                    player.Points += GameConstants.MediumHitPoints;
                }
                else if (diff <= GameConstants.WorstHitTime)
                {
                    player.Points += GameConstants.WorstHitPoints;
                }

                SetLifePoints(player, GameConstants.HitLifePoints);
            }
            else
            {
                SetLifePoints(player, -GameConstants.BombLifePoints);
            }

            alreadyHit.Add(hitElement);
            return(hitElement);
        }
Ejemplo n.º 5
0
 public SequenceSingleBase(ISequenceElement element) : base()
 {
     Items.Add(element);
 }
Ejemplo n.º 6
0
 public void AddElement(ISequenceElement element)
 {
     SequenceElements.Add(element);
 }