Exploding and Fading an area of the screen - TempodiBasic - 08-04-2022
Hi friends
following the thread of Steve about a logic bug on what a coder was waiting for getting an effect and the transparent quality that masking what the code does....
here an evolution of the explosion code posted by Steve
beyond the added differences for getting fading effects and vertical or horizontal explosion
the main difference is using an incremental speed of movement got by calculating speed at each loop
Code: (Select All) Const Classic = 0, MoveUpLeft = 1, MoveUpRight = 2, MoveDownLeft = 3, MoveDownRight = 4, Horizontal = 5, Vertical = 6
Screen _NewImage(1280, 720, 32)
$Color:32
Dim Shared f As Long
f = _LoadFont("courbd.ttf", 128, "monospace")
testExplosion Red, Green, White, Classic
testExplosion Blue, Yellow, Cyan, MoveUpLeft
testExplosion Brown, Green, Black, MoveUpRight
testExplosion Red, Brown, Green, MoveDownRight
testExplosion White, Red, Yellow, MoveDownLeft
testExplosion Blue, Brown, Cyan, Horizontal
testExplosion Red, Blue, Violet, Vertical
_Font 8
Print "FINISHED!!"
End
Sub testExplosion (ForeC, BackC, LineC, ModeE)
_Font f
Color ForeC, BackC
Cls , 0
_PrintString (284, 200), "Steve is"
_PrintString (284, 328), "Awesome!"
Color LineC
Line (283, 199)-(645, 457), , B
Sleep
Explode2 284, 200, 644, 456, 16, 16, ModeE
Sleep 2
End Sub
'Sub Explode (x1, y1, x2, y2, pw, ph)
' tempScreen = _NewImage(_Width, _Height, 32)
' _PutImage , 0, tempScreen
' w = x2 - x1 + 1: h = y2 - y1 + 1
' ax = 2 * w \ pw + 1: ay = 2 * h \ ph + 1
' cx = x1 + w \ 2: cy = y1 + h \ 2
' Type box
' x As Single
' y As Single
' handle As Long
' rotation As Single
' changex As Single
' changey As Single
' End Type
' Dim Array(0 To ax, 0 To ay) As box
' For x = 0 To ax
' For y = 0 To ay
' Array(x, y).handle = _NewImage(pw, ph, 32)
' Array(x, y).x = x1 + pw * x
' Array(x, y).y = y1 + ph * y
' _PutImage , 0, Array(x, y).handle, (x1 + pw * x, y1 + ph * y)-Step(pw, ph)
' Array(x, y).changex = -(cx - Array(x, y).x) / 10
' Array(x, y).changey = -(cy - Array(x, y).y) / 10
' Next
' Next
' Do
' Cls , 0
' finished = -1
' For x = 0 To ax
' For y = 0 To ay
' Array(x, y).x = Array(x, y).x + Array(x, y).changex
' Array(x, y).y = Array(x, y).y + Array(x, y).changey
' If Array(x, y).x >= 0 And Array(x, y).y >= 0 And _
' Array(x, y).x <= _Width And Array(x, y).y <= _Height Then finished = 0
' 'If Array(x, y).x >= 0 And Array(x, y).y >= 0 And Array(x, y).x <= _Width / 4 And Array(x, y).y <= _Height / 2 Then finished = 0 ' Pete solution
' _PutImage (Array(x, y).x, Array(x, y).y)-Step(pw, ph), Array(x, y).handle, 0, (0, 0)-(pw, ph)
' Next
' Next
' _Display
' _Limit 60
' Loop Until finished
' _AutoDisplay
'End Sub
Sub Explode2 (x1, y1, x2, y2, pw, ph, mode)
' this copy screen visible
tempScreen = _NewImage(_Width, _Height, 32)
_PutImage , 0, tempScreen
' this calculates width, height, maxbox-X, maxbox-Y, center of area passed for exploding
w = x2 - x1 + 1: h = y2 - y1 + 1 ' width and height of image
ax = 2 * w \ pw + 1: ay = 2 * h \ ph + 1 'mAX horyzontal blocks and mA(X)Y vertical blocks
cx = x1 + w \ 2: cy = y1 + h \ 2 ' center of image
Type box
x As Single
y As Single
handle As Long
rotation As Single
changex As Single
changey As Single
End Type
Dim Array(0 To ax, 0 To ay) As box ' two dimensional array for blocks of image to explode
' this save each box/block of image into array and with the relative images
For x = 0 To ax
For y = 0 To ay
Array(x, y).handle = _NewImage(pw, ph, 32)
Array(x, y).x = x1 + pw * x
Array(x, y).y = y1 + ph * y
_PutImage , 0, Array(x, y).handle, (x1 + pw * x, y1 + ph * y)-Step(pw, ph)
Next
Next
' this moves block/boxes for getting animation of explosion
Do
Cls , 0
finished = -1
For x = 0 To ax
For y = 0 To ay
If mode = 0 Then
Array(x, y).changex = -(cx - Array(x, y).x) / 10
Array(x, y).changey = -(cy - Array(x, y).y) / 10
ElseIf mode = 1 Then
Array(x, y).changex = -cx / 10
Array(x, y).changey = -cy / 10
ElseIf mode = 2 Then
Array(x, y).changex = cx / 10
Array(x, y).changey = -cy / 10
ElseIf mode = 3 Then
Array(x, y).changex = -cx / 10
Array(x, y).changey = cy / 10
ElseIf mode = 4 Then
Array(x, y).changex = cx / 10
Array(x, y).changey = cy / 10
ElseIf mode = 5 Then
Array(x, y).changex = -(cx - Array(x, y).x) / 10
Array(x, y).changey = 0
ElseIf mode = 6 Then
Array(x, y).changex = 0
Array(x, y).changey = -(cy - Array(x, y).y) / 10
End If
Array(x, y).x = Array(x, y).x + Array(x, y).changex
Array(x, y).y = Array(x, y).y + Array(x, y).changey
If Array(x, y).x >= 0 And Array(x, y).y >= 0 And _
Array(x, y).x <= _Width And Array(x, y).y <= _Height Then finished = 0
_PutImage (Array(x, y).x, Array(x, y).y)-Step(pw, ph), Array(x, y).handle, 0, (0, 0)-(pw, ph)
Next
Next
_Display
_Limit 60
Loop Until finished
_AutoDisplay
End Sub
Waiting your feedbacks
RE: Exploding and Fading an area of the screen - Pete - 08-04-2022
The last ones hangs (doesn't finish).
> testExplosion Red, Blue, Violet, Vertical
The others work as advertised, but a few leave some remnants on the screen.
Pete
RE: Exploding and Fading an area of the screen - TempodiBasic - 08-04-2022
Hi Pete
thanks
yes I'm looking that BLUE is a 0 value (so it appears as BLACK)
the same White, LightWhite, LightBlue...
in the while Vertical exploding has a rectagular box in the middle that gives 0 changeY so I introduce a corrector or Horizontal and Vertical exploding.
So in the future development for parametric sizing of boxes/blocks to move and for speeds calculations it will be adaptable.
More different effect of fading are coming... just the time to code them!
Code: (Select All) Const Classic = 0, MoveUpLeft = 1, MoveUpRight = 2, MoveDownLeft = 3, MoveDownRight = 4, Horizontal = 5, Vertical = 6
Screen _NewImage(1280, 720, 32)
$Color:32
Dim Shared f As Long
f = _LoadFont("courbd.ttf", 128, "monospace")
testExplosion Red, Green, Violet, Classic
testExplosion Violet, Yellow, Cyan, MoveUpLeft
testExplosion Brown, Green, Black, MoveUpRight
testExplosion Gray, Brown, Green, MoveDownRight
testExplosion LightGreen, Red, Yellow, MoveDownLeft
testExplosion Gray, Brown, Cyan, Horizontal
testExplosion Red, Green, Pink, Vertical
_Font 8
Print "FINISHED!!"
End
Sub testExplosion (ForeC, BackC, LineC, ModeE)
Cls , 0
_Font f
Color ForeC, BackC
_PrintString (284, 200), "Steve is"
_PrintString (284, 328), "Awesome!"
Line (283, 199)-(645, 457), LineC, B
Sleep
Explode2 284, 200, 644, 456, 16, 16, ModeE
Sleep 2
End Sub
Sub Explode2 (x1, y1, x2, y2, pw, ph, mode)
' this copy screen visible
tempScreen = _NewImage(_Width, _Height, 32)
_PutImage , 0, tempScreen
' this calculates width, height, maxbox-X, maxbox-Y, center of area passed for exploding
w = x2 - x1 + 1: h = y2 - y1 + 1 ' width and height of image
ax = 2 * w \ pw + 1: ay = 2 * h \ ph + 1 'mAX horyzontal blocks and mA(X)Y vertical blocks
cx = x1 + w \ 2: cy = y1 + h \ 2 ' center of image
Type box
x As Single
y As Single
handle As Long
rotation As Single
changex As Single
changey As Single
End Type
Dim Array(0 To ax, 0 To ay) As box ' two dimensional array for blocks of image to explode
' this save each box/block of image into array and with the relative images
For x = 0 To ax
For y = 0 To ay
Array(x, y).handle = _NewImage(pw, ph, 32)
Array(x, y).x = x1 + pw * x
Array(x, y).y = y1 + ph * y
_PutImage , 0, Array(x, y).handle, (x1 + pw * x, y1 + ph * y)-Step(pw, ph)
Next
Next
' this moves block/boxes for getting animation of explosion
Do
Cls , 0
finished = -1
For x = 0 To ax
For y = 0 To ay
If mode = 0 Then
Array(x, y).changex = -(cx - Array(x, y).x) / 10
Array(x, y).changey = -(cy - Array(x, y).y) / 10
ElseIf mode = 1 Then
Array(x, y).changex = -cx / 10
Array(x, y).changey = -cy / 10
ElseIf mode = 2 Then
Array(x, y).changex = cx / 10
Array(x, y).changey = -cy / 10
ElseIf mode = 3 Then
Array(x, y).changex = -cx / 10
Array(x, y).changey = cy / 10
ElseIf mode = 4 Then
Array(x, y).changex = cx / 10
Array(x, y).changey = cy / 10
ElseIf mode = 5 Then
Array(x, y).changex = -(cx - Array(x, y).x) / 10
If Array(x, y).changex = 0 Then Array(x, y).changex = -10
Array(x, y).changey = 0
ElseIf mode = 6 Then
Array(x, y).changex = 0
Array(x, y).changey = -(cy - Array(x, y).y) / 10
If Array(x, y).changey = 0 Then Array(x, y).changey = -10
End If
Array(x, y).x = Array(x, y).x + Array(x, y).changex
Array(x, y).y = Array(x, y).y + Array(x, y).changey
If Array(x, y).x >= 0 And Array(x, y).y >= 0 And _
Array(x, y).x <= _Width And Array(x, y).y <= _Height Then finished = 0
_PutImage (Array(x, y).x, Array(x, y).y)-Step(pw, ph), Array(x, y).handle, 0, (0, 0)-(pw, ph)
Next
Next
_Display
_Limit 60
Loop Until finished
_AutoDisplay
End Sub
|