当前位置:网站首页>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
边栏推荐
- 缺少指令集umi2 怎么办?ptk方式安装无法进行
- 8000 字讲透 OBSA 原理与应用实践
- Tencent two sides: @bean and @component are used in the same class, what will happen?
- “蔚来杯“2022牛客暑期多校训练营2
- [leetcode] 8. binary search · binary search
- Rest style
- REST风格
- Fusion cloud native, enabling new mileage | 2022 open atom global open source summit cloud native sub forum successfully held
- 用C语言开发NES游戏(CC65)08、背景 碰撞
- PHP date time application: add or subtract the number of days of a specific date
猜你喜欢

Use Baidu PaddlePaddle easydl to complete garbage classification

易观分析:以用户为中心提升手机银行用户体验,助力用户价值增长

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

用C语言开发NES游戏(CC65)11、Metatiles

程序的存储态与运行态

Stored state and running state of program

本地化、低时延、绿色低碳:阿里云正式启用福州数据中心

Hcip (PAP authentication and chap authentication of PPP)

Training mode and practice of digital applied talents in Colleges and Universities under the integration of industry and education

ViewPager2+Fragment
随机推荐
Force deduction solution summary 735 planetary collision
用C语言开发NES游戏(CC65)06、精灵
PHP获取本周所有日期或者最近七天所有日期
The principle and use of the wrap file of tolua
Hcip (configuration of GRE and mGRE and OSPF related knowledge)
8000 字讲透 OBSA 原理与应用实践
Full resolution of the use of go native plug-ins
使用百度飞桨 EasyDL 完成垃圾分类
SQL注入 Less26(过滤空格和注释符,使用不带空格的报错注入)
QT writing IOT management platform 42 data query export print
ViewPager2+Fragment
Character function and string function (Part 1)
用C语言开发NES游戏(CC65)05、调色板
SQL injection LESS18 (header injection + error injection)
Force buckle 7_ 1672. Total assets of the richest customers
Distributed system (III) construction of distributed transaction service
Idea replication module
[diary of supplementary questions] [2022 Hangdian summer school 2] k-dos card
2022.07.11 summer training personal qualifying (VI)
【vulnhub】Raven2