I recently started learning Java, after doing around 5 years of web development, and have, for my first game project, decided to create a simple 2D worms-style game - in the sense that the background doesn't scroll: your character moves.
I have a class for the Player, a class for the Frame, and a Board class which calls paint and contains an action listener.
What I currently have is simply a background with a house:
I don't wish to use a tile system as it'll mean recreating the maps.
You can move the player by using the left, right, up and down arrow.. However this doesn't really work. The background is a simple image, and I want to do collisions with it and similar backgrounds without remaking the maps. I discovered the PixelGrabber functions and made this:
However, if I call this anywhere the game decides to lag and the function seems to loop forever...Code:
public void checkGroundCollision( )
ImageIcon b = new ImageIcon( "D:/PW/Java/background.png" );
background = b.getImage( );
pw = still.getWidth( null ) + this.getX( );
ph = still.getHeight( null ) + this.getY( );
int pixels = new int[ 800 * 600 ];
for ( int i = 0; i < still.getWidth( null ); i++ )
int nextPixel = ( still.getWidth( null ) + this.getX( ) ) - i;
PixelGrabber pg = new PixelGrabber( background, ph, nextPixel, 800, 600, pixels, 0, 800 );
catch ( InterruptedException e )
System.err.println( "Image fetch aborted or error'd!" );
int c = pixels[ pw * 800 + ph ];
int red = ( c & 0x00ff0000 ) >> 16;
int green = ( c & 0x0000ff00 ) >> 8;
int blue = c & 0x000000ff;
//System.out.println( red + " | " + green + " | " + blue );
//System.out.println( pw + " : " + ph );
if ( red == 200 && green == 200 && blue == 200 )
y += 1;
Any ideas as to what I should do, or any other different ways of approaching it?