Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7864019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:39:52+00:00 2026-06-02T23:39:52+00:00

In continuing with my powerups for my pong game, I’ve gotten them working correctly

  • 0

In continuing with my powerups for my pong game, I’ve gotten them working correctly for the most part (LARGELY thanks to Jim Perry ), but now I can’t seem to get my bats (paddles) to grow or shrink when called on.

I’m thinking it has something to do with the way I’m calling the size of the bat. In my Bat class I have a function called GetSize() which returns the size of the bat.

        public Rectangle GetSize()
    {
        return size;
    }

I’m basically trying to double the size of the bat in one function, and half the size of the original bat in another.

        public void GrowBat()
    {
    } 

    public void ShrinkBat()
    {
    }   

If I insert something like what I have below into the function, I am not noticing any change in the bats.

    public void GrowBat()
    {
size = new Rectangle(0, 0, leftBat.Width * 2, leftBat.Height *2);
} 

   public void ShrinkBat()
    {
size = new Rectangle(0, 0, leftBat.Width / 2, leftBat.Height / 2);
    }

I’m thinking it has something to do with me not returning the size of the bats. How would you guys resolve this?

I’ve included my Bat and Game1 classes below to help clarify, in particular the switch statements in my Game1 class for the powerups, about half way down.

 namespace Pong
{
  using Microsoft.Xna.Framework;
  using Microsoft.Xna.Framework.Content;
  using Microsoft.Xna.Framework.Graphics;
  using System;

 public class Bat
  {
    public Vector2 position;
    public float moveSpeed;
    public Rectangle size;
    private int points;
    private int yHeight;
    private Texture2D leftBat;
    public float turbo;
    public float recharge;
    public float interval;
    public bool isTurbo;


    public Bat(ContentManager content, Vector2 screenSize, bool side)
    {
        moveSpeed = 7f;
        turbo = 15f;
        recharge = 100f;
        points = 0;
        interval = 5f;
        leftBat = content.Load<Texture2D>(@"gfx/batGrey");
        size = new Rectangle(0, 0, leftBat.Width, leftBat.Height);
        if (side) position = new Vector2(30, screenSize.Y / 2 - size.Height / 2);
        else position = new Vector2(screenSize.X - 30, screenSize.Y / 2 - size.Height /       2);
        yHeight = (int)screenSize.Y;
    }

    public void IncreaseSpeed()
    {
        moveSpeed += .5f;

    }


    public void Turbo()
    {
        moveSpeed += 7.0f;
    }

    public void DisableTurbo()
    {
        moveSpeed = 7.0f;
        isTurbo = false;
    }


    public Rectangle GetSize()
    {
        return size;
    }

    public void IncrementPoints()
    {
        points++;
    }

    public int GetPoints()
    {
        return points;
    }

    public void SetPosition(Vector2 position)
    {
        if (position.Y < 0)
        {
            position.Y = 0;
        }
        if (position.Y > yHeight - size.Height)
        {
            position.Y = yHeight - size.Height;
        }
        this.position = position;
    }

    public Vector2 GetPosition()
    {
        return position;
    }

    public void MoveUp()
    {
        SetPosition(position + new Vector2(0, -moveSpeed));
    }

    public void MoveDown()
    {
        SetPosition(position + new Vector2(0, moveSpeed));
    }


    public virtual void UpdatePosition(Ball ball)
    {
        size.X = (int)position.X;
        size.Y = (int)position.Y;
    }

    public void ResetPosition()
    {
        SetPosition(new Vector2(GetPosition().X, yHeight / 2 - size.Height));
    }

    public void GrowBat()
    {

    }

    public void ShrinkBat()
    {
        size = new Rectangle(0, 0, leftBat.Width / 2, leftBat.Height / 2);
    }


    public virtual void Draw(SpriteBatch batch)
    {
        batch.Draw(leftBat, position, Color.White);
    }


   }
}







  namespace Pong
{
using System;
using System.Diagnostics; // There for debugging purposes right now
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;



  /// <summary>
  /// This is the main type for your game
  /// </summary>
  public class Game1 : Microsoft.Xna.Framework.Game
  {

