Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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  
  get stuck all time  (Read 910 times)
0 Members and 1 Guest are viewing this topic.
Offline ranopenjl

Junior Newbie





« Posted 2012-02-06 13:06:57 »

Hello,
i use LWJGL(opengl) and i learn from this tutorial:http://www.youtube.com/watch?v=7G_xtkvyleM
from the beginning everything worked just fine until now:(
i dont know why every time i play this mini game(mine craft 2d) , the window is black and everything get stuck.
why is that happening ?
is that a problem with my processor(intel coreTM 2) ?
or maybe its the display adapters(NVIDIA GeForce 9500 GT)?
help please ! ty.
and if you wanna see my code just ask.
Online theagentd
« Reply #1 - Posted 2012-02-06 13:29:26 »

Yes, we would like to see your code. It's kind of hard to diagnose a disease over a phone when you're told the symptom of the patient is "something is wrong"...  Wink From what you did tell us however, I'd say that this is most likely not a hardware problem.

Also, if you really want an answer quickly I recommend that you create at least one thread in each sub-forum on JGO. The sub-forum topics are just recommendation, so if you're really important anything goes. Also consider spamming private messages to Riven (our glorious leader) and pretty much anyone else if your problem is REALLY urgent.
[/joke]  Wink

Myomyomyo.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #2 - Posted 2012-02-06 16:54:37 »

Also, if you really want an answer quickly I recommend that you create at least one thread in each sub-forum on JGO. The sub-forum topics are just recommendation, so if you're really important anything goes. Also consider spamming private messages to Riven (our glorious leader) and pretty much anyone else if your problem is REALLY urgent.
I am Riven, and I endorse this message.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline ranopenjl

Junior Newbie





« Reply #3 - Posted 2012-02-07 17:08:59 »

fine , here's the classes:
BLOCK class:
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  
package mineCraft2d;


import static mineCraft2d.World.BLOCK_SIZE;
import static org.lwjgl.opengl.GL11.*;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class Block
{


   private BlockType type = BlockType.AIR;
   private float x;
   private float y;
   private Texture texture = null;
   
   public Block(BlockType type, float x, float y) {
      super();
      this.type = type;
      this.x = x;
      this.y = y;
      try
      {
         this.texture = TextureLoader.getTexture("PNG",new FileInputStream(new File(type.location)));
      } catch (FileNotFoundException e)
      {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
   }


   public void draw()
   {
      texture.bind();
      glLoadIdentity();
      glTranslatef(x,y,0);
      glBegin(GL_QUADS);
      glTexCoord2f(0,0);
      glVertex2f(0,0);
      glTexCoord2f(1,0);
      glVertex2f(BLOCK_SIZE,0);
      glTexCoord2f(1,1);
      glVertex2f(BLOCK_SIZE,BLOCK_SIZE);
      glTexCoord2f(0,1);
      glVertex2f(0,BLOCK_SIZE);
      glEnd();
      glLoadIdentity();
   }
   public BlockType getType() {
      return type;
   }


   public void setType(BlockType type) {
      this.type = type;
   }


   public float getX() {
      return x;
   }


   public void setX(float x) {
      this.x = x;
   }


   public float getY() {
      return y;
   }


   public void setY(float y) {
      this.y = y;
   }
   
}


BlockGrid class:
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  
package mineCraft2d;


import static mineCraft2d.World.*;


public class BlockGrid
{
   private Block[][] blocks = new Block[BLOCKS_WIDTH][BLOCKS_HEIGHT];
   
   public BlockGrid()
   {
     
      for(int i=0 ; i<BLOCKS_WIDTH - 1 ; i++)
      {
         for(int j=0 ; j<BLOCKS_HEIGHT - 1 ; j++)
         {
            blocks[i][j] = new Block(BlockType.AIR,i * BLOCK_SIZE,j * BLOCK_SIZE);
         }
      }
     
   }
   
   public void setAt(int x , int y , BlockType b)
   {
      blocks[x][y] = new Block(b,x * BLOCK_SIZE,y * BLOCK_SIZE);
   }
   public Block getAt(int x , int y)
   {
      return blocks[x][y];
   }
   public void draw()
   {
      for(int i=0 ; i<BLOCKS_WIDTH - 1 ; i++)
      {
         for(int j=0 ; j<BLOCKS_HEIGHT - 1 ; j++)
         {
            blocks[i][j].draw();
         }
      }
   }
   
   
}


blockType class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
package mineCraft2d;


public enum BlockType
{


   STONE("res/stone.png") , AIR("res/air.png") , GRASS("res/grass.png") , DIRT("res/dirt.png");
   public final String location;
   
    BlockType(String location)
   {
      this.location = location;
   }
   
}


Boot class:
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  
package mineCraft2d;




import static org.lwjgl.opengl.GL11.*;


import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.*;
import org.lwjgl.*;


public class Boot
{
   BlockGrid grid;
   
   public Boot()
   {
      try
      {
         Display.setDisplayMode(new DisplayMode(640,480));
         Display.setTitle("Minecraft 2D");
         Display.create();
      }catch(LWJGLException e)
      {
         e.printStackTrace();
         
      }
     
      grid = new BlockGrid();
      grid.setAt(10,10,BlockType.STONE);
     
     
      //initialization code OpenGL
     glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0,640,480,0,1,-1);
      glMatrixMode(GL_MODELVIEW);
      glEnable(GL_TEXTURE_2D);
     
      while(!Display.isCloseRequested())
      {
         glClear(GL_COLOR_BUFFER_BIT);
         
         input();
         grid.draw();
         
         Display.update();
         Display.sync(60);
         
      }
     
      Display.destroy();
     
   }
   
   private void input()
   {
      int mousex = Mouse.getX();
      int mousey = 480 - Mouse.getY() - 1;
      boolean mouseClicked = Mouse.isButtonDown(0);
      if(mouseClicked)
      {
         int grid_x = Math.round(mousex / World.BLOCKS_WIDTH);
         int grid_y = Math.round(mousex / World.BLOCKS_HEIGHT);
         grid.setAt(grid_x, grid_y, BlockType.STONE);
      }
     
   }
   
   public static void main(String[] args)
   {
     
      new Boot();
     
     
   }
}


World class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
package mineCraft2d;






public class World
{


   public static final int BLOCK_SIZE = 32;
   public static final int BLOCKS_WIDTH = 24 , BLOCKS_HEIGHT = 20;
   
   
}

that's it.Smiley
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #4 - Posted 2012-02-07 18:52:27 »

For starters...


Change this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
   public void draw()
   {
      for(int i=0 ; i<BLOCKS_WIDTH - 1 ; i++)
      {
         for(int j=0 ; j<BLOCKS_HEIGHT - 1 ; j++)
         {
            ...
         }
      }
   }


To this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
   public void draw()
   {
      for(int i=0 ; i<BLOCKS_WIDTH; i++)
      {
         for(int j=0 ; j<BLOCKS_HEIGHT; j++)
         {
            ...
         }
      }
   }

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline ranopenjl

Junior Newbie





« Reply #5 - Posted 2012-02-07 19:04:36 »

it didnt help:(
another suggestions ?
Offline OttoMeier

Senior Member


Medals: 4
Projects: 1



« Reply #6 - Posted 2012-02-07 20:35:53 »

http://www.jeffwofford.com/?p=843
Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #7 - Posted 2012-02-07 23:36:55 »

I have been wanting a similar article to show to my friend for ages! I was really close to finally writing something similar Tongue
Thank you!

@OP
Rarely will anyone look through all your code and figure out what the problem is. You should at least have some sense of where the bug might occur, but just dumping it all on us will not help you very much :/

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (96 views)
2013-05-17 21:29:12

alaslipknot (104 views)
2013-05-16 21:24:48

gouessej (134 views)
2013-05-16 00:53:38

gouessej (129 views)
2013-05-16 00:17:58

theagentd (140 views)
2013-05-15 15:01:13

theagentd (127 views)
2013-05-15 15:00:54

StreetDoggy (169 views)
2013-05-14 15:56:26

kutucuk (191 views)
2013-05-12 17:10:36

kutucuk (194 views)
2013-05-12 15:36:09

UnluckyDevil (200 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.292 seconds with 21 queries.