Ejemplo n.º 1
0
 public override void Shoot(World world)
 {
     Rocket rocket1 = Game.Objects.CreateRocket(Owner.Position + new Vector2(-40f * Maf.Cos(Owner.Rotation), -40f * Maf.Sin(Owner.Rotation)), Owner.Speed, Owner.Rotation);
     Rocket rocket2 = Game.Objects.CreateRocket(Owner.Position + new Vector2(40f * Maf.Cos(Owner.Rotation), 40f * Maf.Sin(Owner.Rotation)), Owner.Speed, Owner.Rotation);
     world.Add(rocket1);
     world.Add(rocket2);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            TextureManager.LoadContents(Content);
            FontManager.LoadContents(Content);

            //initializing here because they are dependent on content managers
            background = new Background(Width, Height, TextureManager.GetTexture(TextureNames.BACKGROUND));

            world = WorldGenerator.Generate(WorldNumber.One);
            world.Add(new Player(PlayerNumber.One, new Vector2(200, 200)));
            world.Add(new Player(PlayerNumber.Two, new Vector2(100, 100)));

            ui = new UserInterface();

            mainMenu = new MainMenu();
        }
Ejemplo n.º 3
0
        public override void Shoot(World world)
        {
            var kickRocket = 60f;

            SinPlasmaBullet plasmaBullet = Game.Objects.CreateSinPlasmaBullet();
            plasmaBullet.Size = 10;
            plasmaBullet.Position = Owner.Position + kickRocket * new Vector2(Maf.Sin(Owner.Rotation), -Maf.Cos(Owner.Rotation));
            plasmaBullet.StartSpeed = Owner.Speed + Speed * new Vector2(Maf.Sin(Owner.Rotation), -Maf.Cos(Owner.Rotation));
            plasmaBullet.Speed = plasmaBullet.StartSpeed;
            world.Add(plasmaBullet);
        }
Ejemplo n.º 4
0
        public override void Shoot(World world)
        {
            var kickRocket = 40f;
            int countBullet = 7;

            for (int i = -(countBullet / 2); i < (countBullet / 2) + 1; ++i)
            {
                float rot = Owner.Rotation + i * 0.1f;

                PlasmaBullet plasmaBullet = Game.Objects.CreatePlasmaBullet();
                plasmaBullet.Size = 10;
                plasmaBullet.Position = Owner.Position + kickRocket * new Vector2(Maf.Sin(rot), -Maf.Cos(rot));
                plasmaBullet.Speed = Owner.Speed + Speed * new Vector2(Maf.Sin(rot), -Maf.Cos(rot));
                world.Add(plasmaBullet);
            }
        }
Ejemplo n.º 5
0
 // Use this for initialization
 void Start()
 {
     world = new World();
     world.Add(new Unit());
     world.Add(new WinRule());
 }
Ejemplo n.º 6
0
        public TheoJansenWalker(World world, Vector2 position)
        {
            _position   = position;
            _motorSpeed = 2.0f;
            _motorOn    = true;

            _leftShoulders = new Body[3];
            _leftLegs      = new Body[3];

            _rightShoulders = new Body[3];
            _rightLegs      = new Body[3];

            Vector2 pivot = new Vector2(0f, 0.8f);

            // Chassis
            PolygonShape box = new PolygonShape(1f);

            box.Vertices = PolygonTools.CreateRectangle(2.5f, 1.0f);
            _body        = new Sprite(ContentWrapper.TextureFromShape(box, _walkerColors[0], ContentWrapper.Black, 24f));

            _chassis          = world.CreateBody();
            _chassis.BodyType = BodyType.Dynamic;
            _chassis.Position = pivot + _position;

            Fixture bodyFixture = _chassis.CreateFixture(box);

            bodyFixture.CollisionGroup = -1;

            // Wheel
            CircleShape circle = new CircleShape(1.6f, 1f);

            _engine = new Sprite(ContentWrapper.TextureFromShape(circle, "Stripe", _walkerColors[1] * 0.6f, _walkerColors[2] * 0.8f, ContentWrapper.Black, 3f, 24f));

            _wheel          = world.CreateBody();
            _wheel.BodyType = BodyType.Dynamic;
            _wheel.Position = pivot + _position;

            Fixture wheelFixture = _wheel.CreateFixture(circle);

            wheelFixture.CollisionGroup = -1;

            // Physics
            _motorJoint = new RevoluteJoint(_wheel, _chassis, _chassis.Position, true);
            _motorJoint.CollideConnected = false;
            _motorJoint.MotorSpeed       = _motorSpeed;
            _motorJoint.MaxMotorTorque   = 400f;
            _motorJoint.MotorEnabled     = _motorOn;
            world.Add(_motorJoint);

            Vector2 wheelAnchor = pivot + new Vector2(0f, -0.8f);

            CreateLeg(world, -1f, wheelAnchor, out _leftShoulders[0], out _leftLegs[0]);
            CreateLeg(world, 1f, wheelAnchor, out _rightShoulders[0], out _rightLegs[0]);

            _wheel.SetTransform(_wheel.Position, 120f * MathHelper.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, out _leftShoulders[1], out _leftLegs[1]);
            CreateLeg(world, 1f, wheelAnchor, out _rightShoulders[1], out _rightLegs[1]);

            _wheel.SetTransform(_wheel.Position, -120f * MathHelper.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, out _leftShoulders[2], out _leftLegs[2]);
            CreateLeg(world, 1f, wheelAnchor, out _rightShoulders[2], out _rightLegs[2]);

            CreateLegTextures();
        }
Ejemplo n.º 7
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0f, -10f);

            HasCursor           = false;
            EnableCameraControl = true;

            _hzFront  = 8.5f;
            _hzBack   = 5.0f;
            _zeta     = 0.85f;
            _maxSpeed = 50.0f;

            // terrain
            _ground = World.CreateBody();
            {
                Vertices terrain = new Vertices();
                terrain.Add(new Vector2(-20f, 5f));
                terrain.Add(new Vector2(-20f, 0f));
                terrain.Add(new Vector2(20f, 0f));
                terrain.Add(new Vector2(25f, 0.25f));
                terrain.Add(new Vector2(30f, 1f));
                terrain.Add(new Vector2(35f, 4f));
                terrain.Add(new Vector2(40f, 0f));
                terrain.Add(new Vector2(45f, 0f));
                terrain.Add(new Vector2(50f, -1f));
                terrain.Add(new Vector2(55f, -2f));
                terrain.Add(new Vector2(60f, -2f));
                terrain.Add(new Vector2(65f, -1.25f));
                terrain.Add(new Vector2(70f, 0f));
                terrain.Add(new Vector2(75f, 0.3f));
                terrain.Add(new Vector2(80f, 1.5f));
                terrain.Add(new Vector2(85f, 3.5f));
                terrain.Add(new Vector2(90f, 0f));
                terrain.Add(new Vector2(95f, -0.5f));
                terrain.Add(new Vector2(100f, -1f));
                terrain.Add(new Vector2(105f, -2f));
                terrain.Add(new Vector2(110f, -2.5f));
                terrain.Add(new Vector2(115f, -1.3f));
                terrain.Add(new Vector2(120f, 0f));
                terrain.Add(new Vector2(160f, 0f));
                terrain.Add(new Vector2(159f, -10f));
                terrain.Add(new Vector2(201f, -10f));
                terrain.Add(new Vector2(200f, 0f));
                terrain.Add(new Vector2(240f, 0f));
                terrain.Add(new Vector2(250f, 5f));
                terrain.Add(new Vector2(250f, -10f));
                terrain.Add(new Vector2(270f, -10f));
                terrain.Add(new Vector2(270f, 0));
                terrain.Add(new Vector2(310f, 0));
                terrain.Add(new Vector2(310f, 5));

                for (int i = 0; i < terrain.Count - 1; ++i)
                {
                    _ground.CreateEdge(terrain[i], terrain[i + 1]);
                }

                _ground.SetFriction(0.6f);
            }

            // teeter board
            {
                _board          = World.CreateBody();
                _board.BodyType = BodyType.Dynamic;
                _board.Position = new Vector2(140.0f, 1.0f);

                PolygonShape box = new PolygonShape(1f);
                box.Vertices = PolygonTools.CreateRectangle(20.0f / 2f, 0.5f / 2f);
                _teeter      = new Sprite(ContentWrapper.TextureFromShape(box, "Stripe", ContentWrapper.Gold, ContentWrapper.Black, ContentWrapper.Black, 1f, 24f));

                _board.CreateFixture(box);

                RevoluteJoint teeterAxis = JointFactory.CreateRevoluteJoint(World, _ground, _board, Vector2.Zero);
                teeterAxis.LowerLimit   = -8.0f * MathHelper.Pi / 180.0f;
                teeterAxis.UpperLimit   = 8.0f * MathHelper.Pi / 180.0f;
                teeterAxis.LimitEnabled = true;

                _board.ApplyAngularImpulse(100.0f);
            }

            // bridge
            {
                _bridgeSegments = new List <Body>();

                const int    segmentCount = 20;
                PolygonShape shape        = new PolygonShape(1f);
                shape.Vertices = PolygonTools.CreateRectangle(1.0f, 0.125f);

                _bridge = new Sprite(ContentWrapper.TextureFromShape(shape, ContentWrapper.Gold, ContentWrapper.Black, 24f));

                Body prevBody = _ground;
                for (int i = 0; i < segmentCount; ++i)
                {
                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(161f + 2f * i, -0.125f);
                    Fixture fix = body.CreateFixture(shape);
                    fix.Friction = 0.6f;
                    JointFactory.CreateRevoluteJoint(World, prevBody, body, -Vector2.UnitX);

                    prevBody = body;
                    _bridgeSegments.Add(body);
                }
                JointFactory.CreateRevoluteJoint(World, _ground, prevBody, Vector2.UnitX);
            }

            // boxes
            {
                _boxes = new List <Body>();
                PolygonShape box = new PolygonShape(1f);
                box.Vertices = PolygonTools.CreateRectangle(0.5f, 0.5f);
                _box         = new Sprite(ContentWrapper.TextureFromShape(box, "Square", ContentWrapper.Sky, ContentWrapper.Sunset, ContentWrapper.Black, 1f, 24f));

                Body body = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, 0.5f);
                body.CreateFixture(box);
                _boxes.Add(body);

                body          = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, 1.5f);
                body.CreateFixture(box);
                _boxes.Add(body);

                body          = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, 2.5f);
                body.CreateFixture(box);
                _boxes.Add(body);
            }

            // car
            {
                Vertices vertices = new Vertices(8);
                vertices.Add(new Vector2(-2.5f, -0.08f));
                vertices.Add(new Vector2(-2.375f, 0.46f));
                vertices.Add(new Vector2(-0.58f, 0.92f));
                vertices.Add(new Vector2(0.46f, 0.92f));
                vertices.Add(new Vector2(2.5f, 0.17f));
                vertices.Add(new Vector2(2.5f, -0.205f));
                vertices.Add(new Vector2(2.3f, -0.33f));
                vertices.Add(new Vector2(-2.25f, -0.35f));

                PolygonShape chassis = new PolygonShape(vertices, 2f);

                _car          = World.CreateBody();
                _car.BodyType = BodyType.Dynamic;
                _car.Position = new Vector2(0.0f, 1.0f);
                _car.CreateFixture(chassis);

                _wheelBack          = World.CreateBody();
                _wheelBack.BodyType = BodyType.Dynamic;
                _wheelBack.Position = new Vector2(-1.709f, 0.78f);
                Fixture fix = _wheelBack.CreateFixture(new CircleShape(0.5f, 0.8f));
                fix.Friction = 0.9f;

                _wheelFront          = World.CreateBody();
                _wheelFront.BodyType = BodyType.Dynamic;
                _wheelFront.Position = new Vector2(1.54f, 0.8f);
                _wheelFront.CreateFixture(new CircleShape(0.5f, 1f));

                Vector2 axis = new Vector2(0.0f, 1.2f);
                _springBack                = new WheelJoint(_car, _wheelBack, _wheelBack.Position, axis, true);
                _springBack.MotorSpeed     = 0.0f;
                _springBack.MaxMotorTorque = 20.0f;
                _springBack.MotorEnabled   = true;
                _springBack.Frequency      = _hzBack;
                _springBack.DampingRatio   = _zeta;
                World.Add(_springBack);

                _springFront                = new WheelJoint(_car, _wheelFront, _wheelFront.Position, axis, true);
                _springFront.MotorSpeed     = 0.0f;
                _springFront.MaxMotorTorque = 10.0f;
                _springFront.MotorEnabled   = false;
                _springFront.Frequency      = _hzFront;
                _springFront.DampingRatio   = _zeta;
                World.Add(_springFront);

                // GFX
                _carBody = new Sprite(ContentWrapper.GetTexture("Car"), ContentWrapper.CalculateOrigin(_car, 24f));
                _wheel   = new Sprite(ContentWrapper.GetTexture("Wheel"));
            }

            Camera.MinRotation = -0.05f;
            Camera.MaxRotation = 0.05f;

            Camera.TrackingBody   = _car;
            Camera.EnableTracking = true;
        }
Ejemplo n.º 8
0
        private WebTest()
        {
            World.JointRemoved += JointRemovedFired;
            World.BodyRemoved  += BodyRemovedFired;

            Body ground = World.CreateEdge(new Vector2(-40, 0), new Vector2(40, 0));

            {
                _bodies[0]          = World.CreateRectangle(1f, 1f, 5, new Vector2(-5.0f, 5.0f));
                _bodies[0].BodyType = BodyType.Dynamic;

                _bodies[1]          = World.CreateRectangle(1f, 1f, 5, new Vector2(5.0f, 5.0f));
                _bodies[1].BodyType = BodyType.Dynamic;

                _bodies[2]          = World.CreateRectangle(1f, 1f, 5, new Vector2(5.0f, 15.0f));
                _bodies[2].BodyType = BodyType.Dynamic;

                _bodies[3]          = World.CreateRectangle(1f, 1f, 5, new Vector2(-5.0f, 15.0f));
                _bodies[3].BodyType = BodyType.Dynamic;

                DistanceJoint dj = new DistanceJoint(ground, _bodies[0], new Vector2(-10.0f, 0.0f), new Vector2(-0.5f, -0.5f));
                _joints[0]      = dj;
                dj.Frequency    = 2.0f;
                dj.DampingRatio = 0.0f;
                World.Add(_joints[0]);

                DistanceJoint dj1 = new DistanceJoint(ground, _bodies[1], new Vector2(10.0f, 0.0f), new Vector2(0.5f, -0.5f));
                _joints[1]       = dj1;
                dj1.Frequency    = 2.0f;
                dj1.DampingRatio = 0.0f;
                World.Add(_joints[1]);

                DistanceJoint dj2 = new DistanceJoint(ground, _bodies[2], new Vector2(10.0f, 20.0f), new Vector2(0.5f, 0.5f));
                _joints[2]       = dj2;
                dj2.Frequency    = 2.0f;
                dj2.DampingRatio = 0.0f;
                World.Add(_joints[2]);

                DistanceJoint dj3 = new DistanceJoint(ground, _bodies[3], new Vector2(-10.0f, 20.0f), new Vector2(-0.5f, 0.5f));
                _joints[3]       = dj3;
                dj3.Frequency    = 2.0f;
                dj3.DampingRatio = 0.0f;
                World.Add(_joints[3]);

                DistanceJoint dj4 = new DistanceJoint(_bodies[0], _bodies[1], new Vector2(0.5f, 0.0f), new Vector2(-0.5f, 0.0f));
                _joints[4]       = dj4;
                dj4.Frequency    = 2.0f;
                dj4.DampingRatio = 0.0f;
                World.Add(_joints[4]);

                DistanceJoint dj5 = new DistanceJoint(_bodies[1], _bodies[2], new Vector2(0.0f, 0.5f), new Vector2(0.0f, -0.5f));
                _joints[5]       = dj5;
                dj5.Frequency    = 2.0f;
                dj5.DampingRatio = 0.0f;
                World.Add(_joints[5]);

                DistanceJoint dj6 = new DistanceJoint(_bodies[2], _bodies[3], new Vector2(-0.5f, 0.0f), new Vector2(0.5f, 0.0f));
                _joints[6]       = dj6;
                dj6.Frequency    = 2.0f;
                dj6.DampingRatio = 0.0f;
                World.Add(_joints[6]);

                DistanceJoint dj7 = new DistanceJoint(_bodies[3], _bodies[0], new Vector2(0.0f, -0.5f), new Vector2(0.0f, 0.5f));
                _joints[7]       = dj7;
                dj7.Frequency    = 2.0f;
                dj7.DampingRatio = 0.0f;
                World.Add(_joints[7]);
            }
        }
