Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  Java Game APIs & Engines / OpenGL Development / Re: get stuck all time on: 2012-02-07 18:04:36
it didnt help:(
another suggestions ?
2  Java Game APIs & Engines / OpenGL Development / Re: get stuck all time on: 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
3  Java Game APIs & Engines / OpenGL Development / get stuck all time on: 2012-02-06 12:07:41
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.
4  Java Game APIs & Engines / OpenGL Development / get stuck all time on: 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.
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.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (58 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
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!