Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scrolling fog/cloud image for moving background
#9
If I only use 2 layers, it still looks 3d a little and ALMOST moves fast enough on my laptop for some gameplay.  Remember the flying witch through candies that you helped me out with collision detecting?  I put it all together with the scrolling fog code.  Just wanted to see what the speed would be like.

- Dav

Code: (Select All)
SCREEN _NEWIMAGE(1000, 600, 32)

candy& = BASIMAGE1&
witch& = BASIMAGE2&

fog& = _NEWIMAGE(300, 300, 32)
_DEST fog&
FOR i = 1 TO 10000
    c = RND * 200 + 50
    ball RND * _WIDTH, RND * _HEIGHT, RND * 15, c, c, c + 50, RND * 2
NEXT


fog1& = _COPYIMAGE(fog&)
_PUTIMAGE (_WIDTH, 0)-(0, _HEIGHT), fog1&
fog2& = _COPYIMAGE(fog1&)

_DEST 0


candies = 7
DIM SHARED candyx(candies), candyy(candies), candya(candies)


'======
restart:
'======

witchflyx = 20
witchflyy = 300

candycount = 0

FOR j = 1 TO candies
    candyx(j) = _WIDTH + (RND * _WIDTH) * 2
    candyy(j) = 40 + (RND * (_HEIGHT - 100))
    candya(j) = RND * 360
NEXT


DO

    'draw candies
    FOR j = 1 TO candies
        RotoZoom3 candyx(j), candyy(j), candy&, 1, 1, _D2R(candya(j))
        candya(j) = candya(j) + 6
        IF candya(j) > 360 THEN candya(j) = 1
    NEXT

    'see if witch hit a candy
    FOR j = 1 TO candies
        wx1 = witchflyx: wy1 = witchflyy
        wx2 = wx1 + 75: wy2 = wy1 + 75
        jx1 = candyx(j): jy1 = candyy(j)
        jx2 = jx1 + 75: jy2 = jy1 + 75

        hit = collision%(wx1, wy1, 75, 75, candyx(j) - 37, candyy(j) - 37, 60, 60)

        IF hit THEN
            CLS
            FOR r = -3 TO 0
                _PUTIMAGE (spos2, 0 + r)-(spos2 + _WIDTH + r, _HEIGHT), fog1&
                _PUTIMAGE (spos2 + _WIDTH + r, 0)-(spos2 + (_WIDTH * 2) + r, _HEIGHT), fog2&
                spos2 = spos2 - 3: IF spos2 <= -_WIDTH THEN spos2 = 0
                'draw jacks
                FOR j2 = 1 TO candies
                    RotoZoom3 candyx(j2), candyy(j2), candy&, 1, 1, _D2R(candya(j2))
                NEXT
                _PUTIMAGE (spos3, 0 + r)-(spos3 + _WIDTH + 800 + r, _HEIGHT + 800), fog1&
                _PUTIMAGE (spos3 + _WIDTH + 800 + r, 0)-(spos3 + ((_WIDTH + 800) * 2) + r, _HEIGHT + 800), fog2&
                spos3 = spos3 - 12: IF spos3 <= -_WIDTH - 800 THEN spos3 = 0
            NEXT

            _DISPLAY

            tmp& = _COPYIMAGE(_DISPLAY)

            'spin witch out here
            r = 1
            FOR dy = witchflyy + 35 TO _HEIGHT STEP 3
                _PUTIMAGE (0, 0), tmp&
                RotoZoom3 witchflyx + 75, dy, witch&, 1, 1, _D2R(r)
                r = r + 5: IF r > 360 THEN r = 1
                _LIMIT 150
                _DISPLAY
            NEXT
            _FREEIMAGE tmp&

            EXIT DO

        END IF

    NEXT


    'move candies, compute
    FOR j = 1 TO candies
        candyx(j) = candyx(j) - 8
        IF candyx(j) < -75 THEN
            candycount = candycount + 1
            'If won...
            IF candycount > 75 THEN
                _DELAY 3
                END
            END IF
            candyx(j) = _WIDTH + (RND * _WIDTH) * 2
            candyy(j) = 40 + (RND * (_HEIGHT - 100))
        END IF
    NEXT

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

    'Here's the witch code....
    'if pressed space, move witch up& forward
    IF INP(&H60) = 57 THEN
        witchflyy = witchflyy - 6
        witchflyx = witchflyx + 6
        spos3 = spos3 - 4 '<-- scroll fog faster too (remove it wanted)
    ELSE
        ' else wich drifts down
        witchflyy = witchflyy + 3
        witchflyx = witchflyx - 2
    END IF

    'keep witch in screen bounds
    IF witchflyx < 5 THEN witchflyx = 5
    IF witchflyx > _WIDTH - 100 THEN witchflyx = _WIDTH - 100
    IF witchflyy < 5 THEN witchflyy = 5
    IF witchflyy > _HEIGHT - 100 THEN witchflyy = _HEIGHT - 100

    _PUTIMAGE (witchflyx, witchflyy), witch&

    LOCATE 1, 1: PRINT "Press SPACE to fly...Avoid touching the candies!";

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

    _PUTIMAGE (spos2, 0)-(spos2 + _WIDTH, _HEIGHT), fog1&
    _PUTIMAGE (spos2 + _WIDTH, 0)-(spos2 + (_WIDTH * 2), _HEIGHT), fog2&
    spos2 = spos2 - 3: IF spos2 <= -_WIDTH THEN spos2 = 0

    _PUTIMAGE (spos3, 0)-(spos3 + _WIDTH + 800, _HEIGHT + 800), fog1&
    _PUTIMAGE (spos3 + _WIDTH + 800, 0)-(spos3 + ((_WIDTH + 800) * 2), _HEIGHT + 800), fog2&
    spos3 = spos3 - 12: IF spos3 <= -_WIDTH - 800 THEN spos3 = 0

    _DISPLAY
    _LIMIT 30