Ejemplo n.º 9
0
        private PinballTest()
        {
            // Ground body
            Body ground;
            {
                ground = World.CreateBody();

                Vertices vertices = new Vertices(5);
                vertices.Add(new Vector2(0.0f, -2.0f));
                vertices.Add(new Vector2(8.0f, 6.0f));
                vertices.Add(new Vector2(8.0f, 20.0f));
                vertices.Add(new Vector2(-8.0f, 20.0f));
                vertices.Add(new Vector2(-8.0f, 6.0f));

                ChainShape chain = new ChainShape(vertices, true);
                ground.CreateFixture(chain);
            }

            // Flippers
            {
                Vector2 p1 = new Vector2(-2.0f, 0f);
                Vector2 p2 = new Vector2(2.0f, 0f);

                Body leftFlipper = World.CreateBody(p1);
                leftFlipper.BodyType = BodyType.Dynamic;
                Body rightFlipper = World.CreateBody(p2);
                rightFlipper.BodyType = BodyType.Dynamic;

                PolygonShape box = new PolygonShape(1);
                box.Vertices = PolygonTools.CreateRectangle(1.75f, 0.1f);

                leftFlipper.CreateFixture(box);
                rightFlipper.CreateFixture(box);

                _leftJoint = new RevoluteJoint(ground, leftFlipper, p1, Vector2.Zero);
                _leftJoint.MaxMotorTorque = 1000.0f;
                _leftJoint.LimitEnabled   = true;
                _leftJoint.MotorEnabled   = true;
                _leftJoint.MotorSpeed     = 0.0f;
                _leftJoint.LowerLimit     = -30.0f * MathHelper.Pi / 180.0f;
                _leftJoint.UpperLimit     = 5.0f * MathHelper.Pi / 180.0f;
                World.Add(_leftJoint);

                _rightJoint = new RevoluteJoint(ground, rightFlipper, p2, Vector2.Zero);
                _rightJoint.MaxMotorTorque = 1000.0f;
                _rightJoint.LimitEnabled   = true;
                _rightJoint.MotorEnabled   = true;
                _rightJoint.MotorSpeed     = 0.0f;
                _rightJoint.LowerLimit     = -5.0f * MathHelper.Pi / 180.0f;
                _rightJoint.UpperLimit     = 30.0f * MathHelper.Pi / 180.0f;
                World.Add(_rightJoint);
            }

            // Circle character
            {
                _ball          = World.CreateBody(new Vector2(1.0f, 15.0f));
                _ball.BodyType = BodyType.Dynamic;
                _ball.IsBullet = true;
                _ball.CreateFixture(new CircleShape(0.2f, 1.0f));
            }
        }
Ejemplo n.º 10
0
        private TheoJansenTest()
        {
            _offset     = new Vector2(0.0f, 8.0f);
            _motorSpeed = 2.0f;
            _motorOn    = true;
            Vector2 pivot = new Vector2(0.0f, 0.8f);

            // Ground
            {
                Body ground = World.CreateEdge(new Vector2(-50.0f, 0.0f), new Vector2(50.0f, 0.0f));
                ground.CreateEdge(new Vector2(-50.0f, 0.0f), new Vector2(-50.0f, 10.0f));
                ground.CreateEdge(new Vector2(50.0f, 0.0f), new Vector2(50.0f, 10.0f));
            }

            // Balls
            for (int i = 0; i < 40; ++i)
            {
                CircleShape shape = new CircleShape(0.25f, 1);

                Body body = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(-40.0f + 2.0f * i, 0.5f);

                body.CreateFixture(shape);
            }

            // Chassis
            {
                PolygonShape shape = new PolygonShape(1);
                shape.Vertices = PolygonTools.CreateRectangle(2.5f, 1.0f);

                _chassis          = World.CreateBody();
                _chassis.BodyType = BodyType.Dynamic;
                _chassis.Position = pivot + _offset;

                Fixture fixture = _chassis.CreateFixture(shape);
                fixture.CollisionGroup = -1;
            }

            {
                CircleShape shape = new CircleShape(1.6f, 1);

                _wheel          = World.CreateBody();
                _wheel.BodyType = BodyType.Dynamic;
                _wheel.Position = pivot + _offset;

                Fixture fixture = _wheel.CreateFixture(shape);
                fixture.CollisionGroup = -1;
            }

            {
                _motorJoint = new RevoluteJoint(_wheel, _chassis, _chassis.Position, true);
                _motorJoint.CollideConnected = false;
                _motorJoint.MotorSpeed       = _motorSpeed;
                _motorJoint.MaxMotorTorque   = 400.0f;
                _motorJoint.MotorEnabled     = _motorOn;
                World.Add(_motorJoint);
            }

            Vector2 wheelAnchor = pivot + new Vector2(0.0f, -0.8f);

            CreateLeg(-1.0f, wheelAnchor);
            CreateLeg(1.0f, wheelAnchor);

            _wheel.SetTransform(_wheel.Position, 120.0f * MathHelper.Pi / 180.0f);
            CreateLeg(-1.0f, wheelAnchor);
            CreateLeg(1.0f, wheelAnchor);

            _wheel.SetTransform(_wheel.Position, -120.0f * MathHelper.Pi / 180.0f);
            CreateLeg(-1.0f, wheelAnchor);
            CreateLeg(1.0f, wheelAnchor);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Erzeugt eine neue Instanz eines CreativeModeScreen-Objekts und initialisiert diese mit einem Knot3Game-Objekt game, sowie einem Knoten knot.
        /// </summary>
        public VisualTestsScreen(GameCore game)
            : base(game)
        {
            // die Spielwelt
            world = new World (screen: this, drawOrder: DisplayLayer.GameWorld, bounds: Bounds.FromLeft (0.60f));

            // der Knoten-Renderer
            knotRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            world.Add (knotRenderer);

            // Hintergrund
            //SkyCube skyCube = new SkyCube (screen: this, position: Vector3.Zero, distance: world.Camera.MaxPositionDistance + 500);
            //world.Add (skyCube);

            // Menü
            settingsMenu = new Menu (this, DisplayLayer.Overlay + DisplayLayer.Menu);
            settingsMenu.Bounds = Bounds.FromRight (0.40f).FromBottom (0.9f).FromLeft (0.8f);
            settingsMenu.Bounds.Padding = new ScreenPoint (this, 0.010f, 0.010f);
            settingsMenu.RelativeItemHeight = 0.030f;

            float[] validEdgeCounts = new float[] { 500, 1000, 2000, 3000, 4000, 5000, 7500, 10000, 15000 };
            optionEdgeCount = new FloatOption (
                section: "visualtests",
                name: "edgecount",
                defaultValue: validEdgeCounts.At (0),
                validValues: validEdgeCounts,
                configFile: Config.Default
            ) { Verbose = false };
            optionEdgeCount.Value = validEdgeCounts.At (0);
            itemEdgeCount = new ComboBox (
                screen: this,
                drawOrder: DisplayLayer.Overlay + DisplayLayer.MenuItem,
                text: "Edges:"
            );
            itemEdgeCount.AddEntries (optionEdgeCount);
            itemEdgeCount.ValueChanged += OnEdgeCountChanged;

            itemDisplayTime = new InputItem (
                screen: this,
                drawOrder: DisplayLayer.Overlay + DisplayLayer.MenuItem,
                text: "Time:",
                inputText: ""
            );

            itemFPS = new InputItem (
                screen: this,
                drawOrder: DisplayLayer.Overlay + DisplayLayer.MenuItem,
                text: "FPS:",
                inputText: ""
            );

            OnEdgeCountChanged (null);
        }
Ejemplo n.º 12
0
        public WarheadTrailProjectile(WarheadTrailProjectileInfo info, ProjectileArgs args)
        {
            this.info = info;
            this.args = args;

            projectilepos = args.Source;
            sourcepos     = args.Source;

            var firedBy = args.SourceActor;

            world = args.SourceActor.World;

            if (info.Speed.Length > 1)
            {
                speed = new WDist(world.SharedRandom.Next(info.Speed[0].Length, info.Speed[1].Length));
            }
            else
            {
                speed = info.Speed[0];
            }

            targetpos = GetTargetPos();

            mindelay = args.Weapon.MinRange.Length / speed.Length;

            projectiles = new WarheadTrailProjectileEffect[info.Offsets.Count()];
            var range      = OpenRA.Mods.Common.Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers);
            var mainFacing = (targetpos - sourcepos).Yaw.Facing;

            // used for lerping projectiles at the same pace
            var estimatedLifespan = Math.Max(args.Weapon.Range.Length / speed.Length, 1);

            // target that will be assigned
            Target target;

            // subprojectiles facing
            int facing = 0;

            for (int i = 0; i < info.Offsets.Count(); i++)
            {
                switch (info.FireMode)
                {
                case FireMode.Focus:
                    offsetRotation  = WRot.FromFacing(mainFacing);
                    offsetTargetPos = sourcepos + new WVec(range, 0, 0).Rotate(offsetRotation);
                    offsetSourcePos = sourcepos + info.Offsets[i].Rotate(offsetRotation);
                    break;

                case FireMode.Line:
                    offsetRotation  = WRot.FromFacing(mainFacing);
                    offsetTargetPos = sourcepos + new WVec(range + info.Offsets[i].X, info.Offsets[i].Y, info.Offsets[i].Z).Rotate(offsetRotation);
                    offsetSourcePos = sourcepos + info.Offsets[i].Rotate(offsetRotation);
                    break;

                case FireMode.Spread:
                    offsetRotation  = WRot.FromFacing(info.Offsets[i].Yaw.Facing - 64) + WRot.FromFacing(mainFacing);
                    offsetSourcePos = sourcepos + info.Offsets[i].Rotate(offsetRotation);
                    offsetTargetPos = sourcepos + new WVec(range + info.Offsets[i].X, info.Offsets[i].Y, info.Offsets[i].Z).Rotate(offsetRotation);
                    break;
                }

                if (info.Inaccuracy.Length > 0)
                {
                    var inaccuracy       = OpenRA.Mods.Common.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
                    var maxOffset        = inaccuracy * (args.PassiveTarget - projectilepos).Length / range;
                    var inaccuracyOffset = WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
                    offsetTargetPos += inaccuracyOffset;
                }

                target = Target.FromPos(offsetTargetPos);

                // If it's true then lifespan is counted from source position to target instead of max range.
                lifespan = info.KillProjectilesWhenReachedTargetLocation
                                        ? Math.Max((args.PassiveTarget - args.Source).Length / speed.Length, 1)
                                        : estimatedLifespan;

                facing = (offsetTargetPos - offsetSourcePos).Yaw.Facing;
                var projectileArgs = new ProjectileArgs
                {
                    Weapon          = args.Weapon,
                    DamageModifiers = args.DamageModifiers,
                    Facing          = facing,
                    Source          = offsetSourcePos,
                    CurrentSource   = () => offsetSourcePos,
                    SourceActor     = firedBy,
                    PassiveTarget   = target.CenterPosition
                };

                projectiles[i] = new WarheadTrailProjectileEffect(info, projectileArgs, lifespan, estimatedLifespan);
                world.Add(projectiles[i]);
            }
        }
Ejemplo n.º 13
0
        private void CreateLeg(float s, Vector2 wheelAnchor)
        {
            Vector2 p1 = new Vector2(5.4f * s, -6.1f);
            Vector2 p2 = new Vector2(7.2f * s, -1.2f);
            Vector2 p3 = new Vector2(4.3f * s, -1.9f);
            Vector2 p4 = new Vector2(3.1f * s, 0.8f);
            Vector2 p5 = new Vector2(6.0f * s, 1.5f);
            Vector2 p6 = new Vector2(2.5f * s, 3.7f);

            PolygonShape poly1 = new PolygonShape(1);
            PolygonShape poly2 = new PolygonShape(1);

            Vertices vertices = new Vertices(3);

            if (s > 0.0f)
            {
                vertices.Add(p1);
                vertices.Add(p2);
                vertices.Add(p3);
                poly1.Vertices = vertices;

                vertices[0]    = Vector2.Zero;
                vertices[1]    = p5 - p4;
                vertices[2]    = p6 - p4;
                poly2.Vertices = vertices;
            }
            else
            {
                vertices.Add(p1);
                vertices.Add(p3);
                vertices.Add(p2);
                poly1.Vertices = vertices;

                vertices[0]    = Vector2.Zero;
                vertices[1]    = p6 - p4;
                vertices[2]    = p5 - p4;
                poly2.Vertices = vertices;
            }

            Body body1 = World.CreateBody();

            body1.BodyType       = BodyType.Dynamic;
            body1.Position       = _offset;
            body1.AngularDamping = 10.0f;

            Body body2 = World.CreateBody();

            body2.BodyType       = BodyType.Dynamic;
            body2.Position       = p4 + _offset;
            body2.AngularDamping = 10.0f;

            Fixture f1 = body1.CreateFixture(poly1);

            f1.CollisionGroup = -1;

            Fixture f2 = body2.CreateFixture(poly2);

            f2.CollisionGroup = -1;

            // Using a soft distanceraint can reduce some jitter.
            // It also makes the structure seem a bit more fluid by
            // acting like a suspension system.
            DistanceJoint djd = new DistanceJoint(body1, body2, p2 + _offset, p5 + _offset, true);

            djd.DampingRatio = 0.5f;
            djd.Frequency    = 10.0f;

            World.Add(djd);

            DistanceJoint djd2 = new DistanceJoint(body1, body2, p3 + _offset, p4 + _offset, true);

            djd2.DampingRatio = 0.5f;
            djd2.Frequency    = 10.0f;

            World.Add(djd2);

            DistanceJoint djd3 = new DistanceJoint(body1, _wheel, p3 + _offset, wheelAnchor + _offset, true);

            djd3.DampingRatio = 0.5f;
            djd3.Frequency    = 10.0f;

            World.Add(djd3);

            DistanceJoint djd4 = new DistanceJoint(body2, _wheel, p6 + _offset, wheelAnchor + _offset, true);

            djd4.DampingRatio = 0.5f;
            djd4.Frequency    = 10.0f;

            World.Add(djd4);

            Vector2       anchor = p4 - new Vector2(0.0f, 0.8f) /*+ _offset*/;
            RevoluteJoint rjd    = new RevoluteJoint(body2, _chassis, p4 + _offset, true);

            World.Add(rjd);
        }
