private void NewLevel() { gameLevel++; //Reset game sounds shipSounds = Sounds.ShipHum; gameSounds = Sounds.LevelStart; soundHandler.Play(shipSounds | gameSounds); DisplayLevel(gameLevel); //Remove all sprites from the sprite manager's list sm.Clear(); //Create new entities NewShip(); for (int i = 0; i < gameLevel; i++) { s = new DonutSprite(donutTileSet); s.CollisionxExtent = 24; //make collision box smaller s.CollisionyExtent = 24; s.PositionY = rnd.Next(donutTileSet.ExtentY * 4, this.Height - donutTileSet.ExtentY * 4); s.PositionX = rnd.Next(donutTileSet.ExtentX * 4, this.Width - donutTileSet.ExtentX * 4); s.Angle = (float)rnd.Next(10, 350); s.Velocity = (float)rnd.Next(75, 150); s.CanCollide = false; totalTargets++; sm.AddSprite(s); } shipSounds = 0; gameSounds = 0; hrt.Reset(); }
public void CollisionTest() { //iterate through first half of sprites for complete collision coverage for (int i = 0; i < sprites.Count; i++) { BasicSprite sprite1 = (BasicSprite)sprites[i]; if (sprite1.CanCollide && sprite1.Visible) { int sprite1Height = sprite1.CollisionyExtent; int sprite1Width = sprite1.CollisionxExtent; for (int j = 0; j < sprites.Count; j++) { BasicSprite sprite2 = (BasicSprite)sprites[j]; if (sprite2.Visible && !sprite2.CanCollide) //don't check two collidable sprites { int sprite2Height = sprite2.CollisionyExtent; int sprite2Width = sprite2.CollisionxExtent; //Simple AABB Collision Check float deltaX = Math.Abs(sprite1.PositionX - sprite2.PositionX); float deltaY = Math.Abs(sprite1.PositionY - sprite2.PositionY); if ((deltaX <= (sprite2Width + sprite1Width) && (deltaY <= (sprite2Height + sprite1Height)))) { OnCollisionDetected(sprite1, sprite2); //invoke delegate } } } } } }
private void CollisionHandler(BasicSprite s1, BasicSprite s2) { //Check to see if a bullet or ship is hitting a target object BasicSprite collidable; BasicSprite target; if ((s1.GetType() == typeof(ShipSprite)) || (s1.GetType() == typeof(BulletSprite))) { collidable = s1; target = s2; } else { collidable = s2; target = s1; } //remove the bullet/ship from collision checking and take off list collidable.Visible = false; //will be ignored for future collisions collidable.DurationOver = true; //will be removed at next update //if it was a ship, take away a life and restart the ship if (collidable.GetType() == typeof(ShipSprite)) { shipSounds = Sounds.ShipExplode; ship.Visible = false; //remove the ship from the sprite manager ship.DurationOver = true; //subtract a life livesRemaining--; //now make a new ship NewShip(); } //Blow up object Destroy(target); }
private void Destroy(BasicSprite sprite) { totalTargets--; gameSounds = 0; //clear out game sounds //sprite type should be: donut, pyramid, cube, or sphere if (sprite.GetType() == typeof(DonutSprite)) { for (int i = 0; i < 3; i++) { s = new PyramidSprite(pyramidTileSet); s.PositionY = sprite.PositionY; s.PositionX = sprite.PositionX; s.Angle = (float)rnd.Next(0, 359); s.Velocity = (float)rnd.Next(30, 200); sm.AddSprite(s); totalTargets++; gameSounds |= Sounds.DonutExplode; } totalScore += 10; } else if (sprite.GetType() == typeof(PyramidSprite)) { for (int i = 0; i < 2; i++) { s = new CubeSprite(cubeTileSet); s.PositionY = sprite.PositionY; s.PositionX = sprite.PositionX; s.Angle = (float)rnd.Next(0, 359); s.Velocity = (float)rnd.Next(30, 200); s.Visible = true; sm.AddSprite(s); totalTargets++; gameSounds |= Sounds.PyramidExplode; } totalScore += 20; } else if (sprite.GetType() == typeof(CubeSprite)) { for (int i = 0; i < 2; i++) { s = new SphereSprite(sphereTileSet); s.PositionY = sprite.PositionY; s.PositionX = sprite.PositionX; s.Angle = (float)rnd.Next(0, 359); s.Velocity = (float)rnd.Next(50, 200); sm.AddSprite(s); totalTargets++; gameSounds |= Sounds.CubeExplode; } totalScore += 10; } else if (sprite.GetType() == typeof(SphereSprite)) { totalScore += 10; gameSounds |= Sounds.SphereExplode; } sprite.Visible = false; //will be ignored for future collisions sprite.DurationOver = true; //will be removed at next update }
public void Update(float DeltaTime) { for (int i = 0; i < sprites.Count; i++) { BasicSprite sprite = (BasicSprite)sprites[i]; sprite.Update(DeltaTime); if (sprite.DurationOver) { sprites.RemoveAt(i); } else if (bounceSprites) { sprite.BoundaryCheck(world); } } }
private void NewLevel() { gameLevel++; //Reset game sounds shipSounds = Sounds.ShipHum; gameSounds = Sounds.LevelStart; soundHandler.Play(shipSounds | gameSounds); DisplayLevel(gameLevel); //Remove all sprites from the sprite manager's list sm.Clear(); //Create new entities NewShip(); for(int i = 0; i < gameLevel; i++) { s = new DonutSprite(donutTileSet); s.CollisionxExtent = 24; //make collision box smaller s.CollisionyExtent = 24; s.PositionY = rnd.Next(donutTileSet.ExtentY*4, this.Height-donutTileSet.ExtentY*4); s.PositionX = rnd.Next(donutTileSet.ExtentX*4, this.Width-donutTileSet.ExtentX*4); s.Angle = (float)rnd.Next(10, 350); s.Velocity = (float) rnd.Next(75, 150); s.CanCollide = false; totalTargets++; sm.AddSprite(s); } shipSounds = 0; gameSounds = 0; hrt.Reset(); }
private void Destroy(BasicSprite sprite) { totalTargets--; gameSounds = 0; //clear out game sounds //sprite type should be: donut, pyramid, cube, or sphere if (sprite.GetType() == typeof(DonutSprite)) { for(int i = 0; i < 3; i++) { s = new PyramidSprite(pyramidTileSet); s.PositionY = sprite.PositionY; s.PositionX = sprite.PositionX; s.Angle = (float)rnd.Next(0, 359); s.Velocity = (float) rnd.Next(30, 200); sm.AddSprite(s); totalTargets++; gameSounds |= Sounds.DonutExplode; } totalScore += 10; } else if (sprite.GetType() == typeof(PyramidSprite)) { for(int i = 0; i < 2; i++) { s = new CubeSprite(cubeTileSet); s.PositionY = sprite.PositionY; s.PositionX = sprite.PositionX; s.Angle = (float)rnd.Next(0, 359); s.Velocity = (float) rnd.Next(30, 200); s.Visible = true; sm.AddSprite(s); totalTargets++; gameSounds |= Sounds.PyramidExplode; } totalScore += 20; } else if (sprite.GetType() == typeof(CubeSprite)) { for(int i = 0; i < 2; i++) { s = new SphereSprite(sphereTileSet); s.PositionY = sprite.PositionY; s.PositionX = sprite.PositionX; s.Angle = (float)rnd.Next(0, 359); s.Velocity = (float) rnd.Next(50, 200); sm.AddSprite(s); totalTargets++; gameSounds |= Sounds.CubeExplode; } totalScore += 10; } else if (sprite.GetType() == typeof(SphereSprite)) { totalScore += 10; gameSounds |= Sounds.SphereExplode; } sprite.Visible = false; //will be ignored for future collisions sprite.DurationOver = true; //will be removed at next update }
public void AddSprite(BasicSprite TargetSprite) { sprites.Add(TargetSprite); }