Beispiel #1
0
        public override void Input()
        {
            ButtonInput state = Woofer.Controller.InputManager.ActiveInputMap.Pause;

            if (state.Consume())
            {
                Woofer.Controller.Paused = !Woofer.Controller.Paused;
            }
        }
Beispiel #2
0
        public override void Input()
        {
            ButtonInput changeButton = Woofer.Controller.InputManager.ActiveInputMap.Back;

            if (changeButton.Consume())
            {
                BeginModalChange();
            }
        }
Beispiel #3
0
        public override void Input()
        {
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            foreach (PulseAbility pa in WatchedComponents.Where(c => c is PulseAbility))
            {
                ButtonInput pulseButton = inputMap.Pulse;

                if (pa.Owner.GetComponent <Health>() is Health health && health.CurrentHealth <= 0)
                {
                    continue;
                }

                if (pa.EnergyMeter >= pa.PulseCost)
                {
                    if (pulseButton.Consume())
                    {
                        double strength = (pa.PulseStrength * Math.Sqrt(pa.EnergyMeter / pa.MaxEnergy));

                        if (pa.Owner.Components.Has <Physical>() && pa.Owner.Components.Has <PlayerOrientation>())
                        {
                            pa.Owner.Components.Get <Physical>().Velocity = pa.Owner.Components.Get <PlayerOrientation>().Unit * -strength;

                            ISoundEffect sound_low = Woofer.Controller.AudioUnit["pulse_low"];
                            sound_low.Pitch = (float)(strength / 256) - 1;
                            ISoundEffect sound_mid = Woofer.Controller.AudioUnit["pulse_mid"];
                            sound_mid.Pitch = sound_low.Pitch;
                            ISoundEffect sound_high = Woofer.Controller.AudioUnit["pulse_high"];
                            sound_high.Pitch = sound_low.Pitch;

                            sound_low.Volume = 0.6f;


                            sound_low.Play();
                            sound_mid.Play();
                            sound_high.Play();
                        }

                        pa.EnergyMeter -= pa.PulseCost;

                        if (pa.Owner.Components.Has <Spatial>())
                        {
                            Spatial sp = pa.Owner.Components.Get <Spatial>();
                            if (sp == null)
                            {
                                continue;
                            }
                            PlayerOrientation po = pa.Owner.Components.Get <PlayerOrientation>();

                            Owner.Events.InvokeEvent(new PulseEvent(pa, sp.Position + pa.Offset, po != null ? po.Unit : new Vector2D(), strength, pa.MaxRange));
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public override void Input()
        {
            IEnumerable <InteractingAgent> agents = WatchedComponents.Where(c => c is InteractingAgent && c.Owner.Active).Select(c => c as InteractingAgent);

            foreach (Component rawC in WatchedComponents)
            {
                if (!rawC.Owner.Active)
                {
                    continue;
                }
                if (rawC is Interactable interactable)
                {
                    InteractingAgent currentAgent = null;
                    bool             inRange      = false;
                    foreach (InteractingAgent agent in agents)
                    {
                        if ((agent.Owner.Components.Get <Spatial>().Position - interactable.Owner.Components.Get <Spatial>().Position).Magnitude <= agent.MaxDistance)
                        {
                            currentAgent = agent;
                            inRange      = true;
                            break;
                        }
                    }
                    if (inRange != interactable.InRange)
                    {
                        if (inRange)
                        {
                            CurrentInteractions[interactable] = currentAgent;
                        }
                        else
                        {
                            CurrentInteractions.Remove(interactable);
                        }
                        Owner.Events.InvokeEvent(inRange ?
                                                 (Event) new InteractionRangeEnter(currentAgent, interactable) :
                                                 (Event) new InteractionRangeExit(null));
                        interactable.InRange = inRange;
                    }

                    if (inRange)
                    {
                        ButtonInput interact = Woofer.Controller.InputManager.ActiveInputMap.Interact;

                        if (interact.Consume())
                        {
                            Entity sendTo = interactable.EntityToActivate != 0 ? Owner.Entities[interactable.EntityToActivate] : interactable.Owner;
                            Owner.Events.InvokeEvent(new ActivationEvent(currentAgent, sendTo, null));
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public override void Input()
        {
            ButtonInput saveButton = Woofer.Controller.InputManager.ActiveInputMap.Quicksave;
            ButtonInput loadButton = Woofer.Controller.InputManager.ActiveInputMap.Quickload;

            if (saveButton.Consume())
            {
                SaveOperation save = new SaveOperation(Owner, TargetFile);
                save.AddConverter(new CollisionBoxConverter());
                save.AddConverter(new ColorConverter());
                save.AddConverter(new ListConverter <CollisionBox>());
                save.AddConverter(new ListConverter <Sound>());
                save.AddConverter(new ListConverter <Sprite>());
                save.AddConverter(new ListConverter <AnimatedSprite>());
                save.AddConverter(new EnumConverter <DrawMode>());
                save.AddConverter(new BoolMapConverter());

                save.Save();
                Owner.Events.InvokeEvent(new ShowTextEvent("Saved", null));
            }

            if (loadButton.Consume())
            {
                LoadOperation load = new LoadOperation(Woofer.Controller, TargetFile);
                load.AddConverter(new CollisionBoxConverter());
                load.AddConverter(new ColorConverter());
                load.AddConverter(new ListConverter <CollisionBox>());
                load.AddConverter(new ListConverter <Sound>());
                load.AddConverter(new ListConverter <Sprite>());
                load.AddConverter(new ListConverter <AnimatedSprite>());
                load.AddConverter(new EnumConverter <DrawMode>());
                load.AddConverter(new BoolMapConverter());

                Woofer.Controller.CommandFired(new InternalSceneChangeCommand(load.Load()));
                Woofer.Controller.ActiveScene.Events.InvokeEvent(new ShowTextEvent("Loaded", null));
                Woofer.Controller.Paused = false;
            }
        }
Beispiel #6
0
        public override void Input()
        {
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            foreach (PlayerMovementComponent pmc in WatchedComponents)
            {
                if (!pmc.Owner.Active)
                {
                    continue;
                }
                if ((pmc.Owner.Components.Get <Health>()?.InvincibilityTimer ?? 0) > 40)
                {
                    continue;
                }
                if ((pmc.Owner.Components.Get <Health>()?.CurrentHealth ?? 1) <= 0)
                {
                    continue;
                }

                Physical phys = pmc.Owner.Components.Get <Physical>();
                if (phys == null)
                {
                    continue;
                }

                ButtonInput jumpButton = inputMap.Jump;

                //Jump logic
                if (pmc.OnGround)
                {
                    if (jumpButton.Consume())
                    {
                        phys.Velocity.Y = pmc.JumpSpeed;
                        Owner.Events.InvokeEvent(new PlayerJumpEvent(pmc));
                    }
                }

                //Walking logic
                double xMovement    = inputMap.Movement.X * pmc.CurrentSpeed;
                double xMovementCap = pmc.CurrentMaxSpeed;
                if (xMovement > 0)
                {
                    if (phys.Velocity.X <= xMovementCap)
                    {
                        phys.Velocity.X = Math.Min(phys.Velocity.X + xMovement, xMovementCap);
                    }
                }
                else if (xMovement < 0)
                {
                    if (phys.Velocity.X >= -xMovementCap)
                    {
                        phys.Velocity.X = Math.Max(phys.Velocity.X + xMovement, -xMovementCap);
                    }
                }

                //For smoothly walking down slopes
                if (phys.Velocity.Y <= 0)
                {
                    //Raycast down under the player's feet up to a distance of 4 pixels
                    RaycastEvent raycast = new RaycastEvent(pmc, new FreeVector2D(phys.Position, phys.Position - 8 * Vector2D.UnitJ));
                    Owner.Events.InvokeEvent(raycast);
                    if (raycast.Intersected != null)
                    {
                        foreach (RaycastIntersection intersection in raycast.Intersected)
                        {
                            if (intersection.Component.Owner != pmc.Owner)
                            {
                                if (intersection.FaceProperties.Snap)   //If the intersected face has the 'snap' property enabled (for slopes)
                                {
                                    phys.Position = intersection.Point; //Move the player down to the point of intersection, assuming the player's origin is at their feet
                                }
                            }
                        }
                    }
                }
            }
        }