Ejemplo n.º 14
0
        public Overlay(IScreen screen, World world)
            : base(screen, DisplayLayer.Overlay)
        {
            // game world
            World = world;

            // create a new SpriteBatch, which can be used to draw textures
            effect = new BasicEffect (screen.GraphicsDevice);
            spriteBatch = new SpriteBatch (screen.GraphicsDevice);
            effect.VertexColorEnabled = true;
            effect.World = Matrix.CreateFromYawPitchRoll (0, 0, 0);
            if (Config.Default ["video", "camera-overlay", false]) {
                debugModel = new DebugModel (screen: screen);
                world.Add (debugModel);
            }

            // load fonts
            try {
                font = Screen.LoadFont ("font-overlay");
            }
            catch (ContentLoadException ex) {
                font = null;
                Log.Debug (ex.Message);
            }
        }
        private CollisionFilteringTest()
        {
            //Ground
            World.CreateEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            {
                // Small triangle
                Vertices vertices = new Vertices(3);
                vertices.Add(new Vector2(-1.0f, 0.0f));
                vertices.Add(new Vector2(1.0f, 0.0f));
                vertices.Add(new Vector2(0.0f, 2.0f));
                PolygonShape polygon = new PolygonShape(vertices, 1);

                Body triangleBody = World.CreateBody();
                triangleBody.BodyType = BodyType.Dynamic;
                triangleBody.Position = new Vector2(-5.0f, 2.0f);

                Fixture triangleFixture = triangleBody.CreateFixture(polygon);
                triangleFixture.CollisionGroup      = SmallGroup;
                triangleFixture.CollisionCategories = TriangleCategory;
                triangleFixture.CollidesWith        = TriangleMask;

                // Large triangle (recycle definitions)
                vertices[0]     *= 2.0f;
                vertices[1]     *= 2.0f;
                vertices[2]     *= 2.0f;
                polygon.Vertices = vertices;

                Body triangleBody2 = World.CreateBody();
                triangleBody2.BodyType      = BodyType.Dynamic;
                triangleBody2.Position      = new Vector2(-5.0f, 6.0f);
                triangleBody2.FixedRotation = true; // look at me!

                Fixture triangleFixture2 = triangleBody2.CreateFixture(polygon);
                triangleFixture2.CollisionGroup      = LargeGroup;
                triangleFixture2.CollisionCategories = TriangleCategory;
                triangleFixture2.CollidesWith        = TriangleMask;

                {
                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(-5.0f, 10.0f);

                    Vertices     box = PolygonTools.CreateRectangle(0.5f, 1.0f);
                    PolygonShape p   = new PolygonShape(box, 1);
                    body.CreateFixture(p);

                    PrismaticJoint jd = new PrismaticJoint(triangleBody2, body, new Vector2(0, 4), Vector2.Zero, new Vector2(0.0f, 1.0f));
                    jd.LimitEnabled = true;
                    jd.LowerLimit   = -1.0f;
                    jd.UpperLimit   = 1.0f;

                    World.Add(jd);
                }

                // Small box
                polygon.Vertices = PolygonTools.CreateRectangle(1.0f, 0.5f);

                Body boxBody = World.CreateBody();
                boxBody.BodyType = BodyType.Dynamic;
                boxBody.Position = new Vector2(0.0f, 2.0f);

                Fixture boxFixture = boxBody.CreateFixture(polygon);
                boxFixture.Restitution = 0.1f;

                boxFixture.CollisionGroup      = SmallGroup;
                boxFixture.CollisionCategories = BoxCategory;
                boxFixture.CollidesWith        = BoxMask;

                // Large box (recycle definitions)
                polygon.Vertices = PolygonTools.CreateRectangle(2, 1);

                Body boxBody2 = World.CreateBody();
                boxBody2.BodyType = BodyType.Dynamic;
                boxBody2.Position = new Vector2(0.0f, 6.0f);

                Fixture boxFixture2 = boxBody2.CreateFixture(polygon);
                boxFixture2.CollisionGroup      = LargeGroup;
                boxFixture2.CollisionCategories = BoxCategory;
                boxFixture2.CollidesWith        = BoxMask;

                // Small circle
                CircleShape circle = new CircleShape(1.0f, 1);

                Body circleBody = World.CreateBody();
                circleBody.BodyType = BodyType.Dynamic;
                circleBody.Position = new Vector2(5.0f, 2.0f);

                Fixture circleFixture = circleBody.CreateFixture(circle);

                circleFixture.CollisionGroup      = SmallGroup;
                circleFixture.CollisionCategories = CircleCategory;
                circleFixture.CollidesWith        = CircleMask;

                // Large circle
                circle.Radius *= 2.0f;

                Body circleBody2 = World.CreateBody();
                circleBody2.BodyType = BodyType.Dynamic;
                circleBody2.Position = new Vector2(5.0f, 6.0f);

                Fixture circleFixture2 = circleBody2.CreateFixture(circle);
                circleFixture2.CollisionGroup      = LargeGroup;
                circleFixture2.CollisionCategories = CircleCategory;
                circleFixture2.CollidesWith        = CircleMask;

                // Large circle - Ignore with other large circle
                Body circleBody3 = World.CreateBody();
                circleBody3.BodyType = BodyType.Dynamic;
                circleBody3.Position = new Vector2(6.0f, 9.0f);

                //Another large circle. This one uses IgnoreCollisionWith() logic instead of categories.
                circleFixture3 = circleBody3.CreateFixture(circle);
                circleFixture3.CollisionGroup      = LargeGroup;
                circleFixture3.CollisionCategories = CircleCategory;
                circleFixture3.CollidesWith        = CircleMask;

                circleFixture3.BeforeCollision = circleFixture3_BeforeCollision;
            }
        }
Ejemplo n.º 16
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0f, -10f);

            HasCursor           = false;
            EnableCameraControl = true;
            HasVirtualStick     = true;

            // terrain
            _ground = World.CreateBody();
            {
                Vertices terrain = new Vertices();
                terrain.Add(new Vector2(-20f, 5f));
                terrain.Add(new Vector2(-20f, 0f));
                terrain.Add(new Vector2(20f, 0f));
                terrain.Add(new Vector2(25f, 0.25f));
                terrain.Add(new Vector2(30f, 1f));
                terrain.Add(new Vector2(35f, 4f));
                terrain.Add(new Vector2(40f, 0f));
                terrain.Add(new Vector2(45f, 0f));
                terrain.Add(new Vector2(50f, -1f));
                terrain.Add(new Vector2(55f, -2f));
                terrain.Add(new Vector2(60f, -2f));
                terrain.Add(new Vector2(65f, -1.25f));
                terrain.Add(new Vector2(70f, 0f));
                terrain.Add(new Vector2(75f, 0.3f));
                terrain.Add(new Vector2(80f, 1.5f));
                terrain.Add(new Vector2(85f, 3.5f));
                terrain.Add(new Vector2(90f, 0f));
                terrain.Add(new Vector2(95f, -0.5f));
                terrain.Add(new Vector2(100f, -1f));
                terrain.Add(new Vector2(105f, -2f));
                terrain.Add(new Vector2(110f, -2.5f));
                terrain.Add(new Vector2(115f, -1.3f));
                terrain.Add(new Vector2(120f, 0f));
                terrain.Add(new Vector2(160f, 0f));
                terrain.Add(new Vector2(159f, -10f));
                terrain.Add(new Vector2(201f, -10f));
                terrain.Add(new Vector2(200f, 0f));
                terrain.Add(new Vector2(240f, 0f));
                terrain.Add(new Vector2(250f, 5f));
                terrain.Add(new Vector2(250f, -10f));
                terrain.Add(new Vector2(270f, -10f));
                terrain.Add(new Vector2(270f, 0));
                terrain.Add(new Vector2(310f, 0));
                terrain.Add(new Vector2(310f, 5));

                for (int i = 0; i < terrain.Count - 1; ++i)
                {
                    var gfixture = _ground.CreateEdge(terrain[i], terrain[i + 1]);
                    gfixture.Friction = 0.6f;
                }
            }

            // teeter board
            {
                _board          = World.CreateBody();
                _board.BodyType = BodyType.Dynamic;
                _board.Position = new Vector2(140.0f, 1.0f);

                PolygonShape box = new PolygonShape(PolygonTools.CreateRectangle(20.0f / 2f, 0.5f / 2f), 1);
                _teeter =
                    new Sprite(ScreenManager.Assets.TextureFromShape(box, MaterialType.Pavement, Color.LightGray, 1.2f));

                _board.CreateFixture(box);

                RevoluteJoint teeterAxis = JointFactory.CreateRevoluteJoint(World, _ground, _board, Vector2.Zero);
                teeterAxis.LowerLimit   = -8.0f * MathHelper.Pi / 180.0f;
                teeterAxis.UpperLimit   = 8.0f * MathHelper.Pi / 180.0f;
                teeterAxis.LimitEnabled = true;

                _board.ApplyAngularImpulse(100.0f);
            }

            // bridge
            {
                _bridgeSegments = new List <Body>();

                const int    segmentCount = 20;
                PolygonShape shape        = new PolygonShape(PolygonTools.CreateRectangle(1.0f, 0.125f), 1f);
                _bridge = new Sprite(ScreenManager.Assets.TextureFromShape(shape, MaterialType.Dots, Color.SandyBrown, 1f));

                Body prevBody = _ground;
                for (int i = 0; i < segmentCount; ++i)
                {
                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(161f + 2f * i, -0.125f);
                    Fixture fix = body.CreateFixture(shape);
                    fix.Friction = 0.6f;
                    JointFactory.CreateRevoluteJoint(World, prevBody, body, -Vector2.UnitX);

                    prevBody = body;
                    _bridgeSegments.Add(body);
                }
                JointFactory.CreateRevoluteJoint(World, _ground, prevBody, Vector2.UnitX);
            }

            // boxes
            {
                _boxes = new List <Body>();
                PolygonShape box = new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f), 1f);
                _box = new Sprite(ScreenManager.Assets.TextureFromShape(box, MaterialType.Squares, Color.SaddleBrown, 2f));

                Body body = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, 0.5f);
                body.CreateFixture(box);
                _boxes.Add(body);

                body          = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, 1.5f);
                body.CreateFixture(box);
                _boxes.Add(body);

                body          = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, 2.5f);
                body.CreateFixture(box);
                _boxes.Add(body);
            }

            // car
            {
                Vertices vertices = new Vertices(8);
                vertices.Add(new Vector2(-2.5f, -0.08f));
                vertices.Add(new Vector2(-2.375f, 0.46f));
                vertices.Add(new Vector2(-0.58f, 0.92f));
                vertices.Add(new Vector2(0.46f, 0.92f));
                vertices.Add(new Vector2(2.5f, 0.17f));
                vertices.Add(new Vector2(2.5f, -0.205f));
                vertices.Add(new Vector2(2.3f, -0.33f));
                vertices.Add(new Vector2(-2.25f, -0.35f));

                PolygonShape chassis    = new PolygonShape(vertices, 2);
                CircleShape  wheelShape = new CircleShape(0.5f, 0.8f);

                _car          = World.CreateBody();
                _car.BodyType = BodyType.Dynamic;
                _car.Position = new Vector2(0.0f, 1.0f);
                _car.CreateFixture(chassis);

                _wheelBack          = World.CreateBody();
                _wheelBack.BodyType = BodyType.Dynamic;
                _wheelBack.Position = new Vector2(-1.709f, 0.78f);
                var wFixture = _wheelBack.CreateFixture(wheelShape);
                wFixture.Friction = 0.9f;

                wheelShape.Density   = 1;
                _wheelFront          = World.CreateBody();
                _wheelFront.BodyType = BodyType.Dynamic;
                _wheelFront.Position = new Vector2(1.54f, 0.8f);
                _wheelFront.CreateFixture(wheelShape);

                Vector2 axis = new Vector2(0.0f, 1.2f);
                _springBack                = new WheelJoint(_car, _wheelBack, _wheelBack.Position, axis, true);
                _springBack.MotorSpeed     = 0.0f;
                _springBack.MaxMotorTorque = 20.0f;
                _springBack.MotorEnabled   = true;
                _springBack.Frequency      = 4.0f;
                _springBack.DampingRatio   = 0.7f;
                World.Add(_springBack);

                _springFront                = new WheelJoint(_car, _wheelFront, _wheelFront.Position, axis, true);
                _springFront.MotorSpeed     = 0.0f;
                _springFront.MaxMotorTorque = 10.0f;
                _springFront.MotorEnabled   = false;
                _springFront.Frequency      = 4.0f;
                _springFront.DampingRatio   = 0.7f;
                World.Add(_springFront);

                _carBody = new Sprite(ScreenManager.Content.Load <Texture2D>("Samples/car"), AssetCreator.CalculateOrigin(_car, 24f));
                _wheel   = new Sprite(ScreenManager.Content.Load <Texture2D>("Samples/wheel"));
            }

            Camera.MinRotation = -0.05f;
            Camera.MaxRotation = 0.05f;

            Camera.TrackingBody   = _car;
            Camera.EnableTracking = true;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initialize the Game.
        /// </summary>
        public override void Initialize()
        {
            // world
            world = new World (this);
            // input
            knotInput = new KnotInputHandler (this, world);
            // overlay
            overlay = new Overlay (this, world);
            // pointer
            pointer = new MousePointer (this);
            // picker
            picker = new ModelMouseHandler (this, world);

            // pipe renderer
            var knotRenderInfo = new GameObjectInfo ();
            knotRenderInfo.Position = Vector3.Zero;
            renderer = new KnotRenderer (this, knotRenderInfo);
            world.Add (renderer as IGameObject);

            // pipe movements
            movement = new EdgeMovement (this, world, knotRenderInfo);
            world.Add (movement as IGameObject);

            // pipe colors
            coloring = new EdgeColoring (this);

            // load nodes
            Node.Scale = 100;
            Knot = new Knot ();
        }
