Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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  
  LibGDX top grass tiles  (Read 5568 times)
0 Members and 1 Guest are viewing this topic.
Offline VIrtueeL
« Posted 2015-09-21 16:35:40 »

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  
if(isAlive){
         if(body.isActive()){
           
            for(Chunk chunk : gameScreen.chunks){ <-- all game chunks
               
               Chunk checkCheck = chunk;
               
               for(Block blocks : checkCheck.getBlocks()){ <-- all chunks blocks
                 
                  Block checkBlock = blocks;
               
                  if(checkBlock != this){ <-- make sure its not the block we are currently checking
                     
                     if(checkBlock.blockFace_UP.overlaps(boxRectangle)){ if the if the checkbox'es rectangle above it overlaps the checking rectangle then we set it to dirt
                        setType(BlockType.DIRT);
                     }else{
                        setType(BlockType.GRASS_TOP); else we set it to grass top
                     }
                     
                  }
                 
                 
               }
               
            }
           
         }
      }


it just makes everything grass tiles

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #1 - Posted 2015-09-21 16:38:20 »

remove:
1  
2  
3  
else{
    setType(BlockType.GRASS_TOP); else we set it to grass top
}

Offline VIrtueeL
« Reply #2 - Posted 2015-09-21 16:42:00 »

remove:
1  
2  
3  
else{
    setType(BlockType.GRASS_TOP); else we set it to grass top
}


i want to be able to set all blocks underneath to dirt and all blocks that is not intersecting with anything from top to be dirt

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #3 - Posted 2015-09-21 16:45:38 »

Is it a side scroller? What kind of game is it. it's impossible to help without knowing.

so checkBlock.blockFace_UP.overlaps(boxRectangle) is always returning false?

Offline VIrtueeL
« Reply #4 - Posted 2015-09-21 16:50:36 »

Is it a side scroller? What kind of game is it. it's impossible to help without knowing.

so checkBlock.blockFace_UP.overlaps(boxRectangle) is always returning false?

yeah its a side scroller, but why is it false doh here are the rectangles
https://gyazo.com/4d59e4bfe47dae153391c918bbb6afd0

the once at top is suppose to be the grass tiles coos there rects are not intersecting with any block


i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #5 - Posted 2015-09-21 16:54:29 »

So the little rectangles are grass? Are your blocks in an array or list?

is blockFace_UP an adjacent block?

Offline VIrtueeL
« Reply #6 - Posted 2015-09-21 16:57:41 »

So the little rectangles are grass? Are your blocks in an array or list?

is blockFace_UP an adjacent block?

in a list

but not even this works :/

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
      boxRectangle = new Rectangle(block_pos.x - Assets.blockSize / 2, block_pos.x - Assets.blockSize / 2, 0.3f, 0.3f);
   
      blockFace_UP = new Rectangle(block_pos.x, block_pos.x , 0.3f, 0.3f);
     
//      if(isAlive){
//         if(body.isActive()){
            if(boxRectangle.contains(blockFace_UP)){
               setType(BlockType.GRASS_TOP);
            }
//         }
//      }


tried blockFace_UP = new Rectangle(block_pos.x - Assets.blockSize / 2, block_pos.x - Assets.blockSize / 2, 0.3f, 0.3f); as well

and just check my y was x but correcting it did not work

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #7 - Posted 2015-09-21 17:14:32 »

Is that image what it should look like? it's confusing. I can't tell whats grass.

No y coord?

1  
2  
3  
boxRectangle = new Rectangle(block_pos.x - Assets.blockSize / 2, block_pos.x - Assets.blockSize / 2, 0.3f, 0.3f);
   
blockFace_UP = new Rectangle(block_pos.x, block_pos.x , 0.3f, 0.3f);


to:

1  
2  
3  
boxRectangle = new Rectangle(block_pos.x - Assets.blockSize / 2, block_pos.y - Assets.blockSize / 2, 0.3f, 0.3f);
   
blockFace_UP = new Rectangle(block_pos.x, block_pos.y , 0.3f, 0.3f);

Offline VIrtueeL
« Reply #8 - Posted 2015-09-21 17:15:52 »

Is that image what it should look like? it's confusing. I can't tell whats grass.

No y coord?

1  
2  
3  
boxRectangle = new Rectangle(block_pos.x - Assets.blockSize / 2, block_pos.x - Assets.blockSize / 2, 0.3f, 0.3f);
   
blockFace_UP = new Rectangle(block_pos.x, block_pos.x , 0.3f, 0.3f);


to:

1  
2  
3  
boxRectangle = new Rectangle(block_pos.x - Assets.blockSize / 2, block_pos.y - Assets.blockSize / 2, 0.3f, 0.3f);
   
blockFace_UP = new Rectangle(block_pos.x, block_pos.y , 0.3f, 0.3f);

i edited those boxes, is where the boxRectangle is and where blockFace_UP  is the small once is all the blocks blockface up the bigger once are the blocks

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #9 - Posted 2015-09-21 17:20:33 »

I have no idea what you mean anymore.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline VIrtueeL
« Reply #10 - Posted 2015-09-21 17:22:48 »

I have no idea what you mean anymore.

checking the block with it self like this
1  
2  
3  
      boxRectangle = new Rectangle(block_pos.x , block_pos.y , 0.3f , 0.3f);
   
      blockFace_UP = new Rectangle(block_pos.x , block_pos.y, 0.3f , 0.3f);


and check if they overlap etch other works

but when i do this

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
      boxRectangle = new Rectangle(block_pos.x , block_pos.y , 0.3f , 0.3f);
   
      blockFace_UP = new Rectangle(block_pos.x , block_pos.y + 0.4f, 0.3f , 0.3f);
     
      if(isAlive){
         if(body.isActive()){
           
            for(Chunk chunk : gameScreen.chunks){
               
               for(Block block : chunk.getBlocks()){
                  if(block != this){
                     if(!block.boxRectangle.overlaps(this.blockFace_UP)){
                        setType(BlockType.DIRT);
                     }else{
                        setType(BlockType.GRASS_TOP);
                     }
                  }
   
                  break;
               }
            }
         }
      }


it does not work

and if you wonder why i add 0.4f to blockface its so the rectangle check moves up one block

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #11 - Posted 2015-09-21 17:33:48 »

Honestly I don't get your code.

if you use am array for the chunks you can do something like this:
Keeping it as similar as your original method.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
for (Chunk chunk : chunks) {
    for (int y = 0; y < rows; y++) {
        for (int x = 0; x < columns; x++) {
            if (chunk.blocks[x][y + 1] != null) {
                //has block on top
            } else {
                //is top block    
            }
        }
    }
}

Offline VIrtueeL
« Reply #12 - Posted 2015-09-21 17:36:25 »

Honestly I don't get your code.

if you use am array for the chunks you can do something like this:
Keeping it as similar as your original method.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
for (Chunk chunk : chunks) {
    for (int y = 0; y < rows; y++) {
        for (int x = 0; x < columns; x++) {
            if (chunk.blocks[x][y + 1] != null) {
                //has block on top
            } else {
                //is top block    
            }
        }
    }
}


i'am using arraylist btw =P just so you know can you convert that?

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline VIrtueeL
« Reply #13 - Posted 2015-09-21 18:17:34 »

can you? convert that code with arraylist instead?

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline Longarmx
« Reply #14 - Posted 2015-09-21 18:36:51 »

This is what I gather from what a compilation of your posts have said about this chunking system: Each chunk is 8x8, the world is comprised of chunks stretching left and right procedurally (un-bounded), and fixed vertically. The chunks are stored in a List, and the block inside of chunks are stored in individual Lists. Correct?

