Пример #1
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);
        }
Пример #2
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);
            }
        }
Пример #3
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;
        }
Пример #4
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);
                }
            }
        }