当前位置:网站首页>Developing NES games with C language (cc65) 10. Game cycle
Developing NES games with C language (cc65) 10. Game cycle
2022-07-28 12:23:00 【firseve】
Paste the CSDN The format is not adjusted , If you want to see a good format, click below
https://happysoul.github.io/nes/nesdoug/
Let's talk about the game cycle
The game needs a cycle ,while(1){}
The first item in the cycle is ppu_wait_nmi(), He will wait for the start of a new frame to trigger nmi, Per second 60 frame ( European version is 50 frame )
however , If the logic of the game is too complex, it will take more time , And more than nmi Start of trigger , Then wait until ppu_wait_nmi() after , He will wait for the next frame , This will make the game slow .
Fortunately, this has not happened yet , Because our code is too short , But the later game is not so simple , So we should pay attention to the simplicity of the code .
The controller uses
pad_poll(0)
get_pad_new(0)
Then I want to say clear_vram_buffer(), These codes are unique to me . because nmi The role of , We need to rewrite him , So that he can achieve more functions
score_lives_draw() Use one_vram_buffer() Redisplay the scoreboard at the top of the screen .
These similar vram_put(), But they will be put in the buffer , also nmi The code will be v-blank Automatically push them to ppu.
Then there is the logic of the game , Mobile racket , Moving ball , Check for collisions .
Moving handle
if(pad1 & PAD_LEFT){
Paddle.X -= 2;
if(Paddle.X < PADDLE_MIN) Paddle.X = PADDLE_MIN;
}
if(pad1 & PAD_RIGHT){
Paddle.X += 2;
if(Paddle.X > PADDLE_MAX) Paddle.X = PADDLE_MAX;
}
Moving ball , If he is mobile
if(ball_direction == GOING_UP){
Ball.Y -= 3;
if(Ball.Y < MAX_UP){
ball_direction = GOING_DOWN;
}
}
else { // going down
Ball.Y += 3;
if(Ball.Y > MAX_DOWN){
--lives01;
ball_state = BALL_OFF;
}
}
Then came the drawing wizard , First, clean up the old , Then redraw all active sprites .
If a piece is hit by the ball ,hit_block(), Delete this block from the collision graph , Fill this area with a blank block .
Again , I use vram The buffer temporarily stores it , And in v-blank Automatically send it to PPU.
Usually , I will use many
game_states: Such as the title , game , Pause , end .
I use different ball_states: Fly out of the screen BALL_OFF, Prepare to launch the ball BALL_STUCK ( Stuck on the edge of the plate ), The ball is moving BALL_ACTIVE
I use NES Screen Tool Production background , stay c1.csv Blocks that can be destroyed are defined in . I'm useless Tiled Tools , Because he shows easily , However, if the corresponding destructible block layout is modified, it also needs to be modified ( That's the front one c1.csv)
const unsigned char c1 [] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
Use grey bricks in NES Screen Tool Chinese painting , Then compress the export RLE file .

I am here NES Screen Tool The property sheet has been changed in advance , Then save the background . This is the color of the tiles , They are different palettes . But they all use the same tiles . This is the property inspector view ( Press “A”).

The scoreboard will be updated every frame , Please note that I save each number of scores as a separate variable ( Grade is 0-9)
score10 yes 10 digit ,score01 It's a single digit . because 6502 The processor lacks built-in mathematical operations , So division and modulus pair NES The operation of is very slow , So keeping each number separate can speed up the code .

https://github.com/nesdoug/12_Break
Now it's easy to turn this into a game , But horizontal movement requires complex code , I will write the example as simple as possible .
边栏推荐
- 一些知识概念
- Saltstack command injection vulnerability analysis (cve-2020-16846)
- SQL injection less23 (filter comment)
- 用C语言开发NES游戏(CC65)08、背景 碰撞
- 要想组建敏捷团队,这些方法不可少
- Play with poetry - appreciate the beauty of ancient poetry
- Hcip day 6 (OSPF related knowledge)
- 新手如何快速完成建站?来免费“试衣间”体验
- Solve the PHP prompt warning: division by zero in error
- 【vulnhub】Raven2
猜你喜欢

Anhui Jingzhun: Beidou satellite synchronous clock | Beidou synchronous clock | NTP network clock server

REST风格

Hcip (condition matching and OSPF packet related knowledge)

Unity中使用UnityWebRequest进行网络和本地图片加载

Fusion cloud native, enabling new mileage | 2022 open atom global open source summit cloud native sub forum successfully held

论治理与创新 | 2022 开放原子全球开源峰会 OpenAnolis 分论坛圆满召开

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

瑞吉外卖——Day01

Design process sharing of wireless anti loss alarm based on single chip microcomputer
![Opencv notes sorting [Hough transform]](/img/80/8f5b0d7e1c5adc39cb5404dcdb1b11.png)
Opencv notes sorting [Hough transform]
随机推荐
用C语言开发NES游戏(CC65)06、精灵
Several ways to bind controls --butterknife/viewbinding/databinding
金九银十 再不卷就来不及了
用C语言开发NES游戏(CC65)11、Metatiles
配置Jupyter远程服务器
REST风格
缺少指令集umi2 怎么办?ptk方式安装无法进行
QT writing IOT management platform 42 data query export print
PHP timestamp subtraction converts to days, hours, minutes and seconds
本地化、低时延、绿色低碳:阿里云正式启用福州数据中心
游戏流程与底层实现 逐步完成
Huawei releases harmonyos 3 and all scene new products, and the smart experience goes further
2022.07.07 summer training personal qualifying (II)
[diary of supplementary questions] [2022 Niuke summer multi school 2] l-link with level editor I
【Try to Hack】udf提权
Fusion cloud native, enabling new mileage | 2022 open atom global open source summit cloud native sub forum successfully held
LyScript 获取上一条与下一条指令
Hcip rip comprehensive experiment
Code simplification
Unitywebrequest is used in unity to load network and local pictures