-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExample - Moveable Nodes.bb
151 lines (139 loc) · 2.62 KB
/
Example - Moveable Nodes.bb
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
;
;
;
;
Graphics 640,480,16,2
SetBuffer BackBuffer()
Type pup
Field nodex[10]
Field nodey[10]
Field active[10]
Field connectto[10]
End Type
makenewpop
Function makenewpop()
this.pup = New pup
For i=0 To 10
this\nodex[i] = Rand(96) + 100
this\nodey[i] = Rand(96) + 100
this\active[i]= False
this\connectto[i] = -1
Next
End Function
Function drawpop()
For this.pup = Each pup
For i=0 To 10
Color 32,32,32
Rect this\nodex[i],this\nodey[i],8,8,True
Color 255,255,0
Rect this\nodex[i],this\nodey[i],8,8,False
If this\active[i] = True Then
Color 255,0,0
Rect this\nodex[i],this\nodey[i],8,8,True
End If
Next
Next
End Function
Function deselectnodes()
For this.pup =Each pup
For i=0 To 10
this\active[i] = False
Next
Next
End Function
Function popnodecol()
If MouseDown(2) = True Then
For this.pup = Each pup
For i=0 To 10
If RectsOverlap(MouseX(),MouseY(),1,1,this\nodex[i],this\nodey[i],8,8) = True Then
this\active[i] = True : Return
End If
Next
Next
End If
If MouseDown(1) = False Then Return
deselectnodes
For this.pup = Each pup
For i=0 To 10
If RectsOverlap(MouseX(),MouseY(),1,1,this\nodex[i],this\nodey[i],8,8) = True Then
this\active[i] = True : Return
End If
Next
Next
End Function
Function connectto()
If KeyDown(57) = True Then
For this.pup = Each pup
For i = 0 To 10
If this\active[i] = True
For ii = 0 To 10
If i<>ii Then
If this\active[ii] = True Then
this\connectto[i ] = ii
this\connectto[ii] = i
this\active[i] = False
this\active[ii] = False
Return
End If
End If
Next
End If
Next
Next
End If
End Function
Function drawconnectto()
For this.pup = Each pup
For i=0 To 10
;
If this\connectto[i] > -1 Then
x1 = this\nodex[i]
y1 = this\nodey[i]
x2 = this\nodex[this\connectto[i]]
y2 = this\nodey[this\connectto[i]]
;
Line x1+4,y1+4,x2+4,y2+4
End If
;
Next
Next
End Function
Function movenode()
;
For this.pup = Each pup
For i=0 To 10
If this\active[i] = True Then
Exit
End If
Next
If i>10 Then Return
;
If KeyDown(205) = True Then ; right
this\nodex[i] = this\nodex[i] + 1
End If
If KeyDown(203) = True Then ; left
this\nodex[i] = this\nodex[i] - 1
End If
If KeyDown(208) = True Then ; down
this\nodey[i] = this\nodey[i] + 1
End If
If KeyDown(200) = True Then ; up
this\nodey[i] = this\nodey[i] - 1
End If
;
Next
End Function
While KeyDown(1) = False
Cls
;
movenode
drawconnectto
connectto
drawpop
popnodecol
Flip
Wend
End
Function dist#(x1,y1,x2,y2)
Return Sqr((x1-x2)^2+(y1-y2)^2)
End Function