[Dino爱编程]编写一个FlappyBird小游戏
作者:dinochen1983 日期:2020-02-12
【DINO爱编程】编写一个FlappyBird的游戏
【编程工具】采用delphi进行编程
【资源网站】https://opengameart.org/
【游戏介绍】https://en.wikipedia.org/wiki/Flappy_Bird
游戏的设计理念
1. FlappyBird 是一只小鸟,要通过飞行穿过一系列的水管
2.点击屏幕或点空格键,小鸟向小飞一下
3.穿过一个水管得一分。如果撞到水管就会GameOver
【技术要点】
(1) 声音的播放方式。
procedure PlaySoundFile(FileName: string);
begin
if FileExists(FileName)
then PlaySound(pchar(FileName), 0, SND_ASYNC or SND_FILENAME);
{ Flags are:
SND_SYNC =0 = Start playing, and wait for the sound to finish
SND_ASYNC =1 = Start playing, and don't wait to return
SND_LOOP =8 = Keep looping the sound until another sound is played }
end;
2. 对象之间的碰撞的分析与判断,如下图所示
if (((bird.x+20>pile[i].x)and(bird.x+20<pile[i].x+pile[i].w))
or ((bird.x-20>pile[i].x)and(bird.x-20<pile[i].x+pile[i].w)))
and (((bird.y-15>0) and (bird.y-15<pile[i].up))
or ((bird.y+15>pile[i].down-15) and (bird.y+15<image1.height)) ) then
begin
collision:=true;
end;
3.按空格键对游戏的响应。
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key=#32 THEN
begin
end;
end;
【FlappyBird的源代码】点击下载此文件:FlappyBirdexe.zip
【FlappyBird游戏的EXE文件】点击下载此文件:FlappyBird.zip
delphi 常用按键对照表