Scrollers On Timers
#1
Made some experiments with On Timer() and with the help of Terry Ritchie´s awesome tutorials it turned out quite graphical, so here are the results. Since there is no measured "update" based on passed time, you might want to adjust timer rates for your system. So far, program seems to function as expected but few questions remain. How much workload timers can actually carry? Is there technical limitations to expand use of timers, similarly that I´ve already used them?

Hope you have as much fun to play around with it, as I had writing it. More like a learning journey Smile
   
Code: (Select All)
_TITLE "Scrollers On Timers"
'Created by Hemulius Aug 2022 with QB64 Phoenix Edition version 3.0.0 x64
'
'Controls:
' Esc to quit
' Left mouse button to stop scroller
' Right mouse button to restore default speed
' Mouse wheel up and down to increase and decrease scrolling speed
' Mouse wheel button to set current speed as new default speed
'
'$static
OPTION BASE 0
OPTION _EXPLICIT
OPTION _EXPLICITARRAY
SCREEN _NEWIMAGE(640, 480, 32) ': _FULLSCREEN

COMMON SHARED system_stop AS LONG: system_stop& = &B0 'System running flag

TYPE software_surface_data 'Temporary surfaces for graphics creation
    background AS LONG
    ship AS LONG
    wave1 AS LONG
    wave2 AS LONG
    wave3 AS LONG
    wave4 AS LONG
    wave5 AS LONG
    beach AS LONG
    palm1 AS LONG
    palm2 AS LONG
    palm3 AS LONG
END TYPE

TYPE hardware_surface_data 'Hardware surfaces for drawing to screen
    background AS LONG
    ship AS LONG
    wave1 AS LONG
    wave2 AS LONG
    wave3 AS LONG
    wave4 AS LONG
    wave5 AS LONG
    beach AS LONG
    palm1 AS LONG
    palm2 AS LONG
    palm3 AS LONG
END TYPE

TYPE colordata '= _RGB32() values
    background1 AS LONG
    background2 AS LONG
    background3 AS LONG
    background4 AS LONG
    wave1 AS LONG
    wave2 AS LONG
    wave3 AS LONG
    wave4 AS LONG
    wave5 AS LONG
    beach AS LONG
    ship AS LONG
    palm AS LONG
END TYPE

TYPE parameterdata
    position AS SINGLE
    shipx AS SINGLE
    shipy AS SINGLE
    shipr AS INTEGER
    shipadd AS SINGLE
    wave1x AS SINGLE
    wave1y AS SINGLE
    wave1r AS INTEGER
    wave2x AS SINGLE
    wave2y AS SINGLE
    wave2r AS INTEGER
    wave3x AS SINGLE
    wave3y AS SINGLE
    wave3r AS INTEGER
    wave4x AS SINGLE
    wave4y AS SINGLE
    wave4r AS INTEGER
    wave5x AS SINGLE
    wave5y AS SINGLE
    wave5r AS INTEGER
    beachx AS SINGLE
    beachy AS SINGLE
    palm1x AS SINGLE
    palm2x AS SINGLE
    palm3x AS SINGLE
    palmy AS SINGLE
    speed AS SINGLE
    speed_default AS SINGLE
END TYPE

REDIM software_surface(3) AS software_surface_data
REDIM hardware_surface(3) AS hardware_surface_data
REDIM colors(3) AS colordata
REDIM parameters(3) AS parameterdata

REDIM scroller0_wavedata!(127) 'Wave patterns
REDIM scroller1_wavedata!(127)
REDIM scroller2_wavedata!(127)
REDIM scroller3_wavedata!(127)


'--------= START =--------
set_defaults: create_graphics
free_software_surfaces
_DISPLAYORDER _HARDWARE

DIM controls_timer: controls_timer = _FREETIMER
DIM scrolling_timer: scrolling_timer = _FREETIMER
DIM drawing_timer: drawing_timer = _FREETIMER

DIM controls_rate AS SINGLE: controls_rate! = 0.1000 'User interaction, decrease for less input lag
DIM scrolling_rate AS SINGLE: scrolling_rate! = 0.0100 'Modify values, increase to slow down
DIM drawing_rate AS SINGLE: drawing_rate! = 0.0010 'Draw graphics, increase to decreases frame rate

'Heart of the program pulsing at _rate!
ON TIMER(controls_timer, controls_rate!) controls
ON TIMER(scrolling_timer, scrolling_rate!) scrolling
ON TIMER(drawing_timer, drawing_rate!) drawing

TIMER(controls_timer) ON: TIMER(scrolling_timer) ON: TIMER(drawing_timer) ON

DO: _LIMIT 200: LOOP UNTIL system_stop& = &B1 'Main loop

TIMER(controls_timer) OFF: TIMER(scrolling_timer) OFF: TIMER(drawing_timer) OFF
TIMER(controls_timer) FREE: TIMER(scrolling_timer) FREE: TIMER(drawing_timer) FREE
free_hardware_surfaces
'---------= END =---------
SYSTEM


SUB controls
    SHARED parameters() AS parameterdata 'READ and WRITE parameters

    'Controls
    STATIC addspeed AS SINGLE: addspeed! = 0.0360026 'Speed change per mouse wheel turn
    STATIC kind_of_zero AS SINGLE: kind_of_zero! = 0.0000002 'To prevent glitches when scrolling is stopped at random time
    STATIC key_esc AS LONG: key_esc& = 27
    STATIC mouse_wheel_up AS LONG: mouse_wheel_up& = &B0
    STATIC mouse_wheel_down AS LONG: mouse_wheel_down& = &B0
    STATIC mouse_left_button AS LONG: mouse_left_button& = &B0 'Hold button to select over many
    STATIC mouse_right_button AS LONG: mouse_right_button& = &B0
    STATIC mouse_wheel_button AS LONG: mouse_wheel_button& = &B0
    STATIC mouse_yposition AS LONG: mouse_yposition& = 0 'Mouse Y coordinate

    IF _KEYDOWN(key_esc&) THEN system_stop& = &B1 'Esc to quit

    DO 'Read mouse
        mouse_yposition& = _MOUSEY
        IF _MOUSEWHEEL = -1 THEN mouse_wheel_up& = &B1
        IF _MOUSEWHEEL = 1 THEN mouse_wheel_down& = &B1
        IF _MOUSEBUTTON(1) THEN mouse_left_button& = &B1
        IF _MOUSEBUTTON(2) THEN mouse_right_button& = &B1
        IF _MOUSEBUTTON(3) THEN mouse_wheel_button& = &B1
    LOOP WHILE _MOUSEINPUT

    STATIC mouse_over_scroller AS INTEGER 'Determine mouse position
    IF mouse_yposition& < parameters(1).position! THEN
        mouse_over_scroller% = 0
    END IF
    IF (mouse_yposition& > parameters(1).position!) AND (mouse_yposition& < parameters(2).position!) THEN
        mouse_over_scroller% = 1
    END IF
    IF (mouse_yposition& > parameters(2).position!) AND (mouse_yposition& < parameters(3).position!) THEN
        mouse_over_scroller% = 2
    END IF
    IF (mouse_yposition& > parameters(3).position!) AND (mouse_yposition& < parameters(3).position! + parameters(1).position!) THEN
        mouse_over_scroller% = 3
    END IF

    IF mouse_left_button& = &B1 THEN 'Left to stop scroller
        parameters(mouse_over_scroller%).speed! = kind_of_zero!
        mouse_left_button& = &B0
    END IF

    IF mouse_right_button& = &B1 THEN 'Right to restore default speed
        parameters(mouse_over_scroller%).speed! = parameters(mouse_over_scroller%).speed_default!
        mouse_right_button& = &B0
    END IF

    IF mouse_wheel_button& = &B1 THEN 'Wheel button to set new default speed
        parameters(mouse_over_scroller%).speed_default! = parameters(mouse_over_scroller%).speed!
        mouse_wheel_button& = &B0
    END IF

    IF mouse_wheel_up& = &B1 THEN 'Wheel up to increase speed
        parameters(mouse_over_scroller%).speed! = parameters(mouse_over_scroller%).speed! + addspeed!
        mouse_wheel_up& = &B0
    END IF

    IF mouse_wheel_down& = &B1 THEN 'Wheel down to decrease speed
        parameters(mouse_over_scroller%).speed! = parameters(mouse_over_scroller%).speed! - addspeed!
        IF parameters(mouse_over_scroller%).speed! <= 0 THEN
            parameters(mouse_over_scroller%).speed! = kind_of_zero!
        END IF
        mouse_wheel_down& = &B0
    END IF
END SUB

