Collision Detection

I made a little Rectangle for my Player, I got it set up for a bit.
Can someone now tell me how I can listen to collisions from my Player?
You can find my source here: https://github.com/Desmaster/Stibbs
Biggest part of the Rectangle is in the class Player (*.player.Player)

Thanks for the help so far!

I don’t see a player class within Stibbs. Do you mean here ?

Your already listening to collissions with these lines?

for (Block blocks: Level.grassBlocks) {
if (playerRect.intersects(blocks)) {
playerRect.y = blocks.y;
Skyrim.say(“DERPPP”);
}
}

If you need to do actions on the event, this can be annoying.
you can check wich side is closest to the player (left, right, top or bottom).
Then according to this you could move the player like:

x = blocks.x - playerWidth; //Move to left side of block

or

x = blocks.x + blocks.width; //Move to right side of block

Same with the top and bottom, after this you need to update the player rect.

Sorry about that, I forgot to sync my git!
Please go look for it again,.

Thanks

First of all you shoudent put all those lines in your render code, because you will only need to call these when you change projections.
You should put then in your initGL

		GL11.glMatrixMode(GL11.GL_PROJECTION);
			GL11.glLoadIdentity();
			GL11.glOrtho(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight(), 1, -1);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
			GL11.glColor3f(1.0f, 1.0f, 1.0f);

I have no idea what your trying to do in your tick() function, but you should move your player and then theck collission with all objects in the room.
Just check the collission rectangle of the player with the collission rectangle of other objects / players.

It may be better to check collision first as you don’t want to move your player where he cant go.

Basically, check of collision, no collision? move, else do stuff.

Also, after you collide with something, do not check to see if you collided with other things as that is probably unnecessary computations.

If I would cut that part of code and put that into initGL(), it would give me plenty of errors.


public void tick() {
	int colsens = (int) (width % (height * width)) / 2;
	rect.setX((int) x);
	rect.setY((int) y);
	colbox.setX((int) x);
	colbox.setY((int) y);
	colbox.setWidth((int) (width + width / colsens));
	Stibbs.say("set width!");
	colbox.setHeight((int) (height + height / colsens));
	Stibbs.say("set height!");
}

First of all, I’m setting my player(rect) to the x and y positions to keep them synced.
Same to colbox(collision box) which will be the area around my player which will detect collision.
After that, it sets the width and height of the collision box, divided by colsens(collision sensivity).
That’s basically my tick method