Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QIX
#1
Making my way through this game, thought I'd share what I have done so far.

For those not familiar, it's an old arcade game from 1981.   The idea is to fill in 75% of the screen to complete a level.   (So far no scores yet, and unlimited lives)

Still some things missing (like those sparks) and there are some bugs to sort out.   No sound either - not sure how I'll do that because the original game had bad sound effects.

One thing I'd like to do eventually is learn a flood fill algorithm.   I struggled with that and decided to just use paint for now.   Flood fill in this case was more complicated than I was expecting it to be.   But it'd be nice to do it like the original game does.

Code: (Select All)
'QB64 Qix
'james2464 - November 2022

'controls : arrow keys to move
'        : left CTRL for fast draw (blue)
'        : left ALT for slow draw (red)


_FullScreen
Option _Explicit

Dim Shared scx, scy
scx = 610: scy = 500

Screen _NewImage(scx, scy, 32)

Const PI = 3.141592654#
Randomize Timer

Dim Shared bg&, dbg&, logo1
bg& = _NewImage(scx, scy, 32)
dbg& = _NewImage(scx, scy, 32)

Dim Shared xx, yy, t, olddir, x, y, h, hd, fl, fl2, ct
Dim Shared sdinprocess, fdinprocess As Integer
Dim Shared qpath, flag, n, movepermit, flagrestart As Integer
Dim Shared qixtot, qxv, qyv, f, pmove, pfast, pslow, oldpx, oldpy, ps, drawoldx, drawoldy
Dim Shared j, k, checkx1, checkx2, checky1, checky2, totpct, btot, rtot
Dim Shared bluetot, redtot As _Integer64

'origin
xx = 320: yy = 240

Dim Shared c(50) As Long
c(0) = _RGB(0, 0, 0)
c(1) = _RGB(200, 200, 210) 'outside border
c(2) = _RGB(255, 255, 255) 'cursor white dot
c(3) = _RGB(200, 100, 100)
c(4) = _RGB(50, 120, 150) 'fast zone (fill)
c(5) = _RGB(180, 60, 30) 'slow zone (fill)
c(6) = _RGB(0, 255, 0)
c(7) = _RGB(255, 0, 0) 'cursor red
c(44) = _RGB(50, 120, 155) 'fast zone (drawing lines)
c(45) = _RGB(185, 60, 30) 'slow zone (drawing lines)



Type player
    x As Single
    y As Single
End Type
Dim Shared pl As player



Type qix
    dir As Single
    x1 As Integer
    x2 As Integer
    y1 As Integer
    y2 As Integer
    xx As Single
    yy As Single
    len1 As Single
    c1 As Integer
    c2 As Integer
    c3 As Integer
End Type
Dim Shared q(7) As qix
Dim Shared qd(7) As qix


qixtot = 7: qpath = 0: f = 1
ps = 5


