Here is quick demo for making background, making a sprite, sprite move with _Putimage, and sprite scale and tilt while moving with RotoZoom
Code: (Select All)
Screen _NewImage(600, 350, 32)
' =========================================== make background snapshot
Color , _RGB32(30, 30, 60)
snapBack& = _NewImage(_Width, _Height, 32)
Cls
DrawTerrain 100, 25, &HFF332211
DrawTerrain 150, 20, &HFF443322
DrawTerrain 200, 15, &HFF554433
DrawTerrain 250, 10, &HFF665544
DrawTerrain 300, 5, &HFF776655
_PutImage , 0, snapBack&
'check it
Cls
_PutImage , snapBack&, 0
Print "Press any for sprite drawn in middle of screen..."
Sleep
' ========================================== make a spaceship sprite
ship& = _NewImage(61, 31, 32) ' ship is 60 x 30 drawn in top left hand corner
' need black backgrounf for ship
Color , &HFF000000 '= balck background
Cls
drawShip 30, 15, &HFF00FF88
_PutImage , 0, ship&, (0, 0)-(61, 31) ' <<<< upper left corner of screen!!!
' make the background black of ship transparent
_ClearColor &HFF000000, ship&
'now check our ship by putting it into middle of screen
Cls 'still black
x = _Width / 2 - 30: y = _Height / 2 - 15 ' x, y upper left corner so center of image at center of screen
_PutImage (x, y), ship&, 0 ' ship to screen destiation (x, y)
Print " Press any to see sprint move across background"
Sleep
' move sprite over landscape
sx = 0 'from left edge to right and back
dx = 5
Do
sx = sx + dx
If sx > _Width - 60 Then
sx = _Width - 60: dx = -dx
ElseIf sx < 0 Then
sx = 0: dx = -dx
End If
_PutImage , snapBack&, 0 ' back to screen
_PutImage (sx, 175), ship&, 0 ' ship to screen at destination x, y
Locate 1, 1
Print "Press enter to see Rotozoom scale and tilt sprite..."
_Display 'no flicker
_Limit 20 ' max 20 loops a second
Loop Until _KeyDown(13)
sx = 0 'from left edge to right and back
tilt = 45: scale = 1.2
dx = 5
Do
sx = sx + dx
If sx > _Width - 60 Then
sx = _Width - 60: dx = -dx
scale = 2: tilt = 135
ElseIf sx < 0 Then
sx = 0: dx = -dx
scale = 1.2: tilt = 45
End If
_PutImage , snapBack&, 0 ' back to screen
'rotozoom workes from image center
RotoZoom sx + 30, 175 + 15, ship&, scale, tilt ' ship to screen at destination x, y
Locate 1, 1
Print "Press escape to quit..."
_Display 'no flicker
_Limit 20 ' max 20 loops a second
Loop Until _KeyDown(27)
Sub drawShip (x, y, colr As _Unsigned Long) 'shipType collisions same as circle x, y radius = 30
Static ls
Dim light As Long, r As Long, g As Long, b As Long
r = _Red32(colr): g = _Green32(colr): b = _Blue32(colr)
fellipse x, y, 6, 15, _RGB32(r, g - 120, b - 100)
fellipse x, y, 18, 11, _RGB32(r, g - 60, b - 50)
fellipse x, y, 30, 7, _RGB32(r, g, b)
For light = 0 To 5
fcirc x - 30 + 11 * light + ls, y, 1, _RGB32(ls * 50, ls * 50, ls * 50)
Next
ls = ls + 1
If ls > 5 Then ls = 0
End Sub
' ======== helper subs for drawShip that you can use for other things specially fcirc = fill_circle x, y, radius, color
Sub fellipse (CX As Long, CY As Long, xr As Long, yr As Long, C As _Unsigned Long)
If xr = 0 Or yr = 0 Then Exit Sub
Dim h2 As _Integer64, w2 As _Integer64, h2w2 As _Integer64
Dim x As Long, y As Long
w2 = xr * xr: h2 = yr * yr: h2w2 = h2 * w2
Line (CX - xr, CY)-(CX + xr, CY), C, BF
Do While y < yr
y = y + 1
x = Sqr((h2w2 - y * y * w2) \ h2)
Line (CX - x, CY + y)-(CX + x, CY + y), C, BF
Line (CX - x, CY - y)-(CX + x, CY - y), C, BF
Loop
End Sub
Sub fcirc (x As Long, y As Long, R As Long, C As _Unsigned Long) 'vince version fill circle x, y, radius, color
Dim x0 As Long, y0 As Long, e As Long
x0 = R: y0 = 0: e = 0
Do While y0 < x0
If e <= 0 Then
y0 = y0 + 1
Line (x - x0, y + y0)-(x + x0, y + y0), C, BF
Line (x - x0, y - y0)-(x + x0, y - y0), C, BF
e = e + 2 * y0
Else
Line (x - y0, y - x0)-(x + y0, y - x0), C, BF
Line (x - y0, y + x0)-(x + y0, y + x0), C, BF
x0 = x0 - 1: e = e - 2 * x0
End If
Loop
Line (x - R, y)-(x + R, y), C, BF
End Sub
Sub DrawTerrain (h, modN, c As _Unsigned Long) ' modN for ruggedness the higher the less smooth
For x = 0 To _Width
If x Mod modN = 0 Then ' adjust mod number for ruggedness the higher the number the more jagged
If h < 350 - modN And h > 50 + modN Then
dy = Rnd * 20 - 10
ElseIf h >= 350 - modN Then
dy = Rnd * -10
ElseIf h <= 50 + modN Then
dy = Rnd * 10
End If
End If
h = h + .1 * dy
Line (x, _Height)-(x, h), c
Next
End Sub
Sub RotoZoom (X As Long, Y As Long, Image As Long, Scale As Single, degreesRotation As Single)
Dim px(3) As Single, py(3) As Single, W&, H&, sinr!, cosr!, i&, x2&, y2&
W& = _Width(Image&): H& = _Height(Image&)
px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
sinr! = Sin(-degreesRotation / 57.2957795131): cosr! = Cos(-degreesRotation / 57.2957795131)
For i& = 0 To 3
x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
px(i&) = x2&: py(i&) = y2&
Next
_MapTriangle (0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
_MapTriangle (0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
End Sub
b = b + ...