LOOP

GOTO restart


SUB ball (BallX, BallY, size, r&, g&, b&, a&)
    FOR s = 1 TO size STEP .35
        CIRCLE (BallX, BallY), s, _RGBA(r&, g&, b&, a&)
        r& = r& - .5: g& = g& - .5: b& = b& - .5
    NEXT
END SUB



FUNCTION BASIMAGE2& 'witch.png
    v& = _NEWIMAGE(100, 96, 32)
    DIM m AS _MEM: m = _MEMIMAGE(v&)
    A$ = ""
    A$ = A$ + "haIkMV\Bc4447?7mP??NcCRGl5#?XRXX8j11AAa=R8^P;h2^S2^7#Aa3NaK2"
    A$ = A$ + "nDhIO7lJomm_CjhT9Cb<IVNjZ<CMh767UTdeoYk^ZZ[^WLiEib98888THFMe"
    A$ = A$ + "EEGNiUZc>k<=hehJK^iVJXnkGF0H_Q]OQ5FhoG8GMIWMfA]hR;:jB:aXS>JX"
    A$ = A$ + "J#md5Y?Sm0S557]`?mfK_R^`8m``<c<SFC`HOH<#ZKOo5a<?]OVJZYDOla79"
    A$ = A$ + "BOFNiUEgOomR^H9Nla7EaMn53_mfKJ=9OnlR^H9#o5<7Q=VWQjfBc4f#C`k3"
    A$ = A$ + "6;TjfBc2FAC:Y;[_njR^H1#\7fbW\a6K<eMgMWFGfMgM3dgR`0nbMk]gVIeF"
    A$ = A$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_Wo3K_mfZ?olCb]3L0X5nmUQ2#MH^dB;A^mPJhB]V<b8S#^]P3#"
    A$ = A$ + "UNlmgOGnl7\onkWLk07PZeL7af]fJ[YJ_mf9g6`9XB?<m=diEQ1f1>0b?b3?"
    A$ = A$ + "l0YcM8SCm;DOna5glVPLSmlc?[NmeG9g6J;dkm32e2#DggNX?<F?7<fZYV=P"
    A$ = A$ + "?j`ghFJY5b]UF1Re2_JBLcI[I>8XA8W27Ola>]NN\5IQj#YZJ8WahMMUJfQk"
    A$ = A$ + "JBFX_QG#mfT6k1CKY5Q]W4J61[A3gdT\ni_7b5`;_l2ijPX5o27jW8e7GUX["
    A$ = A$ + "A3Rd2i<c=HXh\lAjGDK#><ek;77Y5MgMgRFD7POV^B?j[_n4]84LAm]PaWbj"
    A$ = A$ + "W[HLA?Ti:J<B[jSDNFN6O\MN]THlB>fhl>6aG:?_^\3je;91JQllOdn4ga]T"
    A$ = A$ + "cc]dS6Jo6V_dI9>3nNg\BDmoEVcf=4Vo_bc75gBmZc59f>gC#?_7oj[_Zj\#"
    A$ = A$ + "F`Qh[?1GfO`IA#MLIfoMbIjVPPPPPPPP#S`o0XLK%%h1"
    btemp$ = ""
    FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
        IF INSTR(1, B$, "%") THEN
            FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
                IF F$ <> "%" THEN C$ = C$ + F$
            NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
            IF MID$(B$, j, 1) = "#" THEN
        MID$(B$, j) = "@": END IF: NEXT
        FOR t% = LEN(B$) TO 1 STEP -1
            B& = B& * 64 + ASC(MID$(B$, t%)) - 48
            NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
            X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
    NEXT: btemp$ = btemp$ + X$: NEXT
    btemp$ = _INFLATE$(btemp$, m.SIZE)
    _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
    BASIMAGE2& = _COPYIMAGE(v&): _FREEIMAGE v&