Do
    'start
    pl.x = 320: pl.y = 440
    flagrestart = 0

    For t = 1 To qixtot
        q(t).xx = xx: q(t).yy = yy: q(t).len1 = 40
    Next t

    '_MouseHide

    Cls

    'screen setup
    Line (120, 40)-(520, 440), c(1), B 'outer border

    '_PutImage (500, 50), logo1

    bluetot = 0: redtot = 0

    _PutImage (1, 1)-(scx - 1, scy - 1), 0, bg&, (1, 1)-(scx, scy) 'take snapshot of screen

    Do

        _Limit 20



        'player cursor                =======================================================================================

        'get keyboard input
        pmove = arrowkey
        pfast = fastdraw
        pslow = slowdraw

        oldpx = pl.x: oldpy = pl.y

        If pfast + pslow = 0 Then normalmove
        If pfast > pslow Then fastdrawmove
        If pfast < pslow Then slowdrawmove




        'ok so about that qix thing....=======================================================================================


        'heading and direction  -----------------------------------------------------
        If qpath < 1 Then
            If qpath = 0 Then
                '_Delay 1.
                qpath = Int(Rnd * 11) + 1: qxv = Rnd * 30 - 15: qyv = Rnd * 30 - 15
                olddir = q(1).dir: q(1).dir = olddir + Rnd * PI - PI / 2
            End If
            If qpath = -1 Then
                '_Delay .5
                qpath = (Rnd * 22) + 1: qxv = Rnd * 30 - 15: qyv = Rnd * 30 - 15
                olddir = q(1).dir
                If olddir > PI Then
                    q(1).dir = olddir - PI
                Else
                    q(1).dir = olddir + PI
                End If
            End If
        End If

        qpath = Int(qpath - 1)

        'update trailing lines -----------------------------------------------------
        For t = 7 To 2 Step -1
            q(t).xx = q(t - 1).xx: q(t).yy = q(t - 1).yy
            q(t).x1 = q(t - 1).x1: q(t).x2 = q(t - 1).x2
            q(t).y1 = q(t - 1).y1: q(t).y2 = q(t - 1).y2
            q(t).len1 = q(t - 1).len1
            q(t).c1 = q(t - 1).c1: q(t).c2 = q(t - 1).c2: q(t).c3 = q(t - 1).c3
        Next t


        'collision detection -------------------------------------------------------

        flag = 0 'collision - assume none to start

        q(1).xx = q(1).xx + qxv
        q(1).yy = q(1).yy + qyv



        q(1).dir = q(1).dir + Rnd * .9 - .45
        q(1).len1 = q(1).len1 + Rnd * 10 - 4.4
        If q(1).len1 > 40 Then q(1).len1 = 40
        If q(1).len1 < 5 Then q(1).len1 = 5

        x = Cos(q(1).dir) * q(1).len1
        y = Sin(q(1).dir) * q(1).len1
        q(1).x1 = q(1).xx + x: q(1).x2 = q(1).xx - x
        q(1).y1 = q(1).yy - y: q(1).y2 = q(1).yy + y


        'scan background colour along line
        For j = 0 To q(1).len1
            x = Cos(q(1).dir) * j: y = Sin(q(1).dir) * j
            checkx1 = q(1).xx + x: checkx2 = q(1).xx - x
            checky1 = q(1).yy - y: checky2 = q(1).yy + y
            c(19) = Point(checkx1, checky1)
            c(20) = Point(checkx2, checky2)
            If c(19) <> c(0) Then
                Select Case c(19)
                    Case c(1)
                        flag = 1
                    Case q(2).c1, q(3).c1, q(4).c1, q(5).c1, q(6).c1, q(7).c1
                        flag = 1
                    Case c(44), c(7)
                        If fdinprocess = 1 Then
                            flag = 2
                        End If
                    Case c(45), c(7)
                        If sdinprocess = 1 Then
                            flag = 2
                        End If
                End Select
            End If
            If c(20) <> c(0) Then
                Select Case c(20)
                    Case c(1)
                        flag = 1
                    Case q(2).c1, q(3).c1, q(4).c1, q(5).c1, q(6).c1, q(7).c1
                        flag = 1
                    Case c(44), c(7)
                        If fdinprocess = 1 Then
                            flag = 2
                        End If
                    Case c(45), c(7)
                        If sdinprocess = 1 Then
                            flag = 2
                        End If
                End Select
            End If
        Next j

        'check for skipped/crossed line
        h = _Hypot(qyv, qxv)
        hd = _Atan2(-qxv, -qyv)

        For j = 0 To Int(h) Step .5
            x = Sin(-hd) * j: y = Cos(hd) * j
            checkx2 = q(1).xx - x
            checky2 = q(1).yy + y
            c(20) = Point(checkx2, checky2)
            If c(20) <> c(0) Then
                Select Case c(20)
                    Case c(1)
                        flag = 1
                    Case q(2).c1, q(3).c1, q(4).c1, q(5).c1, q(6).c1, q(7).c1
                        flag = 1
                    Case c(4), c(7)
                        If fdinprocess = 1 Then
                            flag = 2
                        End If
                    Case c(5), c(7)
                        If sdinprocess = 1 Then
                            flag = 2
                        End If
                End Select
            End If
        Next j


        'changing colour
        q(1).c1 = q(1).c1 + Rnd * 60 - 30
        If q(1).c1 < 80 Then q(1).c1 = 80
        If q(1).c1 > 255 Then q(1).c1 = 255
        q(1).c2 = q(1).c2 + Rnd * 60 - 30
        If q(1).c2 < 80 Then q(1).c2 = 80
        If q(1).c2 > 255 Then q(1).c2 = 255
        q(1).c3 = q(1).c3 + Rnd * 60 - 30
        If q(1).c3 < 80 Then q(1).c3 = 80
        If q(1).c3 > 255 Then q(1).c3 = 255


        'if collision detected...
        If flag = 1 Then
            qpath = -1 'new path needed - reverse direction
            q(1).xx = q(3).xx: q(1).yy = q(3).yy
            q(1).x1 = q(3).x1: q(1).x2 = q(3).x2
            q(1).y1 = q(3).y1: q(1).y2 = q(3).y2
            q(1).len1 = q(3).len1 - 3 'shorter line
        End If

        If flag = 2 Then
            youdead
            _PutImage (1, 1)-(scx, scy), dbg&, bg&, (1, 1)-(scx, scy)
        End If


        '====================================================================================================
        '====================================================================================================
        '====================================================================================================
        '====================================================================================================



        Cls

        _PutImage (0, 0)-(scx, scy), bg&, 0 'draw background


        For t = 1 To qixtot
            c(9) = _RGB(q(t).c1, q(t).c2, q(t).c3)
            Line (q(t).x1, q(t).y1)-(q(t).x2, q(t).y2), c(9)
        Next t

        Line (pl.x - ps, pl.y)-(pl.x, pl.y - ps), c(7)
        Line (pl.x, pl.y - ps)-(pl.x + ps, pl.y), c(7)
        Line (pl.x + ps, pl.y)-(pl.x, pl.y + ps), c(7)
        Line (pl.x, pl.y + ps)-(pl.x - ps, pl.y), c(7)
        Line (pl.x - 1, pl.y)-(pl.x + 1, pl.y), c(2)
        Line (pl.x, pl.y - 1)-(pl.x, pl.y + 1), c(2)


        btot = Int(bluetot / 1570)
        rtot = Int(redtot / 1570)
        totpct = Int(btot + rtot)

        Locate 29, 20
        Print "BLUE:"; btot; "%"
        Locate 29, 36
        Print "RED:"; rtot; "%"
        Locate 29, 52
        Print "TOTAL:"; totpct; "%"





        _Display

        If sdinprocess < 0 Then
            _Delay .8
            sdinprocess = 0
        End If

        If fdinprocess < 0 Then
            _Delay .8
            fdinprocess = 0
        End If

        If totpct > 75 Then
            endlevel
            flagrestart = 1
        End If

        If _KeyDown(15104) Then
            endlevel
            flagrestart = 1
        End If


    Loop Until flagrestart = 1

