File tree 3 files changed +12
-7
lines changed
3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 57
57
var dogVector = new point ( 1 , 1 ) ;
58
58
59
59
var bone = new point ( 50 , 50 ) ;
60
-
60
+
61
61
function getVector ( a , b ) {
62
62
var dist = distance ( a , b ) ;
63
63
64
64
if ( dist == 0 ) {
65
65
return new point ( 0 , 0 ) ;
66
66
}
67
67
68
- var distX = Math . abs ( a . x - b . x ) / dist ;
69
- var distY = Math . abs ( a . y - b . y ) / dist ;
70
-
68
+ var distX = Math . abs ( a . x - b . x ) ;
69
+ var distY = Math . abs ( a . y - b . y ) ;
70
+
71
+ total = distX + distY ;
72
+
73
+ distX = distX / total ;
74
+ distY = distY / total ;
75
+
71
76
if ( b . x < a . x ) {
72
77
distX = - distX ;
73
78
}
104
109
}
105
110
106
111
function processFindingCat ( ) {
107
-
108
112
for ( var i = 0 ; i < cats . length ; i ++ ) {
109
113
var c = cats [ i ] ;
110
114
if ( distance ( mouse , c ) < 5 ) {
141
145
142
146
var dVector = dogVectors [ i ] ;
143
147
d . x = d . x + dVector . x ;
144
- d . y = d . y + dVector . y ;
148
+ d . y = d . y + dVector . y ;
145
149
if ( d . x > width || d . y > height ) {
146
150
d . x = 0 ;
147
151
d . y = 0 ;
166
170
$ ( document ) . ready ( function ( ) {
167
171
var canvas = $ ( '#canvas' ) ;
168
172
context = canvas . get ( 0 ) . getContext ( '2d' ) ;
173
+ setBackground ( ) ;
169
174
170
175
setInterval ( draw , 10 ) ;
171
176
canvas . mousemove ( function ( e ) {
Original file line number Diff line number Diff line change 209
209
dist = objectDist ;
210
210
object = array [ i ] ;
211
211
212
- }
212
+
213
213
}
214
214
215
215
object . highlighted = true ;
You can’t perform that action at this time.
0 commit comments