Camera::Camera(){ ParseXML * parser = ParseXML::getInstance(); HandleChars * handle = new HandleChars(); parser->parseXML("xml/camera.xml", handle); eye << handle->getXmlFloat("pos_x"), handle->getXmlFloat("pos_y"), handle->getXmlFloat("pos_z"); aim << handle->getXmlFloat("aim_x"), handle->getXmlFloat("aim_y"), handle->getXmlFloat("aim_z"); up << handle->getXmlFloat("up_x"), handle->getXmlFloat("up_y"), handle->getXmlFloat("up_z"); fov = handle->getXmlFloat("fov"); aspect_x = handle->getXmlFloat("aspect_x"); aspect_y = handle->getXmlFloat("aspect_y"); near_clip = handle->getXmlFloat("near_clip"); far_clip = handle->getXmlFloat("far_clip"); cout << "Building camera!" << endl; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective( fov, aspect_x/aspect_y, near_clip, far_clip ); gluLookAt( eye(0), eye(1), eye(2), aim(0), aim(1), aim(2), up(0), up(1), up(2) ); glMatrixMode(GL_MODELVIEW); delete handle; }
void Camera::drawAimPoint() const{ glPointSize(4.0); glColor4f(1.0, 0.0, 1.0, 1.0); glBegin(GL_POINTS); glVertex3f(aim(0), aim(1), aim(2)); glEnd(); }
void Camera::setCamera() const{ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective( fov, aspect_x/aspect_y, near_clip, far_clip ); gluLookAt( eye(0), eye(1), eye(2), aim(0), aim(1), aim(2), up(0), up(1), up(2) ); glMatrixMode(GL_MODELVIEW); }
void straight_self_bullet::loop() { if(age==1) { cx=estg->self->x+startx; cy=estg->self->y+starty; update_xy(); aim(); } if(age==3) aim(); x=age*_speed; }
template<> void Bullet<rapid>::update(){ if(!active) return; draw(); x += xv; y += yv; if(out_of_bounds()) active = 0; else if(Entity* e = enemy_contact(16.0)){ aim(e->x,e->y,0.0); if(e = enemy_contact(1)){ e->hit(2); gbullet_explosion(x,y,rand()%4+1); active = 0; return; } } draw(); }
void ManualBot::update(const BotInput &input, BotOutput &output) { //output.m_moveDirection.set(m_rand.norm()*2.0-1.0, m_rand.norm()*2.0-1.0); output.motor = 1.0; XINPUT_STATE xbox; XInputGetState(0,&xbox); kf::Vector2 vel; vel.x = xbox.Gamepad.sThumbLX/32767.0f; vel.y = -xbox.Gamepad.sThumbLY/32767.0f; if(vel.length()<0.2) vel.set(0,0); output.moveDirection = vel; output.motor = vel.length_squared(); if(xbox.Gamepad.wButtons & XINPUT_GAMEPAD_B) { int dummy=0; } kf::Vector2 aim(0,0); aim.x = xbox.Gamepad.sThumbRX/32767.0f; aim.y = -xbox.Gamepad.sThumbRY/32767.0f; if(aim.length()>0.2) m_lookDir.set(aim); output.lookDirection = m_lookDir; output.action = BotOutput::scan; if(xbox.Gamepad.bRightTrigger>127) { output.action = BotOutput::shoot; } }
void W_FireSpikes( float ox ) { vec3_t dir, tmp; // gedict_t* old; makevectors( self->s.v.v_angle ); if ( self->s.v.ammo_nails >= 2 && self->s.v.weapon == IT_SUPER_NAILGUN ) { W_FireSuperSpikes(); return; } if ( self->s.v.ammo_nails < 1 ) { self->s.v.weapon = W_BestWeapon(); W_SetCurrentAmmo(); return; } sound( self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM ); self->attack_finished = g_globalvars.time + 0.2; if ( deathmatch != 4 ) self->s.v.currentammo = self->s.v.ammo_nails = self->s.v.ammo_nails - 1; aim( dir ); // dir = aim (self, 1000); VectorScale( g_globalvars.v_right, ox, tmp ); VectorAdd( tmp, self->s.v.origin, tmp ); tmp[2] += 16; launch_spike( tmp, dir ); g_globalvars.msg_entity = EDICT_TO_PROG( self ); trap_WriteByte( MSG_ONE, SVC_SMALLKICK ); }
void Turret::aimAndFire(int a, int e) { if(aim(a, e)) { delay(500); fire(); } }
bool AimerDemo::on_event(Event const& e) { if (ConstrainedClothoidDemo::on_event(e)) { aim(); return true; } return false; }
template<> Bullet<good>::Bullet(float origx, float origy, float targetx, float targety){ x = origx; y = origy; boost = 14.0; aim(targetx,targety,110.0); w = 2.0; h = 2.0; }
template<> Bullet<gbomb>::Bullet(float origx, float origy, float targetx, float targety){ x = origx; y = origy; boost = 5.0; aim(targetx, targety, 110.0); w = 4.0; h = 4.0; }
template<> Bullet<rapid>::Bullet(float origx, float origy, float targetx, float targety){ x = origx; y = origy; boost = 7.0; aim(targetx, targety,50.0); w = 3.0; h = 3.0; }
MStatus sgHair_controlJoint::getJointPositionBaseWorld() { MStatus status; if( !m_bStaticRotation ) { MVector vAim; MVector vUp( m_mtxJointParentBase(1,0), m_mtxJointParentBase(1,1), m_mtxJointParentBase(1,2) ); MVector vCross; MMatrix mtxLocal; MMatrix mtxWorld = m_mtxJointParentBase; m_mtxArrBase.setLength( m_cvs.length() ); for( int i=0; i< m_cvs.length()-1; i++ ) { vAim = ( m_cvs[i+1] - m_cvs[i] )*m_mtxBaseCurve; vCross = vAim ^ vUp; vUp = vCross ^ vAim; vAim.normalize(); vUp.normalize(); vCross.normalize(); m_mtxArrBase[i] = buildMatrix( vAim, vUp, vCross, m_cvs[i]*m_mtxBaseCurve ); } MPoint pointWorld = m_cvs[m_cvs.length()-1]*m_mtxBaseCurve; MMatrix mtxLastWorld; mtxLastWorld( 3, 0 ) = pointWorld.x; mtxLastWorld( 3, 1 ) = pointWorld.y; mtxLastWorld( 3, 2 ) = pointWorld.z; m_mtxArrBase[m_cvs.length()-1] = mtxLastWorld; } else { MVector aim( 1,0,0 ); MVector up( 0,1,0 ); MVector cross( 0,0,1 ); m_mtxArrBase.setLength( m_cvs.length() ); aim *= m_mtxJointParentBase; up *= m_mtxJointParentBase; cross *= m_mtxJointParentBase; for( int i=0; i< m_cvs.length(); i++ ) { m_mtxArrBase[i] = buildMatrix( aim, up, cross, m_cvs[i]*m_mtxBaseCurve ); } } return MS::kSuccess; }
//Tries to shoot something bool GameLogic::shoot(char c) { //Do we have a target? if (target == 0){ //Look for a target return aim(c); } else{ //Try to shoot at target return shootAt(c); } }
// Throw Toaster void Toaster ( ) { gedict_t *missile; if ( self->no_grenades_2 < 2 ) { G_sprint( self, 1, "Not enough type 2 grenades... get more\n" ); return; } if (!tf_data.drop2) { G_sprint (self, 2, "Toasters have been disabled by the admin!\n"); return; } self->no_grenades_2 = self->no_grenades_2 - 2; sound( self, CHAN_WEAPON, "misc/power.wav", 1, ATTN_NORM ); missile = spawn( ); missile->s.v.owner = EDICT_TO_PROG( self ); missile->s.v.movetype = 10; missile->s.v.solid = 2; missile->s.v.classname = "grenade"; missile->s.v.effects = 8; // throw that toaster! makevectors( self->s.v.v_angle ); if (self->s.v.v_angle[0]) { missile->s.v.velocity[0] = g_globalvars.v_forward[0] * 600 + g_globalvars.v_up[0] * 200 + crandom( ) * g_globalvars.v_right[0] * 10 + crandom( ) * g_globalvars.v_up[0] * 10; missile->s.v.velocity[1] = g_globalvars.v_forward[1] * 600 + g_globalvars.v_up[1] * 200 + crandom( ) * g_globalvars.v_right[1] * 10 + crandom( ) * g_globalvars.v_up[1] * 10; missile->s.v.velocity[2] = g_globalvars.v_forward[2] * 600 + g_globalvars.v_up[2] * 200 + crandom( ) * g_globalvars.v_right[2] * 10 + crandom( ) * g_globalvars.v_up[0] * 10; } else { //missile->s.v.velocity = aim(self, 10000); aim( self->s.v.velocity ); // = aim(self, 10000); missile->s.v.velocity[0] = missile->s.v.velocity[0] * 600; missile->s.v.velocity[1] = missile->s.v.velocity[1] * 600; // missile->s.v.velocity[2] = missile->s.v.velocity[2] * 600; missile->s.v.velocity[2] = 200; } SetVector( missile->s.v.avelocity, 300, 300, 300 ); //missile.angles = vectoangles(missile.velocity); vectoangles( missile->s.v.velocity, missile->s.v.angles ); missile->s.v.touch = ( func_t ) ToasterTouch; missile->s.v.nextthink = g_globalvars.time + 3; missile->s.v.think = ( func_t ) ToasterElec; setmodel( missile, "progs/v_spike.mdl" ); setsize( missile, 0, 0, 0, 0, 0, 0 ); setorigin( missile, self->s.v.origin[0], self->s.v.origin[1], self->s.v.origin[2]); }
void StandCanon::rollUpdate() { _rotateDelay += Timer::getRoundTime(); if (_rotateDelay >= TIME_ROTATE_DELAY) { int requiredRollStepToAim = (int)(aim() / STAND_CANON_DIRECTION_MEASURE + 0.5) - _shootDirection - 4; if (STAND_CANON_CHECK_IF_SHOOT_ANGLE(Default::round(_currentAimingAngle, STAND_CANON_DIRECTION_MEASURE))) { _shootDirection += GET_SIGN(requiredRollStepToAim); _rotateDelay = 0; } } }
template<> Bullet<particle>::Bullet(float origx, float origy, float targetx, float targety){ boost = (float)(rand()%100)*0.01+1; x = origx; y = origy; aim(targetx, targety, 110.0); xv+=(float)((rand()%9)-4); yv+=(float)((rand()%9)-4); w = (float)(rand()%5+1); h = w; decay = 0.98; }
/* ================ W_FireShotgun ================ */ void W_FireShotgun() { vec3_t dir; sound( self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM ); g_globalvars.msg_entity = EDICT_TO_PROG( self ); trap_WriteByte( MSG_ONE, SVC_SMALLKICK ); if ( deathmatch != 4 ) self->s.v.currentammo = --( self->s.v.ammo_shells ); //dir = aim (self, 100000); aim( dir ); FireBullets( 6, dir, 0.04, 0.04, 0 ); }
//========================================================================= // Fire a laserbolt -- mtf style void W_FireLaser( ) { vec3_t vec; vec3_t org; self->s.v.currentammo = --( self->s.v.ammo_nails ); makevectors( self->s.v.v_angle ); VectorScale( g_globalvars.v_forward, 8, org ); VectorAdd( self->s.v.origin, org, org ); aim( vec ); VectorNormalize( vec ); newmis = spawn( ); newmis->s.v.owner = EDICT_TO_PROG( self ); newmis->s.v.enemy = EDICT_TO_PROG( self ); // The real owner newmis->s.v.movetype = MOVETYPE_FLYMISSILE; newmis->s.v.solid = SOLID_TRIGGER; // set model, skin, and effects setmodel( newmis, "progs/beam.mdl" ); if ( tf_data.coloredlights == TRUE ) { if ( self->team_no == 1 ) newmis->s.v.effects = 64; else { if ( self->team_no == 2 ) newmis->s.v.effects = 128; else newmis->s.v.effects = 2; } } else newmis->s.v.effects = 2; newmis->s.v.skin = self->team_no - 1; SetVector( newmis->s.v.avelocity, 0, 0, 500 ); setsize( newmis, 0, 0, 0, 0, 0, 0 ); setorigin( newmis, org[0], org[1], org[2] + 16 ); VectorScale( vec, 1500, newmis->s.v.velocity ); vectoangles( newmis->s.v.velocity, newmis->s.v.angles ); newmis->s.v.angles[1] += 0.1; VectorCopy( newmis->s.v.velocity, newmis->s.v.oldorigin ); newmis->s.v.nextthink = g_globalvars.time + 5; newmis->s.v.think = ( func_t ) SUB_Remove; newmis->s.v.touch = ( func_t ) LaserBolt_Touch; }
void UnitFiring::autoFire() { mTargetAquired = selectTarget(); if (!mTargetAquired) mAimReset = true; if (mTargetAquired) { mTargetPosition = predictTargetPosition( const_cast<Unit*>(mTargetUnit)); aim(); if (isAimed()) { fire(); } } else if (mAimReset) { resetAim(); } else { freezeAim(); } theApp->displayUnitReload(this, getRemainingReloadTime()); }
/* ================ W_FireSuperShotgun ================ */ void W_FireSuperShotgun() { vec3_t dir; if ( self->s.v.currentammo == 1 ) { W_FireShotgun(); return; } sound( self, CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM ); g_globalvars.msg_entity = EDICT_TO_PROG( self ); trap_WriteByte( MSG_ONE, SVC_BIGKICK ); if ( deathmatch != 4 ) self->s.v.currentammo = self->s.v.ammo_shells = self->s.v.ammo_shells - 2; //dir = aim (self, 100000); aim( dir ); FireBullets( 14, dir, 0.14, 0.08, 0 ); }
void W_FireRocket() { if ( deathmatch != 4 ) self->s.v.currentammo = self->s.v.ammo_rockets = self->s.v.ammo_rockets - 1; sound( self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM ); g_globalvars.msg_entity = EDICT_TO_PROG( self ); trap_WriteByte( MSG_ONE, SVC_SMALLKICK ); newmis = spawn(); g_globalvars.newmis = EDICT_TO_PROG( newmis ); newmis->s.v.owner = EDICT_TO_PROG( self ); newmis->s.v.movetype = MOVETYPE_FLYMISSILE; newmis->s.v.solid = SOLID_BBOX; // set newmis speed makevectors( self->s.v.v_angle ); aim( newmis->s.v.velocity ); // = aim(self, 1000); VectorScale( newmis->s.v.velocity, 1000, newmis->s.v.velocity ); // newmis->s.v.velocity = newmis->s.v.velocity * 1000; vectoangles( newmis->s.v.velocity, newmis->s.v.angles ); newmis->s.v.touch = ( func_t ) T_MissileTouch; newmis->voided = 0; // set newmis duration newmis->s.v.nextthink = g_globalvars.time + 5; newmis->s.v.think = ( func_t ) SUB_Remove; newmis->s.v.classname = "rocket"; setmodel( newmis, "progs/missile.mdl" ); setsize( newmis, 0, 0, 0, 0, 0, 0 ); // setorigin (newmis, self->s.v.origin + v_forward*8 + '0 0 16'); setorigin( newmis, self->s.v.origin[0] + g_globalvars.v_forward[0] * 8, self->s.v.origin[1] + g_globalvars.v_forward[1] * 8, self->s.v.origin[2] + g_globalvars.v_forward[2] * 8 + 16 ); }
void TankAI::hunt() { //choose some random position on the map and find a way from here to this position if (Utils::distance(_tank->getPosition(), _currentTarget->getPosition()) > SHOOTING_DISTANCE) { while (_path == NULL) { Point randomGoal; do { randomGoal = _scene.getTerrain().getRandomPointOnMap(); } while (Utils::distance(randomGoal, _currentTarget->getPosition()) < SHOOTING_DISTANCE); _path = _scene.getTerrain().findPath(_tank->getPosition(), randomGoal); } followPath(); } aim(); if (_tank->_reloadingTime == 0) { //shoot _tank->fireBullet(); _tank->_reloadingTime = SMALLTANK_RELOADING_TIME; } }
void W_FireSuperSpikes() { vec3_t dir, tmp; // gedict_t* old; sound( self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM ); self->attack_finished = g_globalvars.time + 0.2; if ( deathmatch != 4 ) self->s.v.currentammo = self->s.v.ammo_nails = self->s.v.ammo_nails - 2; aim( dir ); //dir = aim (self, 1000); VectorCopy( self->s.v.origin, tmp ); tmp[2] += 16; launch_spike( tmp, dir ); newmis->s.v.touch = ( func_t ) superspike_touch; setmodel( newmis, "progs/s_spike.mdl" ); setsize( newmis, 0, 0, 0, 0, 0, 0 ); g_globalvars.msg_entity = EDICT_TO_PROG( self ); trap_WriteByte( MSG_ONE, SVC_SMALLKICK ); }
void Camera::printCamera() const{ cout << " Eye : " << eye(0) << " " << eye(1) << " " << eye(2) << endl; cout << " Aim : " << aim(0) << " " << aim(1) << " " << aim(2) << endl; cout << " Up : " << up(0) << " " << up(1) << " " << up(2) << endl; cout << " Eye to Aim distance: " << (eye-aim).norm() << endl; }
bool P_Thing_Projectile (int tid, AActor *source, int type, const char *type_name, angle_t angle, fixed_t speed, fixed_t vspeed, int dest, AActor *forcedest, int gravity, int newtid, bool leadTarget) { int rtn = 0; const PClass *kind; AActor *spot, *mobj, *targ = forcedest; FActorIterator iterator (tid); double fspeed = speed; int defflags3; if (type_name == NULL) { if (type >= MAX_SPAWNABLES) return false; if ((kind = SpawnableThings[type]) == NULL) return false; } else { if ((kind = PClass::FindClass(type_name)) == NULL || kind->ActorInfo == NULL) return false; } // Handle decorate replacements. kind = kind->ActorInfo->GetReplacement()->Class; defflags3 = GetDefaultByType (kind)->flags3; if ((defflags3 & MF3_ISMONSTER) && ((dmflags & DF_NO_MONSTERS) || (level.flags2 & LEVEL2_NOMONSTERS))) return false; if (tid == 0) { spot = source; } else { spot = iterator.Next(); } while (spot != NULL) { FActorIterator tit (dest); if (dest == 0 || (targ = tit.Next())) { do { fixed_t z = spot->z; if (defflags3 & MF3_FLOORHUGGER) { z = ONFLOORZ; } else if (defflags3 & MF3_CEILINGHUGGER) { z = ONCEILINGZ; } else if (z != ONFLOORZ) { z -= spot->floorclip; } mobj = Spawn (kind, spot->x, spot->y, z, ALLOW_REPLACE); if (mobj) { mobj->tid = newtid; mobj->AddToHash (); P_PlaySpawnSound(mobj, spot); if (gravity) { mobj->flags &= ~MF_NOGRAVITY; if (!(mobj->flags3 & MF3_ISMONSTER) && gravity == 1) { mobj->gravity = FRACUNIT/8; } } else { mobj->flags |= MF_NOGRAVITY; } mobj->target = spot; if (targ != NULL) { fixed_t spot[3] = { targ->x, targ->y, targ->z+targ->height/2 }; FVector3 aim(float(spot[0] - mobj->x), float(spot[1] - mobj->y), float(spot[2] - mobj->z)); if (leadTarget && speed > 0 && (targ->velx | targ->vely | targ->velz)) { // Aiming at the target's position some time in the future // is basically just an application of the law of sines: // a/sin(A) = b/sin(B) // Thanks to all those on the notgod phorum for helping me // with the math. I don't think I would have thought of using // trig alone had I been left to solve it by myself. FVector3 tvel(targ->velx, targ->vely, targ->velz); if (!(targ->flags & MF_NOGRAVITY) && targ->waterlevel < 3) { // If the target is subject to gravity and not underwater, // assume that it isn't moving vertically. Thanks to gravity, // even if we did consider the vertical component of the target's // velocity, we would still miss more often than not. tvel.Z = 0.0; if ((targ->velx | targ->vely) == 0) { goto nolead; } } double dist = aim.Length(); double targspeed = tvel.Length(); double ydotx = -aim | tvel; double a = acos (clamp (ydotx / targspeed / dist, -1.0, 1.0)); double multiplier = double(pr_leadtarget.Random2())*0.1/255+1.1; double sinb = -clamp (targspeed*multiplier * sin(a) / fspeed, -1.0, 1.0); // Use the cross product of two of the triangle's sides to get a // rotation vector. FVector3 rv(tvel ^ aim); // The vector must be normalized. rv.MakeUnit(); // Now combine the rotation vector with angle b to get a rotation matrix. FMatrix3x3 rm(rv, cos(asin(sinb)), sinb); // And multiply the original aim vector with the matrix to get a // new aim vector that leads the target. FVector3 aimvec = rm * aim; // And make the projectile follow that vector at the desired speed. double aimscale = fspeed / dist; mobj->velx = fixed_t (aimvec[0] * aimscale); mobj->vely = fixed_t (aimvec[1] * aimscale); mobj->velz = fixed_t (aimvec[2] * aimscale); mobj->angle = R_PointToAngle2 (0, 0, mobj->velx, mobj->vely); } else { nolead: mobj->angle = R_PointToAngle2 (mobj->x, mobj->y, targ->x, targ->y); aim.Resize (fspeed); mobj->velx = fixed_t(aim[0]); mobj->vely = fixed_t(aim[1]); mobj->velz = fixed_t(aim[2]); } if (mobj->flags2 & MF2_SEEKERMISSILE) { mobj->tracer = targ; } } else { mobj->angle = angle; mobj->velx = FixedMul (speed, finecosine[angle>>ANGLETOFINESHIFT]); mobj->vely = FixedMul (speed, finesine[angle>>ANGLETOFINESHIFT]); mobj->velz = vspeed; } // Set the missile's speed to reflect the speed it was spawned at. if (mobj->flags & MF_MISSILE) { mobj->Speed = fixed_t (sqrt (double(mobj->velx)*mobj->velx + double(mobj->vely)*mobj->vely + double(mobj->velz)*mobj->velz)); } // Hugger missiles don't have any vertical velocity if (mobj->flags3 & (MF3_FLOORHUGGER|MF3_CEILINGHUGGER)) { mobj->velz = 0; } if (mobj->flags & MF_SPECIAL) { mobj->flags |= MF_DROPPED; } if (mobj->flags & MF_MISSILE) { if (P_CheckMissileSpawn (mobj)) { rtn = true; } } else if (!P_TestMobjLocation (mobj)) { // If this is a monster, subtract it from the total monster // count, because it already added to it during spawning. if (mobj->CountsAsKill()) { level.total_monsters--; } // Same, for items if (mobj->flags & MF_COUNTITEM) { level.total_items--; } mobj->Destroy (); } else { // It spawned fine. rtn = 1; } } } while (dest != 0 && (targ = tit.Next())); } spot = iterator.Next(); } return rtn != 0; }
void runGame(){ // matrix led(64, 32, true, target::pins::d43, target::pins::d42, target::pins::d39, // target::pins::d25, target::pins::d26, target::pins::d27, target::pins::d28, // target::pins::d33, target::pins::d34, target::pins::d35, target::pins::d36, // target::pins::d37, target::pins::d38); matrix led(64, 32, true); led.start(); auto jump_button = hwlib::target::pin_in(hwlib::target::pins::d2); auto flip_button = hwlib::target::pin_in(hwlib::target::pins::d3); uint32_t line_color = 0xFA00; Timer t; while (1) { AnimatedImage aim(led, runner, vector(10,9)); Runner doll(aim, jump_button); Obstacles obs(led, flip_button); straightLine l(led, vector(0, 19), vector(63, 19), line_color); String points(led, tahoma8, (char*)"0", 255, 0,0, vector(0, 7)); bool next = true; // menue while (jump_button.get() && flip_button.get()){ led.clear(); String s1(led, tahoma10, (char*)"Press a key", 0x73A81E, vector(5, 15)); String s2(led, tahoma10, (char*)"to start", 0x73A81E, vector(15,25)); s1.draw(); s2.draw(); led.swap_buffer(false); } // run the game while (next){ led.clear(); doll.update(); if (obs.update(doll) == false) next = false; points.draw(); l.setColor(line_color); l.print(); led.swap_buffer(false); line_color += 500; } t.delayMilliseconds(800); // Losed the game do { led.clear(); led.swap_buffer(false); t.delayMilliseconds(200); led.clear(); String s1(led, tahoma10, (char*)"Game", 0XBA005D, vector(5, 15)); String s2(led, tahoma10, (char*)"Over", 0XBA005D, vector(5, 25)); Image im(led, gameover, vector(32, 0)); im.draw(); s1.draw(); s2.draw(); led.swap_buffer(false); t.delayMilliseconds(300); } while (jump_button.get() && flip_button.get()); } // end WHILE(1) }
int main(int argc, char *argv[]) { atexit(atexit_function); if(signal(SIGTSTP, exit_handler) == SIG_ERR) error("signal()"); if(signal(SIGINT, exit_handler) == SIG_ERR) error("signal()"); printf("\nParsing arguments"); parse_arguments(argc, argv); printf("\t\t\t\t\033[32m[ OK ]\033[0m\n"); printf("Client's name:\t%s\n", client_name); init_client(); // Odpalanie watku gry if(pthread_create(&thread, NULL, thread_function, NULL) == -1) error("pthread_create()"); // Rejestracja klienta na serwerze request_t request; strcpy(request.name, client_name); request.lobby=MENU; request.action = ADD_USER; printf("Sending registration request"); pthread_mutex_lock(&mutex); if(send(socket_fd, (void*) &request, sizeof(request), 0) == -1) error("send()"); printf("\t\t\t\033[32m[ OK ]\033[0m\n"); pthread_mutex_unlock(&mutex); printf("\nClient registered\n"); request_t response; while(1) { //OBSLUGA GRY //EDIT if(recv(socket_fd, (void*) &response, sizeof(response), 0) == -1) error("recv()"); switch(response.lobby){ case MENU: switch(response.action){ case HISTORY: if(strcmp(response.msg, END_HISTORY) != 0) printf("%s\n", response.msg); else pthread_cond_signal(&waiting_cond); break; default: printf("Request received but not recognized: %d\n", response.action); break; } break; case GAME: switch(response.action){ case FIELD: printf("Przeciwnik strzela w: %c %d\n",'A'+response.field.y,response.field.x); pthread_mutex_lock(&game_mutex); aim(response.field.x,response.field.y); pthread_mutex_unlock(&game_mutex); break; case FIELD_STATE: if(response.field_state==MISS){ pthread_mutex_lock(&game_mutex); my_turn=0; field.enemy_fields[response.field.y][response.field.x]=3; print_board(); printf("Pudlo! Kolej przeciwnika.\n"); pthread_mutex_unlock(&game_mutex); }else{ pthread_mutex_lock(&game_mutex); my_turn=1; field.enemy_fields[response.field.y][response.field.x]=2; print_board(); printf("Trafiles! Twoja kolej.\n"); pthread_cond_signal(&waiting_cond); pthread_mutex_unlock(&game_mutex); } break; case GAME_STATE: if(response.game_state == WIN){ printf("BRAWO! WYGRALES!!!\n"); request_t response; strcpy(response.name,client_name); response.lobby = GAME; response.action = GAME_STATE; response.game_state=WIN; pthread_mutex_lock(&mutex); if(send(socket_fd, (void*) &response, sizeof(response), 0) == -1) error("send() game"); pthread_mutex_unlock(&mutex); pthread_mutex_lock(&game_mutex); game_state=0; pthread_cond_signal(&waiting_cond); pthread_mutex_unlock(&game_mutex); } else if(response.game_state == DISCON){ exit(EXIT_SUCCESS); } break; case SERVER_INFO: if(response.server_info==OPPONENT){ opponent_socket=response.opponent_socket; printf("enemy found \033[32m[ OK ]\033[0m\n"); pthread_mutex_lock(&game_mutex); wait=1; pthread_cond_signal(&waiting_cond); pthread_mutex_unlock(&game_mutex); } break; case START_GAME: if(response.field_state==HIT){ printf("starting game...\n"); pthread_mutex_lock(&game_mutex); enemy_ready=1; my_turn = 1; pthread_cond_signal(&waiting_cond); pthread_mutex_unlock(&game_mutex); } break; default: printf("response received but not recognized: %d\n", response.action); break; } break; default: printf("response received but not recognized: %d\n", response.lobby); break; } } exit(EXIT_SUCCESS); }
task main() { initializeRobot(); int IRvalue = SensorValue[IR]; Start(); IRvalue = SensorValue[IR]; int i; for (i=0;i<100;i++) { nxtDisplayCenteredBigTextLine(4, "%d", IRvalue); } if(IRvalue==1) { Move(20.0, 70.0); // drive forward 15 inches wait10Msec(10); Turn_gyro(90.0); // turn counterclockwise 35 degrees wait10Msec(10); Move(26.0, 70.0); // drive forward 24 inches wait10Msec(10); } else if(IRvalue==2 || IRvalue==0) { Move(15.0, 70.0); // drive forward 15 inches wait10Msec(10); Turn_gyro(45.0); // turn counterclockwise 35 degrees wait10Msec(10); Move(12.0, 70.0); // drive forward 24 inches wait10Msec(10); } else if(IRvalue==3) { Move(15.0, 70.0); // drive forward 15 inches wait10Msec(10); //Turn_gyro(30.0); // turn counterclockwise 35 degrees //wait10Msec(10); Move(12.0, 70.0); // drive forward 24 inches wait10Msec(10); } /*Arm(205.0, 70.0); // arm down 205 degrees wait10Msec(100);*/ aim(4); wait10Msec(100); /*Move(6.0, 70.0); // drive forward 6 inches wait10Msec(10);*/ aim(5); wait10Msec(100); aim(4); wait10Msec(100); /*Arm(-50.0, 70.0); // arm move 50 degrees wait10Msec(100); Move(-18.0, 70.0); // drive backward 18 inches wait10Msec(10);*/ }
void DropFlag( gedict_t *flag, qbool tossed ) { gedict_t *p = PROG_TO_EDICT( flag->s.v.owner ); gedict_t *p1; p->ctf_flag -= ( p->ctf_flag & CTF_FLAG ); p->s.v.effects -= ( (int) p->s.v.effects & ( EF_FLAG1 | EF_FLAG2 )); p->s.v.items -= ( (int) p->s.v.items & (int) flag->s.v.items ); setorigin( flag, PASSVEC3(p->s.v.origin) ); flag->s.v.origin[2] -= 24; flag->cnt = FLAG_DROPPED; if ( tossed ) { trap_makevectors( p->s.v.v_angle ); if ( p->s.v.v_angle[0] ) { flag->s.v.velocity[0] = g_globalvars.v_forward[0] * 300 + g_globalvars.v_up[0] * 200; flag->s.v.velocity[1] = g_globalvars.v_forward[1] * 300 + g_globalvars.v_up[1] * 200; flag->s.v.velocity[2] = g_globalvars.v_forward[2] * 300 + g_globalvars.v_up[2] * 200; } else { aim( flag->s.v.velocity ); VectorScale( flag->s.v.velocity, 300, flag->s.v.velocity ); flag->s.v.velocity[2] = 200; } } else { SetVector( flag->s.v.velocity, 0, 0, 300 ); } flag->s.v.flags = FL_ITEM; flag->s.v.solid = SOLID_TRIGGER; flag->s.v.movetype = MOVETYPE_TOSS; setmodel( flag, flag->mdl ); setsize ( flag, -16, -16, 0, 16, 16, 74 ); flag->super_time = g_globalvars.time + FLAG_RETURN_TIME; if ( tossed ) { flag->s.v.nextthink = g_globalvars.time + 0.75; flag->s.v.think = (func_t) FlagResetOwner; } else { flag->s.v.owner = EDICT_TO_PROG( flag ); } G_bprint( 2, "%s", p->s.v.netname ); if ( streq(getteam(p), "red") ) G_bprint( 2, " %s the %s flag!\n", tossed ? redtext("tossed") : redtext("lost"), redtext("BLUE") ); else G_bprint( 2, " %s the %s flag!\n", tossed ? redtext("tossed") : redtext("lost"), redtext("RED") ); for ( p1 = world; (p1 = find_plr( p1 )); ) { if ( strneq(getteam(p), getteam(p1)) ) p1->carrier_hurt_time = -1; } refresh_plus_scores (); // update players status bar faster }