キャッチゲームの制作 VB6
 (6) リンゴの落下 前へ 目次へ 次へ 

 リンゴ落下(移動)についてもタイマー(Timer1)で処理する。
 50(m秒)ごとに、「表示されているリンゴ」についてだけy座標(Top)にSpeedの値を加算していく。そして、地面(ウィンドウの最下部)に到達したときに非表示にする。

・プログラムリスト青色部分(リンゴ発生の後に追加)

Private Sub Timer1_Timer()
    Dim n As Integer

    'Apple発生
    If Ransuu(1, 20) = 1 Then   '20回に1度リンゴを発生
        For n = 1 To MaxApple
            If imgApple(n).Visible = False Then   '非表示のリンゴを探す
                With imgApple(n)
                    .Left = Ransuu(0, Form1.ScaleWidth - imgApple(n).Width)  'X座標
                    .Top = 0                                                 'Y座標
                    .Visible = True    'リンゴ表示
                End With
                Speed(n) = Ransuu(5, 8) * 10   'スピードの決定(50,60,70,80)
                Exit For
            End If
        Next n
    End If
    'Apple移動等
    For n = 1 To MaxApple
        If imgApple(n).Visible = True Then    '表示のリンゴだけ
            'Apple移動
            imgApple(n).Top = imgApple(n).Top + Speed(n)
            imgApple(n).Move imgApple(n).Left, imgApple(n).Top  '移動
            'Apple地面に到達
            If imgApple(n).Top > Form1.ScaleHeight Then
                imgApple(n).Visible = False    'リンゴ非表示
            End If
        End If
    Next n
End Sub

 実行するとリンゴがウィンドウ上部に表示され、下に向かって移動する。ウィンドウの下部まで到達したリンゴは消える(非表示)。


 (6) リンゴの落下 前へ 目次へ 次へ 
Copyright © 2001,2002 Hiroshi Masuda 

 

 

inserted by FC2 system