I've been trying to make a tile engine for AAAGES, and I've got further than ever before! Well, I've been able to get the window up without any errors. But still no tiles. At one point there was one red one in the top left corner, but after a bit of tweaking that unfortunately disappeared. I've been using this as my example: https://github.com/captainkraft/Orc-Canyon

But, I've had an idea in my head for a while now for a small and simple-ish top-down puzzle game using the Slick2D library. In the game, you're trying to break out of a jail cell, but walls block your exit. These walls are attached to pressure plates, and you have to stand on them to make the walls move. I've included a basic idea below (Paint ftw):

At the minute I've got 2 sorts of tiles, one black and one green. The window just shows empty blackness. I'm not sure if this is the correct way of going about this, so any suggestions are very welcome!

The first 8 steps and my code are covered in http://slick.cokeandcode.com/wiki/doku.php?id=01_-_tiled_and_maps1. Google Tiled2. First link should be "Tiled Map Editor", click that3. On the right hand side click download (download your OS version)4. Open Tiled, go to File->New Map-> Set your map size and type (your game view is Orthogonal)5. Go to Edit->Preferences->Store tile later data as: "Base64(gzip compressed)"6. Go to Map->New Tileset->Find the tile image you want to use7. Draw in your map with your tiles located at the bottom right8. Go to File->Save As->Save your map into your game's res folder

NOTE: Make sure to save your tile images where you save your map. So have your res folder contain the map AND the tiles.

Here is some example code for running your game, NOTE: I'm no expert in Slick2D and this code is incomplete and not optimized (in the future you will learn about using an entity system) but this should help you as a starting point.http://pastebin.java-gaming.org/038ee1a8e2e

If all of he following still doesn't help you: remember to add in a System.out.println(); at certain points to check what is and isn't being called. Using System.out.println(); you can also display variable values and see if something is changing or being set properly. If even that doesn't work try to pinpoint what isn't working for you and I can help. Good luck!

NOTE: Currently (and in this post) I've been replying to your post as if the player has to constantly stand on your pressure plate in order for the block to be moved up. Once the player steps off the pressure plate the blocking wall is moved back into position.

This code checks if the player Polygon is either intersecting or contained by the the pressure plate Polygon. It basically reads "If the player is touching or inside the pressure plate".

What this code does is change the map. It looks like to me your map is made up of these tiles, outer wall, pressure block, regular tiles, and blocking wall. In Tiled you'll draw the map with the wall initially blocking the exit. Then with this code, when the player is standing on the pressure plate, you switch the tiles at and above the blocking wall so that the exit is now un-blocked.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

// Each tile in your map has an ID, when you change its ID you change the tile.

// As an example we will say that the ID for a regular tile is 1 and that the ID for a regular tile is 2.// We will also say that the x location of the blocking tile is 30 and its y location is 16.if (pressurePlate.intersects(player) || pressurePlate.contains(player)){// Set the blocking tile to 1 position higher.map.setTileId(30, 15, 0, 2);// Set the old blocking position to a regular tile.map.setTileId(30, 16, 0, 1); } else {// Since the map is now blocked, do the reverse of the above// Set the blocking tile to default position.map.setTileId(30, 16, 0, 2);// Set the position above the blocking wall as a regular tile.map.setTileId(30, 15, 0, 1); }}

if (pressurePlate.contains(player)){// Set the blocking tile to 1 position higher.map.setTileId(540, 180, 0, 4);// Set the old blocking position to a regular tile.map.setTileId(540, 240, 0, 1); } else {// Since the map is now blocked, do the reverse of the above// Set the blocking tile to default position.map.setTileId(540, 180, 0, 1);// Set the position above the blocking wall as a regular tile.map.setTileId(540, 240, 0, 4); }if (pressurePlate.intersects(player) || pressurePlate.contains(player)) {System.out.println("C'est true"); }

The xTileLocation is the actual map tile location, not the pixel location on screen. For your code to work you would have to have at least 541 tiles in the x direction and 181 tiles in the y direction.

I understand your just starting out right now, but later on in development i would recommend loading the tiles in from a file structure rather than directly through an array declared within the program, it means later on you can create an engine to design levels in and you'll be able to have a lot less excess code.

Keep going at it, i remember when i was doing what you're doing now and sometimes it gets annoying when things don't work but if you keep trying you'll get used to it all

Unfortunately that doesn't work :/ I'm not really sure how to get this to work at all I may just stick to playing other peoples' games haha

Don't give up, if you're stuck what I sometimes do is create the game or just the methods/classes which arent working from scratch again. This usually makes what's going wrong or what you need to do clearer.

What is your understanding of Java? If Slick2D seems too complicated you might want to do some reading on Slick2D tutorials and/or Java. Also do not feel over overwhelmed trying to make a game; it is a lot of work but it is easy to accomplish when you make the game in steps.

Here is a very basic version of your game, you can simply copy paste this and it will be up and running. If all the code here makes sense to you we can move on to the next step. Please ask any questions you have otherwise.

NOTE: This code does not use the program Tiled and Slick2Ds TiledMap system.

// Game is drawn here.publicvoidrender(GameContainergc, Graphicsg) throwsSlickException {// Draw the pressure plate with the color red.g.setColor(Color.red);g.fill(pressurePlate);

// Draw the plate with the color yellow.g.setColor(Color.yellow);g.fill(player);

// Draw the blocking wall with the color blue.g.setColor(Color.blue);if (blocked) {// The exit is now blocked so have the blocking wall be in the way.g.fillRect(700, 300, 32, 32); } else {// The exit is now not blocked so move the blocking wall up.g.fillRect(700, 200, 32, 32); }

// Game logic is updated here.publicvoidupdate(GameContainergc, intdelta) throwsSlickException {// This is needed to get input from the user.Inputinput = gc.getInput();

// WASD movement of the player.// In the future you will need to use delta when calculating movement.if (input.isKeyDown(Input.KEY_W)) {// Move the player up if the user is holding down W.yLocation--; } elseif (input.isKeyDown(Input.KEY_S)) {// Move the player down if the user is holding down S.yLocation++; } elseif (input.isKeyDown(Input.KEY_A)) {// Move the player left if the user is holding down A.xLocation--; } elseif (input.isKeyDown(Input.KEY_D)) {// Move the player right if the user is holding down D.xLocation++; }

// Sets the player coordinatesplayer.setX(xLocation);player.setY(yLocation);

// Checks to see if the player is standing on the pressure plate.if (pressurePlate.intersects(player) || pressurePlate.contains(player)) {// If the player is standing on the pressure plate move the blocking wall up.blocked = false; } else {// The player is not standing on the pressure plate so block the exit.blocked = true; } }

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