XNA Creators Club Online
community forums
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Help

Last post 5/3/2009 11:39 PM by Michael Stewardson. 3 replies.
  • 5/3/2009 10:26 PM

    Help

    I have posted a few times for a final exam/project with great results.  Thanks to everyone who has responded to my posts.  I am finalizing the project and no need help in a few areas.  The largest, and most pressing issue now is how to make the characted stay in bounds.

    The game is a PAC MAN type game and I think that I need a rectangle class with the coordinates for the walls, then use the Intersect() method, but I am not sure how to impliment this. 
    Also, I am confused by the following line of code,

    Vector2

     

    loc = new Vector2(MathHelper.Clamp(355, 500, 1183), MathHelper.Clamp(498, 245, 743));

    Shouldn't this keep the vector between the specified range?  I use if statements to increment/decriment, the values fo the vector to move the character but want it to stay in the bound I give it.  For some reason, It ignors the bound and just goes fight through.

     


    Thanks once again to everyone.....
  • 5/3/2009 11:23 PM In reply to

    Re: Help

    Maybe I'm misunderstanding what you're getting at, but just putting MathHelper.Clamp() in the declaration of your Vector2 won't do anything afterwards.  If you want to keep the values in that range, you should insert the following at the appropriate place in your code, in the Update() method or wherever:
    loc.X = MathHelper.Clamp(loc.X, 500, 1183); 
    loc.Y = MathHelper.Clamp(loc.Y, 245, 743); 
    This is assuming the values from your originally posted code are the values you want to clamp to.
  • 5/3/2009 11:23 PM In reply to

    Re: Help

    It's a little hard to get full context just from one line of code, but I'm going to guess that 500 and 1183 are the left and right sides of the level, and 245 and 743 are the top and bottom of the level, and that "loc" is the location of the player (same one used in his Draw method). Does that sound right?

    I can't really give too many suggestions without seeing a larger part of those if statements you're referring to; maybe the entire class for the Character, or any code you think is related, would be helpful.
  • 5/3/2009 11:39 PM In reply to

    Re: Help

    The first poster solved that part of the probolem, have any ideas about the rectangle class to prevent the character from moving in and out of the walls.

Page 1 of 1 (4 items) Previous Next