Tuesday, 25 August 2015

VB.NET :: source code game mantul-mantul dengan vb.net

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Font
Imports System.Drawing.FontFamily
Public Class Form1
    Dim x, y, xe, ye As Integer
    Dim arahx, arahy As Integer
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        x = -100
        y = -100
        xe = 50
        ye = 50
        arahx = 1
        arahy = 1
        ‘Timer1.Start()
    End Sub
    Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
        Dim g As Graphics = e.Graphics
        If ComboBox1.SelectedIndex = 0 Then
            g.DrawRectangle(Pens.Aqua, x, y, 100, 50)
        Else
            g.DrawEllipse(Pens.Aqua, x, y, 100, 50)
        End If
        Dim a() As Point = {New Point(x, y), New Point(x + 50, y + 100), New Point(x + 100, y), New Point(x, y)}
        g.DrawLines(Pens.Red, a)
        Dim gp As GraphicsPath = New GraphicsPath(FillMode.Alternate)
        gp.AddLines(a)
        g.FillPath(Brushes.Blue, gp)
        g.DrawEllipse(Pens.Aqua, xe, ye, 50, 50)
    End Sub
    Private Sub Panel1_MouseClick(sender As Object, e As MouseEventArgs) Handles Panel1.MouseClick
        x = e.X
        y = e.Y
        Panel1.Refresh()
    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        xe += arahx
        ye += arahy
        If xe + 50 > Panel1.Width Then
            arahx *= -1
        End If
        If ye + 50 > Panel1.Height Then
            arahy *= -1
        End If
        If ye < 0 Then
            arahy *= -1
        End If
        If xe < 0 Then
            arahx *= -1
        End If
        Panel1.Refresh()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Timer1.Start()
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Timer1.Stop()
    End Sub
End Class



No comments:

Post a Comment