    public static GameStates gamestate;
    private GraphicsDeviceManager graphics;
    public int screenWidth;
    public int screenHeight;
    private Texture2D backgroundTexture;
    private SpriteBatch spriteBatch;
    private Menu menu;
    private SpriteFont arial;
    private HUD hud;
    Animation player;

    // Bats & Ball
    public Bat rightBat;
    public Bat leftBat;
    public Ball ball;


    // Scoring
    private int resetTimer;
    private bool resetTimerInUse;
    public bool lastScored;  

    // All things having to do with the powerup
    Powerup powerup;
    SpriteFont font;
    Vector2 vec;
    Vector2 vec2;
    Vector2 tickVec;
    Vector2 activatedVec;
    Vector2 deactivatedVec;     
    Vector2 promptVec;
    Random random;
    GamePadState lastState;
    int tickCount;
    bool powerupInitialized;



    // Menus
    private SoundEffect menuButton;
    private SoundEffect menuClose;
    public Song MainMenuSong { get; private set; }
    public Song PlayingSong { get; private set; }

    private Input input;

    // For resetting the speed burst of the paddle
    int coolDown = 0;
    int disableCooldown = 0;
    int powerEnableCooldown = 5000;
    int powerDisableCooldown = 2000;

    // Creates a new intance, which is used in the HUD class
    public static Game1 Instance;

    public enum GameStates
    {
        Menu,
        Running,
        Paused,
        End
    }

    // Constructor (I'm a n00b, remember?)
    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";

        // Creates an instance of the class, which is used in the HUD class
        Instance = this; 

    }


    protected override void Initialize()
    {
        screenWidth = 1280;
        screenHeight = 720;
        menu = new Menu();
        gamestate = GameStates.Menu;
        resetTimer = 0;
        resetTimerInUse = true;
        lastScored = false;
        graphics.PreferredBackBufferWidth = screenWidth;
        graphics.PreferredBackBufferHeight = screenHeight;
        graphics.IsFullScreen = true;
        graphics.ApplyChanges(); 
        ball = new Ball(Content, new Vector2(screenWidth, screenHeight));
        SetUpMulti();
        input = new Input();
        hud = new HUD();

        // Places the powerup animation inside of the surrounding box
        player = new Animation(Content.Load<Texture2D>(@"gfx/powerupSpriteSheet"), new     Vector2(103, 44), 64, 64, 4, 5);

        // Used by for the Powerups
        random = new Random();
        vec = new Vector2(100, 50);
        vec2 = new Vector2(100, 100);
        promptVec = new Vector2(50, 25);
        powerupInitialized = false;  

        base.Initialize();         
    }


    protected override void LoadContent()
    {
        arial = Content.Load<SpriteFont>("Arial"); // for game scores
        spriteBatch = new SpriteBatch(GraphicsDevice);  
        backgroundTexture = Content.Load<Texture2D>(@"gfx/background");
        hud.LoadContent(Content);   
        menuButton = Content.Load<SoundEffect>(@"sfx/menuButton");
        menuClose = Content.Load<SoundEffect>(@"sfx/menuClose");
        MainMenuSong = Content.Load<Song>(@"sfx/getWeapon");
        PlayingSong = Content.Load<Song>(@"sfx/boomer");
        MediaPlayer.IsRepeating = true;
 //         MediaPlayer.Play(MainMenuSong); // getWeapon music 
        font = Content.Load<SpriteFont>("Arial"); // Used by the Powerup

    }


    private void PowerupActivated(object sender, PowerupEventArgs e)
    {
        activatedVec = new Vector2(100, 125);          
    }

    private void PowerupDeactivated(object sender, PowerupEventArgs e)
    {
        deactivatedVec = new Vector2(100, 150);
        //do whatever - shrink ball, paddle, slow down ball
    }

    private void PowerupTick(object sender, PowerupEventArgs e)
    {
        tickVec = new Vector2(100, 175);
        tickCount++;
        //for powerup like Regen, add hp
    }


