Ejemplo n.º 1
0
 private static void PersistEnemyHealth(HealthPool oldHealth, HealthPool newHealth)
 {
     if (oldHealth.Health < oldHealth.MaxHealth)
     {
         newHealth.Damage(oldHealth.MaxHealth - oldHealth.Health);
     }
 }
    void updatePushingPlayers(bool pvMine)
    {
        teamCaptains.Clear();
        int count = detectionColl.Cast(Vector2.zero, rch2ds, 0, true);

        for (int i = 0; i < count; i++)
        {
            RaycastHit2D rch2d = rch2ds[i];
            GameObject   rchGO = rch2d.collider.gameObject;
            if (rchGO.CompareTag("Player"))
            {
                TeamToken  tt         = TeamToken.getTeamToken(rchGO);
                HealthPool healthPool = rchGO.GetComponentInChildren <HealthPool>();
                if (healthPool)
                {
                    if (!teamCaptains.ContainsKey(tt.teamCaptain))
                    {
                        teamCaptains.Add(tt.teamCaptain, 0);
                    }
                    float amount = healthPool.Health;
                    //Add in distance to caravan
                    float distance           = (rchGO.transform.position - transform.position).magnitude;
                    float distanceMultiplier = 1 + ((maxAllowedDistance - distance) / maxAllowedDistance);
                    //Update team captains dict
                    teamCaptains[tt.teamCaptain] += amount * distanceMultiplier;
                }
            }
        }
        updateDirection(pvMine);
    }
    // *****************************************************************************************************************


    // *****************************************************************************************************************
    #region private Functions
    // *****************************************************************************************************************
    private void AttemptHeal(Collider2D _other)
    {
        // Get the health pool from our collided object
        HealthPool healthPool = _other.GetComponent <HealthPool>();

        // If it had a health pool...
        if (healthPool != null)
        {
            // Heal it by the amount set
            bool healed = healthPool.Heal(m_healing, m_targetType);

            // if we did in fact heal....
            if (healed)
            {
                // If we should destroy this object, do so
                if (m_destroyOnCollect)
                {
                    Destroy(gameObject);
                }

                // If we have a sound to play, play it
                if (m_collectSound)
                {
                    // Play the sound for collecting at this locaiton
                    AudioSource.PlayClipAtPoint(m_collectSound, transform.position);
                }
            }
        }
    }
Ejemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        healthPool         = GetComponent <HealthPool>();
        teamTokenCaptain   = GetComponent <TeamTokenCaptain>();
        healthPool.onDied += checkGameOver;
        //Team Token Captains
        teamCaptains = FindObjectsOfType <TeamTokenCaptain>().ToList();
        //Text Map Name
        txtMapName = gameObject.FindComponent <TMP_Text>();
        MapGenerator mapGenerator = FindObjectOfType <MapGenerator>();

        txtMapName.text = mapGenerator.mapName;
        mapGenerator.onMapNameChanged += (mapName) => txtMapName.text = mapName;
        //Marker
        MapMarker mapMarker = MapMarkerManager.CreateMapMarker(
            PhotonView.Get(gameObject),
            transform.position,
            flagMarkerInfo
            );
        GameObject balloons = Instantiate(flagMarkerBalloonPrefab);

        balloons.transform.parent        = mapMarker.iconSR.transform;
        balloons.transform.localPosition = Vector2.zero;
        balloons.GetComponent <FlagMapMarkerDisplay>().Init(this);
    }
Ejemplo n.º 5
0
 private void Start()
 {
     capsuleCollider = GetComponent <CapsuleCollider2D>();
     circleCollider  = gameObject.transform.Find("ActorBase").GetComponent <CircleCollider2D>();
     actor           = gameObject;
     healthPool      = actor.GetComponent <HealthPool>();
     animator        = gameObject.GetComponent <Animator>();
     spriteRenderer  = gameObject.GetComponent <SpriteRenderer>();
 }
    // Start is called before the first frame update
    void Start()
    {
        int sortingOrder = GetComponentInParent <SpriteRenderer>().sortingOrder + 1;

        gameObject.FindComponents <SpriteRenderer>(true)
        .ForEach(sr => sr.sortingOrder = sortingOrder);
        healthPool            = gameObject.FindComponent <HealthPool>();
        healthPool.onDamaged += checkOnDamaged;
    }
