Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  [Help]2D tile map lighting  (Read 7433 times)
0 Members and 1 Guest are viewing this topic.
Offline Tom-Todd

Senior Newbie





« Reply #30 - Posted 2012-04-25 23:19:06 »

Nothing shows up... I was using 2 for loops to run through the x/y positions I wanted to check for lighting...
EDIT: Oh, It was due to a stupid error I made... no worries, seems to be working great Cheesy - Just need to clean it all up now, bit messy currently
Offline Ciaran54

Junior Member


Medals: 4



« Reply #31 - Posted 2012-04-25 23:23:53 »

hmm... would you like to post your code for some help, or try at it yourself some more? I can't really tell much more without actually seeing what you've done...

It'll work out in the end, don't you worry Tongue
Offline Tom-Todd

Senior Newbie





« Reply #32 - Posted 2012-04-25 23:26:56 »

Nah, it seems to be working fine now, thanks, I'll fiddle around with it, to get it looking exactly how I want it, but the hard work I feel is pretty much done for now, I shall clean up my code and post it up, in case anyone else wants a peek at it...
Thanks for all the help! Everyone's been really helpful. I'll probably make a thread about my Game at some point so I can post more about it...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Tom-Todd

Senior Newbie





« Reply #33 - Posted 2012-04-25 23:29:21 »

Oh, looks like some angles/lines may not be working... oops, will just check that out...
EDIT: Yeah it looks like when the line goes upwards and to the left it's not working... need to check why that is...
I'll post up my code and possibly some screenshots tomorrow, so you can see what's happening, for now Im off to bed, as I am tired...
but it's looking better than yesterday Smiley
Offline Tom-Todd

Senior Newbie





« Reply #34 - Posted 2012-04-25 23:38:10 »

Ok, I'll post up the code now, it's not working for the top left hand side, when the line gets past the tile above the one that I'm checking from...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package kingdom.blue;

import java.awt.Point;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;

/**
 *
 * @author Tom
 */

public class TileTorch extends Tile {

    public TileTorch(int x, int y, map m){
        lightLevel = 5;
        floorBlock = false;
        lightSurroundings(x,y,m);
    }
   
    public void lightSurroundings(int x, int y,map m){
       
        int firstx = x-4;
        int firsty = y-4;
       
       
        for(int x1 = firstx;x1 < x+4;x1++){
            for(int y1 = firsty;y1 < y+4;y1++){
               if(tileVisible(x,x1,y,y1,m)){
                   if(x1 > -1 && x1 < map.WIDTH){
                       if(y1 > -1 && y1 < map.HEIGHT){
                            if(m.Map[x1][y1] != null){
                                m.Map[x1][y1].lightLevel = 5;
                                System.out.println("lighting tile!");
                            }
                        }
                    }    
               }
            }
        }

    }
   
   
    public static boolean tileVisible(int x1, int x2, int y1, int y2, map m){
       
        int xinc1;
        int xinc2;
        int yinc1;
        int yinc2;
        int abs;
        int den;
        int num;
        int numadd;
        int numTiles;
        int deltax = (int)(x2 - x1);          
        int deltay = (int)(y2 - y1);        
        int x = x1;                                
        int y = y1;                                

        if (x2 >= x1)                          
        {
            xinc1 = 1;
            xinc2 = 1;
        }
        else                                              
        {
            xinc1 = -1;
            xinc2 = -1;
        }

        if (y2 >= y1)                          
        {
            yinc1 = 1;
            yinc2 = 1;
        }
        else                                              
        {
            yinc1 = -1;
            yinc2 = -1;
        }

        if (deltax >= deltay)          
        {
            xinc1 = 0;                              
            yinc2 = 0;                              
            den = deltax;
            num = deltax / 2;
            numadd = deltay;
            numTiles = deltax;          
        }
        else                                              
        {
            xinc2 = 0;                              
            yinc1 = 0;                              
            den = deltay;
            num = deltay / 2;
            numadd = deltax;
            numTiles = deltay;          
        }

        for (int currentTile = 0; currentTile <= numTiles; currentTile++)
        {
            if(x > -1 && x <= map.WIDTH){
                if(y > -1 && y <= map.HEIGHT){
                    if(m.Map[x][y] != null){
                        if(m.Map[x][y].lightBlock){
                            return false;
                        }
                    }
                }
            }
            num += numadd;                          
            if (num >= den)                      
            {
                num -= den;                    
                x += xinc1;                    
                y += yinc1;                    
            }
            x += xinc2;                          
            y += yinc2;                          
        }
        return true;
    }

}


Now I really am off to bed, I'll check back in the morning...
Offline Tom-Todd

Senior Newbie





« Reply #35 - Posted 2012-04-26 08:46:21 »

I've solved the problem, I used (int) instead of Maths.abs  for some strange reason, can't work out what I was thinking... maybe it was too late for my brain to work properly... who knows?
Offline Tom-Todd

Senior Newbie





« Reply #36 - Posted 2012-04-26 17:29:06 »

I'm now trying to figure out how to smooth the shadows, so they're not so sharp... I thought about having it check all the tiles that the torch has lit and checking if they have any unlit tiles next to them, if they do, changing the unlit tile's light value to something slightly higher... but that'd be messy...
Offline Ciaran54

Junior Member


Medals: 4



« Reply #37 - Posted 2012-04-27 00:54:39 »

I think that whatever you do, it's going to involve iterating through all of the tiles in the range of the light. A different technique might be to check for dark tiles and make the dark tile brighter, depending on how many light tiles it borders with, but its a matter of lighting style choice, best way to do it is probably just to try a few different things yourself. Implement different ways of calculating lighting values for unlit tiles, until you find something you like.
Pages: 1 [2]
  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.

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

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

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

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

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
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!