这是我写的液晶触摸控制贪食蛇上的程序
看能不能帮助你:
//加尾巴
if((Move_X==Food_X)&&(Move_Y==Food_Y))
{
for(i=0;i<=Track.MaxTrack;i++)
{
pTrackPoint[i+1][0]=TrackPoint[Track.TrackLoad][0];//将蛇身放入缓存
pTrackPoint[i+1][1]=TrackPoint[Track.TrackLoad][1];
Track.TrackLoad=(Track.TrackLoad==0)?(Track.MaxTrack):(Track.TrackLoad-1);
}
Track.MaxTrack++;
Track.TrackLoad=Track.MaxTrack;
for(i=0;i<=Track.MaxTrack;i++)
{
TrackPoint[Track.MaxTrack-i][0]=pTrackPoint[i][0];//增加蛇身后将缓存值放入显示
TrackPoint[Track.MaxTrack-i][1]=pTrackPoint[i][1];
}
while(ProduceFood());//生成小球(食物)
Track.TrackFood++;
Track.TrackSpeed=(Track.TrackSpeed<50)?50:(Track.TrackSpeed-25);//加速
}
else//清尾巴
{
if(Track.TrackLoad>=Track.MaxTrack)Track.TrackLoad=0;
else Track.TrackLoad++;
LCD_DispBox(TrackPoint[Track.TrackLoad][0],TrackPoint[Track.TrackLoad][1],WHITE);
}
//检查是是否自咬
for(i=0;(i<=Track.MaxTrack)&&(Game==GameRun);i++)
{
if((TrackPoint[i][0]==Move_X)&&(TrackPoint[i][1]==Move_Y))
{
Game=GameOver;
LCD_DispStr(84,192,"Game Over",BLACK);
sprintf((char*)ptr,"%d Level",Track.TrackFood);
LCD_DispStr(84,170,ptr,BLACK);
LCD_DispStr(180,52,"Save",BLACK);
}
}
//正常后在伸头
TrackPoint[Track.TrackLoad][0]=Move_X;
TrackPoint[Track.TrackLoad][1]=Move_Y;
LCD_DispBox(Move_X,Move_Y,BLACK);
MoveTime=0;
}