Ejemplo n.º 1
0
    private void GenerateLayer(LevelLayer levelLayer)
    {
        Color pixelColor;

        for (int i = 0; i < levelLayer.map.width; i++)
        {
            for (int j = 0; j < levelLayer.map.height; j++)
            {
                pixelColor = levelLayer.map.GetPixel(i, j);
                // If pixel is not opaque, skip, it's empty.
                if (pixelColor.a < 1)
                {
                    continue;
                }

                if (!colorToObjectMap.ContainsKey(pixelColor))
                {
                    Debug.LogWarning("Color " + pixelColor + " found in terrain map but it has no prefab mapped to it. Ignoring.");
                    continue;
                }

                Instantiate(colorToObjectMap[pixelColor], new Vector3(i * blockSize, levelLayer.yHeight, j * blockSize), Quaternion.identity, transform);
            }
        }
    }
Ejemplo n.º 2
0
        void StartLevel()
        {
            var levelScene        = LevelLayer.CreateScene(Window, levels, activePlayer);
            var transitionToLevel = new CCTransitionFade(3.0f, levelScene);

            Director.ReplaceScene(transitionToLevel);
        }
Ejemplo n.º 3
0
    public Level() : base()
    {
        //initialise variables
        _scrollSpeed = MyGame.GetScrollSpeed();
        _tileSize    = MyGame.GetTileSize();

        //Timer initialization
        _lastUpdatedVictimTime = 0;
        _lastUpdatedEnemyTime  = 0;

        //Depth
        _floorLayer  = new LevelLayer();
        _victimLayer = new LevelLayer();
        _poopLayer   = new LevelLayer();
        _flightLayer = new LevelLayer();
        _hudLayer    = new LevelLayer();
        AddChild(_floorLayer);
        AddChild(_victimLayer);
        AddChild(_poopLayer);
        AddChild(_flightLayer);
        AddChild(_hudLayer);

        CreatePlayer();
        CreateRoad();
        //CreateEnemy();
        CreateHUD();
    }
Ejemplo n.º 4
0
        //---------------------------------------------------------------------------------------------------------
        // ContinueGame - Used in menu selection
        //---------------------------------------------------------------------------------------------------------
        // Transitions to GameLayer
        //---------------------------------------------------------------------------------------------------------
        void ContinueGame(object stuff = null)
        {
            var mainGame         = LevelLayer.CreateScene(Window, levels, currentPlayer);
            var transitionToGame = new CCTransitionFade(2.0f, mainGame);

            Director.ReplaceScene(transitionToGame);
        }
Ejemplo n.º 5
0
        void RetryLevel(object stuff = null)
        {
            var level            = LevelLayer.CreateScene(Window, levels, activePlayer);
            var transitionToGame = new CCTransitionFade(2.0f, level);

            Director.ReplaceScene(transitionToGame);
        }
Ejemplo n.º 6
0
    private IEnumerator GetLevel()
    {
        UnityWebRequest request = UnityWebRequest.Get("http://localhost:8080/level");

        yield return(request.SendWebRequest());

        if (request.isNetworkError || request.isHttpError)
        {
            Debug.Log("GetLevel failure: " + request.error);
        }
        // Show results as text
        string json = request.downloadHandler.text;

        Debug.Log(json);

        Level level = JsonConvert.DeserializeObject <Level>(json);

        Tilemap baseTileMap = grids[0];
        int     xDist       = level.base_x / 2;
        int     yDist       = level.base_y / 2;

        for (int x = -xDist; x < xDist; x++)
        {
            for (int y = -yDist; y < yDist; y++)
            {
                baseTileMap.SetTile(new Vector3Int(x, y, 1), baseTile);
            }
        }

        for (int i = 0; i < level.layers.Length; i++)
        {
            LevelLayer levelLayer = level.layers[i];

            grids[i + 1].tag = levelLayer.walkable.GetValueOrDefault(true)
                ? "Walkable" : "Obstacle";

            foreach (TextureToCell textureToCell in levelLayer.cells)
            {
                TileBase tile = baseTile;
                switch (textureToCell.texture)
                {
                case "flower":
                    tile = flower;
                    break;
                }
                foreach (CellInfo cellInfo in textureToCell.cells)
                {
                    grids[i + 1].SetTile(cellInfo.GetVector3Int(), tile);
                    bool hasTile = grids[i + 1].HasTile(cellInfo.GetVector3Int());
                    //Debug.Log(String.Format("HasTile: Loc={0}, val={1}", cellInfo.GetVector3Int(), hasTile));
                }
            }
            grids[i + 1].RefreshAllTiles();
        }
    }
