예제 #1
0
 public SpecialEffect(Model model, Vector2 position, Trigger spawnTrigger, Trigger moveTrigger, Func<float, Matrix> scale, Func<float, float> alpha)
 {
     this.model = model;
     this.position = position;
     this.spawnTrigger = spawnTrigger;
     this.moveTrigger = moveTrigger;
     this.scale = scale;
     this.alpha = alpha;
     r = new Random();
 }
예제 #2
0
        public void Update(float dt)
        {
            time += dt;
            if (time > 1f)
            {
                if (spawnTrigger != null)
                {
                    spawnTrigger.Fire();
                    spawnTrigger = null;
                }
            }

            if (time > 2.5f)
            {
                if (moveTrigger != null)
                {
                    moveTrigger.Fire();
                    moveTrigger = null;
                }
            }
        }
예제 #3
0
파일: Level.cs 프로젝트: myko/tempusfugit
        // TODO: Don't take a reference to the list of special effects
        // TODO: Load all the scripts from a file? Or at least make a "Level 1" subclass
        public Level(IList<SpecialEffect> specialEffects, IDictionary<string, Model> models)
        {
            Model timeTravelSphere = models["timetravelsphere"];
            Model playerModel = models["dude"];
            Model groundModel = models["ground"];
            Model doorModel = models["door"];
            Model travelPadModel = models["travelpad"];
            Model buttonModel = models["button"];

            Time = new Time();

            lines = new List<Line2>();
            lines.Add(new Line2(new Vector2(-10, 0), new Vector2(25, 0)));
            lines.Add(new Line2(new Vector2(30, 0), new Vector2(50, 0)));
            lines.Add(new Line2(new Vector2(-10, 4), new Vector2(-10, 0)));
            lines.Add(new Line2(new Vector2(50, 4), new Vector2(-10, 4)));
            lines.Add(new Line2(new Vector2(50, 0), new Vector2(50, 4)));
            lines.Add(new Line2(new Vector2(25, 0), new Vector2(25, -10)));
            lines.Add(new Line2(new Vector2(30, -10), new Vector2(30, 0)));

            PresentPlayer = new PresentPlayer(playerModel);
            PresentPlayer.Position = new Vector2(-5, 2); // -5

            futurePlayer = new FuturePlayer(playerModel);
            futurePlayer.Position = new Vector2(4, 0);
            futurePlayer.Exists = false;

            pastPlayer = new PastPlayer(playerModel);
            pastPlayer.Exists = false;

            var ground = new StaticEntity(groundModel, Matrix.Identity);
            var travelPad = new StaticEntity(travelPadModel, Matrix.CreateTranslation(4, 0, 0));
            var travelPad2 = new StaticEntity(travelPadModel, Matrix.CreateTranslation(32, 0, 0));
            var button = new StaticEntity(buttonModel, Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(10, 1, -1.7f));
            var button2 = new StaticEntity(buttonModel, Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(35, 1, -1.7f));

            var door1 = new Door(doorModel);
            door1.Position = new Vector2(0, 2);
            door1.IsOpen = false;

            var door2 = new Door(doorModel);
            door2.Position = new Vector2(8, 2);
            door2.IsOpen = true;

            var door3 = new Door(doorModel);
            door3.Position = new Vector2(27.5f, 0);
            door3.IsOpen = true;
            door3.Width = 4;
            door3.Height = 1;

            entities.Add(ground);
            entities.Add(travelPad);
            entities.Add(travelPad2);
            entities.Add(button);
            entities.Add(button2);
            entities.Add(door1);
            entities.Add(door2);
            entities.Add(door3);

            Vector2 doorsButtonPosition = new Vector2() { X = 10 };
            Vector2 door3ButtonPosition = new Vector2() { X = 34 };
            Vector2 timeMachinePosition = new Vector2() { X = 4f };
            Vector2 timeMachine2Position = new Vector2() { X = 32 };

            // toggle doors trigger
            positionalTriggers.Add(new PositionalTrigger()
            {
                Position = doorsButtonPosition,
                Actions = {
                    () =>
                    {
                        door1.Toggle();
                        door2.Toggle();
                    }}
            });

            // toggle door 3 trigger
            positionalTriggers.Add(new PositionalTrigger()
            {
                Position = door3ButtonPosition,
                Actions = {
                    () =>
                    {
                        door3.Toggle();
                    }}
            });

            var moveFuturePlayerTrigger = new Trigger() { OneTime = true };
            moveFuturePlayerTrigger.Actions.Add(() =>
            {
                futurePlayerMoving = true;
            });

            var removePastPlayerTrigger = new Trigger() { OneTime = true };
            removePastPlayerTrigger.Actions.Add(() =>
            {
                pastPlayer.Exists = false;
            });

            var spawnFuturePlayerTrigger = new Trigger() { OneTime = false };
            spawnFuturePlayerTrigger.Actions.Add(() =>
            {
                futurePlayer.Exists = true;
                TargetGtc = Time.GlobalTimeCoordinate;
            });

            //var timeTravelDepartureEffectTrigger = new Trigger() { OneTime = true };
            //timeTravelDepartureEffectTrigger.Actions.Add(() =>
            //{
            //    specialEffects.Add(new SpecialEffect(timeTravelSphere, new Vector2() { X = pastPlayer.Position.X }, removePastPlayerTrigger, null,
            //        t => Matrix.CreateScale(Math.Min(2.5f - t, 1f) * 1.65f),
            //        t => Math.Min(1f, t)));
            //});

            var unlockPlayerTrigger = new Trigger() { OneTime = false };
            unlockPlayerTrigger.Actions.Add(() =>
            {
                lockPlayer = false;
            });

            // timeTravelArrivalEffectTrigger
            positionalTriggers.Add(new PositionalTrigger()
            {
                Position = new Vector2() { X = -2.5f },
                OneTime = true,
                Actions = {
                    () =>
                    {
                        futurePlayer.Exists = true;
                        futurePlayer.Position = new Vector2(timeMachinePosition.X, 0);
                        specialEffects.Add(new SpecialEffect(timeTravelSphere, timeMachinePosition, spawnFuturePlayerTrigger, moveFuturePlayerTrigger,
                            t => Matrix.CreateScale(Math.Min(t, 1f) * 1.65f),
                            t => Math.Min(1f, 2.5f - t)));
                    }}
            });

            // timeTravelArrivalEffect2Trigger
            positionalTriggers.Add(new PositionalTrigger()
            {
                Position = new Vector2() { X = 23.5f },
                OneTime = true,
                Actions = {
                    () =>
                    {
                        futurePlayer.Exists = true;
                        futurePlayer.Position = new Vector2(timeMachine2Position.X, 0);
                        specialEffects.Add(new SpecialEffect(timeTravelSphere, timeMachine2Position, spawnFuturePlayerTrigger, moveFuturePlayerTrigger,
                            t => Matrix.CreateScale(Math.Min(t, 1f) * 1.65f),
                            t => Math.Min(1f, 2.5f - t)));
                    }}
            });

            // timeTravelTrigger
            positionalTriggers.Add(new PositionalTrigger()
            {
                Position = timeMachinePosition,
                OneTime = true,
                Actions = {
                    () =>
                    {
                        Time.JumpTo(TargetGtc);
                        pastPlayer.Spawn();
                        door1.IsOpen = false;
                        door2.IsOpen = true;
                        door3.IsOpen = true;
                        futurePlayer.Exists = false;
                        lockPlayer = true;
                        PresentPlayer.Velocity = new Vector2(0, 0);
                        specialEffects.Add(new SpecialEffect(timeTravelSphere, timeMachinePosition, null, unlockPlayerTrigger,
                            t => Matrix.CreateScale(1.65f),
                            t => (float)Math.Sin(t / 2.5 * Math.PI)));
                    }}
            });

            // timeTravel2Trigger
            positionalTriggers.Add(new PositionalTrigger()
            {
                Position = timeMachine2Position,
                OneTime = true,
                Actions = {
                    () =>
                    {
                        Time.JumpTo(TargetGtc);
                        pastPlayer.Spawn();
                        door1.IsOpen = false;
                        door2.IsOpen = true;
                        door3.IsOpen = true;
                        futurePlayer.Exists = false;
                        lockPlayer = true;
                        PresentPlayer.Velocity = new Vector2(0, 0);
                        specialEffects.Add(new SpecialEffect(timeTravelSphere, timeMachine2Position, null, unlockPlayerTrigger,
                            t => Matrix.CreateScale(1.65f),
                            t => (float)Math.Sin(t / 2.5 * Math.PI)));
                    }}
            });

            decisionPoints.Add(new DecisionPoint() { Position = new Vector2(-2, 0), Condition = () => door1.IsOpen });
            //decisionPoints.Add(new DecisionPoint() { Position = new Vector2(timeMachinePosition.X, 0), Condition = () => true });
            decisionPoints.Add(new DecisionPoint() { Position = new Vector2(24, 0), Condition = () => !door3.IsOpen });
            //decisionPoints.Add(new DecisionPoint() { Position = new Vector2(door3.Position.X, 0), Condition = () => true });
            //decisionPoints.Add(new DecisionPoint() { Position = new Vector2(timeMachine2Position.X, 0), Condition = () => true });
        }