Loop

Function arrowkey
    arrowkey = 0
    If _KeyDown(18432) Then '                                IF up arrow key was pressed
        arrowkey = 1 '
    End If
    If _KeyDown(20480) Then '                                IF down arrow key was pressed
        arrowkey = 2 '
    End If
    If _KeyDown(19200) Then '                                IF left arrow key was pressed
        arrowkey = 3 '
    End If
    If _KeyDown(19712) Then '                                IF right arrow key was pressed
        arrowkey = 4 '
    End If
End Function

Function fastdraw
    fastdraw = 0
    If _KeyDown(100306) Then '                                  IF L-CTRL key was pressed
        fastdraw = 1 '
    End If
End Function

Function slowdraw
    slowdraw = 0
    If _KeyDown(100308) Then '                                  IF L-ALT key was pressed
        slowdraw = 1 '
    End If
End Function

'-----------------------------------------------------------------------------------------------------------------



Sub normalmove
    Select Case pmove
        Case 1
            pl.y = pl.y - 4
            c(19) = Point(pl.x, pl.y)
            c(20) = Point(pl.x + 1, pl.y)
            c(21) = Point(pl.x - 1, pl.y)
            c(22) = Point(pl.x, pl.y + 1)
            c(23) = Point(pl.x, pl.y - 1)
            c(24) = Point(pl.x + 1, pl.y + 1)
            c(25) = Point(pl.x - 1, pl.y - 1)
            c(26) = Point(pl.x - 1, pl.y + 1)
            c(27) = Point(pl.x + 1, pl.y - 1)
            fl2 = 0
            For fl = 20 To 27 Step 1
                If c(fl) = c(0) Then fl2 = 1
            Next fl
            movepermit = 0
            While movepermit = 0
                If c(19) = c(1) And fl2 > 0 Then
                    movepermit = 1
                Else
                    pl.y = pl.y + 2
                    c(19) = Point(pl.x, pl.y)
                    c(20) = Point(pl.x + 1, pl.y)
                    c(21) = Point(pl.x - 1, pl.y)
                    c(22) = Point(pl.x, pl.y + 1)
                    c(23) = Point(pl.x, pl.y - 1)
                    c(24) = Point(pl.x + 1, pl.y + 1)
                    c(25) = Point(pl.x - 1, pl.y - 1)
                    c(26) = Point(pl.x - 1, pl.y + 1)
                    c(27) = Point(pl.x + 1, pl.y - 1)
                    fl2 = 0
                    For fl = 20 To 27 Step 1
                        If c(fl) = c(0) Then fl2 = 1
                    Next fl
                    If c(19) = c(1) And fl2 > 0 Then
                        movepermit = 1
                    Else
                        pl.y = pl.y + 2
                        movepermit = -1
                    End If
                End If
            Wend

        Case 2
            pl.y = pl.y + 4
            c(19) = Point(pl.x, pl.y)
            c(20) = Point(pl.x + 1, pl.y)
            c(21) = Point(pl.x - 1, pl.y)
            c(22) = Point(pl.x, pl.y + 1)
            c(23) = Point(pl.x, pl.y - 1)
            c(24) = Point(pl.x + 1, pl.y + 1)
            c(25) = Point(pl.x - 1, pl.y - 1)
            c(26) = Point(pl.x - 1, pl.y + 1)
            c(27) = Point(pl.x + 1, pl.y - 1)
            fl2 = 0
            For fl = 20 To 27 Step 1
                If c(fl) = c(0) Then fl2 = 1
            Next fl
            movepermit = 0
            While movepermit = 0
                If c(19) = c(1) And fl2 > 0 Then
                    movepermit = 1
                Else
                    pl.y = pl.y - 2
                    c(19) = Point(pl.x, pl.y)
                    c(20) = Point(pl.x + 1, pl.y)
                    c(21) = Point(pl.x - 1, pl.y)
                    c(22) = Point(pl.x, pl.y + 1)
                    c(23) = Point(pl.x, pl.y - 1)
                    c(24) = Point(pl.x + 1, pl.y + 1)
                    c(25) = Point(pl.x - 1, pl.y - 1)
                    c(26) = Point(pl.x - 1, pl.y + 1)
                    c(27) = Point(pl.x + 1, pl.y - 1)
                    fl2 = 0
                    For fl = 20 To 27 Step 1
                        If c(fl) = c(0) Then fl2 = 1
                    Next fl
                    If c(19) = c(1) And fl2 > 0 Then
                        movepermit = 1
                    Else
                        pl.y = pl.y - 2
                        movepermit = -1
                    End If
                End If
            Wend

        Case 3
            pl.x = pl.x - 4
            c(19) = Point(pl.x, pl.y)
            c(20) = Point(pl.x + 1, pl.y)
            c(21) = Point(pl.x - 1, pl.y)
            c(22) = Point(pl.x, pl.y + 1)
            c(23) = Point(pl.x, pl.y - 1)
            c(24) = Point(pl.x + 1, pl.y + 1)
            c(25) = Point(pl.x - 1, pl.y - 1)
            c(26) = Point(pl.x - 1, pl.y + 1)
            c(27) = Point(pl.x + 1, pl.y - 1)
            fl2 = 0
            For fl = 20 To 27 Step 1
                If c(fl) = c(0) Then fl2 = 1
            Next fl

            movepermit = 0
            While movepermit = 0
                If c(19) = c(1) And fl2 > 0 Then
                    movepermit = 1
                Else
                    pl.x = pl.x + 2
                    c(19) = Point(pl.x, pl.y)
                    c(20) = Point(pl.x + 1, pl.y)
                    c(21) = Point(pl.x - 1, pl.y)
                    c(22) = Point(pl.x, pl.y + 1)
                    c(23) = Point(pl.x, pl.y - 1)
                    c(24) = Point(pl.x + 1, pl.y + 1)
                    c(25) = Point(pl.x - 1, pl.y - 1)
                    c(26) = Point(pl.x - 1, pl.y + 1)
                    c(27) = Point(pl.x + 1, pl.y - 1)
                    fl2 = 0
                    For fl = 20 To 27 Step 1
                        If c(fl) = c(0) Then fl2 = 1
                    Next fl
                    If c(19) = c(1) And fl2 > 0 Then
                        movepermit = 1
                    Else
                        pl.x = pl.x + 2
                        movepermit = -1
                    End If
                End If
            Wend

        Case 4
            pl.x = pl.x + 4
            c(19) = Point(pl.x, pl.y)
            c(20) = Point(pl.x + 1, pl.y)
            c(21) = Point(pl.x - 1, pl.y)
            c(22) = Point(pl.x, pl.y + 1)
            c(23) = Point(pl.x, pl.y - 1)
            c(24) = Point(pl.x + 1, pl.y + 1)
            c(25) = Point(pl.x - 1, pl.y - 1)
            c(26) = Point(pl.x - 1, pl.y + 1)
            c(27) = Point(pl.x + 1, pl.y - 1)
            fl2 = 0
            For fl = 20 To 27 Step 1
                If c(fl) = c(0) Then fl2 = 1
            Next fl
            movepermit = 0
            While movepermit = 0
                If c(19) = c(1) And fl2 > 0 Then
                    movepermit = 1
                Else
                    pl.x = pl.x - 2
                    c(19) = Point(pl.x, pl.y)
                    c(20) = Point(pl.x + 1, pl.y)
                    c(21) = Point(pl.x - 1, pl.y)
                    c(22) = Point(pl.x, pl.y + 1)
                    c(23) = Point(pl.x, pl.y - 1)
                    c(24) = Point(pl.x + 1, pl.y + 1)
                    c(25) = Point(pl.x - 1, pl.y - 1)
                    c(26) = Point(pl.x - 1, pl.y + 1)
                    c(27) = Point(pl.x + 1, pl.y - 1)
                    fl2 = 0
                    For fl = 20 To 27 Step 1
                        If c(fl) = c(0) Then fl2 = 1
                    Next fl
                    If c(19) = c(1) And fl2 > 0 Then
                        movepermit = 1
                    Else
                        pl.x = pl.x - 2
                        movepermit = -1
                    End If
                End If
            Wend

    End Select
