Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 2428 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
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


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  

EgonOlsen (79 views)
2018-06-10 19:43:48

EgonOlsen (59 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (261 views)
2018-05-13 18:23:11

nelsongames (160 views)
2018-04-24 18:15:36

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!