- Код: Выделить всё
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Dim Pt(0 To 2) As POINTAPI
Dim Angle As Double
Private Const PI As Double = 3.14159265358979
Private Declare Function PlgBlt Lib "gdi32" (ByVal hdcDest As Long, lpPoint As POINTAPI, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hbmMask As Long, ByVal xMask As Long, ByVal yMask As Long) As Long
Private Sub Slider1_Click()
Angle = Slider1 / 100
Rotate Picture2, Picture1, Angle
End Sub
Private Sub Slider1_Scroll()
Angle = Slider1 / 100
Rotate Picture2, Picture1, Angle
End Sub
Private Sub Rotate(picDest As PictureBox, picsrc As PictureBox, Angle As Double)
Dim a As Integer
Pt(0).x = 0
Pt(0).y = 0
Pt(1).x = picsrc.Width
Pt(1).y = 0
Pt(2).x = 0
Pt(2).y = picsrc.Height
For a = 0 To 2
Pt(a) = RotateP(picsrc.Width / 2, picsrc.Height / 2, Pt(a), Angle)
Next
PlgBlt picDest.hDC, Pt(0), picsrc.hDC, 0, 0, picsrc.Width, picsrc.Height, ByVal 0&, ByVal 0&, ByVal 0&
picDest.Refresh
End Sub
Private Function RotateP(ByRef x As Long, ByRef y As Long, ByRef Point As POINTAPI, Angle As Double) As POINTAPI
Dim Tmp1 As Double
Dim Tmp2 As Double
Tmp1 = Point.x - x
Tmp2 = Point.y - y
Point.x = Tmp1 * Cos(Angle) - Tmp2 * Sin(Angle)
Point.y = Tmp1 * Sin(Angle) + Tmp2 * Cos(Angle)
Point.x = Point.x + x
Point.y = Point.y + y
RotateP = Point
End Function
Пытаюсь написать простенькую плоскую игру: на звездном фоне летает кораблик (желательно бы Image), с помощью клавиш лево-право - поворот коробля, вверх - разгон.
Код этой программы - громоздкий, есть ли альтернативные способы вращение растровой картинки? (Желательно Image)
И еще один вопрос. Как сделать фон имеджевой картинки прозрачным для *.jpg или *.bmp? (у Gif слишком мало цветов)