Ejemplo n.º 7
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            right       = new RightGame(graphics, spriteBatch, this);
            right.LoadContent();
            left = new LeftGame(graphics, spriteBatch, this);
            left.LoadContent();
            title                = Content.Load <Texture2D>("Title");
            hp                   = new HealthPool(Content.Load <Texture2D>("Heart"), Content.Load <SoundEffect>("GameSounds/playerdamage"), this, 42, 36, 10);
            switchTexture        = Content.Load <Texture2D>("Switcharoo");
            switchTexturePrime   = Content.Load <Texture2D>("SwitcharooSwitch");
            reverseTexture       = Content.Load <Texture2D>("Reversearoo");
            swapTexture          = Content.Load <Texture2D>("Swaparoo");
            timerFont            = Content.Load <SpriteFont>("timerSpritefont");
            fade                 = Content.Load <Texture2D>("Fade");
            pause                = Content.Load <Texture2D>("Pause");
            progress             = Content.Load <Texture2D>("Progress");
            emptyProgressCirle   = Content.Load <Texture2D>("UnfilledCircle");
            filledProgressCircle = Content.Load <Texture2D>("FilledCircle");
            explosionSound       = Content.Load <SoundEffect>("GameSounds/Explosion");
            bossMarker           = Content.Load <Texture2D>("BossLabel");
            gameOverBG1          = Content.Load <Texture2D>("GameOverBG");
            countDown            = new Texture2D[3];
            countDown[0]         = Content.Load <Texture2D>("1");
            countDown[1]         = Content.Load <Texture2D>("2");
            countDown[2]         = Content.Load <Texture2D>("3");
            Texture2D  buttonTexture = Content.Load <Texture2D>("Button");
            SpriteFont buttonFont    = Content.Load <SpriteFont>("ButtonFont");

            gameOverFont = Content.Load <SpriteFont>("GameOverSpritefont");
            gameOverMes  = gameOverFont.MeasureString("Game Over");
            instructions = Content.Load <Texture2D>("Instructions");
            SoundEffect buttonClick = Content.Load <SoundEffect>("GameSounds/click");

            victoryExplosion              = Content.Load <Texture2D>("DeadBoss");
            mainMenuPlay                  = new Button(buttonTexture, WIDTH / 2 - 400 / 2, 325, 400, 150, buttonClick, buttonFont, "Play");
            mainMenuPlay.OnClick         += MainMenuPlayClick;
            mainMenuExit                  = new Button(buttonTexture, WIDTH / 2 - 400 / 2, 675, 400, 150, buttonClick, buttonFont, "Exit");
            mainMenuExit.OnClick         += () => { Exit(); };
            mainMenuInstructions          = new Button(buttonTexture, WIDTH / 2 - 400 / 2, 500, 400, 150, buttonClick, buttonFont, "Instructions");
            mainMenuInstructions.OnClick += () => { gameState = GameState.InstructionMenu; };
            pauseMenuResume               = new Button(buttonTexture, WIDTH / 2 - 400 / 2, 325, 400, 200, buttonClick, buttonFont, "Play");
            pauseMenuResume.OnClick      += PauseMenuResumeClick;
            pauseMenuMainMenu             = new Button(buttonTexture, WIDTH / 2 - 400 / 2, 600, 400, 200, buttonClick, buttonFont, "Main Menu");
            pauseMenuMainMenu.OnClick    += () => { gameState = GameState.MainMenu; };
            instructionMainMenu           = new Button(buttonTexture, WIDTH - 315, HEIGHT - 140, 250, 100, buttonClick, buttonFont, "Main Menu");
            instructionMainMenu.OnClick  += () => { gameState = GameState.MainMenu; };
            gameOverExit                  = new Button(buttonTexture, WIDTH - 300 - 50, HEIGHT - 150 - 50, 300, 150, buttonClick, buttonFont, "Exit");
            gameOverExit.OnClick         += () => { Exit(); };
            gameOverPlayAgain             = new Button(buttonTexture, WIDTH / 2 - 300 / 2, HEIGHT - 150 - 50, 300, 150, buttonClick, buttonFont, "Play Again");
            gameOverPlayAgain.OnClick    += () => { gameState = GameState.Game; };
            gameOverMainMenu              = new Button(buttonTexture, 100 / 2, HEIGHT - 150 - 50, 300, 150, buttonClick, buttonFont, "Main Menu");
            gameOverMainMenu.OnClick     += () => { gameState = GameState.MainMenu; };
            switcharooSound               = Content.Load <SoundEffect>("GameSounds/switcharoo");
            gameOverSound                 = Content.Load <SoundEffect>("GameSounds/lose");
        }
    void addOnHitFlash(HealthPool hp)
    {
        int indexOffset = 1;

        if (hasOnDieDestroy(hp))
        {
            indexOffset++;
        }
        addComponent <OnHitFlash>(hp, indexOffset);
    }
Ejemplo n.º 9
0
    // *****************************************************************************************************************
    // When a collision interaction starts involving this game object...
    void OnCollisionEnter2D(Collision2D _collision)
    {
        // Check if the other collider that we hit has a HealthPool on it
        HealthPool healthPool = _collision.collider.GetComponent <HealthPool>();

        if (healthPool != null)
        {
            // Apply damage to the health pool
            healthPool.Damage(m_damage, m_targetType);
        }
    }
 void checkCollision(GameObject go)
 {
     if (friendlyHit || !TeamToken.onSameTeam(gameObject, go))
     {
         HealthPool hp = go.FindComponent <HealthPool>();
         if (hp && entityTypes.Contains(hp.entityType))
         {
             takeDamage();
         }
     }
 }
Ejemplo n.º 11
0
 void checkCollisionWithObject(GameObject other)
 {
     if (other != owner)
     {
         HealthPool hp = other.GetComponent <HealthPool>();
         if (hp)
         {
             hp.HP -= (int)damage;
             Destroy(gameObject);
         }
     }
 }
Ejemplo n.º 12
0
    void explode()
    {
        List <Rigidbody2D> rb2ds = new List <Rigidbody2D>();

        RaycastHit2D[] rch2ds = Physics2D.CircleCastAll(transform.position, explodeRange, Vector2.zero);
        for (int i = 0; i < rch2ds.Length; i++)
        {
            Rigidbody2D rb2d = rch2ds[i].rigidbody;
            if (!rb2d)
            {
                continue;
            }
            if (!rb2ds.Contains(rb2d))
            {
                rb2ds.Add(rb2d);
            }
        }
        foreach (Rigidbody2D rb2d in rb2ds)
        {
            HealthPool hp = rb2d.gameObject.FindComponent <HealthPool>();
            if (hp && entityTypes.Contains(hp.entityType))
            {
                Vector2 explodeDir    = (rb2d.transform.position - transform.position).normalized;
                Vector2 explodeVector = explodeDir * explodePower;
                rb2d.velocity = explodeVector;
                //PlayerMovement
                PlayerMovement playerMovement = rb2d.gameObject.FindComponent <PlayerMovement>();
                if (playerMovement)
                {
                    //TODO: refactor this once MovementLayer has been implemented
                    float speed = explodePower / playerMovement.MovementSpeed;
                    playerMovement.forceMovement(explodeVector, true);
                    int       viewID    = gameObject.FindComponent <PhotonView>().ViewID;
                    StatLayer statLayer = new StatLayer(StatLayer.STAT_IGNORE)
                    {
                        moveSpeed = speed
                    };
                    StatKeeper statKeeper = playerMovement.gameObject.FindComponent <StatKeeper>();
                    statKeeper.selfStats.addLayer(viewID, statLayer);
                    TimerManager.StartTimer(forceMoveDuration, () =>
                    {
                        playerMovement.forceMovement(false);
                        statKeeper.selfStats.removeLayer(viewID);
                    });
                }
            }
        }
    }
Ejemplo n.º 13
0
 // Start is called before the first frame update
 void Start()
 {
     PV                 = GetComponent <PhotonView>();
     healthPool         = GetComponent <HealthPool>();
     healthPool.onDied += (hp) =>
     {
         if (PV.IsMine)
         {
             PhotonNetwork.Destroy(this.gameObject);
         }
         else
         {
             Destroy(this.gameObject);
         }
     };
 }
    void addStaticRB2D(HealthPool hp)
    {
        int indexOffset = 1;

        if (hasOnDieDestroy(hp))
        {
            indexOffset++;
        }
        if (hasOnHitFlash(hp))
        {
            indexOffset++;
        }
        Rigidbody2D rb2d = addComponent <Rigidbody2D>(hp, indexOffset);

        //Make it static
        rb2d.bodyType = RigidbodyType2D.Static;
    }
    T addComponent <T>(HealthPool hp, int indexOffset = 1) where T : Component
    {
        T comp = hp.gameObject.AddComponent <T>();
        //Component reordering copied from:
        //2021-11-23: http://answers.unity.com/answers/1080266/view.html
        //2021-11-23: https://forum.unity.com/threads/component-index-guarantee.770501/#post-5130215
        List <Component> compList = hp.GetComponents <Component>().ToList();
        int hpIndex   = compList.IndexOf(hp);
        int compIndex = compList.IndexOf(comp);

        while (compIndex > hpIndex + indexOffset)
        {
            UnityEditorInternal.ComponentUtility.MoveComponentUp(comp);
            compIndex = comp.GetComponents <Component>().ToList().IndexOf(comp);
        }
        UnityEditorInternal.InternalEditorUtility.SetIsInspectorExpanded(comp, false);
        return(comp);
    }
    protected override void processCollision(Collider2D collision, bool useInitialDamage)
    {
        base.processCollision(collision, useInitialDamage);
        if (TeamToken.onSameTeam(gameObject, collision.gameObject))
        {
            //don't trap teammates
            return;
        }
        HealthPool hp = collision.gameObject.FindComponent <HealthPool>();

        if (hp)
        {
            if (trapTypes.Contains(hp.entityType))
            {
                //TODO: enable trapping other types
                trapPlayer(hp.gameObject.FindComponent <PlayerController>());
            }
        }
    }