    // Sets up single player game
    private void SetUpSingle()
    {
        rightBat = new AIBat(Content, new Vector2(screenWidth, screenHeight), false);
        leftBat = new Bat(Content, new Vector2(screenWidth, screenHeight), true);
    }

    // Sets up 2 player game
    private void SetUpMulti()
    {
        rightBat = new Bat(Content, new Vector2(screenWidth, screenHeight), false);
        leftBat = new Bat(Content, new Vector2(screenWidth, screenHeight), true);
    }


    // Increases the speed of the bats slightly after each round
    private void IncreaseSpeed()
    {
        ball.IncreaseSpeed();
        leftBat.IncreaseSpeed();
        rightBat.IncreaseSpeed();
    }


    protected override void Update(GameTime gameTime)
    {
        input.Update();
        player.Update(gameTime);

        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || 
            Keyboard.GetState().IsKeyDown(Keys.Escape))
            this.Exit();


        GamePadState state = GamePad.GetState(PlayerIndex.One);

        if (state.Buttons.RightShoulder == ButtonState.Pressed &&    lastState.Buttons.RightShoulder == ButtonState.Released
            || Keyboard.GetState().IsKeyDown(Keys.LeftAlt))
        {
            //generate a random powerup
            PowerupType type =    (PowerupType)random.Next(Enum.GetNames(typeof(PowerupType)).Length);

            switch (type)
            {
                case PowerupType.BigBalls:
                    {
                    powerup = new Powerup(type, 10.0f, 1.0f);
                    ball.ShrinkBall();
                    break;

                    }
                case PowerupType.BigPaddle:
                    {
                        powerup = new Powerup(type, 10.0f, 10.0f);
                        leftBat.GrowBat();
                        break;
                    }
                case PowerupType.ShrinkEnemy:
                    {
                        powerup = new Powerup(type, 10.0f, 10.0f);
                        rightBat.ShrinkBat();
                        break;

                    }
                case PowerupType.SpeedBall:
                    {
                        powerup = new Powerup(type, 10.0f, 20.0f);
                        ball.IncreaseSpeed();
                       break;

                    }
                case PowerupType.SplitWall:
                case PowerupType.ThreeBurst:
                case PowerupType.Heal:
                    {
                        powerup = new Powerup(type, 1.0f, 1.0f);
                        hud.AddHealthP1();

                        break;
                    }
                case PowerupType.Regen:
                    {
                        powerup = new Powerup(type, 20.0f, 1.0f);

                        break;
                    }
            }

            powerupInitialized = false;

        }
        else if (state.Buttons.LeftShoulder == ButtonState.Pressed && 
            lastState.Buttons.LeftShoulder == ButtonState.Released || 
            Keyboard.GetState().IsKeyDown(Keys.LeftControl) &&    Keyboard.GetState().IsKeyUp(Keys.LeftControl))
        {
            powerup.Activate();
        }

        if (powerup != null && IsActive)
        {
            if (!powerupInitialized)
            {
                powerup.Activated += PowerupActivated;
                powerup.Deactivated += PowerupDeactivated;

                if (powerup.Type == PowerupType.Regen)
                    powerup.Tick += PowerupTick;

                powerupInitialized = true;
            }

            powerup.Update((float)gameTime.ElapsedGameTime.TotalMilliseconds);
        }

        lastState = state;


