Example #1
0
 public void Teleport(Vector2 vec)
 {
     if (state == TeleState.None)
     {
         timer.Start();
         state = TeleState.Tele;
         GetComponent <BarnMove>().audio.PlayOneShot(GetComponent <BarnMove>().sfxtele);
     }
     inputvec    = vec;
     inputvec.y *= 1.5f;
     //GetComponent<SpriteRenderer> ().color = new Color (256, 256, 256, 0);
 }
Example #2
0
 void Update()
 {
     if (state == TeleState.Tele)
     {
         if (timer.GetElapsedTimeSecs() < teleTime)
         {
             rbody.AddForce(inputvec * teleamt);
         }
         else if (timer.GetElapsedTimeSecs() > teleTime * 3.0)
         {
             //GetComponent<SpriteRenderer> ().color = new Color (256, 256, 256, 256);
             state = TeleState.None;
         }
     }
 }
Example #3
0
        private void UpdateSides()
        {
            if (leftOrb.health <= 5)
                leftOrb.Invulnerable=true;
            if (rightOrb.health <= 5)
                rightOrb.Invulnerable = true;
            if (leftOrb.Invulnerable)
            {
                switch (leftPos)
                {
                    case TeleState.Up:
                        {
                            leftOrb.Position = new Vector2(0+orbRad*2, -Screen.Y + leftOrb.radius*2);
                            leftPos = TeleState.Shoot;
                        } break;

                    case TeleState.Left:
                        {
                            leftOrb.Position = new Vector2(-Screen.X + leftOrb.radius * 2, 0 + orbRad*2);
                            leftPos = TeleState.Shoot;

                        } break;
                    case TeleState.Shoot:
                        {
                            if (stateTime >= 5)
                                leftPos = TeleState.Laser;
                            Vector2 distance = (p.getPosition() - leftOrb.Position) * Screen.Scale;
                            if (cooldown <= 0)
                            {
                                Tesseract.Engine.GameWorld.GameState.InstantiateCurrent(new EnemyBullet(leftOrb.Position, distance));
                                lcd = 1;
                            }
                            else
                            {
                                lcd = lcd - 2 * Time.Delta;
                            }
                        }break;
                    case TeleState.Laser:
                        {
                            Random r = new Random();
                            Vector2 pos = new Vector2(0, 0);
                            pos.Y += ((float)r.NextDouble() - 0.5f) / 10;
                            emitter.Burst(leftOrb.Position, 1, (float)Math.PI);
                            p = GameManager.State.FindObject<Player>();
                            if (leftPos == TeleState.Left || leftPos == TeleState.Right)
                            {
                                if (leftOrb != null && p.Position.Y > leftOrb.Position.Y - 0.1 && p.Position.Y < leftOrb.Position.Y + 0.1)
                                    p.OnDamage(1);
                            }
                            else
                            {
                                if (leftOrb != null && p.Position.X > leftOrb.Position.X - 0.1 && p.Position.X < leftOrb.Position.Y + 0.1)
                                    p.OnDamage(1);
                            }
                        } break;
                }
            }
            if (rightOrb.Invulnerable)
            {
                switch (rightPos)
                {
                    case TeleState.Down:
                        {
                            rightOrb.Position = new Vector2(0 - orbRad*2, Screen.Y - leftOrb.radius * 2);
                            rightPos = TeleState.Shoot;

                        } break;
                    case TeleState.Right:
                        {
                            rightOrb.Position = new Vector2(Screen.X - orbRad * 2, 0 - orbRad*2);
                            rightPos = TeleState.Shoot;
                        } break;
                    case TeleState.Shoot:
                        {
                            if (stateTime >= 5)
                                rightPos = TeleState.Laser;
                            Vector2 distance = (p.getPosition() - rightOrb.Position) * Screen.Scale;
                            if (cooldown <= 0)
                            {
                                Tesseract.Engine.GameWorld.GameState.InstantiateCurrent(new EnemyBullet(rightOrb.Position, distance));
                                rcd = 1;
                            }
                            else
                            {
                                rcd = rcd - 2 * Time.Delta;
                            }
                        }break;
                    case TeleState.Laser:
                        {
                            Random r = new Random();
                            Vector2 pos = new Vector2(0, 0);
                            pos.Y += ((float)r.NextDouble() - 0.5f) / 10;
                            emitter.Burst(rightOrb.Position, 1, (float)Math.PI);
                            p = GameManager.State.FindObject<Player>();
                            if (rightPos == TeleState.Left || rightPos == TeleState.Right)
                            {
                                if (rightOrb != null && p.Position.Y > leftOrb.Position.Y - 0.1 && p.Position.Y < leftOrb.Position.Y + 0.1)
                                    p.OnDamage(1);
                            }
                            else
                            {
                                if (rightOrb != null && p.Position.X > leftOrb.Position.X - 0.1 && p.Position.X < leftOrb.Position.Y + 0.1)
                                    p.OnDamage(1);
                            }
                        } break;
                }
            }
        }
