Пример #1
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (!GameData.FriendlyFire && collision.gameObject.GetComponent <BallBehavior>().lastPlayer == player)
        {
            return;
        }
        if (Destroyed)
        {
            return;
        }
        PlatformBehavior pb = player.GetComponent <PlatformBehavior>();

        if (--pb.Health > 0)
        {
            if (pb.Health < Cracks.Length)
            {
                sr.sprite = Cracks[Cracks.Length - pb.Health];
            }
            return;
        }
        audioSource.PlayOneShot(GameData.S_BreakSound);
        sr.sprite     = Cracks[0];
        sr.material   = faded;
        col.isTrigger = true;
        Destroyed     = true;
    }
Пример #2
0
    //switches the type of behavior on the fly if necessary later
    void ChangeBehavior(PlatformBehavior newBehavior)
    {
        switch (newBehavior)
        {
        case PlatformBehavior.Disappearing:
            //choose an obstacle/platform behavior
            break;

        case PlatformBehavior.Normal:
            //does nothing, supports weight and platforming
            break;

        case PlatformBehavior.Moving:
            //choose an obstacle/platform behavior
            break;

        case PlatformBehavior.Falling:
            //choose an obstacle/platform behavior
            break;

        default:
            break;
        }
        behavior = newBehavior;
        Debug.Log("WARNING!! This is a " + behavior + " type of Platform.");
    }
Пример #3
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     //If collision if with platform
     if (collision.transform.CompareTag("Platform"))
     {
         //Get platform script
         PlatformBehavior collidedPlatform = collision.collider.GetComponent <PlatformBehavior>();
         //Bounce off the platform
         Bounce(collision.contacts[0].normal, collidedPlatform.PlatformPower);
         //If platform power has been increased
         if (collidedPlatform.PlatformPower > 0)
         {
             //Activate platform Particle System
             collidedPlatform.platformParticles.gameObject.SetActive(true);
             //Unparent partcile system (so particles are not destroyed with platform)
             collidedPlatform.platformParticles.transform.parent = null;
         }
         //Set the platformInstance in PlatformSpawner to null.
         PlatformSpawner.singleton.platformInstance = null;
         //Destroy the platform game object.
         Destroy(collision.gameObject);
     }
     else
     {
         Bounce(collision.contacts[0].normal);
     }
 }
Пример #4
0
 void checkPlatforms()
 {
     for (int i = 0; i < platforms.Length; i++)
     {
         ps = platforms[i].GetComponent <PlatformBehavior>();
     }
 }
Пример #5
0
    public void SpawnBallForPlayer(GameObject player)
    {
        PlatformBehavior pb   = player.GetComponent <PlatformBehavior>();
        GameObject       ball = Instantiate(ballObject, pb.BoredBallSpawn.position, Quaternion.identity);

        ball.GetComponent <Rigidbody2D>().velocity = (player.transform.position - pb.BoredBallSpawn.position).normalized * startSpeed;
        balls.Add(ball);
    }
Пример #6
0
    public void CollidePlatform(PlatformBehavior pb)
    {
        var relpos = pb.transform.position - transform.position;

        if (Mathf.Abs(relpos.x) <= winThreshold.x && Mathf.Abs(relpos.y) <= winThreshold.y && pb.gameObject.GetInstanceID() == winPlatform.gameObject.GetInstanceID())
        {
            winFlag = true;
        }
        ((BoatState)CurrentState).CollidePlatform(pb);
    }
Пример #7
0
 public override void OnTriggerEnter2D(Collider2D collider)
 {
     base.OnTriggerEnter2D(collider);
     if (collider.tag == "Ball")
     {
         PlatformBehavior pb = collider.GetComponent <BallBehavior>().lastPlayer.GetComponent <PlatformBehavior>();
         pb.StartCoroutine(pb.SizeBuff(SizeMod, Duration));
         GetComponent <BoxCollider2D>().enabled = false;
         anim.Play(Anim);
         //Destroy(gameObject);
     }
 }
Пример #8
0
 public override void OnTriggerEnter2D(Collider2D collider)
 {
     base.OnTriggerEnter2D(collider);
     if (collider.tag == "Ball")
     {
         PlatformBehavior pb = collider.GetComponent <BallBehavior>().lastPlayer.GetComponent <PlatformBehavior>();
         pb.Health += ShieldAmount;
         GetComponent <BoxCollider2D>().enabled = false;
         anim.Play(Anim);
         //Destroy(gameObject);
     }
 }
