Exemplo n.º 1
0
 //.................................>8.......................................
 void OnTriggerEnter2D(Collider2D collidingObj)
 {
     if (collidingObj.name == stringLib.PROJECTILE_WARP)
     {
         string sMessage = stringLib.LOG_WARPED + filename;
         Logger.printLogFile(sMessage, this.transform.position);
         Destroy(collidingObj.gameObject);
         lg.toolsAirborne--;
         if (!toolgiven)
         {
             toolgiven = true;
             for (int i = 0; i < stateLib.NUMBER_OF_TOOLS; i++)
             {
                 if (tools[i] > 0)
                 {
                     lg.floatingTextOnPlayer("New Tools!");
                 }
                 ToolSelectorObject.GetComponent <SelectedTool>().bonusTools[i] += tools[i];
                 if (ToolSelectorObject.GetComponent <SelectedTool>().toolCounts[i] == 0 && ToolSelectorObject.GetComponent <SelectedTool>().bonusTools[i] == 0)
                 {
                     ToolSelectorObject.GetComponent <SelectedTool>().toolIcons[i].GetComponent <GUITexture>().enabled = false;
                     if (ToolSelectorObject.GetComponent <SelectedTool>().projectilecode == i)
                     {
                         ToolSelectorObject.GetComponent <SelectedTool>().NextTool();
                     }
                 }
             }
         }
         lg.BuildLevel(lg.gamemode + "leveldata" + Menu.GetComponent <Menu>().filepath + filename, true, warpToLine);
     }
 }
Exemplo n.º 2
0
        private async void InitProxyAsync(string serverUrl)
        {
            //perform async initiating operations.
            var pl = await PlayerContext.GetPlayerStateAsync(DeviceInfo.Instance.GetSystemId());

            CurrentPlayerGuid = pl.UserId.ToString();

            hubConnection = new HubConnection(serverUrl);
            hubConnection.Headers.Add("UserGuid", CurrentPlayerGuid);
            MultiPlayerHub              = hubConnection.CreateHubProxy("MultiplayerHub");
            hubConnection.StateChanged += HubConnection_StateChanged;
            await hubConnection.Start().ContinueWith(async task =>
            {
                if (task.IsFaulted)
                {
                    OnConnectionError?.Invoke(task.Exception);
                    //could also be unauthorized due to no correct userguid
                }
                else
                {
                    //connected:
                    MultiPlayerHub.On <MultiPlayerSession>("updateSession", sessionObject => UpdateSession(sessionObject));
                    MultiPlayerHub.On <List <Player>, NormalGamePlatform, bool>("receiveNormalMonsterBroadcast", ReceiveNormalMonsterBroadcast);
                    MultiPlayerHub.On <List <Player>, BossGamePlatform, bool>("receiveBossMonsterBroadcast", ReceiveBossMonsterBroadcast);
                    MultiPlayerHub.On("broadcastYourClicks", RequestClickBatches);
                    MultiPlayerHub.On <BatchedClick>("receiveUploadedBatchClicks", ReceiveUploadedBatchClicks);
                    MultiPlayerHub.On <InviteModel>("receiveInvite", ReceiveInvite);
                }

                //for now render a new level anyways.
                SessionContext = new MultiPlayerSession {
                    CurrentPlayerList = new List <Player> {
                        pl
                    }, HostPlayerId = CurrentPlayerGuid
                };
                SessionContext.CurrentLevel = LevelGenerator.BuildLevel(SessionContext.CurrentPlayerList);
                await BroadcastSessionToServer();
            });

            InitializeComplete?.Invoke(null, null);

            Dictionary <string, string> dingetje = new Dictionary <string, string>
            {
                { "sessionguid", CurrentPlayerGuid }
            };
            await RestHelper.GetRequestAsync("api/multiplayer/AddSession", dingetje);
        }
Exemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        LevelGenerator LG = (LevelGenerator)target;

        EditorGUILayout.Space();

        GUILayout.Label("PSD size: 13 - 12 pixels.\n" +
                        "Use the pencil tool, size 1px.\n" +
                        "Save as PSD en set in Unity filter mode to Point\n" +
                        "and compression to none and in advanced Read/Write enabled");
        if (GUILayout.Button("Build Levels", GUILayout.Height(50)))
        {
            Debug.Log("Build done");
            LG.RemoveLevel();
            LG.BuildLevel();
        }
    }
