Posted: 19th Feb 2003 21:21
Why post a code snippet when you can post 3?

A join the dots program (you draw - the computer joins!)
+ Code Snippet
Rem Project: pattern
Rem Created: 23/01/03 16:35:13

Rem ***** Main Source File *****
Rem By Shadow



sync on: sync rate 100: set display mode 320,240,16

maxx=319: maxy=219
dim screen(maxx,maxy)

do
cls

    for x=0 to maxx
    for y=0 to maxy

        if screen(x,y)=1 then box x,y,x+1,y+1

    next y
    next x

    moc=mouseclick()
    if moc>0
       mox=mousex():moy=mousey()
       if moc=1 then screen(mox,moy)=1
       if moc=2 then screen(mox,moy)=0
    endif

    if rightkey() and keytimer=0 and k  0 then dec k: keytimer=5

    text 10,220,str$(screen fps())
    text 160,220,"Range: "+str$(k+2)

    if returnkey() then join(319,219,k+2)

    if keytimer>0 then dec keytimer

sync
loop

function join(maxx,maxy,maxr)

    for x=0 to maxx
    for y=0 to maxy
        if screen(x,y)=1
            for r=0 to maxr
                for ang=0 to 360 step 10
                    nx=x+sin(ang)*r
                    ny=y+cos(ang)*r
                    if screen(nx,ny)=1 then line x,y,nx,ny
                next ang
            next r
        endif
    next y
    next x

    sync

    wait key

endfunction


2 simple games:

Don't get hit (really imaginative name)
+ Code Snippet
Rem Project: simple thing
Rem Created: 05/02/03 19:41:44

Rem ***** Main Source File *****
Rem ***** Shadow ***************



sync on
t$="Don't get hit!"
sh=len(t$)
bx=320:by=240
shotx#=bx:shoty#=by
sv#=4
rad=50
bvx#=1:bvy#=1
init#=timer()

repeat
cls
text 1,1, "PRESS ANY KEY TO START"
sync
until scancode()>0