SUB scrolling
    SHARED parameters() AS parameterdata 'READ and WRITE parameters

    SHARED scroller0_wavedata!()
    SHARED scroller1_wavedata!()
    SHARED scroller2_wavedata!()
    SHARED scroller3_wavedata!()

    STATIC waves_auto_speed AS SINGLE: waves_auto_speed! = 0.0380002
    STATIC left_limit AS SINGLE: left_limit! = -127.0 'Waves screen limitations
    STATIC right_limit AS SINGLE: right_limit! = 639.0
    STATIC last_index AS INTEGER: last_index% = 127 'Last index in wavedata array

    'Scrollers, using scroller 2 wavedata as common wave pattern
    STATIC scroller%
    FOR scroller% = 0 TO 3
        'Ship motion
        parameters(scroller%).shipx! = parameters(scroller%).shipx! - (parameters(scroller%).speed! / 2)
        IF parameters(scroller%).shipx! < -100 THEN parameters(scroller%).shipx! = right_limit!

        parameters(scroller%).shipy! = scroller2_wavedata!(parameters(scroller%).shipr%) + (parameters(scroller%).shipadd! + parameters(scroller%).position!)
        parameters(scroller%).shipr% = parameters(scroller%).shipr% - 1
        IF parameters(scroller%).shipr% < 0 THEN parameters(scroller%).shipr% = last_index%

        'Waves y motion, fixed y addition to place waves apart
        parameters(scroller%).wave1y! = scroller2_wavedata!(parameters(scroller%).wave1r%) + 40.0 + parameters(scroller%).position!
        parameters(scroller%).wave1r% = parameters(scroller%).wave1r% - 1
        IF parameters(scroller%).wave1r% < 0 THEN parameters(scroller%).wave1r% = last_index%

        parameters(scroller%).wave2y! = scroller2_wavedata!(parameters(scroller%).wave2r%) + 46.0 + parameters(scroller%).position!
        parameters(scroller%).wave2r% = parameters(scroller%).wave2r% - 1
        IF parameters(scroller%).wave2r% < 0 THEN parameters(scroller%).wave2r% = last_index%

        parameters(scroller%).wave3y! = scroller2_wavedata!(parameters(scroller%).wave3r%) + 56.0 + parameters(scroller%).position!
        parameters(scroller%).wave3r% = parameters(scroller%).wave3r% - 1
        IF parameters(scroller%).wave3r% < 0 THEN parameters(scroller%).wave3r% = last_index%

        parameters(scroller%).wave4y! = scroller2_wavedata!(parameters(scroller%).wave4r%) + 67.0 + parameters(scroller%).position!
        parameters(scroller%).wave4r% = parameters(scroller%).wave4r% - 1
        IF parameters(scroller%).wave4r% < 0 THEN parameters(scroller%).wave4r% = last_index%

        parameters(scroller%).wave5y! = scroller2_wavedata!(parameters(scroller%).wave5r%) + 80.0 + parameters(scroller%).position!
        parameters(scroller%).wave5r% = parameters(scroller%).wave5r% - 1
        IF parameters(scroller%).wave5r% < 0 THEN parameters(scroller%).wave5r% = last_index%

        'Waves x motion, fixed speed multiplyer to make each wave go faster than other
        parameters(scroller%).wave1x! = (parameters(scroller%).wave1x! - parameters(scroller%).speed!) - (waves_auto_speed! * 2)
        IF parameters(scroller%).wave1x! < left_limit! THEN parameters(scroller%).wave1x! = 0

        parameters(scroller%).wave2x! = (parameters(scroller%).wave2x! - parameters(scroller%).speed!) - (waves_auto_speed! * 4)
        IF parameters(scroller%).wave2x! < left_limit! THEN parameters(scroller%).wave2x! = 0

        parameters(scroller%).wave3x! = (parameters(scroller%).wave3x! - parameters(scroller%).speed!) - (waves_auto_speed! * 6)
        IF parameters(scroller%).wave3x! < left_limit! THEN parameters(scroller%).wave3x! = 0

        parameters(scroller%).wave4x! = (parameters(scroller%).wave4x! - parameters(scroller%).speed!) - (waves_auto_speed! * 8)
        IF parameters(scroller%).wave4x! < left_limit! THEN parameters(scroller%).wave4x! = 0

        parameters(scroller%).wave5x! = (parameters(scroller%).wave5x! - parameters(scroller%).speed!) - (waves_auto_speed! * 10)
        IF parameters(scroller%).wave5x! < left_limit! THEN parameters(scroller%).wave5x! = 0

        'Beach x motion
        parameters(scroller%).beachx! = parameters(scroller%).beachx! - parameters(scroller%).speed!
        IF parameters(scroller%).beachx! < left_limit! THEN parameters(scroller%).beachx! = 0

        'Palms x motion
        parameters(scroller%).palm1x! = parameters(scroller%).palm1x! - parameters(scroller%).speed!
        IF parameters(scroller%).palm1x! < left_limit! THEN parameters(scroller%).palm1x! = right_limit!

        parameters(scroller%).palm2x! = parameters(scroller%).palm2x! - parameters(scroller%).speed!
        IF parameters(scroller%).palm2x! < left_limit! THEN parameters(scroller%).palm2x! = right_limit!

        parameters(scroller%).palm3x! = parameters(scroller%).palm3x! - parameters(scroller%).speed!
        IF parameters(scroller%).palm3x! < left_limit! THEN parameters(scroller%).palm3x! = right_limit!
    NEXT
END SUB

SUB drawing
    SHARED hardware_surface() AS hardware_surface_data 'READ graphics
    SHARED parameters() AS parameterdata 'READ parameters

    STATIC index AS SINGLE: index! = 0
    STATIC value AS SINGLE: value! = 0
    STATIC x AS SINGLE: x! = 0
    STATIC y AS SINGLE: y! = 0
    STATIC tilesize AS SINGLE: tilesize! = 127
    STATIC tilecount AS SINGLE: tilecount! = 6 'Instead of 6, try 4 and add CLS after _DEST to draw partially
    value! = tilecount! * tilesize!
    _DEST 0 ': CLS

    STATIC scroller%
    FOR scroller% = 0 TO 3 'Draw scrollers

        FOR index! = 0 TO value! STEP tilesize!
            x! = index!
            y! = parameters(scroller%).position!
            _PUTIMAGE (x!, y!), hardware_surface(scroller%).background&
        NEXT

        x! = parameters(scroller%).shipx! 'Ship
        y! = parameters(scroller%).shipy!
        _PUTIMAGE (x!, y!), hardware_surface(scroller%).ship&

        FOR index! = 0 TO value! STEP tilesize! 'Waves
            x! = parameters(scroller%).wave1x! + index!
            y! = parameters(scroller%).wave1y!
            _PUTIMAGE (x!, y!), hardware_surface(scroller%).wave1&
        NEXT

        FOR index! = 0 TO value! STEP tilesize!
            x! = parameters(scroller%).wave2x! + index!
            y! = parameters(scroller%).wave2y!
            _PUTIMAGE (x!, y!), hardware_surface(scroller%).wave2&
        NEXT

        FOR index! = 0 TO value! STEP tilesize!
            x! = parameters(scroller%).wave3x! + index!
            y! = parameters(scroller%).wave3y!
            _PUTIMAGE (x!, y!), hardware_surface(scroller%).wave3&
        NEXT

        FOR index! = 0 TO value! STEP tilesize!
            x! = parameters(scroller%).wave4x! + index!
            y! = parameters(scroller%).wave4y!
            _PUTIMAGE (x!, y!), hardware_surface(scroller%).wave4&
        NEXT

        FOR index! = 0 TO value! STEP tilesize!
            x! = parameters(scroller%).wave5x! + index!
            y! = parameters(scroller%).wave5y!
            _PUTIMAGE (x!, y!), hardware_surface(scroller%).wave5&
        NEXT

        FOR index! = 0 TO value! STEP tilesize! 'Beach
            x! = parameters(scroller%).beachx! + index!
            y! = parameters(scroller%).beachy!
            _PUTIMAGE (x!, y!), hardware_surface(scroller%).beach&
        NEXT

        x! = parameters(scroller%).palm1x! 'Palms
        y! = parameters(scroller%).palmy!
        _PUTIMAGE (x!, y!), hardware_surface(scroller%).palm1&

        x! = parameters(scroller%).palm2x!
        y! = parameters(scroller%).palmy!
        _PUTIMAGE (x!, y!), hardware_surface(scroller%).palm2&

        x! = parameters(scroller%).palm3x!
        y! = parameters(scroller%).palmy!
        _PUTIMAGE (x!, y!), hardware_surface(scroller%).palm3&
    NEXT
    _DISPLAY