Example #4
0
        private void SideState()
        {
            if (leftOrb != null && leftOrb.Invulnerable)
            {
                if(posState!=TeleState.Down&&posState!=TeleState.Up){
                    leftPos=TeleState.Up;
                }

                else {
                    leftPos=TeleState.Left;
                }

            }
            if (rightOrb != null && rightOrb.Invulnerable)
            {
                if (posState != TeleState.Down && posState != TeleState.Up)
                {
                    rightPos = TeleState.Down;
                }

                else
                {
                    rightPos = TeleState.Right;
                }
            }
        }
Example #5
0
 private void SetState(TeleState state)
 {
     this.state = state;
     this.stateTime = 0;
     SideState();
 }
Example #6
0
        public override bool Update()
        {
            stateTime += Time.Delta;
            UpdateSides();
            leftOrb.Update();
            rightOrb.Update();
            Vector2 distance = (p.getPosition() - Position) * Screen.Scale;
            distance.Normalize();
            if (leftOrb.Invulnerable && rightOrb.Invulnerable)
                this.Invulnerable = false;
            if(stateTime>3&&this.state==TeleState.Shoot)
                nBuild.PolyColor = Color.Lerp(this.nBuild.PolyColor, Color.Red, (1) / (float)32);
            switch (state)
            {
                case TeleState.Up:
                    {
                        this.nBuild.PolyColor = Color.Lerp(this.nBuild.PolyColor, Color.Indigo, 1);
                        leftOrb.nBuild.PolyColor = Color.Lerp(leftOrb.nBuild.PolyColor, new Color(0,1f,0), 1);
                        rightOrb.nBuild.PolyColor = Color.Lerp(rightOrb.nBuild.PolyColor, new Color(0, 1f, 0), 1);
                        Position = new Vector2(0, -Screen.Y + radius + radius);
                        posState = state;
                        if (!leftOrb.Invulnerable) { leftOrb.Position = new Vector2(Position.X + radius + orbRad, Position.Y); }
                        if (!rightOrb.Invulnerable) { rightOrb.Position = new Vector2(Position.X - radius - orbRad, Position.Y); }
                        SetState(TeleState.Shoot);
                    } break;

                case TeleState.Down:
                    {
                        this.nBuild.PolyColor = Color.Lerp(this.nBuild.PolyColor, Color.Indigo, 1 );
                        leftOrb.nBuild.PolyColor = Color.Lerp(leftOrb.nBuild.PolyColor, new Color(0, 1f, 0), 1);
                        rightOrb.nBuild.PolyColor = Color.Lerp(rightOrb.nBuild.PolyColor, new Color(0, 1f, 0), 1);
                        Position = new Vector2(0, Screen.Y - radius - radius);
                        posState = state;
                        if (!leftOrb.Invulnerable) { leftOrb.Position = new Vector2(Position.X - radius - orbRad, Position.Y); }
                        if (!rightOrb.Invulnerable) { rightOrb.Position = new Vector2(Position.X + radius + orbRad, Position.Y); }
                        SetState(TeleState.Shoot);
                    } break;
                case TeleState.Left:
                    {
                        this.nBuild.PolyColor = Color.Lerp(this.nBuild.PolyColor, Color.Indigo, 1 );
                        leftOrb.nBuild.PolyColor = Color.Lerp(leftOrb.nBuild.PolyColor, new Color(0, 1f, 0), 1);
                        rightOrb.nBuild.PolyColor = Color.Lerp(rightOrb.nBuild.PolyColor, new Color(0, 1f, 0), 1);
                        Position = new Vector2(-Screen.X + radius + radius, 0);
                        posState = state;
                        if (!leftOrb.Invulnerable) { leftOrb.Position = new Vector2(Position.X, Position.Y - radius - orbRad); }
                        if (!rightOrb.Invulnerable) { rightOrb.Position = new Vector2(Position.X, Position.Y + radius + orbRad); }
                        SetState(TeleState.Shoot);
                    } break;
                case TeleState.Right:
                    {
                        this.nBuild.PolyColor = Color.Lerp(this.nBuild.PolyColor, Color.Indigo, 1 );
                        leftOrb.nBuild.PolyColor = Color.Lerp(leftOrb.nBuild.PolyColor, new Color(0, 1f, 0), 1);
                        rightOrb.nBuild.PolyColor = Color.Lerp(rightOrb.nBuild.PolyColor, new Color(0, 1f, 0), 1);
                        Position = new Vector2(Screen.X - radius - radius, 0);
                        posState = state;
                        if (!leftOrb.Invulnerable) { leftOrb.Position = new Vector2(Position.X, Position.Y + radius + orbRad); }
                        if (!rightOrb.Invulnerable) { rightOrb.Position = new Vector2(Position.X, Position.Y - radius - orbRad); }
                        SetState(TeleState.Shoot);
                    } break;
                case TeleState.Shoot:
                    {
                        if (stateTime >= 5)
                            SetState(TeleState.Laser);
                        if (cooldown <= 0)
                        {
                            Tesseract.Engine.GameWorld.GameState.InstantiateCurrent(new EnemyBullet(Position, distance));
                            cooldown = 1;
                        }
                        else
                        {
                            cooldown = cooldown - 2 * Time.Delta;
                        }
                    } break;
                case TeleState.Laser:
                    {
                        if (stateTime > 2)
                        {
                            this.nBuild.PolyColor = Color.Lerp(this.nBuild.PolyColor, Color.Transparent, 1 / (float)16);
                            leftOrb.nBuild.PolyColor = Color.Lerp(leftOrb.nBuild.PolyColor, Color.Transparent, 1 / (float)16);
                            rightOrb.nBuild.PolyColor = Color.Lerp(rightOrb.nBuild.PolyColor, Color.Transparent, 1 / (float)16);
                        }
                        if (stateTime > 3)
                        {
                            switch (new Random().Next(4))
                            {
                                case 0:
                                    {
                                        if(posState!=TeleState.Up)
                                        SetState(TeleState.Up);
                                    } break;
                                case 1:
                                    {
                                        if (posState != TeleState.Down)
                                        SetState(TeleState.Down);
                                    } break;
                                case 2:
                                    {
                                        if (posState != TeleState.Left)
                                        SetState(TeleState.Left);
                                    } break;
                                case 3:
                                    {
                                        if (posState != TeleState.Right)
                                        SetState(TeleState.Right);
                                    } break;
                            }
                        }

                        else
                        {
                            Random r = new Random();
                            Vector2 pos = new Vector2(0, 0);
                            pos.Y += ((float)r.NextDouble() - 0.5f) / 10;
                            emitter.Burst(Position, 1, (float)Math.PI);
                            if (leftOrb.health>5)
                                emitter.Burst(leftOrb.Position, 1, (float)Math.PI);
                            if (rightOrb.health>5)
                                emitter.Burst(rightOrb.Position, 1, (float)Math.PI);

                            p = GameManager.State.FindObject<Player>();
                            if (posState == TeleState.Left || posState == TeleState.Right)
                            {
                                if ((p.Position.Y > Position.Y - 0.1 && p.Position.Y < Position.Y + 0.1)
                                || (leftOrb.health>5 && p.Position.Y > leftOrb.Position.Y - 0.1 && p.Position.Y < leftOrb.Position.Y + 0.1)
                                || (rightOrb.health>5 && p.Position.Y > rightOrb.Position.Y - 0.1 && p.Position.Y < rightOrb.Position.Y + 0.1))
                                {
                                    p.OnDamage(1);
                                }
                            }
                            else
                            {
                                if ((p.Position.X > Position.X - 0.1 && p.Position.X < Position.X + 0.1)
                                || (leftOrb.health>5 && p.Position.X > leftOrb.Position.X - 0.1 && p.Position.X < leftOrb.Position.Y + 0.1)
                                || (rightOrb.health>5 && p.Position.X > rightOrb.Position.X - 0.1 && p.Position.X < rightOrb.Position.Y + 0.1))
                                {
                                    p.OnDamage(1);
                                }
                            }
                        }
                    } break;
            }
            emitter.Update();
            return base.Update();
        }
Example #7
0
 void Start()
 {
     rbody            = rigidbody2D;
     rbody.fixedAngle = true;
     state            = TeleState.None;
 }