Пример #9
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag(GameTags.SafeZoneTag))
     {
         Player.isGrounded = true;
     }
     if (collision.gameObject.CompareTag(GameTags.PlatformTag))
     {
         Player.isGrounded      = true;
         Player.reachedPlatform = true;
         PlatformBehavior currenPlatform = collision.gameObject.GetComponent <PlatformBehavior>();
         player.SetCurrentPlatform(currenPlatform);
     }
 }
 public void SetCurrentPlatform(PlatformBehavior currentPlatform)
 {
     if (prevPlatform == null || currentPlatform != prevPlatform)
     {
         PlayercurrentPlatform = currentPlatform;
         prevPlatform          = PlayercurrentPlatform;
         NumSO       = (VariableSO <int>)OnChangeValue.Value;
         NumSO.Value = PlayercurrentPlatform.maxNumberOfJumps;
         PlayercurrentPlatform.finished = true;
     }
     else
     {
         PlayercurrentPlatform = prevPlatform;
     }
 }
Пример #11
0
        private void FixedUpdate()
        {
            Vector3 mousePos = platformPositionAction.ReadValue <Vector2>();

            mousePos.z = 10;
            Vector3      screenPos = playerCamera.ScreenToWorldPoint(mousePos);
            RaycastHit2D hit       = Physics2D.Raycast(screenPos, Vector2.zero);

            if (hit)
            {
                if (hit.collider.CompareTag("Platform"))
                {
                    targetedPlatform = hit.collider.GetComponent <PlatformBehavior>();
                }
            }
            else
            {
                targetedPlatform = null;
            }
        }
