12-04-2024, 01:29 AM
(12-02-2024, 03:56 PM)bplus Wrote: https://qb64phoenix.com/forum/showthread...4#pid30124Hi friend
(It's reply #6 if you are dropped to bottom of page on links like I am in this forum.)
If @TempodiBasic can't figure it out then maybe other people could use help too...
Basic setup for playing a game over a very large background. Use arrow keys to move over background in that direction. If you stop, you have gone to edge of background.
Code: (Select All)_Title "Image bigger than screen" ' b+ 2024-12-02
Randomize Timer
Screen _NewImage(800, 600, 32)
_ScreenMove 100, 20
Dim bg&
bgw = 1600 ' double width and height for demo
bgh = 1200
bg& = _NewImage(bgw, bgh, 32)
_Dest bg&
For i = 1 To 80
Line (Rnd * bgw, Rnd * bgh)-Step(Rnd * 100 + 50, Rnd * 75 + 25), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), BF
Next
_Dest 0
d = 0: e = 0
While _KeyDown(27) = 0
Cls
k = _KeyHit
If k = 19200 Then d = -1: e = 0 ' left
If k = 19712 Then d = 1: e = 0 ' right
If k = 18432 Then e = -1: d = 0 ' up
If k = 20480 Then e = 1: d = 0 'down
top = top + e
If top < 0 Then top = 0
If top + _Height > bgh Then top = bgh - _Height
le = le + d
If le < 0 Then le = 0
If le + _Width > bgw Then le = bgw - _Width
_PutImage (0, 0)-(_Width, _Height), bg&, 0, (le, top)-(le + _Width, top + _Height)
_Display
_Limit 120
Wend
Of course you can do this step by step too with the arrow keys.
Code: (Select All)_Title "Step through Image bigger than screen" ' b+ 2024-12-02
Randomize Timer
Screen _NewImage(800, 600, 32)
_ScreenMove 100, 20
Dim bg&
bgw = 1600 ' double area for demo
bgh = 1200
bg& = _NewImage(bgw, bgh, 32)
_Dest bg&
For i = 1 To 80
Line (Rnd * bgw, Rnd * bgh)-Step(Rnd * 100 + 50, Rnd * 75 + 25), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), BF
Next
_Dest 0
stepper = 5 ' <<< set step size here!!!
While _KeyDown(27) = 0
Cls
k = _KeyHit
If k = 19200 Then ' left
If le - stepper >= 0 Then le = le - stepper
End If
If k = 19712 Then ' right
If le + stepper <= bgw - _Width - 1 Then le = le + stepper
End If
If k = 18432 Then ' up
If top - stepper >= 0 Then top = top - stepper
End If
If k = 20480 Then 'down
If top + stepper <= bgh - _Height - 1 Then top = top + stepper
End If
_PutImage (0, 0)-(_Width, _Height), bg&, 0, (le, top)-(le + _Width, top + _Height)
_Display
_Limit 120
Wend
I miss what is moving on the background so I add an Hero that stands on the bottom of the screen and runs left-right and down-up.
Here my MOD to your code
Code: (Select All)
_Title "Step through Image bigger than screen with HERO" ' b+ 2024-12-02 / TdB 2024-12-04
Randomize Timer
Screen _NewImage(800, 600, 32)
_ScreenMove 100, 20
Dim bg&
bgw = 1600 ' double area for demo
bgh = 1200
bg& = _NewImage(bgw, bgh, 32)
_Dest bg&
For i = 1 To 80
Line (Rnd * bgw, Rnd * bgh)-Step(Rnd * 100 + 50, Rnd * 75 + 25), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), BF
Next
_Dest 0
stepper = 5 ' <<< set step size here!!!
m = 1
While _KeyDown(27) = 0
Cls
k = _KeyHit
If k = 19200 Then ' left
If le - stepper >= 0 Then le = le - stepper
End If
If k = 19712 Then ' right
If le + stepper <= bgw - _Width - 1 Then le = le + stepper
End If
If k = 18432 Then ' up
If top - stepper >= 0 Then top = top - stepper
End If
If k = 20480 Then 'down
If top + stepper <= bgh - _Height - 1 Then top = top + stepper
End If
_PutImage (0, 0)-(_Width, _Height), bg&, 0, (le, top)-(le + _Width, top + _Height)
m = m * -1
MakeHero le, top + _Height - 60, m
_Display
_Limit 120
Wend
Sub MakeHero (X As Integer, Y As Integer, status As Integer)
If X > _Width - 40 Then X = _Width - 40
If Y > _Height - 60 Then Y = _Height - 60
Line (X + 20, Y)-(X, Y + 40), _RGBA32(127, 60, 227, 255)
Line (X + 20, Y)-(X + 40, Y + 40), _RGBA32(127, 60, 227, 255)
Line (X, Y + 40)-(X + 40, Y + 40), _RGBA32(127, 60, 227, 255)
Paint (X + 20, Y + 20), _RGBA32(127, 60, 227, 255), _RGBA32(127, 60, 227, 255)
Circle (X + 10, Y + 30), 5, _RGBA32(255, 6, 6, 255)
Circle (X + 30, Y + 30), 5, _RGBA32(255, 6, 6, 255)
If status = 1 Then
Line (X + 15, Y + 40)-(X + 20, Y + 60), _RGBA(127, 60, 227, 255), BF
Line (X + 30, Y + 40)-(X + 35, Y + 60), _RGBA(127, 60, 227, 255), BF
ElseIf status = -1 Then
Line (X + 10, Y + 40)-(X + 15, Y + 60), _RGBA(127, 60, 227, 255), BF
Line (X + 25, Y + 40)-(X + 30, Y + 60), _RGBA(127, 60, 227, 255), BF
End If
End Sub
I hope you like it!