Example #1
0
 /*
  * Author: Maarit Salo ITKP102 Harjoitustyö 2011
  */
 public override void Begin()
 {
     Level.CreateBorders();
     pelaajanHead     = PiirraPelattavatOsaset(this, 0, 0, 50.0, 50.0, Shape.Circle);
     pelaajanVartalo  = PiirraPelattavatOsaset(this, 0, 0, 50.0, 100.0, Shape.Rectangle);
     pelaaja          = new PhysicsStructure(pelaajanHead, pelaajanVartalo);
     pelaaja.Softness = 30;
     Add(pelaaja);
 }
Example #2
0
        public override void Initialize(GameScreen parentScreen)
        {
            base.Initialize(parentScreen);

            if (Settings.Physics != null)
            {
                var body = BodyFactory.CreateRectangle(
                    parentScreen.Physics.World,
                    Settings.Physics.Width * Settings.Scale.X,
                    Settings.Physics.Height * Settings.Scale.Y,
                    Settings.Physics.Density,
                    ConvertUnits.ToSimUnits(Settings.Position),
                    Settings.Physics.Offset);

                body.Enabled = false;

                body.FixtureList[0].CollidesWith        = (Category)Settings.Physics.CollidesWith;
                body.FixtureList[0].CollisionCategories = (Category)Settings.Physics.Category;
                body.FixtureList[0].CollisionGroup      = Settings.Physics.CollisionGroup;

                if (Settings.PhysicsFixture2 != null)
                {
                    Fixture fix2 = FixtureFactory.AttachRectangle(
                        Settings.PhysicsFixture2.Width,
                        Settings.PhysicsFixture2.Height,
                        Settings.PhysicsFixture2.Density,
                        Settings.PhysicsFixture2.Offset,
                        body);

                    fix2.CollidesWith        = (Category)Settings.PhysicsFixture2.CollidesWith;
                    fix2.CollisionCategories = (Category)Settings.PhysicsFixture2.Category;
                    fix2.CollisionGroup      = Settings.PhysicsFixture2.CollisionGroup;
                }

                body.BodyType = BodyType.Dynamic;
                body.Inertia  = Settings.Physics.RotationalInertia;

                physics = new PhysicsStructure
                {
                    Bodies = { body }
                };

                physics.Enabled = Settings.ActivateByDefault;
            }

            this.LevelScreen = (LevelScreen)parentScreen;
        }
Example #3
0
    public override void Begin()
    {
        Camera.ZoomToLevel();
        Level.Background.Color = Color.Black;

        PhysicsObject p1 = new PhysicsObject(2 * 100.0, 2 * 100.0, Shape.Circle);

        p1.Y = Level.Bottom + 200.0;
        Add(p1);

        PhysicsObject p2 = new PhysicsObject(2 * 50.0, 2 * 50.0, Shape.Circle);

        p2.Y = p1.Y + 100 + 50;
        Add(p2);

        PhysicsObject p3 = new PhysicsObject(2 * 30.0, 2 * 30.0, Shape.Circle);

        p3.Y = p2.Y + 50 + 30;
        Add(p3);

        PhysicsStructure ukko = new PhysicsStructure(p1, p2, p3);

        ukko.Softness = 10;
        Add(ukko);

        Gravity = new Vector(0, -400);
        Level.CreateBorders();
        p3.Hit(new Vector(80, 1));

        Timer t = new Timer();

        t.Interval = 5.0;
        t.Timeout += VaihdaPainovoimaa;
        t.Start();

        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu");
        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä näppäinohjeet");
        Keyboard.Listen(Key.Up, ButtonState.Pressed, LyoPalloa, "Lyö keskipalloa ylöspäin", p2, new Vector(0, 1000));
        Keyboard.Listen(Key.Down, ButtonState.Pressed, LyoPalloa, "Lyö keskipalloa alaspäin", p2, new Vector(0, -1000));
        Keyboard.Listen(Key.Left, ButtonState.Pressed, LyoPalloa, "Lyö keskipalloa vasemmalle", p2, new Vector(-1000, 0));
        Keyboard.Listen(Key.Right, ButtonState.Pressed, LyoPalloa, "Lyö keskipalloa oikealle", p2, new Vector(1000, 0));

        Keyboard.Listen(Key.W, ButtonState.Pressed, LyoPalloa, "Lyö alapalloa ylöspäin", p1, new Vector(0, 1000));
        Keyboard.Listen(Key.S, ButtonState.Pressed, LyoPalloa, "Lyö alapalloa alaspäin", p1, new Vector(0, -1000));
        Keyboard.Listen(Key.A, ButtonState.Pressed, LyoPalloa, "Lyö alapalloa vasemmalle", p1, new Vector(-1000, 0));
        Keyboard.Listen(Key.D, ButtonState.Pressed, LyoPalloa, "Lyö alapalloa oikealle", p1, new Vector(1000, 0));
    }
Example #4
0
    public override void Begin()
    {
        PhysicsStructure ukko = new PhysicsStructure();

        var pallo1 = new PhysicsObject(60, 60, Shape.Circle);

        ukko.Add(pallo1);

        var pallo2 = new PhysicsObject(40, 40, Shape.Circle);

        pallo2.Bottom = pallo1.Top;
        ukko.Add(pallo2);

        Gravity = Vector.UnitY * -200;
        Level.CreateBorders();
        Camera.ZoomToLevel();

        Mouse.Listen(MouseButton.Left, ButtonState.Pressed, ValitseOlio, null);
        Mouse.Listen(MouseButton.Left, ButtonState.Down, Liikuta, null);
        Mouse.Listen(MouseButton.Left, ButtonState.Released, IrroitaOlio, null);

        Add(ukko);
    }