⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3dblock.frm

📁 新手学习vb语言的实用资料于其对计算机语言做出相应了解的教材
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   AutoRedraw      =   -1  'True
   Caption         =   "质感极强的三维立方体"
   ClientHeight    =   3465
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5595
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   ScaleHeight     =   231
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   373
   StartUpPosition =   3  '窗口缺省
   WindowState     =   2  'Maximized
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   1
      Left            =   2070
      Top             =   1125
   End
   Begin VB.CommandButton cmdDemo 
      Caption         =   "开始运动"
      Height          =   645
      Left            =   540
      TabIndex        =   3
      Top             =   405
      Width           =   1275
   End
   Begin VB.PictureBox Picture1 
      Height          =   1950
      Left            =   2520
      ScaleHeight     =   1890
      ScaleWidth      =   2295
      TabIndex        =   0
      Top             =   840
      Width           =   2355
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         Caption         =   "X : 5"
         Height          =   195
         Left            =   45
         TabIndex        =   2
         Top             =   0
         Width           =   45
      End
      Begin VB.Label Label2 
         Caption         =   "使用鼠标单击窗体(不要单击立方体)结合按任意键可以使小块在 XY 平面运动,使用Shift+鼠标单击使小块在XZ平面运动."
         Height          =   1545
         Left            =   120
         TabIndex        =   1
         Top             =   960
         Width           =   1995
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private CenterX As Integer
Private CenterY As Integer
Private Const Size = 40
Private CurX As Integer
Private CurY As Integer
Private CurZ As Integer
Private MoveTo As Integer
Private Const MOVE_LEFT = 0
Private Const MOVE_RIGHT = 1
Private Const MOVE_UP = 2
Private Const MOVE_DOWN = 3
Private Const MOVE_FORWARD = 4
Private Const MOVE_BACKWARD = 5
Public Sub EraseBlock()
X = CurX: y = CurY: Z = CurZ
xs = (CenterX + X * Size) - Z * (Size / 2)
Ys = (CenterY - y * Size) + Z * (Size / 2)
Line (xs, Ys)-(xs + Size, Ys - Size), BackColor, BF
Line (xs - Size / 2, Ys + Size / 2)-(xs + Size / 2, Ys - Size / 2), BackColor, BF
For i = 0 To Size / 2
Line (xs - i, Ys + i)-(xs - i, Ys + i - Size - 1), BackColor
Line (xs - i + Size, Ys + i)-(xs - i + Size, Ys + i - Size), BackColor
Next
End Sub
Public Sub DrawBlock()
Line (CenterX, CenterY)-(CenterX + Size * 6, CenterY - Size * 6), vbBlue, B
Line (CenterX, CenterY)-(CenterX - Size * 6 / 2, CenterY + Size * 6 / 2), vbBlue
Line (CenterX, CenterY - Size * 6)-(CenterX - Size * 6 / 2, CenterY + Size * 6 / 2 - Size * 6), vbBlue
Line (CenterX + 1, CenterY - 1)-(CenterX + Size * 6 - 1, CenterY - Size * 6 + 1), RGB(0, 60, 0), BF
For i = 1 To Size * 6 / 2 - 1
Line (CenterX - i + 1, CenterY + i)-(CenterX - i + Size * 6, CenterY + i), RGB(0, 60 + i * 2, 0)
Next

