Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Tiled Based Lighting not working up and left on: 2013-04-07 03:33:29
I have solved the issue. it might be a temporary one, but it works! I just put my original code after the recursive code, and it seems to work. I'll work out a better solution later.
2  Game Development / Newbie & Debugging Questions / Re: Tiled Based Lighting not working up and left on: 2013-04-07 02:39:49
This is just an optional question, but is there a way to make the framerate not so pathetic (used to be about 80 fps, now with lighting is 11 fps avg.)?
3  Game Development / Newbie & Debugging Questions / Re: Tiled Based Lighting not working up and left on: 2013-04-07 01:30:42
Works all fine and dandy, also fixed the lightValue <= 0 thing, but now it looks like this:


I also cut out the boundary checker here, but it's still in the code (to reduce lines)
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  
public void lightSource(int x, int y, int lightValue) {
      if(lightValue <= 0) return;

      if(x == -1 && x > limitx && y == -1 && y > limity){
         //System.out.println("out of bounds " + x + " " + y + " " + limitx + " " + limity);
        return;
      }
       if ((light[y][x] >= lightValue) && lightValue > 0) { // Well, the light has already been set here, we can stop here.
         // System.out.println("light already set");
         return;
       }
     
       light[y][x] = lightValue;
       lightValue -= 1; // need to implement yourself
      // recursiveness:
     
     
      if(x - 1 != -1){
         lightSource((x - 1), y, lightValue);
      }
      if(y - 1 != -1){
         lightSource(x, (y - 1), lightValue);
      }
     
      if(x + 1 != limitx){
         lightSource((x + 1), y, lightValue);
      }
     
      if(y + 1 != limity){
         lightSource(x, (y + 1), lightValue);
      }
       
   }
   public void light() {
       // for each light source:
     for(int i = 0; i < limity; i++){
         for(int x = 0; x < limitx; x++){
            light[i][x] = 0; //darken to current time of day
        }
      }
     
     
     
      for(int by = ty; by < my; by++){
         for(int bx = tx; bx < mx; bx++){//for each block in the area
           if(layer2[by][bx].lightlevel > 0){ //for each LIGHT SOURCE
              lightSource(bx, by, layer2[by][bx].lightlevel);
               
            }else light[by][bx] = 0;
         }
      }
   }


I'm guessing it has something to do with the return statements not processing the rest of the lighting.
4  Game Development / Newbie & Debugging Questions / Re: Tiled Based Lighting not working up and left on: 2013-04-07 01:18:25
Also, my arrays go [Y][X], and not [X][Y]
5  Game Development / Newbie & Debugging Questions / Re: Tiled Based Lighting not working up and left on: 2013-04-07 00:56:41
I implemented the code and it only seems to make a ray of light going up. I'll look at it again, and fix it Tongue
EDIT: got a ton of errors of ArrayIndexOutOfBounds -1, and sometimes StackoverFlow errors.
6  Game Development / Newbie & Debugging Questions / Re: Tiled Based Lighting not working up and left on: 2013-04-07 00:52:35
Thanks! The very long code section was checking boundries for the world limit >.<

This really helps! Thanks! Cheesy

EDIT: sorry, layer2[][] is a block layer, and each block has a lightvalue of how much they give off.
7  Game Development / Newbie & Debugging Questions / Tiled Based Lighting not working up and left on: 2013-04-06 20:24:50
I have an issue where my tile based lighting code is not functioning properly going up and left. It works properly going right and downward (see image), but only goes one tile to the left/up and doesn't continue like it should. http://i.imgur.com/DAM1pg2.png

My code seems correct; I have placed print statements to check values (removed in sample) and it seems alright.

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  
public void light(){
     
     
      for(int i = 0; i < limity; i++){
         for(int x = 0; x < limitx; x++){
            light[i][x] = 0; //darken to current time of day
        }
      }
     
      int ty = (p.desiredy/32)-16;
      int tx = (p.desiredx/32)-16;
      if(ty > limity){
         ty = limity - 1;
      }
      if(ty < 0){
         ty = 0;
      }
      if(tx > limitx){
         tx = limitx - 1;
      }
      if(tx < 0){
         tx = 0;
      }
      int my = ty + 32;
      int mx = tx + 32;
      if(my > limity){
         my = limity - 1;
      }
      if(my < 0){
         my = 0;
      }
      if(mx > limitx){
         mx = limitx - 1;
      }
      if(mx < 0){
         mx = 0;
      }
     
      for(int by = ty; by < my; by++){
         for(int bx = tx; bx < mx; bx++){//for each block in the area
           if(layer2[by][bx].lightlevel > 0){ //for each LIGHT SOURCE
              light[by][bx] = layer2[by][bx].lightlevel;
               
            }else light[by][bx] = 0;
         }
      }
     
     
     
      for(int by = ty; by < my; by++){
         for(int bx = tx; bx < mx; bx++){//for each block in the area, do adjacent check
           
            if(light[by][bx] > 1){
               
               //now do blocks adjacent
              //left, right, up, down
              //must do a check for blocks, otherwise exception
              //then check if block is DARKER than itself
              if(bx - 1 != -1){
                  if(light[by][bx - 1] < light[by][bx]){
                     
                     light[by][bx - 1] = light[by][bx] - 1;
                  }
               }
               if(by - 1 != -1){
                  if(light[by - 1][bx] < light[by][bx]){
                     light[by - 1][bx] = light[by][bx] - 1;
                  }
               }
               
               if(bx + 1 != limitx){
                  if(light[by][bx + 1] < light[by][bx]){
                     light[by][bx + 1] = light[by][bx] - 1;
                  }
               }
               
               if(by + 1 != limity){
                  if(light[by + 1][bx] < light[by][bx]){
                     light[by + 1][bx] = light[by][bx] - 1;
                  }
               }
               
            }
         }
         //System.out.println("end of y loop, " + ty + " " + my);
     }
     
   }
Pages: [1]
 

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 (12 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (182 views)
2014-04-01 02:16:10
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

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