Hi all,
I'd be incredibly grateeful if someone could spare a couple of minutes to look over this code. It's the first time I've done any programming for many years, and the first time I have used 'types' - so it's likely i'm missing something really obvious.
After running for a few seconds - all my particles disappear - why????
(Lower mound number if it runs slow)
Hope you can help
markyb
[p4 2.8 / 512mb / 128mb geforce ti4600]
--------------------------------------------------
;bugged particles
Graphics 800,600,32,2
SeedRnd (MilliSecs())
;make a bug type
Type bug
Field size
Field x#
Field y#
Field direction
Field xspeed#
Field yspeed#
End Type
;make mound of bugs
mound = 2000
For i = 1 To mound
nest.bug = New bug
nest\x# = 400
nest\y# = 300
nest\direction# = Rnd(360) - 180
nest\size = Rand(4)
nest\xspeed# = Rnd(nest\size) + Rnd(4)
nest\yspeed# = Rnd(nest\size) + Rnd(4)
Next
; main loop
While Not KeyHit(1)
For nest.bug =Each bug
SetBuffer BackBuffer()
Cls
draw_bug(nest.bug)
Flip
move_bug(nest.bug)
Next
Wend
; move the bugs
Function move_bug(nest.bug)
For nest.bug = Each bug
;check for edge collisions
If nest\x#-nest\size<=100 Or nest\x#+nest\size>=700 Then nest\xspeed# = -nest\xspeed#
If nest\y#-nest\size<=100 Or nest\y#+nest\size>=500 Then nest\yspeed# = -nest\yspeed#
;update bugs position
nest\x# = nest\x# + Sin(nest\direction#)*nest\xspeed#
nest\y# = nest\y# + Cos(nest\direction#)*nest\yspeed#
Next
End Function
; draw the bugs
Function draw_bug(nest.bug)
For nest.bug = Each bug
Color 255-(nest\size*10),255-(nest\size*20),255-(nest\size*15)
Oval nest\x#, nest\y#,nest\size,nest\size
Next
End Function
;--------------------------------------------
I'd be incredibly grateeful if someone could spare a couple of minutes to look over this code. It's the first time I've done any programming for many years, and the first time I have used 'types' - so it's likely i'm missing something really obvious.
After running for a few seconds - all my particles disappear - why????
(Lower mound number if it runs slow)
Hope you can help
markyb
[p4 2.8 / 512mb / 128mb geforce ti4600]
--------------------------------------------------
;bugged particles
Graphics 800,600,32,2
SeedRnd (MilliSecs())
;make a bug type
Type bug
Field size
Field x#
Field y#
Field direction
Field xspeed#
Field yspeed#
End Type
;make mound of bugs
mound = 2000
For i = 1 To mound
nest.bug = New bug
nest\x# = 400
nest\y# = 300
nest\direction# = Rnd(360) - 180
nest\size = Rand(4)
nest\xspeed# = Rnd(nest\size) + Rnd(4)
nest\yspeed# = Rnd(nest\size) + Rnd(4)
Next
; main loop
While Not KeyHit(1)
For nest.bug =Each bug
SetBuffer BackBuffer()
Cls
draw_bug(nest.bug)
Flip
move_bug(nest.bug)
Next
Wend
; move the bugs
Function move_bug(nest.bug)
For nest.bug = Each bug
;check for edge collisions
If nest\x#-nest\size<=100 Or nest\x#+nest\size>=700 Then nest\xspeed# = -nest\xspeed#
If nest\y#-nest\size<=100 Or nest\y#+nest\size>=500 Then nest\yspeed# = -nest\yspeed#
;update bugs position
nest\x# = nest\x# + Sin(nest\direction#)*nest\xspeed#
nest\y# = nest\y# + Cos(nest\direction#)*nest\yspeed#
Next
End Function
; draw the bugs
Function draw_bug(nest.bug)
For nest.bug = Each bug
Color 255-(nest\size*10),255-(nest\size*20),255-(nest\size*15)
Oval nest\x#, nest\y#,nest\size,nest\size
Next
End Function
;--------------------------------------------