Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
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 1284 times)
0 Members and 1 Guest are viewing this topic.
Offline ranopenjl

Junior Newbie





« Posted 2012-02-06 12: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.
Offline theagentd
« Reply #1 - Posted 2012-02-06 12: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.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2012-02-06 15: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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ranopenjl

Junior Newbie





« Reply #3 - Posted 2012-02-07 16: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
Online Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2012-02-07 17: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
Offline ranopenjl

Junior Newbie





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

it didnt help:(
another suggestions ?
Offline OttoMeier

Senior Member


Medals: 4
Projects: 1



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

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

JGO Kernel


Medals: 346
Projects: 3
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2012-02-07 22: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.

 

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

The first screenshot will be displayed as a thumbnail.

BurntPizza (27 views)
2014-09-21 02:42:18

BurntPizza (18 views)
2014-09-21 01:30:30

moogie (19 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (44 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (100 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56

mitcheeb (71 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!