Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a little tutorial STEP by STEP on scrolling in 2D graphic mode
#3
Hi Bplus
yes the tecnique to use a BIG scenario and a LITTLER camera that shows only a piece of the scenario on the screen is very smart and useful.
Just like the code written by Fellippe in that game online via TCP/IP.  A clone of Among Us.
I remember C&C and AOE as famous prototypes. Very smart also the use of the fog to not discover all the map in a look.
Here a oltragious example

Code: (Select All)

Rem demonstration of scrolling of a camera (little view) on a scenario (Total view)

' global variables
Dim Scenario As Long, Camera As Long
Dim d As Integer, x As Integer, y As Integer, Sw As Integer, Sh As Integer, Cw As Integer, Ch As Integer
Dim k As String
' initialization
Sw = 1200
Sh = 800
Cw = 200
Ch = 200
x = 1
y = 1
k = ""
Randomize Timer
Scenario = _NewImage(Sw, Sh, 32)
Camera = _NewImage(Cw, Ch, 32)
Screen Camera
_FullScreen
_Title "A demonstration of scrolling of a camera on a scenario"

' creating the scenario
_Dest Scenario
For a = 1 To 100
    Line (Rnd * Sw, Rnd * Sh)-(Rnd * Sw, Rnd * Sh), _RGBA32(Rnd * 255, Rnd * 255, Rnd * 255, 255), B
Next a
_Dest Scr

While k <> "Q"

    k = UCase$(InKey$)
    If k = "W" Then y = y - 1
    If k = "S" Then y = y + 1
    If k = "A" Then x = x - 1
    If k = "D" Then x = x + 1

    If x < 1 Then x = 1
    If x > (Sw - Cw) Then x = Sw - Cw
    If y < 1 Then y = 1
    If y > (Sh - Ch) Then y = Sh - Ch
    Cls
    _PutImage (1, 1), Scenario, Camera, (x, y)-(Cw + x, Ch + y)
    _PrintString (1, 1), "Use WASD to move camera"
    _PrintString (1, 180), "Q to quit"
    _Display

Wend
End
The tecnique showed in this tutorial is for background like dino run,  moon racer, car racing game, or infinite pacman labyrinth or infinite frogger. Over this image of background it must be painted the hero, the obstacles, the enemies etc etc all objects variable for position, for movement and dimensions.
But that is another tutorial.
Reply


Messages In This Thread
RE: a little tutorial STEP by STEP on scrolling in 2D graphic mode - by TempodiBasic - 12-01-2024, 08:00 PM



Users browsing this thread: 14 Guest(s)