📄 v100.bak
字号:
void clear_big_point(byte x,byte y){
byte x_t,y_t;
x_t=x*2;
y_t=y*2+17;
clear_point(x_t,y_t);
clear_point(x_t+1,y_t);
clear_point(x_t,y_t+1);
clear_point(x_t+1,y_t+1);
}
//-------------------------write square at the lcd-----------------------------
void write_square(byte x0,byte y0,byte x1,byte y1,byte d){
byte i;
for(i=0;i<(x1-x0);i++){
write_point((x0+i),y0);
write_point((x0+i+1),y1);
}
for(i=0;i<(y1-y0);i++){
write_point(x0,(y0+i+1));
write_point(x1,(y0+i));
}
if(d){
for(i=0;i<(x1-x0);i++){
write_point((x0+i),y0+1);
write_point((x0+i+1),y1-1);
}
for(i=0;i<(y1-y0);i++){
write_point(x0+1,(y0+i+1));
write_point(x1-1,(y0+i));
}
}
}
//--------------------put a char at lcd --------------------------------------
void put_char(byte x,byte y,byte att,byte chara){ //att: 0-> 16x16; 1->8x16; 2->24x24
byte i;
word scope;
switch (att){
case 0:
for(i=0;i<16;i++){
*(xram+(y/8)*128+x+i)=chinese[chara*32+i];
//scope=&(xram+(y/8)*128+x+i);
*(xram+(y/8)*128+x+128+i)=chinese[chara*32+16+i];
//scope=&(xram+(y/8)*128+x+128+i);
}
break;
case 1:
for(i=0;i<16;i++){
*(xram+(y/8)*128+x+i)=chinese[chara*32+i];
//scope=&(xram+(y/8)*128+x+i);
*(xram+(y/8)*128+x+128+i)=chinese[chara*32+16+i];
//scope=&(xram+(y/8)*128+x+128+i);
}
break;
case 2:
for(i=0;i<8;i++){
*(xram+(y/8)*128+x)=chinese[chara*32+i];
*(xram+(y/8)*128+x)=chinese[chara*32+i];
}
break;
default:break;
}
}
void write_body(void){
word i;
byte j,temp,start;
EA=0;
for(i=0;i<spoint;i++){
if(point[sp_start-i].x==point[sp_start-i-1].x){ //write snake bode from snake head
if(point[sp_start-i].y > point[sp_start-i-1].y){ // "|"
start=point[sp_start-i-1].y;
temp=point[sp_start-i].y-point[sp_start-i-1].y;
}
else{
start=point[sp_start-i].y;
temp=point[sp_start-i-1].y-point[sp_start-i].y;
}
for(j=0;j<temp+1;j++){
write_big_point(point[sp_start-i].x,start+j);
}
}
else{
if(point[sp_start-i].x > point[sp_start-i-1].x){
start=point[sp_start-i-1].x;
temp=point[sp_start-i].x-point[sp_start-i-1].x;
}
else{
start=point[sp_start-i].x;
temp=point[sp_start-i-1].x-point[sp_start-i].x;
}
for(j=0;j<temp+1;j++){
write_big_point(start+j,point[sp_start-i].y);
}
}
}
EA=1;
}
//----------check the snake head touch the body and square or not--------------
byte check_point(){
if((point[sp_start].x== 0)||(point[sp_start].x >= 62))
return 0xff;
else{
if((point[sp_start].y==0)||(point[sp_start].y >= 22))
return 0xff;
else
return 0x00; //that's all right
}
}
//------------------------move snake of tail-----------------------------------
void walk_tail(void){ //the snake is walk front and don't creat cells
byte tempx,tempx1,tempy,tempy1;
tempx =point[sp_end].x;
tempx1=point[sp_end+1].x;
tempy =point[sp_end].y;
tempy1=point[sp_end+1].y;
if(tempx==tempx1){
clear_big_point(tempx,point[sp_end].y); // "|"
if(tempy>tempy1){ //move the snake tail
tempy--; // ^
point[sp_end].y=tempy;// |
}
else{
tempy++; // |
point[sp_end].y=tempy;// V
}
}
else{
clear_big_point(tempx,point[sp_end].y); // "--"
if(tempx >tempx1){ // move the snake tail
tempx--; // <----
point[sp_end].x=tempx;
}
else{
tempx++; // ---->
point[sp_end].x=tempx;
}
}
if((point[sp_end].x==point[sp_end+1].x)&&(point[sp_end].y==point[sp_end+1].y)){
sp_end++; //delete a cells lline start move up "1"
if(sp_end>=255)sp_end=0;
spoint--; //line long dec "1"
if(sp_end==sp_start){
sp_end=1;
sp_start=0;
}
}
}
//----------------------walk ago orient---------------------------------------
void walk_old(void){ //the snake is walk front and don't creat cells
byte tempx,tempx1,tempy,tempy1;
byte endx,endx1,endy,endy1;
endx =point[sp_start].x; //move snake head
endx1=point[sp_start-1].x;
endy =point[sp_start].y;
endy1=point[sp_start-1].y;
if(endx==endx1){ // |
if(endy>endy1){ // | endx1
endy++; // V endx
point[sp_start].y=endy;
}
else{ // ^
endy--; // |
point[sp_start].y=endy;
}
}
else{
if(endx>endx1){ //--->
endx++;
point[sp_start].x=endx;
}
else{ //<---
endx--;
point[sp_start].x=endx;
}
}
tempx =point[sp_end].x;
tempx1=point[sp_end+1].x;
tempy =point[sp_end].y;
tempy1=point[sp_end+1].y;
if(tempx==tempx1){
clear_big_point(tempx,point[sp_end].y); // "|"
if(tempy>tempy1){ //move the snake tail
tempy--; // ^
point[sp_end].y=tempy;// |
}
else{
tempy++; // |
point[sp_end].y=tempy;// V
}
}
else{
clear_big_point(tempx,point[sp_end].y); // "--"
if(tempx >tempx1){ // move the snake tail
tempx--; // <----
point[sp_end].x=tempx;
}
else{
tempx++; // ---->
point[sp_end].x=tempx;
}
}
if((point[sp_end].x==point[sp_end+1].x)&&(point[sp_end].y==point[sp_end+1].y)){
sp_end++; //delete a cells lline start move up "1"
if(sp_end>=255)sp_end=0;
spoint--; //line long dec "1"
if(sp_end==sp_start){
sp_end=1;
sp_start=0;
}
}
}
//----------------------the game model-----------------------------------------
void game(){
byte i,key_in;//i is y length;don,t bigger than 15
game_on=1;
orient=0;
write_square(00,17,126,63,0);
for(i=0;i<6;i++)
put_char((16+16*i),0,0,i);
sp_end=sp_start=spoint=0;
point[0].x=1;
point[0].y=1; // snake tail
point[1].x=1;
point[1].y=5;
point[2].x=17;
point[2].y=5;
point[3].x=17;
point[3].y=3;
point[4].x=25;
point[4].y=3;
point[5].x=25;
point[5].y=8;//sp_end is the snake head pointer
last_key=4; //the snake walk to down orient (key record)
sp_start=5;
spoint=5; //initialize snake body
write_body();
display();
while(game_on){
key_in=key();
orient=key_in;
if(move_flag){
move_flag=0;
switch (orient){
case 0:
walk_old();
break;
case 1: //creat a new cell for up at now orient
if((last_key==2)||(last_key==3)){ //input ->1 up ;
point[sp_start+1].x=point[sp_start].x;
point[sp_start+1].y=point[sp_start].y -1;
if(spoint++>=0xff){//last_key must be left(2) or right(3)
spoint=0; //check line
}
sp_start++;
if(sp_start==sp_end){
sp_start=1; //line long and end point add "1"
sp_end=0;
}
last_key=1; //change the last key state
walk_tail();//move snake tail only
}
else
walk_old(); //move snake head and tail
break;
case 2: //creat a new cell for left at now orient
if((last_key==1)||(last_key==4)){ //input ->2 left ;
point[sp_start+1].x=point[sp_start].x -1;
point[sp_start+1].y=point[sp_start].y;
if(spoint++>=0xff){//last_key must be up(1) or down(4)
spoint=0; //check line
}
sp_start++;
if(sp_start==sp_end){
sp_start=1; //line long and end point add "1"
sp_end=0;
}
last_key=2; //change the last key state
walk_tail();
}
else
walk_old();
break;
case 3: //creat a new cell for right at now orient
if((last_key==1)||(last_key==4)){ //input ->3 right ;
point[sp_start+1].x=point[sp_start].x +1;
point[sp_start+1].y=point[sp_start].y;
if(spoint++>=0xff){//last_key must be up(1) or down(4)
spoint=0; //check line
}
sp_start++;
if(sp_start==sp_end){
sp_start=1; //line long and end point add "1"
sp_end=0;
}
last_key=3; //change the last key state
walk_tail();
}
else
walk_old();
break;
case 4: //creat a new cell for down at now orient
if((last_key==2)||(last_key==3)){ //input ->4 down ;
point[sp_start+1].x=point[sp_start].x;
point[sp_start+1].y=point[sp_start].y +1;
if(spoint++>=0xff){//last_key must be left(2) or right(3)
spoint=0; //check line
}
sp_start++;
if(sp_start==sp_end){
sp_start=1; //line long and end point add "1"
sp_end=0;
}
last_key=1; //change the last key state
walk_tail();
}
else
walk_old();
break;
default:
walk_old();
break;
}
write_body();
display();
if(check_point()){
for(i=0;i<4;i++)
put_char((32+16*i),32,0,i+6); //print game over
return;
}
}
}
}
//-----------------------CPU initialization-----------------------------------
void init(void) {
TMOD=0x21 ; // (T1 MODE 2_send_flagME,T0 MODE 1_send_flagME)
TCON=0x51 ; //0101 0000 (TR1=1 , TR0=1
SCON=0x50 ; //0101 0000 (MODE 1 ;RECEIVE ENABLE)
IP=0x10 ; //0001 0000 (S-PORT HIGH interrupt)
IE=0x12 ; //0001 0010 (S_PORT AND TIME0 ENABLE INT)
TL1=TH1=0xfd; //9600bps
PCON=0x00; //SMOD=0
IE = 0x92;
TR1=0;
// RAM=0; //static ram be select
EA=1; // enable all interrupt
}
//-----------------------------------------------------------------------------
main(){
word i;
byte ch;
jk;
jk1;
power=0;
lcd_power=0;
init();
init_lcd();
while(1){
REG573 = CS_256;
C573 = 1;
P2 = CS_256;
C573 = 0;
game();
//------------------------------------------------
display();
while(1){
;// random=rand();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -