void Gun::update(){ if(ofGetElapsedTimeMillis() - timeSinceLastShot > SHOT_DELAY){ ofxVec2f shooting(pos.x + cos(angle) * (s*2),pos.y + sin(angle)*(s*2)); Bullet bul(angle,speed,shooting); //bullets.push_back(bul); timeSinceLastShot = ofGetElapsedTimeMillis(); } }
void soloplay_main(){ //画像読み込み graresource.initialize(); decoder.initialize(); static const int BLACK = GetColor(0, 0, 0); static const int WHITE = GetColor(255, 255, 255); static const int playerNum = 4; Shooting shooting(playerNum); // 移動ルーチン int fpsTimer = GetNowCount(); Input input; ClearDrawScreen(); const static int titleGraph = LoadGraph( "../graphic/ShootingTitle.jpg"); DrawGraph( 0, 0, titleGraph, false); ScreenFlip(); Sleep( 3000); while( 1 ){ input.getKeyInput(); // todo treat dead client //while(true){ // int lostNetWork = GetLostNetWork(); //} for(int i = 0; i < playerNum; ++i){ shooting.setInput(i, input.encode()); } shooting.action(); #ifdef _DEBUG_ // debug messages //dxout << serverMessage << dxendl; #endif // _DEBUG_ decoder.draw(graresource.getMessages()); graresource.clear(); int term; term = GetNowCount()-fpsTimer; if(16-term>0){ Sleep(16-term); } fpsTimer = GetNowCount(); if (!shooting.isValid()) break; // Windows 特有の面倒な処理をDXライブラリにやらせる // -1 が返ってきたらループを抜ける if( ProcessMessage() < 0 ) break ; // もしESCキーが押されていたらループから抜ける if( CheckHitKey( KEY_INPUT_ESCAPE ) ) break; } }
void GameScene::runLogic(float deltaTime, Game& game) { if(game.server) { // SERVER cooldown -= deltaTime; enemySpawnCooldown -= deltaTime; enemyCooldown -= deltaTime; difficulty += deltaTime * 30.0f; bgMotion += deltaTime * bgSpeed; if(bgMotion > 256.0f) bgMotion -= 256.0f; bgSprite->setPosition(0.0f, -600.0f + bgMotion); shooting(deltaTime, game); spawningEnemies(deltaTime, game); flyEnemyPlasma(deltaTime, game); player.runLogic(deltaTime, game); std::string scoreString = std::to_string(score); scoreText.setString("Score: " + scoreString); scoreText.setFont(*game.font); escText.setFont(*game.font); std::string scoreString2 = std::to_string(score2); scoreText2.setString("Score: " + scoreString2); scoreText2.setFont(*game.font); sf::Packet packet; packet << player.position.x << player.position.y; sf::IpAddress clientAddress(game.clientAddress); game.socket->send(packet, clientAddress, game.udpPortClient); } else { // CLIENT sf::Packet packet; float x, y; sf::IpAddress serverAddress(game.serverAddress); game.socket->receive(packet, serverAddress, game.udpPortClient); if(packet >> x >> y) { player.position.x = x; player.position.y = y; } } }
void server_main(){ graresource.initialize(); static const int BLACK = GetColor(0, 0, 0); static const int WHITE = GetColor(255, 255, 255); ServerConnection server(PORT); server.startListen(); while(server.size() < CLIENT_NUM){ DrawBox(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, BLACK, 1); DrawFormatString(60, 60, WHITE, "access: %d", server.size()); ScreenFlip(); Sleep(10); server.action(); // Windows 特有の面倒な処理をDXライブラリにやらせる // -1 が返ってきたらループを抜ける if( ProcessMessage() < 0 ) exit(1) ; // もしESCキーが押されていたらループから抜ける if( CheckHitKey( KEY_INPUT_ESCAPE ) ) exit(1); } server.endListen(); DrawBox(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, BLACK, 1); DrawFormatString(60, 60, WHITE, "access: %d", server.size()); DrawFormatString(60, 80, WHITE, "game start", server.size()); ScreenFlip(); Shooting shooting(CLIENT_NUM); // 移動ルーチン int fpsTimer = GetNowCount(); while( 1 ){ string serverMessage; // todo treat dead client //while(true){ // int lostNetWork = GetLostNetWork(); //} for(int i = 0; i < server.size(); ++i){ if(server.receive(i, serverMessage) >= 0){ while(server.receive(i, serverMessage) >= 0); // receive succssessed shooting.setInput(i, serverMessage); }else{ // receive failed shooting.clearInput(i); } } shooting.action(); // debug messages dxout << serverMessage << dxendl; vector<int> clientMessage = graresource.getMessages(); DrawBox(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, BLACK, 1); DrawFormatString(60, 60, WHITE, "access: %d", server.size()); DrawFormatString(60, 80, WHITE, "game start", server.size()); //DrawFormatString(60, 100, WHITE, clientMessage.c_str()); ScreenFlip(); server.send(clientMessage); graresource.clear(); int term; term = GetNowCount()-fpsTimer; if(16-term>0){ Sleep(16-term); } fpsTimer = GetNowCount(); if (!shooting.isValid()) break; // Windows 特有の面倒な処理をDXライブラリにやらせる // -1 が返ってきたらループを抜ける if( ProcessMessage() < 0 ) break ; // もしESCキーが押されていたらループから抜ける if( CheckHitKey( KEY_INPUT_ESCAPE ) ) break; } }
int main(int argc, char* argv[]) { bool velocity, lsint; int is, nz, nx, im, nm, order, nshot, ndim, nt, nr, ir, i1, i2, ia; float a, b, fb, r0, dr, rmax, xmax, a0, amax, da, r1, r2, tol; float dz, dx, z0, x0, *angle, *slow, **shot, *time; sf_file shots, vel, out; sf_init (argc,argv); vel = sf_input("in"); out = sf_output("out"); /* get 2-D grid parameters */ if (!sf_histint(vel,"n1",&nz)) sf_error("No n1= in input"); if (!sf_histint(vel,"n2",&nx)) sf_error("No n2= in input"); if (!sf_histfloat(vel,"d1",&dz)) sf_error("No d1= in input"); if (!sf_histfloat(vel,"d2",&dx)) sf_error("No d2= in input"); if (!sf_histfloat(vel,"o1",&z0)) z0=0.; if (!sf_histfloat(vel,"o2",&x0)) x0=0.; xmax = x0 + (nx-1)*dx; /* additional parameters */ if(!sf_getbool("vel",&velocity)) velocity=true; /* If y, the input is velocity; if n, slowness */ if(!sf_getint("order",&order)) order=4; /* Interpolation order */ if (!sf_getbool("lsint",&lsint)) lsint=false; /* if use least-squares interpolation */ if (!sf_getint("nt",&nt)) nt=nx*nz; /* Maximum number of time steps */ if (!sf_getint("nr",&nr)) nr=1; /* number of recievers */ if (!sf_getfloat("r0",&r0)) r0=x0; /* first receiver */ if (!sf_getfloat("dr",&dr)) dr=dx; /* receiver increment */ rmax = r0 + (nr-1)*dr; /* sanity check */ if (dr <= 0.) sf_error ("Need positive dr"); if (r0 < x0 || r0 > xmax || rmax < x0 || rmax > xmax) sf_error ("Range of receivers [%f,%f] " "is outside of the model range [%f,%f]", r0,rmax,x0,xmax); /* get shot locations */ if (NULL != sf_getstring("shotfile")) { /* file with shot locations */ shots = sf_input("shotfile"); if (!sf_histint(shots,"n1",&ndim) || 2 != ndim) sf_error("Must have n1=2 in shotfile"); if (!sf_histint(shots,"n2",&nshot)) sf_error("No n2= in shotfile"); shot = sf_floatalloc2 (ndim,nshot); sf_floatread(shot[0],ndim*nshot,shots); sf_fileclose (shots); } else { nshot = 1; ndim = 2; shot = sf_floatalloc2 (ndim,nshot); if (!sf_getfloat("zshot",shot[0])) shot[0][0]=0.; /* shot coordinates (if no shotfile) */ if (!sf_getfloat("yshot",shot[0]+1)) shot[0][1]=x0 + 0.5*(nx-1)*dx; sf_warning("Shooting from z=%f, x=%f",shot[0][0],shot[0][1]); } /* specify output dimensions */ sf_putint (out,"n1",nr); sf_putfloat (out,"d1",dr); sf_putfloat (out,"o1",r0); sf_putint (out,"n2",nshot); /* get velocity */ nm = nz*nx; slow = sf_floatalloc(nm); sf_floatread(slow,nm,vel); if (vel) { /* convert to slowness */ for(im = 0; im < nm; im++){ slow[im] = 1./slow[im]; } } /* initialize ray tracing object */ ct = sf_celltrace_init (lsint, order, nt, nz, nx, dz, dx, z0, x0, slow); free (slow); angle = sf_floatalloc (nr); time = sf_floatalloc (nr); if (!sf_getfloat("tol",&tol)) tol=0.01; /* Shooting tolerance (in degrees) */ tol *= SF_PI/180.; /* 1/100 degree */ for( is = 0; is < nshot; is++) { /* loop over shots */ /* initialize position */ xs[0] = shot[is][0]; xs[1] = shot[is][1]; /* initialize directions */ da = 0.01*SF_PI; a0 = atan2f(r0 -xs[1],xs[0]-z0); amax = atan2f(rmax-xs[1],xs[0]-z0); xr = r0; r1 = 0.; for (a0 -= da; a0 > - SF_PI; a0 -= da) { r1 = shooting(a0); if (r1 <= 0.) break; } r1 += xr; xr = rmax; for (amax += da; amax < SF_PI; amax += da) { if (shooting(amax) >= 0.) break; } for (ir=0; ir < nr; ir++) { time[ir] = angle[ir] = FLT_MAX; } da = (amax-a0)/nr; for (ia=0; ia < nr; ia++) { a = a0+(ia+1)*da; r2 = xr+shooting(a); if (r1 < r2) { i1 = ceilf((r1-r0)/dr); i2 = floorf((r2-r0)/dr); } else { i1 = ceilf((r2-r0)/dr); i2 = floorf((r1-r0)/dr); } for (ir=i1; ir <= i2; ir++) { if (ir >= nr) break; if (ir < 0) continue; xr = r0+ir*dr; /* target */ b = sf_zero(shooting,a-da,a,r1-xr,r2-xr,tol,false); fb = shooting(b); if (fabsf(fb) > 0.5*dr) sf_warning("insufficient accuracy=%f " "on shot %d, receiver %d",fb,is+1,ir+1); if (t < time[ir]) { /* select first arrivals */ angle[ir] = b; time[ir] = t; } } r1 = r2; } sf_floatwrite(angle,nr,out); } exit (0); }
void cover() { s=18;sp=6; w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2 w1=wi=s/4; wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4 h=s;//1 /////////////////// xnxt=-52;ynxt=370; computer(); xnxt+=s/2; graphics(); xnxt=0;ynxt-=2*s-4; mini(); xnxt+=s/2; project(); ///////////////// s=28;sp=8; w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2 w1=wi=s/4; wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4 h=s;//1 /////////////////// glPointSize(3.0); xnxt=-100;ynxt-=2*s; balloon1(); xnxt+=s/2; shooting(); //////////////// s=16;sp=4; w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2 w1=wi=s/4; wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4 h=s;//1 ////////////// glPointSize(2.0); xnxt=320;ynxt-=4*s; glPointSize(1.5); by(); //////////////// s=16;sp=6; w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2 w1=wi=s/4; wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4 h=s;//1 xnxt=170;ynxt-=3*s; arahant(); xnxt=160;ynxt-=2*s; ashrith(); xnxt=170;ynxt-=2*s; dhanush(); xnxt=138;ynxt-=2*s; harsha(); xnxt=184;ynxt-=2*s; shreeman(); /////////////////////////// xnxt=-190;ynxt=124; guidance(); xnxt=-190;ynxt-=3*s; sir(); xnxt=-190;ynxt-=2*s; madam(); }
/* * Hit one guy once. */ void one_hit( CHAR_DATA *ch, CHAR_DATA *victim, int dt ) { OBJ_DATA *wield; OBJ_INDEX_DATA *ammo = NULL; int diceroll; int sn; int dam_type; sn = -1; /* just in case */ if (victim == ch || ch == NULL || victim == NULL) return; /* * Can't beat a dead char! * Guard against weird room-leavings. */ if ( victim->position == P_DEAD || ch->in_room != victim->in_room ) return; /* * Figure out the type of damage message. */ wield = get_eq_char( ch, WEAR_WIELD ); if(wield != NULL && wield->value[0] == WEAPON_FIREARM) ammo = get_obj_index(wield->value[2]); if ( dt == TYPE_UNDEFINED ) { dt = TYPE_HIT; if ( wield != NULL && wield->item_type == ITEM_WEAPON ) { if(wield->value[0] == WEAPON_FIREARM) { if(ammo) dt += ammo->value[3]; } else dt += wield->value[3]; } else dt += ch->dam_type; } if (dt < TYPE_HIT) if (wield != NULL) { if(wield->value[0] == WEAPON_FIREARM) { if(ammo) dam_type = attack_table[ammo->value[3]].damage; else dam_type = attack_table[0].damage; } else dam_type = attack_table[wield->value[3]].damage; } else dam_type = attack_table[ch->dam_type].damage; else dam_type = attack_table[dt - TYPE_HIT].damage; if (dam_type == -1) dam_type = DAM_BASH; /* * The moment of excitement! */ while ( ( diceroll = number_bits( 5 ) ) >= 20 ) ; if( wield == NULL || (wield->value[0] > 1) || (wield->value[0] == 0) ) { strike(ch, victim); } else if(wield->value[0] == 1) { shooting(ch, victim, NULL); } if(!IS_SET(victim->act2, ACT2_NOWARRANT)) add_warrant(ch, 20, FALSE); /* * Funky weapon s***e */ /* if (result && wield != NULL) { int dam; if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_POISON)) { int level; AFFECT_DATA *poison = NULL; AFFECT_DATA af; level = 2; if (!saves_spell(1,victim,DAM_POISON)) { send_to_char("You feel poison coursing through your veins.", victim); act("$n is poisoned by the venom on $p.", victim,wield,NULL,TO_ROOM, 0); af.where = TO_AFFECTS; af.type = gsn_poison; af.level = level * 3/4; af.duration = level / 2; af.location = APPLY_STR; af.modifier = -1; af.bitvector = AFF_POISON; affect_join( victim, &af ); } */ /* weaken the poison if it's temporary */ /* if (poison != NULL) { poison->level = UMAX(0,poison->level - 2); poison->duration = UMAX(0,poison->duration - 1); if (poison->level == 0 || poison->duration == 0) act("The poison on $p has worn off.", ch,wield,NULL,TO_CHAR,1); } } if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_VAMPIRIC)) { dam = number_range(1,2); act("$p draws life from $n.",victim,wield,NULL,TO_ROOM,0); act("You feel $p drawing your life away.", victim,wield,NULL,TO_CHAR,1); damage(ch,victim,dam,0,DAM_NEGATIVE,FALSE,1,-1); ch->RBPG += dam/2; } if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_FLAMING)) { dam = number_range(1,2); act("$n is burned by $p.",victim,wield,NULL,TO_ROOM,0); act("$p sears your flesh.",victim,wield,NULL,TO_CHAR,1); fire_effect( (void *) victim,2,dam,TARGET_CHAR); damage(ch,victim,dam,0,DAM_FIRE,FALSE,1,-1); } if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_FROST)) { dam = number_range(1, 2); act("$p freezes $n.",victim,wield,NULL,TO_ROOM,0); act("The cold touch of $p surrounds you with ice.", victim,wield,NULL,TO_CHAR,1); cold_effect(victim,2,dam,TARGET_CHAR); damage(ch,victim,dam,0,DAM_COLD,FALSE,0,-1); } if (ch->fighting == victim && IS_WEAPON_STAT(wield,WEAPON_SHOCKING)) { dam = number_range(1,2); act("$n is struck by lightning from $p.", victim,wield,NULL,TO_ROOM,0); act("You are shocked by $p.",victim,wield,NULL,TO_CHAR,1); shock_effect(victim,2,dam,TARGET_CHAR); damage(ch,victim,dam,0,DAM_LIGHTNING,FALSE,1,-1); } } */ tail_chain( ); return; }
void sched (Info * info) { //mylogfd (SCHFD, "%d\n", info->state); // if (!info->video_info->is_valid) return; // mylogfd(SCHFD, "%d %d\n", IsEdgeValid(info), getEdgeX(info)); // mylogfd(SCHFD, "IsDoorSeen %d IsDoorAllSeen %d IsDoorLeft %d IsDoorRight %d IsDoorMiddle %d DoorMidX %d DoorMidY %d\n", // IsDoorSeen(info), IsDoorAllSeen(info), IsDoorLeft(info), IsDoorRight(info), IsDoorMiddle(info), getDoorMidx(info), getDoorMidy(info)); /*static int wait_edge = -1; if (wait_edge >= 0) { wait_edge ++; if (wait_edge >= 5) { mylogfd(SCHFD, "Touch edges->Stop\n"); do_stop(info); wait_edge = -1; } return; }*/ // mylogfd(SCHFD, "IsDoorSeen:%d IsEdgeValid:%d IsOutSide:%d edgeX %d\n", IsDoorAllSeen(info), IsEdgeValid(info), IsOutSide(info), getEdgeX(info)); estimate_seen_state(info); // mylogfd(SCHFD, "IsRobotSeen %d RobotX %d RobotY %d\n", IsRobotSeen(info), getRobotX(info), getRobotY(info)); if (info->last_cmd == CMD_FORWARD && info->state != SHOOTING && IsOutSide(info)) { mylogfd(SCHFD, "Outside\n"); info->last_cmd = CMD_STOP; do_stop(info); info->state = OUTSIDE; return; } /* if (info->last_cmd == CMD_FORWARD && IsOutSide(info) && IsEdgeValid(info)) { if (getEdgeX(info) < 50 && getEdgeX(info) >= 0) { mylogfd(SCHFD, "Touch edges %d\n", getEdgeX(info)); do_stop(info); info->state = DONE; //wait_edge = 0; return; } }*/ /* if (info->last_cmd == CMD_FORWARD && IsRobotSeen(info)) { if (IsRobotAcc(info)) { if (getRobotY(info) < 30) { do_stop(info); info->state = SEARCH_BALL; } else if (getRobotY(info) < 60) { info->destP.x = 0; info->destP.y = getRobotY(info) + 50; info->obstacle[0].x = getRobotY(info); info->obstacle[0].y = - getRobotX(info); do_obstacle(info); info->state = OBSTACLE; } } }*/ //mylogfd(-1, "s"); switch (info->state) { case START: //chang in state machine -- redwalker start(info); case FIND_PLACE: // find_place(info); break; case SEARCH_BALL: search_ball(info); break; case SEARCHING_BALL: searching_ball(info); break; case SEARCHING_ADJUST: searching_adjust(info); break; case FORWARDING_BALL: forwarding_ball(info); break; case CATCHING_BALL: catching_ball(info); break; case BALL_CATCHED: ball_catched(info); break; case SHOOT: shoot(info); break; case SHOOTING: shooting(info); break; case MOVING: moving(info); break; case CHANGE_PLACE: change_place(info); break; case FINDING_DIR: finding_dir(info); break; case CHANGING_PLACE: changing_place(info); break; case OBSTACLE: obstacle(info); break; case PROTECT_DOOR: protect_door(info); break; case OUTSIDE: if (!IsOutSide(info)) { mylogfd(SCHFD, "Inside restart to search_ball\n"); info->state = SEARCH_BALL; } break; case FACE_DOOR: face_door(info); break; case DONE: break; case GAME: //game(info); break; case SHOOTED: shooted(info); default : break; } }
void acting(ground& earth, square& another) { moving(earth, another); shooting(another); }