public SpriteComponent(string filename)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentNullException(nameof(filename));
            }

            this.Texture = Texture2DLoader.Load(filename);

            this.Rectangle = new Rectangle(0, 0, this.Texture.Width, this.Texture.Height);
        }
Beispiel #2
0
        public Test(GraphicsDevice gd)
        {
            test = new Selection(0, 0, new string[] { "Duck", "Fillet", "I just want to get out of here!", "LALA" },
                                 "Testington");
            Texture2DLoader tl = new Texture2DLoader(Main.ContentManager.RootDirectory + "/test.zip", true);

            tl.Load();
            AS = new AnimatedSprite(TemporaryContent.GetTexture("dragon"), 40, 40, 100);

            AS.Position = new Vector2(300, 300);
        }
Beispiel #3
0
        private void ShootPlayerProjectile()
        {
            GameObject arrow = new GameObject(GameObject.Transform.Position,
                                              new Vector3(-MathHelper.PiOver2, 0, 0),
                                              "_Resources/Models/arrow.obj");

            arrow.Model.Texture              = Texture2DLoader.LoadFromFile("_Resources/Textures/sun.png");
            arrow.Model.Material             = new Material(new Vector3(0.15f), new Vector3(1), new Vector3(0.2f));
            arrow.Transform.PositionModifier = f => arrow.Transform.Position + new Vector3(0, 0.2f, 0);
            arrow.Transform.ScaleModifier    = f => new Vector3(1f, 1f, 1f);
            arrow.Model.VolumeShader         = GameManager.Shaders["light"];
            arrow.Model.Bind();
            _projectiles.Add(arrow);
        }
        private static GameObject CreateEnemyProjectile()
        {
            GameObject arrow = new GameObject(Vector3.Zero,
                                              new Vector3(-MathHelper.PiOver2, -MathHelper.PiOver2, -MathHelper.PiOver2),
                                              "_Resources/Models/cone.obj");

            arrow.ShouldNotRender            = true;
            arrow.Model.Texture              = Texture2DLoader.LoadFromFile("_Resources/Textures/sun.png");
            arrow.Model.Material             = new Material(new Vector3(0.15f), new Vector3(1), new Vector3(0.2f));
            arrow.Transform.PositionModifier = f => arrow.Transform.Position;
            arrow.Transform.ScaleModifier    = f => new Vector3(1f, 1f, 1f);
            arrow.Model.VolumeShader         = GameManager.Shaders["light"];
            arrow.Model.Bind();
            return(arrow);
        }
Beispiel #5
0
        public void LoadJpgTest()
        {
            EmbeddedResourceDirectory resourceDirectory = new("Zenseless.OpenTK.Tests.Content");

            using var stream = resourceDirectory.Resource("test.jpg").Open();
            Helper.ExecuteOnOpenGL(window =>
            {
                var tex = Texture2DLoader.Load(stream);
                Assert.AreEqual(335, tex.Width);
                Assert.AreEqual(1024, tex.Height);
                GL.GetTextureLevelParameter(tex.Handle, 0, GetTextureParameter.TextureInternalFormat, out int format);
                Assert.AreEqual((int)All.Rgb8, format);
                tex.Dispose();
                return(0);
            });
        }
Beispiel #6
0
        /// <summary>
        /// Initialize the level.
        /// </summary>
        public void Initialize()
        {
            LoadFunc = () =>
            {
                if (Texture2DLoader != null)
                {
                    Texture2DLoader.Load();
                }

                if (SoundEffectLoader != null)
                {
                    SoundEffectLoader.Load();
                }

                PrepareLevel();
            };

            LoadThread = new Thread(LoadFunc);
            LoadThread.Start();

            Initialized = true;
        }
