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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
#include "objects.h"
void Monster::get_border() {
int i=game.RAND(0,3);
if (i%2==0) target_x=game.RAND(0, game.scrwidth-bill.width);
else target_y=game.RAND(0, game.scrheight-bill.height);
switch (i) {
case 0: target_y=-bill.height-16; break;
case 1: target_x=game.scrwidth+1; break;
case 2: target_y=game.scrwidth+1; break;
case 3: target_x=-bill.width-2; break;
}
}
/* Adds a bill to the in state*/
void Monster::enter(){
state = IN;
get_border();
x = target_x; y=target_y;
index = 0;
cels = bill.lcels;
cargo = OS.WINGDOWS;
x_offset = -2;
y_offset = -15;
target_c = game.RAND(0, net.units-1);
target_x = net.computers[target_c].x+net.width-XOFFSET;
target_y = net.computers[target_c].y+YOFFSET;
bill.on_screen++; bill.off_screen--;
}
/* Moves bill toward his target - returns whether or not he moved */
int Monster::move (int mode) {
int xdist = target_x - x;
int ydist = target_y - y;
int step = step_size(game.level);
int dx, dy;
int signx = xdist >= 0 ? 1 : -1;
int signy = ydist >= 0 ? 1 : -1;
xdist = abs(xdist);
ydist = abs(ydist);
if (!xdist && !ydist) return 0;
else if (xdist<step && ydist<step) {
x = target_x;
y = target_y;
}
else {
dx = (xdist*step*signx)/(xdist+ydist);
dy = (ydist*step*signy)/(xdist+ydist);
switch(mode) {
case SLOW: break;
case FAST: dx = 5*dx/4; dy = 5*dy/4; break;
}
x+=dx;
y+=dy;
if (dx<0)
cels = bill.lcels;
else if (dx>0)
cels = bill.rcels;
}
return 1;
}
void Monster::draw() {
switch (state) {
case IN:
case OUT:
case DYING: draw_std(); break;
case AT: draw_at(); break;
case STRAY: draw_stray(); break;
default: break;
}
}
/* Update Bill's position */
void Monster::update_in() {
int moved = move(SLOW);
if (!moved && (net.computers[target_c].os != OS.WINGDOWS)
&& !(net.computers[target_c].busy))
{
net.computers[target_c].busy=1;
cels = bill.acels;
index=0;
state = AT;
return;
}
else if (!moved) {
int i;
do {
i=game.RAND(0, net.units-1);
} while (i == target_c);
target_c = i;
target_x = net.computers[target_c].x + net.width-XOFFSET;
target_y = net.computers[target_c].y + YOFFSET;
}
index++;
index%=bill.WCELS;
y_offset+=(8*(index%2)-4);
}
/* Update Bill standing at a computer */
void Monster::update_at() {
int sys;
if (index==0 && net.computers[target_c].os == OS.OFF) {
index=6;
sys = net.computers[target_c].find_stray();
if (sys<0) cargo = -1;
else {
cargo = bill.list[sys].cargo;
bill.list[sys].state = OFF;
}
}
else index++;
if (index == 13) {
y_offset = -15;
x_offset = -2;
get_border();
index = 0;
cels = bill.lcels;
state = OUT;
net.computers[target_c].busy=0;
return;
}
y_offset = bill.height - OS.height;
switch (index) {
case 1 :
case 2 : x -= 8; x_offset +=8; break;
case 3 : x -= 10; x_offset +=10; break;
case 4 : x += 3; x_offset -=3; break;
case 5 : x += 2; x_offset -=2; break;
case 6 :
if (net.computers[target_c].os != OS.OFF) {
net.base--; net.off++;
cargo = net.computers[target_c].os;
}
else {
x-=21; x_offset+=21;
}
net.computers[target_c].os = OS.OFF;
y_offset = -15;
x += 20;
x_offset -=20;
break;
case 7 : sy = y_offset; sx = -2; break;
case 8 : sy = -15; sx = -2; break;
case 9 : sy = -7; sx = -7; x -= 8; x_offset +=8; break;
case 10 : sy = 0; sx = -7; x -= 15; x_offset +=15; break;
case 11 : sy = 0; sx = -7;
net.computers[target_c].os = OS.WINGDOWS;
net.off--; net.win++;
break;
case 12 : x += 11; x_offset -=11;
}
}
/* Updates Bill fleeing with his ill gotten gain */
void Monster::update_out() {
if (game.INTERSECT(x, y, bill.width, bill.height, 0, 0, game.scrwidth,
game.scrheight))
{
move(FAST);
index++;
index%=bill.WCELS;
y_offset+=(8*(index%2)-4);
}
else {
state = OFF;
bill.on_screen--; bill.off_screen++;
}
}
/* Updates Bill who is dying */
void Monster::update_dying() {
if (index < bill.DCELS-1){
y_offset += (index*GRAVITY);
index++;
}
else {
y+=y_offset;
if (cargo<0 || cargo == OS.WINGDOWS) state = OFF;
else state = STRAY;
bill.on_screen--;
}
}
void Monster::update() {
switch (state) {
case IN: update_in(); break;
case AT: update_at(); break;
case OUT: update_out(); break;
case DYING: update_dying(); break;
default: break;
}
}
int Monster::clicked(int locx, int locy) {
return (locx>x && locx<x+bill.width && locy>y && locy<y+bill.height);
}
int Monster::clickedstray(int locx, int locy) {
return (locx>x && locx<x+OS.width && locy>y && locy<y+OS.height);
}
int Monster::step_size(unsigned int lev) {
return game.MIN(14+lev, 18);
}
void Monster::draw_std() {
if (cargo>=0)
ui.draw(OS.os[cargo], x + x_offset, y + y_offset);
ui.draw(cels[index], x, y);
}
void Monster::draw_at() {
if (index>6 && index<12)
ui.draw(OS.os[0], x + sx, y + sy);
if (cargo>=0)
ui.draw(OS.os[cargo], x + x_offset, y + y_offset);
ui.draw(cels[index], net.computers[target_c].x,
net.computers[target_c].y);
}
void Monster::draw_stray() {
if (game.grabbed==-1 || x != bill.list[game.grabbed].x)
ui.draw(OS.os[cargo], x, y);
}
|