Example #1
0
        /// <summary>
        /// Create thrusts backfire effect and attach to target gameobject.
        /// </summary>
        /// <param name="target">Object to add effect to.</param>
        private void AddBackfireEffect(GameObject target)
        {
            // create a particle type of the ship thrust fire effect
            BaseAnimatorProperties prop     = BaseAnimatorProperties.Defaults;
            GameObject             backfire = new GameObject("backfire");

            // create a sphere renderer for the backfire particle
            ShapeRenderer renderer = backfire.AddComponent(new ShapeRenderer(ShapeMeshes.SphereSmooth)) as ShapeRenderer;

            renderer.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects;

            // add animators, jitter and time-to-live
            backfire.AddComponent(new TimeToLive(0.5f));
            backfire.AddComponent(new SpawnRandomizer(minColor: Color.Red, maxColor: Color.Yellow));
            backfire.AddComponent(new FadeAnimator(prop, 1.0f, 0f, 0.5f));
            backfire.AddComponent(new ScaleAnimator(prop, 0.5f, 0.1f, 0.5f));
            backfire.AddComponent(new MotionAnimator(prop, Vector3.Backward * 15));

            // create particles system for the backfire effect
            GameObject backfireSystem = new GameObject("backfire-system");

            backfireSystem.SceneNode.PositionZ = 1f;
            ParticleSystem system = backfireSystem.AddComponent(new ParticleSystem()) as ParticleSystem;

            // add our backfire particle and set frequency
            system.AddParticleType(new ParticleType(backfire, frequency: 1.0f));
            system.Interval           = 0.025f;
            system.AddParticlesToRoot = true;

            // attach particle system to player
            backfireSystem.Parent = target;
        }
Example #2
0
        /// <summary>
        /// Create explosion effect object prototype.
        /// </summary>
        private void InitExplosions()
        {
            // create an explosion object
            BaseAnimatorProperties prop      = BaseAnimatorProperties.Defaults;
            GameObject             explosion = new GameObject("explosion");

            // create a sphere renderer for the explosion effect
            ShapeRenderer renderer = explosion.AddComponent(new ShapeRenderer(ShapeMeshes.SphereSmooth)) as ShapeRenderer;

            renderer.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects;

            // add animators, jitter and time-to-live
            explosion.AddComponent(new TimeToLive(0.5f));
            explosion.AddComponent(new SpawnRandomizer(minColor: Color.Red, maxColor: Color.Yellow));
            explosion.AddComponent(new FadeAnimator(prop, 1.0f, 0f, 0.5f));
            explosion.AddComponent(new ScaleAnimator(prop, 0.5f, 2.5f, 0.5f));

            // add sound when explosion spawns
            SoundEffect explosionSound = new SoundEffect("game/explode");

            explosionSound.PlayOnSpawn = true;
            explosion.AddComponent(explosionSound);

            // register as prototype
            Managers.Prototypes.Register(explosion);


            // create particles system for multiple explosions effect
            explosion.AddComponent(new SpawnRandomizer(positionJitter: Vector3.One * 1.5f));
            GameObject     explosionsSet = new GameObject("explosions-set");
            ParticleSystem system        = explosionsSet.AddComponent(new ParticleSystem()) as ParticleSystem;

            // add our explosion particle and set frequency
            system.AddParticleType(new ParticleType(explosion, frequency: 1.0f, frequencyChange: -0.35f));
            system.Interval   = 0.05f;
            system.TimeToLive = 3.0f;
            system.DestroyParentWhenExpired = true;
            system.AddParticlesToRoot       = true;

            // register as prototype
            Managers.Prototypes.Register(explosionsSet);
        }