Exemplo n.º 4
0
    private void CreateLevel()
    {
        LevelGenerator generator = new LevelGenerator(levelWidth, levelLength);

        List <Node> listOfRooms = generator.BuildLevel(
            maxIterations,
            roomWidthMin,
            roomLengthMin,
            corridorWidth,
            bottomLeftPointModifier,
            topRightPointModifier,
            offset);

        GameObject parentWall = new GameObject("ParentWall");

        parentWall.transform.parent = transform;

        verticalDoorPossiblePositions   = new List <Vector3Int>();
        horizontalDoorPossiblePositions = new List <Vector3Int>();

        verticalWallPossiblePositions   = new List <Vector3Int>();
        horizontalWallPossiblePositions = new List <Vector3Int>();

        for (int i = 0; i < listOfRooms.Count; i++)
        {
            CreateMesh(listOfRooms[i].BottomLeftAreaCorner, listOfRooms[i].TopRightAreaCorner);
        }

        CreateWalls(parentWall);

        SpawnObjects(listOfRooms);

        SpawnPlayerAndGuards(listOfRooms);

        for (int i = 0; i < AStar.Length; i++)
        {
            AStar[i].GetComponentInChildren <Grid>().FinishedLevelGeneration1 = true;
        }
    }
Exemplo n.º 5
0
        public void TestBuildLevel()
        {
            int           stateNumber = 10;
            List <Player> players     = new List <Player>();

            for (int i = 0; i < 4; i++)
            {
                players.Add(new Player
                {
                    DeviceId = $"{i}",
                    State    = new PlayerState {
                        MonstersDefeated = stateNumber
                    },
                    UserId   = Guid.NewGuid(),
                    Username = $"Test{i}",
                    Wallet   = new PlayerCurrency {
                    }
                });
            }

            GamePlatform platform = levelGenerator.BuildLevel(players);

            if (stateNumber % LevelGenerator.LevelsUntilBoss == 0)
            {
                Assert.IsTrue(platform is BossLevel);

                Assert.IsTrue(platform.Monster is BossScene);

                Assert.IsTrue(platform.Scene is Boss);
            }
            else
            {
                Assert.IsTrue(platform is NormalLevel);

                Assert.IsTrue(platform.Scene is NormalScene);

                Assert.IsTrue(platform.Monster is Normal);
            }
        }
