Exemple #1
0
        public SpaceShip(PlayerIndex playerNumber, Vector2 position, float rotation, SpriteSheet spriteSheet, ProjectileSystem projectileSystem, GameSettings settings, ContentManager content)
        {
            // instantiate the player's number with a player index
            m_playerNumber = playerNumber;
                 if(m_playerNumber == PlayerIndex.One)   { m_colour = SpaceShipColour.Red; }
            else if(m_playerNumber == PlayerIndex.Two)   { m_colour = SpaceShipColour.Blue; }
            else if(m_playerNumber == PlayerIndex.Three) { m_colour = SpaceShipColour.Green; }
            else if(m_playerNumber == PlayerIndex.Four)  { m_colour = SpaceShipColour.Yellow; }

            // instantiate the player's input device type
            m_inputDevice = settings.getInputDevice(playerNumber);
                 if(m_inputDevice == InputDevice.Controller1) { m_controllerNumber = PlayerIndex.One; }
            else if(m_inputDevice == InputDevice.Controller2) { m_controllerNumber = PlayerIndex.Two; }
            else if(m_inputDevice == InputDevice.Controller3) { m_controllerNumber = PlayerIndex.Three; }
            else if(m_inputDevice == InputDevice.Controller4) { m_controllerNumber = PlayerIndex.Four; }
            else											  { m_controllerNumber = PlayerIndex.One; }

            // instantiate local variables
            this.position = position;
            this.rotation = rotation;
            m_scale = new Vector2(1, 1);

            m_maximumVelocity = 5.8f;
            m_acceleration = 0.048f;
            m_rotationSpeed = 3.1f;

            m_settings = settings;
            m_spriteSheet = spriteSheet;
            m_projectileSystem = projectileSystem;

            if(m_spriteSheet == null) { return; }

            // initialize sprite / sprite animation arrays
            m_idleSprite = new Sprite[3];
            m_movingAnimation = new SpriteAnimation[3];

            // set the space ship sprite sheet offset based on the space ship colour
            int spriteOffset = 0;
                 if(m_colour == SpaceShipColour.Red)    { spriteOffset = 0; }
            else if(m_colour == SpaceShipColour.Blue)   { spriteOffset = 18; }
            else if(m_colour == SpaceShipColour.Green)  { spriteOffset = 3; }
            else if(m_colour == SpaceShipColour.Yellow) { spriteOffset = 21; }

            // load the idle sprites for each colour
            for(int i=0;i<3;i++) {
                m_idleSprite[i] = m_spriteSheet.getSprite(i + spriteOffset);
            }
            // create and store the movement animations for each colour
            for(int i=0;i<3;i++) {
                m_movingAnimation[i] = new SpriteAnimation(0.16f, SpriteAnimationType.Loop);
                m_movingAnimation[i].addSprite(m_spriteSheet.getSprite(i + spriteOffset + 6));
                m_movingAnimation[i].addSprite(m_spriteSheet.getSprite(i + spriteOffset + 12));
            }

            m_offset = new Vector2(m_idleSprite[1].xOffset * 0.9f, m_idleSprite[1].yOffset * 0.9f);
            m_size = new Vector2(m_offset.X * 2.0f, m_offset.Y * 2.0f);

            updateInitialValues();
        }
Exemple #2
0
        public SpaceShip(PlayerIndex playerNumber, Vector2 position, float rotation, SpriteSheet spriteSheet, ProjectileSystem projectileSystem, GameSettings settings, ContentManager content)
        {
            // instantiate the player's number with a player index
            m_playerNumber = playerNumber;
            if (m_playerNumber == PlayerIndex.One)
            {
                m_colour = SpaceShipColour.Red;
            }
            else if (m_playerNumber == PlayerIndex.Two)
            {
                m_colour = SpaceShipColour.Blue;
            }
            else if (m_playerNumber == PlayerIndex.Three)
            {
                m_colour = SpaceShipColour.Green;
            }
            else if (m_playerNumber == PlayerIndex.Four)
            {
                m_colour = SpaceShipColour.Yellow;
            }

            // instantiate the player's input device type
            m_inputDevice = settings.getInputDevice(playerNumber);
            if (m_inputDevice == InputDevice.Controller1)
            {
                m_controllerNumber = PlayerIndex.One;
            }
            else if (m_inputDevice == InputDevice.Controller2)
            {
                m_controllerNumber = PlayerIndex.Two;
            }
            else if (m_inputDevice == InputDevice.Controller3)
            {
                m_controllerNumber = PlayerIndex.Three;
            }
            else if (m_inputDevice == InputDevice.Controller4)
            {
                m_controllerNumber = PlayerIndex.Four;
            }
            else
            {
                m_controllerNumber = PlayerIndex.One;
            }

            // instantiate local variables
            this.position = position;
            this.rotation = rotation;
            m_scale       = new Vector2(1, 1);

            m_maximumVelocity = 5.8f;
            m_acceleration    = 0.048f;
            m_rotationSpeed   = 3.1f;

            m_settings         = settings;
            m_spriteSheet      = spriteSheet;
            m_projectileSystem = projectileSystem;

            if (m_spriteSheet == null)
            {
                return;
            }

            // initialize sprite / sprite animation arrays
            m_idleSprite      = new Sprite[3];
            m_movingAnimation = new SpriteAnimation[3];

            // set the space ship sprite sheet offset based on the space ship colour
            int spriteOffset = 0;

            if (m_colour == SpaceShipColour.Red)
            {
                spriteOffset = 0;
            }
            else if (m_colour == SpaceShipColour.Blue)
            {
                spriteOffset = 18;
            }
            else if (m_colour == SpaceShipColour.Green)
            {
                spriteOffset = 3;
            }
            else if (m_colour == SpaceShipColour.Yellow)
            {
                spriteOffset = 21;
            }

            // load the idle sprites for each colour
            for (int i = 0; i < 3; i++)
            {
                m_idleSprite[i] = m_spriteSheet.getSprite(i + spriteOffset);
            }
            // create and store the movement animations for each colour
            for (int i = 0; i < 3; i++)
            {
                m_movingAnimation[i] = new SpriteAnimation(0.16f, SpriteAnimationType.Loop);
                m_movingAnimation[i].addSprite(m_spriteSheet.getSprite(i + spriteOffset + 6));
                m_movingAnimation[i].addSprite(m_spriteSheet.getSprite(i + spriteOffset + 12));
            }

            m_offset = new Vector2(m_idleSprite[1].xOffset * 0.9f, m_idleSprite[1].yOffset * 0.9f);
            m_size   = new Vector2(m_offset.X * 2.0f, m_offset.Y * 2.0f);

            updateInitialValues();
        }
