4
c1 = game.RAND(0, net.units-1);
6
c2 = game.RAND(0, net.units-1);
9
delay = spark.delay(game.level);
10
x1 = net.computers[c1].x + net.width/3;
11
x2 = net.computers[c2].x + net.width/3;
12
y1 = net.computers[c1].y + net.height/2;
13
y2 = net.computers[c2].y + net.height/2;
16
void Cable::update () {
18
if ((net.computers[c1].os == OS.WINGDOWS) ==
19
(net.computers[c2].os == OS.WINGDOWS))
21
else if (net.computers[c1].os == OS.WINGDOWS ||
22
net.computers[c2].os == OS.WINGDOWS)
24
int dir, xdist, ydist,c;
26
dir = (net.computers[c2].os == OS.WINGDOWS);
28
{xdist=x1-x; ydist=y1-y;}
30
{xdist=x2-x; ydist=y2-y;}
31
sx = xdist >= 0 ? 1.0 : -1.0;
32
sy = ydist >= 0 ? 1.0 : -1.0;
35
if (xdist==0 && ydist==0) {
36
if (dir==0) c=c2; else c=c1;
37
if (!net.computers[c].busy) {
38
if (net.computers[c].os == OS.OFF)
43
net.computers[c].os=OS.WINGDOWS;
47
else if (game.MAX (xdist, ydist) < spark.speed) {
54
fx+=(xdist*spark.speed*sx)/(xdist+ydist);
55
fy+=(ydist*spark.speed*sy)/(xdist+ydist);
63
if ((net.computers[c1].os == OS.WINGDOWS) ==
64
(net.computers[c2].os == OS.WINGDOWS))
65
delay = spark.delay(game.level);
66
else if (net.computers[c1].os == OS.WINGDOWS ||
67
net.computers[c2].os == OS.WINGDOWS)
72
if (net.computers[c1].os == OS.WINGDOWS)
81
int Cable::onspark (int locx, int locy) {
82
if (!active) return 0;
83
return (abs(locx-x) < spark.width
84
&& abs(locy-y) < spark.height);
88
int rx = x - spark.width/2;
89
int ry = y - spark.height/2;
90
ui.draw_line(x1,y1,x2,y2);
92
ui.draw(spark.pictures[index], rx, ry);