N.I.の雑談室

ゲーム作成グループ(現在一人)N.I.のきままなブログですhttps://bluewindgrayash.web.fc2.com/(BLUEWIND_GRAYASHホームページ)には色々置いています。

以前書いたVBのはなし。

お久しぶりです。

以前、VB6.0のときに書いたプログラムです。

VBというと、コンストラクト的なところが強い気もして、初心者向きなイメージが強いです。これになれると、excelでマクロを組んだりもできます。

 

VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   4395
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6285
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   ScaleHeight     =   4395
   ScaleWidth      =   6285
   StartUpPosition =   3  'Windows の既定値
   Begin VB.Image Image2 
      Height          =   960
      Left            =   2760
      Picture         =   "Form1.frx":0000
      Top             =   1800
      Width           =   480
   End
   Begin VB.Image Image1 
      Height          =   7200
      Left            =   0
      Picture         =   "Form1.frx":1842
      Top             =   -240
      Width           =   9600
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()

MsgBox "Esc終了"
    
a = 10000
Image2.Move (Image2.Left), (Image2.Top)
Form1.Show
    
Do
    
If a >= 10000 Then
    
If GetAsyncKeyState(vbKeyLeft) Then
Image2.Left = Image2.Left - 50
Image2.Move (Image2.Left), (Image2.Top)
a = 0

ElseIf GetAsyncKeyState(vbKeyRight) Then
Image2.Left = Image2.Left + 50
Image2.Move (Image2.Left), (Image2.Top)
a = 0


ElseIf GetAsyncKeyState(vbKeyUp) Then
Image2.Top = Image2.Top - 50
Image2.Move (Image2.Left), (Image2.Top)
a = 0

ElseIf GetAsyncKeyState(vbKeyDown) Then
Image2.Top = Image2.Top + 50
Image2.Move (Image2.Left), (Image2.Top)
a = 0


ElseIf GetAsyncKeyState(vbKeyEscape) Then

Call Unload(Me)

Exit Do

End If


End If

Form1.Show
Do

a = a + 1

If a >= 10000 Then

Exit Do

End If

Loop


Loop

End Sub

-----------------------------------------------------------

VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   4395
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6285
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   ScaleHeight     =   4395
   ScaleWidth      =   6285
   StartUpPosition =   3  'Windows の既定値
   Begin VB.Image Image2 
      Height          =   960
      Left            =   2760
      Picture         =   "Form1.frx":0000
      Top             =   1800
      Width           =   480
   End
   Begin VB.Image Image1 
      Height          =   7200
      Left            =   0
      Picture         =   "Form1.frx":1842
      Top             =   -240
      Width           =   9600
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()

----------------------------------------------------------------------

・この部分はコンストラクションの部分にあたります。

 

・GetAsyncKeyStateのあたりは、キーボードを取得するモジュールをつかい、その付近の何ドット移動するか、というプログラムだけを書き込めば、画像を十字キーで動かすことができるということです。

 

------------------------------------------------------

If GetAsyncKeyState(vbKeyLeft) Then
Image2.Left = Image2.Left - 50
Image2.Move (Image2.Left), (Image2.Top)
a = 0

ElseIf GetAsyncKeyState(vbKeyRight) Then
Image2.Left = Image2.Left + 50
Image2.Move (Image2.Left), (Image2.Top)
a = 0


ElseIf GetAsyncKeyState(vbKeyUp) Then
Image2.Top = Image2.Top - 50
Image2.Move (Image2.Left), (Image2.Top)
a = 0

ElseIf GetAsyncKeyState(vbKeyDown) Then
Image2.Top = Image2.Top + 50
Image2.Move (Image2.Left), (Image2.Top)
a = 0

---------------------------------------------

・この部分が実際に画像を動かす部分。vbkeydownが下入力、Topが画像の縦位置(?)で、+50すると下を押したときに50ドット下へ画像がずれる。重要なのはモジュールを組み込むことです。入力関係のモジュールを入れれば、GetAsyncKeyStateが使えます。

 

画像もVBで用意したものをピクチャボックスなどとして確か表示できます。ここも重要です。

 

vbvisual studioを使えば難なくできますが、少し慣れるまで触る必要はあります。vb無くなるとのうわさもありますが、どうなんでしょうね。

 

サンプルファイルはホームページに置いてあるので、ビルドして実行してみてください。多分できる...はず。参照urlからもダウンロードページに飛べます。

 

ああ、VC++をもう少し学びたい、VBも良いのですが、個人的にVC好きです。

 

以上。

 

参照url

bluewindgrayash.web.fc2.com

www.mediafire.com