当前位置:网站首页>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 .
边栏推荐
- Several ways to bind controls --butterknife/viewbinding/databinding
- IDEA复制模块
- Modify the running container port mapping
- 【Try to Hack】内网基础
- Launcher sample code
- Lua makes a deep copy of table
- WebView details
- Launcher sample code
- [diary of supplementary questions] [2022 Niuke summer multi school 2] l-link with level editor I
- SQL injection less24 (secondary injection)
猜你喜欢

用C语言开发NES游戏(CC65)08、背景 碰撞

Hcip day 1

Saltstack command injection vulnerability analysis (cve-2020-16846)

China business CDP white paper | love Analysis Report

Interpretation of the paper: attention mechanism in medical images

QT writing IOT management platform 42 data query export print

Docker runs MySQL service

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

瑞吉外卖——Day01

Unity中使用UnityWebRequest进行网络和本地图片加载
随机推荐
PHP date time application: add or subtract the number of days of a specific date
8000 word explanation of OBSA principle and application practice
[diary of supplementary questions] [2022 Niuke summer school 2] h-take the elevator
LyScript 获取上一条与下一条指令
8000 字讲透 OBSA 原理与应用实践
Hcip day 1
Full resolution of the use of go native plug-ins
Unity中使用UnityWebRequest进行网络和本地图片加载
PHP ⽉ the simplest way to add and subtract ⽅
On Governance and innovation | the openanolis sub forum of the 2022 open atom global open source summit was successfully held
[try to hack] at, SC, PS command authorization
玩转诗词-领略古诗文之美
How can a novice quickly complete the establishment of a website? Come to the free "fitting room" experience
[diary of supplementary questions] [2022 Niuke summer multi school 2] i-let fat tension
PHP date calculation operation processing, the current date plus one day and the specified date minus one day
2022.07.10 summer training personal qualifying (V)
Notes on using objectanimator
Implementation method of mouse hover, click and double click in ue4/5
WebView详解
The principle and use of the wrap file of tolua