著名的PONG游戏仿真

近来闲的没事(大4拉),仿真拉一个小游戏(KEIL + PROTEUS ),有点意思啊 这是源代码 很简单我就不说拉

 

#include"STDLIB.H"  
#include"dd.h"   
void main(void)


{ uchar i,ball_x=9,ball_y=0,ball_dx=4,ball_dy=1,k,kk,ii=10,iii,w,ww=10,www,r,rr;
lcd_init();     
delay(1000);
lw(8,i,0xff);
lw(120,i,0xff);
lw(120,i,0xff);
for(rr=0;rr<=7;rr++)
{lw(64,rr,0xff);}
while(1)      //无限循环
{   
     lw(ball_x,ball_y,0x03);
  k=ball_x;
  kk=ball_y;

  ball_x+=ball_dx;
  delay(800);
  ball_y+=ball_dy;
  delay(800);
  lw(k,kk,0x0);
 
     if((0==P2_7)&&(i<7))   //1下
     {  i=i+1;
     delay(1200);
    lw(8,i,0xff);
    lw(8,i-1,0x0);
      


    }
   
   if((0==P2_5)&&(w<7))   //2下
     {  w=w+1;
     delay(1200);
    lw(120,w,0xff);
    lw(120,w-1,0x0);
      


    }
   
  
   if((0==P2_6)&&(i>0))   //1上
     {  i=i-1;
     delay(1200);
    lw(8,i,0xff);
    lw(8,i+1,0x0);

      
    }

  if((0==P2_4)&&(w>0))   //2上
     {  w=w-1;
     delay(1200);
    lw(120,w,0xff);
    lw(120,w+1,0x0);

      
    }


  
 if(((ball_x<=9&&ball_x>=5)&&(ball_y==i))||((ball_x<=122&&ball_x>=117)&&(ball_y==w)))
 
 {
    ball_dx=-ball_dx;
    ball_x+=ball_dx;
    delay(1200);
      
 }
 if(ball_y>7||ball_y<0)
 {
   ball_dy=-ball_dy;
   ball_y+=ball_dy;
   delay(1200);
 }
 if(ball_x>127)
 {
    ball_dx=-ball_dx;
    ball_x+=ball_dx;
    delay(1200);
 }
 
 //失误情况
 if(ball_x==121||ball_x==1){
 if(ball_x==121){ww--;www=1;iii=0;r=0;}
 if(ball_x==1){ii--;www=0;iii=1;r=120;}
 if((www&&ww==9)||(iii&&ii==9))
 {lw(122-r,7,0x0e);
     lw(123-r,7,0x0a);
     lw(124-r,7,0x0a);
     lw(125-r,7,0x7e);}
 }
 if((www&&ww==7)||(iii&&ii==7))
 {lw(122-r,7,0);
     lw(123-r,7,0);
     lw(124-r,7,0);
     lw(125-r,7,0);
  lw(122-r,7,0x7e);
     lw(123-r,7,0x4a);
     lw(124-r,7,0x4a);
     lw(125-r,7,0x7e);}

  if((www&&ww==5)||(iii&&ii==5))
 {lw(122-r,7,0);
     lw(123-r,7,0);
     lw(124-r,7,0);
     lw(125-r,7,0);
  lw(122-r,7,0x02);
     lw(123-r,7,0x02);
     lw(124-r,7,0x02);
     lw(125-r,7,0x7e);}

  if((www&&ww==3)||(iii&&ii==3))
 {lw(122-r,7,0);
     lw(123-r,7,0);
     lw(124-r,7,0);
     lw(125-r,7,0);
  lw(122-r,7,0x7e);
     lw(123-r,7,0x4a);
     lw(124-r,7,0x4a);
     lw(125-r,7,0x7a);}

  if((www&&ww==1)||(iii&&ii==1))
 {lw(122-r,7,0);
     lw(123-r,7,0);
     lw(124-r,7,0);
     lw(125-r,7,0);
  lw(122-r,7,0x4e);
     lw(123-r,7,0x4a);
     lw(124-r,7,0x4a);
     lw(125-r,7,0x7a);}

  if((www&&ww==-1)||(iii&&ii==-1))
 {lw(122-r,7,0);
     lw(123-r,7,0);
     lw(124-r,7,0);
     lw(125-r,7,0);
  lw(122-r,7,0x0e);
     lw(123-r,7,0x08);
     lw(124-r,7,0x08);
     lw(125-r,7,0x7e);}

  if((www&&ww==-3)||(iii&&ii==-3))
 {lw(122-r,7,0);
     lw(123-r,7,0);
     lw(124-r,7,0);
     lw(125-r,7,0);
  lw(122-r,7,0x42);
     lw(123-r,7,0x4a);
     lw(124-r,7,0x4a);
     lw(125-r,7,0x7e);}

  if((www&&ww==-5)||(iii&&ii==-5))
 {lw(122-r,7,0);
     lw(123-r,7,0);
     lw(124-r,7,0);
     lw(125-r,7,0);
  lw(122-r,7,0x46);
     lw(123-r,7,0x62);
     lw(124-r,7,0x52);
     lw(125-r,7,0x4e);}
 
  if((www&&ww==-7)||(iii&&ii==-7))
 {lw(122-r,7,0);
     lw(123-r,7,0);
     lw(124-r,7,0);
     lw(125-r,7,0);
  
     lw(123-r,7,0x7e);
     }
 

 

 
  //结束游戏
  if(ii==-7||ww==-7) {
  //2
  if(ii==-7)
  {lw(36,4,0x46);
     lw(37,4,0x62);
     lw(38,4,0x52);
     lw(39,4,0x4e);}
  //1
  if(ww==-7)
  { lw(38,4,0x7e);}
  //w
  lw(43,4,0xff);
     lw(44,4,0x40);
  lw(45,4,0x20);
     lw(46,4,0x1f);
     lw(47,4,0x1f);
  lw(48,4,0x20);
     lw(49,4,0x40);
     lw(50,4,0xff);
 //I
  lw(52,4,0xff);
     lw(53,4,0xff);
  //N
  lw(55,4,0xff);
     lw(56,4,0x02);
  lw(57,4,0x04);
     lw(58,4,0x08);
  lw(59,4,0x10);
     lw(60,4,0x20);
  lw(61,4,0x40);
     lw(62,4,0xff);
     lw(122,7,0);
     lw(123,7,0);
     lw(124,7,0);
     lw(125,7,0);
  lw(2,7,0);
     lw(3,7,0);
     lw(4,7,0);
     lw(5,7,0);
  delay(5000);
  break;}
}

delay(10000);     
}

DD.H

#include <AT89X51.H>
#define uchar unsigned char   //变量类型标识的宏定义
#define uint unsigned int
sbit p_csl=P3^4;     //引脚定义
sbit p_csr=P3^3;     //引脚定义
sbit p_di=P3^7;     //引脚定义
sbit p_rw=P3^6;     //引脚定义
sbit p_e=P3^5;     //引脚定义
sbit p_rst=P3^2;     //引脚定义
#define lcm P1
void delay(unsigned long v);
void wcode(uchar c,uchar csl,uchar csr);
void wdata(uchar c,uchar csl,uchar csr);
void set_startline(uchar i);
void set_xy(uchar x,uchar y);
void reset();
void lcd_init(void);
void lw(uchar x, uchar y, uchar dd);

图片见 像册

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值