コード例 #1
0
        public void Shoot()
        {
            var creationPosition = Position + Forward * 2;
            var scale            = Vector2.One * 0.2f;
            //bulletTexture, bulletTemplate, creationPosition, scale

            PhysicsObjectTemplate template = new PhysicsObjectTemplate
            {
                Position      = creationPosition,
                BodyTemplate  = bulletTemplate,
                Texture       = bulletTexture,
                PhysicsObject = new Laser(),
                Scale         = scale
            };

            var bulletRef = template.Create(scene).Item1.Convert <Laser>();

            bulletRef.Get(out var bullet);
            bullet.Scene  = scene;
            bullet.Source = this;
            bullet.Body.LinearVelocity = Body.LinearVelocity + Forward * 10;
            bullet.Body.IsBullet       = true;
            bullet.Body.OnCollision   += bullet.OnCollision;
            bullet.Damage        = 10;
            bullet.Body.Rotation = Rotation;
        }
コード例 #2
0
        CastRef <Ship> CreateShip(Texture2D shipTexture, BodyTemplate bodyTemplate, Vector2 position, Texture2D bulletTexture, BodyTemplate bulletTemplate, float health)
        {
            Ship ship = new Ship();

            ship.SetAssets(this, bulletTexture, bulletTemplate);
            ship.HealthAmount = health;

            PhysicsObjectTemplate template = new PhysicsObjectTemplate
            {
                Position      = position,
                BodyTemplate  = bodyTemplate,
                Texture       = shipTexture,
                PhysicsObject = ship
            };

            return(template.Create(this).Item1.Convert <Ship>());
        }