Moving multiple cars in a row for Android
I am developing a game in which i have to move multiple cars in a row. I have run successfully single car but a little bit confused for multiple.. i don't want to move whole tiles in a row. i just want to move my object. how do i do this.My code for a single car movement is.
static char [][] TilesData = {{ 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'},
{ 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c'},
{ 'l', 'a', 'h', 'a', 'f', 'a', 'h', 'a', 'j', 'a'},
{ 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c'},
{ 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c'},
{ 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',开发者_如何学运维 'c', 'c'},
{ 'e', 'a', 'k', 'a', 'l', 'a', 'f', 'a', 'g', 'a'},
{ 'a', 'h', 'a', 'a', 'i', 'a', 'a', 'j', 'a', 'a'},
{ 'e', 'a', 'a', 'f', 'a', 'a', 'g', 'a', 'a', 'a'},
{ 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c'},
{ 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c'},
{ 'i', 'a', 'h', 'a', 'g', 'a', 'f', 'a', 'e', 'a'},
{ 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c'},
{ 'e', 'a', 'a', 'f', 'a', 'a', 'g', 'a', 'a', 'a'},
{ 'a', 'a', 'a', 'c', 'd', 'c', 'c', 'a', 'a', 'a'}};
public void carDraw(int j){
char temp = 'a';
if(j==0){
TilesData2[6][j]='e';
TilesData2[6][9]='a';}
else{if(j<=14){
if(TilesData2[6][j]!='d'){
TilesData2[6][j]='e';}
else{
TilesData2[6][j]='c';
mThread.setFlag(false);
}
System.out.println("check2");
}
if(j>0){
TilesData2[6][j-1]=temp;}
}
if(j==14){
TilesData2[6][j-1]=temp;
}
}
this is a loop that i created to move a single car and thread class m calling this
while (mRun) {
Canvas canvas = null;
startTime=System.currentTimeMillis();
try{
canvas=mPanel.getHolder().lockCanvas();
synchronized(mPanel.getHolder()){
mPanel.onDraw(canvas);
if(j<10&& flag==true){
mPanel.carDraw(j++);
}
else
j=0;
}
} finally
{
if(canvas!=null){
mPanel.getHolder().unlockCanvasAndPost(canvas);
}
}
Please suggest what to do for multiple car movements.
精彩评论