示例#1
0
        // Declaration of collision between Asteroids and Lazers
        public Boolean lazerCollision(Lazers l)
        {
            Rectangle lazerRec    = new Rectangle(l.lazerX, l.lazerY, l.lazerSize, l.lazerSize);
            Rectangle asteroidRec = new Rectangle(asteroidX, asteroidY, size, size);

            // Returns whether or not the two objects have collided
            return(asteroidRec.IntersectsWith(lazerRec));
        }
示例#2
0
        public void ControlShip()
        {
            // Controls the rotation of the ship

            if (frameCounter >= 4)
            {
                if (spaceDown)
                {
                    turnCounter++;
                }
                frameCounter = 0;
            }

            // shotCounter controls how often the player can shoot

            shotCounter++;

            // If the player presses "C" and a certain amount of time has passed
            // since the last lazer was shot, a new Lazer is shot

            if (cKeyDown && shotCounter > 10)
            {
                if (OptionsScreen.setSoundOptions)
                {
                    lazerBlast.Play();
                }

                // shotCounter is reset

                shotCounter = 0;


                // Declares the direction which the Lazer travels

                switch (turnCounter)
                {
                case 0:
                    Lazers newUpLazer = new Lazers(lazerSize, 250, 250, "Up");
                    lazerList.Add(newUpLazer);
                    break;

                case 1:
                    Lazers newLeftLazer = new Lazers(lazerSize, 250, 250, "Left");
                    lazerList.Add(newLeftLazer);
                    break;

                case 2:
                    Lazers newDownLazer = new Lazers(lazerSize, 250, 250, "Down");
                    lazerList.Add(newDownLazer);
                    break;

                case 3:
                    Lazers newRightLazer = new Lazers(lazerSize, 250, 250, "Right");
                    lazerList.Add(newRightLazer);
                    break;
                }
            }

            // Controls how the Lazer moves

            foreach (Lazers l in lazerList)
            {
                if (l.direction == "Up")
                {
                    l.MoveUp(lazerSpeed);
                }
                else if (l.direction == "Left")
                {
                    l.MoveLeft(lazerSpeed);
                }
                else if (l.direction == "Down")
                {
                    l.MoveDown(lazerSpeed);
                }
                else if (l.direction == "Right")
                {
                    l.MoveRight(lazerSpeed);
                }
            }

            // If a Lazer moves off of the screen, the Lazer is removed from the list

            if (lazerList.Count > 0 && (lazerList[0].lazerY >= this.Height || lazerList[0].lazerY <= 0 ||
                                        lazerList[0].lazerX >= this.Width || lazerList[0].lazerX <= 0))
            {
                lazerList.RemoveAt(0);
            }
        }