Пример #1
0
        /// <summary>
        /// Sets the path for the object to follow.
        /// </summary>
        /// <param name="path">The path to follow.</param>
        /// <param name="speed">The velocity or acceleration of the object as it moves along the path.</param>
        /// <param name="type">The path movement type.</param>
        /// <param name="axis">The allowed movement axis of the object.</param>
        /// <param name="movement">Determines whether to set the object's velocity or acceleration as it moves along the path.</param>
        /// <returns>The path that was set.</returns>
        public GenPath SetPath(
            GenPath path,
            float speed,
            GenPath.Type type = GenPath.Type.Clockwise,
            GenMove.Axis axis = GenMove.Axis.Both,
            GenPath.Movement movement = GenPath.Movement.Instant)
        {
            Path = path;
            PathSpeed = speed;
            PathType = type;
            PathAxis = axis;
            PathMovement = movement;

            // Set the initial path node index relative to the path movement type.
            switch (PathType)
            {
                case GenPath.Type.Counterclockwise:
                    PathNodeIndex = Path.Nodes.Count - 1;
                    break;
                case GenPath.Type.Random:
                    PathNodeIndex = GenU.Random(0, Path.Nodes.Count);
                    break;
                default:
                    PathNodeIndex = 0;
                    break;
            }

            return path;
        }
