/// <summary>
        /// Method to toggle the laser state
        /// </summary>
        /// <param name="leftLaser">Parameter to choose the left or the right laser. (True: Left Laser, False: Right Laser)</param>
        public void LaserToggleState(LASER position)
        {
            switch (position)
            {
            case LASER.LEFT:  this.SendCommand(ARDUINO_COMMANDS.LASER_LEFT_TOGGLE); break;

            case LASER.RIGHT: this.SendCommand(ARDUINO_COMMANDS.LASER_RIGHT_TOGGLE); break;

            default: break;
            }
        }
        /// <summary>
        /// Method to command the left laser
        /// </summary>
        /// <param name="state">State of the laser. (True: Laser ON, False: Laser OFF)</param>
        /// <param name="leftLaser">Parameter to choose the left or the right laser. (True: Left Laser, False: Right Laser)</param>
        public void LaserState(LASER position, bool state)
        {
            switch (position)
            {
            case LASER.LEFT:
                this.SendCommand(state ? ARDUINO_COMMANDS.LASER_LEFT_ON : ARDUINO_COMMANDS.LASER_LEFT_OFF);
                break;

            case LASER.RIGHT:
                this.SendCommand(state ? ARDUINO_COMMANDS.LASER_RIGHT_ON : ARDUINO_COMMANDS.LASER_RIGHT_OFF);
                break;

            default: break;
            }
        }
 /// <summary>
 /// Method to toggle the laser state
 /// </summary>
 /// <param name="leftLaser">Parameter to choose the left or the right laser. (True: Left Laser, False: Right Laser)</param>
 public void LaserToggleState(LASER position)
 {
     switch (position)
     {
         case LASER.LEFT:  this.SendCommand(ARDUINO_COMMANDS.LASER_LEFT_TOGGLE); break;
         case LASER.RIGHT: this.SendCommand(ARDUINO_COMMANDS.LASER_RIGHT_TOGGLE); break;
         default: break;
     }
 }
        /// <summary>
        /// Method to command the left laser
        /// </summary>
        /// <param name="state">State of the laser. (True: Laser ON, False: Laser OFF)</param>
        /// <param name="leftLaser">Parameter to choose the left or the right laser. (True: Left Laser, False: Right Laser)</param>
        public void LaserState(LASER position, bool state)
        {
            switch (position)
            {
                case LASER.LEFT:
                    this.SendCommand(state ? ARDUINO_COMMANDS.LASER_LEFT_ON : ARDUINO_COMMANDS.LASER_LEFT_OFF);
                    break;

                case LASER.RIGHT:
                    this.SendCommand(state ? ARDUINO_COMMANDS.LASER_RIGHT_ON : ARDUINO_COMMANDS.LASER_RIGHT_OFF);
                    break;

                default: break;
            }
        }
