文章目录:
一:效果演示
二:实现思路
三:代码实现
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/top 5.2 若相交 事件监听关闭 弹出对话框提示,并显示分数 关闭窗口2,跳转到开始游戏的窗口1 6.工具箱右键添加音乐url:G:\Game\BirdClass\game.mp3 放在主目录里面,不然可能识别不出来
三:代码实现
form1
效果图
代码
Option Explicit Private Sub Command1_Click() Form1.Visible = False Form2.Visible = True End Sub Private Sub Command2_Click() End End Sub Private Sub Command3_Click() Dim rule As String rule = MsgBox("通过按键盘空格、鼠标单击或双击控制小鸟。如果触碰到障碍则游戏结束!", vbQuestion, "游戏规则说明:") End Sub Private Sub Form_Load() End Sub
form2
效果图
代码
Option Explicit Dim score As Integer Private Sub Form_Click() bird.Top = bird.Top - 800 '控制鸟 End Sub Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = Asc(" ") Then bird.Top = bird.Top - 800 '控制鸟,键盘空格高度上升 End Sub Private Sub Image3_Click() End Sub Private Sub Form_Load() 'G:\Game\BirdClass\game.mp3 'WindowsMediaPlayer1.URL = App.Path & "/G:/Game/BirdClass/game.mp3" End Sub Private Sub Label1_Click() Label1.Visible = False Timer1.Enabled = True End Sub Private Sub Label1_DblClick() bird.Top = bird.Top - 800 '控制鸟 End Sub Private Sub Timer1_Timer() '鸟的位置 bird.Top = bird.Top + 400 '上面移动 shang1.Left = shang1.Left - 80 shang2.Left = shang2.Left - 80 shang3.Left = shang3.Left - 80 shang4.Left = shang4.Left - 80 score = score + 1 Label2.Caption = score '下面移动 xia1.Left = shang1.Left xia2.Left = shang2.Left xia3.Left = shang3.Left xia4.Left = shang4.Left '上面变动 If shang1.Left + shang1.Width < 0 Then '出界了 shang1.Left = shang4.Left + shang4.Width + 800 '加一栏 Randomize shang1.Height = Int(Rnd * 3000 + 800) '改变高度 End If If shang2.Left + shang2.Width < 0 Then shang2.Left = shang1.Left + shang1.Width + 800 Randomize shang2.Height = Int(Rnd * 3000 + 800) End If If shang3.Left + shang3.Width < 0 Then shang3.Left = shang2.Left + shang2.Width + 800 Randomize shang3.Height = Int(Rnd * 3000 + 800) End If If shang4.Left + shang4.Width < 0 Then shang4.Left = shang3.Left + shang3.Width + 800 Randomize shang4.Height = Int(Rnd * 3000 + 800) End If '下面变动 xia1.Top = shang1.Height + 3500 xia2.Top = shang2.Height + 3500 xia3.Top = shang3.Height + 3500 xia4.Top = shang4.Height + 3500 '碰撞 '上面超出 If bird.Left + bird.Width > shang1.Left And bird.Top < shang1.Height Then Timer1.Enabled = False Dim a1 As String a1 = MsgBox("非常遗憾,本局游戏 您输了哦!" + "您的得分为:" + Str(score) + "分", vbExclamation, "尊敬的玩家您好!") Form1.Show Form2.Hide End If If bird.Left + bird.Width > shang2.Left And bird.Top < shang2.Height Then Timer1.Enabled = False Dim a2 As String a2 = MsgBox("非常遗憾,本局游戏 您输了哦!" + "您的得分为:" + Str(score) + "分", vbExclamation, "尊敬的玩家您好!") Form1.Show Form2.Hide End If If bird.Left + bird.Width > shang3.Left And bird.Top < shang3.Height Then Timer1.Enabled = False Dim a3 As String a3 = MsgBox("非常遗憾,本局游戏 您输了哦!" + "您的得分为:" + Str(score) + "分", vbExclamation, "尊敬的玩家您好!") Form1.Show Form2.Hide End If '下面超出 If bird.Left + bird.Width > xia1.Left And bird.Top > xia1.Top Then Timer1.Enabled = False Dim b1 As String b1 = MsgBox("非常遗憾,本局游戏 您输了哦!", vbExclamation, "尊敬的玩家您好!") Form1.Show Form2.Hide End If If bird.Left + bird.Width > xia2.Left And bird.Top > xia2.Top Then Timer1.Enabled = False Dim b2 As String b2 = MsgBox("非常遗憾,本局游戏 您输了哦!", vbExclamation, "尊敬的玩家您好!") Form1.Show Form2.Hide End If If bird.Left + bird.Width > xia3.Left And bird.Top > xia3.Top Then Timer1.Enabled = False Dim b3 As String b3 = MsgBox("非常遗憾,本局游戏 您输了哦!", vbExclamation, "尊敬的玩家您好!") Form1.Show Form2.Hide End If End Sub