Map Explorer
#29
Here is another update. This one puts random colors on all the buildings (except the roofs, windows, and doors). I also made the lakes random shapes. Plus now if you run into a building, you are randomly warped a little bit away from the building. B+ I did use the arrayed variables on the houses instead of POINT. So in the future we can make certain houses do certain things, as well as the lakes and cave and anything else we want to add. Oh plus I added in the Title Bar your X and Y coordinates (which are actually player.x and player.y). When you are warped, the Title Bar says to click the mouse to continue. It says it also when you click the mouse to stop. After you click it the notify goes away and you start walking again.  

Code: (Select All)
'Scrolling Map Example by SierraKen - August 10, 2022
'This is a demonstration scrolling map I made to use with games someday.

'Thank you to Felippe, James D. Jarvis, mdijkens, Petr, and B+ for the help and inspiration!

Cls
Print "                       Random Large Map Maker"
Print
Print "                            by SierraKen"
Print: Print
Print
Print "     This is an example to make something with a moving background."
Print "     Use the mouse to move and Esc to quit."
Print "     Press the left mouse button to stop and start moving again."
Print: Print
Print "               Click the Screen With Your Mouse To Start."

Do
    While _MouseInput: Wend
    mouseLeftButton = _MouseButton(1)
    If mouseLeftButton Then
        Clear_MB 1
        GoTo begin:
    End If
Loop

begin:
Randomize Timer
Screen _NewImage(800, 600, 32)

Type object
    x As Single
    y As Single
End Type

Dim Shared player As object
Dim Shared camera As object
Dim Shared map As Long
Dim playerSpeed As Single
Dim housex(30)
Dim housey(30)
Dim housex2(30)
Dim housey2(30)
Dim lx(30)
Dim ly(30)

_Title "Loading....."

start:
player.x = _Width / 2
player.y = _Height / 2

If map <> 0 Then _FreeImage (map)
map = _NewImage(_Width * 5, _Height * 5, 32)

_Dest map

Cls

'--------------------------------------------------------------------------------------
'Graphics Here

'Grass
Line (0, 0)-(4000, 3000), _RGB32(127, 255, 127), BF

'Texture
For texture = 1 To 200000
    tx = Rnd * 4000
    ty = Rnd * 3000
    Circle (tx, ty), 1, _RGB32(155, 166, 127)
Next texture

'Houses
For h = 1 To 30
    again:
    housex(h) = Rnd * 3500
    housey(h) = Rnd * 2500
    For check = 0 To h - 1
        If housex(check) > housex(h) - 150 And housex(check) < housex(h) + 150 And housey(check) > housey(h) - 225 And housey(check) < housey(h) + 225 Then GoTo again:
    Next check
    housex2(h) = (Rnd * 100) + 50
    housey2(h) = (Rnd * 100) + 50
    'House
    Line (housex(h), housey(h))-(housex(h) + housex2(h), housey(h) + housey2(h)), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), BF
    'Roof
    For sz = .25 To (housex2(h) / 2) Step .1
        Circle (housex(h) + (housex2(h) / 2), housey(h)), sz, _RGB32(150, 75, 50), 2 * _Pi, _Pi, 1
    Next sz
    Line (housex(h) + (housex2(h) / 2) - 10, housey(h) + (housey2(h) - 20))-(housex(h) + (housex2(h) / 2) + 10, housey(h) + housey2(h)), _RGB32(128, 116, 128), BF
    'Windows
    For w = 0 To housey2(h) - 45 Step 15
        Line (housex(h) + (housex2(h) / 2) - housex2(h) / 4, housey(h) + (housey2(h) - 35 - w))-(housex(h) + (housex2(h) / 2) - ((housex2(h) / 4) + 10), housey(h) + housey2(h) - 25 - w), _RGB32(128, 116, 128), BF
        Line (housex(h) + (housex2(h) / 2) + housex2(h) / 4, housey(h) + (housey2(h) - 35 - w))-(housex(h) + (housex2(h) / 2) + ((housex2(h) / 4) + 10), housey(h) + housey2(h) - 25 - w), _RGB32(128, 116, 128), BF
    Next w