Ejemplo n.º 7
0
    public Level() : base()
    {
        levelMusic = new Music();
        levelMusic.musicSoundChannel        = levelMusic.gameTrack.Play();
        levelMusic.musicSoundChannel.Volume = Music.musicVolume;

        difficulty = new Difficulty(); //Don't ask please.

        //initialise variables
        _scrollSpeed = Difficulty.GetScrollSpeed();
        _tileSize    = Difficulty.GetTileSize();
        _tileCount   = 0;

        //Timer initialization
        _lastUpdatedVictimTime = 0;
        _lastUpdatedEnemyTime  = 0;
        _lastUpdatedCarsTime   = 0;
        _lastUpdatedBikesTime  = 0;

        //Depth
        _floorLayer      = new LevelLayer();
        _groundPoopLayer = new LevelLayer();
        _victimLayer     = new LevelLayer();
        _poopLayer       = new LevelLayer();
        _powerUpLayer    = new LevelLayer();
        _flightLayer     = new LevelLayer();
        _hudLayer        = new LevelLayer();
        AddChild(_floorLayer);
        AddChild(_groundPoopLayer);
        AddChild(_victimLayer);
        AddChild(_poopLayer);
        AddChild(_powerUpLayer);
        AddChild(_flightLayer);
        AddChild(_hudLayer);

        deathManager = new DeathManager(this);
        AddChild(deathManager);

        CreatePlayer();
        CreateRoad();
        CreateHUD();
    }
Ejemplo n.º 8
0
    public Level() : base()
    {
        difficulty = new Difficulty(); //Don't ask please.

        //initialise variables
        _scrollSpeed = Difficulty.GetScrollSpeed();
        _tileSize    = Difficulty.GetTileSize();

        //Timer initialization
        _lastUpdatedVictimTime = 0;
        _lastUpdatedEnemyTime  = 0;

        //Depth
        _floorLayer  = new LevelLayer();
        _victimLayer = new LevelLayer();
        _poopLayer   = new LevelLayer();
        _flightLayer = new LevelLayer();
        _hudLayer    = new LevelLayer();
        AddChild(_floorLayer);
        AddChild(_victimLayer);
        AddChild(_poopLayer);
        AddChild(_flightLayer);
        AddChild(_hudLayer);

        CreatePlayer();
        CreateRoad();
        //CreateEnemy();
        CreateHUD();

        Constipation newdebuff = new Constipation(this);

        _poopLayer.AddChild(newdebuff);
        newdebuff.SetXY(Utils.Random(0, game.width), Utils.Random(0, game.height) - game.height);

        BeakOfSteel newbuff = new BeakOfSteel(this);

        _poopLayer.AddChild(newbuff);
        newbuff.SetXY(Utils.Random(0, game.width), Utils.Random(0, game.height) - game.height);
    }
