Пример #1
0
    protected virtual void ChangeDirection(Vector2 direction)
    {
        XDirection thisX = XDirection.right;
        YDirection thisY = YDirection.down;

        if (direction.x > 0)   // Going Right
        {
            thisX = XDirection.right;
        }
        else if (direction.x < 0)     // Going Left
        {
            thisX = XDirection.left;
        }
        else     // Not Moving Horizontally
        {
            thisX = curXDirection;
        }

        if (direction.y > 0)   // Going Up
        {
            thisY = YDirection.up;
        }
        else if (direction.y < 0)     // Going Down
        {
            thisY = YDirection.down;
        }
        else     // Not Moving Vertically
        {
            thisY = curYDirection;
        }
        ChangeEffectorBoxLocation(direction);

        ChangeDirection(thisX, thisY);
    }
        public void UpdateMap(XDirection dirX, YDirection dirY)
        {
            switch (dirX)
            {
            case XDirection.None:
                LowerRigth.X = BatmanPosition.X;
                UpperLeft.X  = BatmanPosition.X;
                break;

            case XDirection.Left:
                LowerRigth.X = BatmanPosition.X - 1;
                break;

            case XDirection.Right:
                UpperLeft.X = BatmanPosition.X + 1;
                break;
            }

            switch (dirY)
            {
            case YDirection.None:
                UpperLeft.Y  = BatmanPosition.Y;
                LowerRigth.Y = BatmanPosition.Y;
                break;

            case YDirection.Up:
                LowerRigth.Y = BatmanPosition.Y - 1;
                break;

            case YDirection.Down:
                UpperLeft.Y = BatmanPosition.Y + 1;
                break;
            }
        }
Пример #3
0
 public GameEvent_MoveSingle(int commandTick, int APCost, Entity mover, XDirection x, YDirection y, FloorState currentFloor)
     : base(commandTick, APCost, mover)
 {
     this.X            = x;
     this.Y            = y;
     this.CurrentFloor = currentFloor;
 }