Next h


'Lakes
For rr = 1 To 30
    again2:
    lx(rr) = Rnd * 4000
    ly(rr) = Rnd * 3000
    For check = 0 To 30
        If housex(check) > lx(rr) - 250 And housex(check) < lx(rr) + 250 And housey(check) > ly(rr) - 250 And housey(check) < ly(rr) + 250 Then GoTo again2:
    Next check
    size = Int(Rnd * 150) + 20
    shape = Rnd + .2
    cl = 50
    For sz = size To .25 Step -.25
        cl = cl + .25
        Circle (lx(rr), ly(rr)), sz, _RGB32(0, 0, cl + 50), , , shape
    Next sz
    cl = 0
Next rr


'Cave
again3:
cavex = Rnd * 3800
cavey = (Rnd * 2200) + 300
If chk = 1 Then GoTo again4:
For check = 0 To 30
    If housex(check) > cavex - 400 And housex(check) < cavex + 400 And housey(check) > cavey - 400 And housey(check) < cavey + 400 Then GoTo again3:
Next check
again4:
For check2 = 0 To 30
    If lx(check2) > cavex - 450 And lx(check2) < cavex + 450 And ly(check2) > cavey - 450 And ly(check2) < cavey + 450 Then chk = 1: GoTo again3:
Next check2
chk = 0
For sz = 1 To 100 Step .25
    cl = cl + .25
    Circle (cavex, cavey), sz, _RGB32(220 - cl, 100 - cl, 100 - cl), 2 * _Pi, _Pi, 1
Next sz
cl = 0
For sz = 1 To 30 Step .25
    Circle (cavex, cavey), sz, _RGB32(0, 0, 0), 2 * _Pi, _Pi, 1
Next sz


_Dest 0

_Source map

playerSpeed = 6

Const ESC = 27

_Title "Map Explorer - by SierraKen"

_Dest 0
_Source map

