Ejemplo n.º 1
0
    // Adds a player to the canvas.
    public void AddPlayer(int id, Player player)
    {
        // Create a new instance of our player overlay prefab - this uses the
        // same sprite as the player but has no movement attached.
        PlayerOverlay newObj = Instantiate(playerOverlay);

        // Set the object name and sprite color
        newObj.name = "Player Overlay for Player " + id;
        newObj.GetComponent <Image>().color = player.color;

        // Move the object into the Canvas.
        newObj.transform.SetParent(transform);

        // Bind the new object to the player ID.
        newObj.player = player;
        overlays[id]  = newObj;

        // Sort the player overlays: for each child object with a PlayerOverlay script, set its
        // index in the player list equal to the player ID - 1.
        // Note: sort the child objects by name first, as Transform iteration doesn't have a
        // guaranteed order: http://answers.unity3d.com/questions/276230/
        foreach (Transform child in transform.Cast <Transform>().OrderBy(t => t.name))
        {
            PlayerOverlay overlay = child.gameObject.GetComponent <PlayerOverlay>();
            if (overlay != null)
            {
                Debug.Log(string.Format("PlayerList: sorting PlayerOverlay {0} to position {0}", overlay.player.playerID - 1));
                child.SetSiblingIndex(overlay.player.playerID - 1);
            }
        }
        playerListLabel.transform.SetSiblingIndex(0);
    }
Ejemplo n.º 2
0
    // Initialization: fill in resources and create the player list label
    void Awake()
    {
        playerOverlay = Resources.Load <PlayerOverlay>("PlayerOverlay");

        playerListLabel = Instantiate(GameState.Instance.textLabelTemplate);
        playerListLabel.GetComponent <Text>().text = "Select character: ";
        playerListLabel.transform.SetParent(transform);
    }
Ejemplo n.º 3
0
        public PlayerOverlayMessage(PlayerOverlay HandItemObject)
            : base(MessageTypeGameMode.PlayerOverlay)
        {
            // no "HasLight" allowed... !
            // ...

            this.HandItemObject = HandItemObject;
        }
Ejemplo n.º 4
0
        public override int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            cursor += base.ReadFrom(Buffer, cursor);

            HandItemObject = new PlayerOverlay(Buffer, cursor);
            cursor        += HandItemObject.ByteLength;

            return(cursor - StartIndex);
        }
Ejemplo n.º 5
0
    public override void PlayerHit(Player player)
    {
        // When a player hits the powerup, activate the powerup.
        targetPlayer = player;
        // Apply the effect
        SetEffect();

        // Mark the powerup as used.
        isUsed = true;

        // Disable the renderer to act like the powerup has disappeared.
        // We don't use SetActive(false) or Destroy() because that would turn
        // off the scripts needed for RemoveEffect.
        SpriteRenderer renderer = gameObject.GetComponent <SpriteRenderer>();

        renderer.enabled = false;

        // Show the powerup in the GameState's powerups panel.
        powerupDisplay = new GameObject();
        powerupDisplay.transform.SetParent(GameState.Instance.powerupsPanel.transform);
        Image image = powerupDisplay.AddComponent <Image>();

        // Give the powerup display the same sprite as the current object, and set the size to 48x48.
        image.sprite = renderer.sprite;
        image.rectTransform.sizeDelta = new Vector2(48, 48);
        // Make the overlay colour correspond to the player color.
        image.color = player.color;

        // If the powerup length is > 0, set a timer to remove the timer later.
        if (powerupLength > 0)
        {
            Invoke("RemoveEffect", powerupLength);

            // Add a text box in the powerup display to show the time remaining.
            powerupRemainingTextBox = Instantiate(GameState.Instance.textLabelTemplate, powerupDisplay.transform);
            powerupRemainingTextBox.transform.position = Vector3.zero;
            Text text = powerupRemainingTextBox.GetComponent <Text>();
            text.color     = textColor;
            text.fontStyle = FontStyle.Bold;  // Make the text bold for better readability
        }
        startTime = Time.time;

        // Allow clicking on the powerup display to focus on the player.
        PlayerOverlay po = powerupDisplay.AddComponent <PlayerOverlay>();

        po.player       = player;
        po.copySprite   = false; // Don't overwrite the powerup sprite.
        po.showPlayerID = false; // The player ID text clashes with the "time remaining" display, so turn it off.

        // Disable future collisions.
        Destroy(GetComponent <Collider2D>());
    }
Ejemplo n.º 6
0
        public override void HandleJoystickButtonPressed(JoystickButtonPressedEvent e)
        {
            if (e.Button == JoystickButton.Back)
            {
                SceneManager.Singleton.LoadScene <MainMenu.MainMenu>();
                return;
            }

            if (e.Button == JoystickButton.A)
            {
                if (players[e.JoystickID] == null)
                {
                    this.RemoveElementById(ConnectNotification.ID);

                    var newPlayer = new Player(e.JoystickID);
                    this.players[e.JoystickID]        = newPlayer;
                    newPlayer.CollisionHandler       += this.map.GetMaximumColllisions;
                    newPlayer.BorderCollisionHandler += this.map.GetMapBorderCollisions;
                    this.map.AddEntity(newPlayer);

                    SceneManager.Singleton.LoadScene <CharacterSelection>();
                    var characterSelection = SceneManager.Singleton.CurrentScene as CharacterSelection;
                    characterSelection.EditingPlayer = this.players[e.JoystickID];

                    PlayerOverlay overlay = new PlayerOverlay(newPlayer);
                    this.AddChild(overlay);
                    newPlayer.overlay = overlay;


                    Debug.AddDebugInformation(() => $"Player {e.JoystickID} - X: {(int)newPlayer.Position.X} Y: {(int)newPlayer.Position.Y}");
                    CameraFocus(newPlayer);
                }
            }
            //attack button
            if (e.Button == JoystickButton.B)
            {
            }
        }