        // What to do when the game is over
      if (gamestate == GameStates.Running)
        {
            if (hud.currentHealthP2 < 1)
            {
                menu.InfoText = "Game, blouses.";
                gamestate = GameStates.End;
            }
            else if (hud.currentHealthP1 < 1)
            {
                menu.InfoText = "You just let the AI beat you.";
                gamestate = GameStates.End;
            }
            if (resetTimerInUse)
            {
                resetTimer++;
                ball.Stop();                 
            }

            if (resetTimer == 120)
            {
                resetTimerInUse = false;
                ball.Reset(lastScored);
                resetTimer = 0;
            }


            // Controls movement of the bats              
            if (rightBat.GetType() != typeof(Pong.AIBat))
            {
                if (input.LeftDown) leftBat.MoveDown();
                else if ((input.LeftUp)) leftBat.MoveUp();
                if (input.RightDown) rightBat.MoveDown();
                else if (input.RightUp) rightBat.MoveUp();
            }

            else if (rightBat.GetType() == typeof(Pong.AIBat))
            {
                if (input.LeftDown) leftBat.MoveDown();
                else if ((input.LeftUp)) leftBat.MoveUp();
                if (input.RightDown) leftBat.MoveDown();
                else if (input.RightUp) leftBat.MoveUp();
             }


            // Updating ball and bat position
            leftBat.UpdatePosition(ball);
            rightBat.UpdatePosition(ball);
            ball.UpdatePosition();


          // Checking for collision of the bats
            if (ball.GetDirection() > 1.5f * Math.PI || ball.GetDirection() < 0.5f *  Math.PI)
            {
                if (rightBat.GetSize().Intersects(ball.GetSize()))
                {
                    ball.BatHit(CheckHitLocation(rightBat));
                }
            }
            else if (leftBat.GetSize().Intersects(ball.GetSize()))
            {
                ball.BatHit(CheckHitLocation(leftBat));
            }


            // Triggers the turbo button and cooldown
            if (input.SpaceDown)
            {
                if (disableCooldown > 0)
                {
                    leftBat.isTurbo = true;
                    coolDown = powerEnableCooldown;
                    leftBat.moveSpeed = 40.0f;
                    disableCooldown -= gameTime.ElapsedGameTime.Milliseconds;
                }
                else
                {
                    leftBat.DisableTurbo();
                }
            }
                // If spacebar is not down, begin to refill the turbo bar
            else if (!input.SpaceDown) 
            {
                leftBat.DisableTurbo();
                coolDown -= gameTime.ElapsedGameTime.Milliseconds;
                if (coolDown < 0)
                {
                    disableCooldown = powerDisableCooldown;
                }
            }


            // Makes sure that if Turbo is on, it automatically turns of. Kills it    after () seconds
            if(leftBat.isTurbo)

                disableCooldown -= gameTime.ElapsedGameTime.Milliseconds; 
                    if(disableCooldown < 0)
                     {
                    leftBat.isTurbo = false;
                     }



            if (!resetTimerInUse)
            {   // checks out of bounds for right side
                if (ball.GetPosition().X > screenWidth)
                {
                    resetTimerInUse = true;
                    lastScored = true;

                    hud.SubtractHealthP2();
                    // Checks to see if ball went out of bounds, and triggers warp sfx
                    ball.OutOfBounds();
                    leftBat.IncrementPoints();
                    IncreaseSpeed();
                } // Checks out of bounds for left side
                else if (ball.GetPosition().X < 0)
                {

                    resetTimerInUse = true;
                    lastScored = false;

                    hud.SubtractHealthP1();
                    // Checks to see if ball went out of bounds, and triggers warp sfx
                    ball.OutOfBounds();
                    rightBat.IncrementPoints();
                    IncreaseSpeed();
                }
            }
        }
          // Navigating through the menus
        else if (gamestate == GameStates.Menu)

        {

            if (input.RightDown || input.LeftDown)
            {
                menu.Iterator++;
                menuButton.Play();
            }
            else if (input.RightUp || input.LeftUp)
            {
                menu.Iterator--;
                menuButton.Play();
            }

            if (input.MenuSelect)
            {

                if (menu.Iterator == 0)
                {
                    gamestate = GameStates.Running;
                    SetUpSingle();
                    menuClose.Play();
                }
                else if (menu.Iterator == 1)
                {
                    gamestate = GameStates.Running;
                    SetUpMulti();
                    menuClose.Play();
                }
                else if (menu.Iterator == 2)
                {
                    this.Exit();
                    menuClose.Play();
                }
                menu.Iterator = 0;
            }
        }

        else if (gamestate == GameStates.End)
        {
            if (input.MenuSelect)
            {
                gamestate = GameStates.Menu;
                hud.ResetHealth();

            }
        }