Ejemplo n.º 18
0
        public WebOfGoo(World world, Vector2 position, float radius, int rings, int sides)
        {
            _world  = world;
            _radius = radius;

            _ringBodys  = new List <List <Body> >(rings);
            _ringJoints = new List <DistanceJoint>();

            for (int i = 1; i < rings; i++)
            {
                Vertices vertices = PolygonTools.CreateCircle(i * 2.9f, sides);
                vertices.Translate(ref position);
                List <Body> bodies = new List <Body>(sides);

                //Create the first goo
                Body previous = world.CreateCircle(radius, 0.2f, vertices[0]);
                previous.BodyType = BodyType.Dynamic;

                bodies.Add(previous);

                //Connect the first goo to the next
                for (int j = 1; j < vertices.Count; j++)
                {
                    Body current = world.CreateCircle(radius, 0.2f, vertices[j]);
                    current.BodyType = BodyType.Dynamic;

                    DistanceJoint joint = new DistanceJoint(previous, current, Vector2.Zero, Vector2.Zero);
                    joint.Frequency    = 4.0f;
                    joint.DampingRatio = 0.5f;
                    joint.Breakpoint   = Breakpoint;
                    world.Add(joint);
                    _ringJoints.Add(joint);

                    previous = current;
                    bodies.Add(current);
                }

                //Connect the first and the last goo
                DistanceJoint jointClose = new DistanceJoint(bodies[0], bodies[bodies.Count - 1], Vector2.Zero, Vector2.Zero);
                jointClose.Frequency    = 4.0f;
                jointClose.DampingRatio = 0.5f;
                jointClose.Breakpoint   = Breakpoint;
                world.Add(jointClose);
                _ringJoints.Add(jointClose);

                _ringBodys.Add(bodies);
            }

            //Create an outer ring
            Vertices frame = PolygonTools.CreateCircle(rings * 2.9f - 0.9f, sides);

            frame.Translate(ref position);

            Body anchor = world.CreateBody(position);

            anchor.BodyType = BodyType.Static;

            //Attach the outer ring to the anchor
            for (int i = 0; i < _ringBodys[rings - 2].Count; i++)
            {
                DistanceJoint joint = new DistanceJoint(anchor, _ringBodys[rings - 2][i], frame[i], _ringBodys[rings - 2][i].Position, true);
                joint.Frequency    = 8.0f;
                joint.DampingRatio = 0.5f;
                joint.Breakpoint   = Breakpoint;
                world.Add(joint);
                _ringJoints.Add(joint);
            }

            //Interconnect the rings
            for (int i = 1; i < _ringBodys.Count; i++)
            {
                for (int j = 0; j < sides; j++)
                {
                    DistanceJoint joint = new DistanceJoint(_ringBodys[i - 1][j], _ringBodys[i][j], Vector2.Zero, Vector2.Zero);
                    joint.Frequency    = 4.0f;
                    joint.DampingRatio = 0.5f;
                    joint.Breakpoint   = Breakpoint;
                    world.Add(joint);
                    _ringJoints.Add(joint);
                }
            }

            _link = new Sprite(ContentWrapper.GetTexture("Link"));
            _goo  = new Sprite(ContentWrapper.GetTexture("Goo"));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Erzeugt ein neues CreativeLoadScreen-Objekt und initialisiert dieses mit einem Knot3Game-Objekt.
        /// </summary>
        public CreativeLoadScreen(GameCore game)
            : base(game)
        {
            savegameMenu = new Menu (this, DisplayLayer.ScreenUI + DisplayLayer.Menu);
            savegameMenu.Bounds.Position = ScreenContentBounds.Position;
            savegameMenu.Bounds.Size = new ScreenPoint (this, 0.300f, ScreenContentBounds.Size.Relative.Y);
            savegameMenu.Bounds.Padding = new ScreenPoint (this, 0.010f, 0.010f);
            savegameMenu.ItemAlignX = HorizontalAlignment.Left;
            savegameMenu.ItemAlignY = VerticalAlignment.Center;
            savegameMenu.ItemBackgroundColor = Design.ComboBoxItemBackgroundColorFunc;
            savegameMenu.ItemForegroundColor = Design.ComboBoxItemForegroundColorFunc;
            savegameMenu.RelativeItemHeight = Design.DataItemHeight;

            lines.AddPoints (.000f, .050f, .030f, .970f, .620f, .895f, .740f, .970f, .760f, .895f, .880f, .970f, .970f, .050f, 1.000f);

            title = new TextItem (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem, text: "Load Knot");
            title.Bounds.Position = ScreenTitleBounds.Position;
            title.Bounds.Size = ScreenTitleBounds.Size;
            title.ForegroundColorFunc = (s) => Color.White;

            infoTitle = new TextItem (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem, text: "Knot Info:");
            infoTitle.Bounds.Position = new ScreenPoint (this, 0.45f, 0.62f);
            infoTitle.Bounds.Size = new ScreenPoint (this, 0.900f, 0.050f);
            infoTitle.ForegroundColorFunc = (s) => Color.White;

            knotInfo = new Menu (this, DisplayLayer.ScreenUI + DisplayLayer.Menu);
            knotInfo.Bounds.Position = new ScreenPoint (this, 0.47f, 0.70f);
            knotInfo.Bounds.Size = new ScreenPoint (this, 0.300f, 0.500f);
            knotInfo.Bounds.Padding = new ScreenPoint (this, 0.010f, 0.010f);
            knotInfo.ItemAlignX = HorizontalAlignment.Left;
            knotInfo.ItemAlignY = VerticalAlignment.Center;

            // Erstelle einen Parser für das Dateiformat
            KnotFileIO fileFormat = new KnotFileIO ();
            // Erstelle einen Spielstand-Loader
            loader = new SavegameLoader<Knot, KnotMetaData> (fileFormat, "index-knots");

            // Preview
            Bounds previewBounds = new Bounds (this, 0.45f, 0.1f, 0.48f, 0.5f);
            previewWorld = new World (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.GameWorld,
                bounds: previewBounds
            );
            previewRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            previewWorld.Add (previewRenderer);
            previewBorder = new Border (
                screen: this,
                drawOrder: DisplayLayer.GameWorld,
                bounds: previewBounds,
                lineWidth: 2,
                padding: 0
            );
            previewInput = new KnotInputHandler (screen: this, world: previewWorld);
            previewMouseHandler = new ModelMouseHandler (screen: this, world: previewWorld);

            backButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Back",
                onClick: (time) => NextScreen = Game.Screens.Where ((s) => !(s is CreativeLoadScreen)).ElementAt (0)
            );
            backButton.AddKey (Keys.Escape);
            backButton.SetCoordinates (left: 0.770f, top: 0.910f, right: 0.870f, bottom: 0.960f);
            backButton.AlignX = HorizontalAlignment.Center;

            startButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Load",
                onClick: (time) => NextScreen = new CreativeModeScreen (game: Game, knot: loader.FileFormat.Load (previewKnotMetaData.Filename))
            );
            startButton.IsVisible = false;
            startButton.AddKey (Keys.Enter);
            startButton.SetCoordinates (left: 0.630f, top: 0.910f, right: 0.730f, bottom: 0.960f);
            startButton.AlignX = HorizontalAlignment.Center;
        }
Ejemplo n.º 20
0
        private void CreateLeg(World world, float direction, Vector2 wheelAnchor, out Body shoulder, out Body leg)
        {
            Vector2 p1 = new Vector2(5.4f * direction, -6.1f);
            Vector2 p2 = new Vector2(7.2f * direction, -1.2f);
            Vector2 p3 = new Vector2(4.3f * direction, -1.9f);
            Vector2 p4 = new Vector2(3.1f * direction, 0.8f);
            Vector2 p5 = new Vector2(6.0f * direction, 1.5f);
            Vector2 p6 = new Vector2(2.5f * direction, 3.7f);

            PolygonShape shoulderPolygon;
            PolygonShape legPolygon;

            Vertices vertices = new Vertices(3);

            if (direction > 0f)
            {
                vertices.Add(p1);
                vertices.Add(p2);
                vertices.Add(p3);
                shoulderPolygon = new PolygonShape(vertices, 1);

                vertices[0] = Vector2.Zero;
                vertices[1] = p5 - p4;
                vertices[2] = p6 - p4;
                legPolygon  = new PolygonShape(vertices, 2);
            }
            else
            {
                vertices.Add(p1);
                vertices.Add(p3);
                vertices.Add(p2);
                shoulderPolygon = new PolygonShape(vertices, 1);

                vertices[0] = Vector2.Zero;
                vertices[1] = p6 - p4;
                vertices[2] = p5 - p4;
                legPolygon  = new PolygonShape(vertices, 2);
            }

            leg                = world.CreateBody();
            leg.BodyType       = BodyType.Dynamic;
            leg.Position       = _position;
            leg.AngularDamping = 10f;


            shoulder                = world.CreateBody();
            shoulder.BodyType       = BodyType.Dynamic;
            shoulder.Position       = p4 + _position;
            shoulder.AngularDamping = 10f;


            Fixture f1 = leg.CreateFixture(shoulderPolygon);

            f1.CollisionGroup = -1;

            Fixture f2 = shoulder.CreateFixture(legPolygon);

            f2.CollisionGroup = -1;

            // Using a soft distanceraint can reduce some jitter.
            // It also makes the structure seem a bit more fluid by
            // acting like a suspension system.
            DistanceJoint djd = new DistanceJoint(leg, shoulder, leg.GetLocalPoint(p2 + _position), shoulder.GetLocalPoint(p5 + _position));

            djd.DampingRatio = 0.5f;
            djd.Frequency    = 10f;

            world.Add(djd);
            _walkerJoints.Add(djd);

            DistanceJoint djd2 = new DistanceJoint(leg, shoulder, leg.GetLocalPoint(p3 + _position), shoulder.GetLocalPoint(p4 + _position));

            djd2.DampingRatio = 0.5f;
            djd2.Frequency    = 10f;

            world.Add(djd2);
            _walkerJoints.Add(djd2);

            DistanceJoint djd3 = new DistanceJoint(leg, _wheel, leg.GetLocalPoint(p3 + _position), _wheel.GetLocalPoint(wheelAnchor + _position));

            djd3.DampingRatio = 0.5f;
            djd3.Frequency    = 10f;

            world.Add(djd3);
            _walkerJoints.Add(djd3);

            DistanceJoint djd4 = new DistanceJoint(shoulder, _wheel, shoulder.GetLocalPoint(p6 + _position), _wheel.GetLocalPoint(wheelAnchor + _position));

            djd4.DampingRatio = 0.5f;
            djd4.Frequency    = 10f;

            world.Add(djd4);
            _walkerJoints.Add(djd4);

            Vector2       anchor = p4 - new Vector2(0f, 0.8f);
            RevoluteJoint rjd    = new RevoluteJoint(shoulder, _chassis, shoulder.GetLocalPoint(_chassis.GetWorldPoint(anchor)), anchor);

            world.Add(rjd);
        }
Ejemplo n.º 21
0
        private GravityControllerTest()
        {
            //Ground
            World.CreateEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            //Create the gravity controller
            GravityController gravity = new GravityController(20);

            gravity.DisabledOnGroup      = 3;
            gravity.EnabledOnGroup       = 2;
            gravity.DisabledOnCategories = Category.Cat2;
            gravity.EnabledOnCategories  = Category.Cat3;
            gravity.ControllerCategory   = ControllerCategory.Cat14; // set ControllerCategory to a unique category
            gravity.GravityType          = GravityType.Linear;

            World.Add(gravity);

            Vector2 startPosition = new Vector2(-10, 2);
            Vector2 offset        = new Vector2(2);

            //Create the planet
            Body planet = World.CreateBody();

            planet.Position = new Vector2(0, 20);

            CircleShape planetShape = new CircleShape(2, 1);

            planet.CreateFixture(planetShape);

            //Add the planet as the one that has gravity
            gravity.AddBody(planet);

            //Create 10 smaller circles
            for (int i = 0; i < 10; i++)
            {
                Body circle = World.CreateBody();
                circle.BodyType        = BodyType.Dynamic;
                circle.Position        = startPosition + offset * i;
                circle.SleepingAllowed = false;

                CircleShape circleShape = new CircleShape(1, 0.1f);
                Fixture     fix         = circle.CreateFixture(circleShape);
                fix.CollisionCategories = Category.Cat3;
                fix.CollisionGroup      = 2;

                if (i == 4)
                {
                    circle.ControllerFilter.IgnoreController(gravity.ControllerCategory);
                }

                if (i == 5)
                {
                    fix.CollisionCategories = Category.Cat2;
                    fix.Body.IgnoreGravity  = true;
                }

                if (i == 6)
                {
                    fix.CollisionGroup = 3;
                }
            }
        }
Ejemplo n.º 22
0
        private void CreateBlocks(int rowNumber, int colNumber)
        {
            //remove left wall? let the player fall?
            var cellsize = 1000 + World.SPACE_BETWEEN_THINGS;

            for (int i = 1; i < rowNumber; i++)
            {
                World.Add(new Block(Direction.Top)
                {
                    X = i * cellsize,
                    Y = cellsize
                });
            }

            for (int i = 1; i <= colNumber; i++)
            {
                World.Add(new Block(i == 1 || i == colNumber ? Direction.Center : Direction.Left)
                {
                    X = 0,
                    Y = i * cellsize
                });
            }

            for (int i = 1; i < rowNumber; i++)
            {
                World.Add(new Block(Direction.Bot)
                {
                    X = i * cellsize,
                    Y = cellsize * colNumber
                });
            }

            for (int i = 1; i <= colNumber; i++)
            {
                if (i == 2)
                {
                    World.Add(new InvisibleBlock()
                    {
                        X = cellsize * rowNumber,
                        Y = i * cellsize
                    });
                    continue;
                }

                World.Add(new Block(i == 1 || i == colNumber ? Direction.Center : Direction.Right)
                {
                    X = cellsize * rowNumber,
                    Y = i * cellsize
                });
            }

            var backgrond = GeneratedContent.Create_background_wall_center(
                0
                , cellsize * 6
                , 1
                , cellsize * 14
                , cellsize * 4);

            backgrond.ChangeColor(new Color(158, 165, 178));
            World.Add(backgrond);
        }
        private void CreateLeg(World world, float direction, Vector2 wheelAnchor, out Body shoulder, out Body leg)
        {
            Vector2 p1 = new Vector2(5.4f * direction, -6.1f);
            Vector2 p2 = new Vector2(7.2f * direction, -1.2f);
            Vector2 p3 = new Vector2(4.3f * direction, -1.9f);

            Vector2 p4 = new Vector2(3.1f * direction, 0.8f);
            Vector2 p5 = new Vector2(6.0f * direction, 1.5f);
            Vector2 p6 = new Vector2(2.5f * direction, 3.7f);

            PolygonShape shoulderPolygon;
            PolygonShape legPolygon;

            Vertices vertices = new Vertices(3);

            if (direction > 0f)
            {
                vertices.Add(p1);
                vertices.Add(p2);
                vertices.Add(p3);
                shoulderPolygon = new PolygonShape(vertices, 1f);

                vertices[0] = Vector2.Zero;
                vertices[1] = p5 - p4;
                vertices[2] = p6 - p4;
                legPolygon  = new PolygonShape(vertices, 2f);
            }
            else
            {
                vertices.Add(p1);
                vertices.Add(p3);
                vertices.Add(p2);
                shoulderPolygon = new PolygonShape(vertices, 1f);

                vertices[0] = Vector2.Zero;
                vertices[1] = p6 - p4;
                vertices[2] = p5 - p4;
                legPolygon  = new PolygonShape(vertices, 2f);
            }

            leg                = world.CreateBody();
            leg.BodyType       = BodyType.Dynamic;
            leg.Position       = _position;
            leg.AngularDamping = 10f;

            shoulder                = world.CreateBody();
            shoulder.BodyType       = BodyType.Dynamic;
            shoulder.Position       = p4 + _position;
            shoulder.AngularDamping = 10f;

            Fixture f1 = leg.CreateFixture(shoulderPolygon);

            f1.CollisionGroup = -1;

            Fixture f2 = shoulder.CreateFixture(legPolygon);

            f2.CollisionGroup = -1;

            Vector2       lsp2 = leg.GetLocalPoint(p2 + _position);
            Vector2       lsp5 = shoulder.GetLocalPoint(p5 + _position);
            DistanceJoint djd  = new DistanceJoint(leg, shoulder, lsp2, lsp5)
            {
                DampingRatio = 0.5f,
                Frequency    = 10f
            };

            world.Add(djd);

            DistanceJoint djd2 =
                new DistanceJoint(
                    leg,
                    shoulder,
                    leg.GetLocalPoint(p3 + _position),
                    shoulder.GetLocalPoint(p4 + _position))
            {
                DampingRatio = 0.5f,
                Frequency    = 10f
            };

            world.Add(djd2);

            DistanceJoint djd3 =
                new DistanceJoint(
                    leg,
                    _wheel,
                    leg.GetLocalPoint(p3 + _position),
                    _wheel.GetLocalPoint(wheelAnchor + _position))
            {
                DampingRatio = 0.5f,
                Frequency    = 10f
            };

            world.Add(djd3);

            DistanceJoint djd4 =
                new DistanceJoint(
                    shoulder,
                    _wheel,
                    shoulder.GetLocalPoint(p6 + _position),
                    _wheel.GetLocalPoint(wheelAnchor + _position))
            {
                DampingRatio = 0.5f,
                Frequency    = 10f
            };

            world.Add(djd4);

            Vector2       anchor = p4 - new Vector2(0f, 0.8f);
            RevoluteJoint rjd    =
                new RevoluteJoint(
                    shoulder,
                    _chassis,
                    shoulder.GetLocalPoint(_chassis.GetWorldPoint(anchor)),
                    anchor);

            world.Add(rjd);
        }
