Here is the code for the applet, it may give you a better idea of what i'm trying to accomplish
public class Main extends Applet implements Runnable
{
// variables
private Thread th;
private Player player;
private Invader invader;
private int invaderArrayWidth = 10;
private int invaderArrayHeight = 3;
private int invaderArrayXPlacementIncrement = 40;
private int invaderArrayYPlacementIncrement = 40;
private Invader[][] invaderArray = new Invader[invaderArrayWidth][invaderArrayHeight];
private Shot [] shots;
private boolean invadersMovingRight;
private boolean invadersMovingLeft;
private boolean invaderHit;
private final int appletWidth = 500;
private final int appletHeight = 400;
// speed constants
private final int shotSpeed = -10;
private final int playerLeftSpeed = -2;
private final int playerRightSpeed = 2;
// move flags
private boolean playerMoveLeft;
private boolean playerMoveRight;
// double buffering
private Image dbImage;
private Graphics dbg;
public void init()
{
setBackground (Color.black);
player = new Player(150, 280);
int invaderXPos = 10;
int invaderYPos = 5;
invadersMovingRight = true;
//initialize invader array
for (int i = 0; i < invaderArrayWidth; i++)
{
for (int j = 0;j < invaderArrayHeight; j++)
{
invaderArray[j] = new Invader(invaderXPos, invaderYPos, this);
invaderYPos = invaderYPos + invaderArrayYPlacementIncrement;
}
invaderYPos = 5;
invaderXPos = invaderXPos + invaderArrayXPlacementIncrement;
}
invader = new Invader(100, 50, this);
shots = new Shot[1];
}
public Invader getRightMostInvader(Invader[][] array)
{
for (int i = invaderArrayWidth - 1; i >= 0; i--)
{
for (int j = 0; j < invaderArrayHeight - 1;j++)
{
if(array[j] != null)
{
//Invader leftMostInvader = array[j];
//return leftMostInvader;
return array[j];
}
}
}
//System.out.println("Right most invader XPos is " + array[invaderArrayWidth][0]);
return null;
}
public Invader getLeftMostInvader(Invader[][] array)
{
for (int i = 0; i < invaderArrayWidth; i++)
{
for (int j = 0; j < invaderArrayHeight;j++)
{
if(array[j] != null)
{
//Invader leftMostInvader = array[j];
//return leftMostInvader;
return array[j];
}
}
}
return null;
}
public boolean invaderHitRightBorder(Invader invader)
{
if (invader != null)
{
if(invader.getX() + invaderArrayXPlacementIncrement > appletWidth )
{
return true;
}
}
return false;
}
public boolean invaderHitLeftBorder(Invader invader)
{
if (invader != null)
{
if(invader.getX() < 0 )
{
return true;
}
}
return false;
}
private void moveInvadersLeft(Invader[][] array)
{
for (int i = 0; i < invaderArrayWidth; i++)
{
for (int j = 0; j < invaderArrayHeight;j++)
{
if(invaderArray[j] != null)
{
invaderArray[j].moveLeft();
}
}
}
}
private void moveInvadersRight(Invader[][] array)
{
for (int i = 0; i < invaderArrayWidth; i++)
{
for (int j = 0; j < invaderArrayHeight;j++)
{
if(invaderArray[j] != null)
{
invaderArray[j].moveRight();
}
}
}
}
public void start ()
{
th = new Thread(this);
th.start ();
}
public void stop()
{
th.stop();
}
public void destroy()
{
th.stop();
}
public void run ()
{
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
while (true)
{
// do operations on shots in shots array
for(int i=0; i<shots.length; i++)
{
if(shots != null)
{
// move shot
shots.moveShot(shotSpeed);
// test if shot is out
if(shots.getYPos() < 0)
{
// remove shot from array
System.out.println("Shot is applet border\n");
shots = null;
break;
}
Shot currentShot = shots;
invaderHit = hitInvader(currentShot, invaderArray);
if (invaderHit == true)
{
shots = null;
invaderHit = false;
}
If you notice all the methods like invaderHit etc are defined here inside the Main.java class. I want to put these all inside their own class called InvaderMovement and then call them by issuing something like InvaderMovement.invaderHit(...);
Figured an abstract class with static methods would do the trick, but it doesn't look like it.