📄 snake.h
字号:
#include"..\ucos-ii\includes.h" /* uC/OS interface */
#include "..\ucos-ii\add\osaddition.h"
#include <math.h>
//设定左窗口边界
const u8 xmax = 40;
const u8 xmin = 1;
const u8 ymax = 40;
const u8 ymin = 1;
//定义各个区域豆子位置
u8 bean00[3][2] = { {2,11}, {18,13}, {15,20} };
u8 bean01[1][2] = { {10,27} };
u8 bean10[1][2] = { {38,3} };
u8 bean11[1][2] = { {27,38} };
BOOLEAN boolbean00[3] = {TRUE, TRUE, TRUE};
BOOLEAN boolbean01[1] = { TRUE };
BOOLEAN boolbean10[1] = { TRUE };
BOOLEAN boolbean11[1] = { TRUE };
U8 Length;//the length of the snake
U8 HeadPos[2];//the position of the head of the snake
U8 EndPos[2]; //the position of the end of the snake
U8 HeadDirect; //the direction of the headpoint move toward
U8 EndDirect; //the direction of the endpoint move toward
U8 ChangePointPos[10][2]; //the position of the change point
U8 ChangePointDirect[10]; //the direction of the change point
U8 ChangePointCount; //the number of the change point
u8 addcount=0;//after eat bean,the length to be added
//定义界面左边蛇在其中游动的矩形和界面右边的矩形
structRECT snakeRect, rightRect;
structRECT *psnakeRect, *prightRect;
structRECT barRect1, barRect2;
structRECT *pbarRect1, *pbarRect2;
//定义以5个象素为单位的坐标系统中两个栅栏的矩形
structRECT barRect1_5, barRect2_5;
structRECT *pbarRect1_5, *pbarRect2_5;
BOOLEAN gameover,pause,gamepass;
BOOLEAN catch;
BOOLEAN initfinished;
PDC pdc;
///******************任务定义***************///
OS_STK Main_Stack[STACKSIZE*8]={0, }; //Main_Test_Task堆栈
void Main_Task(void *Id); //Main_Test_Task
#define Main_Task_Prio 12
OS_STK Transmit_Task_Stack[STACKSIZE*8]={0, }; //Transmit_Task堆栈
void Transmit_Task(void *Id); //Transmit_Task
#define Transmit_Task_Prio 20
/**************已经定义的OS任务*************
#define SYS_Task_Prio 1
#define Touch_Screen_Task_Prio 9
#define Main_Task_Prio 12
#define Key_Scan_Task_Prio 58
#define Lcd_Fresh_prio 59
#define Led_Flash_Prio 60
#define Transmit_Task_Prio 20
***************************************/////////
///*****************事件定义*****************///
OS_EVENT *Nand_Rw_Sem; //Nand_Flash读写控制权旗语
//and you can use it as folloeing:
// Nand_Rw_Sem=OSSemCreate(1); //创建Nand-Flash读写控制权旗语,初值为1满足互斥条件//
// OSSemPend(Nand_Rw_Sem,0,&err);
// OSSemPost(Nand_Rw_Sem);
OS_EVENT *Uart_Rw_Sem; //Uart读写控制权旗语
//and you can use it as folloeing:
// Uart_Rw_Sem=OSSemCreate(1); //创建Uart读写控制权旗语,初值为1满足互斥条件//
// OSSemPend(Uart_Rw_Sem,0,&err);
// OSSemPost(Uart_Rw_Sem);
//////////////////////////////////////////////////////////
void initOSGUI() //初始化操作系统的图形界面
{
structRECT rect;
initOSMessage();
initOSList();
initOSDC();
initOSCtrl();
initOSFile();
}
/////////////////////////////////////////////////////
// Main function. //
////////////////////////////////////////////////////
int Main(int argc, char **argv)
{
ARMTargetInit(); // do target (uHAL based ARM system) initialisation //
OSInit(); // needed by uC/OS-II //
uHALr_ResetMMU(); //复位MMU
LCD_Init(); //初始化LCD模块
LCD_printf("LCD initialization is OK\n");
LCD_printf("240 x 128 Text Mode\n");
LoadFont();
LoadConfigSys();
// create the tasks in uC/OS and assign increasing //
// priorities to them so that Task3 at the end of //
// the pipeline has the highest priority. //
LCD_printf("Create task on uCOS-II...\n");
OSTaskCreate(Main_Task, (void *)0, (OS_STK *)&Main_Stack[STACKSIZE*8-1], Main_Task_Prio);
OSTaskCreate(Transmit_Task,(void *)0, (OS_STK *)&Transmit_Task_Stack[STACKSIZE-1], Transmit_Task_Prio);
OSAddTask_Init(); //创建博创公司默认的4个任务,触摸屏任务9、键盘扫描任务58、系统任务1、LCD刷新任务59
LCD_printf("Starting uCOS-II...\n");
LCD_printf("Entering graph mode...\n");
LCD_ChangeMode(DspGraMode);
initOSGUI();
InitRtc();
Nand_Rw_Sem=OSSemCreate(1); //创建Nand-Flash读写控制权旗语,初值为1满足互斥条件//
OSStart(); // start the game //
// never reached //
return 0;
}//main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -