Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  Advance Wars Style Movement  (Read 2780 times)
0 Members and 1 Guest are viewing this topic.
Offline hornzfan3211

Innocent Bystander





« Posted 2009-02-19 18:27:26 »

I am trying to implement a way for a unit to be selected and to be able to highlight the tiles you want to move on and then select the final location and it will move on those tiles. I have achieved this by using a queue and storing each position the selection box hovers over to the queue and then once the final location has been chosen, the unit traverses over the tiles that are stored in the queue, obviously in a FIFO order. This works well and everything is fine, except for the fact of going back on yourself. In advance wars, if you go forward and then decide to move somewhere else you can move back over yourself and then make a new path, even if you do not go back over all of them. I really do not have any idea on how to implement this, any hints or suggestions?

Thanks in advance for your help.
Offline Rowdy

Senior Newbie




High School Student, wanting to make games.


« Reply #1 - Posted 2009-02-20 04:44:16 »

If I were programming, my thought logic would be
1. Get possible spots (Highlighted Spots)
2. Keep adding to queue as the cursor moves
3. If it went backward, take out that last element (May want to consider using arraylist)
4. If the spot is "out of reach" and inside highlighted, find the shortest path to that point. (Clear queue and recursively find the shortest)
5. PROFIT!!!

There's my 2 cents. Good Luck.

Rowdy
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2009-02-20 18:54:42 »

You'll want to use A* or a similar pathfinding method. If it's grid based, A* is definitely your best bet.

http://www.cokeandcode.com/pathfinding

Basically you store the resulting path in an array and then you just fill in the squares that are part of the path from your position to your target (your target being where your mouse is). Add a little bit of simple image matching and you can have tiles instead of filled squares so you get a nice red arrow-like path just as in Advance Wars.

Also have a look at:
http://www.otcsw.com/maze.php

Run the program in the link above, click the check box "Goal at Mouse" and then move your mouse around and watch the path fill in as you move it. That is done using A*, and you can also use the program I posted to get a good understanding for how a couple different pathfinding algorithms work.

If I were programming, my thought logic would be
1. Get possible spots (Highlighted Spots)
2. Keep adding to queue as the cursor moves
3. If it went backward, take out that last element (May want to consider using arraylist)
4. If the spot is "out of reach" and inside highlighted, find the shortest path to that point. (Clear queue and recursively find the shortest)
5. PROFIT!!!

There's my 2 cents. Good Luck.

Rowdy
You don't need to get as complicated as adding to a queue or anything like that. Computers are fast enough these days that you can simply recompute the path every time the goal moves (or even compute it over and over every timestep and I doubt you'd notice any slowdown). You're only doing this one time (for the selected unit) and not very far (only within their range) and the tiles are relatively large. A* will typically do only 10 to 20 computations for even the most windy area as long as you're mostly sticking with Advance Wars complexity. Basically if your tiles are bigger than a pixel wide and the units can't move across the map in a single move, you're fine.

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Rowdy

Senior Newbie




High School Student, wanting to make games.


« Reply #3 - Posted 2009-02-20 21:52:39 »

I did think about recalculating the path everytime, but sometimes there are multiple paths to one spot. So if you wanted to take a path where you wanted to go around a forest instead of going through, all you had to do is move around it (Take the smartest path, not necessarily the shortest). If you need more explaining just ask.

Rowdy
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #4 - Posted 2009-02-20 23:35:48 »

I did think about recalculating the path everytime, but sometimes there are multiple paths to one spot. So if you wanted to take a path where you wanted to go around a forest instead of going through, all you had to do is move around it (Take the smartest path, not necessarily the shortest). If you need more explaining just ask.

Rowdy
You can just put that in A*'s cost heuristic and it's computed automatically.

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.

Riven (12 views)
2014-07-29 18:09:19

Riven (8 views)
2014-07-29 18:08:52

Dwinin (9 views)
2014-07-29 10:59:34

E.R. Fleming (26 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!