コード例 #1
0
ファイル: PlatformScene.cs プロジェクト: nethz/MrPP.com
        private void Awake()
        {
            bool isLoaded = false;

            Platform.Type type = Platform.Instance.type;
            for (int i = 0; i < SceneManager.sceneCount; ++i)
            {
                Scene scene = SceneManager.GetSceneAt(i);
                Debug.Log(scene.name);
                Debug.Log(scene.isLoaded);
                if (scene.name == type.ToString())
                {
                    isLoaded = true;
                }
            }
            if (!isLoaded)
            {
                SceneManager.LoadScene(type.ToString(), LoadSceneMode.Additive);
            }
        }
コード例 #2
0
        public static char TypeToChar(Platform.Type ePlatformType)
        {
            switch (ePlatformType)
            {
            case Platform.Type.UNKOWN:
                return('?');

            case Platform.Type.COMMON:
                return('C');

            case Platform.Type.WEB:
                return('W');

            case Platform.Type.AND:
                return('A');

            case Platform.Type.IOS:
                return('I');
            }
            return('?');
        }
コード例 #3
0
        private bool ApplyResponse(DataResponse response)
        {
            if (response.Version >= NetworkProtocol.NETWORK_PROTOCOL_MIN_VERSION)
            {
                //SaveTestResponse(response);

                switch (response.ResponseType)
                {
                case DataResponse.Type.ReportProgress:
                    Int32 length = response.Reader.ReadInt32();
                    StatusText.Text = new String(response.Reader.ReadChars(length));
                    break;

                case DataResponse.Type.NullFrame:
                    RaiseEvent(new CancelConnectionEventArgs());
                    StatusText.Visibility = System.Windows.Visibility.Collapsed;
                    lock (frames)
                    {
                        frames.Flush();
                        ScrollToEnd();
                    }
                    break;

                case DataResponse.Type.Handshake:
                    TracerStatus status = (TracerStatus)response.Reader.ReadUInt32();

                    KeyValuePair <string, string> warning;
                    if (statusToError.TryGetValue(status, out warning))
                    {
                        RaiseEvent(new ShowWarningEventArgs(warning.Key, warning.Value));
                    }

                    if (response.Version >= NetworkProtocol.NETWORK_PROTOCOL_VERSION_23)
                    {
                        Platform.Connection connection = new Platform.Connection()
                        {
                            Address = response.Source.Address.ToString(),
                            Port    = response.Source.Port
                        };
                        Platform.Type target     = Platform.Type.Unknown;
                        String        targetName = Utils.ReadBinaryString(response.Reader);
                        Enum.TryParse(targetName, true, out target);
                        connection.Target = target;
                        connection.Name   = Utils.ReadBinaryString(response.Reader);
                        RaiseEvent(new NewConnectionEventArgs(connection));
                    }

                    break;

                default:
                    lock (frames)
                    {
                        frames.Add(response);
                        //ScrollToEnd();
                    }
                    break;
                }
            }
            else
            {
                RaiseEvent(new ShowWarningEventArgs("Invalid NETWORK_PROTOCOL_VERSION", String.Empty));
                return(false);
            }
            return(true);
        }
