Buchempfehlung
Visual Basic 6 Kochbuch
Visual Basic 6 Kochbuch
Viele praktische Tipps zum Programmieren mit Visual Basic 6, die sich oft auch auf FB übertragen lassen. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Pixel-Rennen ala Muh

Uploader:MitgliedThe_Muh
Datum/Zeit:21.09.2008 20:54:58

type pixel
    x as integer
    y as integer
    stx as integer
    sty as integer
    disy as integer
    disx as integer
    wayx as integer = 1
    wayy as integer = 1
    ziel as integer = 1
end type

dim as integer my, mx, bt
dim shared p() as pixel
dim x as integer
randomize timer

declare function puffer(p_i as integer) as integer

for i as integer = 1 to 1
    redim preserve p(i)
    p(i).x = rnd*500 +1
    p(i).y = rnd*500 +1
next

dim mp() as pixel
redim mp(1)
for i as integer = 1 to ubound(mp)
    mp(i).x = rnd*100 +1
    mp(i).y = rnd*100 +1
next
screenres 500, 500

do
    for i as integer = 1 to ubound(p)
        pset(p(i).x, p(i).y)
        getmouse mx,my,,bt
        if bt = 1 then
            redim preserve p(ubound(p) +1)
            p(ubound(p)).x = rnd*500 +1
            p(ubound(p)).y = rnd*500 +1
        elseif bt = 2 then
            redim preserve mp(ubound(mp) +1)
            mp(ubound(mp)).x = mx
            mp(ubound(mp)).y = my
        end if
        for i as integer = 1 to ubound(mp)
            circle(mp(i).x, mp(i).y),3,4,,,,f
        next
        if p(i).x > mp(p(i).ziel).x then
            p(i).stx = 1
            p(i).disx = int(p(i).x - mp(p(i).ziel).x )
        elseif p(i).x < mp(p(i).ziel).x then
            p(i).stx = 2
            p(i).disx = int(mp(p(i).ziel).x - p(i).x)
        else
            p(i).stx = 0
        end if

        if p(i).y > mp(p(i).ziel).y then
            p(i).sty = 1
            p(i).disy = int(p(i).y - mp(p(i).ziel).y)
        elseif p(i).y < mp(p(i).ziel).y then
            p(i).sty = 2
            p(i).disy = int(mp(p(i).ziel).y - p(i).y)
        else
            p(i).sty = 0
        end if
        if p(i).sty = 0 and p(i).stx = 0 then
            p(i).ziel += 1
            if p(i).ziel > ubound(mp) then p(i).ziel = 1
        end if
    next

    for i as integer = 1 to ubound(p)
        if p(i).stx = 1 then
            p(i).wayx = int(p(i).disx / 5) +1
            p(i).x -= p(i).wayx
        end if
        if p(i).stx = 2  then
            p(i).wayx = int(p(i).disx / 5) +1
            p(i).x += p(i).wayx
        end if

        if p(i).sty = 1  then
            p(i).wayy = int(p(i).disy / 5) +1
            p(i).y -= p(i).wayy
        end if
        if p(i).sty = 2  then
            p(i).wayy = int(p(i).disy / 5) +1
            p(i).y += p(i).wayy
        end if


    next
    locate 1,1
    sleep 100
    cls
loop

function puffer(p_i as integer) as integer
    dim ret as integer
    dim as integer x,y
    y = p(p_i).y
    x = p(p_i).x

    for i as integer = 1 to ubound(p)
        if p(i).x = x and p(i).y = y and i <> p_i then
            ret = 1
            exit for
        end if
    next
    return ret
end function