Exemple #5
0
        //-----------------------------------------------------------------------------------------------------
        void GameUpdate()
        {
            //DeltaTime Refresh
            System.DateTime time = System.DateTime.Now;
            DeltaTimeTickOld = DeltaTimeTick;
            DeltaTimeTick    = time.Ticks;
            DeltaTime        = (float)(DeltaTimeTick - DeltaTimeTickOld) / System.TimeSpan.TicksPerSecond;

            //Asteroid Logo Flash
            if (AsteroidLogoFlash > 0)
            {
                AsteroidLogoFlash -= 1 * DeltaTime;
            }

            //SpaceShip Turn
            if (SpaceShipTurnLeftFlag)
            {
                SpaceShipPositionX -= SpaceShipSpeed * DeltaTime;
            }
            if (SpaceShipPositionX < 0)
            {
                SpaceShipPositionX = 0;
            }
            if (SpaceShipTurnRightFlag)
            {
                SpaceShipPositionX += SpaceShipSpeed * DeltaTime;
            }
            if (SpaceShipPositionX > 760)
            {
                SpaceShipPositionX = 760;
            }
            if (SpaceShipForwardFlag)
            {
                SpaceShipPositionY -= SpaceShipSpeed * DeltaTime;
            }
            if (SpaceShipPositionY < 100)
            {
                SpaceShipPositionY = 100;
            }
            if (SpaceShipBackwardFlag)
            {
                SpaceShipPositionY += SpaceShipSpeed * DeltaTime;
            }
            if (SpaceShipPositionY > 1300)
            {
                SpaceShipPositionY = 1300;
            }

            //SpaceShip Flame
            if (SpaceShipFlameFlag)
            {
                SpaceShipFlameFlag = false;
            }
            else
            {
                SpaceShipFlameFlag = true;
            }

            //Intro
            IntroAnimation++;
            if (IntroAnimation > 480)
            {
                IntroAnimation = 0;
            }

            if (SpaceShipLaser > 0)
            {
                //LaserShot
                LaserShotTime += DeltaTime;
                if (LaserShotTime > LaserShotRepeatTime)
                {
                    LaserShotTime -= LaserShotRepeatTime;
                    LASER laser = new LASER();
                    laser.PositionX = SpaceShipPositionX + 50;
                    laser.PositionY = SpaceShipPositionY - 50;

                    LaserList.Add(laser);

                    Audio.PlayOneShot(LaserClip, 0.3f);

                    if (SpaceShipLaser > 1000)
                    {
                        LASER laser1 = new LASER();
                        laser.PositionX = SpaceShipPositionX + 30;
                        laser.PositionY = SpaceShipPositionY - 50;
                        LASER laser2 = new LASER();
                        laser.PositionX = SpaceShipPositionX + 70;
                        laser.PositionY = SpaceShipPositionY - 50;

                        LaserList.Add(laser1);
                        LaserList.Add(laser2);

                        //Laser Fuel
                        if (SpaceShipLaser > 0)
                        {
                            SpaceShipLaser -= 3;
                        }
                    }
                    else
                    {
                        //Laser Fuel
                        if (SpaceShipLaser > 0)
                        {
                            SpaceShipLaser--;
                        }
                    }
                }
            }

            //Laser Update
            int count = LaserList.GetCount();

            for (int i = 0; i < count; i++)
            {
                LaserList[i].PositionY -= LaserSpeed * DeltaTime;
                if (LaserList[i].PositionY <= 0)
                {
                    LaserList.RemoveIndex(i);
                }
            }

            //Asteroid LEVEL UP
            if (AsteroidRepeatTime > 0.1f)
            {
                AsteroidRepeatTime -= 0.000001f;
            }
            AsteroidSpeed  += 0.000001f;
            AsteroidEnergy += 0.000001f;

            //Asteroid Field Creation
            AsteroidCreationTime += DeltaTime;
            if (AsteroidCreationTime > AsteroidRepeatTime)
            {
                AsteroidCreationTime -= AsteroidRepeatTime;
                ASTEROID asteroid = new ASTEROID();
                asteroid.Energy    = AsteroidEnergy;
                asteroid.HighRate  = 0;
                asteroid.Type      = Random.Range(1, 3);
                asteroid.PositionX = Random.Range(0, 640);
                asteroid.PositionY = 0;
                AsteroidList.Add(asteroid);
            }

            //Asteroid Update
            count = AsteroidList.GetCount();
            for (int i = 0; i < count; i++)
            {
                ASTEROID asteroid = AsteroidList[i];

                float end = 0;
                if (asteroid.Type == 1)
                {
                    end = 1420;
                }
                if (asteroid.Type == 2)
                {
                    end = 1300;
                }
                asteroid.PositionY += AsteroidSpeed * DeltaTime;
                if (asteroid.PositionY > end)
                {
                    AsteroidList.RemoveIndex(i);
                }
                if (asteroid.HighRate > 0)
                {
                    asteroid.HighRate--;
                }
            }

            //Coin Update
            count = CoinList.GetCount();
            for (int i = 0; i < count; i++)
            {
                COIN coin = CoinList[i];

                coin.AnimationFrame += CoinAnimationSpeed * DeltaTime;
                if (coin.AnimationFrame > 9)
                {
                    coin.AnimationFrame -= 9;
                }
                coin.PositionY += CoinSpeed * DeltaTime;
                if (coin.PositionY > 1450)
                {
                    CoinList.RemoveIndex(i);
                }
            }

            //Explosion Update
            count = ExplosionList.GetCount();
            for (int i = 0; i < count; i++)
            {
                EXPLOSION explosion = ExplosionList[i];

                explosion.PositionY += ExplosionSpeed * DeltaTime;
                if (explosion.PositionY > 1300)
                {
                    ExplosionList.RemoveIndex(i);
                }
                explosion.AnimationFrame += ExplosionAnimationSpeed * DeltaTime;
                if (explosion.AnimationFrame > 31)
                {
                    ExplosionList.RemoveIndex(i);
                }
            }

            //SpaceShip Update
            if (SpaceShipEnergy <= 0)
            {
                //Game Over
                GameOverFlag = true;
            }

            if (!GameOverFlag)
            {
                AsteroidLaserCollision();
                AsteroidSpaceShipCollision();
                CoinSpaceShipCollision();
            }
        }