END SUB

SUB create_graphics
    SHARED colors() AS colordata 'READ colors
    SHARED software_surface() AS software_surface_data 'WRITE graphics

    SHARED scroller0_wavedata!()
    SHARED scroller1_wavedata!()
    SHARED scroller2_wavedata!()
    SHARED scroller3_wavedata!()

    STATIC palmtree%(137) 'Line drawing coordinates
    STATIC pirateship%(111)

    STATIC index AS SINGLE: index! = 0
    STATIC value AS SINGLE: value! = 0

    FOR index! = 0 TO 3
        software_surface(index!).background& = _NEWIMAGE(127, 100, 32) 'Backgrounds
    NEXT
    FOR index! = 0 TO 127
        FOR value! = 0 TO 16
            _DEST software_surface(0).background&: PSET (index!, value!), colors(0).background1&
            _DEST software_surface(1).background&: PSET (index!, value!), colors(1).background1&
            _DEST software_surface(2).background&: PSET (index!, value!), colors(2).background1&
            _DEST software_surface(3).background&: PSET (index!, value!), colors(3).background1&
        NEXT
    NEXT
    FOR index! = 0 TO 127
        FOR value! = 0 TO 16
            _DEST software_surface(0).background&: PSET (index!, value! + 16), colors(0).background2&
            _DEST software_surface(1).background&: PSET (index!, value! + 16), colors(1).background2&
            _DEST software_surface(2).background&: PSET (index!, value! + 16), colors(2).background2&
            _DEST software_surface(3).background&: PSET (index!, value! + 16), colors(3).background2&
        NEXT
    NEXT
    FOR index! = 0 TO 127
        FOR value! = 0 TO 16
            _DEST software_surface(0).background&: PSET (index!, value! + 32), colors(0).background3&
            _DEST software_surface(1).background&: PSET (index!, value! + 32), colors(1).background3&
            _DEST software_surface(2).background&: PSET (index!, value! + 32), colors(2).background3&
            _DEST software_surface(3).background&: PSET (index!, value! + 32), colors(3).background3&
        NEXT
    NEXT
    FOR index! = 0 TO 127
        FOR value! = 0 TO 16
            _DEST software_surface(0).background&: PSET (index!, value! + 48), colors(0).background4&
            _DEST software_surface(1).background&: PSET (index!, value! + 48), colors(1).background4&
            _DEST software_surface(2).background&: PSET (index!, value! + 48), colors(2).background4&
            _DEST software_surface(3).background&: PSET (index!, value! + 48), colors(3).background4&
        NEXT
    NEXT

    FOR index! = 0 TO 3 'Ships
        software_surface(index!).ship& = _NEWIMAGE(70, 50, 32)
    NEXT
    RESTORE pirateshipdata: FOR index! = 0 TO 111: READ value!: pirateship%(index!) = value!: NEXT

    _DEST software_surface(0).ship&: COLOR colors(0).ship&: LINE (pirateship%(0), pirateship%(1))-(pirateship%(2), pirateship%(3))
    _DEST software_surface(1).ship&: COLOR colors(1).ship&: LINE (pirateship%(0), pirateship%(1))-(pirateship%(2), pirateship%(3))
    _DEST software_surface(2).ship&: COLOR colors(2).ship&: LINE (pirateship%(0), pirateship%(1))-(pirateship%(2), pirateship%(3))
    _DEST software_surface(3).ship&: COLOR colors(3).ship&: LINE (pirateship%(0), pirateship%(1))-(pirateship%(2), pirateship%(3))

    FOR index! = 4 TO 111 STEP 2
        _DEST software_surface(0).ship&: LINE -(pirateship%(index!), pirateship%(index! + 1))
        _DEST software_surface(1).ship&: LINE -(pirateship%(index!), pirateship%(index! + 1))
        _DEST software_surface(2).ship&: LINE -(pirateship%(index!), pirateship%(index! + 1))
        _DEST software_surface(3).ship&: LINE -(pirateship%(index!), pirateship%(index! + 1))
    NEXT

    _DEST software_surface(0).ship&: PAINT (16, 26): PAINT (36, 8): PAINT (36, 25): PAINT (36, 39): PAINT (52, 20)
    _DEST software_surface(1).ship&: PAINT (16, 26): PAINT (36, 8): PAINT (36, 25): PAINT (36, 39): PAINT (52, 20)
    _DEST software_surface(2).ship&: PAINT (16, 26): PAINT (36, 8): PAINT (36, 25): PAINT (36, 39): PAINT (52, 20)
    _DEST software_surface(3).ship&: PAINT (16, 26): PAINT (36, 8): PAINT (36, 25): PAINT (36, 39): PAINT (52, 20)

    pirateshipdata: '0-3=line, 4-103=line-x,y pairs
    DATA 60,42,23,42,11,34,0,28,4,28,23,36,35,36,35,32,28,33,26,26,28,15,35,14,35,12,32,12,30,10,29,8,23,20,24,34
    DATA 17,29,6,27,29,6,31,2,35,2,35,0,36,0,36,2,43,2,42,7,43,11,36,12,36,14,44,13,42,22,44,33,36,32,36,36,48,36
    DATA 50,33,54,33,54,29,47,29,45,19,48,6,54,6,54,2,55,2,55,6,62,4,60,17,62,30,55,29,55,33,67,32,68,34,66,39,60,42

    'Waves
    FOR index! = 0 TO 3
        software_surface(index!).wave1& = _NEWIMAGE(127, 40, 32)
        software_surface(index!).wave2& = _NEWIMAGE(127, 40, 32)
        software_surface(index!).wave3& = _NEWIMAGE(127, 40, 32)
        software_surface(index!).wave4& = _NEWIMAGE(127, 40, 32)
        software_surface(index!).wave5& = _NEWIMAGE(127, 40, 32)
    NEXT
    FOR index! = 0 TO 127 'Scroller 0 waves
        FOR value! = scroller0_wavedata!(index!) TO 40
            _DEST software_surface(0).wave1&: PSET (index!, value!), colors(0).wave1&
            _DEST software_surface(0).wave2&: PSET (index!, value!), colors(0).wave2&
            _DEST software_surface(0).wave3&: PSET (index!, value!), colors(0).wave3&
            _DEST software_surface(0).wave4&: PSET (index!, value!), colors(0).wave4&
            _DEST software_surface(0).wave5&: PSET (index!, value!), colors(0).wave5&
        NEXT
    NEXT
    FOR index! = 0 TO 127 'Scroller 1 waves
        FOR value! = scroller1_wavedata!(index!) TO 40
            _DEST software_surface(1).wave1&: PSET (index!, value!), colors(1).wave1&
            _DEST software_surface(1).wave2&: PSET (index!, value!), colors(1).wave2&
            _DEST software_surface(1).wave3&: PSET (index!, value!), colors(1).wave3&
            _DEST software_surface(1).wave4&: PSET (index!, value!), colors(1).wave4&
            _DEST software_surface(1).wave5&: PSET (index!, value!), colors(1).wave5&
        NEXT
    NEXT
    FOR index! = 0 TO 127 'Scroller 2 waves
        FOR value! = scroller2_wavedata!(index!) TO 40
            _DEST software_surface(2).wave1&: PSET (index!, value!), colors(2).wave1&
            _DEST software_surface(2).wave2&: PSET (index!, value!), colors(2).wave2&
            _DEST software_surface(2).wave3&: PSET (index!, value!), colors(2).wave3&
            _DEST software_surface(2).wave4&: PSET (index!, value!), colors(2).wave4&
            _DEST software_surface(2).wave5&: PSET (index!, value!), colors(2).wave5&
        NEXT
    NEXT
    FOR index! = 0 TO 127 'Scroller 3 waves
        FOR value! = scroller3_wavedata!(index!) TO 40
            _DEST software_surface(3).wave1&: PSET (index!, value!), colors(3).wave1&
            _DEST software_surface(3).wave2&: PSET (index!, value!), colors(3).wave2&
            _DEST software_surface(3).wave3&: PSET (index!, value!), colors(3).wave3&
            _DEST software_surface(3).wave4&: PSET (index!, value!), colors(3).wave4&
            _DEST software_surface(3).wave5&: PSET (index!, value!), colors(3).wave5&
        NEXT
    NEXT

    FOR index! = 0 TO 3 'Beaches
        software_surface(index!).beach& = _NEWIMAGE(127, 40, 32)
    NEXT
    FOR index! = 0 TO 127
        FOR value! = scroller1_wavedata!(index!) TO 40 'Each beach is scroller1 type of wavedata
            _DEST software_surface(0).beach&: PSET (index!, value!), colors(0).beach&
            _DEST software_surface(1).beach&: PSET (index!, value!), colors(1).beach&
            _DEST software_surface(2).beach&: PSET (index!, value!), colors(2).beach&
            _DEST software_surface(3).beach&: PSET (index!, value!), colors(3).beach&
        NEXT
    NEXT

    FOR index! = 0 TO 3 'Palmtrees
        software_surface(index!).palm1& = _NEWIMAGE(127, 115, 32)
        software_surface(index!).palm2& = _NEWIMAGE(127, 115, 32)
        software_surface(index!).palm3& = _NEWIMAGE(127, 115, 32)
    NEXT
    RESTORE palmtreedata: FOR index! = 0 TO 137: READ value!: palmtree%(index!) = value!: NEXT

    _DEST software_surface(0).palm1&: COLOR colors(0).palm&: LINE (palmtree%(0), palmtree%(1))-(palmtree%(2), palmtree%(3))
    _DEST software_surface(1).palm1&: COLOR colors(1).palm&: LINE (palmtree%(0), palmtree%(1))-(palmtree%(2), palmtree%(3))
    _DEST software_surface(2).palm1&: COLOR colors(2).palm&: LINE (palmtree%(0), palmtree%(1))-(palmtree%(2), palmtree%(3))
    _DEST software_surface(3).palm1&: COLOR colors(3).palm&: LINE (palmtree%(0), palmtree%(1))-(palmtree%(2), palmtree%(3))

    FOR index! = 4 TO 136 STEP 2
        _DEST software_surface(0).palm1&: LINE -(palmtree%(index!), palmtree%(index! + 1))
        _DEST software_surface(1).palm1&: LINE -(palmtree%(index!), palmtree%(index! + 1))
        _DEST software_surface(2).palm1&: LINE -(palmtree%(index!), palmtree%(index! + 1))
        _DEST software_surface(3).palm1&: LINE -(palmtree%(index!), palmtree%(index! + 1))
    NEXT

    _DEST software_surface(0).palm1&: PAINT (35, 110)
    _DEST software_surface(1).palm1&: PAINT (35, 110)
    _DEST software_surface(2).palm1&: PAINT (35, 110)
    _DEST software_surface(3).palm1&: PAINT (35, 110)

    _DEST software_surface(0).palm2&: _PUTIMAGE (127, 0)-(0, 115), software_surface(0).palm1& 'Palm 2 is flipped to lean left
    _DEST software_surface(0).palm3&: _PUTIMAGE (10, 20)-(127, 115), software_surface(0).palm1& 'Palm 3 is resized

    _DEST software_surface(1).palm2&: _PUTIMAGE (127, 0)-(0, 115), software_surface(1).palm1&
    _DEST software_surface(1).palm3&: _PUTIMAGE (20, 25)-(127, 115), software_surface(1).palm1&

    _DEST software_surface(2).palm2&: _PUTIMAGE (127, 0)-(0, 115), software_surface(2).palm1&
    _DEST software_surface(2).palm3&: _PUTIMAGE (12, 15)-(127, 115), software_surface(2).palm1&

    _DEST software_surface(3).palm2&: _PUTIMAGE (127, 0)-(0, 115), software_surface(3).palm1&
    _DEST software_surface(3).palm3&: _PUTIMAGE (18, 30)-(127, 115), software_surface(3).palm1&

    palmtreedata: '0-3=line, 4-137=line-x,y pairs
    DATA 30,113,28,104,26,91,26,72,31,51,39,34,26,35,26,29,21,37,12,41,12,34,8,42,0,44,1,33,8,24,15,20,28,20,35,22,28,15,33,13,24,12,20,8,22
    DATA 6,14,4,12,2,23,0,35,3,40,9,43,20,48,10,52,6,62,4,66,5,60,10,54,11,58,13,54,17,50,17,52,19,50,22,60,18,68,16,77,18,84,24,83,28,77,28
    DATA 70,22,72,29,65,29,60,25,60,29,51,31,65,36,73,43,75,50,74,58,70,64,65,59,64,45,60,51,55,46,56,39,52,42,44,34,37,54,35,79,38,97,43,113,30,113
