File tree 2 files changed +17
-13
lines changed
2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ class Bug {
20
20
this . lifetime = Math . floor ( Math . random ( ) * 200 ) ;
21
21
this . radius -= Math . floor ( Math . random ( ) * 4 ) ;
22
22
this . trailLength = this . radius ;
23
- this . ageEvery = Math . floor ( Math . random ( ) * 3000 ) + 5000 ;
23
+ this . ageEvery = Math . floor ( Math . random ( ) * 3000 ) + 0 ;
24
24
this . ageTimer = this . ageEvery ;
25
25
this . maxAge = 16 + Math . floor ( Math . random ( ) * 3 ) ;
26
26
this . dead = false ;
Original file line number Diff line number Diff line change @@ -11,32 +11,36 @@ const bugCountMin = 8;
11
11
export const bugCountMax = 16 ;
12
12
13
13
function tick ( dt ) {
14
- var trySpawnKids = 0 ;
14
+ var trySpawnKids = [ ] ;
15
15
for ( var i = 0 ; i < bugs . length ; i ++ )
16
16
{
17
17
var b = bugs [ i ] ;
18
18
b . tick ( dt ) ;
19
19
if ( b . dead ) {
20
20
bugs . splice ( i , 1 ) ;
21
- trySpawnKids ++ ;
21
+ trySpawnKids . push ( b ) ;
22
22
}
23
23
}
24
- for ( var i = 0 ; i < trySpawnKids ; i ++ )
24
+ for ( var i = 0 ; i < trySpawnKids . length ; i ++ )
25
25
{
26
+ var par = trySpawnKids [ i ] ;
26
27
if ( Math . random ( ) > 0.5 && bugs . length < bugCountMax )
27
28
{
28
- var b = new Bug ( Math . floor ( Math . random ( ) * WIDTH ) , Math . floor ( Math . random ( ) * HEIGHT ) )
29
+ var b = new Bug ( par . pos . x , par . pos . y )
29
30
bugs . push ( b ) ;
30
31
console . log ( "Dead bug had first kid" ) ;
31
- if ( Math . random ( ) > 0.5 && bugs . length < bugCountMax )
32
- {
33
- var b = new Bug ( Math . floor ( Math . random ( ) * WIDTH ) , Math . floor ( Math . random ( ) * HEIGHT ) )
34
- bugs . push ( b ) ;
35
- console . log ( "Dead bug had second kid" ) ;
36
- }
37
32
}
38
- else {
39
- console . log ( "Dead bug had no kids" ) ;
33
+ if ( Math . random ( ) > 0.5 && bugs . length < bugCountMax )
34
+ {
35
+ var b2 = new Bug ( par . pos . x , par . pos . y )
36
+ bugs . push ( b2 ) ;
37
+ console . log ( "Dead bug had second kid" ) ;
38
+ }
39
+ if ( Math . random ( ) > 0.5 && bugs . length < bugCountMax )
40
+ {
41
+ var b3 = new Bug ( par . pos . x , par . pos . y )
42
+ bugs . push ( b3 ) ;
43
+ console . log ( "Dead bug had third kid" ) ;
40
44
}
41
45
}
42
46
if ( bugs . length < bugCountMin ) {
You can’t perform that action at this time.
0 commit comments