From 6de8d28ffb5da5c4ac7260b467dd5afc85286fde Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 18 Apr 2006 18:39:41 +0000 Subject: Initial Import --- particle.bmx | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 particle.bmx (limited to 'particle.bmx') diff --git a/particle.bmx b/particle.bmx new file mode 100644 index 0000000..79c7f8c --- /dev/null +++ b/particle.bmx @@ -0,0 +1,130 @@ +' Missile Lock +' +' Copyright (C) 2006 Ian Cowburn (ianc@noddybox.co.uk) +' +' This program is free software; you can redistribute it and/or modify +' it under the terms of the GNU General Public License as published by +' the Free Software Foundation; either version 2 of the License, or +' (at your option) any later version. +' +' This program is distributed in the hope that it will be useful, +' but WITHOUT ANY WARRANTY; without even the implied warranty of +' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +' GNU General Public License for more details. +' +' You should have received a copy of the GNU General Public License +' along with this program; if not, write to the Free Software +' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +' +' ------------------------------------------------------------------------- +' +' $Id$ +' +Strict +Import noddybox.algorithm +Import "global.bmx" +Import "gametypes.bmx" + +Type TParticle + Field life:Int + Field i:TImage + Field x:Double + Field y:Double + Field a:Double + Field dx:Double + Field dy:Double + Field ai:Double + Field s:Double + Field si:Double + + Function Image:TParticle(i:TImage, x:Int, y:Int) + Local o:TParticle=New TParticle + o.life=120 + o.x=x + o.y=y + o.a=1 + o.ai=-0.01 + o.dx=0 + o.dy=0 + o.s=1 + o.si=0 + o.i=i + Return o + End Function + + Function ScaleImage:TParticle(i:TImage, x:Int, y:Int,si:Double) + Local o:TParticle=New TParticle + o.life=120 + o.x=x + o.y=y + o.a=1 + o.ai=-0.01 + o.dx=0 + o.dy=0 + o.s=1 + o.si=si + o.i=i + Return o + End Function + + Method Update:Int() + Local p:TAlgoPointD=DoRotateD(x,y,3599-GameState.ang) + p.x:-GameState.x + p.y:+GameState.y + SetAlpha(a) + SetScale(s,s) + DrawImage(i,p.x,p.y) + x:+dx + y:+dy + life:-1 + a:+ai + s:+si + Return life>0 + End Method +End Type + +Type Particles + Global plist:TList + + Function Init() + plist=CreateList() + End Function + + Function Clear() + plist.Clear() + End Function + + Function AddImage(i:TImage, x:Int, y:Int) + If plist.Count()<1000 + plist.AddLast(TParticle.Image(i,x,y)) + EndIf + End Function + + Function AddScaledImage(i:TImage, x:Int, y:Int, si:Double=0.1) + If plist.Count()<1000 + plist.AddLast(TParticle.ScaleImage(i,x,y,si)) + EndIf + End Function + + Function Draw() + Local r:Double=GetRotation() + + SetRotation(-GameState.ang/10.0) + + SetColor(255,255,255) + Local l:TEasyLink=TEasyLink.Create(plist) + + While l.Value() + Local p:TParticle=TParticle(l.Value()) + + If (p.Update()) + l.MoveNext() + Else + l.Remove() + EndIf + Wend + SetAlpha(1) + SetScale(1,1) + SetRotation(r) + End Function +End Type -- cgit v1.2.3