END SUB

SUB set_defaults
    SHARED colors() AS colordata 'WRITE values
    SHARED parameters() AS parameterdata 'WRITE values

    SHARED scroller0_wavedata!()
    SHARED scroller1_wavedata!()
    SHARED scroller2_wavedata!()
    SHARED scroller3_wavedata!()

    STATIC index AS SINGLE: index! = 0
    STATIC value AS SINGLE: value! = 0

    colors(0).background1& = _RGB32(238, 61, 121) 'Scroller 0 colors
    colors(0).background2& = _RGB32(239, 82, 119)
    colors(0).background3& = _RGB32(246, 120, 117)
    colors(0).background4& = _RGB32(249, 146, 111)
    colors(0).wave1& = _RGB32(0, 138, 162)
    colors(0).wave2& = _RGB32(0, 155, 170)
    colors(0).wave3& = _RGB32(0, 183, 197)
    colors(0).wave4& = _RGB32(46, 197, 215)
    colors(0).wave5& = _RGB32(115, 209, 221)
    colors(0).beach& = _RGB32(107, 11, 59)
    colors(0).ship& = colors(0).wave1&
    colors(0).palm& = colors(0).beach&

    colors(1).background1& = _RGB32(86, 90, 255) 'Scroller 1 colors
    colors(1).background2& = _RGB32(97, 100, 255)
    colors(1).background3& = _RGB32(108, 111, 255)
    colors(1).background4& = _RGB32(118, 121, 255)
    colors(1).wave1& = _RGB32(13, 38, 110)
    colors(1).wave2& = _RGB32(15, 45, 125)
    colors(1).wave3& = _RGB32(17, 58, 139)
    colors(1).wave4& = _RGB32(19, 72, 168)
    colors(1).wave5& = _RGB32(21, 87, 191)
    colors(1).beach& = _RGB32(0, 25, 124)
    colors(1).ship& = colors(1).wave1&
    colors(1).palm& = colors(1).beach&

    colors(2).background1& = _RGB32(137, 173, 113) 'Scroller 2 colors
    colors(2).background2& = _RGB32(113, 187, 137)
    colors(2).background3& = _RGB32(88, 202, 160)
    colors(2).background4& = _RGB32(63, 217, 184)
    colors(2).wave1& = _RGB32(15, 135, 221)
    colors(2).wave2& = _RGB32(39, 146, 221)
    colors(2).wave3& = _RGB32(64, 166, 221)
    colors(2).wave4& = _RGB32(89, 186, 221)
    colors(2).wave5& = _RGB32(114, 206, 221)
    colors(2).beach& = _RGB32(10, 82, 91)
    colors(2).ship& = colors(2).wave1&
    colors(2).palm& = colors(2).beach&

    colors(3).background1& = _RGB32(93, 55, 218) 'Scroller 3 colors
    colors(3).background2& = _RGB32(112, 58, 201)
    colors(3).background3& = _RGB32(126, 61, 181)
    colors(3).background4& = _RGB32(138, 62, 175)
    colors(3).wave1& = _RGB32(12, 88, 189)
    colors(3).wave2& = _RGB32(19, 99, 190)
    colors(3).wave3& = _RGB32(20, 116, 197)
    colors(3).wave4& = _RGB32(26, 144, 214)
    colors(3).wave5& = _RGB32(35, 169, 221)
    colors(3).beach& = _RGB32(75, 28, 96)
    colors(3).ship& = colors(3).wave1&
    colors(3).palm& = colors(3).beach&

    parameters(0).position! = 0.0 'Scroller 0 parameters, top left y position
    parameters(0).shipx! = 510.0
    parameters(0).shipy! = 0.0
    parameters(0).shipr% = 122 'R value is starting index in wavedata
    parameters(0).shipadd! = 9.0 'Ship fixed y addition so bottom of the ship stay below the lowest point of wave
    parameters(0).wave1x! = 0.0
    parameters(0).wave1y! = 0.0
    parameters(0).wave1r% = 0
    parameters(0).wave2x! = 0.0
    parameters(0).wave2y! = 0.0
    parameters(0).wave2r% = 5
    parameters(0).wave3x! = 0.0
    parameters(0).wave3y! = 0.0
    parameters(0).wave3r% = 10
    parameters(0).wave4x! = 0.0
    parameters(0).wave4y! = 0.0
    parameters(0).wave4r% = 15
    parameters(0).wave5x! = 0.0
    parameters(0).wave5y! = 0.0
    parameters(0).wave5r% = 20
    parameters(0).beachx! = 0.0
    parameters(0).beachy! = 100.0 + parameters(0).position!
    parameters(0).palm1x! = 180.0
    parameters(0).palm2x! = -40.0
    parameters(0).palm3x! = 450.0
    parameters(0).palmy! = 8 + parameters(0).position!
    parameters(0).speed! = 0.3360026
    parameters(0).speed_default! = 0.7380004

    parameters(1).position! = 120.0 'Scroller 1 parameters
    parameters(1).shipx! = 470.0
    parameters(1).shipy! = 0.0
    parameters(1).shipr% = 20
    parameters(1).shipadd! = 5.0
    parameters(1).wave1x! = 0.0
    parameters(1).wave1y! = 0.0
    parameters(1).wave1r% = 25
    parameters(1).wave2x! = 0.0
    parameters(1).wave2y! = 0.0
    parameters(1).wave2r% = 30
    parameters(1).wave3x! = 0.0
    parameters(1).wave3y! = 0.0
    parameters(1).wave3r% = 35
    parameters(1).wave4x! = 0.0
    parameters(1).wave4y! = 0.0
    parameters(1).wave4r% = 40
    parameters(1).wave5x! = 0.0
    parameters(1).wave5y! = 0.0
    parameters(1).wave5r% = 45
    parameters(1).beachx! = 0.0
    parameters(1).beachy! = 100.0 + parameters(1).position!
    parameters(1).palm1x! = 380.0
    parameters(1).palm2x! = 60.0
    parameters(1).palm3x! = 540.0
    parameters(1).palmy! = 3 + parameters(1).position!
    parameters(1).speed! = 0.3360026
    parameters(1).speed_default! = 0.8360006

    parameters(2).position! = 240.0 'Scroller 2 parameters
    parameters(2).shipx! = 360.0
    parameters(2).shipy! = 0.0
    parameters(2).shipr% = 45
    parameters(2).shipadd! = 11.0
    parameters(2).wave1x! = 0.0
    parameters(2).wave1y! = 0.0
    parameters(2).wave1r% = 50
    parameters(2).wave2x! = 0.0
    parameters(2).wave2y! = 0.0
    parameters(2).wave2r% = 55
    parameters(2).wave3x! = 0.0
    parameters(2).wave3y! = 0.0
    parameters(2).wave3r% = 60
    parameters(2).wave4x! = 0.0
    parameters(2).wave4y! = 0.0
    parameters(2).wave4r% = 65
    parameters(2).wave5x! = 0.0
    parameters(2).wave5y! = 0.0
    parameters(2).wave5r% = 70
    parameters(2).beachx! = 0.0
    parameters(2).beachy! = 100.0 + parameters(2).position!
    parameters(2).palm1x! = 520.0
    parameters(2).palm2x! = 195.0
    parameters(2).palm3x! = 10.0
    parameters(2).palmy! = 6 + parameters(2).position!
    parameters(2).speed! = 0.3360026
    parameters(2).speed_default! = 1.0000010

    parameters(3).position! = 360.0 'Scroller 3 parameters
    parameters(3).shipx! = 410.0
    parameters(3).shipy! = 0.0
    parameters(3).shipr% = 70
    parameters(3).shipadd! = 12.0
    parameters(3).wave1x! = 0.0
    parameters(3).wave1y! = 0.0
    parameters(3).wave1r% = 75
    parameters(3).wave2x! = 0.0
    parameters(3).wave2y! = 0.0
    parameters(3).wave2r% = 80
    parameters(3).wave3x! = 0.0
    parameters(3).wave3y! = 0.0
    parameters(3).wave3r% = 85
    parameters(3).wave4x! = 0.0
    parameters(3).wave4y! = 0.0
    parameters(3).wave4r% = 90
    parameters(3).wave5x! = 0.0
    parameters(3).wave5y! = 0.0
    parameters(3).wave5r% = 95
    parameters(3).beachx! = 0.0
    parameters(3).beachy! = 100.0 + parameters(3).position!
    parameters(3).palm1x! = 500.0
    parameters(3).palm2x! = 198.0
    parameters(3).palm3x! = 302.0
    parameters(3).palmy! = 11 + parameters(3).position!
    parameters(3).speed! = 0.3360026
    parameters(3).speed_default! = 1.1100010

    'Waves data
    RESTORE wave0: FOR index! = 0 TO 127: READ value!: value! = value! + 0.0000002: scroller0_wavedata!(index!) = value!: NEXT
    RESTORE wave1: FOR index! = 0 TO 127: READ value!: value! = value! + 0.0000002: scroller1_wavedata!(index!) = value!: NEXT
    RESTORE wave2: FOR index! = 0 TO 127: READ value!: value! = value! + 0.0000002: scroller2_wavedata!(index!) = value!: NEXT
    RESTORE wave3: FOR index! = 0 TO 127: READ value!: value! = value! + 0.0000002: scroller3_wavedata!(index!) = value!: NEXT

    wave0: DATA 2,3,3,4,5,6,6,6,7,7,7,8,8,8,8,8,8,8,8,8,8,7,7,7,6,6,6,5,6,7,7,8,8,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,9,9,9,9,9,9,8,8,7,7,6,5,4,4,4,5,6,6,6,7,7,7,8,8,8,8,8,8,8,8,8,8,7,7,7,6,6,6,5,4,3,2,1,2,3,3,4,5,6,6,6,7,7,7,8,8,8,8,8,8,8,8,8,8,7,7,7,6,6,6,5,4,3,3,1
    wave1: DATA 4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,4,4,4,4,4
    wave2: DATA 8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,9,9,9,9,8,8,8,7,7,7,6,5,5,4,3,3,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8
    wave3: DATA 3,4,4,5,5,6,6,7,8,8,8,9,9,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,10,10,10,10,9,9,8,8,7,7,5,5,3,1,0,1,2,3,4,4,5,5,6,6,7,8,8,8,9,9,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,10,10,10,10,9,9,8,8,7,7,5,5,3,1,0,1,2
