当前位置:网站首页>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 .
边栏推荐
- Interpretable ml of Li Hongyi's machine learning model
- Introduction to several methods of keeping two decimal places in PHP
- QT writing IOT management platform 42 data query export print
- Force deduction solution summary 735 planetary collision
- Unity中使用UnityWebRequest进行网络和本地图片加载
- Hcip day 6 (OSPF related knowledge)
- 2022.07.12 summer training personal qualifying (VII)
- Idea replication module
- String function (Part 2)
- The principle and use of the wrap file of tolua
猜你喜欢

Lyscript get previous and next instructions

Untiy中控制Animation的播放速度

Unitywebrequest is used in unity to load network and local pictures

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

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

用arduino开发ESP8266 搭建开发环境

LyScript 获取上一条与下一条指令

Hcip rip comprehensive experiment

Hcip day 6 (OSPF related knowledge)

云原生机器学习落地难?灵雀云助力企业快速应用 MLOps
随机推荐
On Governance and innovation | the openanolis sub forum of the 2022 open atom global open source summit was successfully held
8000 word explanation of OBSA principle and application practice
【vulnhub】presidential1
[try to hack] at, SC, PS command authorization
用arduino开发ESP8266 搭建开发环境
[diary of supplementary questions] [2022 Niuke summer school 2] h-take the elevator
IRBuilder
Character function and string function (Part 1)
太赞了!京东研发一哥力荐的高可用网站构建技术PDF,备好水,慢慢啃
云原生机器学习落地难?灵雀云助力企业快速应用 MLOps
Developing NES games with C language (cc65) 06. Sprites
安徽京准:北斗卫星同步时钟|北斗同步时钟|NTP网络时钟服务器
What if the instruction set umi2 is missing? PTK installation cannot be carried out
PHP获取本周所有日期或者最近七天所有日期
用C语言开发NES游戏(CC65)06、精灵
用C语言开发NES游戏(CC65)09、滚动
Huawei releases harmonyos 3 and all scene new products, and the smart experience goes further
2022.07.07 summer training personal qualifying (II)
Latex矩阵简单使用
Latex matrix is simple to use