Ejemplo n.º 24
0
        private void CreateTouchInputs()
        {
            var btnWidth  = 1000;
            var btnHeight = 1000;
            var space     = 1;
            var yAnchor   = 6200;
            var xAnchor   = 800;

            var extraWidth  = 1000;
            var extraHeight = 500;

            //top left
            World.Add(new TouchArea(
                          xAnchor - extraWidth
                          , yAnchor - extraHeight
                          , btnWidth + extraWidth - space
                          , btnHeight + extraHeight - space
                          , f => World.PlayerInputs.UpDown = World.PlayerInputs.LeftDown = f));
            World.Add(new ButtonAnimation(
                          xAnchor
                          , yAnchor
                          , btnWidth - space
                          , btnHeight - space
                          , () => World.PlayerInputs.UpDown && World.PlayerInputs.LeftDown));

            //top
            World.Add(new TouchArea(
                          xAnchor + btnWidth
                          , yAnchor - extraHeight
                          , btnWidth - space
                          , btnHeight + extraHeight - space
                          , f => World.PlayerInputs.UpDown = f));
            World.Add(new ButtonAnimation(
                          xAnchor + btnWidth
                          , yAnchor
                          , btnWidth - space
                          , btnHeight - space
                          , () => World.PlayerInputs.UpDown && !World.PlayerInputs.LeftDown && !World.PlayerInputs.RightDown));

            //top right
            World.Add(new TouchArea(
                          xAnchor + btnWidth * 2
                          , yAnchor - extraHeight
                          , btnWidth + extraWidth - space
                          , btnHeight + extraHeight - space
                          , f => World.PlayerInputs.UpDown = World.PlayerInputs.RightDown = f));
            World.Add(new ButtonAnimation(
                          xAnchor + btnWidth * 2
                          , yAnchor
                          , btnWidth - space
                          , btnHeight - space
                          , () => World.PlayerInputs.UpDown && World.PlayerInputs.RightDown));

            //left
            World.Add(new TouchArea(
                          xAnchor - extraWidth
                          , yAnchor + btnHeight
                          , (int)(btnWidth * 1.5f) + extraWidth - space
                          , btnHeight - space
                          , f => World.PlayerInputs.LeftDown = f));
            World.Add(new ButtonAnimation(
                          xAnchor
                          , yAnchor + btnHeight
                          , (int)(btnWidth * 1.5f)
                          , btnHeight - space
                          , () => World.PlayerInputs.LeftDown && !World.PlayerInputs.DownDown && !World.PlayerInputs.UpDown));

            //right
            World.Add(new TouchArea(
                          xAnchor + (int)(btnWidth * 1.5f) + space /// 3
                          , yAnchor + btnHeight
                          , (int)(btnWidth * 1.5f) - space + extraWidth
                          , btnHeight - space
                          , f => World.PlayerInputs.RightDown = f));
            World.Add(new ButtonAnimation(
                          xAnchor + (int)(btnWidth * 1.5f) + space /// 3
                          , yAnchor + btnHeight
                          , (int)(btnWidth * 1.5f)
                          , btnHeight - space
                          , () => World.PlayerInputs.RightDown && !World.PlayerInputs.DownDown && !World.PlayerInputs.UpDown));

            //bot left
            World.Add(new TouchArea(xAnchor - extraWidth, yAnchor + btnHeight * 2, btnWidth + extraWidth - space, btnHeight + extraHeight - space, f => World.PlayerInputs.DownDown = World.PlayerInputs.LeftDown = f));
            World.Add(new ButtonAnimation(xAnchor, yAnchor + btnHeight * 2, btnWidth - space, btnHeight - space, () => World.PlayerInputs.DownDown && World.PlayerInputs.LeftDown));

            //bot
            World.Add(new TouchArea(xAnchor + btnWidth, yAnchor + btnHeight * 2, btnWidth - space, btnHeight + extraHeight - space, f => World.PlayerInputs.DownDown = f));
            World.Add(new ButtonAnimation(xAnchor + btnWidth, yAnchor + btnHeight * 2, btnWidth - space, btnHeight - space, () => World.PlayerInputs.DownDown && !World.PlayerInputs.LeftDown && !World.PlayerInputs.RightDown));

            //bot right
            World.Add(new TouchArea(xAnchor + btnWidth * 2, yAnchor + btnHeight * 2, btnWidth + extraWidth - space, btnHeight + extraHeight - space, f => World.PlayerInputs.DownDown = World.PlayerInputs.RightDown = f));
            World.Add(new ButtonAnimation(xAnchor + btnWidth * 2, yAnchor + btnHeight * 2, btnWidth - space, btnHeight - space, () => World.PlayerInputs.DownDown && World.PlayerInputs.RightDown));

            xAnchor   = 9800;
            yAnchor  += 600;
            btnWidth  = 1600;
            btnHeight = 2000;

            //grab
            World.Add(new TouchArea(
                          xAnchor - extraWidth
                          , yAnchor - extraHeight
                          , btnWidth - space + extraWidth
                          , btnHeight - space + extraHeight * 2
                          , f => World.PlayerInputs.Action1Down = f));
            World.Add(new ButtonAnimation(
                          xAnchor
                          , yAnchor
                          , btnWidth - space
                          , btnHeight - space
                          , () => World.PlayerInputs.Action1Down));

            xAnchor += 1800;

            //jump
            World.Add(new TouchArea(
                          xAnchor - 199
                          , yAnchor - extraHeight
                          , btnWidth - space + extraWidth
                          , btnHeight - space + extraHeight * 2
                          , f => World.PlayerInputs.JumpDown = f));
            World.Add(new ButtonAnimation(
                          xAnchor
                          , yAnchor
                          , btnWidth - space
                          , btnHeight - space
                          , () => World.PlayerInputs.JumpDown));
        }
Ejemplo n.º 25
0
        private DominosTest()
        {
            Body b1 = World.CreateEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            {
                Vertices     box   = PolygonTools.CreateRectangle(6.0f, 0.25f);
                PolygonShape shape = new PolygonShape(box, 0);

                Body ground = World.CreateBody();
                ground.Position = new Vector2(-1.5f, 10.0f);
                ground.CreateFixture(shape);
            }

            {
                Vertices     box   = PolygonTools.CreateRectangle(0.1f, 1.0f);
                PolygonShape shape = new PolygonShape(box, 20);

                for (int i = 0; i < 10; ++i)
                {
                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(-6.0f + 1.0f * i, 11.25f);

                    Fixture fixture = body.CreateFixture(shape);
                    fixture.Friction = 0.1f;
                }
            }

            {
                Vertices     box   = PolygonTools.CreateRectangle(7.0f, 0.25f, Vector2.Zero, 0.3f);
                PolygonShape shape = new PolygonShape(box, 0);

                Body ground = World.CreateBody();
                ground.Position = new Vector2(1.0f, 6.0f);

                ground.CreateFixture(shape);
            }

            Body b2;
            {
                Vertices     box   = PolygonTools.CreateRectangle(0.25f, 1.5f);
                PolygonShape shape = new PolygonShape(box, 0);

                b2          = World.CreateBody();
                b2.Position = new Vector2(-7.0f, 4.0f);

                b2.CreateFixture(shape);
            }

            Body b3;
            {
                Vertices     box   = PolygonTools.CreateRectangle(6.0f, 0.125f);
                PolygonShape shape = new PolygonShape(box, 10);

                b3          = World.CreateBody();
                b3.BodyType = BodyType.Dynamic;
                b3.Position = new Vector2(-0.9f, 1.0f);
                b3.Rotation = -0.15f;

                b3.CreateFixture(shape);
            }

            Vector2       anchor = new Vector2(-2.0f, 1.0f);
            RevoluteJoint jd     = new RevoluteJoint(b1, b3, anchor, true);

            jd.CollideConnected = true;
            World.Add(jd);

            Body b4;

            {
                Vertices     box   = PolygonTools.CreateRectangle(0.25f, 0.25f);
                PolygonShape shape = new PolygonShape(box, 10);

                b4          = World.CreateBody();
                b4.BodyType = BodyType.Dynamic;
                b4.Position = new Vector2(-10.0f, 15.0f);

                b4.CreateFixture(shape);
            }

            anchor = new Vector2(-7.0f, 15.0f);
            RevoluteJoint jd2 = new RevoluteJoint(b2, b4, anchor, true);

            World.Add(jd2);

            Body b5;

            {
                b5          = World.CreateBody();
                b5.BodyType = BodyType.Dynamic;
                b5.Position = new Vector2(6.5f, 3.0f);

                Vertices     vertices = PolygonTools.CreateRectangle(1.0f, 0.1f, new Vector2(0.0f, -0.9f), 0.0f);
                PolygonShape shape    = new PolygonShape(vertices, 10);

                Fixture fix = b5.CreateFixture(shape);
                fix.Friction = 0.1f;

                vertices = PolygonTools.CreateRectangle(0.1f, 1.0f, new Vector2(-0.9f, 0.0f), 0.0f);

                shape.Vertices = vertices;
                fix            = b5.CreateFixture(shape);
                fix.Friction   = 0.1f;

                vertices = PolygonTools.CreateRectangle(0.1f, 1.0f, new Vector2(0.9f, 0.0f), 0.0f);

                shape.Vertices = vertices;
                fix            = b5.CreateFixture(shape);
                fix.Friction   = 0.1f;
            }

            anchor = new Vector2(6.0f, 2.0f);
            RevoluteJoint jd3 = new RevoluteJoint(b1, b5, anchor, true);

            World.Add(jd3);

            Body b6;

            {
                Vertices     box   = PolygonTools.CreateRectangle(1.0f, 0.1f);
                PolygonShape shape = new PolygonShape(box, 30);

                b6          = World.CreateBody();
                b6.BodyType = BodyType.Dynamic;
                b6.Position = new Vector2(6.5f, 4.1f);

                b6.CreateFixture(shape);
            }

            anchor = new Vector2(7.50f, 4.0f);
            RevoluteJoint jd4 = new RevoluteJoint(b5, b6, anchor, true);

            jd4.CollideConnected = true;
            World.Add(jd4);

            Body b7;
            {
                Vertices     box   = PolygonTools.CreateRectangle(0.1f, 1.0f);
                PolygonShape shape = new PolygonShape(box, 10);

                b7          = World.CreateBody();
                b7.BodyType = BodyType.Dynamic;
                b7.Position = new Vector2(7.4f, 1.0f);

                b7.CreateFixture(shape);
            }

            DistanceJoint djd = new DistanceJoint(b3, b7, new Vector2(6.0f, 0.0f), new Vector2(0.0f, -1.0f));

            World.Add(djd);

            {
                const float radius = 0.2f;

                CircleShape shape = new CircleShape(radius, 10);

                for (int i = 0; i < 4; ++i)
                {
                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(5.9f + 2.0f * radius * i, 2.4f);

                    Fixture fix = body.CreateFixture(shape);
                    fix.OnBeginContact += BallCollision;
                }
            }
        }
Ejemplo n.º 26
0
        private GearsTest()
        {
            Body ground = World.CreateEdge(new Vector2(50.0f, 0.0f), new Vector2(-50.0f, 0.0f));

            {
                CircleShape circle1 = new CircleShape(1.0f, 5f);

                PolygonShape box = new PolygonShape(5f);
                box.Vertices = PolygonTools.CreateRectangle(0.5f, 5.0f);

                CircleShape circle2 = new CircleShape(2.0f, 5f);

                Body body1 = World.CreateBody(new Vector2(10.0f, 9.0f));
                body1.CreateFixture(circle1);

                Body body2 = World.CreateBody(new Vector2(10.0f, 8.0f));
                body2.BodyType = BodyType.Dynamic;
                body2.CreateFixture(box);

                Body body3 = World.CreateBody(new Vector2(10.0f, 6.0f));
                body3.BodyType = BodyType.Dynamic;
                body3.CreateFixture(circle2);

                RevoluteJoint joint1 = new RevoluteJoint(body2, body1, body1.Position, true);
                World.Add(joint1);

                RevoluteJoint joint2 = new RevoluteJoint(body2, body3, body3.Position, true);
                World.Add(joint2);

                GearJoint joint4 = new GearJoint(body1, body3, joint1, joint2, circle2.Radius / circle1.Radius);
                World.Add(joint4);
            }

            {
                CircleShape circle1 = new CircleShape(1.0f, 5.0f);

                CircleShape circle2 = new CircleShape(2.0f, 5.0f);

                PolygonShape box = new PolygonShape(5f);
                box.Vertices = PolygonTools.CreateRectangle(0.5f, 5.0f);

                Body body1 = World.CreateBody(new Vector2(-3.0f, 12.0f));
                body1.BodyType = BodyType.Dynamic;
                body1.CreateFixture(circle1);

                _joint1 = new RevoluteJoint(ground, body1, body1.Position, true);
                _joint1.ReferenceAngle = body1.Rotation - ground.Rotation;
                World.Add(_joint1);

                Body body2 = World.CreateBody(new Vector2(0.0f, 12.0f));
                body2.BodyType = BodyType.Dynamic;
                body2.CreateFixture(circle2);

                _joint2 = new RevoluteJoint(ground, body2, body2.Position, true);
                World.Add(_joint2);

                Body body3 = World.CreateBody(new Vector2(2.5f, 12.0f));
                body3.BodyType = BodyType.Dynamic;
                body3.CreateFixture(box);

                _joint3              = new PrismaticJoint(ground, body3, body3.Position, new Vector2(0.0f, 1.0f), true);
                _joint3.LowerLimit   = -5.0f;
                _joint3.UpperLimit   = 5.0f;
                _joint3.LimitEnabled = true;

                World.Add(_joint3);

                _joint4 = new GearJoint(body1, body2, _joint1, _joint2, circle2.Radius / circle1.Radius);
                World.Add(_joint4);

                _joint5 = new GearJoint(body2, body3, _joint2, _joint3, -1.0f / circle2.Radius);
                World.Add(_joint5);
            }
        }
Ejemplo n.º 27
0
 public override void Added()
 {
     base.Added();
     World.Add(theRazor);
 }
Ejemplo n.º 28
0
        private SliderCrankTest()
        {
            Body ground;
            {
                ground = World.CreateBody();

                EdgeShape shape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
                ground.CreateFixture(shape);
            }

            {
                Body prevBody = ground;

                // Define crank.
                {
                    PolygonShape shape = new PolygonShape(2);
                    shape.Vertices = PolygonTools.CreateRectangle(0.5f, 2.0f);

                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(0.0f, 7.0f);

                    body.CreateFixture(shape);

                    _joint1                = new RevoluteJoint(prevBody, body, new Vector2(0f, 5f), true);
                    _joint1.MotorSpeed     = 1.0f * MathHelper.Pi;
                    _joint1.MaxMotorTorque = 10000.0f;
                    _joint1.MotorEnabled   = true;
                    World.Add(_joint1);

                    prevBody = body;
                }

                // Define follower.
                {
                    PolygonShape shape = new PolygonShape(2);
                    shape.Vertices = PolygonTools.CreateRectangle(0.5f, 4.0f);

                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(0.0f, 13.0f);

                    body.CreateFixture(shape);

                    RevoluteJoint rjd3 = new RevoluteJoint(prevBody, body, new Vector2(0, 9), true);
                    rjd3.MotorEnabled = false;
                    World.Add(rjd3);

                    prevBody = body;
                }

                // Define piston
                {
                    PolygonShape shape = new PolygonShape(2);
                    shape.Vertices = PolygonTools.CreateRectangle(1.5f, 1.5f);

                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(0.0f, 17.0f);

                    body.CreateFixture(shape);

                    RevoluteJoint rjd = new RevoluteJoint(prevBody, body, new Vector2(0, 17), true);
                    World.Add(rjd);

                    _joint2 = new PrismaticJoint(ground, body, new Vector2(0.0f, 17.0f), new Vector2(0.0f, 1.0f), true);
                    _joint2.MaxMotorForce = 1000.0f;
                    _joint2.MotorEnabled  = true;

                    World.Add(_joint2);
                }

                // Create a payload
                {
                    PolygonShape shape = new PolygonShape(2);
                    shape.Vertices = PolygonTools.CreateRectangle(1.5f, 1.5f);

                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(0.0f, 23.0f);

                    body.CreateFixture(shape);
                }
            }
        }