End Sub



Sub fastdrawmove
    Select Case pmove

        Case 1
            pl.y = pl.y - 4
            If pl.y < 40 Then pl.y = 40
            c(19) = Point(pl.x, pl.y)
            c(18) = Point(pl.x, pl.y + 2)
            movepermit = 0
            While movepermit = 0
                If c(18) = c(0) Then
                    movepermit = 1
                Else
                    pl.y = pl.y + 2
                    If c(18) = c(1) Then
                        movepermit = 1
                    Else
                        pl.y = pl.y + 2
                        movepermit = -1
                    End If
                End If
            Wend


        Case 2
            pl.y = pl.y + 4
            If pl.y > 440 Then pl.y = 440
            c(19) = Point(pl.x, pl.y)
            c(18) = Point(pl.x, pl.y - 2)
            movepermit = 0
            While movepermit = 0
                If c(18) = c(0) Then
                    movepermit = 1
                Else
                    pl.y = pl.y - 2
                    If c(18) = c(1) Then
                        movepermit = 1
                    Else
                        pl.y = pl.y - 2
                        movepermit = -1
                    End If
                End If
            Wend


        Case 3
            pl.x = pl.x - 4
            If pl.x < 120 Then pl.x = 120
            c(19) = Point(pl.x, pl.y)
            c(18) = Point(pl.x + 2, pl.y)
            movepermit = 0
            While movepermit = 0
                If c(18) = c(0) Then
                    movepermit = 1
                Else
                    pl.x = pl.x + 2
                    If c(18) = c(1) Then
                        movepermit = 1
                    Else
                        pl.x = pl.x + 2
                        movepermit = -1
                    End If
                End If
            Wend


        Case 4
            pl.x = pl.x + 4
            If pl.x > 520 Then pl.x = 520
            c(19) = Point(pl.x, pl.y)
            c(18) = Point(pl.x - 2, pl.y)
            movepermit = 0
            While movepermit = 0
                If c(18) = c(0) Then
                    movepermit = 1
                Else
                    pl.x = pl.x - 2
                    If c(18) = c(1) Then
                        movepermit = 1
                    Else
                        pl.x = pl.x - 2
                        movepermit = -1
                    End If
                End If
            Wend
    End Select


    c(19) = Point(pl.x, pl.y)
    If c(19) = c(0) Then
        Cls
        _PutImage (0, 0)-(scx, scy), bg&, 0 'draw background screen
        If fdinprocess = 0 Then
            drawoldx = oldpx: drawoldy = oldpy
            _PutImage (1, 1)-(scx - 1, scy - 1), 0, dbg&, (1, 1)-(scx, scy) 'take snapshot of screen - in case of death
        End If
        Line (oldpx, oldpy)-(pl.x, pl.y), c(44)
        If fdinprocess = 0 Then
            PSet (oldpx, oldpy), c(1)
        End If
        fdinprocess = 1
        _PutImage (1, 1)-(scx - 1, scy - 1), 0, bg&, (1, 1)-(scx, scy) 'take snapshot of screen
    End If

    If fdinprocess = 1 Then
        c(19) = Point(pl.x, pl.y)
        If c(19) = c(1) Then 'fast draw completed
            Cls
            _PutImage (0, 0)-(scx, scy), bg&, 0 'draw background screen
            Line (oldpx, oldpy)-(pl.x, pl.y), c(44)
            PSet (pl.x, pl.y), c(1)
            fdinprocess = -1
            claimlinefast
            claimfillfast
            _PutImage (1, 1)-(scx - 1, scy - 1), 0, bg&, (1, 1)-(scx, scy) 'take snapshot of screen
        End If
    End If