Ejemplo n.º 9
0
        internal static bool Prefix(LevelEditor __instance, ref bool __result, ref GameObject newObj)
        {
            if (newObj is null)
            {
                Debug.LogWarning("Trying to select a null object");
                __result = false;
                return(false);
            }

            if (!newObj.transform.IsRoot() && false)
            {
                Debug.LogWarning("Trying to select a child object");
                __result = false;

                return(false);
            }

            if (!__instance.selectedObjects_.Contains(newObj))
            {
                LevelLayer layerOfObject = __instance.workingLevel_.GetLayerOfObject(newObj);

                if (layerOfObject?.Frozen_ == false)
                {
                    __instance.AddObjectToSelectedList(newObj);
                    __result = true;

                    return(false);
                }
            }
            else
            {
                __instance.SetActiveObject(newObj);
            }

            __result = false;

            return(false);
        }
Ejemplo n.º 10
0
    // Use this for initialization
    public void SetupLevel(string _levelType, string _medialLayerType, string _distalLayerType)
    {
        levelType       = _levelType;
        medialLayerType = _medialLayerType;
        distalLayerType = _distalLayerType;

        layers = new List <GameObject>();

        // Create a huge ground collider for the player to move on.
        GameObject groundCollider = new GameObject("Ground Collider");

        groundCollider.transform.position = new Vector2(0.0f, 1.0f);
        groundCollider.layer = LayerMask.NameToLayer("Ground");

        BoxCollider2D groundBox = groundCollider.AddComponent <BoxCollider2D>();

        groundBox.transform.parent = groundCollider.transform;
        groundBox.size             = new Vector2(100000f, 1.0f);
        groundBox.offset           = new Vector2(0, -0.8f);

        // Ground Layer
        GameObject go = new GameObject("Ground Layer");
        LevelLayer ll = go.AddComponent <LevelLayer>();

        ll.levelManager      = this;
        ll.gameCamera        = gameCamera;
        ll.levelNumberString = levelType;
        ll.levelPart         = "grounds";
        ll.yPosition         = 0.65f;
        ll.sortLayerName     = "Ground";
        ll.needsCollider     = true;
        ll.SetupLevelLayer();
        layers.Add(go);

        // Proximate Background Layer
        // & Sky Objects (clouds, etc.)
        randomSeed += 1;
        Random.InitState(randomSeed);
        GameObject go2 = new GameObject("Proximate Background Layer");
        LevelLayer ll2 = go.AddComponent <LevelLayer>();

        ll2.levelManager      = this;
        ll2.gameCamera        = gameCamera;
        ll2.levelNumberString = levelType;
        ll2.levelPart         = "backgrounds";
        ll2.yPosition         = 4.5f;
        ll2.sortLayerName     = "BackgroundProximate";
        ll2.needsCollider     = false;
        ll2.SetupLevelLayer();
        layers.Add(go2);

        // Medial Background Layer
        randomSeed += 1;
        Random.InitState(randomSeed);
        GameObject go3 = new GameObject("Medial Background layer");
        LevelLayer ll3 = go3.AddComponent <LevelLayer>();

        ll3.levelManager           = this;
        ll3.gameCamera             = gameCamera;
        ll3.levelNumberString      = medialLayerType;
        ll3.levelPart              = "backgrounds";
        ll3.yPosition              = 5.2f;
        ll3.sortLayerName          = "BackgroundMedial";
        ll3.needsCollider          = false;
        ll3.parallaxLayer          = true;
        ll3.parallaxMovementFactor = 0.4f;
        ll3.SetupLevelLayer();
        layers.Add(go3);

        // Distal Background Layer
        randomSeed += 1;
        Random.InitState(randomSeed);
        GameObject go4 = new GameObject("Distal Background layer");
        LevelLayer ll4 = go4.AddComponent <LevelLayer>();

        ll4.levelManager           = this;
        ll4.gameCamera             = gameCamera;
        ll4.levelNumberString      = distalLayerType;
        ll4.levelPart              = "backgrounds";
        ll4.yPosition              = 5.3f;
        ll4.sortLayerName          = "BackgroundDistal";
        ll4.needsCollider          = false;
        ll4.parallaxLayer          = true;
        ll4.parallaxMovementFactor = 0.7f;
        ll4.SetupLevelLayer();
        layers.Add(go4);
    }