Пример #12
0
    /**
     * Generate a world using the given .JSON file in 'levelDescriptionJson'
     */
    public void CreateWorldFromLevelDescription()
    {
        LevelEntitiesJSON level = JsonUtility.FromJson <LevelEntitiesJSON>(levelDescriptionJsonFiles[levelFileIndex].text);

        gameController.winCondition = GetWinConditionFromString(level.winCondition);
        // list of link blocks we are creating
        levelLinks = new List <LinkBehavior>();
        Debug.Log("Loading blocks");
        // while generating the level, add things to levelEntities list so it can be destroyed for the next level generated.
        for (int i = 0; i < level.blocks.Length; i++)
        {
            Vector2 blockPos = new Vector2((float)(level.blocks[i].x + (level.blocks[i].width / 2f)),
                                           (float)(level.blocks[i].y - (level.blocks[i].height / 2f)));
            Transform objToInstances = GetAssocInstanceFromType(level.blocks[i].type);
            if (objToInstances != null)
            {
                if (objToInstances == groundPreFab && level.blocks[i].height == 1)
                {
                    objToInstances = groundTopPreFab; // render it with details on top of the block.
                }
                Transform obj         = Instantiate(objToInstances, blockPos, Quaternion.identity);
                Vector2   sizeOfBlock = new Vector3((int)level.blocks[i].width, (int)level.blocks[i].height);
                obj.GetComponent <SpriteRenderer>().size = sizeOfBlock;
                obj.GetComponent <BoxCollider2D>().size  = sizeOfBlock;
                obj.GetComponent <LoggableBehavior>().setLogID(level.blocks[i].logId); // ground block
                levelEntities.Add(obj);
            }
        }
        Debug.Log("Loading player");
        // create the player
        if (level.player != null)
        {
            Vector2 loc = new Vector2((float)(level.player.x + (1 / 2f)), (float)(level.player.y - (1 / 2f)));
            gameController.playerRef = Instantiate(playerPreFab, loc, Quaternion.identity);
            gameController.playerRef.GetComponent <PlayerBehavior>().gameController = gameController;
            gameController.playerRef.GetComponent <LoggableBehavior>().setLogID(level.player.logId);
            levelEntities.Add(gameController.playerRef);
            // move the backdrop right behind the player initially.
            backgroundRef.position = gameController.playerRef.position + new Vector3(0, 0, -10);
        }
        Debug.Log("Loading goal");
        if (level.goalPortal != null)
        {
            Vector2   loc  = new Vector2((float)(level.goalPortal.x + (1 / 2f)), (float)(level.goalPortal.y - (1 / 2f)));
            Transform goal = Instantiate(goalPortalPreFab, loc, Quaternion.identity);
            goal.GetComponent <LoggableBehavior>().setLogID(level.goalPortal.logId);
            levelEntities.Add(goal);
        }
        Debug.Log("Loading helicopter robot");
        if (level.helicopterRobot != null)
        {
            Vector2   loc   = new Vector2((float)(level.helicopterRobot.x + (1 / 2f)), (float)(level.helicopterRobot.y - (1 / 2f)));
            Transform robot = Instantiate(helicopterRobotPreFab, loc, Quaternion.identity);
            HelicopterRobotBehavior robotBehavior = robot.GetComponent <HelicopterRobotBehavior>();
            robotBehavior.gameController = gameController;
            robotBehavior.targetLocation = robot.position;
            robotBehavior.GetComponent <LoggableBehavior>().setLogID(level.helicopterRobot.logId);

            gameController.helicopterRobotRef = robot;
            robotBehavior.GetComponent <ContainerEntityBehavior>().refreshChildList();
            robotBehavior.getChildLink().GetComponent <LoggableBehavior>().setLogID("helicopter");
            robotBehavior.getChildLink().type = LinkBehavior.Type.HELICOPTER;
            robotBehavior.getChildLink().setVariableName("temp");
            robotBehavior.getChildLink().setContainerEntity(robot.GetComponent <ContainerEntityBehavior>());
            levelEntities.Add(robot);
            levelLinks.Add(robotBehavior.GetComponent <ContainerEntityBehavior>().GetChildComponent <LinkBehavior>());
        }

        // corresponding list of IDs telling the link blocks what they should point to when the level is generated
        List <string>                 levelLinksConnIds     = new List <string>();
        List <LinkBehavior>           levelLinkComps        = new List <LinkBehavior>();
        List <ObjectiveBlockBehavior> levelObjectiveBlocks  = new List <ObjectiveBlockBehavior>();
        List <PlatformBehavior>       levelPlatformEntities = new List <PlatformBehavior>();

        gameController.platformsToAdd = new List <PlatformBehavior>();
        // create the start link
        Debug.Log("Loading start link");
        if (level.startLink != null)
        {
            Vector2      loc               = new Vector2((float)(level.startLink.x + (1 / 2f)), (float)(level.startLink.y - (1 / 2f)));
            Transform    startLinkTran     = Instantiate(linkBlockPreFab, loc, Quaternion.identity);
            LinkBehavior startLinkBehavior = startLinkTran.GetComponent <LinkBehavior>();
            startLinkTran.position          = startLinkTran.position + (new Vector3(0, 0, -5));
            startLinkBehavior.type          = LinkBehavior.Type.START;
            startLinkBehavior.defaultSprite = startLinkBlockSprite;
            startLinkBehavior.nullSprite    = nullStartLinkBlockSprite;
            startLinkBehavior.GetComponent <LoggableBehavior>().setLogID(level.startLink.logId);

            startLinkBehavior.GetComponent <SpriteRenderer>().sprite = startLinkBlockSprite;
            gameController.startingLink = startLinkBehavior; // set start link reference
            levelLinks.Add(startLinkBehavior);
            levelEntities.Add(startLinkTran);

            levelLinksConnIds.Add(level.startLink.objIDConnectingTo);
            levelLinkComps.Add(startLinkBehavior);
        }

        Debug.Log("Loading external link blocks");
        // create the indiv link blocks.
        for (int i = 0; i < level.linkBlocks.Length; i++)
        {
            Vector2   loc     = new Vector2((float)(level.linkBlocks[i].x + (1 / 2f)), (float)(level.linkBlocks[i].y - (1 / 2f)));
            Transform newLink = Instantiate(linkBlockPreFab, loc, Quaternion.identity);
            newLink.position = newLink.position + (new Vector3(0, 0, -5));
            LinkBehavior lb = newLink.GetComponent <LinkBehavior>();
            lb.GetComponent <LoggableBehavior>().setLogID(level.linkBlocks[i].logId);
            levelLinks.Add(lb);
            levelEntities.Add(newLink);

            levelLinksConnIds.Add(level.linkBlocks[i].objIDConnectingTo);
            levelLinkComps.Add(lb);
        }

        Debug.Log("Loading objective blocks");
        // create the objective blocks (fire)
        for (int i = 0; i < level.objectiveBlocks.Length; i++)
        {
            Vector2   loc       = new Vector2((float)(level.objectiveBlocks[i].x + (1 / 2f)), (float)(level.objectiveBlocks[i].y - (1 / 2f)));
            Transform newOBlock = Instantiate(objectiveBlockPreFab, loc, Quaternion.identity);
            newOBlock.GetComponent <LoggableBehavior>().setLogID(level.objectiveBlocks[i].logId);
            levelObjectiveBlocks.Add(newOBlock.GetComponent <ObjectiveBlockBehavior>());
            levelEntities.Add(newOBlock);
        }

        Debug.Log("Loading instruction blocks");
        // create the instruction blocks (question marks)
        for (int i = 0; i < level.instructionBlocks.Length; i++)
        {
            Vector2   loc = new Vector2((float)(level.instructionBlocks[i].x + (1 / 2f)), (float)(level.instructionBlocks[i].y - 1));
            Transform newInstructBlock = Instantiate(instructionViewBlockPreFab, loc, Quaternion.identity);
            newInstructBlock.GetComponent <InstructionViewBlockBehavior>().screenId = level.instructionBlocks[i].screenId;
            levelEntities.Add(newInstructBlock);
        }

        Debug.Log("Loading the platforms");
        // create the platforms.
        Dictionary <string, PlatformBehavior> listPlatformMap = new Dictionary <string, PlatformBehavior>();

        for (int i = 0; i < level.singleLinkedListPlatforms.Length; i++)
        {
            Vector2          loc           = new Vector2((float)(level.singleLinkedListPlatforms[i].x + (3 / 2f)), (float)(level.singleLinkedListPlatforms[i].y - (1 / 2f)));
            Transform        newLLPlatform = Instantiate(singleLinkedListPreFab, loc, Quaternion.identity);
            PlatformBehavior newPlat       = newLLPlatform.GetComponent <PlatformBehavior>();
            newPlat.GetComponent <ConnectableEntityBehavior>().incomingConnectionLinks = new List <LinkBehavior>();
            newPlat.gameController = gameController;

            newPlat.GetComponent <ContainerEntityBehavior>().refreshChildList();
            newPlat.setValue(level.singleLinkedListPlatforms[i].value);
            newPlat.GetComponent <LoggableBehavior>().setLogID(level.singleLinkedListPlatforms[i].logId);
            newPlat.GetComponent <ConnectableEntityBehavior>().incomingConnectionLinks = new List <LinkBehavior>();
            listPlatformMap.Add(level.singleLinkedListPlatforms[i].objId, newPlat);
            newPlat.getChildLink().state = LinkBehavior.State.NORMAL;
            newPlat.getChildLink().GetComponent <LoggableBehavior>().setLogID("child" + level.singleLinkedListPlatforms[i].logId);
            newPlat.getChildLink().setContainerEntity(newPlat.GetComponent <ContainerEntityBehavior>());
            levelLinks.Add(newPlat.GetComponent <ContainerEntityBehavior>().GetChildComponent <LinkBehavior>()); // add it to the list of blocks for references
            levelEntities.Add(newLLPlatform);

            levelLinksConnIds.Add(level.singleLinkedListPlatforms[i].childLinkBlockConnectId);
            levelLinkComps.Add(newPlat.getChildLink());
            levelPlatformEntities.Add(newPlat);

            newPlat.isInLevel = !level.singleLinkedListPlatforms[i].toAdd;
            if (level.singleLinkedListPlatforms[i].toAdd == true)
            {
                newLLPlatform.gameObject.SetActive(false);
                gameController.platformsToAdd.Add(newPlat);
            }
        }
        gameController.hudBehavior.setPlatformsToAddText(gameController.platformsToAdd.Count);
        Debug.Log("Completed loading " + listPlatformMap.Count + " platforms");

        Debug.Log("Establishing links ");
        // establishing links for the link blocks with the platforms
        for (int i = 0; i < levelLinksConnIds.Count; i++)
        {
            if (levelLinksConnIds[i] != null && levelLinksConnIds[i].Length > 0) // if this link has a connection.
            {
                string platformId = levelLinksConnIds[i];
                if (listPlatformMap[platformId].isInLevel == true)
                {
                    // establish the connection
                    levelLinkComps[i].ensureReferences();
                    levelLinkComps[i].setConnectionTo(listPlatformMap[platformId].GetComponent <ConnectableEntityBehavior>());
                }
            }
        }

        Debug.Log("Assigning variable names");
        string[] varNames = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "m", "n", "p", "q", "r", "z", "y" };
        int      varIndex = 0;

        // verify that no link blocks are being displayed
        foreach (LinkBehavior lb in levelLinks)
        {
            if (lb.type == LinkBehavior.Type.HELICOPTER)
            {
                lb.setVariableName("temp");
            }
            else if (lb.type == LinkBehavior.Type.START)
            {
                lb.setVariableName("list.head");
            }
            else
            {
                lb.setVariableName(varNames[varIndex++]);
            }
            lb.ensureReferences();
            lb.UpdateRendering();
        }

        Debug.Log("Updating everything");
        // update the win conditions for the objective blocks
        gameController.setLevelObjectiveBlocksList(levelObjectiveBlocks);
        gameController.setLevelPlatformEntitiesList(levelPlatformEntities);
        gameController.updateObjectiveHUDAndBlocks();
        gameController.updatePlatformEntities();
        gameController.codePanelBehavior.clearCodeText();
        gameController.hudBehavior.setLevelOnText(levelFileIndex + 1);
        gameController.hudBehavior.setPlatformsToAddText(gameController.platformsToAdd.Count);
        Debug.Log("Done loading world");
    }