Пример #4
0
        private void OnClassifierEventUpdate(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            var eventBytes = args.CharacteristicValue.ToArray();

            var eventType = eventBytes[0];

            if (eventType == (byte)ClassifierEventType.Pose)
            {
                lock (_lock)
                {
                    _myoHandPose = (Pose)BitConverter.ToInt16(eventBytes, 1);
                    Debug.Log("Got hand pose: " + _myoHandPose);
                }
            }
            else if (eventType == (byte)ClassifierEventType.ArmSynced)
            {
                lock (_lock)
                {
                    _myoArm            = (Arm)eventBytes[1];
                    _myoXAxisDirection = (XDirection)eventBytes[2];
                    Debug.Log("Got X axis orientation: " + _myoXAxisDirection);
                }
            }
            else if (eventType == (byte)ClassifierEventType.Unlocked)
            {
                Debug.Log("Myo unlocked");
            }
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArmRecognizedEventArgs"/> class.
        /// </summary>
        /// <param name="myo">The Myo that raised the event. Cannot be <c>null</c>.</param>
        /// <param name="timestamp">The timestamp of the event.</param>
        /// <param name="arm">The arm.</param>
        /// <param name="directionX">The direction x.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The exception that is thrown when <paramref name="myo"/> is null.
        /// </exception>
        public ArmRecognizedEventArgs(IMyo myo, DateTime timestamp, Arm arm, XDirection directionX)
            : base(myo, timestamp)
        {
            Contract.Requires<ArgumentNullException>(myo != null, "myo");

            this.Arm = arm;
            this.XDirection = directionX;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ArmRecognizedEventArgs"/> class.
        /// </summary>
        /// <param name="myo">The Myo that raised the event. Cannot be <c>null</c>.</param>
        /// <param name="timestamp">The timestamp of the event.</param>
        /// <param name="arm">The arm.</param>
        /// <param name="directionX">The direction x.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The exception that is thrown when <paramref name="myo"/> is null.
        /// </exception>
        public ArmRecognizedEventArgs(IMyo myo, DateTime timestamp, Arm arm, XDirection directionX)
            : base(myo, timestamp)
        {
            // Contract.Requires<ArgumentNullException>(myo != null, "myo");

            this.Arm        = arm;
            this.XDirection = directionX;
        }
Пример #7
0
        public float?XObstructionCheck(XDirection direction, TileLocation[] vectors)
        {
            float?nullable1 = new float?();

            switch (direction)
            {
            case XDirection.Right:
                float rightBound = this.tiles[this.TileY, this.TileX].RightBound;
                for (int index = 0; index < vectors.Length; ++index)
                {
                    if (this.XCheckRight(vectors[index].X))
                    {
                        return(new float?(rightBound));
                    }
                }
                for (int index = 0; index < vectors.Length; ++index)
                {
                    nullable1 = !this.tiles[vectors[index].Y, vectors[index].X + 1].Collision ? new float?() : new float?(this.tiles[vectors[index].Y, vectors[index].X + 1].LeftBound);
                    if (nullable1.HasValue)
                    {
                        float?nullable2 = nullable1;
                        float num       = rightBound;
                        if (((double)nullable2.GetValueOrDefault() >= (double)num ? 0 : (nullable2.HasValue ? 1 : 0)) != 0)
                        {
                            rightBound = nullable1.Value;
                        }
                    }
                }
                return(new float?(rightBound));

            case XDirection.Left:
                float num1 = 0.0f;
                for (int index = 0; index < vectors.Length; ++index)
                {
                    if (this.XCheckLeft(vectors[index].X))
                    {
                        return(new float?(num1));
                    }
                }
                for (int index = 0; index < vectors.Length; ++index)
                {
                    nullable1 = !this.tiles[vectors[index].Y, vectors[index].X - 1].Collision ? new float?() : new float?(this.tiles[vectors[index].Y, vectors[index].X - 1].RightBound);
                    if (nullable1.HasValue)
                    {
                        float?nullable2 = nullable1;
                        float num2      = num1;
                        if (((double)nullable2.GetValueOrDefault() <= (double)num2 ? 0 : (nullable2.HasValue ? 1 : 0)) != 0)
                        {
                            num1 = nullable1.Value;
                        }
                    }
                }
                return(new float?(num1));

            default:
                throw new Exception("Fool!");
            }
        }
Пример #8
0
 protected void GetHealthState(XDirection xDirection, YDirection yDirection)
 {
     if (this.health > 0)
     {
         return;
     }
     this.dead     = true;
     this.position = this.map.PlayerSpawn;
     this.health   = 100;
     this.Xmom     = 0.0f;
     this.Ymom     = 0.0f;
 }
Пример #9
0
        public Tile TileAt(TileLocation entityLocation, XDirection direction)
        {
            switch (direction)
            {
            case XDirection.Right:
                return(this.tiles[entityLocation.Y, entityLocation.X + 1]);

            case XDirection.Left:
                return(this.tiles[entityLocation.Y, entityLocation.X - 1]);

            default:
                throw new Exception("Invaild use of TileAt Function. Check Argument");
            }
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="elementname"></param>
        /// <param name="index"></param>
        /// <param name="direction"></param>
        public void MoveUpDown(String elementname, int index, XDirection direction)
        {
            doc.Load(Xmlfile);
            XmlElement  element  = GetTopElement(elementname);
            XmlNodeList nodelist = element.ChildNodes;
            XmlElement  el       = (XmlElement)nodelist[index];

            if ((index != 0 && direction == XDirection.Up) || (index != nodelist.Count - 1 && direction == XDirection.Down))
            {
                element.RemoveChild(el);
                element.InsertAfter(el, (XmlElement)nodelist[(index + (int)direction)]);
                doc.Save(Xmlfile);
            }
        }
Пример #11
0
 public virtual void Update(TimeSpan gameTime)
 {
     this.prevDirections = this.currentDirections;
     this.GetDirections();
     this.totalGameTime   += (float)gameTime.TotalMilliseconds;
     this.xDirection       = this.FindXDirection();
     this.yDirection       = this.FindYDirection();
     this.textureDirection = this.FindTextureSDirection();
     this.GetBounds();
     this.GetMoveChanges();
     this.xMove();
     this.yMove();
     this.ECC();
     this.GetTileDamage();
     this.GetActionState();
     this.GotoState();
     if (this.torsoTexture != null)
     {
         this.torsoTexture.Animate();
     }
     if (this.legTexture != null)
     {
         this.legTexture.Animate();
     }
     this.GetShade();
     this.GetTextureChange();
     if (this.attackTimer > 0)
     {
         --this.attackTimer;
     }
     if (this.stun > 0)
     {
         --this.stun;
     }
     if (this.damageCoolDown > 0)
     {
         --this.damageCoolDown;
     }
     else
     {
         this.previousAttacker = (Entity)null;
     }
 }
Пример #12
0
        public TileType LocationCheck(TileLocation entityLocation, XDirection xDirection)
        {
            try
            {
                switch (xDirection)
                {
                case XDirection.Right:
                    return(this.tiles[entityLocation.Y, entityLocation.X + 1].TileType);

                case XDirection.Left:
                    return(this.tiles[entityLocation.Y, entityLocation.X - 1].TileType);

                default:
                    return(TileType.Empty);
                }
            }
            catch (IndexOutOfRangeException ex)
            {
                return(TileType.Empty);
            }
        }
Пример #13
0
        public Player(OcTree octree, string modelName, Vector3 position, Vector3 rotation,
                      Vector3 scale, Vector2 maxSpeed, int maxLife, int attack)
            : base(octree, new AnimatedModel((GameModel)ModelManager.GetModel(modelName),
                                             position, rotation, scale, 0), maxSpeed, maxLife, attack)
        {
            _jump    = false;
            _endJump = true;

            _lastPlayerState = State.Waiting;
            _playerState     = State.Waiting;

            _lastPlayerAction = Action.None;
            _playerAction     = Action.None;

            _lastPlayerXDirection = XDirection.Right;
            _playerXDirection     = XDirection.Right;
            _lastPlayerYDirection = YDirection.None;
            _playerYDirection     = YDirection.None;

            ((AnimatedModel)this.DModel).Animation.StartClip("Waiting", true);
        }
Пример #14
0
        /// <summary>
        /// Called when the Myo has recognized which arm it is on.
        /// </summary>
        /// <param name="evt">The pointer to the event.</param>
        /// <param name="timestamp">The timestamp of the event.</param>
        protected virtual void OnArmRecognized(IntPtr evt, DateTime timestamp)
        {
            var arm = GetArm(evt);

            this.Arm = arm;

            var xDirection = GetEventDirectionX(evt);

            this.XDirectionOnArm = xDirection;

            var handler = ArmRecognized;

            if (handler != null)
            {
                var args = new ArmRecognizedEventArgs(
                    this,
                    timestamp,
                    arm,
                    xDirection);
                handler.Invoke(this, args);
            }
        }
Пример #15
0
        protected void GetXState(XDirection xDirection)
        {
            switch (xDirection)
            {
            case XDirection.Right:
                if (this.map.TileAt(this.TileSlightRight).Collision)
                {
                    this.xState = Entity.XMoveStates.NearWall;
                    break;
                }
                this.xState = Entity.XMoveStates.NotNearWall;
                break;

            case XDirection.Left:
                if (this.map.TileAt(this.TileSlightLeft).Collision)
                {
                    this.xState = Entity.XMoveStates.NearWall;
                    break;
                }
                this.xState = Entity.XMoveStates.NotNearWall;
                break;
            }
        }
Пример #16
0
        /// <summary>
        /// Constructor of the <c>Character</c> class.
        /// </summary>
        /// <param name="scene">Reference to the scene where the character moves.</param>
        /// <param name="model">Reference to the model that represents the character.</param>
        /// <param name="maxSpeed">Max speed of the character.</param>
        /// <param name="maxLife">Max life of the character.</param>
        /// <param name="attack">Attack of the character.</param>
        public Character(SceneRenderer scene, IDrawableModel model,
                         Vector2 maxSpeed, int maxLife, int life, int attack)
            : base(scene, model, maxSpeed, true, true)
        {
            _visible = true;

            _life    = life;
            _maxLife = maxLife;

            _attack = attack;

            _startStaircase  = false;
            _climbStaircase  = false;
            _finishStaircase = false;

            _startDownStaircase  = false;
            _climbDownStaircase  = false;
            _finishDownStaircase = false;

            _lastPlayerXDirection = XDirection.Right;
            _playerXDirection     = XDirection.Right;
            _lastPlayerYDirection = YDirection.None;
            _playerYDirection     = YDirection.None;
        }
Пример #17
0
        private void AnimateTiles(EnterMode mode, XDirection xDirection, ZDirection zDirection, TimeSpan duration, Action callback)
        {
            // If the control has not been rendered or it's empty, cancel the animation
            if (this.ActualWidth <= 0 || this.ActualHeight <= 0 || this._positions == null || this._positions.Count <= 0) return;

            // Get the visible tiles for the current configuration
            // Tiles that are partially visible are also counted
            var visibleitems = this._positions.Where(x => x.Value.X + x.Key.ActualWidth >= 0 && x.Value.X <= this.ActualWidth &&
                                                     x.Value.Y + x.Key.ActualHeight >= 0 && x.Value.Y <= this.ActualHeight);

            // No visible tiles, do nothing
            if (visibleitems.Count() <= 0) return;

            // The Y coordinate of the lowest element is useful 
            // when we animate from bottom to top
            double lowestX = visibleitems.Max(el => el.Value.X);

            // Store the animations to group them in one Storyboard in the end
            var animations = new List<Timeline>();

            foreach (var tilePosition in visibleitems)
            {
                // To make syntax lighter
                var tile = tilePosition.Key;
                var position = tilePosition.Value;
                var projection = tile.Projection as PlaneProjection;

                double rotationFrom, rotationTo, opacityTo;

                // Reset all children's opacity regardless of their animations
                if (mode == EnterMode.Exit)
                {
                    tile.Opacity = 1;
                    opacityTo = 0;
                    rotationFrom = 0;
                    rotationTo = zDirection == ZDirection.BackToFront ? -90 : 90;
                }
                else
                {
                    tile.Opacity = 0;
                    opacityTo = 1;
                    rotationFrom = zDirection == ZDirection.BackToFront ? -90 : 90;
                    rotationTo = 0;
                }

                // Used to determine begin time - depends if we're moving from bottom or from top
                double relativeX;

                if (xDirection == XDirection.LeftToRight)
                {
                    // The lowest element should have relativeY == 0
                    relativeX = lowestX - position.X;
                }
                else
                {
                    relativeX = position.X;
                }

                var easing = new QuadraticEase() { EasingMode = EasingMode.EaseInOut };

                var rotationAnimation = new DoubleAnimation { From = rotationFrom, To = rotationTo, EasingFunction = easing };
                rotationAnimation.Duration = duration;
                rotationAnimation.BeginTime = duration.Multiply(this.GetBeginTimeFactorFavorite(relativeX, position.Y, mode));
                rotationAnimation.SetTargetAndProperty(projection, PlaneProjection.RotationYProperty);

                var opacityAnimation = new DoubleAnimation { To = opacityTo, EasingFunction = easing };
                // The opacity animation takes the last 60% of the rotation animation
                opacityAnimation.Duration = duration.Multiply(0.6);
                opacityAnimation.BeginTime = rotationAnimation.BeginTime;
                if (mode == EnterMode.Exit)
                    opacityAnimation.BeginTime += duration - opacityAnimation.Duration.TimeSpan;
                opacityAnimation.SetTargetAndProperty(tile, UIElement.OpacityProperty);

                animations.Add(rotationAnimation);
                animations.Add(opacityAnimation);
            }

            // Begin all animations
            var sb = new Storyboard();
            sb.Completed += (sender, args) =>
            {
                if (callback != null)
                {
                    callback();
                }
            };

            foreach (var a in animations)
                sb.Children.Add(a);
            sb.Begin();
        }
Пример #18
0
 private void Sync(Arm arm, XDirection xDirection)
 {
     if (arm != Arm.Unknown && xDirection != XDirection.Unknown)
     {
         OnArmSynced(new ArmSyncedEventArgs(this, GetTimestamp(), arm, xDirection));
     }
 }
Пример #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NormalMap"/> class.
 /// </summary>
 /// <param name="xDirection">The x direction.</param>
 /// <param name="yDirection">The y direction.</param>
 public NormalMap(XDirection xDirection, YDirection yDirection)
 {
     YDirection = yDirection;
     XDirection = xDirection;
 }
Пример #20
0
        /// <summary>
        /// 获得对应名字的父节点元素
        /// </summary>
        /// <param name="element"></param>
        /// <param name="keyattriname"></param>
        /// <param name="keyattrivalue"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public XmlElement GetQryElement(XmlElement element, String keyattriname, String keyattrivalue, XDirection direction)     //向上或向下查找对应父元素下符合单个属性值的的第一个二级节点元素并返回
        {
            XmlElement  el       = null;
            XmlNodeList nodelist = element.ChildNodes;
            int         k        = nodelist.Count;

            for (int i = 0; i < k; i++)
            {
                int x = (direction == XDirection.Down) ? i : (k - i - 1);
                if ((((XmlElement)nodelist[x]).Attributes[keyattriname].Value == keyattrivalue) ||
                    ((keyattriname == "Date") && DateTime.Parse(((XmlElement)nodelist[x]).Attributes[keyattriname].Value) <= DateTime.Parse(keyattrivalue))
                    )
                {
                    el = (XmlElement)nodelist[x];
                    break;
                }
            }
            return(el);
        }
Пример #21
0
 public void MyoDirection(string directionName)
 {
     Debug.Log("received direction: " + directionName);
     XDirection direction;
     switch (directionName)
     {
         case "TOWARD_ELBOW":
             direction = XDirection.TowardElbow;
             break;
         case "TOWARD_WRIST":
             direction = XDirection.TowardWrist;
             break;
         default:
             direction = XDirection.Unknown;
             break;
     }
     _xDirection = direction;
     Sync(_currentArm, direction);
 }
Пример #22
0
        /// <summary>
        /// Determines the player's intended x and y velocities based on the most recent user input,
        /// while updating other action-related properties.
        /// </summary>
        /// <param name="time">The amount of gametime that has elapsed since the last frame.</param>
        public override void Update(GameTime time)
        {
            float totalTime = (float)(time.ElapsedGameTime.TotalSeconds);

            if (damageStatus >= INVINCIBLE_END)
            {
                damageStatus = VULNERABLE;
            }
            else if (damageStatus >= STUN_END)
            {
                if (rightBtnFlag == true && leftBtnFlag == false)
                    LatestXArrow = XDirection.Right;
                else if (leftBtnFlag == true && rightBtnFlag == false)
                    LatestXArrow = XDirection.Left;
                else
                    LatestXArrow = XDirection.None;
            }

            if (currentHealth > 0 && (damageStatus < INVINCIBLE_START || damageStatus >= STUN_END))
            {
                if (dashStatus < DASH_HELD)
                {
                    if (LatestXArrow == XDirection.Left && PlayerXFacing == XDirection.Right)
                        PlayerXFacing = XDirection.Left;
                    else if (LatestXArrow == XDirection.Right && PlayerXFacing == XDirection.Left)
                        PlayerXFacing = XDirection.Right;
                }

                if (isOnGround == false && velocityY >= 0)
                {
                    if (wallOnRight && rightBtnFlag)
                    {
                        if (WallSlideDirection == XDirection.None)
                        {
                            soundEngine.Play(AudioEngine.SoundEffects.WallLand);
                            if (jumpBtnFlag == false)
                                PlayerJumpState = JumpState.Allowed;
                            else
                                PlayerJumpState = JumpState.NotAllowed;
                            if (!dashBtnFlag)
                                dashStatus = DASH_ALLOWED;
                            else
                                dashStatus = DASH_NOT_ALLOWED;
                        }
                        WallSlideDirection = XDirection.Right;
                    }
                    else if (wallOnLeft && leftBtnFlag == true)
                    {
                        if (WallSlideDirection == XDirection.None)
                        {
                            soundEngine.Play(AudioEngine.SoundEffects.WallLand);
                            if (jumpBtnFlag == false)
                                PlayerJumpState = JumpState.Allowed;
                            else
                                PlayerJumpState = JumpState.NotAllowed;
                            if (!dashBtnFlag)
                                dashStatus = DASH_ALLOWED;
                            else
                                dashStatus = DASH_NOT_ALLOWED;
                        }
                        WallSlideDirection = XDirection.Left;
                    }
                    else
                        WallSlideDirection = XDirection.None;
                }
                else
                    WallSlideDirection = XDirection.None;

                if (PlayerJumpState == JumpState.NotAllowed && jumpBtnFlag == false)
                    PlayerJumpState = JumpState.Allowed;

                if (jumpBtnFlag == true && PlayerJumpState == JumpState.Allowed &&
                    (isOnGround || midairJumps > 0 || wallOnLeft || wallOnRight))
                {
                    if (isOnGround == false)
                    {
                        if (wallOnRight || wallOnLeft)
                        {
                            velocityY = WALL_JUMP_V_Y;
                            velocityX = WALL_JUMP_V_X;
                            if (wallOnLeft)
                            {
                                velocityX *= -1;
                                PlayerXFacing = XDirection.Right;
                            }
                            else
                            {
                                PlayerXFacing = XDirection.Left;
                            }
                            WallSlideDirection = XDirection.None;
                            soundEngine.Play(AudioEngine.SoundEffects.WallJump);
                        }
                        else
                        {
                            midairJumps = (byte)Math.Max(0, midairJumps - 1);
                            velocityY = JUMP_V;
                            soundEngine.Play(AudioEngine.SoundEffects.WallJump);
                        }
                    }
                    else
                    {
                        LeaveGround();
                        velocityY = JUMP_V;
                        soundEngine.Play(AudioEngine.SoundEffects.Jump);
                    }
                    if (dashStatus >= DASH_HELD)
                    {
                        dashStatus = DASH_LAG_START;
                        isGravityAffected = true;
                    }
                    PlayerJumpState = JumpState.Holding;
                    accelerationY = 0;
                }

                if (!isOnGround)
                {
                    if (PlayerJumpState == JumpState.Holding)
                    {
                        if (jumpBtnFlag == false)
                        {
                            PlayerJumpState = JumpState.Allowed;
                            if (velocityY <= 0)
                            {
                                accelerationY = JUMP_DECAY;
                                velocityLimitY = 0;
                            }
                        }
                    }
                    else if (WallSlideDirection != XDirection.None)
                    {
                        accelerationY = WALL_FRICTION_DEC;
                        velocityLimitY = MAX_WALL_SLIDE_V;
                    }
                    else if (velocityY >= 0)
                    {
                        accelerationY = 0;
                    }
                }

                if (dashStatus == DASH_ALLOWED && dashBtnFlag == true &&
                    (dashes != 0 || WallSlideDirection != XDirection.None))
                {
                    dashStatus = DASH_HELD;
                    accelerationX = 0;
                    if (WallSlideDirection == XDirection.Right)
                    {
                        velocityX = -DASH_V;
                        PlayerXFacing = XDirection.Left;
                    }
                    else if (WallSlideDirection == XDirection.Left)
                    {
                        velocityX = DASH_V;
                        PlayerXFacing = XDirection.Right;
                    }
                    else
                    {
                        if (dashes > 0)
                            dashes--;
                        if (PlayerXFacing == XDirection.Right)
                        {
                            velocityX = DASH_V;
                            velocityLimitX = DASH_V;
                        }
                        else
                        {
                            velocityX = -DASH_V;
                            velocityLimitX = -DASH_V;
                        }
                    }
                    if (!isOnGround)
                    {
                        isGravityAffected = false;
                        velocityY = 0;
                        accelerationY = 0;
                    }
                    soundEngine.Play(AudioEngine.SoundEffects.Dash);
                }
                else if (dashStatus < DASH_NOT_ALLOWED)
                    dashStatus = Math.Min(dashStatus + totalTime, DASH_NOT_ALLOWED);
                else if (dashStatus == DASH_NOT_ALLOWED && dashBtnFlag == false)
                    dashStatus = DASH_ALLOWED;

                if (dashStatus >= DASH_HELD)
                {
                    dashStatus += totalTime;
                    if (dashStatus > MAX_DASH_TIME || dashBtnFlag == false)
                    {
                        if (LatestXArrow == XDirection.Right)
                            velocityX = MAX_RUN_V;
                        else if (LatestXArrow == XDirection.Left)
                            velocityX = -MAX_RUN_V;
                        else
                            velocityX = 0;
                        isGravityAffected = true;
                        dashStatus = DASH_LAG_START;
                    }
                }
                else
                {
                    if (LatestXArrow == XDirection.Right)
                    {
                        if (velocityX < 0)
                        {
                            accelerationX = BRAKE_DEC;
                            velocityLimitX = 0;
                        }
                        else if (velocityX <= MAX_RUN_V)
                        {
                            accelerationX = RUN_ACC;
                            velocityLimitX = MAX_RUN_V;
                        }
                        else
                        {
                            accelerationX = TOO_FAST_DEC;
                            velocityLimitX = MAX_RUN_V;
                        }
                    }
                    else if (LatestXArrow == XDirection.Left)
                    {
                        if (velocityX > 0)
                        {
                            accelerationX = -BRAKE_DEC;
                            velocityLimitX = 0;
                        }
                        else if (velocityX >= -MAX_RUN_V)
                        {
                            accelerationX = -RUN_ACC;
                            velocityLimitX = -MAX_RUN_V;
                        }
                        else
                        {
                            accelerationX = -TOO_FAST_DEC;
                            velocityLimitX = -MAX_RUN_V;
                        }
                    }
                    else if (velocityX != 0)
                    {
                        if (velocityX > MAX_RUN_V)
                        {
                            accelerationX = TOO_FAST_DEC;
                            velocityLimitX = MAX_RUN_V;
                        }
                        else if (velocityX > 0)
                        {
                            accelerationX = STOP_DEC;
                            velocityLimitX = 0;
                        }
                        else if (velocityX < -MAX_RUN_V)
                        {
                            accelerationX = -TOO_FAST_DEC;
                            velocityLimitX = -MAX_RUN_V;
                        }
                        else if (velocityX < 0)
                        {
                            accelerationX = -STOP_DEC;
                            velocityLimitX = 0;
                        }
                    }
                }
            }

            if ((damageStatus >= SWITCH_TO_DEAD_FRAME) && (damageStatus <= deathSequenceEndTime) &&
                (currentFrame == 0))
            {
                SwitchToDeathCollision();
                currentFrame++;
            }

            if (damageStatus >= INVINCIBLE_START)
                damageStatus += totalTime;
            else if (damageStatus < deathSequenceEndTime)
                damageStatus = Math.Min(deathSequenceEndTime, damageStatus + totalTime);

            if (PlayerXFacing == XDirection.Right)
            {
                if (currentHealth <= 0)
                    currentAnimation = currentAnimation = (int)PlayerAnimations.DyingRight;
                else if (damageStatus >= INVINCIBLE_START && damageStatus < STUN_END)
                    currentAnimation = (int)PlayerAnimations.DamageRight;
                else if (dashStatus >= DASH_HELD)
                    currentAnimation = (int)PlayerAnimations.DashRight;
                else if (WallSlideDirection == XDirection.Right)
                    currentAnimation = (int)PlayerAnimations.WallSlideRight;
                else if (!isOnGround)
                    currentAnimation = (int)PlayerAnimations.JumpRight;
                else
                {
                    currentAnimation = (int)PlayerAnimations.WalkRight;
                    if (damageStatus >= STUN_END)
                        animationSpeed[currentAnimation] = 2 * velocityX / MAX_RUN_V;
                    else
                        animationSpeed[currentAnimation] = velocityX / MAX_RUN_V;
                }
            }
            else
            {
                if (currentHealth <= 0)
                    currentAnimation = currentAnimation = (int)PlayerAnimations.DyingLeft;
                else if (damageStatus >= INVINCIBLE_START && damageStatus < STUN_END)
                    currentAnimation = (int)PlayerAnimations.DamageLeft;
                else if (dashStatus >= DASH_HELD)
                    currentAnimation = (int)PlayerAnimations.DashLeft;
                else if (WallSlideDirection == XDirection.Left)
                    currentAnimation = (int)PlayerAnimations.WallSlideLeft;
                else if (!isOnGround)
                    currentAnimation = (int)PlayerAnimations.JumpLeft;
                else
                {
                    currentAnimation = (int)PlayerAnimations.WalkLeft;
                    if (damageStatus >= STUN_END)
                        animationSpeed[currentAnimation] = 2 * -velocityX / MAX_RUN_V;
                    else
                        animationSpeed[currentAnimation] = -velocityX / MAX_RUN_V;
                }
            }
            if (velocityX == 0 && currentHealth > 0)
                currentFrame = 0;

            if (currentAnimation == (int)PlayerAnimations.DashLeft || currentAnimation == (int)PlayerAnimations.DashRight ||
                currentAnimation == (int)PlayerAnimations.DyingLeft || currentAnimation == (int)PlayerAnimations.DyingRight)
                looping = false;
            else
                looping = true;

            base.Update(time);
        }
Пример #23
0
        /// <summary>
        /// Analyzes user input and updates the control flags for the player character.
        /// </summary>
        public void updateControlFlags()
        {
            KeyboardState newKeyState = Keyboard.GetState();
            GamePadState newGPState = GamePad.GetState(PlayerIndex.One);

            if ((keyState.IsKeyUp(Keys.Right) && newKeyState.IsKeyDown(Keys.Right)) ||
                    (keyState.IsKeyUp(Keys.D) && newKeyState.IsKeyDown(Keys.D)) ||
                    ((newGPState.DPad.Right == ButtonState.Pressed) && (gpState.DPad.Right == ButtonState.Released)) ||
                    ((newGPState.ThumbSticks.Left.X > 0) && (gpState.ThumbSticks.Left.X <= 0)))
            {
                rightBtnFlag = true;
                LatestXArrow = XDirection.Right;
            }
            else if ((keyState.IsKeyUp(Keys.Left) && newKeyState.IsKeyDown(Keys.Left)) ||
                    (keyState.IsKeyUp(Keys.A) && newKeyState.IsKeyDown(Keys.A)) ||
                    ((gpState.DPad.Left == ButtonState.Released) && (newGPState.DPad.Left == ButtonState.Pressed)) ||
                    ((gpState.ThumbSticks.Left.X >= 0) && (newGPState.ThumbSticks.Left.X < 0)))
            {
                leftBtnFlag = true;
                LatestXArrow = XDirection.Left;
            }

            if ((keyState.IsKeyUp(Keys.Space) && newKeyState.IsKeyDown(Keys.Space)) ||
                    (keyState.IsKeyUp(Keys.X) && newKeyState.IsKeyDown(Keys.X)) ||
                    (gpState.Buttons.A == ButtonState.Released && newGPState.Buttons.A == ButtonState.Pressed))
                jumpBtnFlag = true;

            if (itemArray[(int)Powerups.Dash] &&
                ((keyState.IsKeyUp(Keys.Z) && newKeyState.IsKeyDown(Keys.Z)) ||
                    (keyState.IsKeyUp(Keys.Q) && newKeyState.IsKeyDown(Keys.Q))))
                dashBtnFlag = true;
            else if (itemArray[(int)Powerups.Dash] && (gpState.Triggers.Right == 0 && newGPState.Triggers.Right > 0))
            {
                if (currentHealth > 0 && dashStatus < DASH_HELD && dashStatus >= DASH_ALLOWED)
                    PlayerXFacing = XDirection.Right;
                dashBtnFlag = true;
            }
            else if (itemArray[(int)Powerups.Dash] && (gpState.Triggers.Left == 0 && newGPState.Triggers.Left > 0))
            {
                if (currentHealth > 0 && dashStatus < DASH_HELD && dashStatus >= DASH_ALLOWED)
                    PlayerXFacing = XDirection.Left;
                dashBtnFlag = true;
            }

            if (keyState.IsKeyUp(Keys.E) && newKeyState.IsKeyDown(Keys.E) ||
                (gpState.Buttons.X == ButtonState.Released && newGPState.Buttons.X == ButtonState.Pressed))
                interactBtnFlag = true;
            else
                interactBtnFlag = false;

            //
            //-----------------------------------------------------------------------------
            //

            if ((keyState.IsKeyDown(Keys.Left) && newKeyState.IsKeyUp(Keys.Left)) ||
                (keyState.IsKeyDown(Keys.A) && newKeyState.IsKeyUp(Keys.A)) ||
                (gpState.DPad.Left == ButtonState.Pressed && newGPState.DPad.Left == ButtonState.Released) ||
                (gpState.ThumbSticks.Left.X != 0 && newGPState.ThumbSticks.Left.X == 0))
            {
                leftBtnFlag = false;
                if (LatestXArrow == XDirection.Left)
                {
                    if (rightBtnFlag == true)
                        LatestXArrow = XDirection.Right;
                    else
                        LatestXArrow = XDirection.None;
                }
            }
            if ((keyState.IsKeyDown(Keys.Right) && newKeyState.IsKeyUp(Keys.Right)) ||
                (keyState.IsKeyDown(Keys.D) && newKeyState.IsKeyUp(Keys.D)) ||
                (gpState.DPad.Right == ButtonState.Pressed && newGPState.DPad.Right == ButtonState.Released) ||
                (gpState.ThumbSticks.Left.X != 0 && newGPState.ThumbSticks.Left.X == 0))
            {
                rightBtnFlag = false;
                if (LatestXArrow == XDirection.Right)
                {
                    if (leftBtnFlag == true)
                        LatestXArrow = XDirection.Left;
                    else
                        LatestXArrow = XDirection.None;
                }
            }

            if ((keyState.IsKeyDown(Keys.Space) && newKeyState.IsKeyUp(Keys.Space)) ||
                (keyState.IsKeyDown(Keys.X) && newKeyState.IsKeyUp(Keys.X)) ||
                (gpState.Buttons.A == ButtonState.Pressed && newGPState.Buttons.A == ButtonState.Released))
            {
                jumpBtnFlag = false;
            }

            if (itemArray[(int)Powerups.Dash] &&
                (keyState.IsKeyDown(Keys.Z) && newKeyState.IsKeyUp(Keys.Z)) ||
                (keyState.IsKeyDown(Keys.Q) && newKeyState.IsKeyUp(Keys.Q)) ||
                (gpState.Triggers.Right > 0 && newGPState.Triggers.Right == 0) ||
                (gpState.Triggers.Left > 0 && newGPState.Triggers.Left == 0))
                dashBtnFlag = false;

            keyState = newKeyState;
            gpState = newGPState;
        }
Пример #24
0
 /// <summary>
 /// Resets all relevant properties to their "fresh"/initial states.
 /// Used for when the player enters rooms, spawns/respawns, or starts
 /// a new game.
 /// </summary>
 /// <param name="direction">The direction the player should face.</param>
 public void ResetActionStates(XDirection direction)
 {
     isOnGround = true;
     isGravityAffected = true;
     PlayerJumpState = JumpState.NotAllowed;
     PlayerXFacing = direction;
     midairJumps = MAX_MIDAIR_JUMPS;
     dashes = INFINITE_DASHES;
     if (rightBtnFlag == true && leftBtnFlag == false)
         LatestXArrow = XDirection.Right;
     else if (leftBtnFlag == true && rightBtnFlag == false)
         LatestXArrow = XDirection.Left;
     else
         LatestXArrow = XDirection.None;
     WallSlideDirection = XDirection.None;
     dashStatus = DASH_NOT_ALLOWED;
     velocityY = 0;
     velocityX = 0;
     accelerationX = 0;
     accelerationY = 0;
     drawnLastFrame = true;
 }
Пример #25
0
    void Horizontalinput()
    {
        if (currentX == XDirection.None) {
            if (leftkeydown) {
                nextX = XDirection.Left;
            }
            if (rightkeydown) {
                nextX = XDirection.Right;
            }
            if(rightkeydown&&leftkeydown){
                nextX = XDirection.Special;
            }
        }
        if (currentX == XDirection.Left) {
            if(rightkeydown){
                nextX = XDirection.Right;
            }
            if(leftkeyup && !rightkey){
                nextX = XDirection.None;
            }
            if(leftkeyup && rightkey){
                nextX = XDirection.Right;
            }
        }
        if (currentX == XDirection.Right) {
            if(leftkeydown){
                nextX = XDirection.Left;
            }
            if(rightkeyup && !leftkey){
                nextX = XDirection.None;
            }
            if(rightkeyup && leftkey){
                nextX = XDirection.Left;
            }
        }
        if (currentX == XDirection.Special) {
            if(rightkeyup && !leftkeyup){
                nextX = XDirection.Left;
            }
            if(leftkeyup && !rightkeyup){
                nextX = XDirection.Right;
            }
            if(leftkeyup && rightkeyup){
                nextX = XDirection.None;
            }

        }
        //Debug.Log ("X:"+nextX);
        currentX = nextX;
    }
Пример #26
0
        internal void HandleEvent(libmyo.EventType type, DateTime timestamp, IntPtr evt)
        {
            switch (type)
            {
            case libmyo.EventType.Connected:
                if (Connected != null)
                {
                    Connected(this, new MyoEventArgs(this, timestamp));
                }
                break;

            case libmyo.EventType.Disconnected:
                if (Disconnected != null)
                {
                    Disconnected(this, new MyoEventArgs(this, timestamp));
                }
                break;

            case libmyo.EventType.ArmSynced:
                if (ArmSynced != null)
                {
                    Arm        arm        = (Arm)libmyo.event_get_arm(evt);
                    XDirection xDirection = (XDirection)libmyo.event_get_x_direction(evt);

                    ArmSynced(this, new ArmSyncedEventArgs(this, timestamp, arm, xDirection));
                }
                break;

            case libmyo.EventType.ArmUnsynced:
                if (ArmUnsynced != null)
                {
                    ArmUnsynced(this, new MyoEventArgs(this, timestamp));
                }
                break;

            case libmyo.EventType.Orientation:
                if (AccelerometerData != null)
                {
                    float x = libmyo.event_get_accelerometer(evt, 0);
                    float y = libmyo.event_get_accelerometer(evt, 1);
                    float z = libmyo.event_get_accelerometer(evt, 2);

                    var accelerometer = new Vector3(x, y, z);
                    AccelerometerData(this, new AccelerometerDataEventArgs(this, timestamp, accelerometer));
                }
                if (GyroscopeData != null)
                {
                    float x = libmyo.event_get_gyroscope(evt, 0);
                    float y = libmyo.event_get_gyroscope(evt, 1);
                    float z = libmyo.event_get_gyroscope(evt, 2);

                    var gyroscope = new Vector3(x, y, z);
                    GyroscopeData(this, new GyroscopeDataEventArgs(this, timestamp, gyroscope));
                }
                if (OrientationData != null)
                {
                    float x = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.X);
                    float y = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.Y);
                    float z = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.Z);
                    float w = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.W);

                    var orientation = new Quaternion(x, y, z, w);
                    OrientationData(this, new OrientationDataEventArgs(this, timestamp, orientation));
                }
                break;

            case libmyo.EventType.Pose:
                if (PoseChange != null)
                {
                    var pose = (Pose)libmyo.event_get_pose(evt);
                    PoseChange(this, new PoseEventArgs(this, timestamp, pose));
                }
                break;

            case libmyo.EventType.Rssi:
                if (Rssi != null)
                {
                    var rssi = libmyo.event_get_rssi(evt);
                    Rssi(this, new RssiEventArgs(this, timestamp, rssi));
                }
                break;

            case libmyo.EventType.Unlocked:
                if (Unlocked != null)
                {
                    Unlocked(this, new MyoEventArgs(this, timestamp));
                }
                break;

            case libmyo.EventType.Locked:
                if (Locked != null)
                {
                    Locked(this, new MyoEventArgs(this, timestamp));
                }
                break;

            case libmyo.EventType.Emg:

                Dictionary <int, sbyte> emgData = new Dictionary <int, sbyte>();
                for (int i = 0; i < 8; i++)
                {
                    emgData[i] = libmyo.event_get_emg(evt, (uint)i);
                }

                if (Emg != null)
                {
                    Emg(this, new EmgEventArgs(this, timestamp, emgData));
                }


                break;
            }
        }
