程序清單4-15 在窗體的Load事件中啟動(dòng)繪制循環(huán)
private void Form1_Load(object sender, EventArgs e)
{
// Enable both of the timers used within the form
fpsTimer.Enabled = true;
// Show the game form and ensure that it repaints itself
this.Show();
this.Invalidate();
// Begin the game's render loop
RenderLoop();
}
項(xiàng)目現(xiàn)在可以運(yùn)行了,并且出現(xiàn)了彈跳的小球。我們對(duì)CBounceGame類的Reset方法稍微進(jìn)行一點(diǎn)修改(參見(jiàn)程序清單4-16)來(lái)體現(xiàn)該游戲引擎的一個(gè)優(yōu)勢(shì)。我們?cè)谘h(huán)中不止添加1個(gè)小球,而是20個(gè),馬上就可以看到窗體中出現(xiàn)了很多運(yùn)動(dòng)著的小球。
程序清單4-16 在CBounceGame.Reset中添加許多小球
[...]
// Add some balls
for (int i = 0; i < 20; i++)
{
// Create a new ball. This will auto-generate a random position for itself.
ball = new CObjBall(this);
// Add the ball to the game engine
GameObjects.Add(ball);
}
[...]