public override void LoadContent() { if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); //Load the game font and HUD font gameFont = content.Load<SpriteFont>("gamefont"); HUDfont = content.Load<SpriteFont>("HUDFont"); //Load background music BGM[0] = soundBank.GetCue("BGM1"); BGM[1] = soundBank.GetCue("BGM2"); BGM[2] = soundBank.GetCue("BGM3"); BGM[3] = soundBank.GetCue("BGM4"); BGM[4] = soundBank.GetCue("BGM5"); BGM[5] = soundBank.GetCue("BGM6"); BGM[6] = soundBank.GetCue("BGM7"); BGM[7] = soundBank.GetCue("BGM8"); BGM[8] = soundBank.GetCue("BGM9"); //Set Powerup Textures and Music Player Textures Expander = content.Load<Texture2D>("Expander"); Decreaser = content.Load<Texture2D>("Decreaser"); AcidBall = content.Load<Texture2D>("AcidBall"); GoldenBall = content.Load<Texture2D>("GoldenBall"); BiggerBall = content.Load<Texture2D>("BigBall"); SmallerBall = content.Load<Texture2D>("SmallBall"); AddLife = content.Load<Texture2D>("AddLife"); tMusicPlayer = content.Load<Texture2D>("MusicPlayer"); tMusicPlayerOff = content.Load<Texture2D>("MusicPlayerOff"); //Instantiate multiple models for Ball,Block and Player model arrays mBall = new Model[5]; mBlock = new Model[4]; mPlayer = new Model[3]; //Load the afformentioned models into content mPlayer[0] = content.Load<Model>("Models/Player"); mPlayer[1] = content.Load<Model>("Models/BigPlayer"); mPlayer[2] = content.Load<Model>("Models/SmallPlayer"); mArena = content.Load<Model>("Models/Arena"); mKillZone = content.Load <Model>("Models/KillZone"); mBall[0] = content.Load<Model>("Models/NormalBall"); mBall[1] = content.Load <Model>("Models/AcidBall"); mBall[2] = content.Load<Model>("Models/GoldBall"); mBall[3] = content.Load<Model>("Models/BigBall"); mBall[4] = content.Load<Model>("Models/SmallBall"); mBlock[0] = content.Load<Model>("Models/BlockLvl1"); mBlock[1] = content.Load<Model>("Models/BlockLvl2"); mBlock[2] = content.Load<Model>("Models/BlockLvl3"); mBlock[3] = content.Load<Model>("Models/BlockUnbreakable"); //Create 30 blocks to be destroyed Blocks = new cls3DObject[30]; //Create a new arena Arena = new cls3DObject(1, new Vector3(20f, 2f, 40f), true, graphicsDevice, WorldMatrix); //Create the music player animation MusicPlayer = new clsDrops(15, tMusicPlayer, new Vector2(435, 133), new Vector2(155, 24), Vector2.Zero, 4); MusicPlayer.Show(); //Add models to various instantiated objects Arena.AddModel(ref mArena, 0); for (int i = 0; i < Blocks.Length; i++) { Blocks[i] = new cls3DObject(4, new Vector3(2, 1, 1), true, graphicsDevice, WorldMatrix); Blocks[i].AddModel(ref mBlock[0], 0); Blocks[i].AddModel(ref mBlock[1], 1); Blocks[i].AddModel(ref mBlock[2], 2); Blocks[i].AddModel(ref mBlock[3], 3); } Player = new cls3DObject(3, new Vector3(2.5f, 2, 2), true, graphicsDevice, WorldMatrix); Player.AddModel(ref mPlayer[0], 0); Player.AddModel(ref mPlayer[1], 1); Player.AddModel(ref mPlayer[2], 2); Ball = new cls3DObject(5, new Vector3(0.5f, 0.5f, 0.5f), true, graphicsDevice, WorldMatrix); Ball.AddModel(ref mBall[0], 0); Ball.AddModel(ref mBall[1], 1); Ball.AddModel(ref mBall[2], 2); Ball.AddModel(ref mBall[3], 3); Ball.AddModel(ref mBall[4], 4); KillZone = new cls3DObject(1, new Vector3(20f, 1, 3f), true, graphicsDevice, WorldMatrix); KillZone.AddModel(ref mKillZone, 0); HealthViewer = new cls3DObject(1, new Vector3(3f, 2, 2), true, graphicsDevice, WorldMatrix); HealthViewer.AddModel(ref mPlayer[0], 0); //Prepare game for first play Arena.SetPosition(new Vector3(-10, 0, -20)); Arena.SetRotation(new Vector3(0, 0, 0)); if (GameType <= 0) { Level = 0; Player.SetHealth(3); GetLevelLayout(); } else { for (int i = 0; i < Blocks.Length; i++) Blocks[i].Hide(); numtoshow = Blocks.Length -1; Player.SetHealth(0); GetAssaultLayout(); } Player.SetPosition(new Vector3(-1,0,16)); SetPlayerCarry = true; Ball.SetPosition(new Vector3(Player.GetPosition().X + (Player.GetSize().X / 2), Ball.GetPosition().Y, 14.5f)); KillZone.SetPosition(new Vector3(-10,-1,20)); HealthViewer.SetScale(0.5f); Thread.Sleep(1000); ScreenManager.Game.ResetElapsedTime(); }
//Determine if an internal object has hit the wall of an eclosing object //Determine if an internal object has hit the wall of an eclosing object public bool InternalCollision(cls3DObject otherModel, int scalar) { if (otherModel.isVisible()) { BoundingBox tester = boundingBox; tester.Max += Velocity*scalar; tester.Min += Velocity*scalar; if (tester.Max.X > otherModel.boundingBox.Max.X || tester.Max.Y > otherModel.boundingBox.Max.Y || tester.Max.Z > otherModel.boundingBox.Max.Z || tester.Min.X < otherModel.boundingBox.Min.X || tester.Min.Y < otherModel.boundingBox.Min.Y || tester.Min.Z < otherModel.boundingBox.Min.Z) return true; } return false; }
//Collision Detection //Objects within objects, hitting object walls. public void InternalBounce(cls3DObject otherModel) { if (Position.X + Size.X > otherModel.Position.X + otherModel.Size.X || Position.X > otherModel.Position.X + otherModel.Size.X) if (Velocity.X > 0) Velocity.X = -Velocity.X; if (Position.X < otherModel.Position.X || Position.X + Size.X<otherModel.Position.X) if (Velocity.X <= 0) Velocity.X = -Velocity.X; if (Position.Y + Size.Y > otherModel.Position.Y + otherModel.Size.Y || Position.Y > otherModel.Position.Y + otherModel.Size.Y) if (Velocity.Y > 0) Velocity.Y = -Velocity.Y; if (Position.Y < otherModel.Position.Y || Position.Y + Size.Y < otherModel.Position.Y) if (Velocity.Y < 0) Velocity.Y = -Velocity.Y; if (Position.Z + Size.Z > otherModel.Position.Z + otherModel.Size.Z || Position.Z > otherModel.Position.Z + otherModel.Size.Z) if (Velocity.Z > 0) Velocity.Z = -Velocity.Z; if (Position.Z < otherModel.Position.Z || Position.Z + Size.Z < otherModel.Position.Z) if (Velocity.Z < 0) Velocity.Z = -Velocity.Z; Move(); }
//Objects colliding with objects that have a flat surface public void ExtFlatSurfaceBounce(cls3DObject otherModel) { if (Position.X < otherModel.Position.X + otherModel.Size.X && Position.X + Size.X > otherModel.Position.X + otherModel.Size.X) if(Velocity.X<0) Velocity.X = -Velocity.X; if (Position.X + Size.X > otherModel.Position.X && Position.X < otherModel.Position.X) if (Velocity.X >= 0) Velocity.X = -Velocity.X; if (Position.Y < otherModel.Position.Y + otherModel.Size.Y && Position.Y + Size.Y > otherModel.Position.Y + otherModel.Size.Y) if (Velocity.Y < 0) Velocity.Y = -Velocity.Y; if (Position.Y + Size.Y > otherModel.Position.Y && Position.Y < otherModel.Position.Y) if (Velocity.Y >= 0) Velocity.Y = -Velocity.Y; if (Position.Z < otherModel.Position.Z + otherModel.Size.Z && Position.Z + Size.Z > otherModel.Position.Z + otherModel.Size.Z) if (Velocity.Z < 0) Velocity.Z = -Velocity.Z; if (Position.Z + Size.Z > otherModel.Position.Z && Position.Z < otherModel.Position.Z) if (Velocity.Z >= 0) Velocity.Z = -Velocity.Z; Move(); }
//Determine if a collision between two objects has been made c public bool ExternalCollision(cls3DObject otherModel, int scalar) { if (otherModel.isVisible()) { BoundingBox tester = boundingBox; tester.Max += Velocity * scalar; tester.Min += Velocity * scalar; if (tester.Intersects(otherModel.boundingBox)) return true; } return false; }
//Objects colliding with objects that have a curved surface public void ExtCurvedSurfaceBounce(cls3DObject otherModel) { ObjCollision = -(otherModel.Position - Position); CollidePercent.X = (float)Math.Floor((ObjCollision.X / otherModel.Size.X) * 100); if (Position.X < otherModel.Position.X + otherModel.Size.X && Position.X + Size.X > otherModel.Position.X + otherModel.Size.X) if (Velocity.X < 0) Velocity.X = -Velocity.X; if (Position.X + Size.X > otherModel.Position.X && Position.X < otherModel.Position.X) if (Velocity.X >= 0) Velocity.X = -Velocity.X; if (Position.Y < otherModel.Position.Y + otherModel.Size.Y && Position.Y + Size.Y > otherModel.Position.Y + otherModel.Size.Y) if (Velocity.Y < 0) Velocity.Y = -Velocity.Y; if (Position.Y + Size.Y > otherModel.Position.Y && Position.Y < otherModel.Position.Y) if (Velocity.Y >= 0) Velocity.Y = -Velocity.Y; if (Position.Z < otherModel.Position.Z + otherModel.Size.Z && Position.Z + Size.Z > otherModel.Position.Z + otherModel.Size.Z) { if (CollidePercent.X >= 0 && CollidePercent.X < 10) { Velocity.Z = Speed * 0.2f; Velocity.X = Speed * -0.8f; } else if (CollidePercent.X >= 10 && CollidePercent.X < 20) { Velocity.Z = Speed * 0.4f; Velocity.X = Speed * -0.6f; } else if (CollidePercent.X >= 20 && CollidePercent.X < 30) { Velocity.Z = Speed * 0.6f; Velocity.X = Speed * -0.4f; } else if (CollidePercent.X >= 30 && CollidePercent.X < 40) { Velocity.Z = Speed * 0.8f; Velocity.X = Speed * -0.2f; } else if (CollidePercent.X >= 40 && CollidePercent.X < 50) { Velocity.Z = Speed * 1f; Velocity.X = Speed * 0f; } else if (CollidePercent.X >= 50 && CollidePercent.X < 60) { Velocity.Z = Speed * 1f; Velocity.X = Speed * 0f; } else if (CollidePercent.X >= 60 && CollidePercent.X < 70) { Velocity.Z = Speed * 0.8f; Velocity.X = Speed * 0.2f; } else if (CollidePercent.X >= 70 && CollidePercent.X < 80) { Velocity.Z = Speed * 0.6f; Velocity.X = Speed * 0.4f; } else if (CollidePercent.X >= 80 && CollidePercent.X < 90) { Velocity.Z = Speed * 0.4f; Velocity.X = Speed * 0.6f; } else if (CollidePercent.X >= 90) { Velocity.Z = Speed * 0.2f; Velocity.X = Speed * 0.8f; } } else if (Position.Z + Size.Z > otherModel.Position.Z && Position.Z < otherModel.Position.Z) { if (CollidePercent.X <= 10) { Velocity.Z = Speed * -0.2f; Velocity.X = Speed * -0.8f; } else if (CollidePercent.X >= 10 && CollidePercent.X < 20) { Velocity.Z = Speed * -0.4f; Velocity.X = Speed * -0.6f; } else if (CollidePercent.X >= 20 && CollidePercent.X < 30) { Velocity.Z = Speed * -0.6f; Velocity.X = Speed * -0.4f; } else if (CollidePercent.X >= 30 && CollidePercent.X < 40) { Velocity.Z = Speed * -0.8f; Velocity.X = Speed * -0.2f; } else if (CollidePercent.X >= 40 && CollidePercent.X < 50) { Velocity.Z = Speed * -1f; Velocity.X = Speed * 0f; } else if (CollidePercent.X >= 50 && CollidePercent.X < 60) { Velocity.Z = Speed * -1f; Velocity.X = Speed * 0f; } else if (CollidePercent.X >= 60 && CollidePercent.X < 70) { Velocity.Z = Speed * -0.8f; Velocity.X = Speed * 0.2f; } else if (CollidePercent.X >= 70 && CollidePercent.X < 80) { Velocity.Z = Speed * -0.6f; Velocity.X = Speed * 0.4f; } else if (CollidePercent.X >= 80 && CollidePercent.X < 90) { Velocity.Z = Speed * -0.4f; Velocity.X = Speed * 0.6f; } else if (CollidePercent.X >= 90) { Velocity.Z = Speed * -0.2f; Velocity.X = Speed * 0.8f; } } Move(); }