久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2180|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

基于Cortex_M3的觸摸屏版吃豆人源碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:197722 發(fā)表于 2018-4-2 19:08 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
基于Cortex_M3的觸摸屏版吃豆人  

mcu源程序如下:
  1. #include "inc/lm3s9b96.h"
  2. #include "inc/hw_types.h"
  3. #include "driverlib/sysctl.h"
  4. #include "driverlib/timer.h"
  5. #include "inc/hw_memmap.h"
  6. #include "inc/hw_ints.h"
  7. #include "driverlib/interrupt.h"
  8. #include "driverlib/sysctl.h"
  9. #include "driverlib/uart.h"
  10. #include "math.h"

  11. #include "inc/hw_types.h"
  12. #include "inc/hw_timer.h"
  13. #include "inc/hw_gpio.h"
  14. #include "inc/hw_sysctl.h"
  15. #include "inc/hw_ints.h"
  16. #include "inc/hw_memmap.h"
  17. #include "inc/hw_nvic.h"

  18. #include "driverlib/interrupt.h"
  19. #include "driverlib/sysctl.h"
  20. #include "driverlib/rom.h"
  21. #include "driverlib/debug.h"
  22. #include "driverlib/gpio.h"
  23. #include "grlib/grlib.h"
  24. #include "grlib/widget.h"
  25. #include "grlib/canvas.h"
  26. #include "grlib/pushbutton.h"
  27. #include "drivers/kitronix320x240x16_ssd2119_8bit.h"
  28. #include "drivers/touch.h"
  29. #include "drivers/set_pinout.h"
  30. #include "driverlib/systick.h"
  31. #include "driverlib/timer.h"
  32. #include "inc/hw_timer.h"

  33. tBoolean g_press1 = false;
  34. tBoolean g_press2 = false;
  35. tBoolean g_press3 = false;
  36. tBoolean g_press4 = false;
  37. char p[9]={"00:00:00"};
  38. // 聲明驅(qū)動庫中定義的tDisplay顯示設(shè)備對象。
  39. extern const tDisplay g_sKitronix320x240x16_SSD2119;
  40. // 提前聲明要使用到的控件。(后文為建立控件樹可能會相互引用)
  41. //extern tCanvasWidget g_sBackground;
  42. //extern tCanvasWidget g_sGame;
  43. extern tPushButtonWidget g_sDown;
  44. extern tPushButtonWidget g_sLeft;
  45. extern tPushButtonWidget g_sUp;
  46. extern tPushButtonWidget g_sRight;
  47. // 提前聲明按鈕按下時的處理凼數(shù)。
  48. void On_downPress(tWidget *pWidget);
  49. void On_leftPress(tWidget *pWidget);
  50. void On_upPress(tWidget *pWidget);
  51. void On_rightPress(tWidget *pWidget);



  52. //作為選擇下的方塊按鈕
  53. RectangularButton(g_sDown,WIDGET_ROOT,&g_sLeft,0,
  54.                                                                         &g_sKitronix320x240x16_SSD2119, 270, 30, 40, 40,
  55.                                                                         (PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
  56.                                                                         PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
  57.                                                                         ClrDarkBlue, ClrRed, ClrWhite, ClrBlue,
  58.                                                                         &g_sFontCmss22b, "R", 0, 0, 0, 0,
  59.                                                                         On_downPress);
  60. //作為選擇左的方塊按鈕                                                                       
  61. RectangularButton(g_sLeft,WIDGET_ROOT,&g_sUp,0,
  62.                                                                         &g_sKitronix320x240x16_SSD2119, 270, 80, 40, 40,
  63.                                                                         (PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
  64.                                                                         PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
  65.                                                                         ClrDarkBlue, ClrRed, ClrWhite, ClrBlue,
  66.                                                                         &g_sFontCmss22b, "D", 0, 0, 0, 0,
  67.                                                                         On_leftPress);
  68. //作為選擇上的方塊按鈕                                                                       
  69. RectangularButton(g_sUp, WIDGET_ROOT,&g_sRight,0,
  70.                                                                         &g_sKitronix320x240x16_SSD2119, 270, 130, 40, 40,
  71.                                                                         (PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
  72.                                                                         PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
  73.                                                                         ClrDarkBlue, ClrRed, ClrWhite, ClrBlue,
  74.                                                                         &g_sFontCmss22b, "L", 0, 0, 0, 0,
  75.                                                                         On_upPress);               
  76. //作為選擇右的方塊按鈕                                                                       
  77. RectangularButton(g_sRight,WIDGET_ROOT,0,0,
  78.                                                                         &g_sKitronix320x240x16_SSD2119, 270, 180, 40, 40,
  79.                                                                         (PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
  80.                                                                         PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
  81.                                                                         ClrDarkBlue, ClrRed, ClrWhite, ClrBlue,
  82.                                                                         &g_sFontCmss22b, "U", 0, 0, 0, 0,
  83.                                                                         On_rightPress);       
  84.                                                                                


  85. #define KEY_PERIPH SYSCTL_PERIPH_GPIOJ
  86. #define KEY_PORT  GPIO_PORTJ_BASE
  87. #define KEY_PIN  GPIO_PIN_7

  88. //吃豆人定義變量
  89. float man_x,man_y;//定義吃豆人的圓心位置
  90. float man_r=9;//定義吃豆人的半徑
  91. float mdu;//定義吃豆人嘴的角度
  92. float mouth_x,mouth_y;//定義吃豆人嘴的邊

  93. float warm_x,warm_y;//定義蟲子位置
  94. float pac_x,pac_y;//定義豆子位置
  95. int flag=-1;
  96. int score;
  97. int i,j;
  98. //聲明繪圖上下文
  99. tContext sContext;
  100. tRectangle pRect;

  101. int move_x,move_y;
  102. //定義方向:1--下;2--左;3--上;4--右

  103. void delayms(int k)
  104. {
  105.         int i,j;
  106.         for(i=k;i>0;i--)
  107.                 for(j=20000;j>0;j--)        ;
  108. }

  109. //定義迷宮形狀
  110. //1--墻 0--有豆子 2--曾有豆子,已被吃掉
  111.         unsigned char maze[16][12]=
  112.                                                          {{1,1,1,1,1,1,1,1,1,1,1,1},
  113.                                                                 {1,0,0,0,0,0,0,0,0,0,0,1},
  114.                                                                 {1,0,1,0,0,0,0,0,0,0,0,1},
  115.                                                                 {1,0,1,0,0,0,0,0,0,0,0,1},
  116.                                                                 {1,0,1,1,1,1,0,1,1,1,0,1},
  117.                                                                 {0,0,1,0,0,0,0,0,1,1,0,0},
  118.                                                                 {1,0,1,0,1,0,0,0,0,0,0,1},
  119.                                                                 {1,0,0,0,1,1,1,0,1,1,0,1},
  120.                                                                 {1,0,0,0,1,1,1,0,1,1,0,1},
  121.                                                                 {1,0,0,0,1,0,1,0,0,1,1,1},
  122.                                                           {1,0,0,0,0,0,0,1,0,0,0,1},
  123.                                                                 {1,0,0,0,0,0,0,1,0,1,1,1},
  124.                                                                 {1,1,1,1,1,1,1,1,1,1,1,1},
  125.                                                                 {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
  126.                                                                 {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
  127.                                                                 {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
  128.                                                         };



  129.                                                        
  130. //迷宮初始化
  131. void maze_init(void)
  132. {
  133.         //int x1,y1;
  134.                 GrContextForegroundSet(&sContext, ClrBlue);                                       
  135.                 for(i=0;i<13;i++)
  136.                         for(j=0;j<12;j++)
  137.                 {
  138.                         if(maze[i][j]==1)
  139.                         {
  140.                                 pRect.sXMin = i*20;
  141.                                 pRect.sYMin = j*20;
  142.                                 pRect.sXMax = i*20+20;
  143.                                 pRect.sYMax = j*20+20;
  144.                                
  145.                                 GrRectFill(&sContext, &pRect);
  146.                                         // 確保圖形被繪制在屏幕上
  147.                                 GrFlush(&sContext);
  148.                         }
  149.                 }
  150.                
  151. }


  152. //豆子初始化
  153. void pac_init(void)
  154. {
  155.                 // 設(shè)置畫筆為黃色
  156.                 GrContextForegroundSet(&sContext, ClrYellow);                                       
  157.                 for(i=0;i<13;i++)
  158.                         for(j=0;j<12;j++)
  159.                 {
  160.                         if(maze[i][j]==0)
  161.                         {
  162.                                 pac_x=i*20+10;
  163.                                 pac_y=j*20+10;
  164.                                 GrCircleFill(&sContext, pac_x, pac_y,3);
  165.                                         // 確保圖形被繪制在屏幕上
  166.                                 GrFlush(&sContext);
  167.                         }
  168.                 }
  169.                
  170. }


  171. //蟲子初始化
  172. void warm(float warm_x,float warm_y)
  173. {
  174.                 GrContextForegroundSet(&sContext, ClrPink);
  175.                 GrCircleFill(&sContext, warm_x, warm_y,6);
  176.        
  177.                 pRect.sXMin = warm_x;
  178.                 pRect.sYMin = warm_y-3;
  179.                 pRect.sXMax = warm_x+4;
  180.                 pRect.sYMax = warm_y+3;       
  181.                 GrContextForegroundSet(&sContext, ClrPink);
  182.                 GrRectFill(&sContext, &pRect);
  183.         // 確保圖形被繪制在屏幕上
  184.                 GrFlush(&sContext);

  185. }

  186. //蟲子運(yùn)動
  187. void warm_move(void)
  188. {
  189.         move_x=(warm_x-10)/20;
  190.         move_y=(warm_y-10)/20;
  191.        
  192.         while(maze[move_x][move_y]!=1)
  193.         {
  194.                 GrContextForegroundSet(&sContext, ClrRed);
  195.                         GrCircleFill(&sContext,50, 50,9);
  196.                         GrContextForegroundSet(&sContext, ClrBlack);
  197.                         GrCircleFill(&sContext,warm_x, warm_y,9);
  198.                         GrContextForegroundSet(&sContext, ClrYellow);
  199.                         GrCircleFill(&sContext,warm_x, warm_y,3);
  200.                         warm_x=warm_x+20;
  201.                         warm_y=warm_y;
  202.                         warm(warm_x,warm_y);
  203.                         move_x=(warm_x-10)/20;
  204.                         move_y=(warm_y-10)/20;
  205.                         delayms(200);
  206.         }

  207. }

  208. void pac_man_down1(float man_x,float man_y)
  209. {
  210.                 // 畫一個實(shí)心圓
  211.                         GrContextForegroundSet(&sContext, ClrYellow);
  212.                         GrCircleFill(&sContext, man_x, man_y,9);
  213.                 //畫吃豆人的嘴
  214.                        
  215.                         for(mdu=-45;mdu<45;mdu++)
  216.                         {
  217.                                 //GrLineDraw(&sContext,man_x,man_y,man_x+man_r,80+10*sin(mdu*3.1415/180));       
  218.                                 mouth_x=man_x+9;
  219.                                 mouth_y=man_y+9*sin(mdu*3.1415/180);
  220.                                 GrContextForegroundSet(&sContext,ClrBlack);
  221.                                 GrLineDraw(&sContext,man_x,man_y,mouth_x,mouth_y);
  222.                         }
  223.                         //GrLineDraw(&sContext,80,80,90,70);       
  224.                         // 確保圖形被繪制在屏幕上
  225.                         GrFlush(&sContext);

  226. }
  227. void pac_man_left2(float man_x,float man_y)
  228. {
  229.                 // 畫一個實(shí)心圓
  230.                         GrContextForegroundSet(&sContext, ClrYellow);
  231.                         GrCircleFill(&sContext, man_x, man_y,9);
  232.                 //畫吃豆人的嘴
  233.                        
  234.                         for(mdu=-45;mdu<45;mdu++)
  235.                         {
  236.                                 //GrLineDraw(&sContext,man_x,man_y,man_x+man_r,80+10*sin(mdu*3.1415/180));       
  237.                                 mouth_x=man_x+9*sin(mdu*3.1415/180);
  238.                         mouth_y=man_y+9;
  239.                                 GrContextForegroundSet(&sContext,ClrBlack);
  240.                                 GrLineDraw(&sContext,man_x,man_y,mouth_x,mouth_y);
  241.                         }
  242.                         //GrLineDraw(&sContext,80,80,90,70);       
  243.                         // 確保圖形被繪制在屏幕上
  244.                         GrFlush(&sContext);

  245. }
  246. void pac_man_up3(float man_x,float man_y)
  247. {
  248.                 // 畫一個實(shí)心圓
  249.                         GrContextForegroundSet(&sContext, ClrYellow);
  250.                         GrCircleFill(&sContext, man_x, man_y,9);
  251.                 //畫吃豆人的嘴
  252.                        
  253.                         for(mdu=-45;mdu<45;mdu++)
  254.                         {
  255.                                 //GrLineDraw(&sContext,man_x,man_y,man_x+man_r,80+10*sin(mdu*3.1415/180));       
  256.                                 mouth_x=man_x-9;
  257.                         mouth_y=man_y+9*sin(mdu*3.1415/180);
  258.                                 GrContextForegroundSet(&sContext,ClrBlack);
  259.                                 GrLineDraw(&sContext,man_x,man_y,mouth_x,mouth_y);
  260.                         }
  261.                         //GrLineDraw(&sContext,80,80,90,70);       
  262.                         // 確保圖形被繪制在屏幕上
  263.                         GrFlush(&sContext);

  264. }
  265. void pac_man_right4(float man_x,float man_y)
  266. {
  267.                 // 畫一個實(shí)心圓
  268.                         GrContextForegroundSet(&sContext, ClrYellow);
  269.                         GrCircleFill(&sContext, man_x, man_y,9);
  270.                 //畫吃豆人的嘴
  271.                        
  272.                         for(mdu=-45;mdu<45;mdu++)
  273.                         {
  274.                                 //GrLineDraw(&sContext,man_x,man_y,man_x+man_r,80+10*sin(mdu*3.1415/180));       
  275.                                 mouth_x=man_x+9*sin(mdu*3.1415/180);
  276.                         mouth_y=man_y-9;
  277.                                 GrContextForegroundSet(&sContext,ClrBlack);
  278.                                 GrLineDraw(&sContext,man_x,man_y,mouth_x,mouth_y);
  279.                         }
  280.                         //GrLineDraw(&sContext,80,80,90,70);       
  281.                         // 確保圖形被繪制在屏幕上
  282.                         GrFlush(&sContext);

  283. }



  284. //改方向為下
  285. void On_downPress(tWidget *pWidget)
  286. {

  287.         g_press1=true;
  288.         move_x=(man_x+10)/20;
  289.         move_y=(man_y-10)/20;
  290.         while(maze[move_x][move_y]!=1)
  291.         {
  292.                         if(maze[move_x][move_y]==0)
  293.                         {
  294.                                         maze[move_x][move_y]=2;
  295.                                         score++;
  296.                                        
  297.                         }
  298.                         GrContextForegroundSet(&sContext, ClrBlack);
  299.                         GrCircleFill(&sContext, man_x, man_y,9);
  300.                         man_x=man_x+20;
  301.                         man_y=man_y;
  302.                         pac_man_down1(man_x,man_y);
  303.                         move_x=(man_x+10)/20;
  304.                         move_y=(man_y-10)/20;
  305.                         delayms(200);       
  306.         }
  307. }

  308. //改方向為下
  309. void On_leftPress(tWidget *pWidget)
  310. {
  311.         g_press2=true;
  312.         move_x=(man_x-10)/20;
  313.         move_y=(man_y+10)/20;
  314.         while(maze[move_x][move_y]!=1)
  315.         {
  316.                 if(maze[move_x][move_y]==0)
  317.                         {
  318.                                         maze[move_x][move_y]=2;
  319.                                         score++;
  320.                                        
  321.                         }
  322.                         GrContextForegroundSet(&sContext, ClrBlack);
  323.                         GrCircleFill(&sContext, man_x, man_y,9);
  324.                         man_x=man_x;
  325.                         man_y=man_y+20;
  326.                         pac_man_left2(man_x,man_y);
  327.                         move_x=(man_x-10)/20;
  328.                         move_y=(man_y+10)/20;
  329.                         delayms(200);
  330.         }

  331. }
  332. //改方向為下
  333. void On_upPress(tWidget *pWidget)
  334. {
  335.         g_press3=true;
  336.         move_x=(man_x-30)/20;
  337.         move_y=(man_y-10)/20;
  338.         while(maze[move_x][move_y]!=1)
  339.         {
  340.                 if(maze[move_x][move_y]==0)
  341.                         {
  342.                                         maze[move_x][move_y]=2;
  343.                                         score++;
  344.                                        
  345.                         }
  346.                         GrContextForegroundSet(&sContext, ClrBlack);
  347.                         GrCircleFill(&sContext, man_x, man_y,9);
  348.                         man_x=man_x-20;
  349.                         man_y=man_y;
  350.                
  351.                         pac_man_up3(man_x,man_y);
  352.                         move_x=(man_x-30)/20;
  353.                         move_y=(man_y-10)/20;
  354.                
  355.                         delayms(200);
  356.                
  357.         }       
  358. }
  359. //改方向為下
  360. void On_rightPress(tWidget *pWidget)
  361. {
  362.         g_press4=true;
  363.         move_x=(man_x-10)/20;
  364.         move_y=(man_y-30)/20;
  365.         while(maze[move_x][move_y]!=1)
  366.         {
  367.                 if(maze[move_x][move_y]==0)
  368.                         {
  369.                                         maze[move_x][move_y]=2;
  370.                                         score++;
  371.                                        
  372.                         }
  373.                 GrContextForegroundSet(&sContext, ClrBlack);
  374.                 GrCircleFill(&sContext, man_x, man_y,9);
  375.                 man_x=man_x;
  376.                 man_y=man_y-20;
  377.                 pac_man_right4(man_x,man_y);
  378.                 move_x=(man_x-10)/20;
  379.                 move_y=(man_y-30)/20;
  380.                 delayms(200);
  381.         }
  382.                
  383. }

  384. int main(void)
  385. {
  386.    //設(shè)置時鐘
  387.     SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
  388.                        SYSCTL_XTAL_16MHZ);
  389.    
  390.                 //初始化顯示驅(qū)動
  391.     PinoutSet();
  392.     Kitronix320x240x16_SSD2119Init();
  393.         //初始化StellarisWare圖形庫上下文
  394.     GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119);
  395.         TouchScreenInit(); // 初始化觸摸驅(qū)動程序。
  396.   TouchScreenCallbackSet(WidgetPointerMessage);// 設(shè)置觸摸驅(qū)動凼數(shù)的回調(diào)凼數(shù)為圖形庫的處理凼數(shù)。
  397.        
  398.                   
  399.                 IntMasterEnable( );
  400.          // 將g_sBackground以下的控件加入控件樹。
  401.   WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sDown);
  402.   // 繪制控件樹中的所有控件。
  403.   WidgetPaint(WIDGET_ROOT);       
  404.                 //界面初始化
  405.                 maze_init();
  406.                 pac_init();
  407.         //吃豆人初始化
  408.                 score=0;
  409.                 man_x=30;
  410.                 man_y=130;
  411.                 pac_man_down1(30,130);
  412.                 warm(30,30);
  413.                 warm_move();
  414.                
  415.         while(1)
  416.         {
  417.                
  418.           // 處理所有控件事件。
  419.     WidgetMessageQueueProcess();
  420.         }

  421.        

  422. }

復(fù)制代碼

所有資料51hei提供下載:
觸摸屏版豆人.rar (3.24 MB, 下載次數(shù): 9)



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 中文字幕在线免费视频 | 国产男人的天堂 | 欧美日韩精品一区二区 | 国产精品久久国产精品99 gif | 日韩在线电影 | 天天射影院 | 一区二区视频在线 | 97av视频在线观看 | 亚洲精品一区二区二区 | 蜜桃官网 | 在线成人 | 国产精品久久久久免费 | 在线亚洲一区二区 | 欧产日产国产精品v | 日韩欧美三区 | 欧美精品一区二区三区四区五区 | 久久99精品久久久久久国产越南 | 久久久久国产一区二区三区 | 日韩精品免费看 | 日韩欧美操 | 国产99精品| 18gay男同69亚洲网站 | 91成人午夜性a一级毛片 | 国产精品成人一区 | 日本三级视频 | 久久亚洲国产精品日日av夜夜 | 精品一区二区三区视频在线观看 | 欧美日韩精品在线一区 | 国产黄色免费网站 | 天天看天天摸天天操 | 亚洲精品在线看 | 在线观看国产 | 91av在线电影 | 91资源在线| 成人在线网址 | 九九色综合 | 成人国产精品色哟哟 | 91精品国产日韩91久久久久久 | 亚洲国产精品日韩av不卡在线 | 久久99精品久久久97夜夜嗨 | 午夜丰满寂寞少妇精品 |