Results 1 to 5 of 5
  1. #1
    RyanHenness is offline Member
    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0

    Default Need help with chasing box

    Hey guy, I'm Ryan and I'm new to this forum!
    I've been working on a simple Java code, and need just a little bit of help.
    I am designing a game in graphics that will have a rectangle chase another rectangle.

    //Create chasing box
    chaseBoxX = lilBoxX;
    chaseBoxY = lilBoxY;
    canvas.setColor(Color.white);
    canvas.fillRect(chaseBoxX, chaseBoxY, chaseBoxSize, chaseBoxSize);
    canvas.setColor(Color.blue);
    canvas.drawRect(chaseBoxX, chaseBoxY, chaseBoxSize, chaseBoxSize);

    lilBoxX and Y are the cursor coordinates.
    chaseBoxX and Y are set to zero at the beginning of the code.
    I'm trying to make it so that the chase box tries to collide with the users coordinate.
    Any suggestions?

    I've tried things like:
    chaseBoxX = lilBoxX + (chaseBoxX = bigBoxX) / 10;

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: Need help with chasing box

    Is the objective to make the box move directly to the user supplied x,y position
    or is it supposed to move slowly from where it is, step by step, to the user position?

    If directly, can the box's location be set to the user supplied position?

    When posting code be sure to wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    RyanHenness is offline Member
    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0

    Default Re: Need help with chasing box

    Step by step, so that the user has got to run away from it. The idea for the game is that if this chasing box collides with the user's box, the user loses a life.

    Thanks for the code tip forum tip too!

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: Need help with chasing box

    What have you tried? Do you have code that allows the user to move his box?
    What problem(s) do you have with the computer's box chasing the user's box? Have you used a piece of paper and pencil to draw the two boxes and then the new positions for the computer's box?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,651
    Rep Power
    5

    Default Re: Need help with chasing box

    It wasn't a tip. It was a request to edit your post and place the code between code tags.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •