I’ve just started to learn Java for mobile devices, and i’ve been playing around with simple MIDP1.0.3 games.
The problem is this, i have one square in the center of the screen, and on the X and Y axis i have targets.
By pressing the up, down, left, right keys a small shot is fired in the corresponding direction.
these shots are colouered pixels of about 2 high by 2 wide.
when they are launched the game draws in their path [a straigth line along the appropriate axis] the game leaves in all the images it draws during it’s movment.
So instead of having a shot fly up the screen, i have a trail leading to the top of the screen.
Deleting the object only removes the dot that remians on the end of the trail, not any of the ones that are before it.
These are the areas of code that i think have the errant instructions in them
[excuse the poor quality of the code, i’m still trying to get my head arouns Java and OO]
In GameScreen.java
[i]
//
private Vector actorList;
private Vector NactorList;
private Vector SactorList;
private Vector EactorList;
private Vector WactorList;
private Vector ShotList;
protected void cycle()
{
if (lastCycleTime > 0)
{
msSinceLastCycle = System.currentTimeMillis() - lastCycleTime;
// cycle all the actors
// North actors
// shot actors
for (int i = 0; i < ShotList.size(); i++)
{
Actor a = (Actor) ShotList.elementAt(i);
Actor N = (Actor) NactorList.elementAt((NactorList.size() - 1));
Actor S = (Actor) SactorList.elementAt((SactorList.size() - 1));
Actor E = (Actor) EactorList.elementAt((EactorList.size() - 1));
Actor W = (Actor) WactorList.elementAt((WactorList.size() - 1));
System.out.println("*********[Cycle]*************");
a.cycle((int)msSinceLastCycle);
System.out.println("*********[End cycle]*********");
// check if any hit the oncomming cubes
if ((N.isCollidingWith(a) && N != a) ||((S.isCollidingWith(a) && S != a))
|| (E.isCollidingWith(a) && E != a) ||(W.isCollidingWith(a) && W != a))
{
// yar! it's a hit
System.out.println("HIT!");
// if so, remove the brick
ShotList.removeElementAt(i);
// remove the shot
}
System.out.println("ShotList.size() " + ShotList.size());
}
}
}
lastCycleTime = System.currentTimeMillis();
}[/i]
In GameScreen.java
[i]
private void renderWorld()
{
// this is called every cycle to paint the world
// first to an offscreen buffer, then to the screen
Graphics osg = offScreenBuffer.getGraphics();
// there is very little to draw to begin with,
// once we render the actors later then we'll be doing much more
// so draw the score line
osg.setColor(0, 0, 0);
osg.fillRect(0, getHeight() - 10, getWidth(), getHeight());
osg.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
osg.setColor(0x00ffffff);
osg.setColor(0x00ffffff);
osg.drawString("CPS: " + cps , 5, getHeight() - 10 + 1,
Graphics.LEFT | Graphics.TOP);
for (int i=0; i < actorList.size(); i++)
{
Actor a = (Actor)actorList.elementAt(i);
a.render(osg);
}
// draw the 'attacking' blocks
for (int i=0; i < NactorList.size(); i++)
{
Actor a = (Actor)NactorList.elementAt(i);
a.render(osg);
}
for (int i=0; i < SactorList.size(); i++)
{
Actor a = (Actor)SactorList.elementAt(i);
a.render(osg);
}
for (int i=0; i < EactorList.size(); i++)
{
Actor a = (Actor)EactorList.elementAt(i);
a.render(osg);
}
for (int i=0; i < WactorList.size(); i++)
{
Actor a = (Actor)WactorList.elementAt(i);
a.render(osg);
}
// render the shots
for (int i=0; i < ShotList.size(); i++)
{
System.out.println("**************[Start Shots!]******************");
Actor a = (Actor)ShotList.elementAt(i);
a.render(osg);
System.out.println("**************[End Shots!]******************");
}
}
[/i]
And finally in ShotActor.java
[i]
public void cycle(long deltaMS)
{
long ticks = (deltaMS + fluff) / 100;
// remember the bit we missed
fluff += (deltaMS - (ticks * 100));
// move based on our speed in pixels per ticks
if (ticks > 0)
{
int move = (int)(10 * ticks);
switch(Direction)
{
case 0:
System.out.println("Moving Down");
setY(move);
break;
case 1:
System.out.println("Moving up");
setY(move);
break;
case 2:
System.out.println("Moving Right");
setX(move);
break;
case 3:
System.out.println("Moving left");
setX(move);
break;
}
}
}
[/i]
thanks in advance for any help i recieve.