Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
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  
  Looking for a suggestion, pseudo code or article on paths  (Read 663 times)
0 Members and 1 Guest are viewing this topic.
Offline Darrin

Junior Duke


Projects: 1



« Posted 2009-05-12 15:51:20 »

I have a couple ideas for some games but I'm not sure how to implement it.  I was wondering if anyone had any suggestions.

Here is the basic idea.

I want the player to move around the edge of multiple rectangles.    The rectangles can be any size and there can be multiple ones but the player sprite has to stay on the side.   If the rectangles share a side the player can move to either rectangle


1  
2  
3  
4  
5  
6  
7  
8  
-----
|    |--x--
|    |     |
-----      |
     |     |
      -----

 


Would you set up each rectangle as an object then just check its bounds versus the players attempt at movement?  For example if the player attempts to move Right, the code checks to see if the player coordinates are only the top or bottom plane of a rectangle?  If the player is not on that plane, right is not allowed?

Is there a better way to set up a player path? 

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #1 - Posted 2009-05-12 16:41:50 »

I'd probably just do some smart linking at level initialization. Pretty much, give each Rectangle a List of north, south, east, and west linked rectangles. When you first load up your level, do bounds checking to populate the list, then all you need to do during the game is know what side of which rectangle the the player currently is, and then only check against the bounds of the rectangles in that list.

ex.)
I'm on the north side of RectangleX.
RectangleX has RectangleY, RectangleZ, and RectangleW in its north List.
I iterate through those 3 rectangles in the north list and see if I'm within the bounds of any of them.
I move to the one that I'm within, or I don't move at all.

You've still got ways to make this faster but it will probably be cheap enough in most situations, because you are unlikely to ever be comparing against more than 3 rectangles at a time, and bounding box collision is cheap.

See my work:
OTC Software
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.

theagentd (16 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (45 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
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!