END SUB

SUB free_software_surfaces
    SHARED software_surface() AS software_surface_data 'FREE
    SHARED hardware_surface() AS hardware_surface_data 'WRITE copy of surfaces
    STATIC scroller%

    FOR scroller% = 0 TO 3 'Copy all software_surface() arrays to videohardware handles
        hardware_surface(scroller%).background& = _COPYIMAGE(software_surface(scroller%).background&, 33)
        hardware_surface(scroller%).ship& = _COPYIMAGE(software_surface(scroller%).ship&, 33)
        hardware_surface(scroller%).wave1& = _COPYIMAGE(software_surface(scroller%).wave1&, 33)
        hardware_surface(scroller%).wave2& = _COPYIMAGE(software_surface(scroller%).wave2&, 33)
        hardware_surface(scroller%).wave3& = _COPYIMAGE(software_surface(scroller%).wave3&, 33)
        hardware_surface(scroller%).wave4& = _COPYIMAGE(software_surface(scroller%).wave4&, 33)
        hardware_surface(scroller%).wave5& = _COPYIMAGE(software_surface(scroller%).wave5&, 33)
        hardware_surface(scroller%).beach& = _COPYIMAGE(software_surface(scroller%).beach&, 33)
        hardware_surface(scroller%).palm1& = _COPYIMAGE(software_surface(scroller%).palm1&, 33)
        hardware_surface(scroller%).palm2& = _COPYIMAGE(software_surface(scroller%).palm2&, 33)
        hardware_surface(scroller%).palm3& = _COPYIMAGE(software_surface(scroller%).palm3&, 33)
    NEXT

    FOR scroller% = 0 TO 3 'Free software surfaces
        _FREEIMAGE software_surface(scroller%).background&
        _FREEIMAGE software_surface(scroller%).ship&
        _FREEIMAGE software_surface(scroller%).wave1&
        _FREEIMAGE software_surface(scroller%).wave2&
        _FREEIMAGE software_surface(scroller%).wave3&
        _FREEIMAGE software_surface(scroller%).wave4&
        _FREEIMAGE software_surface(scroller%).wave5&
        _FREEIMAGE software_surface(scroller%).beach&
        _FREEIMAGE software_surface(scroller%).palm1&
        _FREEIMAGE software_surface(scroller%).palm2&
        _FREEIMAGE software_surface(scroller%).palm3&
    NEXT
