Ejemplo n.º 1
0
        private void LuoPelaaja(Vector position, double width, double height)
        {
            PlatformCharacter hahmo = new PlatformCharacter(40, 80);

            hahmo.Position = position;
            Add(hahmo);

            AssaultRifle ase = new AssaultRifle(60, 15);

            hahmo.Weapon = ase;

            //PlatformCharacter apu = new PlatformCharacter( 20, 20, Shape.Circle );
            PhysicsObject apu   = new PhysicsObject(20, 20, Shape.Circle);
            FollowerBrain aivot = new FollowerBrain(hahmo);

            aivot.DistanceClose       = 80;
            aivot.StopWhenTargetClose = true;
            apu.Brain          = aivot;
            apu.IgnoresGravity = true;
            Add(apu);

            AddCollisionHandler(apu, "ammus", delegate(PhysicsObject a, PhysicsObject b) { a.Destroy(); b.Destroy(); });

            Label hahmonNimi = new Label(RandomGen.NextLetter(true).ToString() + RandomGen.NextLetter(false).ToString());

            hahmonNimi.Bottom = hahmo.Height;
            hahmo.Add(hahmonNimi);

            Keyboard.Listen(Key.Space, ButtonState.Down, delegate { var ammus = ase.Shoot(); if (ammus != null)
                                                                    {
                                                                        ammus.Tag = "ammus";
                                                                    }
                            }, null);
            Keyboard.Listen(Key.Right, ButtonState.Down, () => hahmo.Walk(200), null);
            Keyboard.Listen(Key.Left, ButtonState.Down, () => hahmo.Walk(-200), null);
            Keyboard.Listen(Key.Up, ButtonState.Down, () => hahmo.Jump(600), null);
            Keyboard.Listen(Key.Enter, ButtonState.Pressed, delegate { if (!apu.IsDestroyed)
                                                                       {
                                                                           MessageDisplay.Add("boop!");
                                                                       }
                            }, null);
        }