Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BallShoot - A bare bones shooter game easy to expand on.
#31
Here's the little space dust particle system for the explosions I used in the last update, just in case anyone wants to use have this code separate for something.  This code is easy to incorporate in other games.

- Dav

Code: (Select All)
'Space dust explosion particle system for ballshoot game
'Click mouse on screen to see dust.
'Dav, SEP/2024

Randomize Timer

Screen _NewImage(640, 480, 32)

'=== for space dust (explosion particles)
dustmax = 600 'make sure enough dust particles
Dim dustx(dustmax), dusty(dustmax)
Dim dustxv(dustmax), dustyv(dustmax)
Dim dustr(dustmax), dusta(dustmax)
dustcount = 0 'no active dust particles yet


Do

    Line (0, 0)-(_Width, _Height), _RGBA(0, 0, 0, 75), BF

    While _MouseInput: Wend

    'If click on sceen, do the dust..
    If _MouseButton(1) Then
        For ex = 1 To 15 'this will be ball radius
            If dustcount < dustmax Then
                dustcount = dustcount + 1
                dustx(dustcount) = _MouseX 'will be ball x
                dusty(dustcount) = _MouseY 'will be ball y
                dustxv(dustcount) = Rnd * 5 - 2.5
                dustyv(dustcount) = Rnd * 5 - 2.5
                dustr(dustcount) = Int(Rnd * 2) + 1
                dusta(dustcount) = Rnd * 255
            End If
        Next
    End If

    'do your other program stuff...


    'below maintains dust on the screen...
    'It handle/Updates any space dust on screen
    If dustcount > 0 Then
        For i = 1 To dustcount
            dustyv(i) = dustyv(i) + .1 'gravity effect
            dustx(i) = dustx(i) + dustxv(i)
            dusty(i) = dusty(i) + dustyv(i)
            If dusta(i) > 0 Then
                Line (dustx(i), dusty(i))-Step(dustr(i), dustr(i)), _RGBA(Rnd * 155 + 100, Rnd * 155 + 100, Rnd * 155 + 100, dusta(i)), BF
                dusta(i) = dusta(i) - 4 'fading
            End If
        Next
        'cleanup any dust fully faded out
        For i = 1 To dustcount
            If dusta(i) <= 0 Then
                dustcount = dustcount - 1
                For j = i To dustcount
                    dustx(j) = dustx(j + 1)
                    dusty(j) = dusty(j + 1)
                    dustxv(j) = dustxv(j + 1)
                    dustyv(j) = dustyv(j + 1)
                    dustr(j) = dustr(j + 1)
                    dusta(j) = dusta(j + 1)
                Next
            End If
        Next

    End If

    _Display
    _Limit 30
Loop Until _KeyDown(27) 'ESC to quit

End

Find my programs here in Dav's QB64 Corner
Reply




Users browsing this thread: 30 Guest(s)