t = 1
Do
    Cls

    _PutImage (camera.x, camera.y), map

    While _MouseInput: Wend
    mousex = _MouseX
    mousey = _MouseY
    mouseLeftButton = _MouseButton(1)

    If mouseLeftButton Then
        Clear_MB 1
        st = st + 1
        If st > 1 Then st = 0
    End If

    dy = 0
    dx = 0
    If mousey < player.y + camera.y - 5 Then dy = -1
    If mousey > player.y + camera.y + 5 Then dy = 1
    If mousex < player.x + camera.x - 5 Then dx = -1
    If mousex > player.x + camera.x + 5 Then dx = 1

    For ch = 1 To 30
        If player.x > housex(ch) And player.x < housex(ch) + housex2(ch) And player.y > housey(ch) - (housex2(ch) / 2) And player.y < housey(ch) + housey2(ch) Then
            location:
            player.x = (player.x) + (Rnd * 150)
            player.y = (player.y) + (Rnd * 150)
            st = 1
            For check = 0 To 30
                If housex(check) > player.x - 250 And housex(check) < player.x + 250 And housey(check) > player.y - 250 And housey(check) < player.y + 250 Then GoTo location:
            Next check
        End If
    Next ch
    more2:
    If dy = -1 And st = 0 Then player.y = player.y - (playerSpeed / 2): t = t + 1
    If dy = 1 And st = 0 Then player.y = player.y + (playerSpeed / 2): t = t + 1
    If dx = -1 And st = 0 Then player.x = player.x - (playerSpeed / 2): t = t + 1
    If dx = 1 And st = 0 Then player.x = player.x + (playerSpeed / 2): t = t + 1
    If st = 0 Then _Title "X = " + Str$(Int(player.x)) + "    Y = " + Str$(Int(player.y))
    If st = 1 Then _Title "X = " + Str$(Int(player.x)) + "    Y = " + Str$(Int(player.y)) + "    Click Mouse To Continue!"
    If _KeyDown(ESC) Then End

    If player.x < 0 Then player.x = 0
    If player.x > _Width(map) Then player.x = _Width(map)
    If player.y < 0 Then player.y = 0
    If player.y > _Height(map) Then player.y = _Height(map)

    adjustCamera

    'Draw Head
    For sz = .25 To 10 Step .25
        Circle (player.x + camera.x, player.y + camera.y), sz, _RGB32(255, 166, 127)
    Next sz
    'Draw Smile
    Circle (player.x + camera.x, player.y + camera.y + 2), 7, _RGB32(255, 0, 0), _Pi, 2 * _Pi, .5
    'Draw Eyes
    Circle (player.x + camera.x - 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
    Circle (player.x + camera.x + 4, player.y + camera.y - 2), 1, _RGB32(0, 0, 255)
    'hat
    Line (player.x + camera.x - 10, player.y + camera.y - 10)-(player.x + camera.x + 10, player.y + camera.y - 9), _RGB32(155, 0, 0), BF
    Line (player.x + camera.x - 5, player.y + camera.y - 9)-(player.x + camera.x + 5, player.y + camera.y - 15), _RGB32(155, 0, 0), BF
    'Body
    Line (player.x + camera.x - 10, player.y + camera.y + 10)-(player.x + camera.x + 10, player.y + camera.y + 40), _RGB32(155, 0, 0), BF

    If t > 12 Then t = 1
    If t > 0 And t < 6 Then
        'Left Arm
        For wid2 = .1 To 3 Step .1
            Line (player.x + camera.x - 10 - wid2, player.y + camera.y + 10)-(player.x + camera.x - 20 - wid2, player.y + camera.y + 30), _RGB32(255, 166, 127)
        Next wid2
        'Right Arm
        For wid1 = .1 To 3 Step .1
            Line (player.x + camera.x + 10 + wid1, player.y + camera.y + 10)-(player.x + camera.x + 20 + wid1, player.y + camera.y + 30), _RGB32(255, 166, 127)
        Next wid1
        'Left leg
        For wid2 = .1 To 3 Step .1
            Line (player.x + camera.x - 10 + wid2, player.y + camera.y + 40)-(player.x + camera.x - 10 + wid2, player.y + camera.y + 60), _RGB32(255, 166, 127)
        Next wid2
        'Right leg
        For wid1 = .1 To 3 Step .1
            Line (player.x + camera.x + 10 - wid1, player.y + camera.y + 40)-(player.x + camera.x + 10 - wid1, player.y + camera.y + 60), _RGB32(255, 166, 127)
        Next wid1
    End If
    If t > 5 And t < 13 Then
        'Left Arm
        For wid2 = .1 To 3 Step .1
            Line (player.x + camera.x - 10 - wid2, player.y + camera.y + 10)-(player.x + camera.x - 30 - wid2, player.y + camera.y + 30), _RGB32(255, 166, 127)
        Next wid2
        'Right Arm
        For wid1 = .1 To 3 Step .1
            Line (player.x + camera.x + 10 + wid1, player.y + camera.y + 10)-(player.x + camera.x + 30 + wid1, player.y + camera.y + 30), _RGB32(255, 166, 127)
        Next wid1
        'Left leg
        For wid2 = .1 To 3 Step .1
            Line (player.x + camera.x - 10 + wid2, player.y + camera.y + 40)-(player.x + camera.x - 15 + wid2, player.y + camera.y + 60), _RGB32(255, 166, 127)
        Next wid2
        'Right leg
        For wid1 = .1 To 3 Step .1
            Line (player.x + camera.x + 10 - wid1, player.y + camera.y + 40)-(player.x + camera.x + 15 - wid1, player.y + camera.y + 60), _RGB32(255, 166, 127)
        Next wid1
    End If

    _Display
    _Limit 60
Loop

Sub adjustCamera
    If player.x + camera.x > _Width / 2 Or player.x + camera.x < _Width / 2 Then
        camera.x = _Width / 2 - player.x
    End If
    If camera.x > 0 Then camera.x = 0
    If camera.x < -(_Width(map) - _Width) Then camera.x = -(_Width(map) - _Width)

    If player.y + camera.y > _Height / 2 Or player.y + camera.y < _Height / 2 Then
        camera.y = _Height / 2 - player.y
    End If
    If camera.y > 0 Then camera.y = 0
    If camera.y < -(_Height(map) - _Height) Then camera.y = -(_Height(map) - _Height)
End Sub


Sub Clear_MB (var As Integer)
    Do Until Not _MouseButton(var)
        While _MouseInput: Wend
    Loop
End Sub 'Clear_MB
Reply


Messages In This Thread
Map Explorer - by SierraKen - 08-10-2022, 12:22 AM
RE: Map Explorer - by mdijkens - 08-10-2022, 01:56 PM
RE: Map Explorer - by Petr - 08-10-2022, 02:54 PM
RE: Map Explorer - by James D Jarvis - 08-10-2022, 02:55 PM
RE: Map Explorer - by James D Jarvis - 08-10-2022, 03:03 PM
RE: Map Explorer - by SierraKen - 08-10-2022, 04:17 PM
RE: Map Explorer - by SierraKen - 08-10-2022, 04:25 PM
RE: Map Explorer - by James D Jarvis - 08-10-2022, 06:38 PM
RE: Map Explorer - by SierraKen - 08-10-2022, 06:41 PM
RE: Map Explorer - by James D Jarvis - 08-10-2022, 06:50 PM
RE: Map Explorer - by SierraKen - 08-10-2022, 04:37 PM
RE: Map Explorer - by Petr - 08-10-2022, 04:56 PM
RE: Map Explorer - by SierraKen - 08-10-2022, 05:24 PM
RE: Map Explorer - by SierraKen - 08-10-2022, 05:28 PM
RE: Map Explorer - by SierraKen - 08-10-2022, 07:22 PM
RE: Map Explorer - by SierraKen - 08-10-2022, 07:37 PM
RE: Map Explorer - by James D Jarvis - 08-10-2022, 08:13 PM
RE: Map Explorer - by bplus - 08-10-2022, 08:29 PM
RE: Map Explorer - by bplus - 08-10-2022, 08:32 PM
RE: Map Explorer - by James D Jarvis - 08-10-2022, 08:44 PM
RE: Map Explorer - by SierraKen - 08-10-2022, 11:17 PM
RE: Map Explorer - by James D Jarvis - 08-10-2022, 11:57 PM
RE: Map Explorer - by James D Jarvis - 08-11-2022, 12:19 AM
RE: Map Explorer - by bplus - 08-11-2022, 01:41 AM
RE: Map Explorer - by SierraKen - 08-11-2022, 05:44 AM
RE: Map Explorer - by James D Jarvis - 08-11-2022, 01:26 PM
RE: Map Explorer - by bplus - 08-11-2022, 03:19 PM
RE: Map Explorer - by SierraKen - 08-11-2022, 05:07 PM
RE: Map Explorer - by SierraKen - 08-11-2022, 11:59 PM
RE: Map Explorer - by vince - 08-12-2022, 06:33 AM
RE: Map Explorer - by SierraKen - 08-12-2022, 07:39 PM
RE: Map Explorer - by James D Jarvis - 08-12-2022, 02:37 PM
RE: Map Explorer - by SierraKen - 08-12-2022, 07:41 PM
RE: Map Explorer - by James D Jarvis - 08-12-2022, 11:39 PM



Users browsing this thread: 14 Guest(s)