Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (711)
Games in Android Showcase (213)
games submitted by our members
Games in WIP (785)
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 1120 times)
0 Members and 1 Guest are viewing this topic.
Offline RyanMB97

Junior Devvie

Medals: 1
Projects: 1

« Posted 2013-09-13 18: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: 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 Devvie

Medals: 1
Projects: 1

« Reply #1 - Posted 2013-09-14 02: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.
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: Just change the "System.out.print" to the tiles that you want changed.
Offline lcass
« Reply #2 - Posted 2013-09-15 13: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.

numerical (275 views)
2017-02-21 07:32:16

numerical (273 views)
2017-02-21 07:31:46

theagentd (385 views)
2017-02-18 13:42:33

theagentd (384 views)
2017-02-18 13:35:16

h.pernpeintner (1551 views)
2017-01-24 22:39:11

h.pernpeintner (1538 views)
2017-01-24 22:38:32

Galdo (2103 views)
2017-01-12 13:44:09

Archive (2103 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2639 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2347 views)
2016-12-15 21:50:57
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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!