Hello I'm currently working on a 2D platformer game. I would like to have per-pixel collisions between my player (a Rectangle) and a freeform terrain (uses slopes, a BufferedImage).
I am a bit confused on the concept to check if any part of my rectangle collides with the terrain.
Currently I'm trying to see if a part of my terrain contains a non-transparent pixel. I compare this to each coordinate in my rectangle and see if they meet, however I am not having luck.
Here is my code:
public boolean rgbCollide () {
int a = terrain.getRGB(x, y);
System.out.println(a);
// Per-pixel Bitwise collision check
for (int i =0; i < width; i++) {
for (int j =0; j < height; j++) {
//Hmm what to do here...?
}
}
return false;
}
where: terrain is my bufferedImage x,y,width, and height are my player's Rectangle coordinates