Skip to content
Snippets Groups Projects

CollisionIgnoreGroup aseelle

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Denis Zhidkikh
    Edited
    CollisionIgnoreGroupTest.cs 2.12 KiB
    using Jypeli;
    using Jypeli.Assets;
    
    public class CollisionIgnoreGroupTest : PhysicsGame
    {
        public override void Begin()
        {
            const int speed = 500;
            const int jumpSpeed = 1000;
            const int maxBaddies = 10;
    
            Gravity = -1000 * Vector.UnitY;
            Level.CreateBottomBorder();
    
            var player = new PlatformCharacter(50, 50)
            {
                CollisionIgnoreGroup = 1, // Pelaajalla sama CIG kuin vihulla, mutta ei aseella => ammuksien pitäisi osua viholliseen
                CanRotate = false,
                Weapon = new AssaultRifle(40, 30)
                {
                    CanHitOwner = false,
                    ProjectileCollision = (ammo, other) =>
                    {
                        if (other.Tag.ToString() == "bad")
                            other.Destroy();
                        ammo.Destroy();
                    }
                }
            };
            Add(player);
            Camera.Follow(player);
    
            for (var i = 0; i < maxBaddies; i++)
                Add(new PhysicsObject(30, 50)
                {
                    Color = Color.Blue,
                    CollisionIgnoreGroup = 1,  // Pelaajalla sama CIG kuin vihulla, mutta ei aseella => ammuksien pitäisi osua viholliseen
                    X = RandomGen.NextDouble(Level.Left, Level.Right),
                    CanRotate = false,
                    Tag = "bad"
                });
    
            Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Exit game");
            Keyboard.Listen(Key.A, ButtonState.Down,
                            () => player.Move(-speed * Vector.UnitX), "Move Left");
            Keyboard.Listen(Key.D, ButtonState.Down,
                            () => player.Move(speed * Vector.UnitX), "Move Right");
            Keyboard.Listen(Key.W, ButtonState.Pressed,
                            () => player.Jump(jumpSpeed), "Move Right");
            Keyboard.Listen(Key.Space, ButtonState.Down, () =>
            {
                var proj = player.Weapon.Shoot();
                if (proj != null)
                {
                    //proj.CollisionIgnoreGroup = 0; // Resetoi sekä ammuksen ETTÄ pelaajan CIG => pelaaja alkaa törmäillä vihuihin
                    Add(proj);
                }
            }, "Move Right");
        }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment