void Area::findConnections() { // XXX TODO fix this #if 0 if (!this->mDoc) return; this->mConnPins.clear(); Layer layer = this->layer(); QList<QSharedPointer<PartPin> > pins = net->pins(); foreach(QSharedPointer<PartPin> pin, pins) { // see if pin is on the right layer Pad pad = pin->getPadOnLayer(layer); if (pad.isNull()) continue; // no pad on this layer if( pad.connFlag() == Pad::CONN_NEVER ) continue; // pad never allowed to connect if( pad.connFlag() == Pad::CONN_DEFAULT && pin->isSmt() && !mConnectSMT ) continue; // SMT pad, not allowed to connect to this area // add to list if pad is inside copper area if( mPoly.testPointInside(pin->pos()) ) this->mConnPins.append(pin.toWeakRef()); }
int main( int argc, char** argv ){ QApplication app( argc, argv ) ; Pad* pad = new Pad() ; pad->show() ; return app.exec() ; }
void Robo::update( const Vector3& enemyPos ){ Pad* pad = Pad::instance(); if ( pad->isOn( Pad::TURN, mId ) ){ if ( pad->isOn( Pad::LEFT, mId ) ){ mAngleY += 1.0; if ( mAngleY > 180.0 ){ //-PIからPIにおさめる mAngleY -= 360.0; } } if ( pad->isOn( Pad::RIGHT, mId ) ){ mAngleY -= 1.0; if ( mAngleY < -180.0 ){ //-PIからPIにおさめる mAngleY += 360.0; } } }else{ //移動処理。まず視点を考慮しない加速度を出す Vector3 move( 0.0, 0.0, 0.0 ); if ( pad->isOn( Pad::UP, mId ) ){ move.z = -1.0; } if ( pad->isOn( Pad::DOWN, mId ) ){ move.z = 1.0; } if ( pad->isOn( Pad::LEFT, mId ) ){ move.x = -1.0; } if ( pad->isOn( Pad::RIGHT, mId ) ){ move.x = 1.0; } //視線方向を加味して回転 Matrix34 m; m.setRotationY( mAngleY + 180.0 ); m.multiply( &move, move ); mPosition += move; } //武器生成 if ( pad->isOn( Pad::FIRE, mId ) ){ //空き武器を探す for ( int i = 0; i < mBulletNumber; ++i ){ if ( mBullets[ i ].isEmpty() ){ mBullets[ i ].create( mDatabase, "bullet", mPosition, 45.0, mAngleY ); break; } } } //武器更新 for ( int i = 0; i < mBulletNumber; ++i ){ if ( !mBullets[ i ].isEmpty() ){ mBullets[ i ].update( enemyPos ); } } }
//-------------------------------------------------------------- void ofApp::setup(){ Pad thepad; thepad.setup(); Pad1.push_back(thepad); Enemy theenemy; theenemy.setup(); Enemy1.push_back(theenemy); Ball theball; theball.setup(); Ball1.push_back(theball); int padx; int pady; }
void Robo::think( bool* jump, bool* fire, bool* turn, bool* left, bool* right, bool* up, bool* down ) const { Pad* pad = Pad::instance(); if ( mId == 0 ){ //プレイヤー *jump = pad->isOn( Pad::JUMP, mId ); *fire = pad->isTriggered( Pad::FIRE, mId ); *turn = pad->isOn( Pad::TURN, mId ); *left = pad->isOn( Pad::LEFT, mId ); *right = pad->isOn( Pad::RIGHT, mId ); *up = pad->isOn( Pad::UP, mId ); *down = pad->isOn( Pad::DOWN, mId ); }else{ //AI //超馬鹿 //ロックオンしてなければジャンプする *jump = !mLockOn; //弾は撃てるだけ撃つ。 *fire = true; //旋回はしない *turn = false; //移動は変数を持つのが面倒なのでしない。 *left = *right = *up = *down = false; } }
void Renderer::render(Pad const& pad) { sf::RectangleShape rect(sf::Vector2f( unitsToPixelsX(Pad::Width), unitsToPixelsY(Pad::Height))); rect.setPosition(sf::Vector2f( worldToScreenX(pad.getPosition()) - rect.getSize().x/2.0f, worldToScreenY(Pad::VerticalPosition))); m_window.draw(rect); }
void LandPattern::initialize(QXmlStreamReader& xml, UnitsType units) { while (!xml.atEnd() && !xml.hasError()) { xml.readNext(); if (xml.isStartElement()) { if (xml.name() == "Pad") { Pad pad; pad.initialize(xml, units); m_pads.append(pad); } else if (xml.name() == "Target") { Target target; target.initialize(xml, units); m_targets.append(target); } } else if (isEndElementWithName(xml, "LandPattern")) { // </LandPattern> return; } } }
u8 pad_poll(u8 value) { if (query.lastByte + 1 >= query.numBytes) { return 0; } if (query.lastByte && query.queryDone) { return query.response[++query.lastByte]; } Pad *pad = &pads[query.port][query.slot]; if (query.lastByte == 0) { query.lastByte++; query.currentCommand = value; switch (value) { case CMD_CONFIG_MODE: if (pad->config) { // In config mode. Might not actually be leaving it. query.set_result(ConfigExit); return 0xF3; } // fallthrough on purpose (but I don't know why) case CMD_READ_DATA_AND_VIBRATE: { query.response[2] = 0x5A; #if 0 int i; Update(query.port, query.slot); ButtonSum *sum = &pad->sum; u8 b1 = 0xFF, b2 = 0xFF; for (i = 0; i<4; i++) { b1 -= (sum->buttons[i] > 0) << i; } for (i = 0; i<8; i++) { b2 -= (sum->buttons[i+4] > 0) << i; } #endif // FIXME #if 0 if (config.padConfigs[query.port][query.slot].type == GuitarPad && !config.GH2) { sum->buttons[15] = 255; // Not sure about this. Forces wammy to be from 0 to 0x7F. // if (sum->sticks[2].vert > 0) sum->sticks[2].vert = 0; } #endif #if 0 for (i = 4; i<8; i++) { b1 -= (sum->buttons[i+8] > 0) << i; } #endif // FIXME #if 0 //Left, Right and Down are always pressed on Pop'n Music controller. if (config.padConfigs[query.port][query.slot].type == PopnPad) b1=b1 & 0x1f; #endif uint16_t buttons = g_key_status.get(query.port); query.numBytes = 5; query.response[3] = (buttons >> 8) & 0xFF; query.response[4] = (buttons >> 0) & 0xFF; if (pad->mode != MODE_DIGITAL) { // ANALOG || DS2 native query.numBytes = 9; query.response[5] = g_key_status.get(query.port, PAD_R_RIGHT); query.response[6] = g_key_status.get(query.port, PAD_R_UP); query.response[7] = g_key_status.get(query.port, PAD_L_RIGHT); query.response[8] = g_key_status.get(query.port, PAD_L_UP); if (pad->mode != MODE_ANALOG) { // DS2 native query.numBytes = 21; query.response[9] = !test_bit(buttons, 13) ? g_key_status.get(query.port, PAD_RIGHT) : 0; query.response[10] = !test_bit(buttons, 15) ? g_key_status.get(query.port, PAD_LEFT) : 0; query.response[11] = !test_bit(buttons, 12) ? g_key_status.get(query.port, PAD_UP) : 0; query.response[12] = !test_bit(buttons, 14) ? g_key_status.get(query.port, PAD_DOWN) : 0; query.response[13] = !test_bit(buttons, 4) ? g_key_status.get(query.port, PAD_TRIANGLE) : 0; query.response[14] = !test_bit(buttons, 5) ? g_key_status.get(query.port, PAD_CIRCLE) : 0; query.response[15] = !test_bit(buttons, 6) ? g_key_status.get(query.port, PAD_CROSS) : 0; query.response[16] = !test_bit(buttons, 7) ? g_key_status.get(query.port, PAD_SQUARE) : 0; query.response[17] = !test_bit(buttons, 2) ? g_key_status.get(query.port, PAD_L1) : 0; query.response[18] = !test_bit(buttons, 3) ? g_key_status.get(query.port, PAD_R1) : 0; query.response[19] = !test_bit(buttons, 0) ? g_key_status.get(query.port, PAD_L2) : 0; query.response[20] = !test_bit(buttons, 1) ? g_key_status.get(query.port, PAD_R2) : 0; } } #if 0 query.response[3] = b1; query.response[4] = b2; query.numBytes = 5; if (pad->mode != MODE_DIGITAL) { query.response[5] = Cap((sum->sticks[0].horiz+255)/2); query.response[6] = Cap((sum->sticks[0].vert+255)/2); query.response[7] = Cap((sum->sticks[1].horiz+255)/2); query.response[8] = Cap((sum->sticks[1].vert+255)/2); query.numBytes = 9; if (pad->mode != MODE_ANALOG) { // Good idea? No clue. //query.response[3] &= pad->mask[0]; //query.response[4] &= pad->mask[1]; // No need to cap these, already done int CapSum(). query.response[9] = (unsigned char)sum->buttons[13]; //D-pad right query.response[10] = (unsigned char)sum->buttons[15]; //D-pad left query.response[11] = (unsigned char)sum->buttons[12]; //D-pad up query.response[12] = (unsigned char)sum->buttons[14]; //D-pad down query.response[13] = (unsigned char) sum->buttons[8]; query.response[14] = (unsigned char) sum->buttons[9]; query.response[15] = (unsigned char) sum->buttons[10]; query.response[16] = (unsigned char) sum->buttons[11]; query.response[17] = (unsigned char) sum->buttons[6]; query.response[18] = (unsigned char) sum->buttons[7]; query.response[19] = (unsigned char) sum->buttons[4]; query.response[20] = (unsigned char) sum->buttons[5]; query.numBytes = 21; } } #endif } query.lastByte = 1; return pad->mode; case CMD_SET_VREF_PARAM: query.set_final_result(noclue); break; case CMD_QUERY_DS2_ANALOG_MODE: // Right? Wrong? No clue. if (pad->mode == MODE_DIGITAL) { queryMaskMode[1] = queryMaskMode[2] = queryMaskMode[3] = 0; queryMaskMode[6] = 0x00; } else { queryMaskMode[1] = pad->umask[0]; queryMaskMode[2] = pad->umask[1]; queryMaskMode[3] = 0x03; // Not entirely sure about this. //queryMaskMode[3] = 0x01 | (pad->mode == MODE_DS2_NATIVE)*2; queryMaskMode[6] = 0x5A; } query.set_final_result(queryMaskMode); break; case CMD_SET_MODE_AND_LOCK: query.set_result(setMode); pad->reset_vibrate(); break; case CMD_QUERY_MODEL_AND_MODE: if (IsDualshock2()) { query.set_final_result(queryModelDS2); } else { query.set_final_result(queryModelDS1); } // Not digital mode. query.response[5] = (pad->mode & 0xF) != 1; break; case CMD_QUERY_ACT: query.set_result(queryAct[0]); break; case CMD_QUERY_COMB: query.set_final_result(queryComb); break; case CMD_QUERY_MODE: query.set_result(queryMode); break; case CMD_VIBRATION_TOGGLE: memcpy(query.response + 2, pad->vibrate, 7); query.numBytes = 9; //query.set_result(pad->vibrate); // warning copy 7b not 8 (but it is really important?) pad->reset_vibrate(); break; case CMD_SET_DS2_NATIVE_MODE: if (IsDualshock2()) { query.set_result(setNativeMode); } else { query.set_final_result(setNativeMode); } break; default: query.numBytes = 0; query.queryDone = 1; break; } return 0xF3; } else {
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; } }
int main( int argc , char*argv[] ) { int start = 0 ; XInfo xInfo; initX(argc, argv, xInfo); while(true) { int i = eventLoop(xInfo, 0); ship.reset(); pad.reset(); pad2.reset(); leftx = pad.getx()+pad.getl(); // the right x-ixs of the first pad lefty = pad.gety(); //the right y-ixs of the first pad rightx = pad2.getx(); // the left x-ixs of the second pad righty = pad2.gety(); // the left y-ixs of the second pad mountain1.reset(0,500, pad.getx(), pad.gety()); mountain3.reset(leftx,lefty,rightx,righty); mountain2.reset( pad2.getx()+pad2.getl(),pad2.gety(),800,0); while(dList.size() > 0 ) { dList.pop_front(); } if( i == 0 ) { break; } start = 0; } XCloseDisplay(xInfo.display); }
/* function to repaint a display list Checking collisions with mountain NOTE: all the conditions for mountains are different cannot use helper function to reduce the code */ int repaint(XInfo &xinfo) { list<Displayable *>::const_iterator begin = dList.begin(); list<Displayable *>::const_iterator end = dList.end(); int status = 1; //1: nothing happened 0:landed 2: crushed float slop; int ship_point; int i; float length; float height; float expecty; int extra; int real_y; vector<int> x; vector<int> y; //big black rectangle to clear background XFillRectangle(xinfo.display, xinfo.pixmap, xinfo.gc[0], 0 , 0 , xinfo.width, xinfo.height); //draw display list while (begin != end) { Displayable *d = *begin; d->paint(xinfo); begin++; } //check if the ship landed if ( (ship.getY() >= lefty && pad.getx() <= ship.getX()+40 && ship.getX() <= leftx ) || (ship.getY() >= righty && rightx <= ship.getX()+40 && ship.getX() < rightx+pad2.getl()) ) { if(ship.getspeed() > 2) { status = 2; } else { status = 0; } } if(ship.getX() < pad.getx() ) { /*mountain 1*/ x = mountain1.getx(); y = mountain1.gety(); vector<int> indexs = findPoints(ship.getX(), ship.getX()+40, x); vector<int> points; for(int j = 0; j < indexs.size(); j ++ ) { points.push_back(y[indexs[j]]); } real_y = ship.getY(); // right point if(ship.getX() +40 < pad.getx()) { ship_point = ship.getX()+40; i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - 0; height = y[i] - 500; slop = height / length; extra = 500; } else if( i == x.size() ) { length = pad.getx() - x[i-1]; height = pad.gety() - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; if ( real_y >= expecty) { status = 2; } } // left point if( status == 1) { ship_point = ship.getX(); i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - 0; height = y[i] - 500; slop = height / length; extra = 500; } else if( i == x.size() ) { length = pad.getx() - x[i-1]; height = pad.gety() - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; if ( real_y >= expecty) { status = 2; } } //line if(lower(points, ship.getY()) && status == 1) { status = 2; } } else if( ship.getX() < pad2.getx() && ship.getX()+40 > pad.getx() + pad.getl() ) { //mountain 3 x = mountain3.getx(); y = mountain3.gety(); vector<int> indexs = findPoints(ship.getX(), ship.getX()+40, x); vector<int> points; for(int j = 0; j < indexs.size(); j ++ ) { points.push_back(y[indexs[j]]); } real_y = ship.getY(); //right point if(ship.getX() +40 > pad.getx() +pad.getl() && ship.getX() +40 < pad2.getx()) { ship_point = ship.getX()+40; i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - pad.getx()+pad.getl(); height = y[i] - pad.gety(); slop = height / length; extra = y[i] - x[i] *slop; } else if( i == x.size() ) { length = pad2.getx() - x[i-1]; height = pad2.gety() - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; if ( real_y >= expecty) { status = 2; } } //left point if(ship.getX() < pad2.getx() && ship.getX() > pad.getx() + pad.getl()) { if(status == 1) { ship_point = ship.getX(); i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - pad.getx()+pad.getl(); height = y[i] - pad.gety(); slop = height / length; extra = pad.gety() - (pad.getx()+pad.getl()) *slop; } else if( i == x.size() ) { length = pad2.getx() - x[i-1]; height = pad2.gety() - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; cout << "real_y " << real_y << endl; cout << "expecty" << expecty << endl; if ( real_y >= expecty) { status = 2; } } } //line if(lower(points,ship.getY()) && status == 1) { status = 2; } } else if( ship.getX() +40< 800 && ship.getX()+40 > pad2.getx() + pad2.getl() ) { x = mountain2.getx(); y = mountain2.gety(); vector<int> indexs = findPoints(ship.getX(), ship.getX()+40, x); vector<int> points; for(int j = 0; j < indexs.size(); j ++ ) { points.push_back(y[indexs[j]]); } real_y = ship.getY(); //right point ship_point = ship.getX()+40; i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - pad2.getx()+pad.getl(); height = y[i] - pad2.gety(); slop = height / length; extra = y[i] - x[i] *slop; } else if( i == x.size() ) { length = 0 - x[i-1]; height = 800 - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; if ( real_y >= expecty) { status = 2; } //left point if(ship.getX() > pad2.getx() &&ship.getX() < 800) { if(status == 1) { ship_point = ship.getX(); i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - pad2.getx()+pad2.getl(); height = y[i] - pad2.gety(); slop = height / length; extra = pad2.gety() - (pad2.getx()+pad2.getl()) *slop; } else if( i == x.size() ) { length = 0 - x[i-1]; height = 800 - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; if ( real_y >= expecty) { status = 2; } } } //line if(lower(points, ship.getY()) && status == 1) { status = 2; } } XCopyArea(xinfo.display , xinfo.pixmap, xinfo.window , xinfo.gc[0], 0,0,xinfo.width,xinfo.height,(xinfo.width-800)/2,(xinfo.height-600)/2); XFlush(xinfo.display); return status; }
// constructor Text(int x, int y, string s):x(x), y(y), s(s) {} private: XPoint p; int x; int y; string s; // string to show }; //=============================================================================== list<Displayable *> dList; Ship ship(40,0,0); Pad pad(50,100,200); Pad pad2(50, 500, 600); int leftx = pad.getx()+pad.getl(); // the right x-ixs of the first pad int lefty = pad.gety(); //the right y-ixs of the first pad int rightx = pad2.getx(); // the left x-ixs of the second pad int righty = pad2.gety(); // the left y-ixs of the second pad //draw mountains Mountain mountain1(10,0,500, pad.getx(), pad.gety()); Mountain mountain3(10,leftx,lefty,rightx,righty); Mountain mountain2(10, pad2.getx()+pad2.getl(),pad2.gety(),800,0); Bomb bomb(ship.getX(), ship.getY(), 40); void initX(int argc, char* argv[], XInfo &xInfo) { XSizeHints hints; unsigned long white, black;
Pad::Pad(Pad & orig_pad) : AudibleElem() { setActive(orig_pad.isActive()); setVolume(orig_pad.volumePercent()); }
void demoMain() { Renderer* renderer = zenic_new ps2::Renderer(false); ZENIC_ASSERT(renderer); float deltaTime = 1.0f / 60.0f; float time = 0.0f; if (!renderer) return; #if defined(ZENIC_PS2) #ifndef ONE_PART #else //FileSystem::instance().setIoMode(FileSystem::Host); #endif FileSystem::instance().setIoMode(FileSystem::Hdd); //FileSystem::instance().setIoMode(FileSystem::Host); #endif Part* parts[14]; renderer->create(); renderer->setClearColor(127, 127, 127); renderer->init(); LoadingPart* loadingPart = zenic_new LoadingPart(*renderer, MasterChain::instance()->chain()); loadingPart->create(); loadingPart->update(); FftStream::instance().create(); SyncPoints syncPoints; SaPart::loadSaObjects(); // Alloc all parts parts for (uint i = 0; i < 14; ++i) parts[i] = 0; #if defined(ZENIC_PS2) #ifndef NO_MUSIC MusicStream* stream = zenic_new MusicStream("DATA/OUTPUT/SAPART1.APM"); #else MusicStream dummy; MusicStream* stream = &dummy; #endif #endif #ifndef ONE_PART parts[0] = zenic_new StartPart(*renderer, MasterChain::instance()->chain()); parts[1] = zenic_new MountainsPart(*renderer, MasterChain::instance()->chain()); parts[2] = zenic_new SpeachPart1(*renderer, MasterChain::instance()->chain());; parts[3] = zenic_new SaPart1(*renderer, MasterChain::instance()->chain()); parts[4] = zenic_new BlobPart(*renderer, MasterChain::instance()->chain()); parts[5] = zenic_new SaPart2(*renderer, MasterChain::instance()->chain()); parts[6] = zenic_new CityScapePart(*renderer, MasterChain::instance()->chain()); parts[7] = zenic_new TunnelPart(*renderer, MasterChain::instance()->chain()); parts[8] = zenic_new SpeachPart2(*renderer, MasterChain::instance()->chain());; parts[9] = zenic_new SaPart3(*renderer, MasterChain::instance()->chain()); parts[10] = zenic_new ParkingHousePart(*renderer, MasterChain::instance()->chain()); parts[11] = zenic_new EndPart(*renderer, MasterChain::instance()->chain()); for (uint i = 0; i < 14; ++i) { if (parts[i]) parts[i]->create(); } // Ugly but what the hell ((SaPart*)parts[8])->setScene(((SaPart*)parts[2])->scene()); /* u8* tempBuffer = zenic_new u8[8 * ((512 * 512) / 2)]; ZENIC_ASSERT(tempBuffer); for (uint i = 0; i < (8 * ((512 * 512) / 2)); ++i) tempBuffer[i] = i; */ #else parts[0] = zenic_new ParkingHousePart(*renderer, MasterChain::instance()->chain()); //parts[0] = zenic_new SpeachPart1(*renderer, MasterChain::instance()->chain());; //parts[0] = zenic_new StartPart(*renderer, MasterChain::instance()->chain()); //parts[0] = zenic_new TunnelPart(*renderer, MasterChain::instance()->chain()); //parts[0] = zenic_new CityScapePart(*renderer, MasterChain::instance()->chain()); //parts[0] = zenic_new MountainsPart(*renderer, MasterChain::instance()->chain()); parts[0]->create(); #endif while (time < 1.0f) { loadingPart->update(1.0f, time); renderer->flip(); time += deltaTime; } // Fade down the Loading screen before the "real" demo start while (time < 1.0f) { loadingPart->update(1.0f, time); renderer->flip(); time += deltaTime; } // Do real demo //MusicStream stream; #ifndef ZENIC_FINAL pad.create(0, 0); PadCamera padCamera(pad); parts[0]->setPadCamera(&padCamera); #endif #if defined(ZENIC_PS2) #ifndef NO_MUSIC stream->play(); #endif #endif uint prevPartId = 0; time = 0.0f; FftStream::instance().setTime(0); //renderer->setRenderFrames(true); while (1) { #ifndef ONE_PART uint partId = syncPoints.partId(); if (prevPartId != partId) { if (parts[prevPartId]) parts[prevPartId]->reset(); prevPartId = partId; } if (parts[partId]) parts[partId]->update(time - syncPoints.partStartTime(), deltaTime); #else parts[0]->update(time, deltaTime); #endif #if !defined(ZENIC_FINAL) && defined(ZENIC_PS2) time = syncPoints.update(pad, *stream, time); #else time = syncPoints.update(time); #endif #if !defined(ZENIC_FINAL) && defined(ZENIC_PS2) pad.update(); padCamera.update(); if (pad.status().triangle) { renderer->screenShot("host:frames/screenshot.tga"); } if (pad.status().select) { stream->stop(); } #endif #ifndef NO_MUSIC #if defined(ZENIC_PS2) if (time > 278.0f) { stream->stop(); } #endif #endif FftStream::instance().update(*renderer, MasterChain::instance()->chain()); renderer->flip(); time += deltaTime; } }
Result * PathPlanner::applyInternal(Image *img) { PathResult *path = NULL; PadResult *padResult = dynamic_cast<PadResult*>(img->getResult(source)); if (padResult) { if (padResult->size() < 1 || padResult->size() > 1000) { qWarning() << "Found too much/less pads (" << padResult->size() << ")! Skipping PathPlanner"; return path; } switch (algo) { case NEAREST_NEIGHBOUR: { path = new PathResult; PadResult pads = *padResult; /* create a copy */ PadResult::iterator start = pads.begin(); /* fixed */ Pad last = *start; path->append(*start); pads.erase(start); while (!pads.isEmpty()) { PadResult::iterator nearest = pads.getNearest(last); path->append(*nearest); pads.erase(nearest); last = *nearest; } } break; case REPETETIVE_NEAREST_NEIGHBOUR: { double minLength = FLT_MAX; for (int i = 0; i < padResult->size(); i++) { double currentLength = 0; PathResult *currentPath = new PathResult; PadResult pads = *padResult; PadResult::iterator start = pads.begin() + i; Pad last = *start; currentPath->append(*start); pads.erase(start); while (!pads.isEmpty()) { PadResult::iterator nearest = pads.getNearest(last); CV_Assert(nearest != pads.end()); currentLength += last.getDistance(*nearest); if (currentLength > minLength) break; currentPath->append(*nearest); pads.erase(nearest); last = *nearest; } if (currentLength > minLength) delete currentPath; else { if (path) delete path; minLength = currentLength; path = currentPath; } } } break; } return path; } else qWarning() << getName() << "Missing pad list!"; return new Result; }