Beispiel #1
0
        public override void Update()
        {
            if (this.commands == null)
            {
                World.Remove(this);
                return;
            }
            //make the wheel spin
            wheel.Angle -= 1;

            //keep track of mouse movement direction
            Point cMouse = new Point(Mouse.ScreenX, Mouse.ScreenY);
            int   angle  = (int)FP.Angle(cMouse.X, cMouse.Y, this.X, this.Y);

            if (commands != null && commands.Length > 0)
            {
                if (lastMouse != cMouse)
                {
                    //check which command is being selected
                    int deginc = 360 / commands.Length;
                    //turn angle to '0'
                    angle += deginc / 2 + 270;
                    //find index of the command
                    angle /= deginc;
                    angle %= commands.Length;
                    lastc  = commands[angle];

                    //clear the last update scaling
                    foreach (var img in commandImages.Values)
                    {
                        img.Scale = 1;
                    }
                    // Make it bigger to show its selected
                    commandImages[lastc].Scale = 2;
                }
            }
            //Fire it if clicked
            if (Mouse.Left.Pressed)
            {
                if (lastc != null && lastc.Actions != null && lastc.Actions.Length > 0)
                {
                    Action.runActions(lastc.Actions);

                    World.Remove(this);
                }
            }
            else if (Mouse.Right.Pressed)
            {
                World.Remove(this);
            }


            //update last mouse
            lastMouse = cMouse;
        }
Beispiel #2
0
        public override void Update()
        {
            base.Update();
            var currentAnimaion = this.CheckAnimation();

            if (Keyboard.Space.Pressed)
            {
                switch (InteractiveObjectRef.Attributes["AvatarSpriteState"])
                {
                case 0:
                    InteractiveObjectRef.Attributes["AvatarSpriteState"] = 1;
                    break;

                case 1:
                    InteractiveObjectRef.Attributes["AvatarSpriteState"] = 2;
                    break;

                case 2:
                    InteractiveObjectRef.Attributes["AvatarSpriteState"] = 3;
                    break;

                case 3:
                    InteractiveObjectRef.Attributes["AvatarSpriteState"] = 0;
                    break;

                default:
                    break;
                }
            }

            if (InventoryObject)
            {
                if (currentAnimaion != "Idle" + InteractiveObjectRef.Attributes["AvatarSpriteState"])
                {
                    PlayAnimation("Idle" + InteractiveObjectRef.Attributes["AvatarSpriteState"]);
                }
                return;
            }

            if (IsMoving)
            {
                this.MoveToward(walkToX, walkToY, FP.Elapsed * this.MoveSpeedX, FP.Elapsed * this.MoveSpeedY);

                //Trigger event if needed
                var worldMetadata = ((DynamicSceneWorld)World).metaData;
                if (worldMetadata.Regions != null)
                {
                    foreach (var r in worldMetadata.Regions)
                    {
                        if (r.Area.Contains(X, Y))
                        {
                            if (!wasInRegion[r])
                            {
                                //just entered, execute shit
                                Action.runActions(r.OnEnter);
                                wasInRegion[r] = true;
                            }
                        }
                        else
                        {
                            if (wasInRegion[r])
                            {
                                //just left region, execute other shit
                                Action.runActions(r.OnExit);
                                wasInRegion[r] = false;
                            }
                        }
                    }
                }

                //Animation stuff

                List <int> footFallFrameNumbers;
                footFallFrames.TryGetValue(currentAnimaion, out footFallFrameNumbers);
                if (footFallFrameNumbers != null && footFallFrameNumbers.Contains(sprite.Frame) && lastFootFrame != sprite.Frame)
                {
                    lastFootFrame = sprite.Frame;
                    SoundManager.PlaySoundVariations("footstepL", .8f, .9f);
                }

                if (pathNodes != null)
                {
                    if ((int)X == (int)walkToX && (int)Y == (int)walkToY)
                    {
                        if (pathNodes.MoveNext())
                        {
                            walkToX = pathNodes.Current.X;
                            walkToY = pathNodes.Current.Y;
                        }
                        else
                        {
                            PlayAnimation("Idle" + InteractiveObjectRef.Attributes["AvatarSpriteState"]);
                            pathNodes = null;
                            IsMoving  = false;
                            return;
                        }
                    }

                    var  walkAngle = FP.Angle(this.X, this.Y, walkToX, walkToY);
                    bool flip      = walkAngle >= 90 && walkAngle <= 270;
                    if (Flipped != flip)
                    {
                        Flipped = flip;
                    }

                    if (currentAnimaion != ("WalkDown" + InteractiveObjectRef.Attributes["AvatarSpriteState"]) && (walkAngle >= 0 && walkAngle <= 180))
                    {
                        PlayAnimation("WalkDown" + InteractiveObjectRef.Attributes["AvatarSpriteState"]);
                    }
                    else if (currentAnimaion != ("WalkUp" + +InteractiveObjectRef.Attributes["AvatarSpriteState"]) && walkAngle > 180 && walkAngle < 360)
                    {
                        PlayAnimation("WalkUp" + InteractiveObjectRef.Attributes["AvatarSpriteState"]);
                    }
                }
            }
        }