public Explosion(Vector2 position, Vector2 velocity, SpriteSheet spriteSheet) { m_explosion = new SpriteAnimation(0.17f, SpriteAnimationType.Single, spriteSheet); this.position = position; this.velocity = velocity; }
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 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 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(); }