Exemplo n.º 1
0
        public void EnterPressed()
        {
            String selected = menuView.GetCurrentName();

            menuView.ResetCurrent();
            if (selected.Equals("start"))
            {
                if (GameEngine.Instance.achievement_state.get_starting_level() >= 0)
                {
                    GameEngine.Instance.State = GameEngine.GameState.PLAYING;
                    GameEngine.Instance.StartNewLevel(GameEngine.Instance.achievement_state.get_starting_level());
                }
                else
                {
                    GameEngine.Instance.refreshMenus();
                    GameEngine.Instance.State = GameEngine.Instance.achievement_state.get_menu_world_state();
                }
            }
            else if (selected.Equals("levelselect"))
            {
                GameEngine.Instance.State = GameEngine.GameState.LEVEL_MENU;
            }
            else if (selected.Equals("Controls"))
            {
                GameEngine.Instance.State = GameEngine.GameState.CONTROL_MENU;
            }
            else if (selected.Equals("Achievements"))
            {
                GameEngine.Instance.State = GameEngine.GameState.ACHIEVEMENT_MENU;
            }
            else if (selected.Equals("Credits"))
            {
                GameEngine.Instance.StartNewLevel(GameEngine.CREDITS_LEVEL_ID);
                GameEngine.Instance.State = GameEngine.GameState.PLAYING;
            }
            else if (selected.Equals("exit"))
            {
                AchievementState.toSaveFile(GameEngine.Instance.achievement_state.toSaveState());
                GameEngine.Instance.Exit();
            }
        }
Exemplo n.º 2
0
        public static bool BeginContact(Contact contact)
        {
            if (GameEngine.Instance.currentLevel.is_peeking)
            {
                return(false);
            }

            var obj1  = contact.FixtureA.Body.UserData;
            var obj2  = contact.FixtureB.Body.UserData;
            var body1 = contact.FixtureA.Body;
            var body2 = contact.FixtureB.Body;
            var ud1   = contact.FixtureA.UserData;
            var ud2   = contact.FixtureB.UserData;

            if ((obj1 is Player && !(obj2 is Player)) ||
                (obj2 is Player && !(obj1 is Player)))
            {
                Player p     = obj1 is Player ? (Player)obj1 : (Player)obj2;
                var    other = obj1 is Player ? obj2 : obj1;
                if (!objects_in_contact.Contains(other))
                {
                    objects_in_contact.Add(other);
                }

                if (other is Reflexio.Wall)
                {
                    ReflectableObject obj = (ReflectableObject)other;
                    if (CheckPlayerInsideObject(obj))
                    {
                        GameEngine.Instance.currentLevel.SetGameOver(false);
                        GameEngine.Instance.achievement_state.death_by_wall(); //Achievement Logic - 'failure is an option'
                    }
                    PlayerGroundedStart(contact);
                    return(true);
                }
                // Collision with Block
                else if (other is Reflexio.Block)
                {
                    ReflectableObject obj = (ReflectableObject)other;
                    if (CheckPlayerInsideObject(obj))
                    {
                        GameEngine.Instance.currentLevel.SetGameOver(false);
                        GameEngine.Instance.achievement_state.death_by_block(); //Achievement logic - 'failure is an option'
                    }
                    PlayerGroundedStart(contact);
                    return(true);
                }
                // Collision With collectible
                else if (other is Reflexio.Collectible)
                {
                    if (!((Collectible)other).is_inside_non_reflectable_object)
                    {
                        ((Collectible)other).CollectedByPlayer();
                    }
                }
                // Collision with Spike
                else if (other is Reflexio.Spike)
                {
                    Spike s = (Reflexio.Spike)other;
                    if (spikes_in_contact.Contains(s))
                    {
                        return(false);
                    }
                    if (CheckPlayerInsideObject((ReflectableObject)s))
                    {
                        GameEngine.Instance.currentLevel.SetGameOver(false);
                        GameEngine.Instance.achievement_state.death_by_spike_collision(); //Achievement logic - 'failure is an option'
                    }
                    bool consider = PlayerSpikeContactStarted(s);
                    if (!consider)
                    {
                        return(false);
                    }
                    PlayerGroundedStart(contact);
                    return(true);
                }
                // Collision with Door
                else if (other is Reflexio.Door)
                {
                    Door d = (Reflexio.Door)other;
                    if (d.IsOpen() && !d.is_inside_non_reflectable_object && CheckPlayerInsideObject(d))
                    {
                        GameEngine.Instance.currentLevel.SetGameOver(true);
                        //Achievement logic - speed achievements and completion achievements
                        GameEngine.Instance.achievement_state.register_level_complete_time(GameEngine.Instance.currentLevelPos, GameEngine.Instance.currentLevelStopwatch.ElapsedMilliseconds);
                        GameEngine.Instance.achievement_state.complete_level(GameEngine.Instance.currentLevelPos,
                                                                             GameEngine.Instance.currentLevel.buddydeath);
                        AchievementState.toSaveFile(GameEngine.Instance.achievement_state.toSaveState());
                    }
                    //else
                    //    PlayerGroundedStart(contact);
                    return(false);
                }
            }

            if (obj1 is Switch && !(obj2 is Player) || obj2 is Switch && !(obj1 is Player))
            {
                Switch s = obj1 is Switch ? (Switch)obj1 : (Switch)obj2;
                s.PressSwitch((PhysicsObject)(obj1 is Switch ? obj2 : obj1));
                return(false);
            }

            if (obj1 is Block || obj2 is Block)
            {
                object other = obj1 is Block ? obj2 : obj1;
                return(!(other is Key || other is Switch));
            }
            return(false);
        }