Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (565) Games in Android Showcase (151) games submitted by our members Games in WIP (606) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Player positioning  (Read 1781 times) 0 Members and 1 Guest are viewing this topic.
Bomber23

Innocent Bystander

 « Posted 2009-07-23 12:23:17 »

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

indexunknown

Junior Devvie

 « Reply #1 - Posted 2009-07-23 15:26:42 »

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
fermixx

Senior Newbie

 « Reply #2 - Posted 2009-08-12 05:04:22 »

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)

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

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

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

to convert radians to angles you can do either

degrees = radians * 180 / Math.pi

or

that was a mix between pseudo-code and java code

let me know how did you solved the problem

see ya

RTS game or a big rock-paper-sissors ?
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 ags1 (20 views) 2015-03-31 10:55:12 theagentd (13 views) 2015-03-27 23:08:20 wxwsk8er (54 views) 2015-03-20 15:39:46 Fairy Tailz (47 views) 2015-03-15 21:52:20 Olo (29 views) 2015-03-13 17:51:59 Olo (32 views) 2015-03-13 17:50:51 Olo (39 views) 2015-03-13 17:50:16 Olo (44 views) 2015-03-13 17:47:07 ClaasJG (58 views) 2015-03-10 11:36:42 ClaasJG (43 views) 2015-03-10 11:33:01
 BurntPizza 21x LiquidNitrogen 21x basil_ 19x KevinWorkman 18x EgonOlsen 17x theagentd 16x Roquen 16x wessles 11x Varkas 11x 65K 11x Riven 11x princec 9x phu004 8x SHC 8x Ashedragon 8x Rayvolution 8x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org