文章目录:
一:效果演示
二:实现思路
三:代码实现
form1
效果图
代码
form2
效果图
代码
一:效果演示
效果图◕‿◕✌✌✌
代码下载
二:实现思路
窗口1 就是实现窗口的跳转和关闭窗口2 1.先添加背景图片、小鸟、障碍物、timer、分数显示2.小鸟2.1 放好小鸟的位置,让它自己不停的下降2.2 通过键盘、鼠标单击双击改变top让小鸟上升3.障碍物3.1 每四个为一组,上面和下面一样的3.2 让每一个到左边的距离递减从而移动3.3 每出界一个障碍物,改变它的位置,让它在后面显示3.4 后面改变位置的障碍物,也通过随机函数改变高度4.有变动的都在timer里面控制5.如果碰到障碍物就退出游戏5.1 看是否相交来判断小鸟到左边的位置 与 障碍物到左边的距离小鸟的高度 与 障碍物的height/top5.2 若相交事件监听关闭弹出对话框提示,并显示分数关闭窗口2,跳转到开始游戏的窗口16.工具箱右键添加音乐url:G:\Game\BirdClass\game.mp3放在主目录里面,不然可能识别不出来
三:代码实现
form1
效果图
代码
Option ExplicitPrivate Sub Command1_Click()Form1.Visible = FalseForm2.Visible = True End SubPrivate Sub Command2_Click()End End SubPrivate Sub Command3_Click()Dim rule As Stringrule = MsgBox("通过按键盘空格、鼠标单击或双击控制小鸟。如果触碰到障碍则游戏结束!", vbQuestion, "游戏规则说明:") End SubPrivate Sub Form_Load()End Sub
form2
效果图
代码
Option Explicit Dim score As IntegerPrivate Sub Form_Click()bird.Top = bird.Top - 800 '控制鸟 End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)If KeyCode = Asc(" ") Then bird.Top = bird.Top - 800 '控制鸟,键盘空格高度上升 End SubPrivate Sub Image3_Click()End SubPrivate Sub Form_Load()'G:\Game\BirdClass\game.mp3'WindowsMediaPlayer1.URL = App.Path & "/G:/Game/BirdClass/game.mp3" End SubPrivate Sub Label1_Click()Label1.Visible = FalseTimer1.Enabled = TrueEnd SubPrivate Sub Label1_DblClick()bird.Top = bird.Top - 800 '控制鸟 End SubPrivate Sub Timer1_Timer()'鸟的位置bird.Top = bird.Top + 400'上面移动shang1.Left = shang1.Left - 80shang2.Left = shang2.Left - 80shang3.Left = shang3.Left - 80shang4.Left = shang4.Left - 80score = score + 1Label2.Caption = score'下面移动xia1.Left = shang1.Leftxia2.Left = shang2.Leftxia3.Left = shang3.Leftxia4.Left = shang4.Left'上面变动If shang1.Left + shang1.Width < 0 Then '出界了shang1.Left = shang4.Left + shang4.Width + 800 '加一栏Randomizeshang1.Height = Int(Rnd * 3000 + 800) '改变高度End IfIf shang2.Left + shang2.Width < 0 Thenshang2.Left = shang1.Left + shang1.Width + 800Randomizeshang2.Height = Int(Rnd * 3000 + 800)End IfIf shang3.Left + shang3.Width < 0 Thenshang3.Left = shang2.Left + shang2.Width + 800Randomizeshang3.Height = Int(Rnd * 3000 + 800)End IfIf shang4.Left + shang4.Width < 0 Thenshang4.Left = shang3.Left + shang3.Width + 800Randomizeshang4.Height = Int(Rnd * 3000 + 800)End If'下面变动xia1.Top = shang1.Height + 3500xia2.Top = shang2.Height + 3500xia3.Top = shang3.Height + 3500xia4.Top = shang4.Height + 3500'碰撞'上面超出If bird.Left + bird.Width > shang1.Left And bird.Top < shang1.Height ThenTimer1.Enabled = FalseDim a1 As Stringa1 = MsgBox("非常遗憾,本局游戏 您输了哦!" + "您的得分为:" + Str(score) + "分", vbExclamation, "尊敬的玩家您好!")Form1.ShowForm2.HideEnd IfIf bird.Left + bird.Width > shang2.Left And bird.Top < shang2.Height ThenTimer1.Enabled = FalseDim a2 As Stringa2 = MsgBox("非常遗憾,本局游戏 您输了哦!" + "您的得分为:" + Str(score) + "分", vbExclamation, "尊敬的玩家您好!")Form1.ShowForm2.HideEnd IfIf bird.Left + bird.Width > shang3.Left And bird.Top < shang3.Height ThenTimer1.Enabled = FalseDim a3 As Stringa3 = MsgBox("非常遗憾,本局游戏 您输了哦!" + "您的得分为:" + Str(score) + "分", vbExclamation, "尊敬的玩家您好!")Form1.ShowForm2.HideEnd If'下面超出If bird.Left + bird.Width > xia1.Left And bird.Top > xia1.Top ThenTimer1.Enabled = FalseDim b1 As Stringb1 = MsgBox("非常遗憾,本局游戏 您输了哦!", vbExclamation, "尊敬的玩家您好!")Form1.ShowForm2.HideEnd IfIf bird.Left + bird.Width > xia2.Left And bird.Top > xia2.Top ThenTimer1.Enabled = FalseDim b2 As Stringb2 = MsgBox("非常遗憾,本局游戏 您输了哦!", vbExclamation, "尊敬的玩家您好!")Form1.ShowForm2.HideEnd IfIf bird.Left + bird.Width > xia3.Left And bird.Top > xia3.Top ThenTimer1.Enabled = FalseDim b3 As Stringb3 = MsgBox("非常遗憾,本局游戏 您输了哦!", vbExclamation, "尊敬的玩家您好!")Form1.ShowForm2.HideEnd IfEnd Sub