End Sub


Sub slowdrawmove
    Select Case pmove
        Case 1
            pl.y = pl.y - 2
            If pl.y < 40 Then pl.y = 40
            c(19) = Point(pl.x, pl.y)
            movepermit = 0
            While movepermit = 0
                If c(19) = c(0) Then
                    movepermit = 1
                Else
                    If c(19) = c(1) Then
                        movepermit = 1
                    Else
                        pl.y = pl.y + 2
                        movepermit = -1
                    End If
                End If
            Wend


        Case 2
            pl.y = pl.y + 2
            If pl.y > 440 Then pl.y = 440
            c(19) = Point(pl.x, pl.y)
            movepermit = 0
            While movepermit = 0
                If c(19) = c(0) Then
                    movepermit = 1
                Else
                    If c(19) = c(1) Then
                        movepermit = 1
                    Else
                        pl.y = pl.y - 2
                        movepermit = -1
                    End If
                End If
            Wend


        Case 3
            pl.x = pl.x - 2
            If pl.x < 120 Then pl.x = 120
            c(19) = Point(pl.x, pl.y)
            movepermit = 0
            While movepermit = 0
                If c(19) = c(0) Then
                    movepermit = 1
                Else
                    If c(19) = c(1) Then
                        movepermit = 1
                    Else
                        pl.x = pl.x + 2
                        movepermit = -1
                    End If
                End If
            Wend


        Case 4
            pl.x = pl.x + 2
            If pl.x > 520 Then pl.x = 520
            c(19) = Point(pl.x, pl.y)
            movepermit = 0
            While movepermit = 0
                If c(19) = c(0) Then
                    movepermit = 1
                Else
                    If c(19) = c(1) Then
                        movepermit = 1
                    Else
                        pl.x = pl.x - 2
                        movepermit = -1
                    End If
                End If
            Wend
    End Select



    c(19) = Point(pl.x, pl.y)
    If c(19) = c(0) Then
        Cls
        _PutImage (0, 0)-(scx, scy), bg&, 0 'draw background screen
        If sdinprocess = 0 Then
            drawoldx = oldpx: drawoldy = oldpy
            _PutImage (1, 1)-(scx - 1, scy - 1), 0, dbg&, (1, 1)-(scx, scy) 'take snapshot of screen - in case of death
        End If
        Line (oldpx, oldpy)-(pl.x, pl.y), c(45)
        If sdinprocess = 0 Then
            PSet (oldpx, oldpy), c(1)
        End If
        sdinprocess = 1
        _PutImage (1, 1)-(scx - 1, scy - 1), 0, bg&, (1, 1)-(scx, scy) 'take snapshot of screen
    End If

    If sdinprocess = 1 Then
        c(19) = Point(pl.x, pl.y)
        If c(19) = c(1) Then 'slow draw completed
            Cls
            _PutImage (0, 0)-(scx, scy), bg&, 0 'draw background screen
            Line (oldpx, oldpy)-(pl.x, pl.y), c(45)
            PSet (pl.x, pl.y), c(1)
            sdinprocess = -1
            claimlineslow
            claimfillslow
            _PutImage (1, 1)-(scx - 1, scy - 1), 0, bg&, (1, 1)-(scx, scy) 'take snapshot of screen
        End If
    End If

