Ejemplo n.º 1
0
        public override void OnUpdate(float deltaTime)
        {
            // Lerp everything off life time
            if (!lifeTime.Check(false))
            {
                curColor = ColorRGB.Lerp(fireColor, smokeColor, lifeTime.PercentComplete);
                curScale = Utils.Lerp(0.2f, 1, lifeTime.PercentComplete);
                curRot   = Utils.Lerp(0, 90, lifeTime.PercentComplete);

                if (lifeTime.PercentComplete >= 2f / 3f)
                {
                    curTexture    = smokeTexture3;
                    smokeOffset.x = smokeTexture3.width / 2;
                    smokeOffset.y = smokeTexture3.height / 2;
                }
                else if (lifeTime.PercentComplete >= 1f / 3f)
                {
                    curTexture    = smokeTexture2;
                    smokeOffset.x = smokeTexture2.width / 2;
                    smokeOffset.y = smokeTexture2.height / 2;
                }
                else
                {
                    smokeOffset.x = smokeTexture1.width / 2;
                    smokeOffset.y = smokeTexture1.height / 2;
                }
                smokeOffset *= curScale;

                base.OnUpdate(deltaTime);
                return;
            }

            // Death Zone
            SmokeManager.RemoveSmoke(this);
        }
Ejemplo n.º 2
0
        public override void OnUpdate(float deltaTime)
        {
            Move(deltaTime);
            RotateTurret(deltaTime);

            // Update Healthbar
            healthBar.Update(deltaTime);

            // Fire bullets
            if (canFire & attackDelay.Check(false))
            {
                float rotation = MathF.Atan2(turretObject.GlobalTransform.m2, turretObject.GlobalTransform.m1);
                rotation = (rotation < 0) ? rotation + (2 * MathF.PI) : rotation;

                Vector2 bulletPos = Position + (new Vector2(turretObject.GlobalTransform.m1, turretObject.GlobalTransform.m2).Normalised() * turretSprite.Height);

                bullets.Add(new Bullet(ref PreLoadedTextures.EnemyBulletTexture, 800, bulletPos, rotation, 2, this));
                attackDelay.Reset();
            }

            // Update Bullets
            for (int x = 0; x < bullets.Count; x++)
            {
                bullets[x].Update(deltaTime);

                if (bullets.Count <= x)
                {
                    continue;
                }

                bullets[x].CheckCollision(player);
            }

            // Alter color when AI gets hit
            tankColor = Color.WHITE;
            if (!hurtTime.Check(false))
            {
                if (hurtTime.Time / (hurtTime.delay / 2) < 1) // Become more red until halfway through timer
                {
                    tankColor = ColorRGB.Lerp(Color.WHITE, hurtColor, hurtTime.Time / (hurtTime.delay / 2));
                }
                else // Become less red from halfway through timer to completion
                {
                    tankColor = ColorRGB.Lerp(hurtColor, Color.WHITE, (hurtTime.Time - (hurtTime.delay / 2)) / ((hurtTime.delay / 2)));
                }
            }
            tankSprite.spriteColor   = tankColor;
            turretSprite.spriteColor = tankColor;

            // shift AI position to simulate camera follow (usually you base.onUpdate but can't be used here
            Vector2 tmpVector = Program.Center - Game.CurCenter;

            Translate(tmpVector.x, tmpVector.y);

            // Set position of healthbar and collider
            healthBar.SetPosition(Position.x, Position.y - distFromEnemyCenter);
            collider.SetPosition(Position);
        }
Ejemplo n.º 3
0
        public override void OnUpdate(float deltaTime)
        {
            RotateBody(deltaTime);
            MoveBody(deltaTime);
            RotateTurret(deltaTime);
            Game.CurCenter = Position;

            // Fire bullets
            if (IsKeyPressed(KeyboardKey.KEY_SPACE) & attackDelay.Check(false) && !ammoCount.IsComplete(false))
            {
                float rotation = MathF.Atan2(turretObject.GlobalTransform.m2, turretObject.GlobalTransform.m1);
                rotation = (rotation < 0) ? rotation + (2 * MathF.PI) : rotation;

                Vector2 bulletPos = Position + (new Vector2(turretObject.GlobalTransform.m1, turretObject.GlobalTransform.m2).Normalised() * turretSprite.Height);

                bullets.Add(new Bullet(ref PreLoadedTextures.EnemyBulletTexture, 800, bulletPos, rotation, 3, this));

                ammoCount.CountByValue(1);
                attackDelay.Reset();
            }

            // Update bullets and check for bullet collision
            for (int x = 0; x < bullets.Count; x++)
            {
                bullets[x].Update(deltaTime);

                if (x >= bullets.Count)
                {
                    continue;
                }

                // Collision deection for bullets against enemies
                AI    tmpEnemy = null;
                float dist     = float.MaxValue;
                for (int y = 0; y < EnemyManager.curEnemies.Count; y++)
                {
                    float tmpDist = bullets[x].Position.Distance(EnemyManager.curEnemies[y].Position);
                    if (tmpDist < dist)
                    {
                        dist     = tmpDist;
                        tmpEnemy = EnemyManager.curEnemies[y];
                    }
                }
                if (tmpEnemy != null)
                {
                    bullets[x].CheckCollision(tmpEnemy);
                }
            }

            // Push player back if they run into enemies
            for (int x = 0; x < EnemyManager.curEnemies.Count; x++)
            {
                EnemyManager.curEnemies[x].Push(this);
            }

            // Alter color when player gets hit
            tankColor = Color.WHITE;
            if (!hurtTime.Check(false))
            {
                if (hurtTime.Time / (hurtTime.delay / 2) < 1) // Become more red until halfway through timer
                {
                    tankColor = ColorRGB.Lerp(Color.WHITE, hurtColor, hurtTime.Time / (hurtTime.delay / 2));
                }
                else // Become less red from halfway through timer to completion
                {
                    tankColor = ColorRGB.Lerp(hurtColor, Color.WHITE, (hurtTime.Time - (hurtTime.delay / 2)) / ((hurtTime.delay / 2)));
                }
            }
            tankSprite.spriteColor   = tankColor;
            turretSprite.spriteColor = tankColor;

            // Shift object back to simulate camera movement
            base.OnUpdate(deltaTime);
        }