Tile-based game help!

try

if (pressurePlate.intersects(player){

Does that work?

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

-Hope it helps :slight_smile:

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

Cmon, man. Don’t give up. Persistence is the best thing a programmer can have.

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.

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Polygon;

// A basic version of your game.
public class SimplePuzzleGame extends BasicGame {

	// The player and the pressure plate.
	private Polygon player;
	private Polygon pressurePlate;

	// The location of the player.
	private float xLocation;
	private float yLocation;

	// The location of the pressure plate.
	private int yourXPixelOfChoice;
	private int yourYPixelOfChoice;

	// Blocked is equal to false when the player is standing on the pressure plate.
	private boolean blocked = true;

	public SimplePuzzleGame() {
		super("Slick2DPath2Glory - SimplePuzzleGame");
	}

	// Initialize all variables here.
	public void init(GameContainer gc) throws SlickException {

		// Creates the player and pressure plate as a polygon.
		player = new Polygon(new float[] { 0, 0, 32, 0, 32, 32, 0, 32 });
		pressurePlate = new Polygon(new float[] { 0, 0, 32, 0, 32, 32, 0, 32 });

		// Sets the location of the pressure plate.
		yourXPixelOfChoice = 200;
		yourYPixelOfChoice = 200;
		pressurePlate.setX(yourXPixelOfChoice);
		pressurePlate.setY(yourYPixelOfChoice);

		// Sets the initial location of the player.
		xLocation = 50;
		yLocation = 50;
		player.setX(xLocation);
		player.setY(yLocation);
	}

	// Game is drawn here.
	public void render(GameContainer gc, Graphics g) throws SlickException {
		// 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);
		}
		
		g.setColor(Color.white);
		// Text to help understand gameplay.
		g.drawString("This is the pressure plate.", yourXPixelOfChoice - 90, yourYPixelOfChoice - 30);
		g.drawString("This is the player.", xLocation - 60, yLocation - 30);
		g.drawString("Blocked ->", 500, 300);
		g.drawString("Not blocked ->", 500, 200);
	}

	// Game logic is updated here.
	public void update(GameContainer gc, int delta) throws SlickException {
		// This is needed to get input from the user.
		Input input = 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--;
		} else if (input.isKeyDown(Input.KEY_S)) {
			// Move the player down if the user is holding down S.
			yLocation++;
		} else if (input.isKeyDown(Input.KEY_A)) {
			// Move the player left if the user is holding down A.
			xLocation--;
		} else if (input.isKeyDown(Input.KEY_D)) {
			// Move the player right if the user is holding down D.
			xLocation++;
		}

		// Sets the player coordinates
		player.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;
		}
	}

	// Program starts here.
	public static void main(String[] args) throws SlickException {
		AppGameContainer app = new AppGameContainer(new SimplePuzzleGame());

		app.setDisplayMode(800, 600, false);
		app.start();
	}
}

I have an embarrassingly small understanding of Java, but I’m doing my best to learn :stuck_out_tongue: I can understand all of that, that’s a great example by the way! Thanks mate.