Beispiel #7
0
        public Title()
        {
            this.Texture2DLoader   = new Texture2DLoader(Main.ContentManager.RootDirectory + "/Compressed/ShooterTextures.zip", false);
            this.SoundEffectLoader = new Content.SoundEffectLoader(Main.ContentManager.RootDirectory +
                                                                   "/Compressed/ShooterSoundEffects.zip", false);

            LoadFunc = () =>
            {
                TitleScreenTexture = Texture2D.FromStream(Main.GraphicsDevice,
                                                          File.OpenRead(Main.ContentManager.RootDirectory + "/Textures/TitleScreen.dat"));

                if (Texture2DLoader != null)
                {
                    Texture2DLoader.Load();
                }
                if (SoundEffectLoader != null)
                {
                    SoundEffectLoader.Load();
                }
            };

            LoadThread = new Thread(LoadFunc);
            LoadThread.Start();
        }
        public override void CreateScene()
        {
            GameObject cubePlane = new GameObject(new Vector3(0f, 0f, 0f),
                                                  new Vector3(MathHelper.PiOver2, 0, 0f),
                                                  "_Resources/Models/simple_cube.obj");

            cubePlane.Model.Texture       = Texture2DLoader.LoadFromFile("_Resources/Textures/galaxy.png");
            cubePlane.Transform.Position += new Vector3(0f, 0f, 0f);
            cubePlane.Transform.Rotation  = new Vector3(MathHelper.PiOver2, 0, 0f);
            cubePlane.Model.Material      = new Material(new Vector3(0.5f), new Vector3(1), new Vector3(0.2f));
            //cubePlane.Transform.PositionModifier = f => new Vector3(2 * (float)Math.Sin(MathHelper.DegreesToRadians(f * 80 % 360)), 0f, 2 * (float)Math.Cos(MathHelper.DegreesToRadians(f * 80 % 360)));
            cubePlane.Transform.ScaleModifier = f => new Vector3(50f, 0.1f, 50f);
            cubePlane.Model.PbrValues         = new Model.PBRValues
            {
                AO                 = 0.5f,
                Metallic           = 0.5f,
                ReflectionStrength = 0.5f,
                Refraction         = 4f,
                Roughness          = 0.5f
            };
            cubePlane.Model.VolumeShader = GameManager.Shaders[GameManager.ActiveShader];
            cubePlane.Model.Bind();

            GameObject playerShip = new GameObject(new Vector3(0f, -40f, -10f),
                                                   new Vector3(-MathHelper.PiOver2, 0, 0),
                                                   new Vector3(0.05f, 0.05f, 0.05f),
                                                   "_Resources/Models/ship2.obj");

            playerShip.Model.Material  = new Material(new Vector3(1), new Vector3(1), new Vector3(0.8f));
            playerShip.Model.Texture   = Texture2DLoader.LoadFromFile("_Resources/Textures/ship2_diffuse.bmp");
            playerShip.Model.PbrValues = new Model.PBRValues
            {
                AO                 = 1f,
                Metallic           = 0.5f,
                ReflectionStrength = 0f,
                Refraction         = 0f,
                Roughness          = 0f
            };
            playerShip.Model.VolumeShader = GameManager.Shaders["light"];
            playerShip.Model.Bind();
            playerShip.AddComponent <PlayerComponent>();
            playerShip.AddComponent <ShooterComponent>();

            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < 6; i++)
                {
                    GameObject ship = new GameObject(new Vector3(40f - 15 * i, 20f - 10 * j, 0f), new Vector3(MathHelper.Pi, 0, -MathHelper.PiOver2), Vector3.One, ModelLoader.LoadFromFile("_Resources/Models/ship_dread_t.obj"));
                    ship.Model.Texture = Texture2DLoader.LoadFromFile("_Resources/Textures/dread_ship_t.png");
                    //ship.Transform.Position += new Vector3(40f - 15 * i, 20f - 10 * j, 0f);
                    ship.Transform.PositionModifier = f => ship.Transform.Position + new Vector3((float)Math.Sin(GameManager.Time) / 100f, -GameManager.Time / 1000f, 0);
                    ship.Transform.Rotation         = new Vector3(MathHelper.Pi, 0, -MathHelper.PiOver2);
                    ship.Model.Material             = new Material(new Vector3(0.5f), new Vector3(1), new Vector3(0.8f));
                    //cubePlane.PositionModifier = f => new Vector3(2 * (float)Math.Sin(MathHelper.DegreesToRadians(f * 80 % 360)), 0f, 2 * (float)Math.Cos(MathHelper.DegreesToRadians(f * 80 % 360)));
                    ship.Transform.ScaleModifier = f => new Vector3(0.005f, 0.005f, 0.005f);
                    ship.Model.PbrValues         = new Model.PBRValues
                    {
                        AO                 = 0.5f,
                        Metallic           = 0.5f,
                        ReflectionStrength = (float)Basic.Random.NextDouble(),
                        Refraction         = 0f,
                        Roughness          = 0.5f
                    };
                    ship.Model.VolumeShader = GameManager.Shaders["PBR"];
                    ship.Model.Bind();
                    ship.AddComponent <EnemyComponent>();
                }
            }

            ReorganizeCollections();
            foreach (var gameObject in _gameObjects)
            {
                gameObject.Start();
            }
        }