예제 #1
0
        public static void Update()
        {
            Directions[LocalID] = Vector2.Zero;

            if (KeyboardCondition.Held(Keys.A))
            {
                Directions[LocalID] -= new Vector2(MoveSpeed, 0f);
            }
            if (KeyboardCondition.Held(Keys.D))
            {
                Directions[LocalID] += new Vector2(MoveSpeed, 0f);
            }
            if (KeyboardCondition.Held(Keys.W))
            {
                Directions[LocalID] -= new Vector2(0f, MoveSpeed);
            }
            if (KeyboardCondition.Held(Keys.S))
            {
                Directions[LocalID] += new Vector2(0f, MoveSpeed);
            }

            if (Directions[LocalID] != Vector2.Zero)
            {
                Directions[LocalID].Normalize();
            }

            Bodies[LocalID].ApplyForce(Directions[LocalID] * MoveSpeed);
            Bodies[LocalID].Position = Vector2.Clamp(Bodies[LocalID].Position, new Vector2(Functions.ToSim(-128 * 12)), new Vector2(Functions.ToSim(128 * 12)));

            Angles[LocalID] = MathF.Atan2(Data.MousePosition.Y - Functions.FromSim(Bodies[LocalID].Position.Y), Data.MousePosition.X - Functions.FromSim(Bodies[LocalID].Position.X));
        }
예제 #2
0
        public override void Update()
        {
            if (KeyboardCondition.Pressed(Keys.R))
            {
                Playing = !Playing;
            }

            if (!Playing)
            {
                if (KeyboardCondition.Pressed(Keys.E))
                {
                    if ((byte)Layer < Enum.GetNames(typeof(Layers)).Length - 1)
                    {
                        Layer++;
                    }
                    Label_CurrentLayer.Text.Message = Enum.GetNames(typeof(Layers))[(byte)Layer];
                }
                else if (KeyboardCondition.Pressed(Keys.Q))
                {
                    if ((byte)Layer > 0)
                    {
                        Layer--;
                    }
                    Label_CurrentLayer.Text.Message = Enum.GetNames(typeof(Layers))[(byte)Layer];
                }

                if (MouseCondition.Pressed(MouseButton.RightButton))
                {
                    switch (Layer)
                    {
                    case Layers.StaticObjects:
                        Functions.PlaceStaticObject(Data.MousePosition.X, Data.MousePosition.Y, ObjectType.Wall);
                        break;

                    case Layers.Zombies:
                        Functions.PlaceZombie(Data.MousePosition.X, Data.MousePosition.Y, ZombieType.Regular);
                        break;
                    }
                }

                if (MouseCondition.Pressed(MouseButton.MiddleButton))
                {
                    var thing = Data.World.TestPoint(Functions.ToSim(Data.MousePosition));

                    if (thing != null && thing.Body != null)
                    {
                        if (thing.Body.Tag is StaticObjectTag)
                        {
                            Pool.GameObjects_Static[Functions.ConvertBodyToStaticObject(thing.Body)].Active = false;
                        }
                        else if (thing.Body.Tag is ZombieTag)
                        {
                            Zombies.Active[Functions.ConvertBodyToStaticObject(thing.Body)] = false;
                        }
                    }
                }

                if (MouseCondition.Pressed(MouseButton.LeftButton))
                {
                    var thing = Data.World.TestPoint(Functions.ToSim(Data.MousePosition));

                    if (thing != null && thing.Body != null)
                    {
                        Grabbed       = thing.Body;
                        GrabbedOffset = thing.Body.Position - Functions.ToSim(Data.MousePosition);
                    }
                }

                if (MouseCondition.Released(MouseButton.LeftButton))
                {
                    Grabbed       = null;
                    GrabbedOffset = Vector2.Zero;
                }

                if (Grabbed != null)
                {
                    Grabbed.Position = Functions.ToSim(Data.MousePosition) + GrabbedOffset;
                }

                Camera.Velocity = Vector2.Lerp(Camera.Velocity, Vector2.Zero, .25f);

                if (KeyboardCondition.Held(Keys.A))
                {
                    Camera.Velocity -= new Vector2(CameraSpeed, 0f);
                }
                if (KeyboardCondition.Held(Keys.D))
                {
                    Camera.Velocity += new Vector2(CameraSpeed, 0f);
                }
                if (KeyboardCondition.Held(Keys.W))
                {
                    Camera.Velocity -= new Vector2(0f, CameraSpeed);
                }
                if (KeyboardCondition.Held(Keys.S))
                {
                    Camera.Velocity += new Vector2(0f, CameraSpeed);
                }

                Camera.Position = Vector2.Clamp(Camera.Position, new Vector2(-128 * 12) + Data.ScreenCentre,
                                                new Vector2(128 * 12) - Data.ScreenCentre);

                if (KeyboardCondition.Pressed(Keys.Enter))
                {
                    Functions.SaveLevel(LevelType.Level1);
                }

                Label_CurrentLayer.Update();
            }
            else
            {
                GameScreen.Instance.Update();
            }
        }