Assuming this (and keeping the same system), I would store the blocks in arrays (either 1D or 2D, it doesn't matter) inside each chunk instead of the Lists. The chunks themselves can continue to be stored in List format. That way, you can implement what KudoDEV suggested, which would be much easier than searching the List for each block.

Offline VIrtueeL
« Reply #15 - Posted 2015-09-21 18:53:46 »

This is what I gather from what a compilation of your posts have said about this chunking system: Each chunk is 8x8, the world is comprised of chunks stretching left and right procedurally (un-bounded), and fixed vertically. The chunks are stored in a List, and the block inside of chunks are stored in individual Lists. Correct?

Assuming this (and keeping the same system), I would store the blocks in arrays (either 1D or 2D, it doesn't matter) inside each chunk instead of the Lists. The chunks themselves can continue to be stored in List format. That way, you can implement what KudoDEV suggested, which would be much easier than searching the List for each block.

well so i did but get error here
1  
2  
3  
4  
5  
6  
7  
         for(int x = 0; x < chunkBlockList.length;x++){
            for(int y = 0; y < chunkBlockList.length;y++){
               if(chunkBlockList != null){
                  chunkBlockList[x][y].draw(batch);
               }
            }
         }


and here is where i add blocks to chunk

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  
      chunkBlockList = new Block[8][8];
     
      for(int x = 0; x < chunkBlockList.length;x++){
         for(int y = 0; y < chunkBlockList.length;y++){

           
            int col = map.getPixel(region.getRegionX() + x, region.getRegionY() + y);

            switch(col & 0xFFFFFFFF){
               
               case 0xFFFFFFFF:
                  chunkBlockList[x][y] = new Block(
                        this,
                        gameScreen,
                        chunk_pos.x + x * Assets.blockSize,
                        chunk_pos.y + y * Assets.blockSize, BlockType.DIRT);
                  System.out.println("ADDED: NEW DIRT BLOCK: "+x+","+y + " TYPE: "+chunkBlockList[x][y].getBlockType());
                 
                 
               break;
               
           
            }
         }  
      }


it gives me the msg and it says it adds blocks so why do i get NullPointerException


EDIT: Got Rid off the error

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #16 - Posted 2015-09-21 19:02:53 »

You're using

1  
chunkBlockList.length


Edit: Oh you fixed it.

Offline VIrtueeL
« Reply #17 - Posted 2015-09-21 19:05:53 »

You're using

1  
chunkBlockList.length


Edit: Oh you fixed it.

https://gyazo.com/e11f7eff60d2814e4d80d55642b2aa97

was not what i expected there is tons off dirt blocks at top that is still dirt and some chunks are just grass O,o

current code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
             for (int y = 0; y < 7; y++) {
                    for (int x = 0; x < 8; x++) {
                        if (chunk.chunkBlockList[x][y + 1] != null) {
                            //has block on top
                           setType(BlockType.DIRT);
                        } else {
                            //is top block    
                           setType(BlockType.GRASS_TOP);
                        }
                    }
                }

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline ags1

JGO Kernel


Medals: 356
Projects: 7


Make code not war!


« Reply #18 - Posted 2015-09-21 19:11:08 »

You need to learn to write test code. Design a universe with just 4 blocks and execute the method. What happens? Run it again using a debugger.

Offline VIrtueeL
« Reply #19 - Posted 2015-09-21 19:13:16 »

You need to learn to write test code. Design a universe with just 4 blocks and execute the method. What happens? Run it again using a debugger.

https://gyazo.com/623a1dc1b8f4fb4dd69abd8e306abc0b

well i kinda solve it but its still alot off dirt that is dirt at top

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #20 - Posted 2015-09-21 19:20:52 »

Well is that the top of that chunk?

Draw the bounds of the chunks. So that you can visualize better.

Offline VIrtueeL
« Reply #21 - Posted 2015-09-21 19:26:38 »

Well is that the top of that chunk?

Draw the bounds of the chunks. So that you can visualize better.

cant my ShapedRenderer overrides my textures for some reason =P

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline VIrtueeL
« Reply #22 - Posted 2015-09-21 21:36:01 »

Well is that the top of that chunk?

Draw the bounds of the chunks. So that you can visualize better.


this does not work with the system i want how would i fix like corner blocks and shit then?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
          for (int y = 0; y < 7; y++) {
              for (int x = 0; x < 8; x++) {
                 
               
               if(chunk.chunkBlockList[x][y] != null){
                     if (chunk.chunkBlockList[x][y + 1] != null) {
                         //has block on top
                        chunk.chunkBlockList[x][y].setType(BlockType.DIRT);
                     } else {
                         //is top block    
                        chunk.chunkBlockList[x][y].setType(BlockType.GRASS_TOP);
                       
                     }
               }
                 
              }
          }


this is all that does Sad
https://gyazo.com/b01db316c8a4256f401e519494a73325

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #23 - Posted 2015-09-21 23:57:36 »

There's an obvious pattern there. You can do it.

Offline VIrtueeL
« Reply #24 - Posted 2015-09-22 05:59:17 »

There's an obvious pattern there. You can do it.

i have been trying for hours now please come with a clue or something

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline VIrtueeL
« Reply #25 - Posted 2015-09-22 07:30:33 »

please help me with this problem?

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 485
Exp: 7 years



« Reply #26 - Posted 2015-09-22 07:57:15 »

Maybe you should redesign this part of your program, as it is clear you don't understand your current design.

Judging by the code snippets here, you probably have large chunks of code that do too many different things all mixed together in the same places.

Identify the individual problems to be solved and factor them out as functions and/or datatypes, then compose them together to form the overall solution. This style is easier to understand, test, and reuse in other parts of the program.
It is known as (Functional) Decomposition, a theme that permeates engineering in general, and in the context of computer science is the mark of a good programmer. Practice this pattern of thought and you'll do well.
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #27 - Posted 2015-09-22 13:24:09 »

I'll give you a hint. That's only part of the problem.

1  
2  
        for (int y = 0; y < 7; y++) {
              for (int x = 0; x < 8; x++) {

Offline VIrtueeL
« Reply #28 - Posted 2015-09-22 13:44:26 »

I'll give you a hint. That's only part of the problem.

1  
2  
        for (int y = 0; y < 7; y++) {
              for (int x = 0; x < 8; x++) {


well they cant both be 8 if i do
  • [y + 1]

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #29 - Posted 2015-09-22 14:38:09 »

You're looking at it the wrong way.

Pages: [1] 2
  ignore  |  Print  
 
 

 
xxMrPHDxx (17 views)
2017-11-21 16:21:00

xxMrPHDxx (11 views)
2017-11-21 16:14:31

xxMrPHDxx (14 views)
2017-11-21 16:10:57

Ecumene (114 views)
2017-09-30 02:57:34

theagentd (148 views)
2017-09-26 18:23:31

cybrmynd (248 views)
2017-08-02 12:28:51

cybrmynd (247 views)
2017-08-02 12:19:43

cybrmynd (244 views)
2017-08-02 12:18:09

Sralse (258 views)
2017-07-25 17:13:48

Archive (878 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!