Example #3
0
        /// <summary>
        /// Create the meteor object prototype.
        /// </summary>
        /// <param name="scene">Game main scene.</param>
        private void InitAsteroids(GameScene scene)
        {
            // create the asteroid gameobject
            GameObject asteroid = new GameObject("asteroid");

            // create the asteroid physical body
            RigidBody asteroidBody = new RigidBody(new SphereInfo(1.5f), mass: 500f);

            asteroidBody.Gravity    = Vector3.Zero;
            asteroidBody.IsEthereal = true;
            asteroid.AddComponent(asteroidBody);

            // add asteroid controller component
            asteroid.AddComponent(new AsteroidControls());

            // create the asteroid model renderer
            GameObject asteroidModelObject = new GameObject("model");

            asteroidModelObject.Parent = asteroid;
            ModelRenderer astroidModelRenderer = new ModelRenderer("game/astroid");

            astroidModelRenderer.MaterialOverride.Texture       = Resources.GetTexture("game/astroid_tex");
            astroidModelRenderer.MaterialOverride.SpecularColor = Color.Black;
            asteroidModelObject.AddComponent(astroidModelRenderer);

            // register the asteroid prototype
            Managers.Prototypes.Register(asteroid);

            // create a particle system to generate asteroids randomly
            ParticleSystem asteroidsGenerator = new ParticleSystem();

            asteroidsGenerator.AddParticleType(new ParticleType(asteroid, frequency: 0.08f, frequencyChange: 0.00085f));
            asteroidsGenerator.Interval           = 0.25f;
            asteroidsGenerator.AddParticlesToRoot = true;

            // add asteroids generator to scene
            scene.Root.AddComponent(asteroidsGenerator);
        }
