Buchempfehlung
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Umfassend, aber leicht verständlich führt dieses Buch in die Programmierung von ATMEL AVR Mikrocontrollern ein. [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

Particles ;)

Uploader:MitgliedDonStevone
Datum/Zeit:31.12.2011 14:28:06

#Define Speed 2
#Define Versatz 250
#Define ScreenWidth 640
#Define ScreenHeight 480

Type Particle
    X as Double
    Y as Double
    XL as Double
    YL as Double
    XV as Double
    YV as Double
    Col as Integer
End Type

Type ParticleSystem
    PPTR as Particle PTR

    Declare Constructor()
    Declare Sub G()
    Declare Sub GClear()
    Declare Sub Control()
End Type

Constructor ParticleSystem()
    Dim X as Integer
    Dim Y as Integer
    Dim a as Integer
    Dim Col as Integer

    PPTR = Allocate(SizeOf(Particle) * 10000)
    If PPTR = 0 then
        Print "[ERROR] Zero pointer exception in: Constructor ParticleSystem()"
    Endif

    For a = 0 to 9999
        PPTR[a].X = X + Versatz
        PPTR[a].Y = Y
        PPTR[a].XL = X
        PPTR[a].YL = Y
        PPTR[a].YV = Speed
        PPTR[a].Col = RGB(Col, 0, 255)
        X += 1
        If X = 99 then X = 0 : Y += 1 : Col += 1
    Next a
End Constructor

Sub ParticleSystem.G()
    Dim as Integer a

    For a = 0 to 9999
        PSET(PPTR[a].X, PPTR[a].Y), PPTR[a].Col
    Next a
End Sub

Sub ParticleSystem.GClear()
    Dim as Integer a

    For a = 0 to 9999
        PSET(PPTR[a].XL, PPTR[a].YL), &h000000
    Next a
End Sub

Sub ParticleSystem.Control()
    Dim as Integer a

    For a = 0 to 9999
        PPTR[a].XL = PPTR[a].X
        PPTR[a].YL = PPTR[a].Y
        PPTR[a].X += PPTR[a].XV
        PPTR[a].Y += PPTR[a].YV
        If PPTR[a].Y < 0 then PPTR[a].YV = ABS(PPTR[a].YV) : PPTR[a].XV += (RND * 0.4) - 0.2
        If PPTR[a].Y > ScreenHeight then PPTR[a].YV = -ABS(PPTR[a].YV) : PPTR[a].XV += (RND * 0.4) - 0.2
        If PPTR[a].X < 0 then PPTR[a].XV = ABS(PPTR[a].XV) : PPTR[a].YV += (RND * 0.4) - 0.2
        If PPTR[a].X > ScreenWidth then PPTR[a].XV = -ABS(PPTR[a].XV) : PPTR[a].YV += (RND * 0.4) - 0.2
    Next a
End Sub



Screenres ScreenWidth, ScreenHeight, 32

Dim as ParticleSystem PS = ParticleSystem()

While(NOT Multikey(&h01))
    PS.Control()
    ScreenLock
        PS.GClear()
        PS.G()
    ScreenUnlock
    Sleep 10
Wend