Ejemplo n.º 29
0
        private void CreateLeg(World world, float direction, Vector2 wheelAnchor, out Body shoulder, out Body leg)
        {
            Vector2 p1 = new Vector2(5.4f * direction, -6.1f);
            Vector2 p2 = new Vector2(7.2f * direction, -1.2f);
            Vector2 p3 = new Vector2(4.3f * direction, -1.9f);
            Vector2 p4 = new Vector2(3.1f * direction, 0.8f);
            Vector2 p5 = new Vector2(6.0f * direction, 1.5f);
            Vector2 p6 = new Vector2(2.5f * direction, 3.7f);

            PolygonShape shoulderPolygon = new PolygonShape(1f);
            PolygonShape legPolygon      = new PolygonShape(1f);

            if (direction > 0f)
            {
                legPolygon.Vertices      = new Vertices(new[] { p1, p2, p3 });
                shoulderPolygon.Vertices = new Vertices(new[] { Vector2.Zero, p5 - p4, p6 - p4 });
            }
            else
            {
                legPolygon.Vertices      = new Vertices(new[] { p1, p3, p2 });
                shoulderPolygon.Vertices = new Vertices(new[] { Vector2.Zero, p6 - p4, p5 - p4 });
            }

            leg                = world.CreateBody();
            leg.BodyType       = BodyType.Dynamic;
            leg.Position       = _position;
            leg.AngularDamping = 10f;

            shoulder                = world.CreateBody();
            shoulder.BodyType       = BodyType.Dynamic;
            shoulder.Position       = p4 + _position;
            shoulder.AngularDamping = 10f;

            Fixture legFixture = leg.CreateFixture(legPolygon);

            legFixture.CollisionGroup = -1;

            Fixture shoulderFixture = shoulder.CreateFixture(shoulderPolygon);

            shoulderFixture.CollisionGroup = -1;

            // Using a soft distancejoint can reduce some jitter.
            // It also makes the structure seem a bit more fluid by
            // acting like a suspension system.
            DistanceJoint djd = new DistanceJoint(leg, shoulder, p2 + _position, p5 + _position, true);

            djd.DampingRatio = 0.5f;
            djd.Frequency    = 10f;

            world.Add(djd);
            _walkerJoints.Add(djd);

            DistanceJoint djd2 = new DistanceJoint(leg, shoulder, p3 + _position, p4 + _position, true);

            djd2.DampingRatio = 0.5f;
            djd2.Frequency    = 10f;

            world.Add(djd2);
            _walkerJoints.Add(djd2);

            DistanceJoint djd3 = new DistanceJoint(leg, _wheel, p3 + _position, wheelAnchor + _position, true);

            djd3.DampingRatio = 0.5f;
            djd3.Frequency    = 10f;

            world.Add(djd3);
            _walkerJoints.Add(djd3);

            DistanceJoint djd4 = new DistanceJoint(shoulder, _wheel, p6 + _position, wheelAnchor + _position, true);

            djd4.DampingRatio = 0.5f;
            djd4.Frequency    = 10f;

            world.Add(djd4);
            _walkerJoints.Add(djd4);

            RevoluteJoint rjd = new RevoluteJoint(shoulder, _chassis, p4 + _position, true);

            world.Add(rjd);
        }
Ejemplo n.º 30
0
 public void Defeat()
 {
     ScorePoints(Const.SCORE_BEETLE);
     World.Add(new PopingUpPoints(World, Boundary.Location, Const.SCORE_KOOPA));
     RemoveSelf();
 }
Ejemplo n.º 31
0
        public Ragdoll(World world, Vector2 position)
        {
            // Physics
            // Head
            _head                = world.CreateCircle(0.75f, 10f);
            _head.BodyType       = BodyType.Dynamic;
            _head.AngularDamping = LimbAngularDamping;
            _head.Mass           = 2f;
            _head.Position       = position;

            // Torso
            _upperBody          = world.CreateCapsule(0.5f, 0.75f, LegDensity);
            _upperBody.BodyType = BodyType.Dynamic;
            _upperBody.Mass     = 1f;
            _upperBody.SetTransform(position + new Vector2(0f, -1.75f), -MathHelper.Pi / 2f);
            _middleBody          = world.CreateCapsule(0.5f, 0.75f, LegDensity);
            _middleBody.BodyType = BodyType.Dynamic;
            _middleBody.Mass     = 1f;
            _middleBody.SetTransform(position + new Vector2(0f, -3f), -MathHelper.Pi / 2f);
            _lowerBody          = world.CreateCapsule(0.5f, 0.75f, LegDensity);
            _lowerBody.BodyType = BodyType.Dynamic;
            _lowerBody.Mass     = 1f;
            _lowerBody.SetTransform(position + new Vector2(0f, -4.25f), -MathHelper.Pi / 2f);

            // Left Arm
            _lowerLeftArm                = world.CreateCapsule(1f, 0.45f, ArmDensity);
            _lowerLeftArm.BodyType       = BodyType.Dynamic;
            _lowerLeftArm.AngularDamping = LimbAngularDamping;
            _lowerLeftArm.Mass           = 2f;
            _lowerLeftArm.Rotation       = -1.4f;
            _lowerLeftArm.Position       = position + new Vector2(-4f, -2.2f);

            _upperLeftArm                = world.CreateCapsule(1f, 0.45f, ArmDensity);
            _upperLeftArm.BodyType       = BodyType.Dynamic;
            _upperLeftArm.AngularDamping = LimbAngularDamping;
            _upperLeftArm.Mass           = 2f;
            _upperLeftArm.Rotation       = -1.4f;
            _upperLeftArm.Position       = position + new Vector2(-2f, -1.8f);

            // Right Arm
            _lowerRightArm                = world.CreateCapsule(1f, 0.45f, ArmDensity);
            _lowerRightArm.BodyType       = BodyType.Dynamic;
            _lowerRightArm.AngularDamping = LimbAngularDamping;
            _lowerRightArm.Mass           = 2f;
            _lowerRightArm.Rotation       = 1.4f;
            _lowerRightArm.Position       = position + new Vector2(4f, -2.2f);

            _upperRightArm                = world.CreateCapsule(1f, 0.45f, ArmDensity);
            _upperRightArm.BodyType       = BodyType.Dynamic;
            _upperRightArm.AngularDamping = LimbAngularDamping;
            _upperRightArm.Mass           = 2f;
            _upperRightArm.Rotation       = 1.4f;
            _upperRightArm.Position       = position + new Vector2(2f, -1.8f);

            // Left Leg
            _lowerLeftLeg                = world.CreateCapsule(1f, 0.5f, LegDensity);
            _lowerLeftLeg.BodyType       = BodyType.Dynamic;
            _lowerLeftLeg.AngularDamping = LimbAngularDamping;
            _lowerLeftLeg.Mass           = 2f;
            _lowerLeftLeg.Position       = position + new Vector2(-0.6f, -8f);

            _upperLeftLeg                = world.CreateCapsule(1f, 0.5f, LegDensity);
            _upperLeftLeg.BodyType       = BodyType.Dynamic;
            _upperLeftLeg.AngularDamping = LimbAngularDamping;
            _upperLeftLeg.Mass           = 2f;
            _upperLeftLeg.Position       = position + new Vector2(-0.6f, -6f);

            // Right Leg
            _lowerRightLeg                = world.CreateCapsule(1f, 0.5f, LegDensity);
            _lowerRightLeg.BodyType       = BodyType.Dynamic;
            _lowerRightLeg.AngularDamping = LimbAngularDamping;
            _lowerRightLeg.Mass           = 2f;
            _lowerRightLeg.Position       = position + new Vector2(0.6f, -8f);

            _upperRightLeg                = world.CreateCapsule(1f, 0.5f, LegDensity);
            _upperRightLeg.BodyType       = BodyType.Dynamic;
            _upperRightLeg.AngularDamping = LimbAngularDamping;
            _upperRightLeg.Mass           = 2f;
            _upperRightLeg.Position       = position + new Vector2(0.6f, -6f);

            // head -> upper body
            DistanceJoint jointHeadBody = new DistanceJoint(_head, _upperBody, new Vector2(0f, -1f), new Vector2(-0.75f, 0f));

            jointHeadBody.CollideConnected = true;
            jointHeadBody.DampingRatio     = DampingRatio;
            jointHeadBody.Frequency        = Frequency;
            jointHeadBody.Length           = 0.025f;
            world.Add(jointHeadBody);

            // lowerLeftArm -> upperLeftArm
            DistanceJoint jointLeftArm = new DistanceJoint(_lowerLeftArm, _upperLeftArm, new Vector2(0f, 1f), new Vector2(0f, -1f));

            jointLeftArm.CollideConnected = true;
            jointLeftArm.DampingRatio     = DampingRatio;
            jointLeftArm.Frequency        = Frequency;
            jointLeftArm.Length           = 0.02f;
            world.Add(jointLeftArm);

            // upperLeftArm -> upper body
            DistanceJoint jointLeftArmBody = new DistanceJoint(_upperLeftArm, _upperBody, new Vector2(0f, 1f), new Vector2(-0.15f, -1f));

            jointLeftArmBody.DampingRatio = DampingRatio;
            jointLeftArmBody.Frequency    = Frequency;
            jointLeftArmBody.Length       = 0.02f;
            world.Add(jointLeftArmBody);

            // lowerRightArm -> upperRightArm
            DistanceJoint jointRightArm = new DistanceJoint(_lowerRightArm, _upperRightArm, new Vector2(0f, 1f), new Vector2(0f, -1f));

            jointRightArm.CollideConnected = true;
            jointRightArm.DampingRatio     = DampingRatio;
            jointRightArm.Frequency        = Frequency;
            jointRightArm.Length           = 0.02f;
            world.Add(jointRightArm);

            // upperRightArm -> upper body
            DistanceJoint jointRightArmBody = new DistanceJoint(_upperRightArm, _upperBody, new Vector2(0f, 1f), new Vector2(-0.15f, 1f));

            jointRightArmBody.DampingRatio = DampingRatio;
            jointRightArmBody.Frequency    = 25;
            jointRightArmBody.Length       = 0.02f;
            world.Add(jointRightArmBody);

            // lowerLeftLeg -> upperLeftLeg
            DistanceJoint jointLeftLeg = new DistanceJoint(_lowerLeftLeg, _upperLeftLeg, new Vector2(0f, 1.1f), new Vector2(0f, -1f));

            jointLeftLeg.CollideConnected = true;
            jointLeftLeg.DampingRatio     = DampingRatio;
            jointLeftLeg.Frequency        = Frequency;
            jointLeftLeg.Length           = 0.05f;
            world.Add(jointLeftLeg);

            // upperLeftLeg -> lower body
            DistanceJoint jointLeftLegBody = new DistanceJoint(_upperLeftLeg, _lowerBody, new Vector2(0f, 1.1f), new Vector2(0.7f, -0.8f));

            jointLeftLegBody.CollideConnected = true;
            jointLeftLegBody.DampingRatio     = DampingRatio;
            jointLeftLegBody.Frequency        = Frequency;
            jointLeftLegBody.Length           = 0.02f;
            world.Add(jointLeftLegBody);

            // lowerRightleg -> upperRightleg
            DistanceJoint jointRightLeg = new DistanceJoint(_lowerRightLeg, _upperRightLeg, new Vector2(0f, 1.1f), new Vector2(0f, -1f));

            jointRightLeg.CollideConnected = true;
            jointRightLeg.DampingRatio     = DampingRatio;
            jointRightLeg.Frequency        = Frequency;
            jointRightLeg.Length           = 0.05f;
            world.Add(jointRightLeg);

            // upperRightleg -> lower body
            DistanceJoint jointRightLegBody = new DistanceJoint(_upperRightLeg, _lowerBody, new Vector2(0f, 1.1f), new Vector2(0.7f, 0.8f));

            jointRightLegBody.CollideConnected = true;
            jointRightLegBody.DampingRatio     = DampingRatio;
            jointRightLegBody.Frequency        = Frequency;
            jointRightLegBody.Length           = 0.02f;
            world.Add(jointRightLegBody);

            // upper body -> middle body
            RevoluteJoint jointUpperTorso = new RevoluteJoint(_upperBody, _middleBody, _upperBody.Position + new Vector2(0f, -0.625f), true);

            jointUpperTorso.LimitEnabled = true;
            jointUpperTorso.SetLimits(MathHelper.Pi / 16f, -MathHelper.Pi / 16f);
            world.Add(jointUpperTorso);

            // middle body -> lower body
            RevoluteJoint jointLowerTorso = new RevoluteJoint(_middleBody, _lowerBody, _middleBody.Position + new Vector2(0f, -0.625f), true);

            jointLowerTorso.LimitEnabled = true;
            jointLowerTorso.SetLimits(MathHelper.Pi / 8f, -MathHelper.Pi / 8f);
            world.Add(jointLowerTorso);

            // GFX
            _face      = new Sprite(ContentWrapper.CircleTexture(0.75f, "Square", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Grey, 1f, 24f));
            _torso     = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateRoundedRectangle(1.5f, 2f, 0.75f, 0.75f, 2), "Stripe", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Black, 2.0f, 24f));
            _upperLimb = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateCapsule(1.9f, 0.45f, 16), "Square", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Black, 1f, 24f));
            _lowerLimb = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateCapsule(2f, 0.5f, 16), "Square", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Black, 1f, 24f));
        }
Ejemplo n.º 32
0
 public override void Added()
 {
     base.Added();
     World.Add(hat);
 }
Ejemplo n.º 33
0
        private ApplyForceTest()
        {
            World.Gravity = Vector2.Zero;

            const float restitution = 0.4f;

            Body ground;
            {
                ground          = World.CreateBody();
                ground.Position = new Vector2(0.0f, 20.0f);

                EdgeShape shape = new EdgeShape(new Vector2(-20.0f, -20.0f), new Vector2(-20.0f, 20.0f));

                // Left vertical
                Fixture fixture = ground.CreateFixture(shape);
                fixture.Restitution = restitution;

                // Right vertical
                shape = new EdgeShape(new Vector2(20.0f, -20.0f), new Vector2(20.0f, 20.0f));
                ground.CreateFixture(shape);

                // Top horizontal
                shape = new EdgeShape(new Vector2(-20.0f, 20.0f), new Vector2(20.0f, 20.0f));
                ground.CreateFixture(shape);

                // Bottom horizontal
                shape = new EdgeShape(new Vector2(-20.0f, -20.0f), new Vector2(20.0f, -20.0f));
                ground.CreateFixture(shape);
            }

            {
                Transform xf1 = new Transform(new Vector2(1.0f, 0.0f), Complex.One);
                Transform.Multiply(ref xf1, Complex.FromAngle(0.3524f * MathHelper.Pi), out xf1);

                Vertices vertices = new Vertices(3);
                vertices.Add(Transform.Multiply(new Vector2(-1.0f, 0.0f), ref xf1));
                vertices.Add(Transform.Multiply(new Vector2(1.0f, 0.0f), ref xf1));
                vertices.Add(Transform.Multiply(new Vector2(0.0f, 0.5f), ref xf1));

                PolygonShape poly1 = new PolygonShape(vertices, 4);

                Transform xf2 = new Transform(new Vector2(-1.0f, 0.0f), Complex.One);
                Transform.Multiply(ref xf2, Complex.FromAngle(-0.3524f * MathHelper.Pi), out xf2);

                vertices[0] = Transform.Multiply(new Vector2(-1.0f, 0.0f), ref xf2);
                vertices[1] = Transform.Multiply(new Vector2(1.0f, 0.0f), ref xf2);
                vertices[2] = Transform.Multiply(new Vector2(0.0f, 0.5f), ref xf2);

                PolygonShape poly2 = new PolygonShape(vertices, 2);

                _body                 = World.CreateBody();
                _body.BodyType        = BodyType.Dynamic;
                _body.Position        = new Vector2(0.0f, 2.0f);
                _body.Rotation        = MathHelper.Pi;
                _body.AngularDamping  = 5.0f;
                _body.LinearDamping   = 0.8f;
                _body.SleepingAllowed = true;

                _body.CreateFixture(poly1);
                _body.CreateFixture(poly2);
            }

            {
                Vertices     box   = PolygonTools.CreateRectangle(0.5f, 0.5f);
                PolygonShape shape = new PolygonShape(box, 1);

                for (int i = 0; i < 10; ++i)
                {
                    Body body = World.CreateBody();
                    body.Position = new Vector2(0.0f, 5.0f + 1.54f * i);
                    body.BodyType = BodyType.Dynamic;

                    Fixture fixture = body.CreateFixture(shape);
                    fixture.Friction = 0.3f;

                    const float gravity = 10.0f;
                    float       I       = body.Inertia;
                    float       mass    = body.Mass;

                    // For a circle: I = 0.5 * m * r * r ==> r = sqrt(2 * I / m)
                    float radius = (float)Math.Sqrt(2.0 * (I / mass));

                    FrictionJoint jd = new FrictionJoint(ground, body, Vector2.Zero);
                    jd.CollideConnected = true;
                    jd.MaxForce         = mass * gravity;
                    jd.MaxTorque        = mass * radius * gravity;

                    World.Add(jd);
                }
            }
        }
