Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmistervirtue

Posted 11 October 2012 - 11:07 AM

This is my BasePaddle Class. My Parent Class
----------------
[source lang="csharp"] abstract class BasePaddle { //Texture For the Block Texture2D texture; //Postion of the Block Vector2 postion; //Directoin of the Block Vector2 direction; //Collision Rectangle for the block Rectangle screenBounds; //Speed of Paddle Movement float paddleSpeed = 20;public BasePaddle(Texture2D texture, Rectangle screenBounds, Vector2 direction, Vector2 postion) { this.texture = texture; this.screenBounds = screenBounds; this.direction = direction; this.postion = postion; } public virtual void Update() { direction = Vector2.Zero; direction.Y *= paddleSpeed; postion += direction; } public virtual Rectangle GetBounds() { return new Rectangle( (int)postion.X, (int)postion.Y, texture.Width, texture.Height); } public virtual void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(texture, postion, Color.White); } }[/source]

----------------
This is my Child Class PlayerPaddle
[source lang="csharp"] class Paddle : BasePaddle { //Texture For the Block Texture2D texture; //Postion of the Block Vector2 postion; //Directoin of the Block Vector2 direction; //Collision Rectangle for the block Rectangle screenBounds; //Speed of Paddle Movement float paddleSpeed = 20; //INPUT KeyboardState keyboardState; //Consturotor for Paddle public Paddle(Texture2D texture, Rectangle screenBounds) { this.texture = texture; this.screenBounds = screenBounds; } //Update for paddle public void Update() { direction = Vector2.Zero; keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Up)) { direction.Y = -1; } if (keyboardState.IsKeyDown(Keys.Down)) { direction.Y = 1; } direction.Y *= paddleSpeed; postion += direction; CheckScreenBounds(); } //Check To see if player has left Screenbounds private void CheckScreenBounds() { if (postion.Y < 0) { postion.Y = 0; } if (postion.Y + texture.Height > screenBounds.Height) { postion.Y = screenBounds.Height - texture.Height; } } public void SetInStartPosition() { postion.Y = ((screenBounds.Height - texture.Height) / 2); postion.X = (screenBounds.Width - texture.Width); } public Rectangle GetBounds() { return new Rectangle( (int)postion.X, (int)postion.Y, texture.Width, texture.Height); } public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(texture, postion, Color.White); } }[/source]

Can someone help me out and walk me through Subclassing and Inheritance, I am having a lot of trouble learning how to make this work. I am sorry If i sound like a needy four year old, But I can't figure out the whole subclassing thing.

#3mistervirtue

Posted 11 October 2012 - 11:02 AM

This is my BasePaddle Class. My Parent Class
----------------
[source lang="csharp"] abstract class BasePaddle { //Texture For the Block Texture2D texture; //Postion of the Block Vector2 postion; //Directoin of the Block Vector2 direction; //Collision Rectangle for the block Rectangle screenBounds; //Speed of Paddle Movement float paddleSpeed = 20; public BasePaddle(Texture2D texture, Rectangle screenBounds, Vector2 direction, Vector2 postion) : this(texture, screenBounds, direction, postion) { } public virtual void Update() { direction = Vector2.Zero; direction.Y *= paddleSpeed; postion += direction; } public virtual Rectangle GetBounds() { return new Rectangle( (int)postion.X, (int)postion.Y, texture.Width, texture.Height); } public virtual void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(texture, postion, Color.White); } }[/source]

----------------
This is my Child Class PlayerPaddle
[source lang="csharp"] class Paddle : BasePaddle { //Texture For the Block Texture2D texture; //Postion of the Block Vector2 postion; //Directoin of the Block Vector2 direction; //Collision Rectangle for the block Rectangle screenBounds; //Speed of Paddle Movement float paddleSpeed = 20; //INPUT KeyboardState keyboardState; //Consturotor for Paddle public Paddle(Texture2D texture, Rectangle screenBounds) { this.texture = texture; this.screenBounds = screenBounds; } //Update for paddle public void Update() { direction = Vector2.Zero; keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Up)) { direction.Y = -1; } if (keyboardState.IsKeyDown(Keys.Down)) { direction.Y = 1; } direction.Y *= paddleSpeed; postion += direction; CheckScreenBounds(); } //Check To see if player has left Screenbounds private void CheckScreenBounds() { if (postion.Y < 0) { postion.Y = 0; } if (postion.Y + texture.Height > screenBounds.Height) { postion.Y = screenBounds.Height - texture.Height; } } public void SetInStartPosition() { postion.Y = ((screenBounds.Height - texture.Height) / 2); postion.X = (screenBounds.Width - texture.Width); } public Rectangle GetBounds() { return new Rectangle( (int)postion.X, (int)postion.Y, texture.Width, texture.Height); } public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(texture, postion, Color.White); } }[/source]

Can someone help me out and walk me through Subclassing and Inheritance, I am having a lot of trouble learning how to make this work. I am sorry If i sound like a needy four year old, But I can't figure out the whole subclassing thing.

#2mistervirtue

Posted 11 October 2012 - 10:59 AM

This is my BasePaddle Class. My Parent Class
----------------
[source lang="csharp"] abstract class BasePaddle { //Texture For the Block Texture2D texture; //Postion of the Block Vector2 postion; //Directoin of the Block Vector2 direction; //Collision Rectangle for the block Rectangle screenBounds; //Speed of Paddle Movement float paddleSpeed = 20; public BasePaddle(Texture2D texture, Rectangle screenBounds, Vector2 direction, Vector2 postion) : this(texture, screenBounds, direction, postion) { } public virtual void Update() { direction = Vector2.Zero; direction.Y *= paddleSpeed; postion += direction; } public virtual Rectangle GetBounds() { return new Rectangle( (int)postion.X, (int)postion.Y, texture.Width, texture.Height); } public virtual void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(texture, postion, Color.White); } }[/source]

----------------
This is my Child Class PlayerPaddle
[source lang="csharp"] class Paddle : BasePaddle { //Texture For the Block Texture2D texture; //Postion of the Block Vector2 postion; //Directoin of the Block Vector2 direction; //Collision Rectangle for the block Rectangle screenBounds; //Speed of Paddle Movement float paddleSpeed = 20; //INPUT KeyboardState keyboardState; //Consturotor for Paddle public Paddle(Texture2D texture, Rectangle screenBounds) { this.texture = texture; this.screenBounds = screenBounds; } //Update for paddle public void Update() { direction = Vector2.Zero; keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Up)) { direction.Y = -1; } if (keyboardState.IsKeyDown(Keys.Down)) { direction.Y = 1; } direction.Y *= paddleSpeed; postion += direction; CheckScreenBounds(); } //Check To see if player has left Screenbounds private void CheckScreenBounds() { if (postion.Y < 0) { postion.Y = 0; } if (postion.Y + texture.Height > screenBounds.Height) { postion.Y = screenBounds.Height - texture.Height; } } public void SetInStartPosition() { postion.Y = ((screenBounds.Height - texture.Height) / 2); postion.X = (screenBounds.Width - texture.Width); } public Rectangle GetBounds() { return new Rectangle( (int)postion.X, (int)postion.Y, texture.Width, texture.Height); } public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(texture, postion, Color.White); } }[/source]

Can someone help me out and walk me through Subclassing and Inheritance, I am having a lot of trouble learning how to make this work.

#1mistervirtue

Posted 11 October 2012 - 10:58 AM

This is my BasePaddle Class. My Parent Class
----------------
abstract class BasePaddle
{
//Texture For the Block
Texture2D texture;
//Postion of the Block
Vector2 postion;
//Directoin of the Block
Vector2 direction;
//Collision Rectangle for the block
Rectangle screenBounds;

//Speed of Paddle Movement
float paddleSpeed = 20;

public BasePaddle(Texture2D texture, Rectangle screenBounds, Vector2 direction, Vector2 postion)
:this(texture,screenBounds,direction,postion)
{
}
public virtual void Update()
{
direction = Vector2.Zero;
direction.Y *= paddleSpeed;
postion += direction;
}
public virtual Rectangle GetBounds()
{
return new Rectangle(
(int)postion.X, (int)postion.Y, texture.Width, texture.Height);
}
public virtual void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, postion, Color.White);
}

}
----------------
This is my Child Class PlayerPaddle
[source lang="csharp"] class Paddle : BasePaddle { //Texture For the Block Texture2D texture; //Postion of the Block Vector2 postion; //Directoin of the Block Vector2 direction; //Collision Rectangle for the block Rectangle screenBounds; //Speed of Paddle Movement float paddleSpeed = 20; //INPUT KeyboardState keyboardState; //Consturotor for Paddle public Paddle(Texture2D texture, Rectangle screenBounds) { this.texture = texture; this.screenBounds = screenBounds; } //Update for paddle public void Update() { direction = Vector2.Zero; keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Up)) { direction.Y = -1; } if (keyboardState.IsKeyDown(Keys.Down)) { direction.Y = 1; } direction.Y *= paddleSpeed; postion += direction; CheckScreenBounds(); } //Check To see if player has left Screenbounds private void CheckScreenBounds() { if (postion.Y < 0) { postion.Y = 0; } if (postion.Y + texture.Height > screenBounds.Height) { postion.Y = screenBounds.Height - texture.Height; } } public void SetInStartPosition() { postion.Y = ((screenBounds.Height - texture.Height) / 2); postion.X = (screenBounds.Width - texture.Width); } public Rectangle GetBounds() { return new Rectangle( (int)postion.X, (int)postion.Y, texture.Width, texture.Height); } public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(texture, postion, Color.White); } }[/source]

Can someone help me out and walk me through Subclassing and Inheritance, I am having a lot of trouble learning how to make this work.

PARTNERS