예제 #1
0
        public RangeIndicator(ActorModel actorModel, GraphicsDevice graphicsDevice, Effect billboardEffect, Texture2D texture)
        {
            this.actorModel = actorModel;
            this.graphicsDevice = graphicsDevice;
            this.billboardEffect = billboardEffect;
            this.texture = texture;

            vertices = new VertexPositionTexture[6];
            vertices[0] = new VertexPositionTexture(new Vector3(-1, 0, -1), new Vector2(0, 0));
            vertices[1] = new VertexPositionTexture(new Vector3(1, 0, -1), new Vector2(1, 0));
            vertices[2] = new VertexPositionTexture(new Vector3(-1, 0, 1), new Vector2(0, 1));
            vertices[3] = new VertexPositionTexture(new Vector3(1, 0, -1), new Vector2(1, 0));
            vertices[4] = new VertexPositionTexture(new Vector3(1, 0, 1), new Vector2(1, 1));
            vertices[5] = new VertexPositionTexture(new Vector3(-1, 0, 1), new Vector2(0, 1));
        }
예제 #2
0
        public ActorWidgets(GraphicsDevice graphicsDevice, Effect effect, Texture2D selectionTexture, Texture2D destinationTexture, Texture2D orderedDestinationTexture, ActorModel actor)
        {
            this.graphicsDevice = graphicsDevice;
            this.billboardEffect = effect;
            this.selectionTexture = selectionTexture;
            this.destinationTexture = destinationTexture;
            this.orderedDestinationTexture = orderedDestinationTexture;
            this.selectedActor = actor;

            vertices = new VertexPositionTexture[6];
            vertices[0] = new VertexPositionTexture(new Vector3(-1, 0, -1), new Vector2(0, 0));
            vertices[1] = new VertexPositionTexture(new Vector3(1, 0, -1), new Vector2(1, 0));
            vertices[2] = new VertexPositionTexture(new Vector3(-1, 0, 1), new Vector2(0, 1));
            vertices[3] = new VertexPositionTexture(new Vector3(1, 0, -1), new Vector2(1, 0));
            vertices[4] = new VertexPositionTexture(new Vector3(1, 0, 1), new Vector2(1, 1));
            vertices[5] = new VertexPositionTexture(new Vector3(-1, 0, 1), new Vector2(0, 1));
        }