Ejemplo n.º 17
0
    private void ChangeToPresent(GameObject shot, Vector2 pos, Vector2 dir)
    {
        //Only change the shots, not the constructs
        HealthPool healthPool = shot.FindComponent <HealthPool>();

        if (healthPool && healthPool.entityType == EntityType.SHOT)
        {
            shot.FindComponent <SpriteRenderer>().sprite = shotSprite;
            OnHitGiveAmina ohga = shot.AddComponent <OnHitGiveAmina>();
            ohga.aminaToGive = this.aminaToGive;
        }
        //Propagate spawning presents even further
        ObjectSpawner os = shot.FindComponent <ObjectSpawner>();

        if (os)
        {
            os.onObjectSpawned += ChangeToPresent;
        }
    }
Ejemplo n.º 18
0
    //private void OnCollisionStay2D(Collision2D collision)
    //{
    //    processCollision(collision.collider, false);
    //}

    public void processCollision(Collider2D collision, bool useInitialDamage)
    {
        if (!damageFriendlies && TeamToken.onSameTeam(gameObject, collision.gameObject))
        {
            //don't damage teammates
            return;
        }
        HealthPool hp = collision.gameObject.GetComponent <HealthPool>();

        if (hp)
        {
            if (damagableTypes.Contains(hp.entityType))
            {
                if (useInitialDamage)
                {
                    hp.Health += -damage;
                    onDealtDamage?.Invoke(damage, hp);
                }
            }
        }
    }
    protected override void processCollision(Collider2D collision, bool useInitialDamage)
    {
        //If it's a flag, don't teleport it
        Rigidbody2D rb2d = collision.gameObject.FindComponent <Rigidbody2D>();

        if (rb2d && rb2d.gameObject.CompareTag("TeamFlag"))
        {
            return;
        }
        //If it is destroyable,
        HealthPool hp = collision.gameObject.FindComponent <HealthPool>();

        if (hp)
        {
            //It doesn't matter what it is, teleport it
            Vector2 teleportPos = Utility.MouseWorldPos;
            //Check if it's a Unicorn using Rainbow Path
            UnicornController unicorn = collision.gameObject.FindComponent <UnicornController>();
            if (unicorn)
            {
                unicorn.redirectPath(teleportPos);
            }
            //Teleport like usual
            Utility.teleportObject(hp.gameObject, teleportPos);
            //If it's a WeaponController (like the weapons from Astral)
            WeaponController weapon = collision.gameObject.FindComponent <WeaponController>();
            if (weapon)
            {
                //Make it unowned
                weapon.Controller = null;
            }
            //and then destroy this shot
            health.Health = 0;
        }
        else if (!collision.isTrigger)
        {
            //Destroy this shot if object is destroyable
            health.Health = 0;
        }
    }
 private void Start()
 {
     healthPool = gameObject.FindComponent <HealthPool>();
 }
Ejemplo n.º 21
0
 public void Damage(GameObject?attacker, double amount)
 {
     HealthPool.Damage(amount);
     LastDamagedBy = attacker;
     OnDamage(attacker, amount);
 }
Ejemplo n.º 22
0
 private void Kill(HealthPool healthPool)
 {
     OnKill();
 }
Ejemplo n.º 23
0
 public Actor(Region region, Vector3 <decimal> position, Team team, double health) : base(region, position)
 {
     CollisionHull        = new CollisionHull(this, team);
     HealthPool           = new HealthPool(this, health);
     HealthPool.Depleted += Kill;
 }
 bool hasRB2D(HealthPool hp) => hasComponent <Rigidbody2D>(hp);
Ejemplo n.º 25
0
    private PreviewDisplayer.PreviewState getPreviewState(Vector2 position)
    {
        preview.transform.position = position + ChargedShotSpawnInfo.spawnOffset;
        preview.transform.up       = Vector2.up;
        previewDisplayer.updatePreviewSprite();
        GameObject conflictingObject = null;
        bool       coHasSC           = false;

        if (previewCollider)
        {
            RaycastHit2D[] rch2ds = new RaycastHit2D[10];
            int            count  = previewCollider.Cast(Vector2.zero, rch2ds, 0, false);
            for (int i = 0; i < count; i++)
            {
                RaycastHit2D rch2d  = rch2ds[i];
                Collider2D   coll2d = rch2d.collider;
                GameObject   rchGO  = coll2d.gameObject;
                HealthPool   hp     = rchGO.FindComponent <HealthPool>();
                //If the conflicting object is a regular moving shot,
                if (hp && hp.entityType == EntityType.SHOT)
                {
                    //You can build here anyway
                    continue;
                }
                //If the conflicting object is not solid,
                else if (coll2d.isTrigger)
                {
                    //You can build here anyway
                    continue;
                }
                //If the conflicting object is non-moving or is not a shot,
                else
                {
                    //Double-check to make sure the sprites overlap
                    SpriteRenderer coSR    = rchGO.FindComponent <SpriteRenderer>();
                    bool           overlap = previewDisplayer.boundsIntersects(coSR.bounds);
                    if (overlap)
                    {
                        //it's conflicting
                        conflictingObject = rchGO;
                        coHasSC           = rchGO.FindComponent <ShotController>();
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
        if (!conflictingObject && upgradeRange > 0)
        {
            RaycastHit2D[] rch2ds = Physics2D.CircleCastAll(
                position,
                upgradeRange,
                Vector2.zero
                );
            for (int i = 0; i < rch2ds.Length; i++)
            {
                RaycastHit2D rch2d  = rch2ds[i];
                Collider2D   coll2d = rch2d.collider;
                GameObject   rchGO  = coll2d.gameObject;
                HealthPool   hp     = rchGO.FindComponent <HealthPool>();
                //If the conflicting object is a regular moving shot,
                if (hp && hp.entityType == EntityType.SHOT)
                {
                    //You can build here anyway
                    continue;
                }
                //If the conflicting object is not solid,
                else if (coll2d.isTrigger)
                {
                    //You can build here anyway
                    continue;
                }
                //If the conflicting object is non-moving or is not a shot,
                else
                {
                    //If the object is upgradable
                    if (rchGO.name.Contains(ChargedShotSpawnInfo.objectName))
                    {
                        //it's conflicting
                        conflictingObject = rchGO;
                        coHasSC           = rchGO.FindComponent <ShotController>();
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
        if (conflictingObject)
        {
            //If this player owns the conflicting object,
            if (TeamToken.ownedBySamePlayer(gameObject, conflictingObject))
            {
                //if they're the same type,
                if (conflictingObject.name.Contains(ChargedShotSpawnInfo.objectName))
                {
                    //upgrade the one there
                    targetObject = conflictingObject;
                    preview.transform.position = conflictingObject.transform.position;
                    preview.transform.up       = conflictingObject.transform.up;
                    return(PreviewDisplayer.PreviewState.UPGRADE);
                }
                //else if they're not the same type,
                //but still both constructs
                else if (coHasSC)
                {
                    ChargedShotController csc = conflictingObject.FindComponent <ChargedShotController>();
                    Sprite conflictingSprite  = csc.previewSprite;
                    //delete the object already there
                    targetObject = conflictingObject;
                    preview.transform.position = conflictingObject.transform.position;
                    preview.transform.up       = conflictingObject.transform.up;
                    previewDisplayer.updatePreviewSprite(conflictingSprite);
                    return(PreviewDisplayer.PreviewState.DESTROY);
                }
            }
            return(PreviewDisplayer.PreviewState.NONE);
        }
        else
        {
            targetObject = null;
        }
        if (aminaPool.ReservedAmina < minAminaReserved)
        {
            return(PreviewDisplayer.PreviewState.NONE);
        }
        return(PreviewDisplayer.PreviewState.BUILD);
    }
 bool hasOnHitFlash(HealthPool hp) => hasComponent <OnHitFlash>(hp);
 void addOnDieDestroy(HealthPool hp) => addComponent <OnDieDestroy>(hp);
Ejemplo n.º 28
0
 // Start is called before the first frame update
 void Start()
 {
     healthPool         = gameObject.FindComponent <HealthPool>();
     healthPool.onDied += (hp) => explode();
 }
 bool hasOnDieDestroy(HealthPool hp) => hasComponent <OnDieDestroy>(hp);
    bool hasComponent <T>(HealthPool hp) where T : Component
    {
        T comp = hp.GetComponent <T>();

        return(comp);
    }