End Sub



Sub claimlinefast
    'scan board for blue line
    For j = 41 To 439
        For k = 121 To 519
            c(19) = Point(k, j)
            n = 0
            If c(19) = c(44) Then 'blue pixel found
                c(20) = Point(k - 1, j)
                c(21) = Point(k + 1, j)
                c(22) = Point(k, j - 1)
                c(23) = Point(k, j + 1)
                c(24) = Point(k, j + 2)
                c(25) = Point(k, j - 2)
                c(26) = Point(k + 2, j)

                'horizontal line
                If c(22) = c(0) Then 'look above
                    If c(23) = c(0) Then n = Int(2) 'look below
                End If

                'upper left corner
                If n = 0 Then
                    'look below 2 pixels
                    If c(23) = c(44) Then
                        If c(24) = c(44) Then
                            If c(20) = c(0) Then
                                n = Int(2)
                            End If
                        End If
                    End If
                End If

                'upper right corner
                If n = 0 Then
                    'look below 2 pixels
                    If c(23) = c(44) Then
                        If c(24) = c(44) Then
                            If c(21) = c(0) Then
                                n = Int(2)
                            End If
                        End If
                    End If
                End If


                'lower left corner
                If n = 0 Then
                    'look to the right 2 pixels
                    If c(21) = c(44) Then
                        If c(26) = c(44) Then
                            If c(23) = c(0) Then
                                n = Int(2)
                            End If
                        End If
                    End If
                End If


                'lower right corner
                If n = 0 Then
                    'look above 2 pixels
                    If c(22) = c(1) Then
                        If c(25) = c(1) Then
                            If c(23) = c(0) Then
                                n = Int(2)
                            End If
                        End If
                    End If
                End If


                'if part of vertical line
                If c(20) = c(0) Then
                    If c(21) = c(0) Then n = Int(2)
                End If


                If n = 2 Then
                    PSet (k, j), c(1) 'change blue pixel to white
                End If
            End If
        Next k
    Next j
End Sub


Sub claimlineslow
    'scan board for red line
    For j = 41 To 439
        For k = 121 To 519
            c(19) = Point(k, j)
            n = 0
            If c(19) = c(45) Then 'red pixel found
                c(20) = Point(k - 1, j)
                c(21) = Point(k + 1, j)
                c(22) = Point(k, j - 1)
                c(23) = Point(k, j + 1)
                c(24) = Point(k, j + 2)
                c(25) = Point(k, j - 2)
                c(26) = Point(k + 2, j)

                'horizontal line
                If c(22) = c(0) Then 'look above
                    If c(23) = c(0) Then n = Int(2) 'look below
                End If

                'upper left corner
                If n = 0 Then
                    'look below 2 pixels
                    If c(23) = c(45) Then
                        If c(24) = c(45) Then
                            If c(20) = c(0) Then
                                n = Int(2)
                            End If
                        End If
                    End If
                End If

                'upper right corner
                If n = 0 Then
                    'look below 2 pixels
                    If c(23) = c(45) Then
                        If c(24) = c(45) Then
                            If c(21) = c(0) Then
                                n = Int(2)
                            End If
                        End If
                    End If
                End If



                'if lower left corner
                If n = 0 Then
                    'look to the right 2 pixels
                    If c(21) = c(45) Then
                        If c(26) = c(45) Then
                            If c(23) = c(0) Then
                                n = Int(2)
                            End If
                        End If
                    End If
                End If

                'if lower right corner
                If n = 0 Then
                    'look above 2 pixels
                    If c(22) = c(1) Then
                        If c(25) = c(1) Then
                            If c(23) = c(0) Then
                                n = Int(2)
                            End If
                        End If
                    End If
                End If

                'if part of vertical line
                If c(20) = c(0) Then
                    If c(21) = c(0) Then n = Int(2)
                End If


                If n = 2 Then
                    PSet (k, j), c(1) 'change red pixel to white
                End If
            End If
        Next k
    Next j
End Sub



Sub claimfillfast 'using paint for flood fills
    'start at qix
    c(14) = _RGB(30, 30, 30)
    k = q(1).xx: j = q(1).yy
    Paint (k, j), c(14), c(1)

    'fill black with blue
    For j = 41 To 439
        For k = 121 To 519
            c(16) = Point(k, j)
            If c(16) = c(0) Then
                PSet (k, j), c(4)
                bluetot = bluetot + 1
            End If
        Next k
    Next j

    'fill gray with black
    k = q(1).xx: j = q(1).yy
    Paint (k, j), c(0), c(1)
