'打磚塊--部份完成版
Public Class Form1
'Dim Ball As Image = Image.FromFile("..\..\resources\ball.gif")
Dim Ball As Image = My.Resources.ball
Dim x, y As Integer
Dim dx, dy As Integer
Dim ballsize = 36
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Right Then PBox1.Left = PBox1.Left + 20
If e.KeyCode = Keys.Left Then PBox1.Left = PBox1.Left - 20
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 50
Timer1.Enabled = True
x = 0
dx = 1
y = 10
dy = 1
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If x > Me.Width - ballsize Then dx = -1
If y > 376 - ballsize Then dy = -1
If x < 1 Then dx = 1
If y < 1 Then dy = 1
x = x + 10 * dx
y = y + 10 * dy
Me.Refresh()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = e.Graphics
g.DrawImage(Ball, x, y, ballsize, ballsize)
End Sub
End Class
沒有留言:
張貼留言