public CollisionManager(Game game, Car car, GameCar car1, GameCar car2, GameCar car3, Vector2 stage) : base(game) { // TODO: Construct any child components here this.car = car; this.car1 = car1; this.car2 = car2; this.car3 = car3; this.stage = stage; }
public TwoPlayerGame(Game game, SpriteBatch spriteBatch) : base(game) { // TODO: Construct any child components here this.spriteBatch = spriteBatch; creamcar = game.Content.Load <Texture2D>("images/creamcar"); purplecar = game.Content.Load <Texture2D>("images/purplecar"); redcar = game.Content.Load <Texture2D>("images/redcar"); yellowcar = game.Content.Load <Texture2D>("images/yellowcar"); greencar = game.Content.Load <Texture2D>("images/greencar"); bluecar = game.Content.Load <Texture2D>("images/bluecar"); orangecar = game.Content.Load <Texture2D>("images/orangecar"); policecar = game.Content.Load <Texture2D>("images/policecar"); lefthorn = game.Content.Load <SoundEffect>("sounds/Horn"); righthorn = game.Content.Load <SoundEffect>("sounds/Horn"); exploSound = game.Content.Load <SoundEffect>("sounds/expl06"); boomtex = game.Content.Load <Texture2D>("images/explosion.hasgraphics"); Rectangle leftroadRect = new Rectangle(0, 100, 376, 478); Vector2 leftRoadPos = new Vector2(100, 0); Rectangle rightroadRect = new Rectangle(0, 100, 376, 478); Vector2 rightRoadPos = new Vector2(475, 0); leftroad = new Road(game, spriteBatch, game.Content.Load <Texture2D>("images/goodroad"), leftroadRect, leftRoadPos, new Vector2(0, 0)); rightroad = new Road(game, spriteBatch, game.Content.Load <Texture2D>("images/goodroad"), rightroadRect, rightRoadPos, new Vector2(0, 0)); //Player cars leftcarstartpos = new Vector2(260, 375); Vector2 leftcarspd = new Vector2(5, 0); leftcar = new Car(game, spriteBatch, greencar, leftcarstartpos, leftcarspd); rightcarstartpos = new Vector2(635, 375); Vector2 rightcarspd = new Vector2(5, 0); rightcar = new Car(game, spriteBatch, redcar, rightcarstartpos, rightcarspd); //Player cars// // Computer cars //Left Cars leftcarleftbounds = 130; leftcarrightbounds = 389; Vector2 leftc1pos = new Vector2(-1, -105); Vector2 leftc1spd = new Vector2(0, +8); leftc1 = new GameCar(game, spriteBatch, leftrandomcar, leftc1pos, leftcarleftbounds, leftcarrightbounds, 1, 4); Vector2 leftc2pos = new Vector2(-1, -105); Vector2 leftc2spd = new Vector2(0, +2); leftc2 = new GameCar(game, spriteBatch, leftrandomcar, leftc2pos, leftcarleftbounds, leftcarrightbounds, 1, 4); Vector2 leftc3pos = new Vector2(-1, -105); Vector2 leftc3spd = new Vector2(0, +4); leftc3 = new GameCar(game, spriteBatch, leftrandomcar, leftc3pos, leftcarleftbounds, leftcarrightbounds, 1, 4); //Right Cars rightcarleftbounds = 503; rightcarrightbounds = 762; Vector2 rightc1pos = new Vector2(-1, -105); Vector2 rightc1spd = new Vector2(0, +2); rightc1 = new GameCar(game, spriteBatch, rightrandomcar, rightc1pos, rightcarleftbounds, rightcarrightbounds, 1, 4); Vector2 rightc2pos = new Vector2(-1, -105); Vector2 rightc2spd = new Vector2(0, +2); rightc2 = new GameCar(game, spriteBatch, rightrandomcar, rightc2pos, rightcarleftbounds, rightcarrightbounds, 1, 4); Vector2 rightc3pos = new Vector2(-1, -105); Vector2 rightc3spd = new Vector2(0, +2); rightc3 = new GameCar(game, spriteBatch, rightrandomcar, rightc3pos, rightcarleftbounds, rightcarrightbounds, 1, 4); //Computer Cars// Vector2 exppos = new Vector2(0, 0); explosion = new Explosion(game, spriteBatch, boomtex, exppos, 1); rightcm = new CollisionManager(game, rightcar, rightc1, rightc2, rightc3, Stage.size); this.Components.Add(rightcm); leftcm = new CollisionManager(game, leftcar, leftc1, leftc2, leftc3, Stage.size); this.Components.Add(leftcm); Vector2 leftscorePos = new Vector2(0, 0); leftScoreMsg = "Left Score\n" + leftscorecount.ToString(); leftscore = new ScoreString(game, spriteBatch, leftScoreMsg, leftscorePos, Color.White, game.Content.Load <SpriteFont>("fonts/StandardMenuFont")); rightScoreMsg = "Right Score\n" + rightscorecount.ToString(); Vector2 rightscorePos = new Vector2(Stage.size.X - 140, 0); rightscore = new ScoreString(game, spriteBatch, rightScoreMsg, rightscorePos, Color.White, game.Content.Load <SpriteFont>("fonts/StandardMenuFont")); gameOverTwoPayerMsg = ""; gameOverFont = game.Content.Load <SpriteFont>("fonts/bigfont"); Vector2 gameOverPos = new Vector2(Stage.size.X / 2 - gameOverFont.MeasureString(gameOverTwoPayerMsg).X - 150, Stage.size.Y / 2 - gameOverFont.LineSpacing); gameOverTwoPlayer = new ScoreString(game, spriteBatch, gameOverTwoPayerMsg, gameOverPos, Color.White, gameOverFont); winVec = new Vector2(315, 230); winString = new ScoreString(game, spriteBatch, "", winVec, Color.Red, game.Content.Load <SpriteFont>("fonts/winner")); spacePos = new Vector2(346, 230); pressSpaceBar = new ScoreString(game, spriteBatch, "Press SpaceBar to start", spacePos, Color.White, game.Content.Load <SpriteFont>("fonts/StandardMenuFont")); this.Components.Add(leftroad); this.Components.Add(rightroad); this.Components.Add(leftcar); this.Components.Add(rightcar); this.Components.Add(leftc1); this.Components.Add(leftc2); this.Components.Add(leftc3); this.Components.Add(rightc1); this.Components.Add(rightc2); this.Components.Add(rightc3); this.Components.Add(explosion); this.Components.Add(leftscore); this.Components.Add(rightscore); this.Components.Add(gameOverTwoPlayer); this.Components.Add(pressSpaceBar); this.Components.Add(winString); }
public GamePlay(Game game, SpriteBatch spriteBatch) : base(game) { // TODO: Construct any child components here this.spriteBatch = spriteBatch; creamcar = game.Content.Load <Texture2D>("images/creamcar"); purplecar = game.Content.Load <Texture2D>("images/purplecar"); redcar = game.Content.Load <Texture2D>("images/redcar"); yellowcar = game.Content.Load <Texture2D>("images/yellowcar"); greencar = game.Content.Load <Texture2D>("images/greencar"); bluecar = game.Content.Load <Texture2D>("images/bluecar"); orangecar = game.Content.Load <Texture2D>("images/orangecar"); policecar = game.Content.Load <Texture2D>("images/policecar"); boomtex = game.Content.Load <Texture2D>("images/explosion.hasgraphics"); horn = game.Content.Load <SoundEffect>("sounds/Horn"); policesound = game.Content.Load <SoundEffect>("sounds/policesound"); boomSound = game.Content.Load <SoundEffect>("sounds/expl06"); Rectangle roadRect = new Rectangle(0, 100, 376, 478); Vector2 roadpos = new Vector2(100, 0); roadspeed = new Vector2(0, 0); road = new Road(game, spriteBatch, game.Content.Load <Texture2D>("images/goodroad"), roadRect, roadpos, roadspeed); Vector2 opcar = new Vector2(-1, -105); Vector2 opcarspd = new Vector2(0, 0); int leftlimits = 130; int rightlimits = 389; car1 = new GameCar(game, spriteBatch, randomcar, opcar, leftlimits, rightlimits, 1, 4); Vector2 opcar2 = new Vector2(-1, -105); Vector2 opcarspd2 = new Vector2(0, 0); car2 = new GameCar(game, spriteBatch, randomcar, opcar2, leftlimits, rightlimits, 1, 4); Vector2 opcar3 = new Vector2(-1, -105); Vector2 opcarspd3 = new Vector2(0, 0); car3 = new GameCar(game, spriteBatch, randomcar, opcar3, leftlimits, rightlimits, 1, 4); carpos = new Vector2(260, 375); Vector2 carspd = new Vector2(5, 0); car = new Car(game, spriteBatch, game.Content.Load <Texture2D>("images/greencar"), carpos, carspd); boompos = new Vector2(100, 100); boom = new Explosion(game, spriteBatch, boomtex, boompos, 1); cm = new CollisionManager(game, car, car1, car2, car3, Stage.size); this.Components.Add(cm); scoreMsg = "Score \n" + scorecount.ToString(); Vector2 scorePos = new Vector2(0, 0); score = new ScoreString(game, spriteBatch, scoreMsg, scorePos, Color.White, game.Content.Load <SpriteFont>("fonts/StandardMenuFont")); gameOverMsg = ""; gameOverFont = game.Content.Load <SpriteFont>("fonts/bigfont"); Vector2 gameOverPos = new Vector2(Stage.size.X / 2 - gameOverFont.MeasureString(gameOverMsg).X - 150, Stage.size.Y / 2 - gameOverFont.LineSpacing); gameOver = new ScoreString(game, spriteBatch, gameOverMsg, gameOverPos, Color.White, gameOverFont); Vector2 spacePos = new Vector2(346, 230); pressSpaceBarOne = new ScoreString(game, spriteBatch, "Press SpaceBar to start", spacePos, Color.White, game.Content.Load <SpriteFont>("fonts/StandardMenuFont")); this.Components.Add(road); this.Components.Add(score); this.Components.Add(car1); this.Components.Add(car2); this.Components.Add(car3); this.Components.Add(car); this.Components.Add(boom); this.Components.Add(gameOver); this.Components.Add(pressSpaceBarOne); }