Пример #13
0
 public void UnCollidePlatform(PlatformBehavior pb)
 {
 }
Пример #14
0
        public static IEnumerable <ValueTest <T> > MakeStrings(EncodingBehavior encodingBehavior,
                                                               bool allPermutations)
        {
            var testValues = new List <StringTestValue>()
            {
                new StringTestValue("empty", "", ""),
                new StringTestValue("simple", "abc", "abc"),
            };
            var allEscapeTests = new List <StringTestValue>();

            if (encodingBehavior.ForParsing)
            {
                // These escapes are not used when writing, but may be encountered when parsing
                allEscapeTests.Add(new StringTestValue("", "/", "\\/"));
                allEscapeTests.Add(new StringTestValue("", "も", "\\u3082"));
            }
            if (allPermutations)
            {
                var stringsToEscape = new string[] {
                    "\"", "\\", "\x05", "\x1c", "🦜🦄😂🧶😻 yes"
                };

                var escapeTests = new List <StringTestValue>();
                foreach (var stringValue in stringsToEscape)
                {
                    // JSON writers have some leeway in how they choose to do character escaping. The PlatformBehavior
                    // class will tell us how we expect the writer implementation we're testing to represent the string.
                    escapeTests.Add(new StringTestValue("", stringValue, PlatformBehavior.GetExpectedStringEncoding(stringValue)));
                }
                foreach (var et in escapeTests)
                {
                    allEscapeTests.Add(et);
                    foreach (var s in new string[] { "{0}abcd", "abcd{0}", "ab{0}cd" })
                    {
                        allEscapeTests.Add(new StringTestValue("",
                                                               String.Format(s, et.Value),
                                                               String.Format(s, et.Encoding)));
                    }
                    foreach (var et2 in escapeTests)
                    {
                        foreach (var s in new string[] { "{0}{1}abcd", "ab{0}{1}cd", "a{0}bc{1}d", "abcd{0}{1}" })
                        {
                            allEscapeTests.Add(new StringTestValue("",
                                                                   String.Format(s, et.Value, et2.Value),
                                                                   String.Format(s, et.Encoding, et2.Encoding)));
                        }
                    }
                }
            }
            else
            {
                allEscapeTests.Add(new StringTestValue("", "simple\tescape", "simple\\tescape"));
            }
            var i = 0;

            foreach (var et in allEscapeTests)
            {
                testValues.Add(new StringTestValue("with escapes " + i++, et.Value, et.Encoding));
            }
            var ret = new List <ValueTest <T> >();

            foreach (var tv in testValues)
            {
                ret.Add(new ValueTest <T>
                {
                    Name  = "string " + tv.Name,
                    Value = new TestValue <T>
                    {
                        Type        = ValueType.String,
                        StringValue = tv.Value
                    },
                    Encoding = '"' + tv.Encoding + '"'
                });
            }
            return(ret);
        }
