summaryrefslogtreecommitdiff
path: root/main.bmx
blob: f6ca18dec8b5075c363ea584b06fbfb64bc85e24 (plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
' It's all a bit rolly
'
Strict

Import noddybox.vector
Import noddybox.bitmapfont

' Includes
'
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

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
'

' Test code
'
Global main_mass:TMass=New TMass
Global mass:TList=CreateList()
Global star:TList=CreateList()
Global cx:Int=GraphicsWidth()/2
Global cy:Int=GraphicsHeight()/2

main_mass.x=cx'/2
main_mass.y=cy
main_mass.friend=False
'main_mass.inverse=True
main_mass.img=star_img

For Local r:Int=0 Until 1000
	Local s:TPoint=New TPoint
	Local d:Float
	Local a:Float
	s=New TPoint
	d=Rnd(50,100)
	'a=Rnd(0,360)
	a=Rand(0,3)*90
	s.x=main_mass.x+d*Sin(a)
	s.y=main_mass.y+d*Cos(a)
	s.v.x=Sin(a+90)/(d/30)
	s.v.y=Cos(a+90)/(d/30)
	star.AddLast(s)
Next

mass.AddLast(main_mass)

TParticleMachine.Clear()

While Not KeyHit(KEY_ESCAPE)
	Cls
	
	Local dead:Int=0
	Local lost:Int=0
	
	For Local m:TMass=EachIn mass
		For Local s:TPoint=EachIn star
			s.Attract(m)
		Next
	Next
	
	TParticleMachine.Process()
	
	For Local m:TMass=EachIn mass
		m.MoveAndDraw()
	Next
	
	For Local s:TPoint=EachIn star
		s.MoveAndDraw()
		
		If s.dead
			dead:+1
		ElseIf s.lost
			lost:+1
		EndIf
	Next
	
	font.Draw("PARTICLES",0,0)
	font.DrawColoured(star.Count()-dead-lost,font.TextWidth("PARTICLES")+10,0,255,255,0)
	font.Draw("CAPTURED",200,0)
	font.DrawColoured(dead,font.TextWidth("CAPTURED")+210,0,255,0,255)
	font.Draw("LOST",400,0)
	font.DrawColoured(lost,font.TextWidth("LOST")+410,0,255,0,0)
	
	If MouseHit(1)
		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



' Globals
'
Rem
Global player:TBall=New TBall
player.r=255
player.g=255
player.b=255

Global balls:TList=CreateList()

balls.AddLast(player)

For Local f:Int=0 To 10
	balls.AddLast(New TBall)
Next

While Not KeyHit(KEY_ESCAPE)
	Cls
	
	If KeyHit(KEY_MOUSELEFT)
		player.v.x=MouseX()-player.x
		player.v.y=MouseY()-player.y
		player.v.Normalise()
		player.v.Scale(2)
	EndIf
	
	For Local b1:TBall=EachIn balls
		For Local b2:TBall=EachIn balls
			If b1<>b2
				b1.Collide(b2)
			EndIf
		Next
	Next
	
	For Local b1:TBall=EachIn balls
		b1.MoveAndDraw()
	Next
	
	FlushMem
	Flip
Wend
EndRem

EndGraphics
End