|
こんばんわ、またしてもお世話になります。
以下のシューティングゲームを作成途中なのですが、左右に実機を動かしながら連発で弾丸を発射していると途中、描画が残ってしまいます。
Excelの限界なのか、、それともコードに不備があるのか、、
分かりません。
どなたか、回答いただけると助かります。
Option Explicit
Declare Function GetAsyncKeyState Lib "User32.dll" (ByVal vKey As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function GetTickCount Lib "kernel32" () As Long 'Windows起動後経過時間取得API
'音声再生用API宣言
Public Declare Function mciSendString Lib "Winmm.dll" Alias "mciSendStringA" _
(ByVal lpMciComm As String, ByVal lpMciRetString As String, _
ByVal lpRetLength As Long, ByVal CallBackhWnd As Long) As Long
Sub シューティングゲーム()
'自機の設定
Dim ViewF As Range
Set ViewF = Range("B2:L12")
Dim ViewD As Variant
Set ViewD = ViewF
Dim Jiki As String
Jiki = "凸"
Dim JikiX As Long
JikiX = 1
Dim JikiY As Long
JikiY = 11
ViewD(JikiY, JikiX) = Jiki
'弾丸の設定
Dim Tama As String
Tama = "^"
Dim j As Integer
Dim k As Integer
Dim i(11, 10) As Integer
For j = 1 To 11
For k = 1 To 10
i(j, k) = 1
Next k
Next j
'ゲーム継続時間
Dim StartTime As Long
StartTime = GetTickCount
Dim WaitTime As Long
WaitTime = Cells(1, 1) * 1000
'ゲーム間隔時間
Dim StartLoop As Long
'ゲーム終了フラグ
Dim GameFlag As Boolean
Do
Sheet12.CommandButton1.Activate
StartLoop = GetTickCount
Do While GetTickCount - StartLoop < 50
Sleep 50
Loop
If GetTickCount - StartTime > WaitTime Then
GameFlag = True
End If
'自機を動かす
If GetAsyncKeyState(39) <> 0 And JikiX < 11 Then '→入力判定
ViewD(JikiY, JikiX).Value = ""
JikiX = JikiX + 1
ViewD(JikiY, JikiX).Value = Jiki
ElseIf GetAsyncKeyState(37) <> 0 And JikiX > 1 Then '←入力判定
ViewD(JikiY, JikiX).Value = ""
JikiX = JikiX - 1
ViewD(JikiY, JikiX).Value = Jiki
End If
'弾丸を打つ
For j = 1 To 11
For k = 1 To 10
If ViewD(1, j).Value = Tama Then
ViewD(1, j).Value = ""
i(j, k) = 1
End If
If ViewD(JikiY - i(j, k), j).Value = Tama Then
ViewD(JikiY - i(j, k), j).Value = ""
i(j, k) = i(j, k) + 1
ViewD(Application.MAX(JikiY - i(j, k), 1), j).Value = Tama
End If
Next k
Next j
If GetAsyncKeyState(32) <> 0 Then
ViewD(JikiY - 1, JikiX).Value = Tama
End If
ViewF.Value = ViewD.Value
DoEvents
Loop While GameFlag = False
'最後に弾を消す
ViewF = ""
JikiX = 1
ViewF(JikiY, JikiX).Value = Jiki
End Sub
|
|