diff options
-rw-r--r-- | GFX/MASS.png | bin | 0 -> 197 bytes | |||
-rw-r--r-- | GFX/PARTICLE.png | bin | 0 -> 166 bytes | |||
-rw-r--r-- | GFX/POINT.png | bin | 0 -> 166 bytes | |||
-rw-r--r-- | GFX/POINTER.png | bin | 0 -> 225 bytes | |||
-rw-r--r-- | GFX/STAR.png | bin | 0 -> 195 bytes | |||
-rw-r--r-- | GFX/sprites.bms | bin | 0 -> 2692 bytes | |||
-rw-r--r-- | main.bmx | 37 | ||||
-rw-r--r-- | types.bmx | 132 |
8 files changed, 153 insertions, 16 deletions
diff --git a/GFX/MASS.png b/GFX/MASS.png Binary files differnew file mode 100644 index 0000000..9965d97 --- /dev/null +++ b/GFX/MASS.png diff --git a/GFX/PARTICLE.png b/GFX/PARTICLE.png Binary files differnew file mode 100644 index 0000000..6e39e3e --- /dev/null +++ b/GFX/PARTICLE.png diff --git a/GFX/POINT.png b/GFX/POINT.png Binary files differnew file mode 100644 index 0000000..6e39e3e --- /dev/null +++ b/GFX/POINT.png diff --git a/GFX/POINTER.png b/GFX/POINTER.png Binary files differnew file mode 100644 index 0000000..c520048 --- /dev/null +++ b/GFX/POINTER.png diff --git a/GFX/STAR.png b/GFX/STAR.png Binary files differnew file mode 100644 index 0000000..6fef517 --- /dev/null +++ b/GFX/STAR.png diff --git a/GFX/sprites.bms b/GFX/sprites.bms Binary files differnew file mode 100644 index 0000000..59a5d29 --- /dev/null +++ b/GFX/sprites.bms @@ -13,19 +13,40 @@ Include "types.bmx" ' Included binaries ' Incbin "GFX/font.bmf" +Incbin "GFX/STAR.png" +Incbin "GFX/MASS.png" +Incbin "GFX/POINT.png" +Incbin "GFX/PARTICLE.png" +Incbin "GFX/POINTER.png" ' Initialise graphics ' SetGraphicsDriver GLMax2DDriver() -Graphics 800,600,32,60 -'HideMouse +Graphics 800,600',32,60 +HideMouse SetBlend(ALPHABLEND) ' Globals ' Global font:TBitmapFont=TBitmapFont.Load("incbin::GFX/font.bmf",0) +Global star_img:TImage=LoadAnimImage("incbin::GFX/STAR.png",8,8,0,2) +Global mass_img:TImage=LoadAnimImage("incbin::GFX/MASS.png",8,8,0,2) +Global point_img:TImage=LoadImage("incbin::GFX/POINT.png",0) +Global particle_img:TImage=LoadImage("incbin::GFX/PARTICLE.png",0) +Global pointer_img:TImage=LoadImage("incbin::GFX/POINTER.png",0) + +SetImageHandle(star_img,3,3) +SetImageHandle(mass_img,3,3) +SetImageHandle(point_img,3,3) +SetImageHandle(particle_img,3,3) +SetImageHandle(pointer_img,0,0) + +TPoint.img=point_img +TParticle.img=particle_img + +TParticleMachine.Init() ' Consts ' @@ -41,9 +62,8 @@ Global cy:Int=GraphicsHeight()/2 main_mass.x=cx'/2 main_mass.y=cy main_mass.friend=False -main_mass.g=100 -main_mass.b=100 -main_mass.inverse=True +'main_mass.inverse=True +main_mass.img=star_img For Local r:Int=0 Until 1000 Local s:TPoint=New TPoint @@ -62,6 +82,8 @@ Next mass.AddLast(main_mass) +TParticleMachine.Clear() + While Not KeyHit(KEY_ESCAPE) Cls @@ -74,6 +96,8 @@ While Not KeyHit(KEY_ESCAPE) Next Next + TParticleMachine.Process() + For Local m:TMass=EachIn mass m.MoveAndDraw() Next @@ -99,9 +123,12 @@ While Not KeyHit(KEY_ESCAPE) Local m:TMass=New TMass m.x=MouseX() m.y=MouseY() + m.img=mass_img mass.AddLast(m) EndIf + SetColor(255,255,255) + DrawImage(pointer_img,MouseX(),MouseY()) FlushMem Flip Wend @@ -1,29 +1,26 @@ ' It's all a bit rolly ' -Global MASSSIZE:Int=4 -Global MASSRAD:Int=MASSSIZE/2 +Global MASSSIZE:Int=6 +Global MASSRAD:Int=3 Type TMass Field x:Float Field y:Float Field v:TVector - Field r:Int - Field g:Int - Field b:Int Field mass:Float Field friend:Int Field inverse:Int + Field img:TImage + Field swallow:Int Method New() v=TVector.Create() x=Rnd(0,GraphicsWidth()) y=Rnd(0,GraphicsWidth()) - r=255 - g=255 - b=255 mass=25 friend=True inverse=False + swallow=False End Method Method Attract(o:TMass) @@ -54,15 +51,20 @@ Type TMass Method MoveAndDraw() x:+v.x y:+v.y - SetColor(r,g,b) - DrawOval(x-MASSRAD,y-MASSRAD,MASSSIZE,MASSSIZE) + SetColor(255,255,255) + DrawImage(img,x,y,swallow) + swallow=0 End Method End Type Type TPoint + Global img:TImage + Field x:Float Field y:Float + Field lx:Float + Field ly:Float Field v:TVector Field r:Int Field g:Int @@ -74,6 +76,8 @@ Type TPoint v=TVector.Create() x=Rnd(0,GraphicsWidth()) y=Rnd(0,GraphicsWidth()) + lx=x + ly=y r=Rand(100,200) g=Rand(100,200) b=Rand(100,200) @@ -95,6 +99,8 @@ Type TPoint Else lost=True EndIf + TParticleMachine.AddCaptured(Self) + o.swallow=1 Else l:*l d.Normalise() @@ -116,14 +122,118 @@ Type TPoint Method MoveAndDraw() If (Not dead) And (Not lost) + lx=x + ly=y x:+v.x y:+v.y + SetColor(r,g,b) - Plot(x,y) + DrawImage(img,x,y,0) If x<0 Or y<0 Or x>GraphicsWidth() Or y>GraphicsHeight() lost=True + TParticleMachine.AddLost(Self) EndIf EndIf End Method End Type + + +Type TParticle + Global img:TImage + Field x:Float + Field y:Float + Field a:Float + Field r:Int + Field g:Int + Field b:Int + Field dx:Float + Field dy:Float + Field ai:Float + + Function FromLostPoint:TParticle(p:TPoint, d:Int) + Local o:TParticle=New TParticle + o.x=p.lx'-p.v.x*d + o.y=p.ly'-p.v.y*d + o.dx=-p.v.x*d + o.dy=-p.v.y*d + o.r=p.r + o.g=p.g + o.b=p.b + o.a=1 + o.ai=-0.05 + Return o + End Function + + Function FromCapturedPoint:TParticle(p:TPoint, d:Int) + Local o:TParticle=New TParticle + o.x=p.x + o.y=p.y + o.dx=Rnd(-1,1) + o.dy=Rnd(-1,1) + o.r=p.r + o.g=p.g + o.b=p.b + o.a=1 + o.ai=-0.05 + Return o + End Function + + Method Update() + x:+dx + y:+dy + a:+ai + + If a>0 + SetAlpha(a) + SetColor(r,g,b) + DrawImage(img,x,y) + EndIf + End Method +End Type + + +Type TParticleMachine + Global list:TList + + Function Init() + list=CreateList() + End Function + + Function Clear() + list.Clear() + End Function + + Function AddLost(p:TPoint) + For Local f:Int=0 To 5 + list.AddLast(TParticle.FromLostPoint(p,f)) + Next + End Function + + Function AddCaptured(p:TPoint) + For Local f:Int=0 To 5 + list.AddLast(TParticle.FromCapturedPoint(p,f)) + Next + End Function + + Function Process() + Local l:TLink=list.FirstLink() + Local t:TLink + + While l<>Null + Local p:TParticle=TParticle(l.Value()) + p.Update() + + If p.a<0.01 + t=l.NextLink() + l.Remove() + l=t + Else + l=l.NextLink() + EndIf + Wend + + SetAlpha(1) + SetColor(255,255,255) + End Function +End Type |