Пример #2
0
        public override void Create()
        {
            base.Create();

            GenG.ShowDebugInfo = true;

            // Set the world bounds before creating any object groups.
            // This allows the quadtrees in each group to be sized correctly.
            GenG.WorldBounds = new Rectangle(-GenG.TitleSafeArea.Left, -GenG.TitleSafeArea.Top, GenG.Game.Width, GenG.Game.Height * 4);

            /*Map = new GenTilemap();

            Map.LoadTile("1", new GenTile()).MakeTexture(Color.LightSkyBlue, 16, 16);
            Map.LoadTile("2", new GenTile()).MakeTexture(Color.IndianRed, 16, 16);

            Map.LoadMap(
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,1\n" +
                "1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,1\n" +
                "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"
                , 16, 16, null);
            Add(Map);*/

            Cave = new GenCave();
            Cave.MakeCave(160, 360);
            Add(Cave);

            BgColor = Color.CornflowerBlue;

            //camera2 = AddCamera(new GenCamera(0, GenG.Game.Height / 2, GenG.Game.Width, GenG.Game.Height / 2, 2f));
            //camera2.BgColor = new Color(50, 50, 70);

            Camera.BgColor = new Color(40, 50, 70);
            //Camera.SetCameraView(0f, 0f, GenG.Game.Width, (int)(GenG.Game.Height * 0.5f));

            /*Camera.BlendState.ColorSourceBlend = Blend.One;
            Camera.BlendState.ColorDestinationBlend = Blend.InverseSourceColor;
            Camera.BlendState.ColorBlendFunction = BlendFunction.Subtract;
            Camera.BlendState.AlphaSourceBlend = Blend.One;
            Camera.BlendState.AlphaDestinationBlend = Blend.InverseSourceColor;
            Camera.BlendState.AlphaBlendFunction = BlendFunction.Subtract;*/

            Path = new GenPath();
            Path.AddNode(new GenPathNode(100, 100));
            Path.AddNode(new GenPathNode(200, 100));
            Path.AddNode(new GenPathNode(200, 200));
            Path.AddNode(new GenPathNode(100, 150));
            Add(Path);

            Chain = new GenVerlet();
            Chain.MakeGrid(300, 200, 5, 15, 1);
            Chain.DrawLines = false;
            Chain.SetMass(1f);
            Chain.SetGravity(0f, 700f);
            Chain.Iterations = 10;

            for (int i = 0; i < Chain.Members.Count; i++)
            {
                ((GenObject)Chain.Members[i]).Width = ((GenObject)Chain.Members[i]).Height = Chain.Members.Count - i;
                ((GenSprite)Chain.Members[i]).MakeTexture(Color.White * 0.3f, (int)((GenObject)Chain.Members[i]).Width, (int)((GenObject)Chain.Members[i]).Height);
            }

            for (int i = 0; i < Chain.Links.Count; i++)
            {
                Chain.Links[i].OffsetA.X = Chain.Links[i].OffsetA.Y = Chain.Links[i].PointA.Width / 2;
                Chain.Links[i].OffsetB.X = Chain.Links[i].OffsetB.Y = Chain.Links[i].PointB.Width / 2;
            }

            ((GenObject)Chain.Members[0]).Immovable = true;
            ((GenObject)Chain.Members[0]).Acceleration.Y = 0f;
            ((GenObject)Chain.Members[0]).SetPath(Path, 100, GenPath.Type.Yoyo, GenMove.Axis.Both, GenPath.Movement.Instant);
            Add(Chain);

            Boxes = new GenGroup();
            Add(Boxes);

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    Box = new GenSprite(i * 32 + 150, j * 16, GenG.Content.Load<Texture2D>("warthog"), 12, 13);
                    Box.CenterOrigin(false);
                    Box.AddAnimation("run", 16, 16, new int[] { 1 }, 0, false);
                    Box.Play("run");
                    Box.DrawOffset.X = -4;
                    Box.DrawOffset.Y = -3;
                    Box.Mass = 0.5f;
                    Box.Deceleration.X = 400f;
                    Box.Acceleration.Y = 400f;
                    Box.MaxVelocity.Y = 400f;
                    Box.Color = GenU.RandomColor(100, 255);
                    Boxes.Add(Box);
                }
            }

            Emitter = new GenEmitter(100, 100);
            Emitter.Width = 16;
            Emitter.Height = 16;
            Emitter.MakeParticles(GenG.Pixel, 4, 4, 400);
            Emitter.EmitQuantity = 5;
            Emitter.EmitFrequency = .05f;
            Emitter.InheritVelocity = true;
            Emitter.SetXSpeed(-300, 300);
            Emitter.SetYSpeed(-50, 50);
            Emitter.SetRotationSpeed(-360, 360);
            Emitter.SetLifetime(2.9f);
            Emitter.Colors.Add(Color.Cyan);
            Emitter.Colors.Add(Color.MediumVioletRed);
            Emitter.Colors.Add(Color.Orange);
            Emitter.SetAlpha(2f, 0f);
            Emitter.SetScale(2f, 1f);
            //Emitter.SetGravity(0, 700);
            Emitter.SetDeceleration(100, 100);
            Add(Emitter);

            Player = new GenSprite(100, 0, GenG.Content.Load<Texture2D>("player"), 16, 16);
            Player.AddAnimation("idle", 16, 18, new int[] { 0 }, 6, false, 1);
            Player.AddAnimation("run", 16, 18, new int[] { 1, 0, 2, 0 }, 6, true, 1);
            Player.AddAnimation("jump", 16, 18, new int[] { 1 }, 6, false, 1);
            Player.AddAnimation("fall", 16, 18, new int[] { 3 }, 6, false, 1);
            // Adjust the origin to keep the player's feet from visually penetrating a wall when rotated.
            Player.CenterOrigin(false);
            Player.SetOrigin(Player.Origin.X, Player.Origin.Y + 8);
            Player.DrawOffset.Y -= 2;
            Player.RotationSpeed = 45;
            Player.DrawRotated = false;
            Add(Player);

            Emitter.Parent = Player;
            Emitter.ParentOffset.X = -Player.Bounds.HalfWidth;
            Emitter.ParentOffset.Y = -Player.Bounds.Height;
            Emitter.Start(false);

            Warthog3 = new GenSprite(200, 300, GenG.Content.Load<Texture2D>("warthog"), 78, 49);
            Warthog3.Deceleration.X = 400;
            Warthog3.Deceleration.Y = 400;
            Warthog3.MaxVelocity.X = 250;
            Warthog3.MaxVelocity.Y = 400;
            Warthog3.Mass = 2f;
            //Warthog3.IsPlatform = true;
            Warthog3.RotationSpeed = -90;
            //Warthog3.SetParent(Player, GenObject.ParentType.Origin);
            Warthog3.ParentOffset = new Vector2(50, 50);
            Add(Warthog3);

            PlayerControl = new GenControl(Player, GenControl.ControlType.Platformer, GenControl.Movement.Accelerates, GenControl.Stopping.Decelerates);
            PlayerControl.SetMovementSpeed(700, 0, 150, 400, 1000, 0);
            PlayerControl.Gravity.Y = 700;
            PlayerControl.JumpSpeed = 300;
            PlayerControl.IdleAnimation = "idle";
            PlayerControl.MoveAnimation = "run";
            PlayerControl.JumpAnimation = "jump";
            PlayerControl.FallAnimation = "fall";
            PlayerControl.UseSpeedAnimation = true;
            PlayerControl.MinAnimationFps = 1f;
            PlayerControl.JumpCount = 2;
            //PlayerControl.JumpInheritVelocity = true;
            PlayerControl.ButtonsSpecial = GenGamePad.ButtonsSpecial.ThumbStickLeft;
            //PlayerControl.LandCallback = PlayerLand;
            PlayerControl.JumpCallback = PlayerJump;
            Add(PlayerControl);

            Warthog4 = new GenSprite(300, 350, GenG.Content.Load<Texture2D>("warthog"), 78, 49);
            //Warthog4.Immovable = true;
            //Warthog4.IsPlatform = true;
            //Warthog4.Mass = 10f;
            Warthog4.Color = Color.Red;
            Warthog4.SetParent(Warthog3, GenObject.ParentType.Origin);
            Warthog4.ParentOffset.X = 75;
            Warthog4.RotationSpeed = 180;
            Add(Warthog4);

            Warthog5 = new GenSprite(2000, 300, GenG.Content.Load<Texture2D>("warthog"), 78, 49);
            //Warthog5.Acceleration.Y = 700;
            Warthog5.Parent = Warthog4;
            Warthog5.ParentOffset.X = 150;
            Warthog5.Velocity.X = -1000;
            Add(Warthog5);

            //Chain.MakeLink(Warthog3, (GenObject)Chain.Members[14]);
            //Chain.SetRestingDistance(10f);

            Beep = new GenSound(GenG.LoadContent<SoundEffect>("beep"), 1f, true);
            Beep.Follow = Warthog5;
            Beep.Volume = 0.1f;
            Add(Beep);

            /*Text = new GenText("Hello, World!\n------------", 200, 200, 100, 12);
            Text.Scale.X = 0.5f;
            Text.Scale.Y = 0.5f;
            Text.TextAlignment = GenText.TextAlign.Center;
            Text.HasShadow = true;
            Text.ShadowColor = Color.Black;
            //Text.Velocity.X = 100;
            //Text.Velocity.Y = 50;
            Text.ScrollFactor.X = 0f;
            Add(Text);*/

            ProgressBar = new GenProgressBar(100, 100);
            ProgressBar.LoadTexture(GenG.Pixel);
            ProgressBar.SetSourceRect(0, 0, 100, 10);
            ProgressBar.Colors.Add(Color.Red);
            ProgressBar.Colors.Add(Color.Orange);
            ProgressBar.Colors.Add(Color.Green);
            ProgressBar.Colors.Add(Color.CornflowerBlue);
            ProgressBar.Colors.Add(Color.White);
            //ProgressBar.BlendColors = true;
            //ProgressBar.MinCallback = Shake;
            ProgressBar.Rotation = -90;
            ProgressBar.SetParent(Player, GenObject.ParentType.Position);
            ProgressBar.ParentOffset.X = 30;
            Add(ProgressBar);

            /*Cloth = new GenVerlet();
            Cloth.MakeGrid(100, 200, 8, 10, 11);
            Cloth.SetGravity(0f, 700f);
            //Cloth.SetDeceleration(100f, 0f);
            Cloth.LineColor = Color.Gray;
            Cloth.Iterations = 2;*/

            /*for (int i = 0; i < 10; i++)
            {
                ((GenObject)Cloth.Members[i]).Immovable = true;
                ((GenObject)Cloth.Members[i]).Acceleration.Y = 0f;
            }*/

            /*((GenObject)Cloth.Members[0]).Immovable = true;
            ((GenObject)Cloth.Members[0]).Acceleration.Y = 0f;
            ((GenObject)Cloth.Members[5]).Immovable = true;
            ((GenObject)Cloth.Members[5]).Acceleration.Y = 0f;
            ((GenObject)Cloth.Members[10]).Immovable = true;
            ((GenObject)Cloth.Members[10]).Acceleration.Y = 0f;

            Add(Cloth);*/

            GenG.TimeScale = 1f;

            Camera.CameraFollowType = GenCamera.FollowType.LockOn;
            //Camera.FollowStrength = 0.05f;
            //Camera.MaxZoom = 10f;
            Camera.AddTarget(Player);
            //Camera.AddTarget(Warthog3);
            //Camera.SetCameraView(0, 0, GenG.Game.Width, GenG.Game.Height / 2);
            //Camera.Rotation = 180f;

            /*camera2.CameraFollowType = GenCamera.FollowType.LockOn;
            camera2.FollowStrength = 0.05f;
            camera2.AddTarget(Warthog5);*/

            Player.Flicker(40f, 1f, Color.Red, true);
            Player.FadeOut(0.5f);

            //Timer = new GenTimer(1f, KillBox);
            //Add(Timer);
            //Timer.Start();

            //Warthog5.Parent = Player;

            //Boxes.Kill();

            //Warthog3.SetPath(Path);
            //Warthog3.PathSpeed = 100;
        }
