public void Load(int id, CONST_TV_KEY upKey, CONST_TV_KEY downKey, CONST_TV_KEY leftKey, CONST_TV_KEY rightKey) { Id = id; UpKey = upKey; DownKey = downKey; LeftKey = leftKey; RightKey = rightKey; Bat = new Bat(_gameManager); }
/// <summary> /// Collision Manager custom constructor /// </summary> /// <param name="game">Main game variable</param> /// <param name="ball">Ball class instance</param> /// <param name="bat">Bat class instance</param> /// <param name="batTwo">Bat class instance Bat 2</param> /// <param name="hit">Hit Sound Effect</param> public CollisionManager(Game game, Ball ball, Bat bat, Bat batTwo, SoundEffect hit) : base(game) { this.ball = ball; this.bat = bat; this.batTwo = batTwo; this.hit = hit; }
/// <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 //Score texture needs to come before ball creation //Winning/Score Texture2D scoreTex = this.Content.Load <Texture2D>("images/Scorebar"); stage = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight - scoreTex.Height); SoundEffect winSound = this.Content.Load <SoundEffect>("sounds/applause1"); Vector2 position = new Vector2(0, (graphics.PreferredBackBufferHeight - scoreTex.Height)); this.font = this.Content.Load <SpriteFont>("fonts/SpriteFont1"); scoreSystem = new ScoreSystem(this, spriteBatch, font, scoreTex, winSound, position, stage); this.Components.Add(scoreSystem); //Ball creation ballTex = this.Content.Load <Texture2D>("Images/ball"); ballPos = new Vector2(stage.X / 2 - ballTex.Width / 2, stage.Y / 2 - ballTex.Height / 2); SoundEffect hit = this.Content.Load <SoundEffect>("sounds/click"); SoundEffect miss = this.Content.Load <SoundEffect>("sounds/ding"); ball = new Ball(this, spriteBatch, ballTex, ballPos, ballSpeed, stage, hit, miss, scoreSystem); this.Components.Add(ball); //Player creation player = 1; Texture2D batTex = this.Content.Load <Texture2D>("Images/BatLeft"); Vector2 batSpeed = new Vector2(0, 4); Vector2 batPos = new Vector2(batTex.Width * (float)1.2f, stage.Y / 2 - batTex.Height / 2); bat = new Bat(this, spriteBatch, batTex, batPos, batSpeed, stage, player); this.Components.Add(bat); player = 2; Texture2D batTexPTwo = this.Content.Load <Texture2D>("Images/BatRight"); Vector2 batSpeedPTwo = new Vector2(0, 4); Vector2 batPosPTwo = new Vector2(stage.X - batTexPTwo.Width * (float)2.4f, stage.Y / 2 - batTexPTwo.Height / 2); bat2 = new Bat(this, spriteBatch, batTexPTwo, batPosPTwo, batSpeedPTwo, stage, player); this.Components.Add(bat2); CollisionManager cm = new CollisionManager(this, ball, bat, bat2, hit); this.Components.Add(cm); }
public CollissionManager(Game game, Ball ball, Bat bat, string batName, SoundEffect clickSound ) : base(game) { this.ball = ball; this.bat = bat; this.batName = batName; this.clickSound = clickSound; }
public void Render() { Bat.Render(); }
public void Update(float inputX, float inputY) { Bat.Update(inputX, inputY); }
/// <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 //All contents loaded used in program SoundEffect clickSound = Content.Load <SoundEffect>("sounds/click"); SoundEffect dingSound = Content.Load <SoundEffect>("sounds/ding"); winSound = Content.Load <SoundEffect>("sounds/applause1"); font = Content.Load <SpriteFont>("fonts/myfont"); scoreBarTex = Content.Load <Texture2D>("images/scorebar"); Texture2D ballTex = Content.Load <Texture2D>("images/ball"); batRTex = Content.Load <Texture2D>("Images/BatRight"); batTex = Content.Load <Texture2D>("Images/BatLeft"); string message = ""; strPos = Vector2.Zero; stage = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight - scoreBarTex.Height); //ScorBar added at the bottom of screen Vector2 scoreBarPos = new Vector2(0, stage.Y); scoreBar = new ScoreBar(this, spriteBatch, scoreBarTex, scoreBarPos, stage); this.Components.Add(scoreBar); //Ball added at center of screen Vector2 ballPos = new Vector2(stage.X / 2 - ballTex.Width / 2, stage.Y / 2 - ballTex.Height / 2); Vector2 ballSpeed = Vector2.Zero; ball = new PongGame.Ball(this, spriteBatch, ballTex, ballPos, ballSpeed, stage, font, clickSound, dingSound); this.Components.Add(ball); //Right bat added at right center of screen batRPos = new Vector2(stage.X - batRTex.Width, stage.Y / 2 - batRTex.Height / 2); Vector2 batRSpeed = new Vector2(0, 4); rightBatName = "rightBat"; batRight = new Bat(this, spriteBatch, batRTex, batRPos, batRSpeed, stage, rightBatName); this.Components.Add(batRight); //Left bat added at left center of screen batPos = new Vector2(0, stage.Y / 2 - batTex.Height / 2); Vector2 batSpeed = new Vector2(0, 4); leftBatName = "leftBat"; batLeft = new Bat(this, spriteBatch, batTex, batPos, batSpeed, stage, leftBatName); this.Components.Add(batLeft); //handle collision cm1 = new CollissionManager(this, ball, batLeft, leftBatName, clickSound); this.Components.Add(cm1); //handle collision cm2 = new CollissionManager(this, ball, batRight, rightBatName, clickSound); this.Components.Add(cm2); ball.Counter = 1; // All strings used in program are added winner = new Winner(this, spriteBatch, font, strPos, message, Color.Purple); this.Components.Add(winner); score1 = new Score1(this, spriteBatch, font, strPos, message, Color.Black); this.Components.Add(score1); score2 = new Score2(this, spriteBatch, font, strPos, message, Color.Black); this.Components.Add(score2); }