END FUNCTION

FUNCTION BASIMAGE1& 'candy.png
    v& = _NEWIMAGE(75, 75, 32)
    DIM m AS _MEM: m = _MEMIMAGE(v&)
    A$ = ""
    A$ = A$ + "haIkL^ZTR3450UOUE^oBHAR4964[49B\8ARTZh;09B\8AR\gjTZ^CeE6jT>9"
    A$ = A$ + "MBo8GaYHNGY?cmEg9c\HQIa2555555UNcbU;=[F]b\NmjZGimSmeD:bf]K=W"
    A$ = A$ + ">MbLkf=cmkg[NmbU;V37>Di]HOmU:#l3NjicWV?Onl3_Oo^jSMnlI3^DMVI1"
    A$ = A$ + ">Ph8K?Ic[G_<?Nl`LmjeIOL6a<h2G^ZNL6iVkf]KFj[S7?n[l_VPh<ZYag7m"
    A$ = A$ + "1RmeoD1eZ8>Qe__^b>6SlbiB<FOMU]c86SjHcQI<jJ>hgl5ekf_OOak:O[]g"
    A$ = A$ + "4hJLN\G;S=DOVlXQh:L]MNHYV?fflEndGDVG5nko<E`K7keFXAZ_CMWnD[2?"
    A$ = A$ + "SGf\Ic?NZTm5i?M]n^d3TJjT7c\3eME9j;FWMaEfNRh9GNbfGUB=<F_nf;\["
    A$ = A$ + "NBP_^BH_TnFOgNfCkjhMQLOOATO#_\VVOGf78aC#OlT0aSaN=?4Hmo]JFbNo"
    A$ = A$ + "4752GUkaGL]cNQUI747I7;5:?E2m8a3DgZ^K2]S:5OaenDhXBaGOK6LeG^S]"
    A$ = A$ + "VJGUSnRi7RQWbEOik\hS5idlGaXNEMR]3l5fcC\ME>m\24[jkB=;PmMV3gK]"
    A$ = A$ + "H6KQW`A<GlO<VZmZVjn:6NBVoElT0^;Uc7SANXh:K?1bIE7KWh2RkC1?9Tji"
    A$ = A$ + "RC]WJbE0ekS]CLaD=[U?N2hN>UZW5mHg?Tm8h[W0>?]Dni=I\Za;g_R^h:9f"
    A$ = A$ + ":E[K=FaFlcUO?`JgG?9Tb?[9QLodbcO:e2kSWTi]R]CLAXZaKk9V1X?NBVO8"
    A$ = A$ + "EW==4W[UDGZ_iMiBo#X_cVFolkin5=4?U3^RH[^FgZ^WXWo#m4`cTOZV3:dU"
    A$ = A$ + "NRQ>F:GVabVVVgjKgGajWI#8boBei[Li;Ggce#W_E?V:UW]b5=iY#k8kI5Bi"
    A$ = A$ + "Jj]i:iggSALT=YnIHe4DOM\mS=YnISfFLeDiYDoLnJSQ\O^iTW\S]6cl`BaC"
    A$ = A$ + "0[SQ\7hflD>fc[9XgDXWg\4m4#_9jAYiMna#??:1fCL9kY#h[ihOkiM]F?ei"
    A$ = A$ + "8o=WNV[2]_HmkjLHH63nLhDVm?GW5?d>Sl:L2c\b[lnh7nLZSn=bo[JDgXXX"
    A$ = A$ + "XXXXXDNlO<Mg%%h1"
    btemp$ = ""
    FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
        IF INSTR(1, B$, "%") THEN
            FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
                IF F$ <> "%" THEN C$ = C$ + F$
            NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
            IF MID$(B$, j, 1) = "#" THEN
        MID$(B$, j) = "@": END IF: NEXT
        FOR t% = LEN(B$) TO 1 STEP -1
            B& = B& * 64 + ASC(MID$(B$, t%)) - 48
            NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
            X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
    NEXT: btemp$ = btemp$ + X$: NEXT
    btemp$ = _INFLATE$(btemp$, m.SIZE)
    _MEMPUT m, m.OFFSET, btemp$: _MEMFREE m
    BASIMAGE1& = _COPYIMAGE(v&): _FREEIMAGE v&
