Ejemplo n.º 1
0
        private void setOptions()
        {
            OptionsComponent options = new OptionsComponent("Fonts/MaturaOptions");

            options.addOption(new OptionType("Back", new Vector2(136, 420), Color.Red, OptionAction.previous, true, true, "Menus/Highlighter", new Vector2(137, 420)));
            options.setAlignment(TextAlignment.center);
            options.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false));
            addComponent(options);

            SwitchComponent selections = new SwitchComponent("Fonts/MaturaOptions");

            selections.addSelection(new SelectionType("On", new Vector2(100, 120), Color.Red, TextAlignment.center, "Menus/Small Highlighter", "Menus/Selector"));
            selections.addSelection(new SelectionType("Off", new Vector2(180, 120), Color.Red, TextAlignment.center, "Menus/Small Highlighter", "Menus/Selector"));

            selections.setEvent(SoundOn, 0);
            selections.setEvent(SoundOff, 1);

            selections.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(null, new Vector2(200, 0), 15, false));

            addComponent(selections);

            TextComponent text = new TextComponent("Fonts/MaturaOptions", "Volume:", new Vector2(50, 165), Color.Red);

            text.setTransitions(new MoveComponent(null, new Vector2(-200, 0), true, 15), new MoveComponent(null, new Vector2(200, 0), false, 15));
            addComponent(text);

            NumberSlideComponent slide = new NumberSlideComponent("Menus/Meter", "Menus/Knob", new Vector2(50, 190), new Rectangle(59, 190, 142, 25));

            slide.ChangeValue += ChangeVolume;
            slide.SetValue    += SetVolume;

            slide.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false));

            addComponent(slide);
        }
Ejemplo n.º 2
0
 public void setSwitchCheckpoints()
 {
     foreach (Entity e in GlobalVars.nonGroundEntities.Values)
     {
         if (e is SwitchEntity)
         {
             SwitchEntity    mySwitch   = ( SwitchEntity )e;
             SwitchComponent switchComp = (SwitchComponent)e.getComponent(GlobalVars.SWITCH_COMPONENT_NAME);
             mySwitch.lastCheckpointState = switchComp.active;
         }
     }
 }
Ejemplo n.º 3
0
        public override void revertToStartingState()
        {
            SwitchComponent sc = ( SwitchComponent )getComponent(GlobalVars.SWITCH_COMPONENT_NAME);

            PositionComponent posComp = ( PositionComponent )getComponent(GlobalVars.POSITION_COMPONENT_NAME);
            float             hDiff   = posComp.height;

            level.getMovementSystem().changeHeight(posComp, defaultHeight);
            hDiff = posComp.height - hDiff;
            level.getMovementSystem().teleportToNoCollisionCheck(posComp, posComp.x, posComp.y - hDiff / 2);

            sc.setActive(false, this);
        }
Ejemplo n.º 4
0
        public override void revertToStartingState()
        {
            SwitchComponent sc = ( SwitchComponent )getComponent(GlobalVars.SWITCH_COMPONENT_NAME);

            sc.setActive(startingState, this);

            DrawComponent drawComp = ( DrawComponent )getComponent(GlobalVars.DRAW_COMPONENT_NAME);

            if (startingState)
            {
                drawComp.setSprite(GlobalVars.SWITCH_ACTIVE_SPRITE_NAME);
            }
            else
            {
                drawComp.setSprite(GlobalVars.SWITCH_INACTIVE_SPRITE_NAME);
            }
        }
Ejemplo n.º 5
0
        protected override void Initialize()
        {
            base.Initialize();
            ConfigurationOptionsChanged(Configuration.Options);

            Mouse.SetCursor(MouseCursor.FromTexture2D(Content.Load <Texture2D>("images/cursor"), 0, 0));
            IsMouseVisible = true;

            Storage.Initialize(Content, GraphicsDevice);

            InputListeners.Input = new InputListeners(this);
            Components.Add(InputListeners.Input);

            UiSystem                = new UiSystem(this, style);
            UiSystem.OnRootAdded   += root => root.OnElementRemoved += element => element.Dispose();
            UiSystem.OnRootAdded   += root => Log.Debug("Root '{Name}' added in UiSystem (class {FullName})", root.Name, root.Element.GetType().FullName);
            UiSystem.OnRootRemoved += root => Log.Debug("Root '{Name}' removed in UiSystem (class {FullName})", root.Name, root.Element.GetType().FullName);

            ElementSlot = new SwitchComponent(UiSystem);
            Components.Add(ElementSlot);
            ScreenManager.LoadScreen(new MainMenuScreen(this), new FadeTransition(GraphicsDevice, Color.Black, 0.5f));
        }