Exemplo n.º 6
0
    //.................................>8.......................................
    // Update is called once per frame
    void Update()
    {
        // Handle "Resume Game" button behavior. If we have a game session we can click it, otherwise grey it out. --[
        if (!gameon)
        {
            buttons[stateLib.GAMEMENU_RESUME_GAME].GetComponent <SpriteRenderer>().color = Color.grey;
        }
        else
        {
            buttons[stateLib.GAMEMENU_RESUME_GAME].GetComponent <SpriteRenderer>().color = Color.white;
        }
        // ]-- End of "Resume Game" button behavior.
        // If we are in the menu, handle up and down arrows --[
        if (lg.gamestate == stateLib.GAMESTATE_MENU)
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                // The previous button should be made blue (change from green to blue).
                // If we are on the first option (New Game), don't allow the up arrow to wrap-around.
                buttons[option].GetComponent <SpriteRenderer>().sprite = bluebutton;
                option = (option == stateLib.GAMEMENU_NEW_GAME) ? stateLib.GAMEMENU_NEW_GAME : option - 1;
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                // The previous button should be made blue (change from green to blue).
                // The last option will be either Resume Game or Exit game. In either case, don't allow the down arrow to wrap-around.
                buttons[option].GetComponent <SpriteRenderer>().sprite = bluebutton;
                if (gameon)
                {
                    option = (option == stateLib.GAMEMENU_RESUME_GAME) ? stateLib.GAMEMENU_RESUME_GAME : option + 1;
                }
                else
                {
                    option = (option == stateLib.GAMEMENU_EXIT_GAME) ? stateLib.GAMEMENU_EXIT_GAME : option + 1;
                }
            }
            if (Input.GetKeyDown(KeyCode.Z))
            {
                lg.ToggleLightDark();
            }
            // ]-- End of Arrow controller.

            // Make the current button appear green. The previous buttons change to blue
            // because there is an Up or Down arrow event. This will fire outside of the event.
            buttons[option].GetComponent <SpriteRenderer>().sprite = greenbutton;

            // When we press Return (Enter Key), take us to the sub-menus
            if ((Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) && delaytime < Time.time)
            {
                switch (option)
                {
                case stateLib.GAMEMENU_NEW_GAME:
                    // Select between RobotON or RoboBUG.
                    lg.gamestate = -3;
                    buttons[option].GetComponent <SpriteRenderer>().sprite = bluebutton;
                    option = 0;
                    m2switch(true);
                    m2buttontext[0].GetComponent <TextMesh>().text = stringLib.GAME_ROBOT_ON;
                    m2buttontext[1].GetComponent <TextMesh>().text = stringLib.GAME_ROBOT_BUG;
                    break;

                case stateLib.GAMEMENU_LOAD_GAME:
                    // Load a level from RobotON or RoboBUG.
                    lg.gamestate = -4;
                    buttons[option].GetComponent <SpriteRenderer>().sprite = bluebutton;
                    option = 0;
                    m2switch(true);
                    m2buttontext[0].GetComponent <TextMesh>().text = stringLib.GAME_ROBOT_ON;
                    m2buttontext[1].GetComponent <TextMesh>().text = stringLib.GAME_ROBOT_BUG;
                    break;

                case stateLib.GAMEMENU_SOUND_OPTIONS:
                    lg.gamestate = -2;
                    buttons[option].GetComponent <SpriteRenderer>().sprite = bluebutton;
                    option = 0;
                    m2switch(true);
                    m2buttontext[0].GetComponent <TextMesh>().text = "Sound: " + (soundon ? lg.stringLibrary.menu_sound_on_color_tag + "ON" + stringLib.CLOSE_COLOR_TAG : lg.stringLibrary.menu_sound_off_color_tag + "OFF" + stringLib.CLOSE_COLOR_TAG);
                    m2buttontext[1].GetComponent <TextMesh>().text = "Back";
                    break;

                case stateLib.GAMEMENU_EXIT_GAME:
                    postToDatabase.Start();
                    Application.Quit();
                    break;

                case stateLib.GAMEMENU_RESUME_GAME:
                    lg.gamestate = stateLib.GAMESTATE_IN_GAME;
                    buttons[option].GetComponent <SpriteRenderer>().sprite = bluebutton;
                    lg.GUISwitch(true);
                    break;

                default:
                    break;
                }
            }
        }
        else if (Input.GetKeyDown(KeyCode.Escape) && lg.gamestate < 0 && !lg.isAnswering)
        {
            m2switch(false);
            flushButtonColor();
            lg.gamestate = stateLib.GAMESTATE_MENU;
        }
        else if (lg.gamestate == stateLib.GAMESTATE_MENU_LOADGAME_SUBMENU)
        {
            if (levoption < levels.Count - 1 && passed[levoption] == "1")
            {
                m2arrows[1].GetComponent <SpriteRenderer>().enabled = true;
            }
            else
            {
                m2arrows[1].GetComponent <SpriteRenderer>().enabled = false;
            }
            if (levoption != 0)
            {
                m2arrows[0].GetComponent <SpriteRenderer>().enabled = true;
            }
            else
            {
                m2arrows[0].GetComponent <SpriteRenderer>().enabled = false;
            }
            m2buttons[option].GetComponent <SpriteRenderer>().sprite = greenbutton;
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                m2buttons[1].GetComponent <SpriteRenderer>().sprite = bluebutton;
                option = 0;
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                m2buttons[0].GetComponent <SpriteRenderer>().sprite = bluebutton;
                option = 1;
            }
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                if (levoption < levels.Count - 1 && passed[levoption] == "1")
                {
                    levoption++;
                }
                m2buttontext[0].GetComponent <TextMesh>().text = levels[levoption];
            }
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                levoption = (levoption == 0) ? 0 : levoption - 1;
                m2buttontext[0].GetComponent <TextMesh>().text = levels[levoption];
            }
            if ((Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)))
            {
                switch (option)
                {
                case 0:
                    lg.BuildLevel(lg.gamemode + "leveldata" + filepath + levels[levoption], false);
                    lg.gamestate = stateLib.GAMESTATE_LEVEL_START;
                    levoption    = 0;
                    gameon       = true;
                    buttons[4].GetComponent <SpriteRenderer>().color = Color.white;
                    m2switch(false);
                    break;

                case 1:
                    lg.gamestate = stateLib.GAMESTATE_MENU;
                    m2buttons[1].GetComponent <SpriteRenderer>().sprite = bluebutton;

                    m2switch(false);
                    break;

                default:
                    break;
                }
            }
        }
        //
        else if (lg.gamestate == stateLib.GAMESTATE_MENU_SOUNDOPTIONS)
        {
            m2buttons[option].GetComponent <SpriteRenderer>().sprite = greenbutton;
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                m2buttons[1].GetComponent <SpriteRenderer>().sprite = bluebutton;
                option = 0;
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                m2buttons[0].GetComponent <SpriteRenderer>().sprite = bluebutton;
                option = 1;
            }
            if ((Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)))
            {
                switch (option)
                {
                case 0:
                    soundon = !soundon;
                    m2buttontext[0].GetComponent <TextMesh>().text = "Sound: " + ((soundon) ? lg.stringLibrary.menu_sound_on_color_tag + "ON" + stringLib.CLOSE_COLOR_TAG : lg.stringLibrary.menu_sound_off_color_tag + "OFF" + stringLib.CLOSE_COLOR_TAG);
                    AudioListener.volume = (soundon) ? 1 : 0;
                    break;

                case 1:
                    lg.gamestate = stateLib.GAMESTATE_MENU;
                    m2buttons[1].GetComponent <SpriteRenderer>().sprite = bluebutton;
                    m2switch(false);
                    option = 2;
                    break;
                }
            }
        }
        else if (lg.gamestate == stateLib.GAMESTATE_MENU_NEWGAME)
        {
            m2buttons[option].GetComponent <SpriteRenderer>().sprite = greenbutton;
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                m2buttons[1].GetComponent <SpriteRenderer>().sprite = bluebutton;
                option = 0;
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                m2buttons[0].GetComponent <SpriteRenderer>().sprite = bluebutton;
                option = 1;
            }
            if ((Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)))
            {
                switch (option)
                {
                case 0:
                    lg.gamemode = stringLib.GAME_MODE_ON;
                    lg.BuildLevel("onleveldata" + filepath + stringLib.START_LEVEL_FILE, false);
                    lg.gamestate = stateLib.GAMESTATE_LEVEL_START;
                    break;

                case 1:
                    lg.gamemode = stringLib.GAME_MODE_ON;
                    lg.BuildLevel("onleveldata" + filepath + stringLib.START_LEVEL_FILE, false);
                    lg.gamestate = stateLib.GAMESTATE_LEVEL_START;

                    /*
                     * lg.gamemode = stringLib.GAME_MODE_BUG;
                     * lg.BuildLevel("bugleveldata" + filepath + "tut1.xml");
                     * lg.gamestate = stateLib.GAMESTATE_INITIAL_COMIC;
                     */
                    break;
                }
                m2switch(false);
                gameon = true;
                buttons[4].GetComponent <SpriteRenderer>().color = Color.white;
            }
        }
        else if (lg.gamestate == stateLib.GAMESTATE_MENU_LOADGAME)
        {
            m2buttons[option].GetComponent <SpriteRenderer>().sprite = greenbutton;
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                m2buttons[1].GetComponent <SpriteRenderer>().sprite = bluebutton;
                option = 0;
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                m2buttons[0].GetComponent <SpriteRenderer>().sprite = bluebutton;
                option = 1;
            }
            if ((Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)))
            {
                switch (option)
                {
                case 0:
                    lg.gamemode = stringLib.GAME_MODE_ON;
                    break;

                case 1:
                    lg.gamemode = stringLib.GAME_MODE_BUG;
                    break;
                }

                levels.Clear();
                passed.Clear();
                lfile = lg.gamemode + "leveldata" + filepath + "levels.txt";
                sr    = File.OpenText(lfile);
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] data = line.Split(' ');
                    levels.Add(data[0]);
                    passed.Add(data[1]);
                }
                sr.Close();

                lg.gamestate = -1;
                option       = 0;
                m2buttons[1].GetComponent <SpriteRenderer>().sprite = bluebutton;
                m2buttontext[0].GetComponent <TextMesh>().text      = levels[levoption];
                m2buttontext[1].GetComponent <TextMesh>().text      = "Back";
            }
        }
        else
        {
            delaytime = Time.time + delay;
        }
    }