END FUNCTION

SUB RotoZoom3 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale AS SINGLE, radianRotation AS SINGLE)
    ' This assumes you have set your drawing location with _DEST or default to screen.
    ' X, Y - is where you want to put the middle of the image
    ' Image - is the handle assigned with _LOADIMAGE
    ' xScale, yScale - are shrinkage < 1 or magnification > 1 on the given axis, 1 just uses image size.
    ' These are multipliers so .5 will create image .5 size on given axis and 2 for twice image size.
    ' radianRotation is the Angle in Radian units to rotate the image
    ' note: Radian units for rotation because it matches angle units of other Basic Trig functions
    '       and saves a little time converting from degree.
    '       Use the _D2R() function if you prefer to work in degree units for angles.

    DIM px(3) AS SINGLE: DIM py(3) AS SINGLE ' simple arrays for x, y to hold the 4 corners of image
    DIM W&, H&, sinr!, cosr!, i&, x2&, y2& '   variables for image manipulation
    W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
    px(0) = -W& / 2: py(0) = -H& / 2 'left top corner
    px(1) = -W& / 2: py(1) = H& / 2 ' left bottom corner
    px(2) = W& / 2: py(2) = H& / 2 '  right bottom
    px(3) = W& / 2: py(3) = -H& / 2 ' right top
    sinr! = SIN(-radianRotation): cosr! = COS(-radianRotation) ' rotation helpers
    FOR i& = 0 TO 3 ' calc new point locations with rotation and zoom
        x2& = xScale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = yScale * (py(i&) * cosr! - px(i&) * sinr!) + Y
        px(i&) = x2&: py(i&) = y2&
    NEXT
    _MAPTRIANGLE _SEAMLESS(0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MAPTRIANGLE _SEAMLESS(0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB


FUNCTION collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
    ' x, y represent the box left most x and top most y
    ' w, h represent the box width and height which is the usual way sprites / tiles / images are described
    ' such that boxbottom = by + bh
    '        and boxright = bx + bw
    'so the specific gosub above is generalized to a function procedure here!
    IF (b1y + b1h < b2y) OR (b1y > b2y + b2h) OR (b1x > b2x + b2w) OR (b1x + b1w < b2x) THEN
        collision% = 0
    ELSE
        collision% = -1 ' Collsion is true
    END IF
END FUNCTION

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
RE: Scrolling fog/cloud image for moving background - by Dav - 05-23-2022, 01:43 AM



Users browsing this thread: 1 Guest(s)