Best collision pixel perfect system EVER, without physics (T_T)

Sup, community, I’m newbie. I’m creating a game with elements of classic platformer (Mario, etc…) on Slick2D. I made a pixel perfect, quick and simple system collision, I think. You can download and try for yourself. But I have some problems with physics (jump, gravity, acceleration). I learned a lot of stuff, soo… and I have no idea how it works. Please, help! T__T

Oh, sorry…


// CHECK
collides(Level level) {
	boolean result = false;
		// TOP
		if (is_tile_solid(x+1, y, level)) result = true;
		if (is_tile_solid(x+w-2, y, level)) result = true;
		// BOTTOM
		if (is_tile_solid(x+1, y+h-1, level)) result = true;
		if (is_tile_solid(x+w-2, y+h-1, level)) result = true;
		// LEFT
		if (is_tile_solid(x, y+1, level)) result = true;
		if (is_tile_solid(x, y+h-2, level)) result = true;
		// RIGHT
		if (is_tile_solid(x+w-1, y+1, level)) result = true;
		if (is_tile_solid(x+w-1, y+h-2, level)) result = true;
	return result;
}


// MOVE ENTITY
void move(Level level, int delta) {
	float axs = Math.abs(xs);
	float ays = Math.abs(ys);
	float max = ays;
	if (axs > ays) { max = axs; }
	float xstep = xs/max;
	float ystep = ys/max;
	float axstep = Math.abs(xstep);
	float aystep = Math.abs(ystep);
	while (axs > 0 || ays > 0) {
		x += xstep;
		if (collides(level)) { x -= xstep; }
		y += ystep;
		if (collides(level)) { y -= ystep; }
		axs -= axstep;
		ays -= aystep;
	}
}


// COLLISION
boolean is_tile_solid(float xpos, float ypos, Level level) {
	int i = (int) ((xpos) / Level.tilesize);
	int j = (int) ((ypos) / Level.tilesize); 
	if (i >= 0 && i < level.getMapWidth() && j >= 0 && j < level.getMapHeight()) {
		if ( level.getMap().getTileId(i, j, Cnst.COLLISION) == Cnst.SOLID ) return true;
		else return false;
	}
	return true;
}

First, what specifically is your problem? No one can help you if you don’t actually tell us what is wrong. Second, you know you just gave out the source code to your game right? On your website, you need to actually export the .jar file instead of giving us your workspace.

If you are using Slick2D you could use Rectangles for collision. They’re pretty simple and easy to use.

I believe that this post was just to show off the code that he wrote. I’ve based this conclusion off of the topic title.

Ah I feel stupid now. OP, sorry for the criticism!

But I think he’s still looking for help:

Check this out: http://www.java-gaming.org/topics/how-to-start-with-lwjgl-physics/29112/view.html

It´s got a couple of really good links where you can read up on game physics.

You know this:


  
// COLLISION
   boolean is_tile_solid(float xpos, float ypos, Level level) {
   int i = (int) ((xpos) / Level.tilesize);
   int j = (int) ((ypos) / Level.tilesize); 
   if (i >= 0 && i < level.getMapWidth() && j >= 0 && j < level.getMapHeight()) {
      if ( level.getMap().getTileId(i, j, Cnst.COLLISION) == Cnst.SOLID ) return true;
      else return false;
   }
   return true;
}

This isn’t a pixel-perfect test right?

Unless your map itself is made of game pixels which is quite a memory hog.

Sorry, that is not expressed. I need a pseudocode of jump & gravity.

https://www.google.de/search?q=platformer+jump+gravity+site%3Ajava-gaming.org

Okay.jpg
I apologize for the stupid question.


definitely check that out! I asked a similar question about jumping / gravity

Ha ha. Exactly what i was originally thinking Tod post, but couldn’t find it :smiley:

Thanx! When I’m done, I’ll share source code.