Example #4
0
        /// <summary>
        /// Initialize to implement per main type.
        /// </summary>
        override public void Initialize()
        {
            // set default scene node type
            GameObject.DefaultSceneNodeType = SceneNodeType.Simple;

            // create the scene
            GameScene scene = new GameScene();

            // add instructions
            GeonBit.UI.Entities.Paragraph instructions = new GeonBit.UI.Entities.Paragraph("Press number keys (1-9) to change particle types.");
            scene.UserInterface.AddEntity(instructions);

            // add diagnostic data paragraph to scene
            var diagnosticData = new GeonBit.UI.Entities.Paragraph("", GeonBit.UI.Entities.Anchor.BottomLeft, offset: Vector2.One * 10f, scale: 0.7f);

            diagnosticData.BeforeDraw = (GeonBit.UI.Entities.Entity entity) =>
            {
                diagnosticData.Text = Managers.Diagnostic.GetReportString();
            };
            scene.UserInterface.AddEntity(diagnosticData);

            // create camera
            camera = new GameObject();
            Camera cameraComponent = new Camera();

            cameraComponent.LookAt = Vector3.Zero;
            camera.AddComponent(cameraComponent);
            camera.SceneNode.PositionZ = 50;
            camera.SceneNode.PositionY = 50;
            camera.AddComponent(new CameraEditorController());
            camera.Parent = scene.Root;

            // add skybox
            Managers.GraphicsManager.CreateSkybox(null, scene.Root);

            // particle system: red fountain
            {
                // define the particle
                GameObject    particle = new GameObject("particle", SceneNodeType.ParticlesNode);
                ShapeRenderer shape    = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer;
                shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects;
                particle.AddComponent(new TimeToLive(3f));
                particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 1f, 0f, 2.5f, 0.5f));
                particle.AddComponent(new MotionAnimator(BaseAnimatorProperties.Defaults, Vector3.Up * 25f, acceleration: Vector3.Down * 15f, velocityDirectionJitter: Vector3.One * 5));
                particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 1.5f, 4f, 0.5f, 0.5f, 0.5f));
                particle.AddComponent(new ColorAnimator(BaseAnimatorProperties.Defaults, Color.Red, Color.Orange, 3f));

                // create particles system
                GameObject     systemObject = new GameObject("system1", SceneNodeType.Simple);
                ParticleSystem system       = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem;
                system.AddParticleType(new ParticleType(particle, frequency: 0.85f));
                systemObject.Parent = scene.Root;
                _systems.Add(systemObject);
            }

            // particle system: gas cloud
            {
                // define the particle
                GameObject    particle = new GameObject("particle");
                ShapeRenderer shape    = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer;
                shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects;
                particle.AddComponent(new TimeToLive(3f));
                particle.AddComponent(new SpawnRandomizer(positionJitter: Vector3.One * 2f));
                particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 0.75f, 0f, 2.5f, 0.5f));
                particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 1.5f), Vector3.One, velocityDirectionJitter: Vector3.One));
                particle.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 1f));
                particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 1.5f, 4f, 0.5f, 0.5f, 0.5f));
                particle.AddComponent(new ColorAnimator(BaseAnimatorProperties.Defaults, Color.Green, Color.Black, 3f, startColorJitter: Color.Blue));

                // create particles system
                GameObject     systemObject = new GameObject("system2");
                ParticleSystem system       = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem;
                system.AddParticleType(new ParticleType(particle, frequency: 0.35f));
                systemObject.Parent = scene.Root;
                _systems.Add(systemObject);
            }

            // particle system: balls madness
            {
                // define the particle
                GameObject    particle = new GameObject("particle");
                ShapeRenderer shape    = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer;
                shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Solid;
                particle.AddComponent(new TimeToLive(3f));
                particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 25f), Vector3.One, velocityDirectionJitter: Vector3.One));
                particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 1.5f, 4f, 0.5f, 0.5f, 0.5f));
                particle.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 20f, 4f));
                particle.AddComponent(new ColorAnimator(BaseAnimatorProperties.Defaults, Color.Black, Color.Black, 1f, startColorJitter: Color.White, endColorJitter: Color.White));

                // create particles system
                GameObject     systemObject = new GameObject("system3");
                ParticleSystem system       = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem;
                system.AddParticleType(new ParticleType(particle, frequency: 0.85f));
                systemObject.Parent = scene.Root;
                _systems.Add(systemObject);
            }

            // particle system: rain
            {
                // define the particle
                GameObject    particle = new GameObject("particle");
                ShapeRenderer shape    = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer;
                shape.RenderingQueue         = GeonBit.Core.Graphics.RenderingQueue.Solid;
                particle.SceneNode.PositionY = 50;
                particle.AddComponent(new TimeToLive(3f));
                particle.AddComponent(new SpawnRandomizer(positionJitter: new Vector3(100, 0, 40)));
                particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 25f), Vector3.Down));

                // create particles system
                GameObject     systemObject = new GameObject("system4");
                ParticleSystem system       = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem;
                system.AddParticleType(new ParticleType(particle, frequency: 0.85f));
                systemObject.Parent = scene.Root;
                _systems.Add(systemObject);
            }

            // particle system: explosions
            {
                // define the particle
                GameObject    particle = new GameObject("particle");
                ShapeRenderer shape    = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer;
                shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects;
                particle.AddComponent(new TimeToLive(1f));
                particle.AddComponent(new SpawnRandomizer(positionJitter: Vector3.One * 2f, minColor: new Color(200, 75, 0), maxColor: new Color(255, 225, 50)));
                particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 1.0f, 0f, 1.0f, 0.25f));
                particle.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 1f));
                particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 2.5f, 1f, 0.15f, 0.25f, 0.25f));
                particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 2f), Vector3.Zero, velocityDirectionJitter: Vector3.One));
                GameObject particle2 = particle.Clone();
                particle.GetComponent <ShapeRenderer>().BlendingState = GeonBit.Core.Graphics.BlendStates.Additive;

                // create particles system
                GameObject     systemObject = new GameObject("system5");
                ParticleSystem system       = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem;
                system.AddParticleType(new ParticleType(particle, frequency: 0.85f));
                system.AddParticleType(new ParticleType(particle2, frequency: 0.85f));
                systemObject.Parent = scene.Root;
                _systems.Add(systemObject);
            }

            // particle system: backfire
            {
                // define the particle
                GameObject    particle = new GameObject("particle");
                ShapeRenderer shape    = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer;
                shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects;
                particle.AddComponent(new TimeToLive(1f));
                particle.AddComponent(new SpawnRandomizer(minColor: new Color(200, 75, 0), maxColor: new Color(255, 225, 50)));
                particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 1.0f, 0f, 0.8f));
                particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 1.5f, 0.1f, 1f, 0.15f, 0.15f, 0.15f));
                particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 25f), Vector3.Down));

                // create an object that's rotating the particles system position around center
                GameObject rotator = new GameObject();
                rotator.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 2f));
                rotator.Parent = scene.Root;

                // create particles system
                GameObject systemObject = new GameObject("system6");
                systemObject.SceneNode.PositionY = 10f;
                ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem;
                system.AddParticleType(new ParticleType(particle, frequency: 1.0f));
                system.Interval           = 0.015f;
                system.AddParticlesToRoot = true;
                systemObject.Parent       = rotator;
                _systems.Add(systemObject);
            }

            // particle system: magic
            {
                // define the particle
                GameObject    particle = new GameObject("particle");
                ShapeRenderer shape    = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer;
                shape.BlendingState  = GeonBit.Core.Graphics.BlendStates.Additive;
                shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects;
                particle.AddComponent(new TimeToLive(3f));
                particle.AddComponent(new SpawnRandomizer(positionJitter: Vector3.One * 2.5f, minColor: Color.Red * 0.25f, maxColor: Color.White * 0.25f));
                particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 0.75f, 0f, 2.5f, 0.5f));
                particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 1.5f), Vector3.One, velocityDirectionJitter: Vector3.One));
                particle.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 1f));
                particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 2.5f, 4f, 0.5f, 0.5f, 0.5f));

                // create particles system
                GameObject     systemObject = new GameObject("system7");
                ParticleSystem system       = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem;
                system.AddParticleType(new ParticleType(particle, frequency: 0.3f));
                systemObject.Parent = scene.Root;
                _systems.Add(systemObject);
            }

            // particle system: magic missile
            {
                // define the particle
                GameObject    particle = new GameObject("particle");
                ShapeRenderer shape    = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer;
                shape.BlendingState  = GeonBit.Core.Graphics.BlendStates.Additive;
                shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects;
                particle.AddComponent(new TimeToLive(3f));
                particle.AddComponent(new SpawnRandomizer(positionJitter: Vector3.One * 2.5f, minColor: Color.Red * 0.25f, maxColor: Color.White * 0.25f));
                particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 0.75f, 0f, 2.5f, 0.5f));
                particle.AddComponent(new MotionAnimator(new BaseAnimatorProperties(speedFactor: 1.5f), Vector3.One, velocityDirectionJitter: Vector3.One));
                particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.5f, 2.5f, 4f, 0.5f, 0.5f, 0.5f));

                // define another type of particle
                GameObject    particle2 = new GameObject("particle2");
                ShapeRenderer shape2    = particle2.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer;
                shape2.BlendingState  = GeonBit.Core.Graphics.BlendStates.Additive;
                shape2.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects;
                particle2.AddComponent(new TimeToLive(2f));
                particle2.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 1.5f, 0.1f, 1.5f, 0.15f, 0.15f, 0.15f));
                particle2.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 0.5f, 0f, 1.5f, 0.5f));

                // create an object that's rotating the particles system position around center
                GameObject rotator = new GameObject();
                rotator.AddComponent(new RotationAnimator(BaseAnimatorProperties.Defaults, 2f));
                rotator.Parent = scene.Root;

                // create particles system
                GameObject systemObject = new GameObject("system8");
                systemObject.SceneNode.PositionY = 10f;
                ParticleSystem system = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem;
                system.AddParticleType(new ParticleType(particle, frequency: 0.3f));
                system.AddParticleType(new ParticleType(particle2, frequency: 0.5f));
                system.AddParticlesToRoot = true;
                systemObject.Parent       = rotator;
                _systems.Add(systemObject);
            }

            // particle system: smoke
            {
                // define the particle
                GameObject    particle = new GameObject("particle");
                ShapeRenderer shape    = particle.AddComponent(new ShapeRenderer(ShapeMeshes.Sphere), "model") as ShapeRenderer;
                shape.RenderingQueue = GeonBit.Core.Graphics.RenderingQueue.Effects;
                particle.AddComponent(new TimeToLive(3f));
                particle.AddComponent(new FadeAnimator(BaseAnimatorProperties.Defaults, 1f, 0f, 2.5f, 0.5f));
                particle.AddComponent(new MotionAnimator(BaseAnimatorProperties.Defaults, Vector3.Up * 10f, velocityDirectionJitter: Vector3.One * 0.75f));
                particle.AddComponent(new ScaleAnimator(BaseAnimatorProperties.Defaults, 0.25f, 3.5f, 4f, 0.5f, 0.5f, 0.5f));
                particle.AddComponent(new ColorAnimator(BaseAnimatorProperties.Defaults, Color.Purple, Color.Black, 3f));

                // create particles system
                GameObject     systemObject = new GameObject("system9");
                ParticleSystem system       = systemObject.AddComponent(new ParticleSystem()) as ParticleSystem;
                system.AddParticleType(new ParticleType(particle, frequency: 0.35f));
                systemObject.Parent = scene.Root;
                _systems.Add(systemObject);
            }

            // select default system
            SelectParticleSystem(0);

            // set scene
            GeonBitMain.Instance.Application.LoadScene(scene);
        }