Ejemplo n.º 1
0
    void OnCollisionEnter2D(Collision2D CollisionInfo)
    {
        GameObject OtherObj = CollisionInfo.collider.gameObject;

        if (OtherObj != Owner)
        {
            if (OtherObj.tag == "Player")
            {
                GPlayer     PlayerScript = OtherObj.GetComponent <GPlayer>();
                FPlayerInfo PlayerInfo   = PlayerScript.GetPlayerInfo();

                float TotalDamage = PlayerInfo.Health * 0.65f;

                FDamageInfo DamageInfo = new FDamageInfo();
                DamageInfo.DamageDone = TotalDamage;

                PlayerScript.SendMessage("TakeDamage", DamageInfo);

                Destroy(this.gameObject);
            }
            else if (OtherObj.tag == "Environment")
            {
                //TODO::Splash damage
                Destroy(this.gameObject);
            }
        }
    }
Ejemplo n.º 2
0
    void OnGUI()
    {
        if (bInitialized)
        {
            // Draw HealthBars
            for (int PlayerIdx = 0; PlayerIdx < PlayerObjects.Length; ++PlayerIdx)
            {
                Vector3     PlayerPosition     = PlayerObjects[PlayerIdx].transform.position;
                Vector3     PlayerScreenCoords = Camera.main.WorldToScreenPoint(PlayerPosition);
                FPlayerInfo PlayerInfo         = PlayerInfos[PlayerIdx];

                float HealthPercentage = PlayerInfo.Health / 100.0f;
                if (HealthPercentage < 0)
                {
                    HealthPercentage = 0;
                }

                GUI.skin.font = MediumGUIFont;
                GUI.DrawTexture(new Rect(PlayerScreenCoords.x - (HealthBarWidth / 2), (Screen.height - (PlayerScreenCoords.y + 50)), HealthBarWidth * HealthPercentage, HealthBarHeight), Healthbars[PlayerIdx]);
                GUI.Label(new Rect(PlayerScreenCoords.x - (HealthBarWidth / 2) / 2 - 5, Screen.height - (PlayerScreenCoords.y + 58), 50, 25), ((int)PlayerInfo.Health).ToString());

                if (PlayerActions[PlayerIdx].HasGrenade())
                {
                    GUI.DrawTexture(new Rect(PlayerScreenCoords.x + (HealthBarWidth / 2) + 5, (Screen.height - PlayerScreenCoords.y) - (GrenadeTexture.width / 2), GrenadeTexture.width * 0.25f, GrenadeTexture.height * 0.25f), GrenadeTexture, ScaleMode.ScaleToFit);
                }

                /*Player Score Area*/
                FCharacterSelectData[] PlayerData = PersistentData.PlayerData;
                Texture2D PlayerTexture           = PlayerData[PlayerIdx].SelectedCharacterTexture;

                float PlayerTexturePosX = (PlayerIdx == 0) ? PlayerTexture.width : Screen.width - PlayerTexture.width * 2;
                GUI.DrawTexture(new Rect(PlayerTexturePosX, Screen.height - (PlayerTexture.height + 20), PlayerTexture.width, PlayerTexture.height), PlayerTexture);

                float InfoBoxPosX = (PlayerIdx == 0) ? PlayerTexture.width * 2 : Screen.width - (PlayerTexture.width * 6.5f);

                GUI.BeginGroup(new Rect(InfoBoxPosX, Screen.height - (PlayerTexture.height + 10), PlayerScoreBoxWidth, PlayerScoreBoxHeight));
                GUI.Box(new Rect(0, 0, PlayerScoreBoxWidth, PlayerScoreBoxHeight), PlayerData[PlayerIdx].PlayerTitle);

                GUI.Label(new Rect(PlayerScoreBoxWidth / 4, PlayerScoreBoxHeight / 4, PlayerScoreBoxWidth / 2, PlayerScoreBoxHeight / 3), "Score:");
                GUI.Label(new Rect(PlayerScoreBoxWidth / 4 + 20, PlayerScoreBoxHeight / 4 + 20, PlayerScoreBoxWidth / 2, PlayerScoreBoxHeight / 3), PlayerInfo.Score.ToString());

                GUI.EndGroup();
            }
        }
    }
Ejemplo n.º 3
0
    public void Attack(float DamageAmt)
    {
        // Raycast
        Vector3 RayStartPos = transform.position;

        RayStartPos.x += (bFacingRight) ? (PlayerTextureWidth / 2) + 0.25f : -((PlayerTextureWidth / 2) + 0.25f);

        RaycastHit2D Hit2D = Physics2D.Raycast(RayStartPos, (bFacingRight) ? Vector2.right * 10 : Vector2.right * -10);

        if (Hit2D && Hit2D.collider)
        {
            if (Hit2D.distance <= MaxAttackDistance)
            {
                // If we've found a player, call take damage for the attack amount.
                FPlayerInfo PlayerInfo = PlayerScript.GetPlayerInfo();
                GameObject  HitObject  = Hit2D.collider.gameObject;

                float TotalDamage = DamageAmt * (1 - (PlayerInfo.Fatigue / 100.0f));

                HitObject.SendMessage("TakeDamage", TotalDamage);
            }
        }
    }