END SUB

SUB free_hardware_surfaces
    SHARED hardware_surface() AS hardware_surface_data 'FREE
    STATIC scroller%
    FOR scroller% = 0 TO 3
        _FREEIMAGE hardware_surface(scroller%).background&
        _FREEIMAGE hardware_surface(scroller%).ship&
        _FREEIMAGE hardware_surface(scroller%).wave1&
        _FREEIMAGE hardware_surface(scroller%).wave2&
        _FREEIMAGE hardware_surface(scroller%).wave3&
        _FREEIMAGE hardware_surface(scroller%).wave4&
        _FREEIMAGE hardware_surface(scroller%).wave5&
        _FREEIMAGE hardware_surface(scroller%).beach&
        _FREEIMAGE hardware_surface(scroller%).palm1&
        _FREEIMAGE hardware_surface(scroller%).palm2&
        _FREEIMAGE hardware_surface(scroller%).palm3&
    NEXT
END SUB
Reply


Messages In This Thread
Scrollers On Timers - by Hemulius - 08-30-2022, 11:02 AM
RE: Scrollers On Timers - by OldMoses - 08-30-2022, 11:52 AM
RE: Scrollers On Timers - by James D Jarvis - 08-30-2022, 01:43 PM
RE: Scrollers On Timers - by TempodiBasic - 08-30-2022, 02:36 PM
RE: Scrollers On Timers - by bplus - 08-30-2022, 04:22 PM



Users browsing this thread: 2 Guest(s)