'************************************************************
'文書1シューティング Ver1.00
' 2004/6/12 By N.Chikada
'http://www1.plala.or.jp/chikada/
'************************************************************
Option Explicit
Declare Function GetTickCount Lib "kernel32" () As Long 'Windows起動後経過時間取得API
Declare Function GetAsyncKeyState Lib "User32.dll" (ByVal vKey As Integer) As Long
Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Const VK_LEFT As Long = &H25
Const VK_RIGHT As Long = &H27
Const VK_Z As Long = &H90
Sub GameStart()
Dim i As Integer
Dim Score As Long
Dim z(1 To 3, 1 To 2) As Integer '座標収納用(1:自機2:ミサイル3:敵、1:行2:列)
Dim h As Integer '敵の進行方向(1:右,-1:左,)
h = 1
z(1, 1) = 10 '自機行
z(1, 2) = 1 '自機列
z(2, 1) = 0 '弾行
z(2, 2) = 0 '弾列
z(3, 1) = 0 '敵行
z(3, 2) = 2 '敵列
Dim GameF As Boolean 'ゲーム進行フラグ
GameF = True
Dim StartTime(0 To 2) As Long '0:ゲーム開始、1:ループ開始、3:当たり表示
'全選択消去
Selection.HomeKey Unit:=wdStory
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
'半角スペース20文字×10行敷き詰め
For i = 1 To 10
Selection.TypeText Text:=" "
Selection.TypeParagraph '改行
Next i
Selection.TypeText Text:="文書1シューティングVer1.00 By N.Chikada"
Selection.MoveRight Unit:=wdCharacter, Count:=30, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.Font.Color = wdColorBlue
Selection.TypeText Text:=" Http://www1.plala.or.jp/chikada/"
Selection.MoveLeft Unit:=wdCharacter, Count:=32, Extend:=wdExtend
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
"http://www1.plala.or.jp/chikada/", SubAddress:=""
Selection.TypeParagraph '改行
Selection.TypeText Text:="ゲーム開始はメニューバーのツール>マクロ>マクロ>GameStartを選択>実行"
Selection.TypeParagraph '改行
Selection.TypeText Text:="※マクロ無効の場合は、ツール>マクロ>セキュリティを中に設定すると実行できます。"
Selection.TypeParagraph '改行
Selection.TypeText Text:="左右キーで自機凸を移動、「只」を狙ってShiftキーでミサイル発射。"
Selection.TypeParagraph '改行
Selection.TypeText Text:="30 秒間の命中回数を競う本格派シューティングゲームです。"
Selection.TypeParagraph '改行
Selection.WholeStory
Selection.Font.Name = "MS ゴシック"
'敵、自機の配置
Selection.HomeKey Unit:=wdStory
'Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="只"
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=10
Selection.TypeText Text:="凸"
Selection.TypeParagraph '改行
StartTime(0) = GetTickCount
'メインループ開始
Do While GameF
StartTime(1) = GetTickCount
' 自機の移動判定、自機表示
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=10
If GetAsyncKeyState(VK_LEFT) <> 0 Then
If z(1, 2) > 1 Then
z(1, 2) = z(1, 2) - 1
Selection.Delete Unit:=wdCharacter, Count:=1
End If
ElseIf GetAsyncKeyState(VK_RIGHT) <> 0 Then
If z(1, 2) < 30 Then
z(1, 2) = z(1, 2) + 1
Selection.TypeText Text:=" "
End If
End If
' ミサイル発射・移動判定、表示
If z(2, 1) = -1 Then '非出現
If GetAsyncKeyState(16) <> 0 Then
z(2, 2) = z(1, 2)
z(2, 1) = 9
End If
ElseIf z(2, 1) > 0 Then '上端か移動中
'直前の弾を消去
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=z(2, 1)
Selection.MoveRight Unit:=wdCharacter, Count:=z(2, 2)
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=" "
z(2, 1) = z(2, 1) - 1
Else
z(2, 1) = -1
End If
'弾の表示
If z(2, 1) > 0 Then
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=z(2, 1)
Selection.MoveRight Unit:=wdCharacter, Count:=z(2, 2)
Selection.TypeText Text:="*"
End If
' 敵移動判定、表示
'折り返しの判定
Select Case z(3, 2)
Case 1
h = 1
'z(3, 1) = z(3, 1) + 1
Case 30
h = -1
'z(3, 1) = z(3, 1) + 1
End Select
z(3, 2) = z(3, 2) + h
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=z(3, 1) - 1
If h = -1 Then
Selection.Delete Unit:=wdCharacter, Count:=1
ElseIf h = 1 Then
Selection.TypeText Text:=" "
End If
' 当たり判定、スコア表示
If z(2, 1) = z(3, 1) And z(2, 2) = z(3, 2) Then
Score = Score + 1
StartTime(2) = GetTickCount
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=5
Selection.MoveRight Unit:=wdCharacter, Count:=13
Selection.TypeText Text:="HIT!"
Selection.HomeKey Unit:=wdStory
Do Until GetTickCount - StartTime(2) > 500
Loop
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=5
Selection.MoveRight Unit:=wdCharacter, Count:=13
Selection.Delete Unit:=wdCharacter, Count:=4
End If
'同期Wait
Do While GetTickCount - StartTime(1) < 50
' ゲーム終了判定
If GetTickCount - StartTime(0) > 30000 Then
GameF = False
Exit Do
End If
Loop
If GetAsyncKeyState(VK_Z) <> 0 Then
GameF = False
End If
'メインループ終了 (繰り返し)
Loop
'ゲーム終了処理
MsgBox Score & "発命中"
End Sub
|