I'm making a sidescroller using java and Lwjgl. But I'm having some trouble getting the screen to actually ... well... sidescroll. The world is randomly generated and drawn in blocks. Like so:
block[x][y] = new Block(BlockType.STONE, x * BLOCK_SIZE, y * BLOCK_SIZE); At the moment I have it so that the player's sprite just moves around independently. But when I try to move it using the glTranslatef method, nothing happens. 41 blocks by 41 blocks are seen on the screen and I have the total world at 60 blocks by 60 blocks. If you could help me actually get this to work that would be GREAT! :D
If anything is unclear just ask and I'll be sure to update you with whatever is necessary.
Thank you for your time!
EDIT: Here's the code for the map generation, sorry it's so long I'm not sure where to condense it:
for(int x = 0; x < worldW; x++) { for(int y = 0; y < worldH; y++) { /* Null pointer on THIS line */ block[x][y] = new Block(BlockType.AIR, (x * BLOCK_SIZE) - cam.getX(), (y * BLOCK_SIZE) - cam.getY()); } } for(int y = 0; y < worldW; y++) { for(int x = 0; x < worldH; x++) { //Random dirt (world) generation// if(y > worldH / 6) { if(rand.nextInt(100) > 10) { try { if(block[x - 1][y - 1].getType() == BlockType.DIRT) { block[x][y] = new Block(BlockType.DIRT, (x * BLOCK_SIZE) - cam.getX(), (y * BLOCK_SIZE) - cam.getY()); } } catch(Exception e) { } } if(rand.nextInt(100) > 10) { try { if(block[x + 1][y - 1].getType() == BlockType.DIRT) { block[x][y] = new Block(BlockType.DIRT, (x * BLOCK_SIZE) - cam.getX(), (y * BLOCK_SIZE) - cam.getY()); } } catch(Exception e) { } } try { if(block[x][y - 1].getType() == BlockType.DIRT) { block[x][y] = new Block(BlockType.DIRT, (x * BLOCK_SIZE) - cam.getX(), (y * BLOCK_SIZE) - cam.getY()); } } catch(Exception e) { } if(rand.nextInt(100) < 10) { block[x][y] = new Block(BlockType.DIRT, (x * BLOCK_SIZE) - cam.getX(), (y * BLOCK_SIZE) - cam.getY()); } } //Random stone generation// if(y > worldH / 4) { if(rand.nextInt(100) > 20) { try { if(block[x - 1][y - 1].getType() == BlockType.STONE) { block[x][y] = new Block(BlockType.STONE, (x * BLOCK_SIZE) - cam.getX(), (y * BLOCK_SIZE) - cam.getY()); } } catch(Exception e) { } } if(rand.nextInt(100) > 20) { try { if(block[x + 1][y - 1].getType() == BlockType.STONE) { block[x][y] = new Block(BlockType.STONE, (x * BLOCK_SIZE) - cam.getX(), (y * BLOCK_SIZE) - cam.getY()); } } catch(Exception e) { } } try { if(block[x][y - 1].getType() == BlockType.STONE) { block[x][y] = new Block(BlockType.STONE, (x * BLOCK_SIZE) - cam.getX(), (y * BLOCK_SIZE) - cam.getY()); } } catch(Exception e) { } if(rand.nextInt(100) < 5) { block[x][y] = new Block(BlockType.STONE, (x * BLOCK_SIZE) - cam.getX(), (y * BLOCK_SIZE) - cam.getY()); } } } } //Placing grass blocks// for(int y = 0; y < block.length; y++) { for(int x = 0; x < block[0].length; x++) { if(block[x][y].getType() == BlockType.DIRT && block[x][y - 1].getType() == BlockType.AIR) { block[x][y] = new Block(BlockType.GRASS, (x * BLOCK_SIZE) - cam.getX(), (y * BLOCK_SIZE) - cam.getY()); } } } EDIT 2:
Ok, so here's the code that I use for rendering a block itself, not the logic for where to place it, just the block:
public void render() { texture.bind(); glLoadIdentity(); glTranslatef(x, y, 0); glBegin(GL_QUADS); glTexCoord2f(0, 0); //Top left texture corner glVertex2f(0, 0); glTexCoord2f(1, 0); //Top right texture corner glVertex2f(BLOCK_SIZE, 0); glTexCoord2f(1, 1); //Bottom right texture corner glVertex2f(BLOCK_SIZE, BLOCK_SIZE); glTexCoord2f(0, 1); //Bottom left texture corner glVertex2f(0, BLOCK_SIZE); glEnd(); glLoadIdentity(); } 