Ejemplo n.º 11
0
 public LevelLayerSettings()
 {
     LevelLayers = new LevelLayer();
 }
Ejemplo n.º 12
0
        //---------------------------------------------------------------------------------------------------------
        // NewGame - Used in menu selection
        //---------------------------------------------------------------------------------------------------------
        // Transitions to LevelLayer
        //---------------------------------------------------------------------------------------------------------
        void NewGame(object stuff = null)
        {
            if (currentPlayer.BranchProgression[1].LastLevelCompleted > -1)
            {
                //if (currentPlayer.LastLevelCompleted > -1) {
                CCRect bounds = VisibleBoundsWorldspace;

                PauseListeners(true);
                Application.Paused = true;

                var newGameLayer = new CCLayerColor(new CCColor4B(0, 0, 0, 230));
                AddChild(newGameLayer, 99999);

                // Add frame to layer
                frameSprite             = new CCSprite(uiSpriteSheet.Frames.Find(x => x.TextureFilename.Equals("frame.png")));
                frameSprite.AnchorPoint = CCPoint.AnchorMiddle;
                frameSprite.Position    = new CCPoint(bounds.Size.Width / 2, bounds.Size.Height / 2);
                newGameLayer.AddChild(frameSprite);

                newGameWarning                     = new CCLabel("This will erase your current progress!\n\n\nProceed?", GOTHIC_56_WHITE_FNT);
                newGameWarning.AnchorPoint         = CCPoint.AnchorMiddle;
                newGameWarning.Scale               = 1.5f;
                newGameWarning.Position            = new CCPoint(frameSprite.BoundingBox.Center);
                newGameWarning.HorizontalAlignment = CCTextAlignment.Center;
                newGameLayer.AddChild(newGameWarning);

                okLabel             = new CCLabel("OK", GOTHIC_44_HD_FNT);
                okLabel.AnchorPoint = CCPoint.AnchorMiddle;
                okLabel.Scale       = 1.5f;

                cancelLabel             = new CCLabel("Cancel", GOTHIC_44_HD_FNT);
                cancelLabel.AnchorPoint = CCPoint.AnchorMiddle;
                cancelLabel.Scale       = 1.5f;

                var okItem = new CCMenuItemLabel(okLabel, okSender => {
                    newGameLayer.RemoveFromParent();
                    ResumeListeners(true);
                    Application.Paused = false;

                    currentPlayer = new Player();
                    currentPlayer.WriteData(currentPlayer);

                    var mainGame         = LevelLayer.CreateScene(Window, levels, currentPlayer);
                    var transitionToGame = new CCTransitionFade(2.0f, mainGame);
                    Director.ReplaceScene(transitionToGame);
                });
                okItem.Position = bounds.Center;

                var cancelItem = new CCMenuItemLabel(cancelLabel, cancelSender => {
                    newGameLayer.RemoveFromParent();
                    ResumeListeners(true);
                    Application.Paused = false;
                });
                cancelItem.Position = bounds.Center;

                var closeMenu = new CCMenu(okItem, cancelItem);
                closeMenu.AlignItemsHorizontally(50);
                closeMenu.AnchorPoint = CCPoint.AnchorMiddleBottom;
                closeMenu.Position    = new CCPoint(bounds.Size.Width / 2, frameSprite.BoundingBox.MinY + (okLabel.BoundingBox.Size.Height * 2.5f));

                newGameLayer.AddChild(closeMenu);
            }
            else
            {
                var mainGame         = LevelLayer.CreateScene(Window, levels, currentPlayer);
                var transitionToGame = new CCTransitionFade(2.0f, mainGame);
                Director.ReplaceScene(transitionToGame);
            }
        }
 public void Merge(LevelLayer other)
 {
     AddRange(other);
 }