Пример #3
0
        /// <summary>
        /// A physical object that can be moved around in screen space.
        /// </summary>
        /// <param name="x">The x position of the top-left corner of the object.</param>
        /// <param name="y">The y position of the top-left corner of the object.</param>
        /// <param name="width">The width of the object.</param>
        /// <param name="height">The height of the object.</param>
        public GenObject(float x, float y, float width, float height)
        {
            _position = new Vector2(x, y);
            _oldPosition = _position;
            _hasMoved = false;
            _bounds = new GenAABB(x, y, width, height);
            _centerPosition = new Vector2(x + _bounds.HalfWidth, y + _bounds.HalfHeight);
            _origin = new Vector2(_bounds.HalfWidth, _bounds.HalfHeight);
            _originPosition = new Vector2(x + _origin.X, y + _origin.Y);
            _boundingRect = new Rectangle(0, 0, (int)width, (int)height);
            _rotation = 0f;
            RotationSpeed = 0f;
            _moveDistance = Vector2.Zero;
            _moveBounds = new GenAABB(x, y, width, height);

            Immovable = false;
            Solid = true;
            Mass = 1f;

            Velocity = Vector2.Zero;
            OldVelocity = Velocity;
            Acceleration = Vector2.Zero;
            Deceleration = Vector2.Zero;
            MaxVelocity = Vector2.Zero;

            _facing = Direction.None;
            OldTouching = Direction.None;
            Touching = Direction.None;

            Parent = null;
            ParentMode = ParentType.None;
            ParentOffset = Vector2.Zero;

            IsPlatform = false;
            Platform = null;
            OldPlatform = null;

            Path = null;
            PathNodeIndex = 0;
            PathDirection = 1;
            PathSpeed = 0f;
            PathType = GenPath.Type.Clockwise;
            PathAxis = GenMove.Axis.Both;
            PathMovement = GenPath.Movement.Instant;
        }