学习VB编程第31天,小游戏-你能坚持到终点吗?

小微 科技学习VB编程第31天,小游戏-你能坚持到终点吗?已关闭评论110字数 1331阅读模式
摘要视频加载中...今天学习了刘金玉老师零基础VB教程的第38期,学习的主要内容是小游戏开发思路(利用事件拖动物体)。一、思路:制作界面,确定物体运动的范围,墙体颜色自定。用鼠标拖动目...

今天学习了刘金玉老师零基础VB教程的第38期,学习的主要内容是小游戏开发思路(应用事件拖动物体)。

一、思路:制作界面,肯定物体运动的规模,墙体色彩自定。用鼠标拖动目标到指定位置,便可获胜,碰到墙体则游戏失败。怎么解决用鼠标拖动问题,用(鼠标按下、鼠标移动、鼠标弹起)三个事件来解决,文章源自微观生活(93wg.com)微观生活-https://93wg.com/20859.html

Mousedown:表示可以移动目标对象,文章源自微观生活(93wg.com)微观生活-https://93wg.com/20859.html

Mousemove:表示移动方向,文章源自微观生活(93wg.com)微观生活-https://93wg.com/20859.html

Mouseup:表示移动对象不能移动。文章源自微观生活(93wg.com)微观生活-https://93wg.com/20859.html

二、游戏案例文章源自微观生活(93wg.com)微观生活-https://93wg.com/20859.html

1.如图新建两个窗体,分别新建好控件文章源自微观生活(93wg.com)微观生活-https://93wg.com/20859.html

2.输入代码:文章源自微观生活(93wg.com)微观生活-https://93wg.com/20859.html

Dim canmove As Boolean文章源自微观生活(93wg.com)微观生活-https://93wg.com/20859.html

Dim x1 As Single文章源自微观生活(93wg.com)微观生活-https://93wg.com/20859.html

Dim y1 As Single文章源自微观生活(93wg.com)微观生活-https://93wg.com/20859.html

Dim oldleft As Single

Dim oldtop As Single

Private Sub Co妹妹and1_Click()

Form2.Show

Unload Form1

End Sub

Private Sub Form_Load()

oldleft = Label1.Left

oldtop = Label1.Top

End Sub

Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, y As Single)

canmove = True

x1 = X

y1 = y

End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single)

Label3(0).Caption = &

Dim j As Integer

For j = 0 To Label3.UBound Step 1

If hanshu(Label1, Label3(j)) Then

MsgBox &

Label1.Left = oldleft

Label1.Top = oldtop

canmove = False

End If

Next j

If canmove Then

Label1.Left = Label1.Left + (X - x1)

Label1.Top = Label1.Top + (y - y1)

If hanshu(Label1, Label2) Then

MsgBox &

Label1.Left = oldleft

Label1.Top = oldtop

End If

End If

End Sub

Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, y As Single)

canmove = False

End Sub

Function hanshu(a As Label, b As Label)

Dim M As Boolean

If a.Left + a.Width >= b.Left And a.Left <= b.Left + b.Width And a.Top + a.Height >= b.Top And a.Top <= b.Top + b.Height Then

M = True

End If

hanshu = M

End Function

③点击生成小程序,运行结果见文章视频。

天气转凉了,一不注意就感冒了,实在没有精神学习,昨天停了一天,今天略微好点了,继续坚持学习。也提示朋友们天凉了多加衣服。

以上就是微观生活(93wg.com)关于“学习VB编程第31天,小游戏-你能坚持到终点吗?”的详细内容,希望对大家有所帮助!

继续阅读
 
小微
  • 版权声明: 本文部分文字与图片资源来自于网络,转载此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请立即通知我们(管理员邮箱:81118366@qq.com),情况属实,我们会第一时间予以删除,并同时向您表示歉意,谢谢!
  • 转载请务必保留本文链接:https://93wg.com/20859.html