      // Updates the HUD
      hud.Update(gameTime);
        base.Update(gameTime);
    }


    // Checking for bat collision & instructs the ball where to deflect to
    private int CheckHitLocation(Bat bat)
    {
        int block = 0;
        if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 20) block = 1;
        else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 2) block = 2;
        else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10   * 3) block = 3;
        else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 4) block = 4;
        else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 5) block = 5;
        else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 6) block = 6;
        else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 7) block = 7;
        else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 10 * 8) block = 8;
        else if (ball.GetPosition().Y < bat.GetPosition().Y + bat.GetSize().Height / 20 * 19) block = 9;
        else block = 10;
        return block;
    }


    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.Black);

        // TODO: Add your drawing code here
        spriteBatch.Begin();
        if (gamestate == GameStates.Running)
        {
            // Draws background
            spriteBatch.Draw(backgroundTexture, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);

            player.Draw(spriteBatch);

            // Draws the bats and ball
            leftBat.Draw(spriteBatch);
            rightBat.Draw(spriteBatch);
            ball.Draw(spriteBatch);

            // Draws the score on screen
            spriteBatch.DrawString(arial, leftBat.GetPoints().ToString(), new Vector2(screenWidth / 4 - arial.MeasureString
                (rightBat.GetPoints().ToString()).X, 20), Color.White);
            spriteBatch.DrawString(arial, rightBat.GetPoints().ToString(), new Vector2(screenWidth / 4 * 3 - arial.MeasureString
                (rightBat.GetPoints().ToString()).X, 20), Color.White);                                               
        }


            // Only draws the menu
        else if (gamestate == GameStates.Menu)
        {
            spriteBatch.Draw(backgroundTexture, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
            menu.DrawMenu(spriteBatch, screenWidth, arial);
        }
        else if (gamestate == GameStates.End)
        {
            spriteBatch.Draw(backgroundTexture, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
            menu.DrawEndScreen(spriteBatch, screenWidth, arial);
        }
        spriteBatch.End();

        // Draws the HUD
        if (gamestate == GameStates.Running)
        {               
            hud.Draw(gameTime);
        }

        spriteBatch.Begin();
        // Powerup text
        if (gamestate == GameStates.Running)
        {
            spriteBatch.DrawString(font, "Press A or Left Alt button to generate powerup", promptVec, Color.White);

            if (powerup != null)
            {
                spriteBatch.DrawString(font, "Powerup Type: " + powerup.Type, vec, Color.White);

                spriteBatch.DrawString(font, "Press Left Bumper or  Left Ctrl to activate powerup", vec2, Color.White);

            }

            if (deactivatedVec != Vector2.Zero)
                spriteBatch.DrawString(font, "Powerup deactivated", deactivatedVec, Color.White);

            if (activatedVec != Vector2.Zero)
                spriteBatch.DrawString(font, "Powerup activated", activatedVec, Color.White);

            if (tickVec != Vector2.Zero)
                spriteBatch.DrawString(font, "Tick count: " + tickCount.ToString(), tickVec, Color.White);
            }
        spriteBatch.End();

        base.Draw(gameTime);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:39:53+00:00Added an answer on June 2, 2026 at 11:39 pm

    I bet you’re not seeing a change in the bat’s visible size, but you should be seeing a change in the bat’s hit detection. You are only changing the size of the bat. Which is used in your collision detection code. However, you don’t reference the size of the bat when drawing the bat. You’ll have to update your code to draw your bat based on it’s current size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Continuing my quest of learning Java by doing a simple game, i stumbled upon
Continuing the question in: Keep windows trying to read a file Thanks to accepted
I'm continuing my migration from rails 2.3.12 to 3.0.9 and am now working sending
Continuing from my previous question , is there a comprehensive document that lists all
Continuing my problem from yesterday, the Silverlight datagrid I have from this issue is
Continuing my investigation of expressing F# ideas in C#, I wanted a pipe forward
Continuing on previous questions ( here , and here ), I implemented a basic
Continuing on my attempt to create a DateTime class , I am trying to
Continuing the discussion about the minimum footprint needed to connect to an Oracle DB
Continuing from this question : When I am trying to do fopen on Windows,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.