public ProjectileSystem(SpriteSheetCollection spriteSheets, GameSettings settings, ContentManager content) { m_projectiles = new List<Projectile>(); // load the projectile sprites and create an animation from them if(spriteSheets != null) { m_projectileSprites = spriteSheets.getSpriteSheet("Projectiles"); } if(m_projectileSprites != null) { m_projectileAnimations = new SpriteAnimation[4]; for(int i=0;i<4;i++) { m_projectileAnimations[i] = new SpriteAnimation(0.18f, SpriteAnimationType.Loop); m_projectileAnimations[i].addSprite(m_projectileSprites.getSprite(i * 2)); m_projectileAnimations[i].addSprite(m_projectileSprites.getSprite(i * 2 + 1)); } } // load the laser sound if(content != null) { m_laserSound = content.Load<SoundEffect>("Laser"); } m_settings = settings; }
public ScoreSystem(SpaceShipSystem spaceShipSystem, ContentManager content, GameSettings settings) { if(spaceShipSystem == null) { return; } m_players = spaceShipSystem; m_settings = settings; if(spaceShipSystem == null) { return; } // initialize the player scores m_score = new long[m_players.maxSpaceShips]; for(int i=0;i<m_score.Length;i++) { m_score[i] = 0; } // initialize the score colours m_colourRed = new Color(255, 0, 0); m_colourBlue = new Color(0, 0, 255); m_colourGreen = new Color(0, 255, 0); m_colourYellow = new Color(255, 255, 0); if(content == null) { return; } // load the score font m_scoreFont = content.Load<SpriteFont>("ScoreFont"); }
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(); }
public AsteroidSystem(SpriteSheetCollection spriteSheets, SpaceShipSystem spaceShipSystem, GameSettings settings) { m_asteroids = new List<Asteroid>(); if(spriteSheets != null) { m_asteroidSprites = spriteSheets.getSpriteSheet("Asteroids"); } m_spaceShipSystem = spaceShipSystem; m_settings = settings; m_maxSmallAsteroids = 12; m_maxBigAsteroids = 10; }
public Projectile(Vector2 position, float rotation, SpriteAnimation projectileAnimation, SpaceShip projectileSource, GameSettings settings) { m_projectile = projectileAnimation; this.position = position; this.rotation = rotation; m_projectileSource = projectileSource; m_settings = settings; // set the acceleration and velocity of the projectile m_acceleration = 9.0f; m_velocity.X = (float) (m_acceleration * Math.Cos(MathHelper.ToRadians(m_rotation - 90))); m_velocity.Y = (float) (m_acceleration * Math.Sin(MathHelper.ToRadians(m_rotation - 90))); m_offset = new Vector2(2.0f, 2.0f); m_size = new Vector2(4.0f, 4.0f); }
public SpaceShipSystem(int numberOfSpaceShips, SpriteSheetCollection spriteSheets, ProjectileSystem projectileSystem, GameSettings settings, ContentManager content) { this.numberOfSpaceShips = numberOfSpaceShips; if(spriteSheets != null) { m_spaceShipSprites = spriteSheets.getSpriteSheet("SpaceShip"); } m_projectileSystem = projectileSystem; m_settings = settings; // initialize all space ships if(m_settings == null || content == null || m_spaceShipSprites == null) { return; } m_spaceShips = new SpaceShip[m_maxSpaceShips]; m_spaceShips[0] = new SpaceShip(PlayerIndex.One, new Vector2(settings.screenWidth * 0.2f, settings.screenHeight * 0.2f), 135, m_spaceShipSprites, projectileSystem, settings, content); m_spaceShips[1] = new SpaceShip(PlayerIndex.Two, new Vector2(settings.screenWidth * 0.8f, settings.screenHeight * 0.8f), -45, m_spaceShipSprites, projectileSystem, settings, content); m_spaceShips[2] = new SpaceShip(PlayerIndex.Three, new Vector2(settings.screenWidth * 0.2f, settings.screenHeight * 0.8f), 45, m_spaceShipSprites, projectileSystem, settings, content); m_spaceShips[3] = new SpaceShip(PlayerIndex.Four, new Vector2(settings.screenWidth * 0.8f, settings.screenHeight * 0.2f), -135, m_spaceShipSprites, projectileSystem, settings, content); }
public Asteroid(Sprite sprite, bool isBigAsteroid, GameSettings settings) { m_sprite = sprite; m_bigAsteroid = isBigAsteroid; m_activeCollisions = new List<Asteroid>(); m_settings = settings; Random rand = new Random(); if(settings == null) { return; } m_position = new Vector2(rand.Next(0, settings.screenWidth), rand.Next(0, settings.screenHeight)); m_scale = new Vector2(1.0f, 1.0f); switch(rand.Next(0, 2)) { case 0: m_rotationDirection = RotationDirection.Clockwise; break; case 1: m_rotationDirection = RotationDirection.CounterClockwise; break; } float minRotationStep = 0.3153f; float maxRotationStep = 0.4584f; m_rotationSpeed = (float) (rand.NextDouble() * (maxRotationStep - minRotationStep)) + minRotationStep; m_rotation = (float) rand.NextDouble() * 359.0f; m_acceleration = 0; float minVelocity = (float) (rand.NextDouble() * 0.3f) + 0.08f; float maxVelocity = (float) (rand.NextDouble() * 2.5f) + 0.8f; float xVelocity = (float) ( (((rand.Next(0, 2) % 2) == 0) ? 1 : -1) * (rand.NextDouble() * (maxVelocity - minVelocity) + minVelocity) ); float yVelocity = (float) ( (((rand.Next(0, 2) % 2) == 0) ? 1 : -1) * (rand.NextDouble() * (maxVelocity - minVelocity) + minVelocity) ); m_velocity = new Vector2(xVelocity, yVelocity); if(m_sprite == null) { return; } m_offset = new Vector2(m_sprite.xOffset * 0.9f, m_sprite.yOffset * 0.9f); m_size = new Vector2(m_offset.X * 2.0f, m_offset.Y * 2.0f); }
public Asteroids() { settings = new GameSettings(); graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services, "Content"); }
// 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; } }
// create the game menu at the default location public Menu(Asteroids game, SpaceShipSystem spaceShipSystem, GameSettings settings, ContentManager content) : this(150, 150, game, spaceShipSystem, settings, content) { }
public SpaceShipSystem(SpriteSheetCollection spriteSheets, ProjectileSystem projectileSystem, GameSettings settings, ContentManager content) : this(0, spriteSheets, projectileSystem, settings, content) { }