Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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  
  Sightlines in a Tile-Based Strategy Game (Fog of War)  (Read 391 times)
0 Members and 1 Guest are viewing this topic.
Offline RyanMB97

Junior Member


Medals: 1
Projects: 1



« Posted 2013-09-13 20:23:02 »

   Hello. I've been working on a side project of mine, tile-based (Easiest thing ever, right?) strategy game. I have given each "unit" a method to "see" tiles, based on a "viewRange" integer. The way that I have it set up right now is that in my "Tile" class, if a tile is not within the view range of any units, it just defaults to a gray "Fog of War" tile. Otherwise, it draws the actual tile image (Grass, Mountain, whatever).

   Anyways, I'm having difficulty setting up a loop that will take care of this automatically, and can be applied as-is without hard-coding anything specific to each "unit" type. The unit I'm experimenting with is a "scanProbe", that can has a 5-tile viewRange. My current method is to have a for loop, starting at -viewRange (To start the value of viewRange to the left/above unit), and adding 1 for every iteration. I'm then setting "tile[unitTileX + i][unitTileY + i].canBeSeen = true;". Github for more in-depth study is here: https://github.com/RyanMB97/TileBasedStrategy. Classes worth mentioning are: "Level", "Tile", "Entity", and "ScanProbe".

   A quick thanks in advance for whoever can help me solve this. Also, seems worth mentioning, but could anyone tell me how to get either a block-like view area, or a diamond-like view area? Thanks again!

P.S.: Almost forgot that a picture would probably be useful:
Offline RyanMB97

Junior Member


Medals: 1
Projects: 1



« Reply #1 - Posted 2013-09-14 04:54:28 »

   Quick update: I figured it out. I was trying to fit it inside of a single for (int i = 0) loop. What I should've been doing is a nested loop for both x and y, separately.
1  
2  
3  
4  
5  
6  
7  
8  
9  
public void seeTiles(Tile tiles[][]) {
      for (int x = -viewRange; x <= viewRange; x++) {
         for (int y = -viewRange; y <= viewRange; y++) {
            if(game.getLevel().tiles[tileX + x][tileY + y] != null){
               game.getLevel().tiles[tileX + x][tileY + y].setCanBeSeen(true);
            }
         }
      }
   }

   A quick snippet from my "Entity" class. I found a separate algorithm/technique that can give a diamond-shape if I wanted. Anyways, just wanted to say that the thread can be closed.

   P.S. Link to the diamond-method can be found here: http://www.java2s.com/Tutorial/Java/0080__Statement-Control/PrintoutaDiamond.htm. Just change the "System.out.print" to the tiles that you want changed.
Offline lcass
« Reply #2 - Posted 2013-09-15 15:40:49 »

It depends what you are trying to do , i think you are attempting to do a radius. So for a radius use a = Atan(angle) to plot your directions then add  sin(a) to x each time and cos(a) to y each time. then draw the respective tile.
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.

xsi3rr4x (50 views)
2014-04-15 18:08:23

BurntPizza (46 views)
2014-04-15 03:46:01

UprightPath (62 views)
2014-04-14 17:39:50

UprightPath (44 views)
2014-04-14 17:35:47

Porlus (61 views)
2014-04-14 15:48:38

tom_mai78101 (84 views)
2014-04-10 04:04:31

BurntPizza (142 views)
2014-04-08 23:06:04

tom_mai78101 (242 views)
2014-04-05 13:34:39

trollwarrior1 (201 views)
2014-04-04 12:06:45

CJLetsGame (208 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!