From 0b93bde7fe64ce51117bb8eb48cbabf757ba4a02 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 15 Sep 2005 01:03:37 +0000 Subject: Updated to use images --- GFX/MASS.png | Bin 0 -> 197 bytes GFX/PARTICLE.png | Bin 0 -> 166 bytes GFX/POINT.png | Bin 0 -> 166 bytes GFX/POINTER.png | Bin 0 -> 225 bytes GFX/STAR.png | Bin 0 -> 195 bytes GFX/sprites.bms | Bin 0 -> 2692 bytes main.bmx | 37 +++++++++++++--- types.bmx | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 8 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 GFX/MASS.png create mode 100644 GFX/PARTICLE.png create mode 100644 GFX/POINT.png create mode 100644 GFX/POINTER.png create mode 100644 GFX/STAR.png create mode 100644 GFX/sprites.bms diff --git a/GFX/MASS.png b/GFX/MASS.png new file mode 100644 index 0000000..9965d97 Binary files /dev/null and b/GFX/MASS.png differ diff --git a/GFX/PARTICLE.png b/GFX/PARTICLE.png new file mode 100644 index 0000000..6e39e3e Binary files /dev/null and b/GFX/PARTICLE.png differ diff --git a/GFX/POINT.png b/GFX/POINT.png new file mode 100644 index 0000000..6e39e3e Binary files /dev/null and b/GFX/POINT.png differ diff --git a/GFX/POINTER.png b/GFX/POINTER.png new file mode 100644 index 0000000..c520048 Binary files /dev/null and b/GFX/POINTER.png differ diff --git a/GFX/STAR.png b/GFX/STAR.png new file mode 100644 index 0000000..6fef517 Binary files /dev/null and b/GFX/STAR.png differ diff --git a/GFX/sprites.bms b/GFX/sprites.bms new file mode 100644 index 0000000..59a5d29 Binary files /dev/null and b/GFX/sprites.bms differ diff --git a/main.bmx b/main.bmx index 1a2646b..f6ca18d 100644 --- a/main.bmx +++ b/main.bmx @@ -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 diff --git a/types.bmx b/types.bmx index 322d863..6622ce4 100644 --- a/types.bmx +++ b/types.bmx @@ -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 -- cgit v1.2.3