void Cliente::start(char* host, int port) { char mensRecive[10000]; char* pmensRecive; //char posicion[100000]; //char* pPosicion; TDA_Parser parser; std::string msj; this->finLoading=false; SDL_Surface *screen; SDL_Event evento; std::string pPosicion = ""; std::string cadena = ""; std::string puntaje =""; std::string tipoBonus = ""; std::string idFigura = ""; std::string ultimoPad = ""; std::string puntajeJugador =""; SDL_Rect rect; try { this->sock.connect(host, port); status = CONNECTED; loading(&sock); Escenario* escenario = Escenario::obtenerInstancia(); escenario->iniciarSDL(); GraficadorPuntajes::obtenerInstancia()->graficarString(escenario->getScreen(),"LOADING...",escenario->getAncho()/3,2*escenario->getAlto()/5); SDL_Flip(escenario->getScreen()); loading(&sock); escenario->cargarArchivo("nivel"+escenario->getNumeroNivelEnString()+".xml"); escenario->clienteInicializarListaBonus(); escenario->setCorriendo(true); receiver.start((void*)&sock); sender.start((void*)&sock); while (receiver.isEmpty()){ Sleep(2); } msj= this->get(); if(msj.find("INICIAR")==0){ GraficadorPuntajes::obtenerInstancia()->graficarString(escenario->getScreen(),"NIVEL "+escenario->getNumeroNivelEnString(),escenario->getAncho()/3,2*escenario->getAlto()/5); SDL_Flip(escenario->getScreen()); Sleep(3000); } Pad* pad = escenario->getPadJugador(); while (receiver.running() == true){ while (receiver.isEmpty()){ Sleep(1); } // std::cout<<"size pila: "<<receiver.getFileSize()<<endl; msj=""; msj= this->get(); ///std::cout<<"msj "<<msj<<endl; if(msj.find("TEJO")==0){ pPosicion = ""; pPosicion = msj.substr(msj.find(" ")+1,msj.find_last_of(" ")); escenario->getTejo()->setX(atoi(pPosicion.c_str())); pPosicion = msj.substr(msj.find_last_of(" ")+1,msj.size()); escenario->getTejo()->setY(atoi(pPosicion.c_str())); } else if(msj.find("PAD1")==0){ pPosicion = ""; pPosicion = msj.substr(msj.find(" ")+1,msj.size()); escenario->getPadCliente1()->setY(atoi(pPosicion.c_str())); } else if(msj.find("PAD2")==0){ pPosicion = ""; pPosicion = msj.substr(msj.find(" ")+1,msj.size()); escenario->getPadCliente2()->setY(atoi(pPosicion.c_str())); } else if(msj.find("PUNTAJE")==0) { //el cliente no se entera quien hizo el gol, cuando recibe puntajes es porque hubo un gol //se setean los puntajes nuevos y se decrementa la cantidad de tejos restantes (esto es solo para graficar los "tejitos" en pantalla cadena = ""; puntaje =""; cadena = msj.substr(msj.find(" ")+1,msj.find_last_of(" ")); puntaje = cadena.substr(0,cadena.find_last_of(" ")); escenario->getPadCliente1()->getPuntaje()->setCantPuntosJugador(atoi(puntaje.c_str())); puntaje = msj.substr(msj.find_last_of(" ")+1,msj.size()); escenario->getPadCliente2()->getPuntaje()->setCantPuntosJugador(atoi(puntaje.c_str())); escenario->decrementarTejosRestantes(); escenario->setPrimerPintada(false); } else if(msj.find("BONUS")==0){ tipoBonus = ""; idFigura = ""; tipoBonus = msj.substr(msj.find(" ")+1,msj.find_last_of(" ")); idFigura = msj.substr(msj.find_last_of(" ")+1,msj.size()); Figura* figura= escenario->getFiguraPorId(idFigura); Bonus* bonus = escenario->obtenerBonusPorTipo(atoi(tipoBonus.c_str())); figura->setImagenBonus(bonus->getImagen()); escenario->setBonusActual(bonus); escenario->setFiguraConBonus(figura); escenario->setPrimerPintada(false); } else if(msj.find("APLICAR_BONUS")==0){ ultimoPad = ""; ultimoPad = msj.substr(msj.find(" ")+1,msj.size()); Bonus::desAplicar(); escenario->getTejo()->setUltimaColisionPad(ultimoPad); escenario->getFiguraConBonus()->setImagenBonus(NULL); escenario->getFiguraConBonus()->setEscalada(false); escenario->setFiguraConBonus(NULL); escenario->setPrimerPintada(false); escenario->getBonusActual()->aplicar(); } else if(msj.find("NIVEL_TERMINADO")==0){ escenario->setCorriendo(false); escenario->setTejosRestantes(7); escenario->incrementarNivel(); GraficadorPuntajes::obtenerInstancia()->graficarString(escenario->getScreen(),"NIVEL "+escenario->getNumeroNivelEnString(),escenario->getAncho()/3,2*escenario->getAlto()/5); SDL_Flip(escenario->getScreen()); Sleep(3000); escenario->borrarListaFiguras(); escenario->borrarListaTexturas(); escenario->setearImagenesEnNull(); escenario->setFiguraConBonus(NULL); Bonus::desAplicar(); escenario->cargarArchivo("nivel"+escenario->getNumeroNivelEnString()+".xml"); escenario->setPrimerPintada(false); escenario->setCorriendo(true); } else if(msj.find("GANADOR")==0){ puntaje =""; cadena = ""; if(msj.find("GANADOR 1")==0){ if(escenario->getNumJugador() == 1) cadena = "GANASTE!!!!!!!"; else cadena = "PERDISTE!!!!!!"; } else if(msj.find("GANADOR 2")==0){ if(escenario->getNumJugador() == 1) cadena = "PERDISTE!!!!!!"; else cadena = "GANASTE!!!!!!!"; } else if(msj.find("GANADOR 0")==0){ cadena = "EMPATARON!!!!!!"; } intToString(escenario->getPadCliente2()->getPuntaje()->getCantPuntosJugador(),puntajeJugador); puntaje+=puntajeJugador; intToString(escenario->getPadCliente1()->getPuntaje()->getCantPuntosJugador(),puntajeJugador); puntaje+='-'; puntaje+=puntajeJugador; cadena += " "+ puntaje; GraficadorPuntajes::obtenerInstancia()->graficarString(escenario->getScreen(),cadena,escenario->getAlto()/3,2*escenario->getAlto()/5); SDL_Flip(escenario->getScreen()); Sleep(3000); //seteo msj en finJuego asi no grafica mas CAMBIAR ESTO this->sock.send("FIN\n"); this->stop(); } else if(msj.find("JUGADOR_DESCONECTADO")==0){ cadena = "SE DESCONECTO EL OPONENTE"; GraficadorPuntajes::obtenerInstancia()->graficarString(escenario->getScreen(),cadena,30,2*escenario->getAlto()/5); SDL_Flip(escenario->getScreen()); Sleep(3000); //seteo msj en finJuego asi no grafica mas CAMBIAR ESTO msj = "FINJUEGO"; } if(msj.find("FINJUEGO")==0){ this->sock.send("QUIT\n"); receiver.stop(); } else{ rect.x =0; rect.y =0; rect.w = escenario->getAncho(); rect.h = escenario->getAlto(); if (!escenario->getPrimerPintada()){ escenario->pintarPantalla(); escenario->setPrimerPintada(true); } SDL_PollEvent(&evento); switch (evento.type) { case SDL_KEYDOWN: //std::cout<<"The %s key was pressed!\n"<<evento.key.keysym.sym; if (evento.key.keysym.sym == SDLK_UP){ //std::cout<<"Arriba"<<std::endl; if(pad->getY()>0) pad->setMoverArriba(true); }else if (evento.key.keysym.sym == SDLK_DOWN){ //std::cout<<"Abajo"<<std::endl; if(pad->getY()<escenario->getAlto() - pad->getAltura()) pad->setMoverAbajo(true); }else if (evento.key.keysym.sym == SDLK_SPACE){ //std::cout<<"Space"<<std::endl; pad->setSoltarTejo(true); }; break; case SDL_QUIT: this->sock.send("QUIT\n"); receiver.stop(); break; default: //std::cout<<"ESTA ACAAA"<<endl; break; } SDL_BlitSurface(escenario->buffer, NULL,escenario->screen, &rect); escenario->getPadCliente1()->dibujar(escenario->screen); escenario->getPadCliente2()->dibujar(escenario->screen); escenario->getTejo()->dibujar(escenario->screen); SDL_Flip(escenario->getScreen()); SDL_FreeSurface(escenario->screen); } } this->stop(); std::cerr << "SALIOOO.." << endl; } catch (cSocketException &e) { std::cerr << e.what() << endl; status = NO_HOST; } }
void MyStrategy::Move(Tank self, World world, model::Move& move) { if (world.tick() == 1) { FirstTick(self, world); } vector<Tank> t = world.tanks(); vector<Shell> s = world.shells(); vector<Bonus> b = world.bonuses(); double xForce = 0 , yForce = 0 ; for (int i = 0; i < t.size(); ++i) { if (self.id() == t[i].id()) continue; if (EnemyDead(&t[i])) continue; ForceModify( self, t[i], xForce, yForce, -1.0 ); } Bonus * pBonus = 0; if ( !TimeToHide( self, world, move ) ) { pBonus = get_need_id(g_need_id, b); //pBonus = GetNeededBonus( self, b ); if (!pBonus || ( pBonus->type() != MEDIKIT && HealthIsCritical(self) ) ) { pBonus = GetNeededBonus( self, b ); } } for (int i = 0; i < b.size(); ++i) { double bonusPower = 1.0; if (pBonus && b[i].id() == pBonus->id()) { bonusPower = 10000.0; } ForceModify( self, b[i], xForce, yForce, bonusPower ); } /* for (int i = 0; i < s.size(); ++i) { if (self.player_name() != s[i].player_name()) { ForceModify( self, s[i], xForce, yForce, -100000.0 ); } } */ double orig_angle = atan2(xForce, yForce); double angle = orig_angle; double fangle = fabs(angle); double MIN_ANGLE_B = M_PI/30.0; double dir = 1.0; double s_angle = self.angle(); if (orig_angle > PI_D_2) { angle = M_PI - fangle; dir = -1.0; } if (orig_angle < -PI_D_2) { angle = fangle - M_PI; dir = -1.0; } if (fangle > PI_D_2) { if ( angle > MIN_ANGLE_B ) { move.set_left_track_power(-1.0); move.set_right_track_power( .75 ); //(.75); } else if ( angle < -MIN_ANGLE_B ) { move.set_left_track_power(.75 );//(.75); move.set_right_track_power(-1.0); } else { move.set_left_track_power(dir*1); move.set_right_track_power(dir*1); } } else { if ( angle > MIN_ANGLE_B ) { move.set_left_track_power(.75 );//(.75); move.set_right_track_power(-1.0); } else if ( angle < -MIN_ANGLE_B ) { move.set_left_track_power(-1.0); move.set_right_track_power( .75 ); //(.75); } else { move.set_left_track_power(dir*1); move.set_right_track_power(dir*1); } } //move.set_left_track_power(0); //move.set_right_track_power(0); Shoot( self, world, move ); }
void RemoteProcessClient::writeBonus(const Bonus& bonus) { writeBoolean(true); writeLong(bonus.getId()); writeDouble(bonus.getMass()); writeDouble(bonus.getX()); writeDouble(bonus.getY()); writeDouble(bonus.getSpeedX()); writeDouble(bonus.getSpeedY()); writeDouble(bonus.getAngle()); writeDouble(bonus.getAngularSpeed()); writeDouble(bonus.getWidth()); writeDouble(bonus.getHeight()); writeEnum<BonusType>(bonus.getType()); }
void VisualEngine::onPaintAlt(IDrawableArea* drawable) { #if 0 Graphics ^g = e->Graphics; Pen ^p = gcnew Pen(Color::Red); int width = form->ClientRectangle.Width; int height = form->ClientRectangle.Height; if (backBuffer == nullptr) { backBuffer = gcnew Bitmap(width, height); } //Bitmap ^ localBitmap = gcnew Bitmap(width, height); //Graphics ^ bitmapGraphics = Graphics::FromImage( localBitmap ); Graphics ^ bitmapGraphics = Graphics::FromImage(backBuffer); bitmapGraphics->Clear(Color::Black); // Begin drawing of scene Serpents::Serpent &serpent = engine->getSerpent(); for (int i = 0; i<serpent.getLength(); i++) { BodyPart * bodyPart = serpent.getBodyPart(i); if (bodyPart != NULL) { bool vis = serpent.getBodyPart(i)->isSpawned(); double x = (int)(serpent.getBodyPart(i)->getLocation().x - serpent.getBodyPart(i)->getSizeFromCenter()); double y = (int)(serpent.getBodyPart(i)->getLocation().y - serpent.getBodyPart(i)->getSizeFromCenter()); double w = (int)serpent.getBodyPart(i)->getSize().x; double h = (int)serpent.getBodyPart(i)->getSize().y; //System::Diagnostics::Trace::WriteLine("index=" + i + "; pos=" // + x + "," // + y + "," // + w + "," // + h + ";" // + " visible=" + vis // ); if (vis) { bitmapGraphics->DrawEllipse(p, (float)x, (float)y, (float)w, (float)h); //bitmapGraphics->DrawRectangle(p, (float)x, (float)y, (float)w, (float)h); } } } for (int i = 0; i< serpent.path->getLength(); i++) { PathStrip *myStrip = serpent.path->getStrip(i); p->Color = Color::Gray; bitmapGraphics->DrawLine(p, (float)myStrip->getHeadLocation().x, (float)myStrip->getHeadLocation().y, (float)myStrip->getTailLocation().x, (float)myStrip->getTailLocation().y); p->Color = Color::GreenYellow; DPOINT myPoint = serpent.path->getCoords(i); float x = (float)myPoint.x; float y = (float)myPoint.y; bitmapGraphics->DrawLine(p, x - 1, y - 1, x + 1, y + 1); bitmapGraphics->DrawLine(p, x - 1, y + 1, x + 1, y - 1); } for (int i = 0; i<engine->getBonusController().getNumberOfItems(); i++) { Bonus * myBonus = engine->getBonusController().getItemAt(i); double x = (int)(myBonus->getLocation().x - myBonus->getSizeFromCenter()); double y = (int)(myBonus->getLocation().y - myBonus->getSizeFromCenter()); double w = (int)myBonus->getSize().x; double h = (int)myBonus->getSize().y; //System::Diagnostics::Trace::WriteLine("bonus, index=" + i + "; pos=" // + x + "," // + y + "," // + w + "," // + h + ";" // ); p->Color = Color::YellowGreen; bitmapGraphics->DrawRectangle(p, (float)x, (float)y, (float)w, (float)h); } // End drawing of scene Brush ^ myBrush = System::Drawing::Brushes::Beige; System::Drawing::Font ^myfont = gcnew Font(System::Drawing::FontFamily::GenericSansSerif, 10); drawable->drawText("up/down = increase/decrease speed; left/right = turn left/right", ColorRgb(0.5, 0.5, 0.5), 0, 0); bitmapGraphics->DrawString("up/down = increase/decrease speed; left/right = turn left/right", myfont, myBrush, 0, 0); bitmapGraphics->SmoothingMode = System::Drawing::Drawing2D::SmoothingMode::AntiAlias; //g->DrawImage( localBitmap, 0, 0 ); e->Graphics->DrawImageUnscaled(backBuffer, 0, 0); #endif }