End Sub


Sub claimfillslow 'using paint for flood fills

    'start at qix
    c(14) = _RGB(30, 30, 30)
    k = q(1).xx: j = q(1).yy
    Paint (k, j), c(14), c(1)

    'fill black with red
    For j = 41 To 439
        For k = 121 To 519
            c(16) = Point(k, j)
            If c(16) = c(0) Then
                PSet (k, j), c(5)
                redtot = redtot + 1
            End If
        Next k
    Next j

    'fill gray with black
    k = q(1).xx: j = q(1).yy
    Paint (k, j), c(0), c(1)
End Sub



Sub endlevel
    'fill black
    For j = 121 To 519
        For k = 439 To 41 Step -1
            PSet (j, k), c(0)
        Next k
        _Display
        _Delay .005
    Next j
End Sub



Sub youdead
    Dim ct2, ct3, ct4, basedir, tx, ty, dist, d2, rp

    basedir = .785
    dist = 15
    d2 = 10
    qd(1).xx = pl.x + 5: qd(1).yy = pl.y - 5
    qd(1).len1 = 10
    qd(1).dir = basedir



    For ct = 1 To 35
        Cls
        _PutImage (0, 0)-(scx, scy), bg&, 0 'draw background screen

        dist = dist + 10
        rp = ct
        If rp > 7 Then rp = 7


        qd(1).dir = basedir
        qd(1).len1 = qd(1).len1 + 1.5

        If rp > 1 Then
            For ct4 = 2 To rp
                qd(ct4).len1 = qd(ct4 - 1).len1 - 1.5
                qd(ct4).dir = basedir
            Next ct4
        End If

        For ct2 = 1 To rp
            For ct3 = 1 To 4
                Select Case ct3
                    Case 1
                        qd(ct2).xx = pl.x + (dist - ct2 * d2): qd(ct2).yy = pl.y - (dist - ct2 * d2)
                    Case 2
                        qd(ct2).xx = pl.x + (dist - ct2 * d2): qd(ct2).yy = pl.y + (dist - ct2 * d2)
                    Case 3
                        qd(ct2).xx = pl.x - (dist - ct2 * d2): qd(ct2).yy = pl.y + (dist - ct2 * d2)
                    Case 4
                        qd(ct2).xx = pl.x - (dist - ct2 * d2): qd(ct2).yy = pl.y - (dist - ct2 * d2)
                End Select

                qd(ct2).dir = qd(ct2).dir + (PI / 2)
                x = Cos(qd(ct2).dir) * qd(ct2).len1
                y = Sin(qd(ct2).dir) * qd(ct2).len1
                qd(ct2).x1 = qd(ct2).xx + x: qd(ct2).x2 = qd(ct2).xx - x
                qd(ct2).y1 = qd(ct2).yy - y: qd(ct2).y2 = qd(ct2).yy + y
                Line (qd(ct2).x1, qd(ct2).y1)-(qd(ct2).x2, qd(ct2).y2), c(1)
            Next ct3
        Next ct2


        _Display
        _Delay .04
    Next ct



    _Delay 1.
    sdinprocess = 0
    fdinprocess = 0
    pl.x = drawoldx: pl.y = drawoldy

End Sub
Reply
#2
So the aim of this is to block off more and more of the screen from that thing that moves around?

Might be interesting to make that thing a one line zigzag that bounces a little like a spring?
b = b + ...
Reply
#3
(11-29-2022, 02:36 AM)james2464 Wrote: For those not familiar, it's an old arcade game from 1981.   The idea is to fill in 75% of the screen to complete a level.   (So far no scores yet, and unlimited lives)
Duh I know what this is, not like that other "Qix" which wasn't what I expected. I had this on Nintendo Game Boy.

Very good job, but oh noes you offed me saying sound effects sucked... OK some of them, but my favorite was the "spring" hitting the player's line...

The colors are very welcome, instead of Game Boy LCD screen which was lame to look at and had to hunch over often for an hour or longer. If I'm going to get neck and back problems out of it at least make it like CGA or do that TV raster trick with two colors.

Please no more full-screen without a way to exit the program quickly! This peaks off some users who might be playing such a game at work and then the boss suddenly drops by... Erm, maybe not but it's polite to program [ESC] to leave the program.

At the first level the "spring" moves too darned quickly. Reserve this for "intermediate" player or higher level from "beginning" stage.

Maybe talk to Terry about the "flood fill", he seems to know a lot about programming old video games, demonstrated it with Pac-Man and Berzerk. :tu:

@bplus the first level of the Game Boy game was hard too, to get at least 2/3 of the screen space. At least for me.
Reply
#4
I have code for flood fill but not nearly as fast as Paint. Don't know what is wrong with Paint but wouldn't a BF'ed Line be even faster? really the code is best used for finding shortest path.

