Мяч в vba
Формулировка задачи:
Изобразить движение футбольного мяча после удара (задается начальное положение мяча и вектор скорости). В процессе полёта мяч ударяется о пол, потолок и стены,стены поле есть,но не пойму как сделать(
Решение задачи: «Мяч в vba»
textual
Листинг программы
Option Explicit Private Type Vector Dx As Single Dy As Single End Type Dim Vec As Vector, Pos As Vector Dim Fri As Single, Loss As Single, Rad As Single Dim Bf As Boolean Private Sub Form_Load() Rad = 20: Loss = 1.2: Fri = 1.01 Pos.Dx = Me.ScaleWidth / 2 Pos.Dy = Me.ScaleHeight / 2 End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim Dx As Single, Dy As Single, R As Single Dx = X - Pos.Dx: Dy = Y - Pos.Dy R = Sqr(Dx * Dx + Dy * Dy) If R < Rad Then Bf = True End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim Dx As Single, Dy As Single If Not Bf Then Exit Sub Dx = X - Pos.Dx: Dy = Y - Pos.Dy Vec.Dx = -Dx: Vec.Dy = -Dy End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Bf = False End Sub Private Sub LossVec() If Vec.Dx Then Vec.Dx = Vec.Dx / Loss If Vec.Dy Then Vec.Dy = Vec.Dy / Loss End Sub Private Sub tmrTimer_Timer() Me.Cls If Bf Then Me.Circle (Pos.Dx, Pos.Dy), Rad, vbRed Me.Line (Pos.Dx, Pos.Dy)-Step(-Vec.Dx, -Vec.Dy), vbGreen Else Vec.Dx = Vec.Dx / Fri: Vec.Dy = Vec.Dy / Fri Pos.Dx = Pos.Dx + Vec.Dx Pos.Dy = Pos.Dy + Vec.Dy If Pos.Dx > Me.ScaleWidth - Rad Then Pos.Dx = Me.ScaleWidth - Rad: Vec.Dx = -Vec.Dx: LossVec If Pos.Dx < Rad Then Pos.Dx = Rad: Vec.Dx = -Vec.Dx: LossVec If Pos.Dy > Me.ScaleHeight - Rad Then Pos.Dy = Me.ScaleHeight - Rad: Vec.Dy = -Vec.Dy: LossVec If Pos.Dy < Rad Then Pos.Dy = Rad: Vec.Dy = -Vec.Dy: LossVec Me.Circle (Pos.Dx, Pos.Dy), Rad End If Me.Refresh End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д