do
cls

    mox=mousex():moy=mousey()

    center text bx,by-8,"[x]"

    center text shotx#,shoty#-8,"o"

    if new0=0 then sa=wrapvalue(atanfull(mousex()-bx,by-mousey())): new0=1

    inc bx,bvx#
    inc by,bvy#
    if bx640 then bvx#=bvx#*-1
    if by480 then bvy#=bvy#*-1

    inc shotx#,sin(sa)*sv#
    dec shoty#,cos(sa)*sv#

    if shotx#640 or shoty#480 then new0=0: shotx#=bx:shoty#=by

    dx#=shotx#-mox: dy#=shoty#-moy

    if sqrt(dx#*dx#+dy#*dy#)0 or mouseclick()>0
        end
    endif

    text 0,450,str$(sa)

    showsh(t$,mox,moy,rad,ang,sh)
    ang=wrapvalue(ang+1)

sync
loop


function showsh(tex$,x,y,r,a,shi)
    circle mousex(),mousey(),r
    da=360/shi
    for i=1 to shi
        center text x+r*sin(a+da*i),y-r*cos(a+da*i)-8,mid$(tex$,i)
    next i
endfunction


and Lizard Tongue

+ Code Snippet
Rem Project: reactions
Rem Created: 16/02/03 19:51:17

Rem ***** Main Source File *****

sync on:sync rate 60:hide mouse

dim level$(18)

for i=1 to 18: read level$(i): next i

repeat
    cls
    center text 320,10,"Lizard Tongue"
    center text 320,140,"Select Difficulty"

    for i=1 to 9
        center text 320,140+20*i,str$(i)+" - "+level$(i)
    next i

    a$=inkey$(): diff=val(a$)
    sync
until diff>0 and diff640 then bad(i,1)=0
            if y480 then bad(i,2)=0
            if x0 > x-7 and x0 y-7 and y012
            max=10
            diff=diff+1
            if diff=10 then halfway()
            if diff>18 then finish()
            r#=1-0.025*diff
        endif
        remaining=max: generate(max)
    endif

    inc px,movex#
    inc py,movey#

    px=px*r#
    py=py*r#

    x0=320+px:y0=240+py

    if gfx=1
        for i=1 to mai
            i#=i: mai#=mai
            c=(255*i#)/mai#
            ink rgb(c,0,(255-c)/4),0
            line 320,240,afterimage(i,0),afterimage(i,1)
        next i
        ink -1,0
    endif

    circle 320,240,3: circle x0,y0,5
    line 320,240,x0,y0

    if gfx=1
        for i=0 to 1
            for j=1 to mai-1
                afterimage(j,i)=afterimage(j+1,i)
            next j
        next i
        afterimage(mai,0)=x0
        afterimage(mai,1)=y0
    endif

    text 10,10,Level$(diff)+" Level"
    center text 320,10,"Lizard Tongue"
    text 540,10,"Stage "+str$(max-9)
    text 10,450,str$(remaining)+" flies remaining"
    text 540,450,str$(screen fps())

    if spacekey() then remaining=0:max=13:diff=17

    sync
loop

data "Baby","Child","Beginner","Intermediate","Skilled","Veteran","Expert","Master","Grand Master"
data "Baby God","Child God","Beginner God","Intermediate God","Skilled God","Veteran God","Expert God","Master God","Grand Master God"


function generate(n)
    for i=1 to n
        bad(i,0)=1
        bad(i,1)=rnd(640)
        bad(i,2)=rnd(480)
        repeat: a=rnd(8)-4: until a  0
        bad(i,3)=a
        repeat: a=rnd(6)-3: until a  0
        bad(i,4)=a
    next i
    for i=n+1 to 100
        bad(i,0)=0
    next i
endfunction

function halfway()
    repeat
        center text 320,180,"YOU HAVE COMPLETELY LIZARD TONGUE ON MORTAL LEVEL - PLAY GOD LEVEL?"
        sync
    until scancode()>0
endfunction

function finish()
    repeat
        center text 320,180,"YOU HAVE COMPLETED LIZARD TONGUE ON GOD LEVEL. CONGRATULATIONS."
        sync
    until scancode()>0
    end
endfunction
Posted: 20th Feb 2003 23:09
No-one interested? These are three working programs and I'm giving the code away for free!
Posted: 20th Feb 2003 23:14
I am aware there are errors in these snippets (forum's fault). I will fix soon.
Posted: 21st Feb 2003 20:14
Let's hope forum doesn't destroy code this time:

Draw something - computer will join up gaps
+ Code Snippet
Rem Project: pattern
Rem Created: 23/01/03 16:35:13

Rem ***** Main Source File *****
Rem By Shadow


sync on: sync rate 100: set display mode 320,240,16

maxx=319: maxy=219
dim screen(maxx,maxy)

do
cls

    for x=0 to maxx
    for y=0 to maxy

        if screen(x,y)=1 then box x,y,x+1,y+1

    next y
    next x

    moc=mouseclick()
    if moc>0
       mox=mousex():moy=mousey()
       if moc=1 then screen(mox,moy)=1
       if moc=2 then screen(mox,moy)=0
    endif

    if rightkey() and keytimer=0 and k < 48 then inc k:keytimer=5
    if leftkey() and keytimer=0 and k > 0 then dec k: keytimer=5

    text 10,220,str$(screen fps())
    text 160,220,"Range: "+str$(k+2)

    if returnkey() then join(319,219,k+2)

    if keytimer>0 then dec keytimer

sync
loop

function join(maxx,maxy,maxr)

    for x=0 to maxx
    for y=0 to maxy
        if screen(x,y)=1
            for r=0 to maxr
                for ang=0 to 360 step 10
                    nx=x+sin(ang)*r
                    ny=y+cos(ang)*r
                    if screen(nx,ny)=1 then line x,y,nx,ny
                next ang
            next r
        endif
    next y
    next x

    sync

    wait key

endfunction


Move player around and don't get shot down:
+ Code Snippet
Rem Project: simple thing
Rem Created: 05/02/03 19:41:44

Rem ***** Main Source File *****
Rem ***** Shadow ***************



sync on
t$="Don't get hit!"
sh=len(t$)
bx=320:by=240
shotx#=bx:shoty#=by
sv#=4
rad=50
bvx#=1:bvy#=1
init#=timer()

repeat
cls
text 1,1, "PRESS ANY KEY TO START"
sync
until scancode()>0


do
cls

    mox=mousex():moy=mousey()

    center text bx,by-8,"[x]"

    center text shotx#,shoty#-8,"o"

    if new0=0 then sa=wrapvalue(atanfull(mousex()-bx,by-mousey())): new0=1

    inc bx,bvx#
    inc by,bvy#
    if bx<0 or bx>640 then bvx#=bvx#*-1
    if by<0 or by>480 then bvy#=bvy#*-1

    inc shotx#,sin(sa)*sv#
    dec shoty#,cos(sa)*sv#

    if shotx#<0 or shotx#>640 or shoty#<0 or shoty#>480 then new0=0: shotx#=bx:shoty#=by

    dx#=shotx#-mox: dy#=shoty#-moy

    if sqrt(dx#*dx#+dy#*dy#)<=rad then new0=0: shotx#=bx:shoty#=by: dec sh

    if sh<1
        losetime=timer()
        repeat
            cls
            print "YOU LOSE AFTER ";(losetime-init#)/1000;" SECONDS"
            sync
        until scancode()>0 or mouseclick()>0
        end
    endif

    text 0,450,str$(sa)

    showsh(t$,mox,moy,rad,ang,sh)
    ang=wrapvalue(ang+1)

sync
loop


function showsh(tex$,x,y,r,a,shi)
    circle mousex(),mousey(),r
    da=360/shi
    for i=1 to shi
        center text x+r*sin(a+da*i),y-r*cos(a+da*i)-8,mid$(tex$,i)
    next i
endfunction


Lizard Tongue - eat the flies up!
+ Code Snippet
Rem Project: reactions
Rem Created: 16/02/03 19:51:17

Rem ***** Main Source File *****

sync on:sync rate 60:hide mouse

dim level$(18)

for i=1 to 18: read level$(i): next i

repeat
    cls
    center text 320,10,"Lizard Tongue"
    center text 320,140,"Select Difficulty"

    for i=1 to 9
        center text 320,140+20*i,str$(i)+" - "+level$(i)
    next i

    a$=inkey$(): diff=val(a$)
    sync
until diff>0 and diff<10

r#=1-0.025*diff

dim bad(100,4)
randomize timer()

max=10
generate(max)
remaining=10

mai=30

dim afterimage(mai,1)
for i=1 to mai: afterimage(i,0)=320: afterimage(i,1)=240: next i

do
    cls

    MoveX#=mousemovex():MoveY#=mousemovey()


    for i=1 to max
        if bad(i,0)=1
            x0=320+px:y0=240+py

            bad(i,1)=bad(i,1)+bad(i,3)
            bad(i,2)=bad(i,2)+bad(i,4)
            x=bad(i,1):y=bad(i,2)

            if x<0 then bad(i,1)=640
            if x>640 then bad(i,1)=0
            if y<0 then bad(i,2)=480
            if y>480 then bad(i,2)=0
            if x0 > x-7 and x0 < x+7 and y0>y-7 and y0<y+7
                bad(i,0)=0
                dec remaining
            endif
        endif
    next i

    if remaining=0
        inc max
        if max>12
            max=10
            diff=diff+1
            if diff=10 then halfway()
            if diff>18 then finish()
            r#=1-0.025*diff
        endif
        remaining=max: generate(max)
    endif

    inc px,movex#
    inc py,movey#

    px=px*r#
    py=py*r#

    x0=320+px:y0=240+py

    if gfx=1
        for i=1 to mai
            i#=i: mai#=mai
            c=(255*i#)/mai#
            ink rgb(c,0,(255-c)/4),0
            line 320,240,afterimage(i,0),afterimage(i,1)
        next i
        ink -1,0
    endif

    circle 320,240,3: circle x0,y0,5
    line 320,240,x0,y0

    if gfx=1
        for i=0 to 1
            for j=1 to mai-1
                afterimage(j,i)=afterimage(j+1,i)
            next j
        next i
        afterimage(mai,0)=x0
        afterimage(mai,1)=y0
    endif

    text 10,10,Level$(diff)+" Level"
    center text 320,10,"Lizard Tongue"
    text 540,10,"Stage "+str$(max-9)
    text 10,450,str$(remaining)+" flies remaining"
    text 540,450,str$(screen fps())

    if spacekey() then remaining=0:max=13:diff=17

    sync
loop

data "Baby","Child","Beginner","Intermediate","Skilled","Veteran","Expert","Master","Grand Master"
data "Baby God","Child God","Beginner God","Intermediate God","Skilled God","Veteran God","Expert God","Master God","Grand Master God"


function generate(n)
    for i=1 to n
        bad(i,0)=1
        bad(i,1)=rnd(640)
        bad(i,2)=rnd(480)
        repeat: a=rnd(8)-4: until a <> 0
        bad(i,3)=a
        repeat: a=rnd(6)-3: until a <> 0
        bad(i,4)=a
    next i
    for i=n+1 to 100
        bad(i,0)=0
    next i
endfunction

function halfway()
    repeat
        center text 320,180,"YOU HAVE COMPLETELY LIZARD TONGUE ON MORTAL LEVEL - PLAY GOD LEVEL?"
        sync
    until scancode()>0
endfunction

function finish()
    repeat
        center text 320,180,"YOU HAVE COMPLETED LIZARD TONGUE ON GOD LEVEL. CONGRATULATIONS."
        sync
    until scancode()>0
    end
endfunction
Posted: 21st Feb 2003 20:20
aaargh! flies invisible! insert dot x,y after
x=bad(i,1):y=bad(i,2)