Пример #27
0
        private void UpdateCopter(GameTime gameTime)
        {
            //figure out if copter has hit either end to reverse direction
            if (copter.Position.X == GraphicsDevice.Viewport.Width - copter.Width)
                copterDirection = XDirection.Left;
            else if (copter.Position.X == 0)
                copterDirection = XDirection.Right;

            if (copterDirection == XDirection.Right)
                copter.Position.X += copterMoveSpeed;
            else
                copter.Position.X -= copterMoveSpeed;

            copter.Position.X = MathHelper.Clamp(copter.Position.X, 0, GraphicsDevice.Viewport.Width - copter.Width);
        }
Пример #28
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            trampolineMoveSpeed = 8.0f;
            trampolineDeceleration = 2.0f;
            copterMoveSpeed = 2f;
            copterDirection = XDirection.Right;

            trampoline = new Trampoline();
            copter = new Copter();
            Kittens = new List<Kitten>();

            kittenSpawnTime = TimeSpan.FromSeconds(5);
            lastKittenSpawnTime = TimeSpan.Zero;

            base.Initialize();
        }
Пример #29
0
 /// <summary>
 /// Initiate damage and flinching caused by collision with a specific
 /// enemy object from a specific direction.
 /// </summary>
 /// <param name="enemy">The enemy to collide with.</param>
 /// <param name="direction">The side of the player that the enemy is touching.</param>
 private void CollideWithEnemy(Enemy enemy, XDirection direction)
 {
     soundEngine.Play(AudioEngine.SoundEffects.Hurt);
     currentHealth = Math.Max(0, currentHealth - enemy.ContactDamage);
     if (direction == XDirection.Left)
     {
         velocityX = KNOCK_BACK_V;
         accelerationX = STOP_DEC;
     }
     else
     {
         velocityX = -KNOCK_BACK_V;
         accelerationX = -STOP_DEC;
     }
     velocityLimitX = 0;
     accelerationY = 0;
     LatestXArrow = XDirection.None;
     isGravityAffected = true;
     if (currentHealth > 0)
         damageStatus = INVINCIBLE_START;
     else
     {
         velocityY -= 500;
         deathSequenceEndTime = DEATH_SEQUENCE_END_WITH_RAGDOLL;
     }
 }