Exemple #3
0
        // create the game menu at a specific location
        public Menu(int x, int y, Asteroids game, SpaceShipSystem spaceShipSystem, GameSettings settings, ContentManager content)
        {
            if(content == null) { return; }

            // initialize menu colours
            m_titleColour = new Color(255, 0, 0);
            m_unselectedColour = new Color(160, 160, 160);
            m_selectedColour = new Color(255, 255, 255);
            m_arrowColour = new Color(0, 255, 0);

            // initialize menu fonts
            m_titleFont = content.Load<SpriteFont>("TitleFont");
            m_menuFont = content.Load<SpriteFont>("MenuFont");

            // initialize menu sounds
            m_scrollSound = content.Load<SoundEffect>("menu_scroll");
            m_selectSound = content.Load<SoundEffect>("menu_select");
            m_backSound = content.Load<SoundEffect>("menu_back");

            // initialize main menu
            m_mainItems = new List<MenuItem>();
            m_mainItems.Add(new MenuItem("New Game", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_mainItems.Add(new MenuItem("Resume Game", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_mainItems.Add(new MenuItem("Options", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_mainItems.Add(new MenuItem("Controls", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_mainItems.Add(new MenuItem("Help", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_mainItems.Add(new MenuItem("Quit", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));

            // initialize new game sub-menu
            m_newGameItems = new List<MenuItem>();
            m_newGameItems.Add(new MenuItem("1 Player", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_newGameItems.Add(new MenuItem("2 Player", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_newGameItems.Add(new MenuItem("3 Player", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_newGameItems.Add(new MenuItem("4 Player", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_newGameItems.Add(new MenuItem("Back", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));

            // intitialize options sub-menu
            m_optionsItems = new List<MenuItem>();
            m_optionsItems.Add(new MenuItem("Music", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_optionsItems[0].addOption("On");
            m_optionsItems[0].addOption("Off");
            m_optionsItems.Add(new MenuItem("Back", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));

            // initialize controls sub-menu
            m_controlsItems = new List<MenuItem>();
            m_controlsItems.Add(new MenuItem("Player 1 ", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_controlsItems.Add(new MenuItem("Player 2", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_controlsItems.Add(new MenuItem("Player 3", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_controlsItems.Add(new MenuItem("Player 4", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_controlsItems.Add(new MenuItem("Back", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            for(int i=0;i<4;i++) {
                m_controlsItems[i].addOption("WSAD");
                m_controlsItems[i].addOption("Arrows");
                m_controlsItems[i].addOption("C1");
                m_controlsItems[i].addOption("C2");
                m_controlsItems[i].addOption("C3");
                m_controlsItems[i].addOption("C4");
            }

            // initialize help sub-menu
            m_helpItems = new List<MenuItem>();
            m_helpItems.Add(new MenuItem("Destroy the Asteroids... or each other!", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_helpItems.Add(new MenuItem("Big Asteroids = 5 Points", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_helpItems.Add(new MenuItem("Small Asteroids = 10 Points", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_helpItems.Add(new MenuItem("Space Ships = 50 Points", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_helpItems.Add(new MenuItem("Back", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));

            // initialize menu location
            xPos = x;
            yPos = y;

            m_settings = settings;
            m_game = game;
            m_players = spaceShipSystem;

            // initialize initial menu item option selections
            m_optionsItems[0].index = (settings.musicEnabled) ? 0 : 1;
            for(int i=0;i<4;i++) {
                int itemIndex = 0;
                switch(m_settings.getInputDevice(i)) {
                    case InputDevice.WSAD:
                        itemIndex = 0;
                        break;
                    case InputDevice.Arrows:
                        itemIndex = 1;
                        break;
                    case InputDevice.Controller1:
                        itemIndex = 2;
                        break;
                    case InputDevice.Controller2:
                        itemIndex = 3;
                        break;
                    case InputDevice.Controller3:
                        itemIndex = 4;
                        break;
                    case InputDevice.Controller4:
                        itemIndex = 5;
                        break;
                }
                m_controlsItems[i].index = itemIndex;
            }
        }
Exemple #4
0
        // create the game menu at a specific location
        public Menu(int x, int y, Asteroids game, SpaceShipSystem spaceShipSystem, GameSettings settings, ContentManager content)
        {
            if (content == null)
            {
                return;
            }

            // initialize menu colours
            m_titleColour      = new Color(255, 0, 0);
            m_unselectedColour = new Color(160, 160, 160);
            m_selectedColour   = new Color(255, 255, 255);
            m_arrowColour      = new Color(0, 255, 0);

            // initialize menu fonts
            m_titleFont = content.Load <SpriteFont>("TitleFont");
            m_menuFont  = content.Load <SpriteFont>("MenuFont");

            // initialize menu sounds
            m_scrollSound = content.Load <SoundEffect>("menu_scroll");
            m_selectSound = content.Load <SoundEffect>("menu_select");
            m_backSound   = content.Load <SoundEffect>("menu_back");

            // initialize main menu
            m_mainItems = new List <MenuItem>();
            m_mainItems.Add(new MenuItem("New Game", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_mainItems.Add(new MenuItem("Resume Game", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_mainItems.Add(new MenuItem("Options", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_mainItems.Add(new MenuItem("Controls", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_mainItems.Add(new MenuItem("Help", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_mainItems.Add(new MenuItem("Quit", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));

            // initialize new game sub-menu
            m_newGameItems = new List <MenuItem>();
            m_newGameItems.Add(new MenuItem("1 Player", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_newGameItems.Add(new MenuItem("2 Player", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_newGameItems.Add(new MenuItem("3 Player", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_newGameItems.Add(new MenuItem("4 Player", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_newGameItems.Add(new MenuItem("Back", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));

            // intitialize options sub-menu
            m_optionsItems = new List <MenuItem>();
            m_optionsItems.Add(new MenuItem("Music", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_optionsItems[0].addOption("On");
            m_optionsItems[0].addOption("Off");
            m_optionsItems.Add(new MenuItem("Back", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));

            // initialize controls sub-menu
            m_controlsItems = new List <MenuItem>();
            m_controlsItems.Add(new MenuItem("Player 1 ", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_controlsItems.Add(new MenuItem("Player 2", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_controlsItems.Add(new MenuItem("Player 3", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_controlsItems.Add(new MenuItem("Player 4", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_controlsItems.Add(new MenuItem("Back", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            for (int i = 0; i < 4; i++)
            {
                m_controlsItems[i].addOption("WSAD");
                m_controlsItems[i].addOption("Arrows");
                m_controlsItems[i].addOption("C1");
                m_controlsItems[i].addOption("C2");
                m_controlsItems[i].addOption("C3");
                m_controlsItems[i].addOption("C4");
            }

            // initialize help sub-menu
            m_helpItems = new List <MenuItem>();
            m_helpItems.Add(new MenuItem("Destroy the Asteroids... or each other!", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_helpItems.Add(new MenuItem("Big Asteroids = 5 Points", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_helpItems.Add(new MenuItem("Small Asteroids = 10 Points", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_helpItems.Add(new MenuItem("Space Ships = 50 Points", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));
            m_helpItems.Add(new MenuItem("Back", m_menuFont, m_unselectedColour, m_selectedColour, m_arrowColour));

            // initialize menu location
            xPos = x;
            yPos = y;

            m_settings = settings;
            m_game     = game;
            m_players  = spaceShipSystem;

            // initialize initial menu item option selections
            m_optionsItems[0].index = (settings.musicEnabled) ? 0 : 1;
            for (int i = 0; i < 4; i++)
            {
                int itemIndex = 0;
                switch (m_settings.getInputDevice(i))
                {
                case InputDevice.WSAD:
                    itemIndex = 0;
                    break;

                case InputDevice.Arrows:
                    itemIndex = 1;
                    break;

                case InputDevice.Controller1:
                    itemIndex = 2;
                    break;

                case InputDevice.Controller2:
                    itemIndex = 3;
                    break;

                case InputDevice.Controller3:
                    itemIndex = 4;
                    break;

                case InputDevice.Controller4:
                    itemIndex = 5;
                    break;
                }
                m_controlsItems[i].index = itemIndex;
            }
        }