Ejemplo n.º 34
0
        public override void Update()
        {
            if (Input.Pressed(Mouse.Button.Right))
            {
                World.Remove(hat);

                if (hat is NoHat)
                {
                    hat = new Ninja(this);
                }
                else
                {
                    hat = new NoHat(this);
                }

                World.Add(hat);
            }


            //Movement
            if (!isHurt)
            {
                if (Input.Pressed(Keyboard.Key.Space) && physics.velocity.Y == 0)
                {
                    physics.velocity.Y += jumpForce;
                    bodySprites.Play("Jump");
                    if (!isAttacking)
                    {
                        faceSprites.Play("Jump");
                    }
                }

                if (Input.Check(Keyboard.Key.A))
                {
                    physics.velocity.X -= this.speed;
                }
                if (Input.Check(Keyboard.Key.D))
                {
                    physics.velocity.X += this.speed;
                }

                if (Input.Check(Keyboard.Key.S))
                {
                    if (!isDucking)
                    {
                        bodySprites.Play("Duck");
                    }
                    isDucking = true;
                }
                else
                {
                    if (isDucking)
                    {
                        bodySprites.Play("Stand");
                    }
                    isDucking = false;
                }

                //Attack
                if (Input.Pressed(Mouse.Button.Left))
                {
                    string nextAnim = hat.attackStart();
                    if (nextAnim != "")
                    {
                        faceSprites.Play(nextAnim);
                    }
                    isAttacking = true;
                }
                else if (Input.Released(Mouse.Button.Left))
                {
                    faceSprites.Play("Release");
                }
            }

            base.Update();

            //Animation stuff
            if (!isHurt)
            {
                //Flippin' stuffs
                if (physics.velocity.X > 0)
                {
                    bodySprites.FlippedX = false;
                    faceSprites.FlippedX = false;
                    Hat.hatmap.FlippedX  = false;
                }
                else if (physics.velocity.X < 0)
                {
                    bodySprites.FlippedX = true;
                    faceSprites.FlippedX = true;
                    Hat.hatmap.FlippedX  = true;
                }

                //Ground
                if (physics.isGrounded)
                {
                    if (isDucking)
                    {
                        //Idle
                        if (physics.velocity.X == 0)
                        {
                            bodySprites.Play("DuckIdle");
                        }
                        //Run
                        else
                        {
                            bodySprites.Play("DuckShuffle", false);
                        }
                    }
                    else
                    {
                        //Idle
                        if (physics.velocity.X == 0 && bodySprites.CurrentAnim != "Stand")
                        {
                            bodySprites.Play("Idle");
                            if (!isAttacking)
                            {
                                faceSprites.Play("Idle");
                            }
                        }
                        //Run
                        else if (physics.velocity.X != 0)
                        {
                            bodySprites.Play("Run");
                            if (!isAttacking)
                            {
                                faceSprites.Play("Run");
                            }
                        }
                    }
                }
                else                 //In air
                {
                    if (physics.velocity.Y > 0)
                    {
                        bodySprites.Play("JumpIdle");
                        //faceSprites.Play("JumpIdle");
                    }
                    else if (bodySprites.CurrentAnim != "FallIdle")
                    {
                        bodySprites.Play("Fall");
                        if (!isAttacking)
                        {
                            faceSprites.Play("Fall");
                        }
                    }
                }
            }

            bodySprites.Update();

            //get y offset of the face
            if (bodySprites.CurrentAnim != "")
            {
                AnimationData animData = BodyAnimDict[bodySprites.CurrentAnim];
                int[]         yoffset  = animData.yFacePoints;
                if (yoffset != null)
                {
                    faceSprites.OriginY = bodySprites.Height - yoffset[bodySprites.Index] / 4
                                          + faceSprites.Height - 10;
                }
            }

            faceSprites.Update();
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Erzeugt eine neue Instanz eines ChallengeModeScreen-Objekts und initialisiert diese mit einem Knot3Game-Objekt, einem Spielerknoten playerKnot und dem Knoten challengeKnot, den der Spieler nachbauen soll.
        /// </summary>
        public ChallengeModeScreen(GameCore game, Challenge challenge)
            : base(game)
        {
            // world
            PlayerWorld = new World (screen: this, drawOrder: DisplayLayer.GameWorld, bounds: Bounds.FromRight (percent: 0.5f));
            ChallengeWorld = new World (screen: this, drawOrder: DisplayLayer.GameWorld, bounds: Bounds.FromLeft (percent: 0.5f));
            ChallengeWorld.Camera = PlayerWorld.Camera;
            PlayerWorld.OnRedraw += () => ChallengeWorld.Redraw = true;
            ChallengeWorld.OnRedraw += () => PlayerWorld.Redraw = true;
            // input
            playerKnotInput = new KnotInputHandler (screen: this, world: PlayerWorld);
            challengeKnotInput = new KnotInputHandler (screen: this, world: ChallengeWorld);
            // overlay
            overlay = new Overlay (screen: this, world: PlayerWorld);
            // pointer
            pointer = new MousePointer (screen: this);
            // model mouse handler
            playerModelMouseHandler = new ModelMouseHandler (screen: this, world: PlayerWorld);
            challengeModelMouseHandler = new ModelMouseHandler (screen: this, world: ChallengeWorld);

            // knot renderer
            PlayerKnotRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            PlayerWorld.Add (PlayerKnotRenderer);
            ChallengeKnotRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            ChallengeWorld.Add (ChallengeKnotRenderer);

            // debug displays
            debugBoundings = new DebugBoundings (screen: this, position: Vector3.Zero);

            // edge movements
            PlayerEdgeMovement = new EdgeMovement (screen: this, world: PlayerWorld, knotRenderer: PlayerKnotRenderer, position: Vector3.Zero);
            PlayerEdgeMovement.KnotMoved = OnKnotMoved;

            // assign the specified challenge
            Challenge = challenge;
            // assign the specified player knot
            PlayerKnot = challenge.Start.Clone () as Knot;
            // assign the specified target knot
            ChallengeKnotRenderer.RenderKnot (challenge.Target);
            // assign the specified start knot
            PlayerKnotRenderer.RenderKnot (PlayerKnot);

            SkyCube playerSkyCube = new SkyCube (screen: this, position: Vector3.Zero, distance: 10000);
            PlayerWorld.Add (playerSkyCube);
            SkyCube challengeSkyCube = new SkyCube (screen: this, position: Vector3.Zero, distance: 10000);
            ChallengeWorld.Add (challengeSkyCube);

            // Die Spielzeit-Anzeige
            playTimeDisplay = new TextItem (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem, text: String.Empty);
            playTimeDisplay.Bounds.Position = new ScreenPoint (this, 0.800f, 0.01f);
            playTimeDisplay.Bounds.Size = new ScreenPoint (this, 0.15f, 0.04f);
            playTimeDisplay.BackgroundColorFunc = (s) => Design.WidgetBackground;
            playTimeDisplay.ForegroundColorFunc = (s) => Design.WidgetForeground;
            playTimeDisplay.AlignX = HorizontalAlignment.Center;
            playTimeBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                         widget: playTimeDisplay, lineWidth: 2, padding: 0);
            //Undo-Button
            undoButton = new Button (screen: this,
                                     drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                     name: "Undo",
                                     onClick: (time) => OnUndo ());
            undoButton.SetCoordinates (left: 0.55f, top: 0.900f, right: 0.65f, bottom: 0.95f);

            undoButtonBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                           widget: undoButton, lineWidth: 2, padding: 0);
            undoButton.AlignX = HorizontalAlignment.Center;
            undoButton.IsVisible = false;

            // Redo-Button
            redoButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Redo",
                onClick: (time) => OnRedo ()
            );
            redoButton.SetCoordinates (left: 0.70f, top: 0.900f, right: 0.80f, bottom: 0.95f);

            redoButtonBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                           widget: redoButton, lineWidth: 2, padding: 0);
            redoButton.AlignX = HorizontalAlignment.Center;
            redoButton.IsVisible = false;

            // die Linien
            lines = new Lines (screen: this, drawOrder: DisplayLayer.Dialog, lineWidth: 2);
            lines.AddPoints (0.500f, 0.000f, 0.500f, 1.000f);

            // Status
            state = ChallengeModeState.Start;
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Erzeugt eine neue Instanz eines CreativeModeScreen-Objekts und initialisiert diese mit einem Knot3Game-Objekt game, sowie einem Knoten knot.
        /// </summary>
        public JunctionEditorScreen(GameCore game)
            : base(game)
        {
            // die Spielwelt
            world = new World (screen: this, drawOrder: DisplayLayer.GameWorld, bounds: Bounds.FromLeft (0.60f));
            // der Input-Handler
            knotInput = new KnotInputHandler (screen: this, world: world);
            // der Mauszeiger
            pointer = new MousePointer (screen: this);
            // der Maus-Handler für die 3D-Modelle
            modelMouseHandler = new ModelMouseHandler (screen: this, world: world);

            // der Knoten-Renderer
            knotRenderer = new JunctionEditorRenderer (screen: this, position: Vector3.Zero);
            world.Add (knotRenderer);

            // visualisiert die BoundingSpheres
            debugBoundings = new DebugBoundings (screen: this, position: Vector3.Zero);
            world.Add (debugBoundings);

            // Hintergrund
            SkyCube skyCube = new SkyCube (screen: this, position: Vector3.Zero, distance: 10000);
            world.Add (skyCube);

            // Backbutton
            backButton = new MenuEntry (
                screen: this,
                drawOrder: DisplayLayer.Overlay + DisplayLayer.MenuItem,
                name: "Back",
                onClick: (time) => NextScreen = new StartScreen (Game)
            );
            backButton.AddKey (Keys.Escape);
            backButton.IsVisible = true;

            // Menü
            settingsMenu = new Menu (this, DisplayLayer.Overlay + DisplayLayer.Menu);
            settingsMenu.Bounds = Bounds.FromRight (0.40f).FromBottom (0.9f).FromLeft (0.8f);
            settingsMenu.Bounds.Padding = new ScreenPoint (this, 0.010f, 0.010f);
            settingsMenu.RelativeItemHeight = 0.030f;

            float[] validJunctionCounts = new float[] { 1, 2, 3 };
            optionJunctionCount = new FloatOption (
                section: "debug",
                name: "debug_junction_count",
                defaultValue: validJunctionCounts.At (-1),
                validValues: validJunctionCounts,
                configFile: Config.Default
            );
            itemJunctionCount = new ComboBox (
                screen: this,
                drawOrder: DisplayLayer.Overlay + DisplayLayer.MenuItem,
                text: "Junctions #"
            );
            itemJunctionCount.AddEntries (optionJunctionCount);
            itemJunctionCount.ValueChanged += OnJunctionCountChanged;

            Direction[] validDirections = Direction.Values;
            optionJuctionDirection = new DistinctOption [3];
            itemJunctionDirection = new ComboBox [3];
            for (int i = 0; i < 3; ++i) {
                DistinctOption option = new DistinctOption (
                    section: "debug",
                    name: "debug_junction_direction" + i.ToString (),
                    defaultValue: validDirections [i * 2],
                    validValues: validDirections.Select (d => d.Name),
                    configFile: Config.Default
                );
                ComboBox item = new ComboBox (
                    screen: this,
                    drawOrder: DisplayLayer.Overlay + DisplayLayer.MenuItem,
                    text: Localizer.Localize ("Direction ") + i.ToString ()
                );
                item.AddEntries (option);
                optionJuctionDirection [i] = option;
                item.ValueChanged += OnDirectionsChanged;
                itemJunctionDirection [i] = item;
            }

            itemBumpRotation = new ComboBox [3];
            for (int i = 0; i < 3; ++i) {
                ComboBox item = new ComboBox (
                    screen: this,
                    drawOrder: DisplayLayer.Overlay + DisplayLayer.MenuItem,
                    text: Localizer.Localize ("Bump Angle ") + i.ToString ()
                );
                item.ValueChanged += OnAnglesChanged;
                itemBumpRotation [i] = item;
            }

            itemModels = new ComboBox [3];
            for (int i = 0; i < 3; ++i) {
                ComboBox item = new ComboBox (
                    screen: this,
                    drawOrder: DisplayLayer.Overlay + DisplayLayer.MenuItem,
                    text: Localizer.Localize ("Model ") + i.ToString ()
                );
                item.ValueChanged += OnModelsChanged;
                itemModels [i] = item;
            }

            OnDirectionsChanged (null);
            OnJunctionCountChanged (null);

            world.Camera.PositionToTargetDistance = 180;
        }
Ejemplo n.º 37
0
        private CantileverTest()
        {
            Body ground = World.CreateEdge(new Vector2(-40, 0), new Vector2(40, 0));

            {
                PolygonShape shape = new PolygonShape(20);
                shape.Vertices = PolygonTools.CreateRectangle(0.5f, 0.125f);

                Body prevBody = ground;
                for (int i = 0; i < Count; ++i)
                {
                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(-14.5f + 1.0f * i, 5.0f);
                    body.CreateFixture(shape);

                    Vector2   anchor = new Vector2(-15.0f + 1.0f * i, 5.0f);
                    WeldJoint jd     = new WeldJoint(prevBody, body, anchor, anchor, true);
                    World.Add(jd);

                    prevBody = body;
                }
            }

            {
                PolygonShape shape = new PolygonShape(20f);
                shape.Vertices = PolygonTools.CreateRectangle(1f, 0.125f);

                Body prevBody = ground;
                for (int i = 0; i < 3; ++i)
                {
                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(-14.0f + 2.0f * i, 15.0f);
                    body.CreateFixture(shape);

                    Vector2   anchor = new Vector2(-15.0f + 2.0f * i, 15.0f);
                    WeldJoint jd     = new WeldJoint(prevBody, body, anchor, anchor, true);
                    jd.FrequencyHz  = 5.0f;
                    jd.DampingRatio = 0.7f;
                    World.Add(jd);

                    prevBody = body;
                }
            }

            {
                PolygonShape shape = new PolygonShape(20f);
                shape.Vertices = PolygonTools.CreateRectangle(0.5f, 0.125f);

                Body prevBody = ground;
                for (int i = 0; i < Count; ++i)
                {
                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(-4.5f + 1.0f * i, 5.0f);

                    body.CreateFixture(shape);

                    if (i > 0)
                    {
                        Vector2   anchor = new Vector2(-5.0f + 1.0f * i, 5.0f);
                        WeldJoint jd     = new WeldJoint(prevBody, body, anchor, anchor, true);
                        World.Add(jd);
                    }

                    prevBody = body;
                }
            }

            {
                PolygonShape shape = new PolygonShape(20f);
                shape.Vertices = PolygonTools.CreateRectangle(0.5f, 0.125f);

                Body prevBody = ground;
                for (int i = 0; i < Count; ++i)
                {
                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(5.5f + 1.0f * i, 10.0f);

                    body.CreateFixture(shape);

                    if (i > 0)
                    {
                        Vector2   anchor = new Vector2(5.0f + 1.0f * i, 10.0f);
                        WeldJoint jd     = new WeldJoint(prevBody, body, anchor, anchor, true);
                        jd.FrequencyHz  = 8.0f;
                        jd.DampingRatio = 0.7f;

                        World.Add(jd);
                    }

                    prevBody = body;
                }
            }

            //Triangels
            Vertices vertices = new Vertices(3);

            vertices.Add(new Vector2(-0.5f, 0.0f));
            vertices.Add(new Vector2(0.5f, 0.0f));
            vertices.Add(new Vector2(0.0f, 1.5f));

            for (int i = 0; i < 2; ++i)
            {
                PolygonShape shape = new PolygonShape(vertices, 1);

                Body body = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(-8.0f + 8.0f * i, 12.0f);

                body.CreateFixture(shape);
            }

            //Circles
            for (int i = 0; i < 2; ++i)
            {
                CircleShape shape = new CircleShape(0.5f, 1);

                Body body = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(-6.0f + 6.0f * i, 10.0f);

                body.CreateFixture(shape);
            }
        }