Пример #30
0
    XDirection Horizontalinput(XDirection x, bool ld, bool rd, bool l, bool r, bool lu, bool ru)
    {
        if (x == XDirection.None) {
            if (ld) {
                return XDirection.Left;
            }
            if (rd) {
                return XDirection.Right;
            }
            if(rd&&ld){
                return XDirection.Special;
            }
        }
        if (x == XDirection.Left) {
            if(rd){
                return XDirection.Right;
            }
            if(lu && !r){
                return XDirection.None;
            }
            if(lu && r){
                return XDirection.Right;
            }
        }
        if (x == XDirection.Right) {
            if(ld){
                return XDirection.Left;
            }
            if(ru && !l){
                return XDirection.None;
            }
            if(ru && l){
                return XDirection.Left;
            }
        }
        if (x == XDirection.Special) {
            if(ru && !lu){
                return XDirection.Left;
            }
            if(lu && !ru){
                return XDirection.Right;
            }
            if(lu && ru){
                return XDirection.None;
            }

        }
        return x;
    }
Пример #31
0
 public ArmSyncedEventArgs(Myo myo, DateTime timestamp, Arm arm, XDirection xDirection)
     : base(myo, timestamp)
 {
     this.Arm        = arm;
     this.XDirection = xDirection;
 }