Exemplo n.º 7
0
    //.................................>8.......................................
    // Update is called once per frame
    void Update()
    {
        if (lg.gamestate == stateLib.GAMESTATE_LEVEL_START)
        {
            if (!cinerun)
            {
                cinerun = true;
                if (lg.gamemode != stringLib.GAME_MODE_ON)
                {
                    GameObject bug = (GameObject)Instantiate(cinebugs[2]);
                    objs.Add(bug);
                }
                else
                {
                    GameObject rob = (GameObject)Instantiate(cinebugs[3]);
                    objs.Add(rob);
                }
            }
            GetComponent <TextMesh>().text = introtext;
            if ((Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) && delaytime < Time.time)
            {
                lg.gamestate = stateLib.GAMESTATE_IN_GAME;
                Destroy(objs[0]);
                cinerun = false;
                objs    = new List <GameObject>();
                lg.GUISwitch(true);
            }
        }
        else if (lg.gamestate == stateLib.GAMESTATE_LEVEL_WIN)
        {
            if (!cinerun)
            {
                cinerun = true;
                GameObject bug = (GameObject)Instantiate(cinebugs[3]);
                objs.Add(bug);
                bug = (GameObject)Instantiate(cinebugs[0]);
                objs.Add(bug);
            }

            GetComponent <TextMesh>().text = endtext;

            if ((Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) && delaytime < Time.time)
            {
                // RobotON 2, don't always want tutorials to run comics.
                // Read in the levels.txt and grab the top one.
                if (lg.currentlevel.StartsWith("tut") && lg.gamemode == stringLib.GAME_MODE_BUG)
                {
                    lg.gamestate = stateLib.GAMESTATE_STAGE_COMIC;
                }
                else
                {
                    lg.gamestate = stateLib.GAMESTATE_LEVEL_START;
                }

                lg.BuildLevel(lg.nextlevel, false);
                Destroy(objs[1]);
                Destroy(objs[0]);
                cinerun = false;
                objs    = new List <GameObject>();
            }
        }
        else if (lg.gamestate == stateLib.GAMESTATE_LEVEL_LOSE)
        {
            if (!cinerun)
            {
                cinerun = true;
                GameObject bug = (GameObject)Instantiate(cinebugs[4]);
                objs.Add(bug);
            }
            GetComponent <TextMesh>().text         = stringLib.LOSE_TEXT;
            prompt2.GetComponent <TextMesh>().text = stringLib.RETRY_TEXT;
            if (Input.GetKeyDown(KeyCode.Escape) && delaytime < Time.time)
            {
                Destroy(objs[0]);
                prompt2.GetComponent <TextMesh>().text = stringLib.CONTINUE_TEXT;

                cinerun      = false;
                objs         = new List <GameObject>();
                lg.gamestate = stateLib.GAMESTATE_MENU;
            }
            if ((Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) && delaytime < Time.time)
            {
                Destroy(objs[0]);
                prompt2.GetComponent <TextMesh>().text = stringLib.CONTINUE_TEXT;

                cinerun = false;
                objs    = new List <GameObject>();
                menu.GetComponent <Menu>().gameon = true;
                // One is called Bugleveldata and another OnLevel data.
                // Levels.txt, coding in menu.cs
                lg.BuildLevel(lg.gamemode + "leveldata" + menu.GetComponent <Menu>().filepath + lg.currentlevel, false);
                lg.gamestate = stateLib.GAMESTATE_LEVEL_START;
            }
        }
        else
        {
            delaytime = Time.time + delay;
        }
    }