@mnrvovrfc
To exit a FullScreen when no escape provided or coder hasn't made plain the secret escape key combo use Alt + F4.
I learned this early on hanging out at QB Forums and trying out code. First time I encountered _FullScreen.
b = b + ...
Reply
#5
This is the old arcade game I'm referring to:

https://youtu.be/EdEOH5O2kCo


Bplus:  In this game, flood fill doesn't need to be very fast.  The slower fill has a nice effect and also it's a scan line version.   It'll be interesting to actually program that at some point.
Reply
#6
That version looked like an utter failure, like few people would risk putting in an entire Lincoln of quarters on it.

I don't remember if the NGB version had "sparks" or a difficulty level, and the sound effects were far superior. I mean, when the player finished a filled area, it did a short pling. When the "spring" touched the player's line, it did a slightly longer pling, it was my favorite sound. Otherwise it was "muzak" a lot like an amateur dance song remix ROFL.

The "slow" drawing really had no point for me with sparks around, I mean, I would never play the original game even if I got 100 chances for one quarter. Leave it to an expert mode. Intermediate then is the "spring" moving as the program stands now, and beginner have it move more slowly and the player is disallowed to use "slow" command. That's so he/she becomes more comfortable playing the game.

I thought it was 2/3, but 3/4 is difficult for sure. The "spring" suddenly could move sideways while a player tries to reach an edge of the screen. It happened to me too often on NGB...
Reply
#7
(11-29-2022, 05:39 AM)mnrvovrfc Wrote: That version looked like an utter failure, like few people would risk putting in an entire Lincoln of quarters on it.

I don't remember if the NGB version had "sparks" or a difficulty level, and the sound effects were far superior. I mean, when the player finished a filled area, it did a short pling. When the "spring" touched the player's line, it did a slightly longer pling, it was my favorite sound. Otherwise it was "muzak" a lot like an amateur dance song remix ROFL.

The "slow" drawing really had no point for me with sparks around, I mean, I would never play the original game even if I got 100 chances for one quarter. Leave it to an expert mode. Intermediate then is the "spring" moving as the program stands now, and beginner have it move more slowly and the player is disallowed to use "slow" command. That's so he/she becomes more comfortable playing the game.

I thought it was 2/3, but 3/4 is difficult for sure. The "spring" suddenly could move sideways while a player tries to reach an edge of the screen. It happened to me too often on NGB...

I've only ever played the original arcade game as shown in that video.   As a kid I loved it!   But then again arcade games were still kind of new so it was all fascinating to me.   The sound effects in this game didn't bother me back then, but it's definitely rough.   I guess they didn't care much about it.   At the time I think most of the arcade was pinball machines and full of noise.

Anyway it's not for everyone but I'm having fun trying to emulate it so far.   I'll look around for the other versions of this game and check out those better sound effects.
Reply
#8
(11-29-2022, 05:25 AM)james2464 Wrote: This is the old arcade game I'm referring to:

https://youtu.be/EdEOH5O2kCo


Bplus:  In this game, flood fill doesn't need to be very fast.  The slower fill has a nice effect and also it's a scan line version.   It'll be interesting to actually program that at some point.

Oh well scan lines are easiest to sim, just draw lines with delay or limit to however fast you desire? We are just filling perfectly upright rectangles correct? Just have to decide vertical or horizontal. What might be fun is a rectangular spiral inward or outward.

Update: watched video, oh you don't have to go all the way across the width of screen or up and down the height. So filling boxes to finished edge or 2 or 3 hmm.... just need to get the 4: top, bottom, left, right and can fill all sorts of ways, how about a Christmas wrap design? Need to see my painting with images! My demo with brick wall might be perfect.
b = b + ...
Reply
#9
(11-29-2022, 12:38 PM)bplus Wrote:
(11-29-2022, 05:25 AM)james2464 Wrote: This is the old arcade game I'm referring to:

https://youtu.be/EdEOH5O2kCo


Bplus:  In this game, flood fill doesn't need to be very fast.  The slower fill has a nice effect and also it's a scan line version.   It'll be interesting to actually program that at some point.

Oh well scan lines are easiest to sim, just draw lines with delay or limit to however fast you desire? We are just filling perfectly upright rectangles correct? Just have to decide vertical or horizontal. What might be fun is a rectangular spiral inward or outward.

Update: watched video, oh you don't have to go all the way across the width of screen or up and down the height. So filling boxes to finished edge or 2 or 3 hmm.... just need to get the 4: top, bottom, left, right and can fill all sorts of ways, how about a Christmas wrap design? Need to see my painting with images! My demo with brick wall might be perfect.

This is sort of new to me.   I have to play around with different flood fill methods.   I thought it would be very simple but I had trouble with it because of the way this game is...you capture a new area and you need to be able to flood only that area.   That's where I had problems.   Paint worked out easily, however.
Reply
#10
Well you know how I hate to show off but it seems a perfect application for painting with a brick wall!

Edit: Just stored in drawing tools collection bplus corner
https://qb64phoenix.com/forum/showthread...3#pid10843
b = b + ...
Reply




Users browsing this thread: 1 Guest(s)