diff options
author | Ian C <ianc@noddybox.co.uk> | 2006-05-27 23:24:02 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2006-05-27 23:24:02 +0000 |
commit | 26c98ba56e72beaf8a99eafbedd2b0c64ac13954 (patch) | |
tree | 6460c30f185bfdf0647055a9a32af111b8f87894 /particle.bmx | |
parent | 0129dc56ba73e43f148b779d9ff549f286e66f1d (diff) |
Diffstat (limited to 'particle.bmx')
-rw-r--r-- | particle.bmx | 652 |
1 files changed, 334 insertions, 318 deletions
diff --git a/particle.bmx b/particle.bmx index 40a9c24..6e8d469 100644 --- a/particle.bmx +++ b/particle.bmx @@ -1,318 +1,334 @@ -' Hardwire
-'
-' Copyright 2005 Ian Cowburn
-'
-' $Id$
-'
-Strict
-Import "types.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 Dust:TParticle(x:Int, y:Int)
- Local o:TParticle=New TParticle
- o.life=50
- o.x=x
- o.y=y
- o.a=1
- o.ai=-0.05
- o.dx=0
- o.dy=0
- o.s=1
- o.si=0.1
- o.i=GameGFX.dust
- Return o
- End Function
-
- 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.1
- o.s=1
- o.si=0
- o.i=i
- Return o
- End Function
-
- Method Update:Int()
- SetAlpha(a)
- SetScale(s,s)
- DrawImage(i,x,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 AddDust(x:Int, y:Int)
- plist.AddLast(TParticle.Dust(x,y))
- End Function
-
- Function AddImage(i:TImage, x:Int, y:Int)
- plist.AddLast(TParticle.Image(i,x,y))
- End Function
-
- Function Draw()
- 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)
- End Function
-End Type
-
-Type TTextParticle
- Field txt:String
- Field x:Double
- Field y:Double
- Field a:Double
- Field dx:Double
- Field dy:Double
- Field ai:Double
- Field s:Double
- Field si:Double
- Field r:Int
- Field g:Int
- Field b:Int
- Field fnt:TBitmapFont
-
- Function Create:TTextParticle(fnt:TBitmapFont, txt:String, x:Double, y:Double, dx:Double, dy:Double, r:Int, g:Int, b:Int, a:Double, ai:Double, s:Double, si:Double)
- Local o:TTextParticle=New TTextParticle
-
- If x=-1
- x=GraphicsWidth()/2
- EndIf
-
- o.x=x
- o.y=y
- o.a=a
- o.ai=ai
- o.dx=dx
- o.dy=dy
- o.s=s
- o.si=si
- o.txt=txt
- o.r=r
- o.g=g
- o.b=b
- o.fnt=fnt
- Return o
- End Function
-
- Method Update:Int()
- SetAlpha(a)
- SetScale(s,s)
- fnt.CentreOn(txt,x,y,r,g,b)
- x:+dx
- y:+dy
- a:+ai
- s:+si
- Return a>0
- End Method
-End Type
-
-Type TextParticles
- Global plist:TList
- Global sy:Int
- Const sx:Int=646
-
- Function Init()
- plist=CreateList()
- sy=300
- End Function
-
- Function Clear()
- plist.Clear()
- sy=300
- End Function
-
- Function Big(txt:String, r:Int=-1, g:Int=-1, b:Int=-1)
- If r=-1 Then r=Rand(128,255)
- If g=-1 Then g=Rand(128,255)
- If b=-1 Then b=Rand(128,255)
- plist.AddLast(TTextParticle.Create(GameGFX.font,txt,-1,GraphicsHeight()-GameGFX.font.MaxHeight()/2,0,0,r,g,b,1,-0.01,1,0))
- plist.AddLast(TTextParticle.Create(GameGFX.font,txt,-1,GraphicsHeight()-GameGFX.font.MaxHeight()/2,0,0,r,g,b,1,-0.02,1,0.1))
- End Function
-
- Function Score(txt:String)
- Local r:Int=Rand(128,255)
- Local g:Int=Rand(128,255)
- Local b:Int=Rand(128,255)
-
- plist.AddLast(TTextParticle.Create(GameGFX.font,txt,sx,sy,0,0,r,g,b,1,-0.01,1,0))
- plist.AddLast(TTextParticle.Create(GameGFX.font,txt,sx,sy,0,0,r,g,b,1,-0.02,1,0.1))
-
- sy:+GameGFX.font.MaxHeight()
-
- If sy>GraphicsHeight()-20
- sy=300
- EndIf
- End Function
-
- Function Draw()
- Local l:TEasyLink=TEasyLink.Create(plist)
-
- While l.Value()
- Local p:TTextParticle=TTextParticle(l.Value())
-
- If (p.Update())
- l.MoveNext()
- Else
- l.Remove()
- EndIf
- Wend
- SetColor(255,255,255)
- SetAlpha(1)
- SetScale(1,1)
- End Function
-End Type
-
-
-Type TExplosionBase
- Field p:TPixmap[4]
-
- Function Create:TExplosionBase(base:TImage)
- Local o:TExplosionBase=New TExplosionBase
- o.p=New TPixmap[4]
- o.p[0]=GrabFrom(base,0,0)
- o.p[1]=GrabFrom(base,16,0)
- o.p[2]=GrabFrom(base,0,16)
- o.p[3]=GrabFrom(base,16,16)
- Return o
- End Function
-
- Function GrabFrom:TPixmap(i:TImage,x:Int, y:Int)
- Local p:TPixmap=LockImage(i)
- Local ret:TPixmap=p.Copy()
- ret=ResizePixmap(ret,16,16)
- For Local cx:Int=0 Until 16
- For Local cy:Int=0 Until 16
- ret.WritePixel(cx,cy,p.ReadPixel(x+cx,y+cy))
- Next
- Next
- UnlockImage(i)
- Return ret
- End Function
-End Type
-
-Type TExplosion_Old
- Field x:Double
- Field y:Double
- Field dy:Double
- Field dx:Double
- Field p:TPixmap
-
- Function Create:TExplosion(p:TPixmap,x:Double,y:Double,dx:Double,dy:Double)
- Local o:TExplosion=New TExplosion
- o.x=x
- o.y=y
- o.dx=dx
- o.dy=dy
- Return o
- End Function
-
- Method Update:Int()
- DrawPixmap(p,x,y)
- x:+dx
- y:+dy
- dy:+0.05
- Return dx>-16 And dx<GraphicsWidth()+16 And y<GraphicsHeight()
- End Method
-End Type
-
-Type TExplosion
- Field x:Double
- Field y:Double
- Field dy:Double
- Field dx:Double
-
- Function Create:TExplosion(x:Double,y:Double,dx:Double,dy:Double)
- Local o:TExplosion=New TExplosion
- o.x=x
- o.y=y
- o.dx=dx
- o.dy=dy
- Return o
- End Function
-
- Method Update:Int()
- SetColor(Rand(0,255),Rand(0,255),Rand(0,255))
- Plot(x,y)
- x:+dx
- y:+dy
- dy:+0.1
- Return dx>-16 And dx<GraphicsWidth()+16 And y<GraphicsHeight()
- End Method
-End Type
-
-Type ExplosionParticles
- Global plist:TList
-
- Function Init()
- plist=CreateList()
- End Function
-
- Function Clear()
- plist.Clear()
- End Function
-
- Function BlowUp(x:Int, y:Int)
- For Local cx:Int=0 Until 32
- For Local cy:Int=0 Until 32
- plist.AddLast(TExplosion.Create(x+cx,y+cy,Rnd(-2,2),Rnd(-2,2)))
- Next
- Next
- End Function
-
- Function Draw()
- Local l:TEasyLink=TEasyLink.Create(plist)
-
- While l.Value()
- Local p:TExplosion=TExplosion(l.Value())
-
- If (p.Update())
- l.MoveNext()
- Else
- l.Remove()
- EndIf
- Wend
- End Function
-End Type
\ No newline at end of file +' Hardwire +' +' Copyright (C) 2005 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 "types.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 Dust:TParticle(x:Int, y:Int) + Local o:TParticle=New TParticle + o.life=50 + o.x=x + o.y=y + o.a=1 + o.ai=-0.05 + o.dx=0 + o.dy=0 + o.s=1 + o.si=0.1 + o.i=GameGFX.dust + Return o + End Function + + 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.1 + o.s=1 + o.si=0 + o.i=i + Return o + End Function + + Method Update:Int() + SetAlpha(a) + SetScale(s,s) + DrawImage(i,x,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 AddDust(x:Int, y:Int) + plist.AddLast(TParticle.Dust(x,y)) + End Function + + Function AddImage(i:TImage, x:Int, y:Int) + plist.AddLast(TParticle.Image(i,x,y)) + End Function + + Function Draw() + 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) + End Function +End Type + +Type TTextParticle + Field txt:String + Field x:Double + Field y:Double + Field a:Double + Field dx:Double + Field dy:Double + Field ai:Double + Field s:Double + Field si:Double + Field r:Int + Field g:Int + Field b:Int + Field fnt:TBitmapFont + + Function Create:TTextParticle(fnt:TBitmapFont, txt:String, x:Double, y:Double, dx:Double, dy:Double, r:Int, g:Int, b:Int, a:Double, ai:Double, s:Double, si:Double) + Local o:TTextParticle=New TTextParticle + + If x=-1 + x=GraphicsWidth()/2 + EndIf + + o.x=x + o.y=y + o.a=a + o.ai=ai + o.dx=dx + o.dy=dy + o.s=s + o.si=si + o.txt=txt + o.r=r + o.g=g + o.b=b + o.fnt=fnt + Return o + End Function + + Method Update:Int() + SetAlpha(a) + SetScale(s,s) + fnt.CentreOn(txt,x,y,r,g,b) + x:+dx + y:+dy + a:+ai + s:+si + Return a>0 + End Method +End Type + +Type TextParticles + Global plist:TList + Global sy:Int + Const sx:Int=646 + + Function Init() + plist=CreateList() + sy=300 + End Function + + Function Clear() + plist.Clear() + sy=300 + End Function + + Function Big(txt:String, r:Int=-1, g:Int=-1, b:Int=-1) + If r=-1 Then r=Rand(128,255) + If g=-1 Then g=Rand(128,255) + If b=-1 Then b=Rand(128,255) + plist.AddLast(TTextParticle.Create(GameGFX.font,txt,-1,GraphicsHeight()-GameGFX.font.MaxHeight()/2,0,0,r,g,b,1,-0.01,1,0)) + plist.AddLast(TTextParticle.Create(GameGFX.font,txt,-1,GraphicsHeight()-GameGFX.font.MaxHeight()/2,0,0,r,g,b,1,-0.02,1,0.1)) + End Function + + Function Score(txt:String) + Local r:Int=Rand(128,255) + Local g:Int=Rand(128,255) + Local b:Int=Rand(128,255) + + plist.AddLast(TTextParticle.Create(GameGFX.font,txt,sx,sy,0,0,r,g,b,1,-0.01,1,0)) + plist.AddLast(TTextParticle.Create(GameGFX.font,txt,sx,sy,0,0,r,g,b,1,-0.02,1,0.1)) + + sy:+GameGFX.font.MaxHeight() + + If sy>GraphicsHeight()-20 + sy=300 + EndIf + End Function + + Function Draw() + Local l:TEasyLink=TEasyLink.Create(plist) + + While l.Value() + Local p:TTextParticle=TTextParticle(l.Value()) + + If (p.Update()) + l.MoveNext() + Else + l.Remove() + EndIf + Wend + SetColor(255,255,255) + SetAlpha(1) + SetScale(1,1) + End Function +End Type + + +Type TExplosionBase + Field p:TPixmap[4] + + Function Create:TExplosionBase(base:TImage) + Local o:TExplosionBase=New TExplosionBase + o.p=New TPixmap[4] + o.p[0]=GrabFrom(base,0,0) + o.p[1]=GrabFrom(base,16,0) + o.p[2]=GrabFrom(base,0,16) + o.p[3]=GrabFrom(base,16,16) + Return o + End Function + + Function GrabFrom:TPixmap(i:TImage,x:Int, y:Int) + Local p:TPixmap=LockImage(i) + Local ret:TPixmap=p.Copy() + ret=ResizePixmap(ret,16,16) + For Local cx:Int=0 Until 16 + For Local cy:Int=0 Until 16 + ret.WritePixel(cx,cy,p.ReadPixel(x+cx,y+cy)) + Next + Next + UnlockImage(i) + Return ret + End Function +End Type + +Type TExplosion_Old + Field x:Double + Field y:Double + Field dy:Double + Field dx:Double + Field p:TPixmap + + Function Create:TExplosion(p:TPixmap,x:Double,y:Double,dx:Double,dy:Double) + Local o:TExplosion=New TExplosion + o.x=x + o.y=y + o.dx=dx + o.dy=dy + Return o + End Function + + Method Update:Int() + DrawPixmap(p,x,y) + x:+dx + y:+dy + dy:+0.05 + Return dx>-16 And dx<GraphicsWidth()+16 And y<GraphicsHeight() + End Method +End Type + +Type TExplosion + Field x:Double + Field y:Double + Field dy:Double + Field dx:Double + + Function Create:TExplosion(x:Double,y:Double,dx:Double,dy:Double) + Local o:TExplosion=New TExplosion + o.x=x + o.y=y + o.dx=dx + o.dy=dy + Return o + End Function + + Method Update:Int() + SetColor(Rand(0,255),Rand(0,255),Rand(0,255)) + Plot(x,y) + x:+dx + y:+dy + dy:+0.1 + Return dx>-16 And dx<GraphicsWidth()+16 And y<GraphicsHeight() + End Method +End Type + +Type ExplosionParticles + Global plist:TList + + Function Init() + plist=CreateList() + End Function + + Function Clear() + plist.Clear() + End Function + + Function BlowUp(x:Int, y:Int) + For Local cx:Int=0 Until 32 + For Local cy:Int=0 Until 32 + plist.AddLast(TExplosion.Create(x+cx,y+cy,Rnd(-2,2),Rnd(-2,2))) + Next + Next + End Function + + Function Draw() + Local l:TEasyLink=TEasyLink.Create(plist) + + While l.Value() + Local p:TExplosion=TExplosion(l.Value()) + + If (p.Update()) + l.MoveNext() + Else + l.Remove() + EndIf + Wend + End Function +End Type |