当前位置:网站首页>用C语言开发NES游戏(CC65)07、控制器
用C语言开发NES游戏(CC65)07、控制器
2022-07-28 11:26:00 【firseve】
07、控制器
NES上有2个控制器端口。您可以使用端口4016和4017随时读取它们。在幕后,它会关闭和打开4016端口,然后一次读取按钮,1个按钮,8次读取,然后将它们转换为变量。
Neslib,使用此功能的方法。
pad1 = pad_poll(0) 读取控制器1。
pad2 = pad_poll(1) 读取控制器2。
如果你希望不重复读取手柄的情况下获取值可以使用下面的方法再次取到值。
pad_state(0)
pad_state(1)
pad_trigger() 获取最近按下的按钮。我不用它。
如果你用了,顺序将是pad_trigger() 然后是pad_state(),因为触发器运行了pad_poll()函数。
我写了一个函数get_pad_new(),它类似于pad_trigger(),除了先运行pad_poll() 然后运行get_pad_new()。
pad1 = pad_poll(0);
pad1_new = get_pad_new(0);
pad1_new 会获取最近被按下的按钮。如果按下了暂停键,我们不希望他连续的暂停、恢复、暂停、恢复的循环。应该是松开暂停键,再按下的时候才会修改当前状态(暂停再按一次应该恢复到运行状态)
pad1 是一个8位的char类型,正好是8个按钮的字段位置。我们需要用位标识来判断按下了那个按键。
if(pad1_new & PAD_START){
Pause();
}
精灵与碰撞
我给每个精灵都设置了单独的控制,当他们碰撞的时候就改变背景颜色。
if(collision){
pal_col(0,0x30);
}
我写了个功能,可以测试任何精灵对象是否发生了触碰。函数需要2个4字节的对象(或数组),字节顺序是(x,y,宽,高)
我让这个函数接受2个void指针,我希望以后可以使用不同类型的对象结构。至少,这是个方案。
碰撞检测代码例子
collision = check_collision(&BoxGuy1, &BoxGuy2);
我们还能把他直接放到if条件里使用
if(check_collision(&BoxGuy1, &BoxGuy2))
可以考虑使用ASM汇编方式优化这个代码
if((obj1_right >= obj2_left) &&
(obj2_right >= obj1_left) &&
(obj1_bottom >= obj2_top) &&
(obj2_bottom >= obj1_top)) return 1;
else return 0;
在发生碰撞的时候屏幕背景变成了白色,能确认他生效了。
一个精灵离开另一个精灵一半的时候会有点问题,不过这已经满足需求了。



https://github.com/nesdoug/08_Pads/blob/master/Pads.c
https://github.com/nesdoug/08_Pads
边栏推荐
- Great! Jd.com developed the highly available website construction technology PDF recommended by the first brother. Prepare the water and chew it slowly
- 云原生机器学习落地难?灵雀云助力企业快速应用 MLOps
- Several ways to bind controls --butterknife/viewbinding/databinding
- Full analysis of seven classical regression analysis methods
- OSCache cache monitoring Refresh Tool
- PHP gets all the dates of this week or the last seven days
- Rest style
- Notes on using objectanimator
- 腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
- LyScript 获取上一条与下一条指令
猜你喜欢

Image filter from the perspective of convolution

瑞吉外卖——Day01

Several ways to bind controls --butterknife/viewbinding/databinding

STL concept and its application

Gecko competition 2.0 is new! Come and show your flexible operation skills!

Application of mobile face stylization Technology

Unity遇坑记之 ab包卸载失败

Untiy中控制Animation的播放速度

Untiy controls the playback speed of animation

IRBuilder
随机推荐
Multithreading and high concurrency (III) -- source code analysis AQS principle
String function (Part 2)
Unity encountered a pitfall and the AB package failed to unload
Hcip (condition matching and OSPF packet related knowledge)
Modify the running container port mapping
解决PHP提示Warning: Division by zero in错误
Design process sharing of wireless anti loss alarm based on single chip microcomputer
What if the instruction set umi2 is missing? PTK installation cannot be carried out
Laravel $object->updated_at 返回的是Carbon对象,如何返回正常时间格式
Laravel form data validation
易观分析:以用户为中心提升手机银行用户体验,助力用户价值增长
【vulnhub】Raven2
Force deduction solution summary 735 planetary collision
14. User web layer services (II)
Unity中使用UnityWebRequest进行网络和本地图片加载
Introduction to several methods of keeping two decimal places in PHP
"Weilai Cup" 2022 Niuke summer multi school training camp 2
PHP获取本周所有日期或者最近七天所有日期
【vulnhub】Raven2
使用百度飞桨 EasyDL 完成垃圾分类