コード例 #1
0
        public override void Update()
        {
            if(!dead) Input();

            if (gunType == Globals.LaserShot) MaxFireRate = 128;

            Position += new Vector2(0, velocityY);

            velocityY *= FRICTION;

            if (Position.Y >= 480 - Orgin.Y)
            {
                velocityY = 0;
            }

            if (!hasSetupKeys)
            {
                Globals.SetupKeys();
                hasSetupKeys = true;
            }

            if (dead)
            {
                respawnCount += 1;

                if (respawnCount % 2 == 0)
                {
                    for (int i = 0; i < 10; i++ )
                        GameObjectManager.Add(new Explosion(Position + new Vector2(Globals.Randomizer.Next((int)-Orgin.X*2, (int)Orgin.X*2), Globals.Randomizer.Next((int)-Orgin.Y*2, (int)Orgin.Y*2))));
                }

                Position = new Vector2(Position.X, Globals.Lerp(Position.Y, 620, 0.04f));

                if (respawnCount >= MAX_RESPAWN_COUNT && Lives > 0)
                {
                    dead = false;
                    gunType = () => Globals.SimpelShot(this, this.Speed + 4, -(float)Math.PI / 2, SimpleProjectile.Pattern.Straight);
                    MaxFireRate = 16;
                    respawnCount = 0;

                    InvisibleCount = 128*4;
                    if (Lives == 1) DeActivate(LifeKey.NumLock);
                    if (Lives == 2) DeActivate(LifeKey.CapsLock);
                    if (Lives == 3) DeActivate(LifeKey.ScrollLock);
                    Lives -= 1;

                    Position = new Vector2(400, 240);
                }
            }

            Globals.gameOver = (Lives <= 0);

            foreach (Enemy e in GameObjectManager.gameObjects.Where(item => item is Enemy))
            {
                if (e.Hitbox.Intersects(Hitbox))
                {
                    e.Health = 0;
                    if(InvisibleCount <= 0) dead = true;
                }
            }

            foreach(Projectile p in GameObjectManager.gameObjects.Where(item => item is Projectile))
            {
                if (p.Hitbox.Intersects(Hitbox) && p.enemy)
                {
                    GameObjectManager.Remove(p);
                    if (InvisibleCount <= 0) dead = true;
                }
            }

            if(laser != null) laser.Update();

            fireRate = (fireRate >= MaxFireRate) ? 0 : fireRate;
            fireRate = (fireRate >= 1) ? fireRate + 1 : fireRate;

            if (fireRate >= 1 && fireRate <= MaxFireRate / 4 && gunType == Globals.LaserShot)
            {
                laser = new Laser(Position, Position + new Vector2(0, -500), new Color(Globals.Randomizer.Next(0, 255), Globals.Randomizer.Next(0, 255), Globals.Randomizer.Next(0, 255), Globals.Randomizer.Next(0, 255)), true);
            }
            else
            {
                laser = null;
            }

            if (InvisibleCount >= 1)
            {
                InvisibleCount += 1;
                if (InvisibleCount >= 128*5) InvisibleCount = 0;
            }

            //TurnOffLight();

            base.Update();
        }
コード例 #2
0
        public override void Update()
        {
            base.Update();

            //gunType = Globals.LaserShot;

            if (gunType == Globals.LaserShot) MaxFireRate = 128;

            fireRate = (fireRate >= 1) ? fireRate + 1 : 0;
            fireRate = (fireRate >= MaxFireRate) ? 0 : fireRate;

            if(invsibileCount <= MAX_INSIVSIBLECOUNT) invsibileCount += 1;

            foreach (Enemy e in GameObjectManager.gameObjects.Where(item => item is Enemy))
            {
                if (e.Hitbox.Intersects(Hitbox))
                {
                    e.Health = 0;
                    if (invsibileCount > MAX_INSIVSIBLECOUNT) dead = true;
                }
            }

            foreach (Projectile p in GameObjectManager.gameObjects.Where(item => item is Projectile))
            {
                if (p.Hitbox.Intersects(Hitbox) && p.enemy)
                {
                    GameObjectManager.Remove(p);
                    if (invsibileCount > MAX_INSIVSIBLECOUNT) dead = true;
                }
            }

            foreach(Player p in GameObjectManager.gameObjects.Where(item => item is Player))
            {
                if (p.dead) dead = p.dead;
                Position = new Vector2(Globals.Lerp(Position.X, p.Position.X + MAX_DISTANCE * Tag, Speed), Globals.Lerp(Position.Y, p.Position.Y, Speed));
            }

            if (dead)
            {
                GameObjectManager.Add(new Explosion(Position));
                GameObjectManager.Remove(this);
            }

            if (laser != null) laser.Update();

            if (fireRate >= 1 && fireRate <= 128 / 4 && gunType == Globals.LaserShot)
            {
                laser = new Laser(Position, Position + new Vector2((float)Math.Cos(ShootAngle) * 800, (float)Math.Sin(ShootAngle) * 800), new Color(Globals.Randomizer.Next(0, 255), Globals.Randomizer.Next(0, 255), Globals.Randomizer.Next(0, 255), Globals.Randomizer.Next(0, 255)), true);
            }
            else
            {
                laser = null;
            }
        }