Player positioning

Hi people,

I Have a problem. The game im making needs to have players on a oval in different positions and not go outside the confines of the oval. The view of the oval is from side on and 45 degrees up giving a nice view of the oval in a 3d perspective.
Im new to java, was going to make this game on XNA but hit a few stumbling blocks with the database i wanted to implement. So Ive invested some money in 2 java books and im reading them at the moment (Java How to Program, 4th 2004. and Developing Games in JAVA).
i just keep thinking how will i keep the players in the oval etc. i had a brief read of that section of the book and its saying 0,0 0,1 1,1 2,2 0,3 etc but i cant just say 4,4 is one boudry and 440,440 is another etc. i havent fully read it yet but i just cant get my head around how the coordinates will work with an oval. I uploaded a picture just to give you an idea of what im trying to do. i was thinking of doing the game 2d and having the players resize larger and smaller depending what side of the field they are on to make them look closer and far away. or should i go 3d? is it much harder? or just as simple as adding one more dimension? Its got me stumped so any help would be great thanks


http://h.imagehost.org/t/0728/oval.jpg

this is more of a maths problem, u basicly just have to take the ellipse equation and not let the players center or edge get further away from the center of ellipse than the ellipses edgepoint is at that angle http://en.wikipedia.org/wiki/Ellipse

indexunknown is right, but the thing gets more complicated due to the perspective.

anyways, despite the perspective, an oval is still an oval.

you need to do something like:

human_coord = human.get(y) + human.getHeight(); //to retrieve the coords of the foot of the player (not the top of the sprite)
radius = doSomeMathWithTheOval();

if (Math.abs(ovalCenter - human_coord) > radius)

           //dont move the player

to calculate the angle to do the math with the oval you need to make a triangle and then using trig calculate alpha

adjacent = Math.abs(oval.centerX - human_coordX);
opposite = Math.abs(oval.centerY - human_coordY);

alpha = Math.atan(opposite/adjacent) //returns the arc tangent, and thats the angle of your triangle
//dont forget its in radians

to convert radians to angles you can do either

degrees = radians * 180 / Math.pi

or

degrees = Math.toDegrees (radians)

that was a mix between pseudo-code and java code :slight_smile:

let me know how did you solved the problem

see ya