Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        healthSlider.gameObject.SetActive(displayHealthBar);
        healthText = healthSlider.GetComponentInChildren <TextType>();

        moneyText.gameObject.SetActive(displayMoneyCount);

        waveText.gameObject.SetActive(false);
        enemyText.gameObject.SetActive(false);

        weaponImage.gameObject.SetActive(displayWeaponUI);
        if (displayWeaponUI)
        {
            weaponController = FindObjectOfType <WeaponController>();
            ammoText         = weaponImage.GetComponentInChildren <TextType>();
        }

        minimap.gameObject.SetActive(displayMinimap);
        map.gameObject.SetActive(false);
        GameInput.BindEvent(GameEventType.NextRoom, room => room.GetChild(0).FindChildWithLayer("LevelMap").SetActive(true));

        textboxCanvas = Instantiate(textboxCanvas);
        textboxCanvas.SetActive(false);
        textbox      = textboxCanvas.GetComponentInChildren <DialogueBox>();
        weaponHolder = GameObject.FindGameObjectWithTag("Player")?.transform.GetChild(0);
    }
Ejemplo n.º 2
0
 public void OnObjectSpawn()
 {
     rb = GetComponent <Rigidbody2D>();
     StartMoving(false);
     rb.velocity = new Vector2(Random.Range(-1, 1), Random.value).normalized *speed;
     GameInput.BindEvent(GameEventType.EndRoom, _ => StartMoving(true));
 }
Ejemplo n.º 3
0
    void Init()
    {
        rb    = GetComponent <Rigidbody2D>();
        cd    = GetComponent <Collider2D>();
        trail = GetComponent <TrailRenderer>();
        anim  = GetComponent <Animator>();
        sr    = GetComponent <SpriteRenderer>();
        if (whiteMat)
        {
            whiteMat = Instantiate(whiteMat);
        }
        if (sr)
        {
            spriteExtents = sr.bounds.extents;
        }

        particle = FindObjectOfType <ParticleEffect>();
        cam      = Camera.main;

        if (HasProperty(EntityProperty.OpenGameOverMenu))
        {
            deathVFX.done += () => { /* TODO: Open Game over menu after vfx */ }
        }
        ;
        if (HasProperty(EntityProperty.SpawnCellWhenDie))
        {
            deathVFX.done += () =>
            {
                int dropValue = valueRange.randomValue;
                for (int i = 0; i < dropValue; i++)
                {
                    ObjectPooler.Spawn(PoolType.Cell, transform.position);
                }
            }
        }
        ;

        SetProperty(EntityProperty.CanBeHurt, true);
        hurtVFX.done += () =>
        {
            SetProperty(EntityProperty.CanBeHurt, true);
            prevStat = -1;
        };

        /*if (HasProperty(EntityProperty.MoveWhenClearRoom))
         *  GameInput.BindEvent(GameEventType.EndRoom, _ => StartMoving(true));*/

        for (int i = 0; i < stats.Length; ++i)
        {
            if (stats[i].properties.HasProperty(EntityStatProperty.EndRoom))
            {
                GameInput.BindEvent(GameEventType.EndRoom, _ => currentStat = i);
            }
        }
    }
Ejemplo n.º 4
0
    public void InitCamera(bool automatic, bool useSmoothDamp, Vector2 value, float waitTime)
    {
        if (stats == null || stats.Length < 2)
        {
            stats = new EntityStat[2];
        }

        SetProperty(EntityProperty.HasTargetOffset, !automatic);
        stats[0] = new EntityStat
        {
            properties = new Property <EntityStatProperty>(EntityStatProperty.FindNewStat),
            targetType = automatic ? TargetType.MoveRegion : TargetType.Player,
            speed      = value.magnitude,
            moveType   = useSmoothDamp ? MoveType.SmoothDamp : MoveType.Fly,
        };
        prevStat = -1;
        //targetType = automatic ? TargetType.MoveRegion : TargetType.Player;
        //speed = value.magnitude;
        //moveType = useSmoothDamp ? MoveType.SmoothDamp : MoveType.Fly;

        speed  = value.x;
        speedY = value.y;

        stats[1] = new EntityStat {
            properties = new Property <EntityStatProperty>(EntityStatProperty.EntityOutOfMoveRegion), chargeTime = waitTime
        };
        GameInput.BindEvent(GameEventType.NextRoom, room => ToNextRoom(GameManager.GetBoundsFromRoom(room).ToRect()));

        void ToNextRoom(Rect roomRect)
        {
            moveRegion      = roomRect;
            moveRegion.min += cam.HalfSize();
            moveRegion.max -= cam.HalfSize();
            if (automatic)
            {
                transform.position = moveRegion.min.Z(transform.position.z);
                SwitchTargetToMax(true, false);
            }
            Debug.Assert((moveRegion.xMin <= moveRegion.xMax) && (moveRegion.yMin <= moveRegion.yMax),
                         $"Camera's limit is wrong: (Move region: {moveRegion}, Rect: {roomRect})");
        }
    }
Ejemplo n.º 5
0
 public void InitManual(Vector2 camOffset, bool useSmoothDamp, Vector2 value, Vector3Variable playerPos)
 {
     Init(camOffset, useSmoothDamp, value);
     this.playerPos = playerPos;
     GameInput.BindEvent(GameEventType.NextRoom, room => ToNextRoom(GameManager.GetBoundsFromRoom(room).ToBounds()));
 }