-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMonkey - CircleOverlap x1 y1 r1 x2 y2 r2 function code example.monkey
More file actions
63 lines (57 loc) · 1.36 KB
/
Monkey - CircleOverlap x1 y1 r1 x2 y2 r2 function code example.monkey
File metadata and controls
63 lines (57 loc) · 1.36 KB
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
Import mojo
Class bubble
Field x:Float
Field y:Float
Field incx:Float
Field incy:Float
Method New()
x = Rnd(640)
y = Rnd(480)
incx = Rnd(-1,1)
incy = Rnd(-1,1)
End
End
Global blist:List<bubble> = New List<bubble>
Class MyGame Extends App
Method OnCreate()
SetUpdateRate(60)
For Local i:Int = 0 Until 10
blist.AddLast(New bubble)
End
End
Method OnUpdate()
For Local i:bubble = Eachin blist
i.x+=i.incx
i.y+=i.incy
If i.x<0 Then i.x = 640
If i.x>640 Then i.x = 0
If i.y<0 Then i.y = 480
If i.y>480 Then i.y = 0
End
For Local i:bubble = Eachin blist
For Local ii:bubble = Eachin blist
If i<>ii
If circleoverlap(i.x,i.y,10,ii.x,ii.y,10) = True
blist.Remove ii
End
End
End
End
End
Method OnRender()
Cls(0,0,0)
SetColor(255,255,255)
For Local i:bubble = Eachin blist
DrawCircle i.x,i.y,10
End
End
End
Function Main()
New MyGame()
End
Function circleoverlap:Bool(x1:Int,y1:Int,r1:Int,x2:Int,y2:Int,r2:Int)
Local dx:Int = x1-x2
Local dy:Int = y1-y2
Local r:Int = r1+r2
If dx*dx+dy*dy <= r*r Then Return True Else Return False
End