For i = 0 To Size * 6 / 2 - 1
Line (CenterX - i - 1, CenterY + i)-(CenterX - i - 1, CenterY + i - Size * 6 + 1), RGB(0, 60 + i * 2, 0)
Next
Label1.Caption = "X : " & CurX & vbCrLf & "Y : " & CurY & vbCrLf & "Z : " & CurZ & vbCrLf
X = CurX: y = CurY: Z = CurZ
col = 10 + Z * 20
xs = (CenterX + X * Size) - Z * (Size / 2)
Ys = CenterY + Z * (Size / 2)
For i = 0 To Size / 2
Line (xs - i, Ys + i)-(xs - i + Size, Ys + i), vbBlack
Next
Ys = (CenterY - y * Size) + Z * (Size / 2)
Line (xs - Size / 2 + 1, Ys + Size / 2 - 1)-(xs + Size / 2 - 1, Ys - Size / 2 + 1), RGB(col + 120, 0, 0), BF
Line (xs + 1, Ys - 1)-(xs + Size - 1, Ys - Size + 1), RGB(col, 0, 0), BF
For i = 0 To Size / 2
Line (xs - i, Ys + i)-(xs - i + Size, Ys + i), RGB(col + i * 8, 0, 0)
Line (xs - i, Ys + i)-(xs - i, Ys + i - Size), RGB(col + i * 8, 0, 0)
Line (xs - i + Size, Ys + i)-(xs - i + Size, Ys + i - Size), RGB(col + i * 8, 0, 0)
Next
Line (CenterX - Size * 6 / 2, CenterY + Size * 6 / 2)-(CenterX + Size * 6 / 2, CenterY - Size * 6 / 2), vbBlue, B
Line (CenterX + Size * 6, CenterY)-(CenterX + Size * 6 - Size * 6 / 2, CenterY + Size * 6 / 2), vbBlue
Line (CenterX + Size * 6, CenterY - Size * 6)-(CenterX + Size * 6 - Size * 6 / 2, CenterY + Size * 6 / 2 - Size * 6), vbBlue
End Sub
Private Sub cmdDemo_Click()
Select Case cmdDemo.Caption
Case "开始运动"
Timer1.Enabled = True
cmdDemo.Caption = "结束运动"
Case Else
Timer1.Enabled = False
cmdDemo.Caption = "开始运动"
End Select
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft
If CurX > 0 Then
EraseBlock
CurX = CurX - 1
DrawBlock
End If
Case vbKeyRight
If CurX < 5 Then
EraseBlock
CurX = CurX + 1
DrawBlock
End If
Case vbKeyUp
If Shift = 0 Then
If CurY < 5 Then
EraseBlock
CurY = CurY + 1
DrawBlock
End If
ElseIf Shift = 1 Then
If CurZ > 0 Then
EraseBlock
CurZ = CurZ - 1
DrawBlock
End If
End If
Case vbKeyDown
If Shift = 0 Then
If CurY > 0 Then
EraseBlock
CurY = CurY - 1
DrawBlock
End If
ElseIf Shift = 1 Then
If CurZ < 5 Then
EraseBlock
CurZ = CurZ + 1
DrawBlock
End If
End If
End Select
End Sub
Private Sub Form_Load()
Move 0, 0, Screen.Width, Screen.Height
Show
Label1.Move Picture1.ScaleWidth - Label2.Width, 0
Label2.Move Picture1.ScaleWidth - Label2.Width, Label1.Height * 4
Picture1.Move ScaleWidth - Picture1.Width, 0
CenterX = ScaleWidth / 4
CenterY = ScaleHeight / 1.5
DrawBlock
End Sub
Private Sub Timer1_Timer()
Randomize
d = Int(Rnd * 11)
If d > 5 And MoveTo < 4 Then MoveTo = RandomMove
EraseBlock
Select Case MoveTo
Case MOVE_DOWN
If CurY > 0 Then CurY = CurY - 1 Else: MoveTo = RandomMove
Case MOVE_UP
If CurY < 5 Then CurY = CurY + 1 Else: MoveTo = RandomMove
Case MOVE_RIGHT
If CurX < 5 Then CurX = CurX + 1 Else: MoveTo = RandomMove
Case MOVE_LEFT
If CurX > 0 Then CurX = CurX - 1 Else: MoveTo = RandomMove
Case MOVE_BACKWARD
If CurZ > 0 Then CurZ = CurZ - 1 Else MoveTo = RandomMove
Case MOVE_FORWARD
If CurZ < 5 Then CurZ = CurZ + 1 Else: MoveTo = RandomMove
End Select
DrawBlock
End Sub
Private Function RandomMove() As Integer
Randomize
Dim d As Integer
d = Int(Rnd * 6)
RandomMove = d
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -