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 8826775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:13:21+00:00 2026-06-14T07:13:21+00:00

I have this program with a small tank and a black square. The tank

  • 0

I have this program with a small tank and a black square. The tank is supposed to respond to user input and stop when it touches the tank. However, after the window appears(containing both the box and the tank) i have no user input. When i press one of the arrow keys, the tank doesn’t move at all.

So here are just a few of the more important examples from my code.

public class TopDownShooter : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    private Texture2D tank, blackSquare;
    private KeyboardState state;
    private float angle1 = 0;
    private float angle2 = 0;
    private float xLocation, yLocation;
    Vector2 location1 = new Vector2(900, 400), origin1;
    Vector2 location2 = new Vector2(400, 400), origin2;
    Rectangle playerRectangle, obstacleRectangle;



    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            this.Exit();
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();
        playerRectangle = Move(playerRectangle);

        base.Update(gameTime);
    }


    private Boolean IsNotCollision(Rectangle rectangle1, Rectangle rectangle2)
    {
        if (rectangle1.Intersects(rectangle2)) return true;
        else return false;
    }


    /// <summary>
    /// Sets the velocity of the targeted object based on user keyboard input
    /// </summary>
    private Rectangle Move(Rectangle rectangle)
    {
        state = Keyboard.GetState();
        xLocation = rectangle.X;
        yLocation = rectangle.Y;

        if (IsNotCollision(obstacleRectangle, playerRectangle))
        {
            if (state.IsKeyDown(Keys.Left)) rectangle.X += -4;
            if (state.IsKeyDown(Keys.Right)) rectangle.X += 4;
            if (state.IsKeyDown(Keys.Up)) rectangle.Y += -4;
            if (state.IsKeyDown(Keys.Down)) rectangle.Y += 4;
        }
        return rectangle;
    }



    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        spriteBatch.Begin();

        playerRectangle = new Rectangle(0, 0, tank.Width, tank.Height);
        origin1 = new Vector2(tank.Width / 2, tank.Height);
        obstacleRectangle = new Rectangle(0, 0, blackSquare.Width, blackSquare.Height);
        origin2 = new Vector2(blackSquare.Width / 2, blackSquare.Height);

        spriteBatch.Draw(tank, location1, playerRectangle, Color.White, angle1, origin1, 1.0f, SpriteEffects.None, 1);
        spriteBatch.Draw(blackSquare, location2, obstacleRectangle, Color.White, angle2, origin2, 1.0f, SpriteEffects.None, 1); 

        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-14T07:13:23+00:00Added an answer on June 14, 2026 at 7:13 am

    EDIT:

    Actually.. you don’t ever seem to update location1…

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

Sidebar

Related Questions

I have this small program that reads a line of input & prints the
I have written this small program in VS2010 to run on Outlook 2007. It
I have a small program where the user can enter a snippet of real
I have this small program and it needs to create a small .txt file
I made this small Java program using eclipse IDE. I have set the workspace
I have this small program: #include <stdio.h> #include <string.h> #include <ctype.h> #define SIZE 30
I have this small C program (play.c): #include <stdio.h> main() { int t; for
I have a problem with this small program. It added some value to list.
I have written this small program for Hive JDBC. Initially it is executing fine
I have this program in Python which should save text files to a folder

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.