Ejemplo n.º 38
0
        /// <summary>
        /// This is a high-level function to cuts fixtures inside the given world, using the start and end points.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="start">The startpoint.</param>
        /// <param name="end">The endpoint.</param>
        /// <param name="thickness">The thickness of the cut</param>
        public static void Cut(World world, Vector2 start, Vector2 end, float thickness)
        {
            List <Fixture> fixtures    = new List <Fixture>();
            List <Vector2> entryPoints = new List <Vector2>();
            List <Vector2> exitPoints  = new List <Vector2>();

            //Get the entry points
            world.RayCast((f, p, n, fr) =>
            {
                fixtures.Add(f);
                entryPoints.Add(p);
                return(1);
            }, start, end);

            //Reverse the ray to get the exitpoints
            world.RayCast((f, p, n, fr) =>
            {
                exitPoints.Add(p);
                return(1);
            }, end, start);

            //We only have a single point. We need at least 2
            if (entryPoints.Count + exitPoints.Count < 2)
            {
                return;
            }

            //There should be as many entry as exit points
            if (entryPoints.Count != exitPoints.Count)
            {
                if (entryPoints.Count > exitPoints.Count)
                {
                    entryPoints.RemoveAt(entryPoints.Count - 1);
                    fixtures.RemoveAt(fixtures.Count - 1);
                }

                if (exitPoints.Count > entryPoints.Count)
                {
                    exitPoints.RemoveAt(exitPoints.Count - 1);
                    fixtures.RemoveAt(fixtures.Count - 1);
                }
            }

            for (int i = 0; i < fixtures.Count; i++)
            {
                if (fixtures[i].Shape.ShapeType != ShapeType.Polygon)
                {
                    continue;
                }

                //Split the shape up into two shapes
                Vertices first;
                Vertices second;
                SplitShape(fixtures[i], entryPoints[i], exitPoints[i], thickness, out first, out second);

                //Delete the original shape and create two new. Retain the properties of the body.
                Body body1 = fixtures[i].Body.Clone(world);
                world.Add(body1);

                PolygonShape shape1 = new PolygonShape(first, fixtures[i].Shape.Density);
                body1.CreateFixture(shape1);

                Body body2 = fixtures[i].Body.Clone(world);
                world.Add(body2);

                PolygonShape shape2 = new PolygonShape(second, fixtures[i].Shape.Density);
                body2.CreateFixture(shape2);

                world.Remove(fixtures[i].Body);
            }
        }
Ejemplo n.º 39
0
        public void Tick(Actor self)
        {
            if (allies1.WinState != WinState.Undefined)
            {
                return;
            }

            if (world.FrameNumber % 50 == 1 && chinookHusk.IsInWorld)
            {
                world.Add(new Smoke(world, chinookHusk.CenterPosition, "smoke_m"));
            }

            if (world.FrameNumber == 1)
            {
                InitializeSovietFactories();
                StartReinforcementsTimer();
            }

            reinforcementsTimer.Tick();

            if (world.FrameNumber == ParatroopersTicks)
            {
                MissionUtils.Paradrop(world, soviets, Badger1Passengers, badgerEntryPoint1.Location, badgerDropPoint1.Location);
                MissionUtils.Paradrop(world, soviets, Badger2Passengers, badgerEntryPoint1.Location + new CVec(3, 0), badgerDropPoint2.Location);
                MissionUtils.Paradrop(world, soviets, Badger3Passengers, badgerEntryPoint1.Location + new CVec(6, 0), badgerDropPoint3.Location);
            }
            if (world.FrameNumber == ParabombTicks)
            {
                MissionUtils.Parabomb(world, soviets, badgerEntryPoint2.Location, parabombPoint1.Location);
                MissionUtils.Parabomb(world, soviets, badgerEntryPoint2.Location + new CVec(0, 3), parabombPoint2.Location);
            }

            if (allies1 != allies2)
            {
                if (yak == null || (yak != null && !yak.IsDead() && (yak.GetCurrentActivity() is FlyCircle || yak.IsIdle)))
                {
                    var alliedUnitsNearYakPoint = world.FindAliveCombatantActorsInCircle(yakAttackPoint.CenterPosition, WRange.FromCells(10))
                                                  .Where(a => a.Owner != soviets && a.HasTrait <IPositionable>() && a != tanya && a != einstein && a != engineer);
                    if (alliedUnitsNearYakPoint.Any())
                    {
                        YakStrafe(alliedUnitsNearYakPoint);
                    }
                }
            }

            if (currentReinforcement > -1 && currentReinforcement < Reinforcements.Length && world.FrameNumber % 25 == 0)
            {
                SpawnAlliedUnit(Reinforcements[currentReinforcement++]);
            }

            if (world.FrameNumber % 25 == 0)
            {
                BuildSovietUnits();
                ManageSovietUnits();
            }

            UpdateDeaths();

            if (findEinstein.Status == ObjectiveStatus.InProgress)
            {
                if (AlliesNearTown())
                {
                    findEinstein.Status = ObjectiveStatus.Completed;
                    OnObjectivesUpdated(true);
                    TransferTownUnitsToAllies();
                    SovietsAttackTown();
                }
            }
            if (destroySamSites.Status == ObjectiveStatus.InProgress)
            {
                if (sams.All(s => s.IsDead() || s.Owner != soviets))
                {
                    destroySamSites.Status = ObjectiveStatus.Completed;
                    extractEinstein.Status = ObjectiveStatus.InProgress;

                    OnObjectivesUpdated(true);

                    world.CreateActor(SignalFlareName, new TypeDictionary {
                        new OwnerInit(allies1), new LocationInit(extractionLZ.Location)
                    });
                    Sound.Play("flaren1.aud");
                    ExtractEinsteinAtLZ();
                }
            }
            if (extractEinstein.Status == ObjectiveStatus.InProgress && einsteinChinook != null)
            {
                if (einsteinChinook.IsDead())
                {
                    extractEinstein.Status = ObjectiveStatus.Failed;
                    OnObjectivesUpdated(true);
                    MissionFailed("The extraction helicopter was destroyed.");
                }
                else if (!world.Map.IsInMap(einsteinChinook.Location) && einsteinChinook.Trait <Cargo>().Passengers.Contains(einstein))
                {
                    extractEinstein.Status  = ObjectiveStatus.Completed;
                    maintainPresence.Status = ObjectiveStatus.Completed;

                    if (fewDeaths.Status == ObjectiveStatus.InProgress)
                    {
                        fewDeaths.Status = ObjectiveStatus.Completed;
                    }

                    OnObjectivesUpdated(true);
                    MissionAccomplished("Einstein was rescued.");
                }
            }

            if (tanya.IsDead())
            {
                MissionFailed("Tanya was killed.");
            }

            else if (einstein.IsDead())
            {
                MissionFailed("Einstein was killed.");
            }

            world.AddFrameEndTask(w =>
            {
                if (!w.FindAliveCombatantActorsInBox(alliedBaseTopLeft, alliedBaseBottomRight)
                    .Any(a => (a.Owner == allies || a.Owner == allies2) && (a.HasTrait <Building>() && !a.HasTrait <Wall>()) || a.HasTrait <BaseBuilding>()))
                {
                    maintainPresence.Status = ObjectiveStatus.Failed;
                    OnObjectivesUpdated(true);
                    MissionFailed("The Allied reinforcements have been defeated.");
                }
            });
        }
Ejemplo n.º 40
0
 public void PrepWorld()
 {
     // car and fire truck are both red
     w.Add(red["car"]);
     w.Add(red["fire truck"]);
 }
Ejemplo n.º 41
0
        private CarTest()
        {
            _hz    = 4.0f;
            _zeta  = 0.7f;
            _speed = 50.0f;

            Body ground = World.CreateEdge(new Vector2(-20.0f, 0.0f), new Vector2(20.0f, 0.0f));
            {
                float[] hs = new[] { 0.25f, 1.0f, 4.0f, 0.0f, 0.0f, -1.0f, -2.0f, -2.0f, -1.25f, 0.0f };

                float       x = 20.0f, y1 = 0.0f;
                const float dx = 5.0f;

                for (int i = 0; i < 10; ++i)
                {
                    float y2 = hs[i];
                    ground.CreateEdge(new Vector2(x, y1), new Vector2(x + dx, y2));
                    y1 = y2;
                    x += dx;
                }

                for (int i = 0; i < 10; ++i)
                {
                    float y2 = hs[i];
                    ground.CreateEdge(new Vector2(x, y1), new Vector2(x + dx, y2));
                    y1 = y2;
                    x += dx;
                }

                var f1 = ground.CreateEdge(new Vector2(x, 0.0f), new Vector2(x + 40.0f, 0.0f));
                f1.Friction = 0.6f;
                x          += 80.0f;
                ground.CreateEdge(new Vector2(x, 0.0f), new Vector2(x + 40.0f, 0.0f));
                x += 40.0f;
                ground.CreateEdge(new Vector2(x, 0.0f), new Vector2(x + 10.0f, 5.0f));
                x += 20.0f;
                ground.CreateEdge(new Vector2(x, 0.0f), new Vector2(x + 40.0f, 0.0f));
                x += 40.0f;
                ground.CreateEdge(new Vector2(x, 0.0f), new Vector2(x, 20.0f));

                foreach (Fixture fixture in ground.FixtureList)
                {
                    fixture.Restitution = 0.6f;
                }
            }

            // Teeter
            {
                Body body = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(140.0f, 1.0f);

                PolygonShape box = new PolygonShape(1);
                box.Vertices = PolygonTools.CreateRectangle(10.0f, 0.25f);
                body.CreateFixture(box);

                RevoluteJoint jd = JointFactory.CreateRevoluteJoint(World, ground, body, Vector2.Zero);
                jd.LowerLimit   = -8.0f * MathHelper.Pi / 180.0f;
                jd.UpperLimit   = 8.0f * MathHelper.Pi / 180.0f;
                jd.LimitEnabled = true;

                body.ApplyAngularImpulse(100.0f);
            }

            //Bridge
            {
                const int    N     = 20;
                PolygonShape shape = new PolygonShape(1);
                shape.Vertices = PolygonTools.CreateRectangle(1.0f, 0.125f);

                Body prevBody = ground;
                for (int i = 0; i < N; ++i)
                {
                    Body body = World.CreateBody();
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(161.0f + 2.0f * i, -0.125f);
                    Fixture fix = body.CreateFixture(shape);
                    fix.Friction = 0.6f;

                    Vector2 anchor = new Vector2(-1, 0);
                    JointFactory.CreateRevoluteJoint(World, prevBody, body, anchor);

                    prevBody = body;
                }

                Vector2 anchor2 = new Vector2(1.0f, 0);
                JointFactory.CreateRevoluteJoint(World, ground, prevBody, anchor2);
            }

            // Boxes
            {
                PolygonShape box = new PolygonShape(0.5f);
                box.Vertices = PolygonTools.CreateRectangle(0.5f, 0.5f);

                Body body = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(230.0f, 0.5f);
                body.CreateFixture(box);

                body          = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(230.0f, 1.5f);
                body.CreateFixture(box);

                body          = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(230.0f, 2.5f);
                body.CreateFixture(box);

                body          = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(230.0f, 3.5f);
                body.CreateFixture(box);

                body          = World.CreateBody();
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(230.0f, 4.5f);
                body.CreateFixture(box);
            }

            // Car
            {
                Vertices vertices = new Vertices(8);
                vertices.Add(new Vector2(-1.5f, -0.5f));
                vertices.Add(new Vector2(1.5f, -0.5f));
                vertices.Add(new Vector2(1.5f, 0.0f));
                vertices.Add(new Vector2(0.0f, 0.9f));
                vertices.Add(new Vector2(-1.15f, 0.9f));
                vertices.Add(new Vector2(-1.5f, 0.2f));

                PolygonShape chassis = new PolygonShape(vertices, 1);

                CircleShape circle = new CircleShape(0.4f, 1);

                _car = World.CreateBody(new Vector2(0.0f, 1.0f), 0, BodyType.Dynamic);
                var cfixture = _car.CreateFixture(chassis);

                _wheel1 = World.CreateBody(new Vector2(-1.0f, 0.35f), 0, BodyType.Dynamic);
                var w1fixture = _wheel1.CreateFixture(circle);
                w1fixture.Friction = 0.9f;

                _wheel2 = World.CreateBody(new Vector2(1.0f, 0.4f), 0, BodyType.Dynamic);
                var w2fixture = _wheel2.CreateFixture(circle);
                w2fixture.Friction = 0.9f;

                Vector2 axis = new Vector2(0.0f, 1.0f);
                _spring1                = new WheelJoint(_car, _wheel1, _wheel1.Position, axis, true);
                _spring1.MotorSpeed     = 0.0f;
                _spring1.MaxMotorTorque = 20.0f;
                _spring1.MotorEnabled   = true;
                _spring1.Frequency      = _hz;
                _spring1.DampingRatio   = _zeta;
                World.Add(_spring1);

                _spring2                = new WheelJoint(_car, _wheel2, _wheel2.Position, axis, true);
                _spring2.MotorSpeed     = 0.0f;
                _spring2.MaxMotorTorque = 10.0f;
                _spring2.MotorEnabled   = false;
                _spring2.Frequency      = _hz;
                _spring2.DampingRatio   = _zeta;
                World.Add(_spring2);
            }
        }
Ejemplo n.º 42
0
        /// <summary>
        /// Erzeugt eine neue Instanz eines CreativeModeScreen-Objekts und initialisiert diese mit einem Knot3Game-Objekt game, sowie einem Knoten knot.
        /// </summary>
        public CreativeModeScreen(GameCore game, Knot knot)
            : base(game)
        {
            // die Spielwelt
            world = new World (screen: this, drawOrder: DisplayLayer.GameWorld, bounds: Bounds);
            // der Input-Handler
            knotInput = new KnotInputHandler (screen: this, world: world);
            // das Overlay zum Debuggen
            overlay = new Overlay (screen: this, world: world);
            // der Mauszeiger
            pointer = new MousePointer (screen: this);
            // der Maus-Handler für die 3D-Modelle
            modelMouseHandler = new ModelMouseHandler (screen: this, world: world);

            // der Knoten-Renderer
            knotRenderer = new KnotRenderer (screen: this, position: Vector3.Zero);
            world.Add (knotRenderer);

            // visualisiert die BoundingSpheres
            debugBoundings = new DebugBoundings (screen: this, position: Vector3.Zero);
            world.Add (debugBoundings);

            // der Input-Handler zur Kanten-Verschiebung
            edgeMovement = new EdgeMovement (screen: this, world: world, knotRenderer : knotRenderer, position: Vector3.Zero);
            edgeMovement.KnotMoved = OnKnotMoved;

            // der Input-Handler zur Kanten-Einfärbung
            edgeColoring = new EdgeColoring (screen: this);

            // Flächen zwischen Kanten
            edgeRectangles = new EdgeRectangles (screen: this);

            // assign the specified knot
            Knot = knot;

            // Hintergrund
            Sky skyCube = new Sky (screen: this, position: Vector3.Zero);
            world.Add (skyCube);

            // Sonne
            Sun sun = new Sun (screen: this);
            world.Add (sun);

            // Undo-Button
            undoButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Undo",
                onClick: (time) => OnUndo ()
            );
            undoButton.SetCoordinates (left: 0.05f, top: 0.900f, right: 0.15f, bottom: 0.95f);
            undoButton.AlignX = HorizontalAlignment.Center;
            undoButton.IsVisible = false;

            undoButtonBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                           widget: undoButton, lineWidth: 2, padding: 0);

            // Redo-Button
            redoButton = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "Redo",
                onClick: (time) => OnRedo ()
            );
            redoButton.SetCoordinates (left: 0.20f, top: 0.900f, right: 0.30f, bottom: 0.95f);
            redoButton.AlignX = HorizontalAlignment.Center;
            redoButton.IsVisible = false;

            redoButtonBorder = new Border (screen: this, drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                                           widget: redoButton, lineWidth: 2, padding: 0);

            invisible = new Button (
                screen: this,
                drawOrder: DisplayLayer.ScreenUI + DisplayLayer.MenuItem,
                name: "menu",
            onClick: (time) => {
                // erstelle einen neuen Pausedialog
                knotInput.IsEnabled = false;
                Dialog pauseDialog = new CreativePauseDialog (screen: this, drawOrder: DisplayLayer.Dialog, knot: Knot);
                // füge ihn in die Spielkomponentenliste hinzu
                pauseDialog.Close += (t) => knotInput.IsEnabled = true;
                AddGameComponents (time, pauseDialog);
            }
            );
            invisible.SetCoordinates (left: 1.00f, top: 1.00f, right: 1.10f, bottom: 1.10f);
            invisible.IsVisible = true;
            invisible.AddKey (Keys.Escape);
        }