Ejemplo n.º 6
0
        public void gotoCheckpoint()
        {
            if (!hasHadCheckpoint)
            {
                resetLevel();
            }

            paused = true;

            if (levelNum == 1)
            {
                if (!checkpointData.colorOrbObtained())
                {
                    setToPreColors();
                }
                else
                {
                    setToPostColors();
                }
            }

            //Deactivate the vision orb if it's active
            if (sysManager.visSystem.orbActive)
            {
                sysManager.visSystem.destroyVisionOrb();
            }

            //Remove border
            if (sysManager.drawSystem.getMainView().hasBorder)
            {
                sysManager.drawSystem.getMainView().hasBorder = false;
            }

            Dictionary <int, Entity> toRestore = GlobalVars.removedStartingEntities.Where(x => !checkpointData.getRemovedEnts().ContainsKey(x.Key)).ToDictionary(x => x.Key, x => x.Value);

            //Remove non-starting entities, and restore starting entities to their initial state
            //Set switches to their last checkpnt state
            Entity[] ents = GlobalVars.nonGroundEntities.Values.ToArray();
            for (int i = 0; i < ents.Length; i++)
            {
                if (ents[i] is SwitchEntity)
                {
                    SwitchEntity    switchEnt  = (SwitchEntity)ents[i];
                    SwitchComponent switchComp = ( SwitchComponent )switchEnt.getComponent(GlobalVars.SWITCH_COMPONENT_NAME);
                    switchComp.setActive(switchEnt.lastCheckpointState, switchEnt);
                }

                if (!ents[i].isStartingEntity)
                {
                    removeEntity(ents[i]);
                }
                else if (ents[i].resetOnCheckpoint)
                {
                    ents[i].revertToStartingState();
                }
            }

            //Do the same for ground
            Entity[] grndents = GlobalVars.groundEntities.Values.ToArray();
            for (int i = 0; i < grndents.Length; i++)
            {
                if (!grndents[i].isStartingEntity)
                {
                    removeEntity(grndents[i]);
                }
                else if (grndents[i].resetOnCheckpoint)
                {
                    grndents[i].revertToStartingState();
                }
            }

            foreach (Entity e in toRestore.Values)
            {
                e.revertToStartingState();
                addEntity(e.randId, e);
                GlobalVars.removedStartingEntities.Remove(e.randId);
            }

            Player player = getPlayer();

            if (player == null)
            {
                Console.WriteLine("Error, trying to go to checkpoint with no player");
                resetLevel();
            }
            PositionComponent playerPos = (PositionComponent)player.getComponent(GlobalVars.POSITION_COMPONENT_NAME);

            getMovementSystem().changePosition(playerPos, checkpointData.getPlayerLoc().X, checkpointData.getPlayerLoc().Y, false, false);

            paused = false;
        }
Ejemplo n.º 7
0
        //You must have an Update.
        public override void Update(float deltaTime)
        {
            foreach (Entity e in getApplicableEntities())
            {
                SwitchComponent switchComp = ( SwitchComponent )e.getComponent(GlobalVars.SWITCH_COMPONENT_NAME);
                if (e.hasComponent(GlobalVars.TIMED_SWITCH_COMPONENT_NAME))
                {
                    TimedSwitchComponent timedComp = ( TimedSwitchComponent )e.getComponent(GlobalVars.TIMED_SWITCH_COMPONENT_NAME);
                    //If it's not a pressure switch, and it's active. Count down
                    if ((timedComp.baseTime > 0) && switchComp.active)
                    {
                        timedComp.timer += deltaTime;
                        if (timedComp.timer > timedComp.baseTime)
                        {
                            switchComp.setActive(false, e);
                            timedComp.timer = 0;
                        }
                    }

                    //If it's a pressure switch
                    if (timedComp.baseTime <= 0)
                    {
                        PositionComponent posComp         = ( PositionComponent )e.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
                        List <Entity>     aboveCollisions = level.getCollisionSystem().findObjectsBetweenPoints(posComp.x - posComp.width / 2, posComp.y - posComp.height / 2 - 5, posComp.x + posComp.width / 2, posComp.y - posComp.height / 2 - 5);
                        //If there's something above the switch, and it's inactive - make it active!
                        if (aboveCollisions.Count > 0)
                        {
                            if (!switchComp.active)
                            {
                                float hDiff = (pressureSwitchActiveHeight - pressureSwitchInactiveHeight) / 2;
                                level.getMovementSystem().changeHeight(posComp, pressureSwitchActiveHeight);
                                level.getMovementSystem().teleportToNoCollisionCheck(posComp, posComp.x, posComp.y - hDiff);
                                switchComp.setActive(true, e);

                                //Move down all objects above the switch
                                foreach (Entity above in aboveCollisions)
                                {
                                    if (above.hasComponent(GlobalVars.POSITION_COMPONENT_NAME))
                                    {
                                        PositionComponent pos         = ( PositionComponent )above.getComponent(GlobalVars.POSITION_COMPONENT_NAME);
                                        float             theirHeight = pos.height;
                                        if (above.hasComponent(GlobalVars.COLLIDER_COMPONENT_NAME))
                                        {
                                            ColliderComponent theirCol = ( ColliderComponent )above.getComponent(GlobalVars.COLLIDER_COMPONENT_NAME);
                                            theirHeight = theirCol.height;
                                        }
                                        ColliderComponent myCol = ( ColliderComponent )e.getComponent(GlobalVars.COLLIDER_COMPONENT_NAME);
                                        level.getMovementSystem().changePosition(pos, pos.x, posComp.y - myCol.height / 2 - theirHeight / 2, true, true);
                                    }
                                }
                            }
                        }
                        else if (switchComp.active)
                        {
                            float hDiff = (pressureSwitchActiveHeight - pressureSwitchInactiveHeight) / 2;
                            level.getMovementSystem().changeHeight(posComp, pressureSwitchInactiveHeight);
                            level.getMovementSystem().teleportToNoCollisionCheck(posComp, posComp.x, posComp.y + hDiff);
                            switchComp.setActive(false, e);
                        }
                    }
                }


                //change sprite if needed
                DrawComponent drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME);
                if (switchComp.active && drawComp.activeSprite != GlobalVars.SWITCH_ACTIVE_SPRITE_NAME)
                {
                    drawComp.setSprite(GlobalVars.SWITCH_ACTIVE_SPRITE_NAME);
                }
                if (!switchComp.active && drawComp.activeSprite != GlobalVars.SWITCH_INACTIVE_SPRITE_NAME)
                {
                    drawComp.setSprite(GlobalVars.SWITCH_INACTIVE_SPRITE_NAME);
                }
            }
        }