コード例 #4
0
    public ProceduralRoom(ProceduralRoom previousRoom) : base(previousRoom)
    {
        _unityObject = new GameObject("ProceduralRoom" + _index);

        GameObject bottomSpriteObject = new GameObject("bottom sprite");

        bottomSpriteObject.transform.parent   = _unityObject.transform;
        bottomSpriteObject.transform.position = new Vector3(_centerX, -4.76f);
        bottomSpriteObject.AddComponent <SpriteRenderer>().sprite = RoomGenerator.StaticBottomOfRoomSprite;


        float       halfRoomWidth     = 50.28f / 2; //because we are using a background with 5028 pixels width
        const float platformWidth     = 6.285f;     //(notice platformWidth * 8 = roomWidth)  , also 1356 * scale= 628.5, scale= 0.4635
        float       halfPlatformWidth = platformWidth / 2;
        const float platformHeight    = 0.616455f;

        float roomX = _centerX;

        Platform previousPlatform = previousRoom == null ? null : previousRoom.LastPlatform;  //the previous platform is the last platform of the previous room


        Transform roomTransform = _unityObject.transform;

        for (int i = 0; i < 8; i++)
        {
            float                  platformX    = roomX - halfRoomWidth + halfPlatformWidth + platformWidth * i; //x is easy as we know the position of the room and the relative position of the platform inside the room
            float                  platformY    = -3.8f;                                                         //it is important that we initialize this to -3.8f. This is the desired y value for the very first platform of our game (for this platform previousplatform=null)
            Platform.Type          type         = Platform.Type.Ordinary;
            ItemThatSitsOnPlatform attachedItem = null;


            if (previousPlatform != null)
            {
                platformY = previousPlatform.Y;


                switch (previousPlatform.MyType)
                {
                case Platform.Type.Gap:
                    type = Platform.Type.Small;
                    //override platformx calculation
                    platformX = roomX - halfRoomWidth + platformWidth * i;
                    break;

                case Platform.Type.Small:
                    type = Platform.Type.Ordinary;
                    break;

                case Platform.Type.Ordinary:

                    //check for gap eligibility
                    if (
                        _index > 0 &&  //not first room, we don't want any gaps and moving platforms in the very first toom
                        i >= 1 && i <= 5 &&     //platforms 0, 6 and 7 cannot be gaps
                        previousPlatform.AttachedItem == null &&
                        Random.Range(0, 4) == 0 //let's say 25% probability of gap
                        )
                    {                           //eligible
                        type = Platform.Type.Gap;
                    }
                    else
                    {    //no gap
                        type = Platform.Type.Ordinary;

                        //override platformy calculation
                        //we want a y that is the y of the previous platform plus/minus a small random value
                        //the only exception is when the previous platform had a ponger on it. We want the new platform to be placed much higher than usual
                        if (previousPlatform.AttachedItem != null && previousPlatform.AttachedItem.RequiresSufficientSpaceAbove)
                        {
                            platformY = previousPlatform.Y + 4 * platformHeight;
                        }
                        else
                        {
                            int upSameOrDown = Random.Range(0, 3);

                            switch (upSameOrDown)
                            {
                            case 0:         //up
                                platformY = previousPlatform.Y + platformHeight;

                                if (platformY > 2f)        //out of bounds, go down instead
                                {
                                    platformY = previousPlatform.Y - platformHeight;
                                }
                                break;

                            case 1:         //same level
                                platformY = previousPlatform.Y;
                                break;

                            case 2:         //down
                                platformY = previousPlatform.Y - platformHeight;

                                if (platformY < -3.8f)        //out of bounds, go up instead
                                {
                                    platformY = previousPlatform.Y + platformHeight;
                                }
                                break;
                            }

                            //check for attached item eligibility
                            //check if we should attach an object to the top of the platform
                            if (
                                _index > 0                            //don't add any objects to the first room so the player adjusts to the gameplay mechanics
                                &&
                                previousPlatform.AttachedItem == null //don't add objects to two platforms in a row
                                &&
                                Random.Range(0, 4) == 0               //25% probability of object
                                )
                            {                                         //eligible
                                int typeIndex = Random.Range(0, RoomGenerator.StaticItemsThatSitOnPlatforms.Length);
                                ItemThatSitsOnPlatform item = RoomGenerator.StaticItemsThatSitOnPlatforms[typeIndex];

                                if (item.RequiresSufficientSpaceAbove)
                                {    //we want to add a ponger. But we should be careful: when we add a ponger the next platform is placed higher than usual.
                                     //this means that in order to add a ponger we should first make sure that there is indeed sufficient space above

                                    if (platformY > 1)
                                    {    //nope, we are way too high for a ponger, instantiate another type
                                        int anotherTypeIndex;
                                        do
                                        {
                                            anotherTypeIndex = Random.Range(0, RoomGenerator.StaticItemsThatSitOnPlatforms.Length);
                                        } while (anotherTypeIndex == typeIndex);

                                        typeIndex = anotherTypeIndex;
                                        item      = RoomGenerator.StaticItemsThatSitOnPlatforms[typeIndex];
                                    }
                                }

                                //now we know what item to add
                                attachedItem = item;
                                //instantiate it
                                GameObject go = Object.Instantiate(item.Prefab, roomTransform);

                                //let's determine its position
                                //to have the object perfectly sit on top of the platform we should move it up a bit.
                                //By how much? ...   By half its height + half the platform's height (constant 0.308227f)
                                //(Oh and it is important that we use the instantiated object for that, not the prefab. The prefab has no bounds)
                                //so:
                                float verticalOffset = go.GetComponent <Collider2D>().bounds.extents.y + 0.308227f;

                                float horizontalOffset = 0.0f;
                                if (item.AutoDetermineHorizontalOffset)
                                {    //e.g. spike
                                     //when we go to a spike platform that is higher than the previous one it is difficult to avoid the spike, so we move the spike to the right
                                     //when we go to a spike platform that is lower than the previous one it is difficult to avoid the spike, so we move the spike to the left
                                    if (platformY > previousPlatform.Y)
                                    {    //new platform is higher, so move the spike right
                                        horizontalOffset = 2.5f;
                                    }
                                    else if (platformY < previousPlatform.Y)
                                    {    //move spike left
                                        horizontalOffset = -2f;
                                    }
                                }

                                //starting with its platform's position
                                go.transform.position = new Vector3(platformX + horizontalOffset, platformY + verticalOffset);
                            }
                        }
                    }
                    break;
                }
            }



            //we instantiate the platform and also make it previousplatform for the next room
            previousPlatform = new Platform(platformX, platformY, type, attachedItem, roomTransform);
        }//for platform


        LastPlatform = previousPlatform;
    }