当前位置:网站首页>Develop NES game (cc65) 07 and controller with C language (collision with spirit)
Develop NES game (cc65) 07 and controller with C language (collision with spirit)
2022-07-28 12:23:00 【firseve】
Translate the original address ( Paste the CSDN The format is not adjusted , If you want to see a good format, click below )
https://happysoul.github.io/nes/nesdoug/
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
边栏推荐
- What if the instruction set umi2 is missing? PTK installation cannot be carried out
- Character function and string function (Part 1)
- IRBuilder
- Hcip (configuration of GRE and mGRE and OSPF related knowledge)
- 【vulnhub】Raven2
- Zhou Hongyi talks about Internet thinking: users, not customers
- 腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
- Loongarch Godson architecture document collection
- Image filter from the perspective of convolution
- Style conversion model style_ Transformer project instance pytorch implementation
猜你喜欢

Reasons and solutions for moving the first column to the last column in El table

Lyscript get previous and next instructions

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

IDEA复制模块

Distributed system (III) construction of distributed transaction service

瑞吉外卖——Day01

China business CDP white paper | love Analysis Report

云原生机器学习落地难?灵雀云助力企业快速应用 MLOps

"Weilai Cup" 2022 Niuke summer multi school training camp 2

Exploration on cache design optimization of community like business
随机推荐
Laravel $object->updated_ At returns the carbon object. How to return the normal time format
SQL注入 Less26(过滤空格和注释符,使用不带空格的报错注入)
Unity中使用UnityWebRequest进行网络和本地图片加载
PHP日期时间运用:添加或减去特定日期的天数
Use Baidu PaddlePaddle easydl to complete garbage classification
【vulnhub】presidential1
SQL injection LESS18 (header injection + error injection)
解决PHP提示Warning: Division by zero in错误
Code simplification
[leetcode] 7. valid anagram · effective letter ectopic words
Hcip (condition matching and OSPF packet related knowledge)
顶级“Redis笔记”,缓存雪崩+击穿+穿透+集群+分布式锁,NB了
Force deduction solution summary 735 planetary collision
数字经济时代的开源数据库创新 | 2022 开放原子全球开源峰会数据库分论坛圆满召开
【vulnhub】presidential1
让arduino支持nuvotom新唐
本地化、低时延、绿色低碳:阿里云正式启用福州数据中心
Distributed timer
用C语言开发NES游戏(CC65)05、调色板
Lua对table进行深拷贝