Exemple #6
0
    public void Update()
    {
        double LastBlockHeight = 50;

        CurrentScore = Convert.ToInt32(GameTimer.Ticks / 10);
        if (CurrentScore > Highscore)
        {
            Highscore = CurrentScore;
        }

        _Player.HandleImput(_Window);
        if (_Player.ResetLevel == true)
        {
            Restart();
        }

        if (!SplashKit.MusicPlaying())
        {
            music.Play();
        }
        Draw();
        if (_Player.LevelEnd == false)
        {
            CheckCollions();
            foreach (Laser LASER in _laser)
            {
                LASER.Update();
            }


            List <Block> RemoveBlocks = new List <Block>();
            foreach (Block BLOCK in _blocks)
            {
                BLOCK.Update();
                if (BLOCK.IsOffScreen(_Window))
                {
                    RemoveBlocks.Add(BLOCK);
                }
            }

            foreach (Block BLOCK in RemoveBlocks)
            {
                if (BLOCK.SpawnNext)
                {
                    double MaybeNegative;
                    if (SplashKit.Rnd() > 0.5)
                    {
                        MaybeNegative = 1;
                    }
                    else
                    {
                        MaybeNegative = -1;
                    }
                    MaybeNegative = SplashKit.Rnd(20) * MaybeNegative;
                    double additon = (GameTimer.Ticks / 1000);
                    //Tell if it ceiling or floor block

                    if (BLOCK.Y == 0)
                    {
                        SpawnBlock(_Window.Width, BLOCK.Y, 50, LastBlockHeight + MaybeNegative + additon);
                    }
                    else
                    {
                        SpawnBlock(_Window.Width, _Window.Height - (LastBlockHeight + MaybeNegative + additon), 50, LastBlockHeight + MaybeNegative + additon);
                    }
                    LastBlockHeight = BLOCK.height;
                }
                _blocks.Remove(BLOCK);
            }

            // 3 second timer
            if (Cooldown.Ticks > 3000)
            {
                FloatBlock();
                // Cooldown.Reset();
            }
            if (BuffSpawnTimer.Ticks > 10000)
            {
                SpawnBuff();
                // Controls how often Buff Spawns
            }
            if (BuffTimer.Ticks > 5000)
            {
                _Player.PowerUp = false;
                BuffTimer.Stop();
                Star.Stop();
                SplashKit.ResumeMusic();
                //SplashKit.PlayMusic();
                //Controls how long the buff goes for
            }
            if (_Player.Shoot)
            {
                //Uses Sprite sheet so width is divided by 5
                Laser laser = new Laser(_Player.X + (_Player.width / 5), _Player.Y + _Player.height / 2);
                _laser.Add(laser);
                _Player.Shoot = false;
                Laser.Play();
            }
        }
        if (_Player.DisplayScore == true)
        {
            DisplayScores();
            _Player.DisplayScore = false;
        }
    }
Exemple #7
0
    private void CheckCollions()
    {
        List <Block> RemoveBlocks = new List <Block>();
        List <Laser> RemoveLaser  = new List <Laser>();
        List <Buff>  RemoveBuff   = new List <Buff>();

        foreach (Block BLOCK in _blocks)
        {
            if (_Player.Collidewith(BLOCK))
            {
                if (_Player.PowerUp == true)
                {
                    if (!BLOCK.SpawnNext)
                    {
                        RemoveBlocks.Add(BLOCK);
                    }
                }
                else
                {
                    _Player.LevelEnd = true;
                    AddScore();
                    GameTimer.Pause();
                    break;
                }
            }

            foreach (Laser LASER in _laser)
            {
                if (LASER.Collidewith(BLOCK))
                {
                    RemoveBlocks.Add(BLOCK);
                    RemoveLaser.Add(LASER);
                }
            }
        }
        foreach (Block BLOCK in RemoveBlocks)
        {
            _blocks.Remove(BLOCK);
        }
        foreach (Laser LASER in RemoveLaser)
        {
            _laser.Remove(LASER);
        }

        foreach (Buff BUFF in _buff)
        {
            if (_Player.Collidewith(BUFF))
            {
                if (BUFF.bufftype == Buff.BuffType.Rainbow)
                {
                    _Player.PowerUp = true;
                    BuffTimer.Start();
                    SplashKit.PauseMusic();
                    Star.Play();
                }
                if (BUFF.bufftype == Buff.BuffType.Ammo)
                {
                    _Player.Ammo = _Player.Ammo + 1;
                }

                RemoveBuff.Add(BUFF);
            }
            if (BUFF.IsOffScreen(_Window))
            {
                RemoveBuff.Add(BUFF);
            }
            BUFF.Update();
        }


        foreach (Buff BUFF in RemoveBuff)
        {
            _buff.Remove(BUFF);
        }
    }