1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
Import mojo Class Particle Global ParticleList:List<particle> = New List<particle> Field x:Float,y:Float,a:Float = 1,r:Int Field ox:Int,oy:Int Field img:Image Field dx:Float,dy:Float, da:Float Field maxdistance:Int Field speed:Float Field dir:Int Field fade:Int Field z:Int Method Create:Particle(_x:Int, _y:Int, _img:Image, _dir:Int = 0, _speed:Float = 0, frames:Int = 1, _fade:Int = False, _autorot:Int = False, _z:Int = 0) ParticleList.AddLast(Self) z = _z x = _x y = _y ox = _x oy = _y img = _img speed = _speed dir = _dir dx = Sin(dir) * speed dy = -Cos(dir) * speed da = 1.0 / frames maxdistance = frames If dir And _autorot r = -dir - 180 End If If _fade fade = True End If End Method Method Update() x+=dx y+=dy If fade a-=da maxdistance-=1 If maxdistance <= 0 Or a <= 0 Destroy() End If If x > VDeviceWidth() Or x < 0 - img.Width Or y > VDeviceHeight() Or y < 0 - img.Height Destroy() End If End Method Method Draw() SetAlpha a DrawImage img,x,y,r,1,1 SetAlpha 1 End Method Method SetPAlpha(alpha:Float) a = alpha End Method Method SetPRotation(rot:Int) r = rot End Method Method Destroy() ParticleList.Remove(Self) End Method Method AddX(_x:Int) x+= _x End Method Method AddY(_y:Int) y+= _y End Method Method SetDirection(_dir:Int) dir = _dir End Method Method SetSpeed(_speed:Float) speed = _speed End Method End Function ParticleExplosion(_x:Float, _y:Float, image:Image, n:Int, frames:Int, speed_multiplyer:Float = 0, ar:Int = False, _z:Int = 0) Local speed:Float For Local i:Int = 1 To n Local dir:Int = Rnd(0, 359) If speed_multiplyer speed = Rnd(0.08*speed_multiplyer, 1.5*speed_multiplyer) Else speed = Rnd(0.08, 1.5) End If Local part:Particle = New Particle() part.Create(_x, _y, image, dir, speed, frames - 10 + Rnd((frames*1.40)), True, ar, _z) Next End Function Function EmitParticle(_x:Float, _y:Float, image:Image, frames:Int, fade:Int = True, dir:Int = 0, speed:Float = 0, ar:Int = False, _z:Int = 0) Local part:Particle = New Particle() part.Create(_x, _y, image, dir, speed, frames, fade, ar, _z) End Function Function ParticleCount:Int() Return Particle.ParticleList.Count() End Function Function ClearParticles() Particle.ParticleList.Clear() End Function Function ClearParticlesZ(z:Int = 0) For Local delp:Particle = Eachin Particle.ParticleList If delp.z = z Particle.ParticleList.Remove(delp) End If Next End Function Function UpdateParticlesZ(z:Int = 0, forcex:Float = 0, forcey:Float = 0) For Local UpdateP:Particle = Eachin Particle.ParticleList If UpdateP.z = z UpdateP.Update() If forcex UpdateP.x+=forcex If forcey UpdateP.y+=forcey End If Next End Function Function DrawParticlesZ(z:Int = 0) For Local UpdateP:Particle = Eachin Particle.ParticleList If UpdateP.z = z UpdateP.Draw() End If Next End Function |