Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Player positioning  (Read 1721 times)
0 Members and 1 Guest are viewing this topic.
Offline 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


Offline 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
Offline 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)
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 Smiley


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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (57 views)
2014-11-26 15:22:04

toopeicgaming1999 (51 views)
2014-11-26 15:20:36

toopeicgaming1999 (10 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (27 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!