当前位置:网站首页>Developing NES game (cc65) 07 and controller with C language
Developing NES game (cc65) 07 and controller with C language
2022-07-28 12:23:00 【firseve】
07、 controller
NES There are 2 Controller ports . You can use port 4016 and 4017 Read them at any time . Behind the scenes , It will close and open 4016 port , Then read the button once ,1 Button ,8 Secondary read , Then convert them into variables .
Neslib, How to use this function .
pad1 = pad_poll(0) Read controller 1.
pad2 = pad_poll(1) Read controller 2.
If you want to get the value without repeatedly reading the handle, you can use the following method to get the value again .
pad_state(0)
pad_state(1)
pad_trigger() Get the most recently pressed button . I don't use it .
If you use , The order will be pad_trigger() And then there was pad_state(), Because the trigger runs pad_poll() function .
I wrote a function get_pad_new(), It is similar to pad_trigger(), In addition to running first pad_poll() And then run get_pad_new().
pad1 = pad_poll(0);
pad1_new = get_pad_new(0);
pad1_new Will get the recently pressed button . If the pause key is pressed , We don't want him to pause continuously 、 recovery 、 Pause 、 The cycle of recovery . It should be to release the pause key , Press again to change the current state ( Pause and press again to return to the running state )
pad1 It's a 8 Bit char type , Is precisely 8 Field position of buttons . We need to use the bit ID to judge which button is pressed .
if(pad1_new & PAD_START){
Pause();
}
Spirit and collision
I set up separate controls for each elf , When they collide, they change the background color .
if(collision){
pal_col(0,0x30);
}
I wrote a function , You can test whether any sprite object has been touched . The function needs 2 individual 4 Byte object ( Or an array ), The byte order is (x,y, wide , high )
I let this function accept 2 individual void The pointer , I hope to use different types of object structures in the future . At least , This is a plan .
Collision detection code example
collision = check_collision(&BoxGuy1, &BoxGuy2);
We can also put him directly into if Use... In conditions
if(check_collision(&BoxGuy1, &BoxGuy2))
Consider using ASM Assembly mode optimizes this code
if((obj1_right >= obj2_left) &&
(obj2_right >= obj1_left) &&
(obj1_bottom >= obj2_top) &&
(obj2_bottom >= obj1_top)) return 1;
else return 0;
In case of collision, the screen background turns white , It can be confirmed that he has taken effect .
There will be some problems when one elf leaves the other half , But this has met the demand .



https://github.com/nesdoug/08_Pads/blob/master/Pads.c
https://github.com/nesdoug/08_Pads
边栏推荐
- 【vulnhub】Raven2
- PHP时间戳相减转化为天小时分秒
- Solve the PHP prompt warning: division by zero in error
- Laravel之缓存
- Introduction to several methods of keeping two decimal places in PHP
- Industry, University, research and application jointly build an open source talent ecosystem | the 2022 open atom global open source summit education sub forum was successfully held
- SQL注入 Less18(头部注入+报错注入)
- Full analysis of seven classical regression analysis methods
- String function (Part 2)
- [diary of supplementary questions] [2022 Niuke summer multi school 2] i-let fat tension
猜你喜欢

用C语言开发NES游戏(CC65)07、控制器

On Governance and innovation | the openanolis sub forum of the 2022 open atom global open source summit was successfully held

用C语言开发NES游戏(CC65)10、游戏循环

聚变云原生,赋能新里程 | 2022 开放原子全球开源峰会云原生分论坛圆满召开

Design process sharing of wireless anti loss alarm based on single chip microcomputer

Great! Jd.com developed the highly available website construction technology PDF recommended by the first brother. Prepare the water and chew it slowly

配置Jupyter远程服务器

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

要想组建敏捷团队,这些方法不可少

The game process and the underlying implementation are gradually completed
随机推荐
[leetcode] 7. valid anagram · effective letter ectopic words
本地化、低时延、绿色低碳:阿里云正式启用福州数据中心
【Try to Hack】AT、SC、PS命令提权
Lua 中 __index、__newindex、rawget、rawset的理解
Solve the PHP prompt warning: division by zero in error
瑞吉外卖——Day01
2022.07.11 summer training personal qualifying (VI)
php 日期计算操作处理,当前日期加一天和指定日期减一天
【Try to Hack】udf提权
Yolov3 complete explanation - from the perspective of data coding
Latex matrix is simple to use
【Try to Hack】内网基础
SQL注入 Less18(头部注入+报错注入)
PHP ⽉ the simplest way to add and subtract ⽅
tolua之wrap文件的原理与使用
Unity中使用UnityWebRequest进行网络和本地图片加载
LyScript 获取上一条与下一条指令
Analysys analysis: focus on users, improve the user experience of mobile banking, and help the growth of user value
华为发布HarmonyOS 3及全场景新品,智慧体验更进一步
Hcip rip comprehensive experiment