示例#1
0
    void StartGame()
    {
        var stringPath = HumanPlayerController.TrackedPath.AsString();

        PlayerPrefs.SetString("LatestCampPath", stringPath);
        PlayerPrefs.Save();

        // Init the run data
        var player = PlayableCharacters.GetPlayerInScene();

        CurrentRunData.StartNewRun();
        CurrentRunData.Instance.MaxLife              = player.MaxLife;
        CurrentRunData.Instance.Life                 = player.Life;
        CurrentRunData.Instance.CurrentWeapon        = player.CurrentWeapon.Id;
        CurrentRunData.Instance.BulletAmmo           = 999;
        CurrentRunData.Instance.ShellAmmo            = 999;
        CurrentRunData.Instance.StartingCharacterTag = player.tag;
        CurrentRunData.Instance.HasPlayerData        = true;

        GameProgressData.CurrentProgress.QuestProgress.ApplyAllRewards();
        CurrentRunData.StoreState();

        HumanPlayerController.CanShoot = true;
        SceneManager.LoadScene(EnterPortalSceneName, LoadSceneMode.Single);
    }
示例#2
0
    IEnumerator EnterPortalCo()
    {
        var player = PlayableCharacters.GetPlayerInScene();

        player.SetIsHumanControlled(false, constraints: RigidbodyConstraints2D.None, showChangeEffect: false);
        player.DisableCollider();

        float   effectTime   = 1.0f;
        float   timeEnd      = Time.unscaledTime + effectTime;
        Vector3 portalCenter = transform.position + Vector3.up * 1.5f;

        collider_.enabled = false;
        enterSound_.Play();

        var baseScale = player.transform.localScale;

        while (Time.unscaledTime < timeEnd)
        {
            float t    = Mathf.Clamp01(1.0f - ((timeEnd - Time.unscaledTime) / effectTime));
            float negT = 1.0f - t;
            cameraShake_.SetMinimumShake(1);

            var playerPos = player.transform.position;
            var direction = portalCenter - playerPos;
            player.SetForce(direction * 20);
            player.transform.localScale    = baseScale * negT;
            player.transform.localRotation = Quaternion.Euler(0, 0, t * 360 * 5);

            yield return(null);
        }

        GameEvents.RaisePlayerEnteredPortal();
        OnPlayerEnter?.Invoke();
    }
示例#3
0
    public void AddPlayerHealthEvent(int amount, string source)
    {
        var player = PlayableCharacters.GetPlayerInScene();

        HealthEvents.Add(new PlayerHealthEvent {
            MaxHealth = player.MaxLife, HealthBefore = player.Life, HealthChange = amount, ChangeSource = source, Time = Time.unscaledTime
        });
    }
示例#4
0
    void Start()
    {
        enemy_    = Enemy.GetComponent <IEnemy>();
        player_   = PlayableCharacters.GetPlayerInScene();
        playerGO_ = player_.gameObject;
        system_   = GetComponent <ParticleSystem>();

        Timing.RunCoroutine(EmitCo().CancelWith(this.gameObject));
    }
示例#5
0
    public void OnPickup()
    {
        var player = PlayableCharacters.GetPlayerInScene();

        weaponObj_.SetActive(true);
        FloatingTextSpawner.Instance.Spawn(player.transform.position + Vector3.up * 0.5f, weapon_.Name, Color.white);
        player.EquipWeapon(weaponObj_);
        Destroy(this.gameObject);
    }
示例#6
0
    public static void SetCameraPositionToActivePlayer()
    {
        var playerInScene = PlayableCharacters.GetPlayerInScene();

        if (playerInScene == null)
        {
            return;
        }

        SceneGlobals.Instance.CameraPositioner.SetPosition(playerInScene.transform.position);
    }
示例#7
0
    IEnumerator <float> LevelUpCo(int newLevel)
    {
        var playerPos = AiBlackboard.Instance.PlayerPosition + Vector3.up * 0.5f;

        AudioManager.Instance.PlaySfxClip(LevelUpSound, 1);
        var player = PlayableCharacters.GetPlayerInScene();

        if (player.Life == 1)
        {
            LootDropScript.Instance.SpawnHealth(1, playerPos, 5);
        }
        FloatingTextSpawner.Instance.Spawn(playerPos, "Level Up!", Color.yellow, 0.1f, 3);
        LightingImageEffect.Instance.FlashColor(LevelUpLightingSettings, LevelUpFlashCurve, 0.2f);
        yield return(0);
    }
示例#8
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.layer == playerLayer_)
        {
            if (TouchPlayerDamage != 0)
            {
                var player = PlayableCharacters.GetPlayerInScene();
                player.TakeDamage(this, TouchPlayerDamage, latestMovementDirection_);
                AddForce(latestMovementDirection_ * -1);
            }
        }

        if (collision.gameObject.layer == mapLayer_)
        {
            // If this event relevant anymore? Hard to tell the difference on/off.
            var targetDir = (moveTo_ - transform_.position).normalized;
            wallAvoidanceDirection_ = ((Vector3)collision.contacts[0].normal + targetDir).normalized;
            wallAvoidanceAmount_    = 1.0f + Random.value * 0.2f;
        }
    }
示例#9
0
    void Update()
    {
        var player = PlayableCharacters.GetPlayerInScene();

        if (Input.GetKeyDown(KeyCode.Tab))
        {
            if (player == null || player.IsDead)
            {
                return;
            }

            Show(!IsShown);
        }

        if (IsShown && player != null)
        {
            var pos = player.transform.position;
            pos.z = Z;
            transform.position = pos;
        }
    }
示例#10
0
    void ExecuteBuy(ShopItemId id, int displayIdx)
    {
        var item = allItems_.Where(i => i.Id == id).Single();

        if (!AcceptBuy(item.Price))
        {
            return;
        }

        var player = PlayableCharacters.GetPlayerInScene();

        switch (id)
        {
        case ShopItemId.Item1Health:
            bool isOverheal = player.Life == player.MaxLife;
            if (isOverheal)
            {
                FloatingTextSpawner.Instance.Spawn(transform.position + Vector3.up * 0.5f, "Hah!", Color.white);
            }
            player.AddHealth(1, "Shop Item");
            break;

        case ShopItemId.IncreaseMaxHp1:
            player.AddMaxHealth(1);
            break;

        default:
            print("Not implemented: " + id);
            break;
        }

        CurrentRunData.Instance.ItemsBought++;

        var display = Displays[displayIdx];

        ParticleScript.EmitAtPosition(ParticleScript.Instance.PlayerLandParticles, display.transform.position, 5);
        ParticleScript.EmitAtPosition(ParticleScript.Instance.MuzzleFlashParticles, display.transform.position, 1);
        display.SetActive(false);
        GameSceneLogic.Instance.UpdateCoinWidget();
    }
示例#11
0
 void CreatePlayer()
 {
     PlayableCharacters.Instance.InstantiateCharacter("Character1", new Vector3(100, 50, 0));
     PlayableCharacters.GetPlayerInScene().SetIsHumanControlled(true, constraints: RigidbodyConstraints2D.FreezeRotation);
     Helpers.SetCameraPositionToActivePlayer();
 }
示例#12
0
    // When destroying walls some colliders are left behind. Fix should be incoming:
    // https://github.com/Unity-Technologies/2d-extras/issues/34
    public void TriggerExplosion(Vector3 worldPosition, float worldRadius, bool damageWallsOnly = true, IEnemy explosionSource = null, bool damageSelf = true)
    {
        int tilesChecked = MapUtil.ClearCircle(this, mapStyle_, worldPosition, worldRadius);

        WallCompositeCollider.generationType = CompositeCollider2D.GenerationType.Manual;
        int tilesCleared = 0;

        for (int i = 0; i < tilesChecked; ++i)
        {
            bool wasDestroyed = MapUtil.LatestResultFlags[i];
            if (wasDestroyed)
            {
                tilesCleared++;
            }

            if (wasDestroyed || !damageWallsOnly)
            {
                var tile = MapUtil.LatestResultPositions[i];

                // Show effect a bit above wall tile center since they also have a top
                const float EffectOffset = 0.5f;
                var         tileWorldPos = WallTileMap.GetCellCenterWorld(tile) + Vector3.up * EffectOffset;
                ParticleScript.EmitAtPosition(SceneGlobals.Instance.ParticleScript.AnimatedFireParticles, tileWorldPos, 3);
            }
        }

        if (!damageWallsOnly)
        {
            var   player    = PlayableCharacters.GetPlayerInScene();
            var   playerPos = player.GetPosition();
            float playerDistanceFromExplosion = (worldPosition - playerPos).magnitude;
            bool  damagePlayer = playerDistanceFromExplosion < worldRadius * 0.8f;
            if (damagePlayer)
            {
                player.TakeDamage(explosionSource, CurrentRunData.Instance.PlayerExplosionDamage, Vector3.zero);
            }

            int mask  = SceneGlobals.Instance.EnemyDeadOrAliveMask;
            int count = Physics2D.OverlapCircleNonAlloc(worldPosition, worldRadius * 0.9f, TempColliderResult, mask);
            for (int i = 0; i < count; ++i)
            {
                var enemyGO = TempColliderResult[i];
                var enemy   = enemyGO.GetComponent <IEnemy>();

                bool isSelf = enemy == explosionSource;
                bool skipDueToSelfDamage = isSelf && !damageSelf;
                if (enemy != null && !skipDueToSelfDamage)
                {
                    var diff      = enemyGO.transform.position - worldPosition;
                    var direction = diff.normalized;
                    enemy.TakeDamage(ExplosionDamageToEnemies, direction * 1.5f);
                }
            }
        }

        SceneGlobals.Instance.AudioManager.PlaySfxClip(SceneGlobals.Instance.AudioManager.AudioClips.LargeExplosion1, 1, 0.1f);
        SceneGlobals.Instance.CameraShake.SetMinimumShake(1.0f);

        WallCompositeCollider.generationType = CompositeCollider2D.GenerationType.Synchronous;
        TilemapCollider.enabled = false;
        TilemapCollider.enabled = true;
    }