大学生
最后登录1970-1-1
在线时间 小时
注册时间2023-7-6
|
本帖最后由 还没吃饭 于 2023-8-25 22:02 编辑
本论坛开源首发:
【野火瑞萨开箱】 https://www.bilibili.com/video/B ... cdfdaee2cf57cf341bc
游戏功能简介:
【[野火]瑞萨RA MCU创意氛围赛+(原创)机械臂游戏创意制作2】https://www.bilibili.com/video/B ... cdfdaee2cf57cf341bc
开始设计游戏开发板。
老虎,杠子,鸡,游戏的机械臂创意版 :扫描按键 玩家输入老虎,杠子,鸡,虫 的4种选项,开发板做出判断并输出到管脚,控制机械臂做出相应的设计动作。
所需硬件:
1,四自由度机械臂一台,用数字舵机驱动。
2,面包板及杜邦线。
3,5V10W开关电源一个。
4, 外接按键2个。
游戏操作流程:
1.打开电源开关,面包板和开发板上电,机械臂会自己动作表示上电正常,已经可以游戏。
2.机械臂动作结束后 可接受按键输入。玩家通过按键输入 自己要选的游戏主角后, AI通过程序也作出相应选择并利用机械臂做出相应动作。
3.机械臂做完动作后,开发板会根据AI的选择和玩家的选择,做出输赢的判断,并利用机械臂做出输、赢或平局的动作。
4.一局结束后 可以再按开发板的复位键 再来一局继续游戏。
玩家和AI平局
AI做出选择
玩家输AI赢
源代码:
- #define KEY_ON 1
- #define KEY_OFF 0
- /* 按键扫描函数(阻塞式)
- * key: KEY1_SW2_PIN 用户按键1(丝印SW2)的引脚
- * KEY2_SW3_PIN 用户按键2(丝印SW3)的引脚
- */
- uint32_t Key_Scan(bsp_io_port_pin_t key)
- {
- bsp_io_level_t state;
- // 读取按键引脚电平
- R_IOPORT_PinRead(&g_ioport_ctrl, key, &state);
- if (BSP_IO_LEVEL_HIGH == state)
- {
- return KEY_OFF; //按键没有被按下
- }
- else
- {
- do //等待按键释放
- {
- R_IOPORT_PinRead(&g_ioport_ctrl, key, &state);
- } while (BSP_IO_LEVEL_LOW == state);
- }
- return KEY_ON; //按键被按下了
- }
- void hal_entry(void)
- {
- /* TODO: add your own code here */
- /* 启明6M5开发板,按键引脚定义 */
- #define KEY1_SW2_PIN BSP_IO_PORT_00_PIN_04
- #define KEY2_SW3_PIN BSP_IO_PORT_00_PIN_05
- #define KEY3_SW2_PIN BSP_IO_PORT_06_PIN_00
- #define KEY4_SW3_PIN BSP_IO_PORT_06_PIN_04
-
-
- int player;
- int computer;
- int result;
- int v;
- R_BSP_PinAccessEnable();
-
-
- //游戏开始
-
-
- for ( v = 80; v > 40 ; v-- )
- {
-
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
- }
- for ( v = 80; v > 40 ; v-- )
- {
-
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
- for ( v = 80; v > 40 ; v-- )
- {
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
-
- for ( v = 80; v > 40 ; v-- )
- {
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
-
-
- /////////////////////////////////////////////////////////////////////
-
- for ( v = 80; v > 40 ; v-- )
- {
-
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
- }
- for ( v = 80; v > 40 ; v-- )
- {
-
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
- for ( v = 80; v > 40 ; v-- )
- {
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
-
- for ( v = 80; v > 40 ; v-- )
- {
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
-
-
-
-
-
-
- // }
-
-
-
- player = 0;
-
- while(player == 0) {
-
- if( Key_Scan(KEY1_SW2_PIN) == KEY_ON ) //扫描按键1
- {
- player = 1;
- }
- if( Key_Scan(KEY2_SW3_PIN) == KEY_ON ) //扫描按键2
- {
- player = 2 ;
- }
- if( Key_Scan(KEY3_SW2_PIN) == KEY_ON ) //扫描按键3
- {
- player = 3;
- }
- if( Key_Scan(KEY4_SW3_PIN) == KEY_ON ) //扫描按键4
- {
- player = 4 ;
- }
- }
-
-
- // 计算机选择
- computer = player;
- // 计算机选择了
- switch (computer) {
- case 1:
- // 老虎
- for ( v = 80; v > 40 ; v-- )
- {
-
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
-
- break;
- case 2:
- //杠子
- for ( v = 80; v > 40 ; v-- )
- {
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
-
-
-
- break;
- case 3:
- //鸡
-
-
- for ( v = 80; v > 40 ; v-- )
- {
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
-
-
-
- break;
- case 4:
- // 虫
- for ( v = 80; v > 40 ; v-- )
- {
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
-
- break;
- }
- // 判断胜负
- if ( (player == computer) || (player == 1 && computer == 4) ||
- (player == 2 && computer == 3) ){
- result = 0; // 平局
- } else if ((player == 1 && computer == 3) ||
- (player == 2 && computer == 1) ||
- (player == 3 && computer == 4) ||
- (player == 4 && computer == 2)) {
- result = 1; // 玩家胜利
- } else {
- result = -1; // 计算机胜利
- }
- // 输出结果
- if (result == 0) {
- // printf("平局!\n");
-
- for ( v = 80; v > 40 ; v-- )
- {
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
-
- } else if (result == 1) {
- // printf("你赢了!\n");
-
-
- R_BSP_PinWrite(BSP_IO_PORT_08_PIN_06 , BSP_IO_LEVEL_HIGH);
- for ( v = 80; v > 40 ; v-- )
- {
-
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
-
- for ( v = 80; v > 40 ; v-- )
- {
-
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
- }
- for ( v = 80; v > 40 ; v-- )
- {
-
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
- }
-
- for ( v = 80; v > 40 ; v-- )
- {
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
- }
- R_BSP_PinWrite( BSP_IO_PORT_08_PIN_06 , BSP_IO_LEVEL_LOW);
-
- } else {
- // printf("你输了!\n");
- R_BSP_PinWrite(BSP_IO_PORT_08_PIN_04 , BSP_IO_LEVEL_HIGH);
-
-
- for ( v = 80; v > 40 ; v-- )
- {
-
-
- R_BSP_PinWrite(BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_HIGH);
- R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_LOW);
- R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
- }
- R_BSP_SoftwareDelay(200, BSP_DELAY_UNITS_MILLISECONDS);
- R_BSP_PinWrite( BSP_IO_PORT_08_PIN_04 , BSP_IO_LEVEL_LOW);
- }
-
- // }
- #if BSP_TZ_SECURE_BUILD
- /* Enter non-secure code */
- R_BSP_NonSecureEnter();
- #endif
- }
复制代码
游戏程序:(游戏构思原创)
AI做出选择 老虎
AI做出选择 老虎
我在其他论坛的网名:还没吃饭,jf_39110170,
试验品视频:
[url=【[野火]瑞萨RA MCU创意氛围赛(原创)】 https://www.bilibili.com/video/B ... cdfdaee2cf57cf341bc][野火]瑞萨RA MCU创意氛围赛(原创)[/url]
【[野火]瑞萨RA MCU创意氛围赛+(原创)机械臂游戏创意制作2】https://www.bilibili.com/video/B ... cdfdaee2cf57cf341bc
谢谢!
|
-
玩家输AI赢
|