Пример #15
0
 public virtual void CollidePlatform(PlatformBehavior pb)
 {
 }
Пример #16
0
 void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.tag == "Ball")
     {
         GameControl      gc       = GameObject.Find("GameControl").GetComponent <GameControl>();
         PlatformBehavior platform = player.GetComponent <PlatformBehavior>();
         if (!GameData.FriendlyFire && collider.gameObject.GetComponent <BallBehavior>().lastPlayer == player)
         {
             gc.SpawnBall();
             return;
         }
         Debug.Log("Killing player " + player.name);
         audioSource.PlayOneShot(GameData.S_DeathSound);
         col.isTrigger             = false;
         collider.gameObject.layer = 8;
         sr.material = dead;
         if (platform.Horizontal)
         {
             player.GetComponent <HorizontalPlatformMovement>().Speed = 0;
         }
         else
         {
             player.GetComponent <VerticalPlatformMovement>().Speed = 0;
         }
         player.GetComponent <BoxCollider2D>().enabled = false;
         gc.players.Remove(player);
         BallBehavior bb = collider.gameObject.GetComponent <BallBehavior>();
         if (bb.lastPlayer != null)
         {
             PlatformBehavior   pb  = bb.lastPlayer.GetComponent <PlatformBehavior>();
             PlayerCardBehavior pcb = pb.playerCard.GetComponent <PlayerCardBehavior>();
             pcb.KillCountUpdate(1);
             pcb.BallCountUpdate(-1);
         }
         platform.CancelInvoke("Bored");
         if (platform.PostDeathControl)
         {
             if (gc.Flaps.Exists(x => !x.GetComponent <Flap>().taken))
             {
                 Flap f = gc.Flaps.First(x => !x.taken);
                 f.taken = true;
                 f.AssignPlayer(player.GetComponent <BasePlatformMovement>(), true);
             }
             if (gc.Flaps.Count > 3 && gc.Flaps.Exists(x => !x.GetComponent <Flap>().taken))
             {
                 Flap f = gc.Flaps.First(x => !x.taken);
                 f.taken = true;
                 f.AssignPlayer(player.GetComponent <BasePlatformMovement>(), false);
             }
         }
         string[] anims = platform.deathAnims;
         player.GetComponent <Animator>().Play(anims[Random.Range(0, anims.Length)], 0);
         foreach (GameObject ball in gc.balls)
         {
             ball.GetComponent <Rigidbody2D>().velocity *= gc.SpeedUpOnKill;
         }
         if (gc.players.Where(x => x.activeSelf).Count() == 1)
         {
             gc.Winner(gc.players[0]);
         }
     }
 }
Пример #17
0
 public void FlagForRespawn(PlatformBehavior platform)
 {
     platform.transform.position += Vector3.right * canvasWidth;
 }
    void Update()
    {
        debugFrameCount++;

        // don't process the game if the world is still being instantiated.
        if (worldGenerator.isBusy())
        {
            return;
        }

        if (playerRef != null)
        {
            // always set the camera on top of the player.
            cameraRef.transform.position = new Vector3(playerRef.position.x, playerRef.position.y, transform.position.z - 50);
        }

        // if you are adding a platform...
        // cancels when you click on nothing or when you right click.

        Vector3 mousePointInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        mousePointInWorld.z = 0;
        // add platform system
        if (addingPlatforms && platformsToAdd.Count > 0)
        {
            PlatformBehavior platformToPreviewForAdd = platformsToAdd[0];  // show a preview of the platform.
            platformToPreviewForAdd.GetComponent <ContainerEntityBehavior>().refreshChildList();
            platformToPreviewForAdd.renderAsFadedPreview();
            platformToPreviewForAdd.setValueBlockText("" + platformToPreviewForAdd.getValue());
            platformToPreviewForAdd.transform.position = mousePointInWorld;
            platformToPreviewForAdd.gameObject.SetActive(true);
            platformToPreviewForAdd.GetComponent <BoxCollider2D>().isTrigger = true;

            if ((Input.GetMouseButtonDown(1) || Input.GetKeyDown(KeyCode.Escape)) && hoverLink == null) // deselecting with right click?
            {
                addingPlatforms = false;
                platformToPreviewForAdd.gameObject.SetActive(false);
                if (selectedLink != null)  // deselect on canceling placement.
                {
                    selectedLink.setPreviewConnection(null);
                    selectedLink.setState(LinkBehavior.State.NORMAL);
                    selectedLink = null;
                }
            }
            else if (selectedLink != null && Input.GetMouseButton(0)) // dragging from a link.
            {
                selectedLink.setPreviewConnection(platformToPreviewForAdd.GetComponent <ConnectableEntityBehavior>());
                selectedLink.UpdateRendering();
            }
            else if (selectedLink != null && Input.GetMouseButtonUp(0)) // release to finish adding platform,
            {
                platformsToAdd.Remove(platformToPreviewForAdd);
                platformToPreviewForAdd.transform.position = mousePointInWorld;
                platformToPreviewForAdd.gameObject.SetActive(true);
                platformToPreviewForAdd.GetComponent <BoxCollider2D>().isTrigger = false;
                platformToPreviewForAdd.isInLevel = true;                                                         // set as being added to the level.
                platformToPreviewForAdd.GetComponent <ContainerEntityBehavior>().refreshChildList();
                selectedLink.setConnectionTo(platformToPreviewForAdd.GetComponent <ConnectableEntityBehavior>()); // connect the selected link to the new platform
                platformToPreviewForAdd.updateRenderAndState();                                                   // force rendering update.
                addingPlatforms = false;
                codePanelBehavior.appendCodeText(selectedLink.getVariableName() + " = new Node();");              // append code to the generated code window.

                string actMsg = "Platform is added from link " + selectedLink.GetComponent <LoggableBehavior>().getLogID() + " at (" + mousePointInWorld.x + ", " + mousePointInWorld.y + ")";
                loggingManager.sendLogToServer(actMsg);

                selectedLink.setPreviewConnection(null);
                selectedLink.setState(LinkBehavior.State.NORMAL);
                selectedLink = null;                                     // deselect.

                hudBehavior.setPlatformsToAddText(platformsToAdd.Count); // update UI
                updateObjectiveHUDAndBlocks();
                updatePlatformEntities();
            }
        } // end addingPlatforms block


        if (!Input.GetMouseButtonDown(0) && !Input.GetMouseButtonDown(0)) // the state of clicking has not changed this frame.
        {
            hoverLink = null;                                             // to make sure it is properly updated this next frame.
        }
        // if it is a hover link and the mouse is released, then check to establish a connection.
        mousePointInWorld.z = 0;
        for (int i = 0; i < worldGenerator.levelLinks.Count; i++)
        {
            LinkBehavior lb = worldGenerator.levelLinks[i];
            if (lb.selectable)
            {
                if (lb.isPointInside(mousePointInWorld))
                {
                    if (lb.state == LinkBehavior.State.NORMAL)
                    {
                        hoverLink = lb;
                        lb.setState(LinkBehavior.State.HOVER);
                        if (selectedLink != null && hoverLink.connectableEntity != null)
                        {
                            selectedLink.setPreviewConnection(hoverLink.connectableEntity); // preview the connection if there is a select link.
                            selectedLink.UpdateRendering();
                        }
                    }

                    if (Input.GetMouseButtonDown(0)) // if the link is just being clicked.
                    {
                        if (lb.state == LinkBehavior.State.SELECTED)
                        {
                            // if the link being clicked is selected
                            if (getMsSinceLastClick() < doubleClickDelay)
                            {
                                lb.setConnectionTo(null); // remove connection on double click
                                lb.setPreviewConnection(null);
                                lb.UpdateRendering();
                                codePanelBehavior.appendCodeText(lb.getVariableName() + " = null;");
                                updatePlatformEntities(); // changing links - update platforms
                                updateObjectiveHUDAndBlocks();
                            }
                        }
                        else // clicking on a link that is NOT selected
                        {
                            selectedLink = lb;
                            lb.setState(LinkBehavior.State.SELECTED);
                            if (hoverLink == selectedLink)
                            {
                                hoverLink.setPreviewConnection(null);
                                hoverLink.UpdateRendering();
                                hoverLink = null; // hover link can't be the same as selected link.
                            }
                        }
                    }
                    else if (Input.GetMouseButtonUp(0))                                                         // if the mouse is being released over this link
                    {
                        if (lb.state == LinkBehavior.State.HOVER && selectedLink != null && selectedLink != lb) // if there IS a selected link. establish link.
                        {
                            selectedLink.setConnectionEqualTo(ref lb);
                            codePanelBehavior.appendCodeText(selectedLink.getVariableName() + " = " + lb.getVariableName() + ";");
                            selectedLink.setPreviewConnection(null);
                            selectedLink.setState(LinkBehavior.State.NORMAL);
                            lb.UpdateRendering();
                            updatePlatformEntities(); // changing links - update platforms
                            updateObjectiveHUDAndBlocks();
                        }
                    }
                }
                else
                { // mouse is NOT over link block
                    if (lb.state == LinkBehavior.State.HOVER)
                    {
                        lb.setState(LinkBehavior.State.NORMAL); // no longer a hover block.
                    }
                    else if (lb.state == LinkBehavior.State.SELECTED && !Input.GetMouseButton(0))
                    {
                        lb.setState(LinkBehavior.State.NORMAL); // no longer the selected block
                        lb.setPreviewConnection(null);          // no preview
                        lb.UpdateRendering();
                    }
                }
            }
            else
            {
                if (lb.state != LinkBehavior.State.NORMAL)
                {
                    lb.setState(LinkBehavior.State.NORMAL);
                }
            }
        } // end iterating through links.

        // validate the selected link
        if (selectedLink != null && selectedLink.state != LinkBehavior.State.SELECTED)
        {
            selectedLink = null;
        }
        // validate the hover link
        if (hoverLink != null && hoverLink.state != LinkBehavior.State.HOVER)
        {
            hoverLink = null;
        }


        // record the last time that the mouse clicked for double clicking
        if (Input.GetMouseButton(0))
        {
            lastTimeClickedMillis = System.DateTime.Now;
        }
    }
Пример #19
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("START");
        audioSource = GetComponent <AudioSource>();
        if (audioSource == null)
        {
            audioSource = gameObject.AddComponent <AudioSource>();
        }
        audioSource.outputAudioMixerGroup = GameData.S_MainMixer;

        UI         = GameObject.Find("UI");
        es         = UI.transform.Find("EventSystem").GetComponent <EventSystem>();
        PauseGroup = UI.transform.Find("Canvas").Find("Pause").gameObject;
        PauseGroup.transform.Find("Continue").GetComponent <Button>().onClick.AddListener(PauseContinueButton);
        PauseGroup.transform.Find("Quit").GetComponent <Button>().onClick.AddListener(PauseQuitButton);

        MatTransparent = Resources.Load <Material>("Transparent");
        MatDefault     = Resources.Load <Material>("Default");
        if (!GameData.S_DisplayFPS)
        {
            GameObject.Find("FPS").SetActive(false);
        }
        else
        {
            FPSCounter = GameObject.Find("FPS").GetComponent <Text>();
        }
        if (!GetComponent <GameData>().Debug)
        {
            endDelay   = GameData.S_EndDelay;
            startDelay = GameData.S_StartDelay;
        }
        Random.InitState(System.DateTime.Now.Millisecond);
        for (int i = 0; i < players.Count; ++i)
        {
            PlatformBehavior     pb  = players[i].GetComponent <PlatformBehavior>();
            DeathBarrierBehavior dbb = pb.deathBarrier.GetComponent <DeathBarrierBehavior>();

            if (i == GameData.AIs.Length)
            {
                for (; i < players.Count; ++i)
                {
                    pb  = players[i].GetComponent <PlatformBehavior>();
                    dbb = pb.deathBarrier.GetComponent <DeathBarrierBehavior>();
                    Debug.Log(dbb.name + "'s player is inactive, deactivating.");
                    dbb.Destroyed = true;
                    dbb.GetComponent <SpriteRenderer>().material = dbb.dead;
                    pb.playerCard.SetActive(false);
                    players[i].SetActive(false);
                }
                break;
            }
            if (GameData.PlayerWins.Count < GameData.AIs.Count())
            {
                GameData.PlayerWins.Add(players[i].name, 0);
            }
            if (GameData.AIs[i])
            {
                pb.AI = true;
                players[i].GetComponent <BasePlatformMovement>().Speed = 0;
                pb.AISpeed          = GameData.S_AISpeed;
                pb.PostDeathControl = false;
            }
            else
            {
                pb.AI = false;
                pb.PostDeathControl = true;
            }
            pb.InvokeRepeating("Bored", 0, pb.BoredCountRate);

            Vector2    pos     = new Vector2(players[i].transform.position.x * ballStartOffset, players[i].transform.position.y * ballStartOffset);
            GameObject ball    = Instantiate(ballObject, new Vector3(pos.x, pos.y, 0), Quaternion.identity);
            Vector2    initDir = new Vector2(players[i].transform.position.x - ball.transform.position.x, players[i].transform.position.y - ball.transform.position.y);
            if (pb.Horizontal)
            {
                initDir.x += Random.Range(-ballStartRandomRange, ballStartRandomRange);
            }
            else
            {
                initDir.y += Random.Range(-ballStartRandomRange, ballStartRandomRange);
            }
            ball.GetComponent <Rigidbody2D>().velocity = initDir.normalized * startSpeed;
            ball.GetComponent <BallBehavior>().StartCoroutine(ball.GetComponent <BallBehavior>().Freeze(startDelay, players[i].transform));
            balls.Add(ball);
            players[i].GetComponent <BasePlatformMovement>().Boundary      = PlatformBoundaryStart;
            pb.playerCard.transform.Find("Win").GetComponent <Text>().text = "Wins: " + GameData.PlayerWins[players[i].name];

            pb.SetScore(GameData.PlayerWins[pb.name]);
        }
        foreach (KeyValuePair <string, int> pair in GameData.PlayerWins)
        {
            Debug.Log(pair.Key + ": " + pair.Value);
        }
        StartCoroutine(LateStart());
    }