void Player::fire(int tx, int ty) { Thing& thing = login.getThing(); if (!thing.isAlive()) { return; } send("@fire requested"); // fire (-1, 5); target, at most // client (x,y) beginning Game& game = Game::getGame(); ID x = thing.getX(); ID y = thing.getY(); int fr = getFirerange(); printf("life: %d, range %d", getLife(), getFirerange()); for(int i=1; i<=fr; i++) { //send("Fire loop"); ID nid = game.getCell(ID(x.asInt() + i*tx),ID(y.asInt() + i*ty)); game.setTransient(ID(x.asInt() + i*tx),ID(y.asInt() + i*ty),1,0.5); long int myid = nid.asInt(); if (myid != 0) { if(myid >= 100) { Thing& other = game.getThing(myid); other.setLife(other.getLife() - 1000); if(other.getLife() <= 0) other.setLifetime(0); } break; // something hit } } //send("Fire finished"); }
void Player::look() { send("@look begins"); ID x, y; Game& game = Game::getGame(); Thing& thing = login.getThing(); x = thing.getX(); y = thing.getY(); char buf[256], buf_bar[256]; int dx = 10, dy = 5; int at = 0; for (long int xx=x.asInt()-dx; xx<=x.asInt()+dx+2; xx++) { buf_bar[at] = ':'; at++; } buf_bar[at] = '\0'; send(buf_bar); for (long int yy=y.asInt()-dy; yy<=y.asInt()+dy; yy++) { at = 0; buf[at] = ':'; at++; for (long int xx=x.asInt()-dx; xx<=x.asInt()+dx; xx++) { char ch = ' '; ID nid = game.getCell(ID(xx),ID(yy)); long int x = nid.asInt(); if (x!=0) { if (x>=100) { if(!game.getThing(nid).isAlive()) { if (x==login.getID().asInt()) { ch = '%'; } else { ch = '*'; } } else if (x==login.getID().asInt()) { ch = 'Q'; // me } else if(game.getThing(nid).isBullet()) { ch = '.'; } else { ch = 'O'; // another one } } else if(x == 1) { ch = '#'; // piece of wall } else if(x == 2) { ch = 'o'; // a bullet } } if (ch==' ') { int transient = game.getTransient(ID(xx),ID(yy)); if (transient) { ch = '='; } } buf[at] = ch; at++; } buf[at] = ':'; at++; buf[at] = '\0'; send(buf); } send(buf_bar); sprintf(buf,"Player %s Location %d %d Life %d", login.getThing().getName(), thing.getX().asInt(), thing.getY().asInt(), login.getThing().getLife()/1000); send(buf); for (long int yy=y.asInt()-dy; yy<=y.asInt()+dy; yy++) { for (long int xx=x.asInt()-dx; xx<=x.asInt()+dx; xx++) { ID nid = game.getCell(ID(xx),ID(yy)); long int x = nid.asInt(); if (x>=100 && x!=login.getID().asInt()) { char buf[1000]; sprintf(buf,"Player %s Location %d %d Life %d", game.getThing(nid).getName(), xx,yy, game.getThing(nid).getLife()/1000); send(buf); } } } send("@look ends"); }