~ubuntu-branches/ubuntu/natty/xbill/natty

« back to all changes in this revision

Viewing changes to Cable.cc

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Bridgett
  • Date: 2004-09-07 09:52:14 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040907095214-d0m46ojc8f7upuqm
Tags: 2.1-4
maintainer upload of NMU - many thanks Tollef (closes: #268885) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "objects.h"
2
 
 
3
 
void Cable::setup() {
4
 
        c1 = game.RAND(0, net.units-1);
5
 
        do {
6
 
                c2 = game.RAND(0, net.units-1);
7
 
        } while (c2 == c1);
8
 
        active = index = 0;
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;
14
 
}
15
 
 
16
 
void Cable::update () {
17
 
        if (active) {
18
 
                if ((net.computers[c1].os == OS.WINGDOWS) ==
19
 
                        (net.computers[c2].os == OS.WINGDOWS))
20
 
                                active=0;
21
 
                else if (net.computers[c1].os == OS.WINGDOWS ||
22
 
                        net.computers[c2].os == OS.WINGDOWS)
23
 
                {
24
 
                        int dir, xdist, ydist,c;
25
 
                        float sx, sy;
26
 
                        dir = (net.computers[c2].os == OS.WINGDOWS);
27
 
                        if (dir)
28
 
                                {xdist=x1-x; ydist=y1-y;}
29
 
                        else
30
 
                                {xdist=x2-x; ydist=y2-y;}
31
 
                        sx = xdist >= 0 ? 1.0 : -1.0;
32
 
                        sy = ydist >= 0 ? 1.0 : -1.0;
33
 
                        xdist = abs(xdist);
34
 
                        ydist = abs(ydist);
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)
39
 
                                                net.off--;
40
 
                                        else
41
 
                                                net.base--;
42
 
                                        net.win++;
43
 
                                        net.computers[c].os=OS.WINGDOWS;
44
 
                                }
45
 
                                active=0;
46
 
                        }
47
 
                        else if (game.MAX (xdist, ydist) < spark.speed) {
48
 
                                if (dir)
49
 
                                        {x = x1; y = y1;}
50
 
                                else
51
 
                                        {x = x2; y = y2;}
52
 
                        }
53
 
                        else {
54
 
                                fx+=(xdist*spark.speed*sx)/(xdist+ydist);
55
 
                                fy+=(ydist*spark.speed*sy)/(xdist+ydist);
56
 
                                x = (int)fx;
57
 
                                y = (int)fy;
58
 
                        }
59
 
                        index = 1 - index;
60
 
                }
61
 
        }
62
 
        else {
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)
68
 
                {
69
 
                        if (delay>0) delay--;
70
 
                        else {
71
 
                                active = 1;
72
 
                                if (net.computers[c1].os == OS.WINGDOWS)
73
 
                                        {fx=x=x1; fy=y=y1;}
74
 
                                else
75
 
                                        {fx=x=x2; fy=y=y2;}
76
 
                        }
77
 
                }
78
 
        }
79
 
}
80
 
 
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);
85
 
}
86
 
 
87
 
void Cable::draw() {
88
 
        int rx = x - spark.width/2;
89
 
        int ry = y - spark.height/2;
90
 
        ui.draw_line(x1,y1,x2,y2);
91
 
        if (active)
92
 
                ui.draw(spark.pictures[index], rx, ry);
93
 
}
94