Пример #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ArmRecognizedEventArgs"/> class.
 /// </summary>
 /// <param name="myo">The Myo that raised the event. Cannot be <c>null</c>.</param>
 /// <param name="timestamp">The timestamp of the event.</param>
 /// <param name="arm">The arm.</param>
 /// <param name="directionX">The direction x.</param>
 /// <exception cref="System.ArgumentNullException">
 /// The exception that is thrown when <paramref name="myo"/> is null.
 /// </exception>
 public ArmRecognizedEventArgs(IMyo myo, DateTime timestamp, Arm arm, XDirection directionX)
     : base(myo, timestamp)
 {
     this.Arm        = arm;
     this.XDirection = directionX;
 }
Пример #33
0
 protected virtual void ChangeDirection(XDirection x, YDirection y)
 {
     curXDirection = x;
     curYDirection = y;
     rend.sprite   = GetSpriteWithKey(y + "_" + x);
 }
Пример #34
0
 public ArmSyncedEventArgs(Myo myo, DateTime timestamp, Arm arm, XDirection xDirection)
     : base(myo, timestamp)
 {
     this.Arm = arm;
     this.XDirection = xDirection;
 }
Пример #35
0
        internal void HandleEvent(libmyo.EventType type, DateTime timestamp, IntPtr evt)
        {
            bool outputEmgData = false;

            switch (type)
            {
            case libmyo.EventType.Connected:
                if (Connected != null)
                {
                    Connected(this, new MyoEventArgs(this, timestamp));
                }
                break;

            case libmyo.EventType.Disconnected:
                if (Disconnected != null)
                {
                    Disconnected(this, new MyoEventArgs(this, timestamp));
                }
                break;

            case libmyo.EventType.ArmSynced:
                if (ArmSynced != null)
                {
                    Arm        arm        = (Arm)libmyo.event_get_arm(evt);
                    XDirection xDirection = (XDirection)libmyo.event_get_x_direction(evt);

                    ArmSynced(this, new ArmSyncedEventArgs(this, timestamp, arm, xDirection));
                }
                break;

            case libmyo.EventType.ArmUnsynced:
                if (ArmUnsynced != null)
                {
                    ArmUnsynced(this, new MyoEventArgs(this, timestamp));
                }
                break;

            case libmyo.EventType.Orientation:
                if (AccelerometerData != null)
                {
                    float x = libmyo.event_get_accelerometer(evt, 0);
                    float y = libmyo.event_get_accelerometer(evt, 1);
                    float z = libmyo.event_get_accelerometer(evt, 2);

                    var accelerometer = new Vector3(x, y, z);
                    AccelerometerData(this, new AccelerometerDataEventArgs(this, timestamp, accelerometer));
                }
                if (GyroscopeData != null)
                {
                    float x = libmyo.event_get_gyroscope(evt, 0);
                    float y = libmyo.event_get_gyroscope(evt, 1);
                    float z = libmyo.event_get_gyroscope(evt, 2);

                    var gyroscope = new Vector3(x, y, z);
                    GyroscopeData(this, new GyroscopeDataEventArgs(this, timestamp, gyroscope));
                }
                if (OrientationData != null)
                {
                    float x = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.X);
                    float y = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.Y);
                    float z = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.Z);
                    float w = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.W);

                    var orientation = new Quaternion(x, y, z, w);
                    OrientationData(this, new OrientationDataEventArgs(this, timestamp, orientation));
                }
                break;

            case libmyo.EventType.Pose:
                if (PoseChange != null)
                {
                    var pose = (Pose)libmyo.event_get_pose(evt);
                    PoseChange(this, new PoseEventArgs(this, timestamp, pose));
                }
                break;

            case libmyo.EventType.Rssi:
                if (Rssi != null)
                {
                    var rssi = libmyo.event_get_rssi(evt);
                    Rssi(this, new RssiEventArgs(this, timestamp, rssi));
                }
                break;

            case libmyo.EventType.Emg:
                outputEmgData = true;
                SetEmgData(evt, timestamp);
                break;

            case libmyo.EventType.Unlocked:
                if (Unlocked != null)
                {
                    Unlocked(this, new MyoEventArgs(this, timestamp));
                }
                break;

            case libmyo.EventType.Locked:
                if (Locked != null)
                {
                    Locked(this, new MyoEventArgs(this, timestamp));
                }
                break;
            }

            if (!outputEmgData && streamEmg)
            {
                SetEmgData(evt, timestamp);
            }
        }
Пример #36
0
 public void AnimateTiles(EnterMode mode, XDirection xDirection, ZDirection zDirection, Action callback, int time = SpeedAnimation)
 {
     this.AnimateTiles(mode, xDirection, zDirection, TimeSpan.FromMilliseconds(time), callback);
 }