예제 #3
0
        public override void Update(GameTime gameTime)
        {
            selectedActors.RemoveAll(x => !x.IsAlive);

            foreach (var actor in battle.Actors.Where(x => !scene.Nodes.OfType<ActorModel>().Any(y => y.Actor == x)))
            {
                var actorTexture = ContentManager.SafeLoad<Texture2D>(@"Models\Actors\" + actor.TextureName + "_portrait", @"Models\Actors\warrior_portrait");
                var actorModel = new ActorModel(actor, actorTexture, ContentManager, ScreenManager.GraphicsDevice, ContentManager.Load<Effect>(@"Shaders\Particle"));

                actorModel.Nodes.Add(new Shadow(ScreenManager.GraphicsDevice, ContentManager.Load<Effect>(@"Shaders\billboard"), ContentManager.Load<Texture2D>(@"Sprites\shadow"), actor));
                actorModel.Nodes.Add(new RangeIndicator(actorModel, ScreenManager.GraphicsDevice, ContentManager.Load<Effect>(@"Shaders\billboard"), ContentManager.Load<Texture2D>(@"Interface\circlearea")));
                actorModel.Nodes.Add(new ActorWidgets(ScreenManager.GraphicsDevice, ContentManager.Load<Effect>(@"Shaders\billboard"), ContentManager.Load<Texture2D>(@"Interface\selection"), ContentManager.Load<Texture2D>(@"Interface\destination"), ContentManager.Load<Texture2D>(@"Interface\destination2"), actorModel));
                actorModel.Nodes.Add(new AbilityAnimation(actor, ScreenManager.GraphicsDevice, ContentManager.Load<Effect>(@"Shaders\billboard"), ContentManager.Load<Texture2D>(@"Sprites\attack_sword_1")));

                scene.Nodes.Add(actorModel);
            }

            foreach (var actorModel in scene.Nodes.OfType<ActorModel>().OrderBy(a => a.Actor.Position.Y))
            {
                actorModel.IsMouseOver = actorModel.Actor == mouseOverActor;
                actorModel.IsTargeted = selectedActors.Any(x => x.Targets.FirstOrDefault() == actorModel.Actor);
                actorModel.HasSelection = selectedActors.Any();
                actorModel.IsSelected = selectedActors.Contains(actorModel.Actor);
            }

            // TODO: Projectiles should not all look the same
            foreach (var projectile in battle.Projectiles.Where(x => !scene.Nodes.OfType<ProjectileModel>().Any(y => y.Projectile == x)))
            {
                var proj = projectile;

                var smokeTrail = new ParticleSystem(ScreenManager.GraphicsDevice, ContentManager.Load<Effect>(@"Shaders\Particle"))
                {
                    Position = projectile.Position,
                    Texture = ContentManager.Load<Texture2D>(@"Sprites\smoke_particle"),
                    SpawnRate = 0.005f,
                    Forces = { new Vector3(random.Between(-0.5f, 0.5f), random.Between(-2.5f, 0.5f), random.Between(-0.5f, 0.5f)) },
                    AlphaFunc = p => p.InverseAgeFraction * 0.5f,
                    ScaleFunc = p => 0.2f + p.Age,
                    RotationSpeed = 1f,
                    Emitter = () => new Particle
                    {
                        Position = new Vector3(projectile.Position.X, projectile.Position.Z, projectile.Position.Y),
                        LifeSpan = 0.8f,
                        Angle = random.Between(0, 6)
                    }
                };

                var fireBall = new ParticleSystem(ScreenManager.GraphicsDevice, ContentManager.Load<Effect>(@"Shaders\Particle"))
                {
                    Position = projectile.Position,
                    Texture = ContentManager.Load<Texture2D>(@"Sprites\fireball"),
                    BlendState = BlendState.Additive,
                    SpawnRate = 0.005f,
                    AlphaFunc = p => p.InverseAgeFraction * 0.8f,
                    ScaleFunc = p => p.InverseAgeFraction * 0.7f,
                    RotationSpeed = 1f,
                    Emitter = () => new Particle
                    {
                        Position = new Vector3(projectile.Position.X, projectile.Position.Z, projectile.Position.Y),
                        LifeSpan = 0.2f,
                        Angle = random.Between(0, 6)
                    }
                };

                scene.Nodes.Add(new ProjectileModel()
                {
                    Projectile = projectile,
                    Model = ContentManager.Load<Model>(@"Models\Objects\" + projectile.ModelName),
                    Texture = ContentManager.Load<Texture2D>(@"Models\Objects\" + projectile.TextureName),
                    Nodes = { smokeTrail, fireBall }
                });
            }

            if (!isPaused)
            {
                float deltaTime = isBenchmarking ? 0.5f : (float)gameTime.ElapsedGameTime.TotalSeconds;
                var turn = battle.Run(deltaTime);
                turns.Add(turn);

                while (battle.GraphicEffects.Any())
                {
                    var graphicsEffect = battle.GraphicEffects.Dequeue();

                    if (graphicsEffect is BillboardDefinition)
                    {
                        var billboardDefinition = graphicsEffect as BillboardDefinition;

                        scene.Nodes.Add(new Billboard(ScreenManager.GraphicsDevice, ContentManager.Load<Effect>(@"Shaders\Billboard"))
                        {
                            Position = billboardDefinition.Position,
                            Texture = ContentManager.SafeLoad<Texture2D>(@"Sprites\" + billboardDefinition.TextureName, BlankTexture),
                            LifeTime = billboardDefinition.LifeTime,
                            Angle = billboardDefinition.Angle,

                            AngleFunc = billboardDefinition.AngleFunc.ToFunc(),
                            AlphaFunc = billboardDefinition.AlphaFunc.ToFunc(),
                            ScaleFunc = billboardDefinition.ScaleFunc.ToFunc(),
                        });
                    }

                    if (graphicsEffect is ParticleSystemDefinition)
                    {
                        var particleSystemDefinition = graphicsEffect as ParticleSystemDefinition;

                        scene.Nodes.Add(new ParticleSystem(ScreenManager.GraphicsDevice, ContentManager.Load<Effect>(@"Shaders\Particle"))
                        {
                            Position = new Vector3(particleSystemDefinition.Position.X, 1f, particleSystemDefinition.Position.Y),
                            Texture = ContentManager.SafeLoad<Texture2D>(@"Sprites\" + particleSystemDefinition.TextureName, BlankTexture),
                            SpawnRate = 0.0001f,
                            BlendState = BlendState.Additive,
                            LifeSpan = particleSystemDefinition.LifeSpan,

                            AngleFunc = p => particleSystemDefinition.AngleFunc.ToFunc()(p.AgeFraction),
                            AlphaFunc = p => particleSystemDefinition.AlphaFunc.ToFunc()(p.AgeFraction),
                            ScaleFunc = p => particleSystemDefinition.ScaleFunc.ToFunc()(p.AgeFraction),

                            Emitter = () => new Particle()
                            {
                                Position = new Vector3(particleSystemDefinition.Position.X, 1f, particleSystemDefinition.Position.Y),
                                Velocity = random.NextUnitVector2().Project(1f) * random.Between(1f, 4f),
                                LifeSpan = 1f,
                            }
                        });
                    }
                }
            }

            scrollingTextSystem.Filter = selectedActors.FirstOrDefault();

            UpdateAbilityButtons();
            UpdateOrderQueueButtons();
            //UpdateStrategyButtons();

            if (battle.Actors.Count(a => a.IsAlive && a.Faction == Factions.Friend) == 0)
            {
                ScreenManager.AddScreen(new DefeatScreen(player, battle));
                ScreenManager.RemoveScreen(this);
            }

            if (battle.Actors.Count(a => a.IsAlive && a.Faction == Factions.Enemy) == 0)
            {
                ScreenManager.AddScreen(new VictoryScreen(player, encounterDefinition, battle, turns));
                ScreenManager.RemoveScreen(this);
            }

            scene.Update(gameTime, isPaused);
        }