public void Update( PlayerShip player) { //Z, and X used to manipulate scale value of the camera for zooming if (Keyboard.GetState().IsKeyDown(Keys.Z)) { if (m_scale < 1.2) m_scale += 0.003f; } else if (Keyboard.GetState().IsKeyDown(Keys.X)) { if (m_scale > 0.4) m_scale -= 0.003f; } //C, and V used to manipulate the orientation of the camera if (Keyboard.GetState().IsKeyDown(Keys.C)) m_rotation += 0.005f; if (Keyboard.GetState().IsKeyDown(Keys.V)) m_rotation -= 0.005f; if (m_rotation >= 2.0f * (float)Math.PI || m_rotation <= -2.0f * (float)Math.PI) m_rotation = 0; m_cameraFocus = player.GetCenter(); //Translate once to focus position, rotate, scale, then translate again to center the camera on the focus. m_transform = Matrix.CreateTranslation(new Vector3(-m_cameraFocus.X, -m_cameraFocus.Y, 1.0f)) * Matrix.CreateRotationZ(m_rotation) * Matrix.CreateScale(new Vector3(m_scale, m_scale, 0)) * Matrix.CreateTranslation(new Vector3( m_view.Width/2, m_view.Height/2, 0)); }
public Collision( Main gameManager, LevelOne level, PlayerShip player, Minimap miniMap) { m_gameManager = gameManager; m_level = level; m_player = player; m_miniMap = miniMap; }
public EnemyShip( Texture2D shipTexture, Vector2 spawnPosition, Texture2D bulletTexture, PlayerShip player ) : base(shipTexture, spawnPosition) { m_rotation = 1.5f * (float)Math.PI; isAlive = true; m_velocity = Vector2.Zero; m_bulletTexture = bulletTexture; m_enemyMiniMapRectangle = Rectangle.Empty; m_evasionRectangle = Rectangle.Empty; m_enemyBullets = new LinkedList<Bullet>(); m_player = player; m_energy = 250; m_shipSpeed = 0.0f; //Very hack way of enforcing different movement around asteroids for different enemy ships (To avoid clutter) if (0.5 - LevelOne.worldRand.NextDouble() < 0) m_movementType = -1; else m_movementType = 1; }
//Level contains a specific number of asteroids (asteroidCount), and will contain the partition tree of the level objects (asteroids, enemies) //This is hack, when refactoring, add in a load content method within the level, and load in level required textures there public LevelOne( PlayerShip player, Texture2D levelMap, Texture2D asteroidTexture, Texture2D enemyShipTexture, Texture2D enemyBulletTexture) { //Set textures of objects the level requires m_mapTexture = levelMap; m_asteroidTexture = asteroidTexture; m_enemyShipTexture = enemyShipTexture; m_enemyBulletTexture = enemyBulletTexture; m_playerShip = player; //Set map position, and the entire map rectangle m_mapPosition = new Vector2(backGroundOriginX, backGroundOriginY); m_levelRectangle = new Rectangle((int)m_mapPosition.X, (int)m_mapPosition.Y, mapWidth, mapHeight); //Spawn asteroids onto map, and store asteroids in partition tree m_asteroidPartitionTree = new SpritePartitionTree<Asteroid>(m_levelRectangle); //Spawn asteroids onto map m_asteroids = new LinkedList<Asteroid>(); InitializeAsteroids(); //Spawn enemies onto map m_enemyShips = new LinkedList<EnemyShip>(); InitializeEnemies(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here //Load in player ship with bullet textures m_playerShip = new PlayerShip(Content.Load<Texture2D>("PlayerShip"), Content.Load<Texture2D>("Bullet"), Content.Load<Texture2D>("PlayerEnergy")); //Load in level one map with player, and required level textures, such as the asteroids, enemies, and enemy bullets //This is pretty hack, should probably call a LoadContent function within the level class, and initiate all required textures there. m_levelOne = new LevelOne(m_playerShip, Content.Load<Texture2D>("BasicBlueBackground"), Content.Load<Texture2D>("Asteroid"), Content.Load<Texture2D>("EnemyShip"), Content.Load<Texture2D>("EnemyBullet")); //Initialize player camera (focused on player) m_playerCamera = new PlayerCamera(GraphicsDevice.Viewport, 0.5f); //Load in mini map with level, camera, and required mini map textures such as... camera / enemies / allies //Mini-map needs handle to graphics device & spritebatch to initialize the map texture that will be drawn upon load m_miniMap = new Minimap(GraphicsDevice, spriteBatch, m_levelOne, m_playerCamera, Content.Load<Texture2D>("PlayerSphere"), Content.Load<Texture2D>("EnemySphere")); //Initialize collision engine, with ship, and level, and the minimap (to see if sprites should be displayed in the mini-map or not) m_collisionEngine = new Collision(this, m_levelOne, m_playerShip, m_miniMap); //Load in Screen management textures m_scrmngr_loadScreenText = Content.Load<Texture2D>("LoadingScreen"); m_scrmngr_gameOverScreen = Content.Load<Texture2D>("GameOverScreen"); }