【平头哥RVB2601创意应用开发】掌上游戏机
本帖最后由 nemon 于 2022-6-7 17:25 编辑<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span class="15" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">作品名称</font></span></span></b><b><span class="15" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">:</font></span></span></b><span class="15" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">掌上游戏机</font></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">作者:</font></span></span></b><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">nemon</font></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><a href="https://bbs.eeworld.com.cn/home.php?mod=space&uid=424743"><u><span class="16" style="font-size:12.0000pt"><span style="font-family:微软雅黑"><span style="color:#0000ff"><span style="text-decoration:underline"><span style="text-underline:single">https://bbs.eeworld.com.cn/home.php?mod=space&uid=424743</span></span></span></span></span></u></a></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><a href="https://occ.t-head.cn/people/user/4020178002997612544"><u><span class="16" style="font-size:12.0000pt"><span style="font-family:微软雅黑"><span style="color:#0000ff"><span style="text-decoration:underline"><span style="text-underline:single">https://occ.t-head.cn/people/user/4020178002997612544</span></span></span></span></span></u></a></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span style="font-size:16.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><font face="微软雅黑">一、项目背景</font></span></span></span></b></span></span></p>
<ul>
<li><font face="微软雅黑" style="font-family: 微软雅黑; font-size: 11pt; text-align: justify;">以前有人统计说大众最热衷</font><span style="font-family: 微软雅黑; font-size: 11pt; text-align: justify;">3个G,其中为首的就是GAME。看到核心为平头哥CH2601芯片的RVB2601开发板的片上资源、板载资源都很丰富。于是基于这个平台,制作了掌上游戏机的原型。</span></li>
<br />
<li> </li>
</ul>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span class="17" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">二、作品简介</font></span></span></b></span></span></p>
<ul>
<li><font face="微软雅黑" style="font-family: 微软雅黑; font-size: 11pt; text-align: justify;">本项目完全基于</font><span style="font-family: 微软雅黑; font-size: 11pt; text-align: justify;">RVB2601开发板本身资源,以用户按键K1、K2作为输入,OLED作为输出,自造了位图、字体、抽象屏幕、游戏应用框架4个车轮,优化了oled的刷新算法,手工绘制了全部所需位图,编制出主菜单和flappy bird共2个应用。</span></li>
<br />
<li> </li>
</ul>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">操作过程:开机后显示菜单。</font></span></span></span></span></p>
<p> <span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">根据屏幕提示,按右键(</font>B)可以更换选项,按左键(A)运行游戏。</span></span></span></span> <span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">根据屏幕提示,按右键(</font>B)退出,按左键(A)开始游戏。</span></span></span></span></p>
<p style="text-align:justify"> <span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">在游戏中,按左键(</font>A)提升小鸟,钻过缺口得一分,撞倒水管游戏结束。</span></span></span></span></p>
<p style="text-align:justify"> <span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span class="17" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">三、系统框图</font></span></span></b></span></span></p>
<p><span style="background:#ffffff"><span style="vertical-align:baseline"><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">1、系统硬件组成</font></span></span></span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">通过</font>GPIO得到按键操作,经mpu处理,通过SPI接口,更新oled屏</span></span></span></span></p>
<p> 2、<span style="background:#ffffff"><span style="vertical-align:baseline"><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">组件关系图</font></span></span></span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">main函数调用csi_gpio_pin进行初始化等。Menu和FlappyBird实现Game结构体,main函数调用Menu并传递事件给它;menu调用FlappyBird并传递事件给它。各种Game都使用Screen更新oled。Font使用Image存储点阵,Screen及各种Game都依赖Image、Font。</font></span></span></span></span></p>
<p>3、<span style="background:#ffffff"><span style="vertical-align:baseline"><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">GAME的状态转移</font></span></span></span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">父过程调用</font>game的init来获取单例并初始化,game自己控制状态,在收到父过程通过event_handle传过来事件后,决定如何处理,并返回状态。当game将自己状态置为退出后,父进程接管控制流。</span></span></span></span><br />
<span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span class="17" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">四、各部分功能说明</font></span></span></b><b><span class="17" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">和解析</font></span></span></b></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span class="17" style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">1、源码文件清单</font></span></span></span></span></p>
<p> <span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">以上文件,以文件名对应第二部分</font>“组件关系图”中的各组件。</span></span></span></span></span></span></span></p>
<p> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">2、位图</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">(</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">Image.h</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">、</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">Image.</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">c</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">):</font></span></span></span></span></span></span></span></p>
<p class="p" style="margin-bottom:16px; text-indent:0.0000pt; text-align:left"><span style="font-size:12pt"><span style="background:#ffffff"><span style="12.6500pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">结构体</font>IMAGE包含3个子元素:位图宽,位图高,数据数组。此处为了简化多维数组处理,数据用了一维数组,于是就定义了一个宏 IMAGE_POT,用于将二维的表示法转为一维的定义。image_create_function 用数据创建位图,如果只提供了大小,可以创建空白图片。 image_destory_function 销毁位图,主要作用是释放位图占用的内存。</span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">另有</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">5个</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">工具函数,</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">作用分别是:水平翻转、垂直翻转、旋转</font>180度、右转90度、左转90度。</span></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">3、</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">字体</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">(</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">Font.h</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">、</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">Font.</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">c</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">):</font></span></span></span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">存储每个字符的位图,用函数</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#f7fafa"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">font_get_char_function</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">从</font>“字库”里检索</span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">。</font></span></span></span></span></span></span></span></p>
<p> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">4、flappy bird游戏(</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">game_FlappyBird.</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">h、</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">game_FlappyBird.c</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">):</font></span></span></span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">实现动画</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">和游戏逻辑,包括按键处理、评分、各阶段屏幕绘制。</font></span></span></span></span></span></span></span></span></p>
<p> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">5、屏幕抽象层(</font>Screen.h、Screen.c):</span></span></span></span></span></span></span></span></p>
<p><span style="font-size:12pt"><span style="background:#ffffff"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">screen_init_function(int b_flag_inversen);用于初始化屏幕,并设置屏幕是否为反色输出。就是这个反色输出功能,使我能用习惯的黑白来画图。如果需要,也可以在OLEd和LCD间方便地切换。</font></span></span></span></span></span></span></span></span></p>
<p class="p" style="margin-bottom:16px; text-indent:0.0000pt; text-align:left"><span style="font-size:12pt"><span style="background:#ffffff"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">screen_set_dirty_flag_function(int b_flag) 和 screen_set_auto_refresh_flag_function(int b_flag) 用于设置是否发生更改和是否自动向设备层刷新。这两个函数是联合使用,我一般先关掉自动刷新,然后绘图的时候,绘图函数自动根据颜色来设置是否有更改。所有的画图都完成后,再打开自动刷新,这时就会根据之前的更改标记来决定是否调用OLED驱动函数进行刷新。</font></span></span></span></span></span></span></span></span></p>
<p class="p" style="margin-bottom:16px; text-indent:0.0000pt; text-align:left"><span style="font-size:12pt"><span style="background:#ffffff"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">void screen_refresh_function();如名字所示,执行它会进行一次强制刷新。</font></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:12pt"><span style="background:#ffffff"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">void screen_clean_function();如名字所示,执行它会清理缓存。</font></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:12pt"><span style="background:#ffffff"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">另外的几个功能函数,分别是</font>screen_draw_bitmap_function(画位图)、screen_draw_string_function(调用字库画字符串)、screen_draw_Int32_function(数字转字符串画出)、screen_draw_horizontal_line_function(画水平线)、screen_draw_vertical_line_function(画垂直线)、screen_draw_rectangular_function(用边框色和填充色画矩形)、screen_draw_dot_function(画一个点)。</span></span></span></span></span></span></span></span></p>
<p> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">6、oled优化(只涉及函数</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">oled_reflesh</font></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">):</font></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">增加一级缓存,用于记录上一次更新后的屏幕数据:</font></span></span></span></span></span></span></span></span><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">uint8_t g_oled_ram_cache={0};</font></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">修改</font>oled_reflesh(),增加输出前判断是否一致(由于硬件特性,连续修改不需要设置列的位置)。</span></span></span></span></span></span></span></span></p>
<p> </p>
<p><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">7、抽象游戏结构体(</font></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal">Game.h</span></span></span></span></span></span><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">)</font></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:12pt"><span style="background:#ffffff"><span style="12.6500pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">在</font></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal">Game.</span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">c中仅是被注释起来的示例。</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal">game_event预定义了按键A、B、1、2、3、4按下,以及定时器触发和请求刷新显示事件。父过程通过结构体_GAME中的(*game_event_handle)(game_event event)向子过程传递事件,并获取最新的GAME_STAT。面向对象的角度看,每个游戏都是一个单例对象。启动一个游戏时,首先执行该游戏的init函数,获得指向该游戏的结构体指针game。</span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">之后有</font>2种处理方法:用中断或是while(1)</span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">:</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">如果用中断,则</font>(1)执行game->game_loop_handle直到退出;(2)在事件对应的处理函数中调用game->game_event_handle,将事件传递给game;(3)维护一个game*的栈,把当前的game压进去,并在game退出时,恢复最新的顶部game。如果使用while(1),则(1)while(1)要写在在main函数一级,也就是整个系统的最高层;(2)通过PIO、延时等方法判断是否触发事件,然后用game->game_event_handle,将事件传递给game,同时根据返回的GAME_STAT值,判断是否游戏已经退出。(3)由于这种情况下,需要父级game管理子级game,并在子级game退出时,接管输入输出。</span></span></span></span></span></span></span></span></span></span></p>
<p> </p>
<p> </p>
<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:"Times New Roman""><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">8、主菜单(</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal">game_MainMenu</span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">.h、</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal">game_MainMenu</span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">.c):</font></span></span></span></span></span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">用于显示菜单和启动游戏。因为现在只做了</font>1个Flappy Bird,所以10个菜单挂的</span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">都</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">是它。</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">然后把菜单</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">画</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">出来,响应按钮事件,更换选择或执行选中游戏的操作。</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">当选中时,将</font>gameMenu状态设置成游戏中,同时初始化对应的game</span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">,这时</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">所有的事件都应该传给当前的</font>game</span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">。传事件之后</font></span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">顺便检查一下,要是已经退出了,那就把</font>gameMenu的状态改回来</span></span></span></span></span></span><span style="font-size:10.5000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="color:#333333"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">,也就是接管控制。</font></span></span></span></span></span></span></span></span></p>
<p> </p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span class="17" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">五、作品源码</font></span></span></b></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span class="17" style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">步统计,代码超过1600行。核心代码在发帖和博客中详细分析(见第七部分的链接)。</font></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span class="17" style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">工程文件压缩后约35MB 。</font></span></span></span></span></p>
<p>**** Hidden Message *****</p>
<p> </p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span class="17" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">六、</font></span></span><span style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">视频</font></span></span><span class="17" style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">演示</font></span></span></b></span></span></p>
<p><span style="font-size:22pt"><span style="background:#ffffff"><span style="vertical-align:baseline"><span style="21.0000pt"><span style="font-family:Calibri"><span style="font-size:11.0000pt"><span style="background:#ffffff"><span style="font-family:微软雅黑"><span style="letter-spacing:0.0000pt"><span style="font-style:normal"><font face="微软雅黑">基于平头哥</font>CH2601的游戏掌机原型:flappy bird</span></span></span></span></span><span class="17" style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">:</font></span></span></span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span class="17" style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">链接地址:</font></span></span><a href="https://www.bilibili.com/video/BV1pa411L7JU"><u><span class="16" style="font-size:11.0000pt"><span style="font-family:微软雅黑"><span style="color:#0000ff"><span style="text-decoration:underline"><span style="text-underline:single"><font face="微软雅黑">https://www.bilibili.com/video/BV1pa411L7JU</font></span></span></span></span></span></u></a></span></span></p>
<p><iframe allowfullscreen="true" frameborder="0" height="250" src="//player.bilibili.com/player.html?bvid=1pa411L7JU&page=1" style="background:#eee;margin-bottom:10px;" width="400"></iframe><br />
</p>
<p> </p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">七、项目总结</font></span></span></b></span></span></p>
<p><span style="font-family: 微软雅黑; font-size: 11pt;">1、项目总结:</span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">本项目验证了</font></span></span><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">RVB2601</font></span></span><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">的资源和处理能力,在</font></span></span><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">YoC的组件基础上,比较快速的搭建出了掌上游戏机平台。受时间约束,完成了主控和一个游戏,可以作为原型验证CH2601的运算速度和片上存储空间。</font></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">后期努力方向包括:</font></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">1)更多控制方式;</font></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">2)了解组件依赖关系,裁剪工程,提高编译速度;</font></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">3)研究</font>udp协议实现,支持网络对战。</span></span></span></span></p>
<p> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">2、</font></span></span><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">“</font></span></span><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">【平头哥</font>RVB2601创意应用开发】掌上游戏机</span></span><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">”系列文章:</font></span></span></span></span></p>
<p> </p>
<table class="MsoTableGrid" style="border-collapse:collapse; width:100.0000%; margin-left:6px; border:none; text-align:justify; font-family:"Times New Roman"; font-size:13px">
<thead>
<tr>
<th scope="col" style="border-width: 1px; border-style: solid; border-color: black; width: 16.7%; padding: 0px 2px;" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">标题</font></span></span></span></span></p>
<br />
</th>
<th scope="col" style="border-width: 1px; border-style: solid; border-color: black; width: 44.4%; padding: 0px 2px;" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">电子工程世界</font>-论坛-平头哥RISC-V RVB2601活动专区</span></span></span></span></p>
<br />
</th>
<th scope="col" style="border-width: 1px; border-style: solid; border-color: black; width: 38.86%; padding: 0px 2px;" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">平头哥芯片开放社区</font>(OCC)</span></span><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">博客</font></span></span></span></span></p>
<br />
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border-bottom:1px solid black; width:16.7000%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">(</font></span></span><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">0</font></span></span><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">)开箱,吓一跳</font></span></span></span></span></p>
<br />
</td>
<td style="border-bottom:1px solid black; width:44.4000%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><a href="https://bbs.eeworld.com.cn/thread-1205763-1-1.html"><font face="微软雅黑">https://bbs.eeworld.com.cn/thread-1205763-1-1.html</font></a></span></span></span></span></p>
<br />
</td>
<td style="border-bottom:1px solid black; width:38.8600%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"> </p>
<br />
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; width:16.7000%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">(</font></span></span><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">1</font></span></span><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">)对眼儿画图记</font></span></span></span></span></p>
<br />
</td>
<td style="border-bottom:1px solid black; width:44.4000%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><a href="https://bbs.eeworld.com.cn/thread-1205765-1-1.html"><font face="微软雅黑">https://bbs.eeworld.com.cn/thread-1205765-1-1.html</font></a></span></span></span></span></p>
<br />
</td>
<td style="border-bottom:1px solid black; width:38.8600%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><a href="https://occ.t-head.cn/community/post/detail?id=4053904347728846848"><font face="微软雅黑">https://occ.t-head.cn/community/post/detail?id=4053904347728846848</font></a></span></span></span></span></p>
<br />
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; width:16.7000%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">(</font></span></span><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">2</font></span></span><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">)飞翔的小鸟</font></span></span></span></span></p>
<br />
</td>
<td style="border-bottom:1px solid black; width:44.4000%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><a href="https://bbs.eeworld.com.cn/thread-1205768-1-1.html"><font face="微软雅黑">https://bbs.eeworld.com.cn/thread-1205768-1-1.html</font></a></span></span></span></span></p>
<br />
</td>
<td style="border-bottom:1px solid black; width:38.8600%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><a href="https://occ.t-head.cn/community/post/detail?id=4053956110129438720"><font face="微软雅黑">https://occ.t-head.cn/community/post/detail?id=4053956110129438720</font></a></span></span></span></span></p>
<br />
</td>
</tr>
<tr>
<td style="border-bottom:1px solid black; width:16.7000%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">(</font></span></span><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">3</font></span></span><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">)一按就蹦</font></span></span></span></span></p>
<br />
</td>
<td style="border-bottom:1px solid black; width:44.4000%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><a href="https://bbs.eeworld.com.cn/thread-1205862-1-1.html"><font face="微软雅黑">https://bbs.eeworld.com.cn/thread-1205862-1-1.html</font></a></span></span></span></span></p>
<br />
</td>
<td style="border-bottom:1px solid black; width:38.8600%; padding:0px 2px 0px 2px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><br />
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:9.0000pt"><span style="font-family:微软雅黑"><a href="https://occ.t-head.cn/community/post/detail?id=4054229384210034688"><font face="微软雅黑">https://occ.t-head.cn/community/post/detail?id=4054229384210034688</font></a></span></span></span></span></p>
<br />
</td>
</tr>
</tbody>
</table>
<p> </p>
<p> </p>
<p> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">八、其他</font></span></span></b></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">感谢</font></span></span><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">电子工程世界</font></span></span><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">和</font></span></span><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">平头哥芯片开放社区</font></span></span><span style="font-size:11.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">的支持!</font></span></span></span></span></p>
<p> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:"Times New Roman""><b><span style="font-size:16.0000pt"><span style="font-family:微软雅黑"><font face="微软雅黑">九、作品完整设计说明WORD文档</font></span></span></b></span></span></p>
<p style="text-align:justify"></p>
<p> </p>
恭喜完成作品! 游戏机点赞了 <p>谢谢分享</p>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>
<p>谢谢分享</p>
</td>
</tr>
</tbody>
</table>
<p>赞一个。可见很费了一番心力!</p>
页:
[1]