/// <summary> /// Creates a new entity packet from the given entity. /// </summary> /// <returns></returns> public EntityPacket(string id, Entity entity) { entityId = id; positionX = entity.Position.X; positionY = entity.Position.Y; velocityX = entity.GetVelocity().X; velocityY = entity.GetVelocity().Y; _isDead = entity.IsDead; type = entity.GetType(); }
/// <summary> /// Update the aniamtion, timers and fire events. /// </summary> /// <param name="entity"></param> public void Update(Entity entity) { //SpeedParticle speed = new SpeedParticle(texture, drawRectangle.X, drawRectangle.Y, sourceRectangle, entity.IsFacingRight); //GameWorld.ParticleSystem.Add(speed); FindHighestPriorityAnimation(); UpdatePositionOnly(entity); if (_currentName == "walk" || _currentName == "run") { // y = 1020/(x + 1) - 20 _currentAnimationData.Speed = (int)(-20 + 500f / (Math.Abs(entity.GetVelocity().X) + 1)); } if (_currentName == "climb") { _currentAnimationData.Speed = (int)(-20 + 500f / (Math.Abs(entity.GetVelocity().Y) + 1)); if (Math.Abs(entity.GetVelocity().Y) < .1f) { _currentAnimationData.Speed = Int32.MaxValue; } } if (_frameTimer.TimeElapsedInMilliSeconds > _currentAnimationData.Speed) { _frameTimer.Reset(); _currentFrame++; if (_currentFrame >= _currentAnimationData.FrameCount) { AnimationEnded?.Invoke(); // Send notice that animation has ended. if (!_currentAnimationData.IsRepeating) { _currentFrame = _currentAnimationData.FrameCount - 1; } else { _currentFrame = 0; } } FrameChanged?.Invoke(new FrameArgs(_currentFrame)); } _sourceRectangle.X = _currentFrame * _currentAnimationData.Width; }
internal static void DoFly(Entity entity) { BaseScript.OnInterval(0, delegate { if (!entity.IsFieldTrue("EnableFly")) { return(false); } if (entity.IsOnGround()) { return(true); } Vector3 Velocity = entity.GetVelocity(); Velocity.Z = 23; if (entity.IsFieldTrue("Up")) { Velocity.Z += 300; } if (entity.IsFieldTrue("Down")) { Velocity.Z -= 300; } if (!entity.IsFieldTrue("Forward") && !entity.IsFieldTrue("Backward") && !entity.IsFieldTrue("Left") && !entity.IsFieldTrue("Right")) { if (Velocity.X > 0) { Velocity.X -= 1; } else if (Velocity.X < 0) { Velocity.X += 1; } if (Velocity.Y > 0) { Velocity.Y -= 1; } else { Velocity.Y += 1; } } entity.SetVelocity(Velocity); return(true); }); }
void OnControllerColliderHit(ControllerColliderHit hit) { if (GameEngine.Instance.isStarted && isFrozen) { Entity e = hit.gameObject.GetComponent <Entity>(); if (!GameEngine.Instance.isKilled && e != null && (e.GetVelocity() > 1.0f && (movement.collisionFlags & CollisionFlags.CollidedAbove) != 0)) { StartCoroutine(GameEngine.Instance.PlayDeath(0)); } } }
private static void shThrusters(Entity player) { bool isGrounded = !player.GetField <bool>("mayThrust"); bool hasThrustJumped = player.GetField <bool>("hasThrustJumped"); bool hasThrusted = player.GetField <bool>("hasThrustedForward"); int thrustsAvailable = player.GetField <int>("thrusterEnergy"); if (!isGrounded && !hasThrustJumped && !hasThrusted && thrustsAvailable > 0 && player.IsAlive) { player.SetField("hasThrustJumped", true); player.SetField("thrusterEnergy", player.GetField <int>("thrusterEnergy") - 1); player.SetField("lastThrust", GSCFunctions.GetTime()); AfterDelay(250, () => player.SetField("maySlam", true)); if (player.HasPerk("specialty_quieter")) { player.PlaySound("bullet_mega_flesh"); } else { player.PlaySound("weap_hind_rocket_fire"); } shThrustRadarBlip(player); player.SetPerk("specialty_automantle", true, false); Vector3 currentVel = player.GetVelocity(); float velZ = 500; player.SetVelocity(new Vector3(currentVel.X, currentVel.Y, velZ)); } else if (!isGrounded && !hasThrustJumped && thrustsAvailable == 0 && player.IsAlive) { player.PlayLocalSound("weap_motiontracker_open_plr"); } else { player.SetField("mayThrust", true); OnInterval(50, () => { bool grounded = player.IsOnGround(); if (grounded) { player.SetField("mayThrust", false); player.SetField("maySlam", false); player.SetField("hasThrustJumped", false); player.SetField("hasThrustedForward", false); player.UnSetPerk("specialty_automantle", true); return(false); } else { return(true); } }); } }
private void Monitor(Entity player, ref Vector3 saved, ref HudElem velocity) { int v = Convert.ToInt32((Math.Truncate(Math.Sqrt((Math.Pow(player.GetVelocity().X, 2)) + (Math.Pow(player.GetVelocity().Y, 2)))))); velocity.SetValue(v); if (player.IsPlayer && player.IsAlive) { if (player.MeleeButtonPressed()) { saved = player.GetOrigin(); player.IPrintLnBold("Saved Location"); } if (player.UseButtonPressed()) { player.SetOrigin(saved); player.IPrintLnBold("Teleported"); } } }
private void runSpecialistWeaponFunctions(Entity player, int func) { switch (func) { case 0: player.SetField("specialistTime", 0); doSlamAnim(player, 0); updateSpecialistTimer(player); Vector3 currentVel = player.GetVelocity(); player.SetVelocity(new Vector3(currentVel.X, currentVel.Y, 350)); AfterDelay(100, () => { OnInterval(50, () => { bool hasHitGround = player.IsOnGround(); if (hasHitGround) { doSlamAnim(player, 1); //Play explode FX + sound player.RadiusDamage(player.Origin, 512, 300, 100, player, "MOD_EXPLOSIVE", "nuke_mp"); AfterDelay(700, () => { doSlamAnim(player, 2); player.TakeWeapon("bomb_site_mp"); }); return(false); } else { return(true); } }); }); return; case 1: //Handled in onWeaponFired break; case 2: //handled in onGrenadeFired break; case 3: //handled in onWeaponFired break; case 4: //handled in onWeaponFired break; case 5: //handled in onWeaponFired break; case 6: //handled in onWeaponFired break; case 7: //perk-based break; case 8: //handled in onWeaponFired break; } //runSpecialistTimer(player); }
public void Update(FrameEventArgs e) { //Game time and delta time dt = (float)e.Time; sceneManager.dt = dt; time += (float)e.Time; SceneManager.time = time; //Pause button toggle timer pauseToggleTimer += dt; //Pauses game when escape is pressed and unpauses when pressed again if (keyboardInput.Contains("Escape") && pauseToggleTimer > 0.25f) { if (paused != true) { paused = true; pauseToggleTimer = 0; } else { paused = false; pauseToggleTimer = 0; } } //Checks game isn't paused if (paused != true) { light.GetTransform().Translation -= light.GetTransform().Forward *dt; test.GetTransform().Translation -= test.GetTransform().Forward *test.GetVelocity().Velocity *dt; test.GetTransform().Translation += test.GetTransform().Right *test.GetVelocity().Velocity *dt; test.GetTransform().Rotation += new Vector3(0, 0.1f * dt, 0); //Button toggle on/off timers noClipToggleTimer += dt; disableCollisionToggleTimer += dt; disableDroneToggleTimer += dt; //Buff timers damageBuffTimer += dt; speedBuffTimer += dt; disableDroneTimer += dt; //Damage delay timers damageDelay += dt; //Gets mouse position from input manager every frame mousePos = inputManager.MousePosition(); #region Player Movement and collision with drone logic if (keyboardInput.Contains("Up")) { //Moves player forward when W is pressed player.GetTransform().Translation += player.GetTransform().Forward *player.GetVelocity().Velocity *dt; //Moves camera forward to stay in line with player position mainCamera.MoveCamera(player.GetTransform().Translation); } if (keyboardInput.Contains("Down")) { //Moves player backwards when S is pressed player.GetTransform().Translation -= player.GetTransform().Forward *player.GetVelocity().Velocity *dt; //Moves camera backwards to stay in line with player position mainCamera.MoveCamera(player.GetTransform().Translation); } if (keyboardInput.Contains("Right")) { //Moves player right when D is pressed player.GetTransform().Translation += player.GetTransform().Right *player.GetVelocity().Velocity *dt; //Moves camera right to stay in line with player position mainCamera.MoveCamera(player.GetTransform().Translation); } if (keyboardInput.Contains("Left")) { //Moves player left when A is pressed player.GetTransform().Translation -= player.GetTransform().Right *player.GetVelocity().Velocity *dt; //Moves camera left to stay in line with player position mainCamera.MoveCamera(player.GetTransform().Translation); } if (player.GetCollidedWith().Count > 0) { foreach (string entityName in player.GetCollidedWith()) { //Removes a life from the player when colliding with a drone if (entityName.Contains("Drone") && damageDelay > 0.5f) { player.GetHealth().Health -= 1; health -= 1; damageDelay = 0; } if (entityName.Contains("Health") || entityName.Contains("Disable") || entityName.Contains("Speed") || entityName.Contains("Damage")) { // player.GetAudio().PlayOnAwake = true; } } } //Checks if drone collides with player foreach (Entity entity in entityManager.Entities()) { if (entity.Name.Contains("Drone")) { if (entity.GetCollidedWith().Count > 0) { foreach (string entityName in entity.GetCollidedWith()) { if (entityName.Contains("Player")) { // entity.GetAudio().PlayOnAwake = true; } } } } } //Game over screen when player runs out of lives if (player.GetHealth().Health <= 0) { //Game over logic sceneManager.LoadScene(new GameOverScene(sceneManager)); } #endregion #region Player Rotation on the Y axis based on mouse movement on the X axis if (sceneManager.Focused) { //Amount mouse has moved since last update call mouseDelta = oldMousePos - mousePos; //Adjusts player rotation on the x and y axis based on the mouse movement on the x and y axis if no clip is on if (noClip == true) { player.GetTransform().Rotation += new Vector3(mouseDelta.Y, mouseDelta.X, 0.0f) * mouseSensitivity; } //Adjusts player rotation on the y axis based on mouse movement on the x axis if no clip is off else { player.GetTransform().Rotation += new Vector3(0.0f, mouseDelta.X, 0.0f) * mouseSensitivity; } //clamp x rotation if (player.GetTransform().Rotation.X > MathHelper.DegreesToRadians(89)) { player.GetTransform().Rotation = new Vector3(MathHelper.DegreesToRadians(89), player.GetTransform().Rotation.Y, 0.0f); } if (player.GetTransform().Rotation.X < MathHelper.DegreesToRadians(-89)) { player.GetTransform().Rotation = new Vector3(MathHelper.DegreesToRadians(-89), player.GetTransform().Rotation.Y, 0.0f); } //Adjusts camera rotation to stay in line with player rotation mainCamera.RotateCamera(player.GetTransform().Rotation); //Centers cursor to center of screen inputManager.CenterCursor(); //Resets mouse position oldMousePos = mousePos; } #endregion #region Shooting logic on left click //Creates new bullet entity on click based on fire rate if (mouseInput.Contains("Left") && time > nextShot) { Entity bullet = new Entity("Bullet(" + bulletCount + ")"); bullet.AddComponent(new ComponentTransform(player.GetTransform().Translation - new Vector3(0, 0.25f, 0), player.GetTransform().Rotation, new Vector3(0.05f, 0.05f, 0.05f))); bullet.AddComponent(new ComponentGeometry("Geometry/sphere.obj")); bullet.AddComponent(new ComponentTexture("Textures/Blue.png")); bullet.AddComponent(new ComponentVelocity(10f)); bullet.AddComponent(new ComponentShader("Shaders/vPulsating.glsl", "Shaders/fPulsating.glsl")); bullet.AddComponent(new ComponentAudio("Audio/GUNSHOT.wav", false, true)); bullet.AddComponent(new ComponentSphereCollider((0.05f), bulletIgnoreCollisionWith)); entityManager.AddEntity(bullet); //Assigns new entity to appropriate system(s) systemManager.AssignNewEntity(bullet); //Iterates bullet count bulletCount++; //Sets timestamp for when next shot can be fired nextShot = time + fireRate; } //Bullet movement and collisions foreach (Entity entity in entityManager.Entities()) { //Moves bullet and destroys on collision if (entity.Name.Contains("Bullet")) { entity.GetTransform().Translation += entity.GetTransform().Forward *entity.GetVelocity().Velocity *dt; //Destroys bullet if it has collided with something if (entity.GetCollidedWith().Count > 0) { //Removes entity from systems to remove it from game systemManager.DestroyEntity(entity); //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory despawnedEntities.Add(entity); } } //Bullet collision with drones if (entity.Name.Contains("Drone")) { if (entity.GetCollidedWith().Count > 0) { foreach (string entityName in entity.GetCollidedWith()) { //Removes life from drone when bullet hits if (entityName.Contains("Bullet")) { if (damageBuff == true) { entity.GetHealth().Health -= 2; } else { entity.GetHealth().Health -= 1; } } } } //Destroys drone when it reaches 0 lives if (entity.GetHealth().Health <= 0) { //Removes entity from systems to remove it from game systemManager.DestroyEntity(entity); droneCount--; //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory despawnedEntities.Add(entity); } } } #endregion #region No Clip and debug keys logic //Activates no clip, allows player to move and rotate freely in 3d space, multiplies speed by 4 if (keyboardInput.Contains("N") && noClipToggleTimer > 0.25f) { if (noClip == false) { noClip = true; disableCollisions = true; noClipToggleTimer = 0; player.GetVelocity().Velocity *= 4; } else { noClip = false; disableCollisions = false; noClipToggleTimer = 0; player.GetVelocity().Velocity /= 4; } } //Moves player up when noclip is true if (keyboardInput.Contains("Space") && noClip == true) { player.GetTransform().Translation += new Vector3(0, 1, 0) * player.GetVelocity().Velocity *dt; mainCamera.MoveCamera(player.GetTransform().Translation); } //Disables/Enables drones when D is pressed if (keyboardInput.Contains("D") && disableDroneToggleTimer > 0.25f) { if (disableDrone == false) { disableDrone = true; disableDroneToggleTimer = 0; } else { disableDrone = false; disableDroneToggleTimer = 0; } } //Disables/Enables collisions when C is pressed if (keyboardInput.Contains("C") && disableCollisionToggleTimer > 0.25f) { if (disableCollisions == false) { disableCollisions = true; disableCollisionToggleTimer = 0; } else { disableCollisions = false; disableCollisionToggleTimer = 0; } } #endregion #region Power Up logic foreach (Entity entity in entityManager.Entities()) { if (entity.Name.Contains("Health")) { if (entity.GetCollidedWith().Contains("Player")) { //If player if (player.GetHealth().Health < 3) { player.GetHealth().Health += 1; health += 1; } //Removes entity from systems to remove it from game systemManager.DestroyEntity(entity); //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory despawnedEntities.Add(entity); } } if (entity.Name.Contains("Damage")) { if (entity.GetCollidedWith().Contains("Player")) { //Sets damage buff to true and sets timer for damage buff if (damageBuff == false) { damageBuff = true; damageBuffTimer = 0; } //Removes entity from systems to remove it from game systemManager.DestroyEntity(entity); //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory despawnedEntities.Add(entity); } } if (entity.Name.Contains("Speed")) { if (entity.GetCollidedWith().Contains("Player")) { //Sets speed buff to true and sets timer for speed buff if (speedBuff == false) { speedBuff = true; speedBuffTimer = 0; player.GetVelocity().Velocity *= 2; } //Removes entity from systems to remove it from game systemManager.DestroyEntity(entity); //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory despawnedEntities.Add(entity); } } if (entity.Name.Contains("Disable")) { if (entity.GetCollidedWith().Contains("Player")) { //Sets disable drones to true and sets timer for disabled drones if (disableDroneBuff == false) { disableDroneBuff = true; disableDroneTimer = 0; } //Removes entity from systems to remove it from game systemManager.DestroyEntity(entity); //Adds entity to despawn list to remove final reference of entity from entity manager to clear it from memory despawnedEntities.Add(entity); } } //Disables buffs when timers reach their end if (damageBuff == true && damageBuffTimer > 3) { damageBuff = false; } if (speedBuff == true && speedBuffTimer > 3) { speedBuff = false; player.GetVelocity().Velocity /= 2; } if (disableDroneBuff == true && disableDroneTimer > 3) { disableDroneBuff = false; } } #endregion #region Victory condition check //Checks if all drones are destroyed dronesDestroyed = true; foreach (Entity entity in entityManager.Entities()) { if (entity.Name.Contains("Drone")) { dronesDestroyed = false; } } //Exits game when all drones destroyed, planned to go to victory screen instead of exit. if (dronesDestroyed || keyboardInput.Contains("V")) { sceneManager.LoadScene(new VictoryScene(sceneManager)); } #endregion //Enables/Disables drone and collisions based on appropriate bools foreach (Entity entity in entityManager.Entities()) { //Collisions if (entity.GetComponentBoxCollider() != null) { if (entity.GetComponentBoxCollider().Disabled != disableCollisions) { entity.GetComponentBoxCollider().Disabled = disableCollisions; } } else if (entity.GetComponentSphereCollider() != null) { if (entity.GetComponentSphereCollider().Disabled != disableCollisions) { entity.GetComponentSphereCollider().Disabled = disableCollisions; } } //Drones if (entity.GetComponentAI() != null) { if (entity.GetComponentAI().Disabled != disableDrone) { entity.GetComponentAI().Disabled = disableDrone; } if (entity.GetComponentAI().Disabled != disableDroneBuff && disableDrone != true) { entity.GetComponentAI().Disabled = disableDroneBuff; } } } //Removes all references to destroyed entities to remove them from memory foreach (Entity entity in despawnedEntities) { entityManager.Entities().Remove(entity); } despawnedEntities.Clear(); //Calls Update Systems every frame systemManager.UpdateSystems(); } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="e">Provides a snapshot of timing values.</param> public override void Update(FrameEventArgs e) { if (GamePad.GetState(1).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Key.Escape)) { sceneManager.Exit(); } List <Entity> entities = entityManager.Entities(); dt = (float)e.Time; if (upPressed) { if (targetPos.X == -5000) { CheckXCollision(entities, -0.1f); if (!wallCollide) { MoveOnX(false); } } else if (targetPos.X == 5000) { CheckXCollision(entities, 0.1f); if (!wallCollide) { MoveOnX(true); } } else if (targetPos.Z < eyePos.Z) { CheckZCollision(entities, -0.1f); if (!wallCollide) { MoveOnZ(false); } } else if (targetPos.Z > eyePos.Z) { CheckZCollision(entities, 0.1f); if (!wallCollide) { MoveOnZ(true); } } } if (downPressed) { if (targetPos.X == -5000) { CheckXCollision(entities, 0.1f); if (!wallCollide) { MoveOnX(true); } } else if (targetPos.X == 5000) { CheckXCollision(entities, -0.1f); if (!wallCollide) { MoveOnX(false); } } else if (targetPos.Z < eyePos.Z) { CheckZCollision(entities, 0.1f); if (!wallCollide) { MoveOnZ(true); } } else if (targetPos.Z > eyePos.Z) { CheckZCollision(entities, -0.1f); if (!wallCollide) { MoveOnZ(false); } } } listenerPosition = eyePos; listenerDirection = targetPos; if (pelletsCollected == pelletIndex) { sceneManager.SceneChange(SceneTypes.GAME_WIN, score); } if (lifeTotal == 0) { sceneManager.SceneChange(SceneTypes.GAME_OVER, score); } if (ghostKill) { timer -= dt; } if (timer <= 0) { ghostKill = false; } Entity ghost = entities.Find(x => x.Name == "ghostA"); if (aDead) { aTimer += dt; if (aTimer >= 5 && aTimer <= 5.1) { aDead = false; aTimer = 0; ghost.ChangeVelocity(new Vector3(0, 0, -ghostASpeed)); } } Vector3 ghostVel = ghost.GetVelocity(); Vector3 ghostPos = ghost.GetPosition(); ghostCollision(entities, ghost, ghostVel, ghostPos, ghostASpeed, 5); ghost = entities.Find(x => x.Name == "ghostB"); ghostTimer += dt; if (ghostTimer >= 10 && ghostTimer <= 10.1) { ghost.ChangeVelocity(new Vector3(0, 0, -ghostBSpeed)); } if (bDead) { bTimer += dt; if (bTimer >= 5 && bTimer <= 5.1) { bDead = false; bTimer = 0; ghost.ChangeVelocity(new Vector3(0, 0, -ghostBSpeed)); } } ghostVel = ghost.GetVelocity(); ghostPos = ghost.GetPosition(); ghostCollision(entities, ghost, ghostVel, ghostPos, ghostBSpeed, 4); ghost = entities.Find(x => x.Name == "ghostC"); if (ghostTimer >= 20 && ghostTimer <= 20.1) { ghost.ChangeVelocity(new Vector3(0, 0, -ghostCSpeed)); } if (cDead) { cTimer += dt; if (cTimer >= 5 && cTimer <= 5.1) { cDead = false; cTimer = 0; ghost.ChangeVelocity(new Vector3(0, 0, -ghostCSpeed)); } } ghostVel = ghost.GetVelocity(); ghostPos = ghost.GetPosition(); ghostCollision(entities, ghost, ghostVel, ghostPos, ghostCSpeed, 6); // TODO: Add your update logic here // Move sounds source from right to left at 2.5 meters per second //emitterPosition = componentAudio.SetVelocity(emitterPosition, (float)(2.5 * e.Time)); //AL.Source(mySource, ALSource3f.Position, ref emitterPosition); // update OpenAL AL.Listener(ALListener3f.Position, ref listenerPosition); AL.Listener(ALListenerfv.Orientation, ref listenerDirection, ref listenerUp); }
public TrailParticle(Entity source, Color color) { Texture = GameWorld.ParticleSpriteSheet; CollRectangle = new Rectangle(source.GetCollRectangle().Center.X, source.GetCollRectangle().Center.Y, 8, 8); SourceRectangle = new Rectangle(8, 0, 8, 8); int buffer = 1; Velocity.X = GameWorld.RandGen.Next((int)-source.GetVelocity().X - buffer, (int)-source.GetVelocity().X + buffer + 1) * (float)GameWorld.RandGen.NextDouble(); Velocity.Y = GameWorld.RandGen.Next((int)-source.GetVelocity().Y - buffer, (int)-source.GetVelocity().Y + buffer + 1); Position = new Vector2(CollRectangle.X, CollRectangle.Y); Opacity = .5f; light = new Lights.DynamicPointLight(this, .5f, false, color, 1); GameWorld.Instance.LightEngine.AddDynamicLight(light); }
public JumpSmokeParticle(Entity entity) { Texture = ContentHelper.LoadTexture("Effects/smoke"); CollRectangle = new Rectangle(entity.GetCollRectangle().Center.X - 4, entity.GetCollRectangle().Bottom - 4, 8, 8); SourceRectangle = new Rectangle(8 * GameWorld.RandGen.Next(0, 4), 0, 8, 8); Position = new Vector2(CollRectangle.X, CollRectangle.Y); Velocity.X = (float)GameWorld.RandGen.NextDouble() * GameWorld.RandGen.Next(-3 - (int)entity.GetVelocity().X / 2, 3 - (int)entity.GetVelocity().X / 2); Velocity.Y = (float)GameWorld.RandGen.NextDouble() * -1f; Opacity = 1f; }
private static void treyarchThrusters(Entity player) { bool isGrounded = player.GetField <int>("mayThrust") == 0; if (!isGrounded) { player.SetField("thrustersActive", 1); Entity thrusterSound = null; if (!player.HasPerk("specialty_quieter") && player.GetField <int>("thrusterEnergy") > 0) { thrusterSound = GSCFunctions.Spawn("script_origin", player.Origin); //thrusterSound.LinkTo(player); thrusterSound.PlayLoopSound("weap_hind_rocket_loop_dist"); player.SetPerk("specialty_radarblip", true, false); } OnInterval(50, () => { int thrusterEnergy = player.GetField <int>("thrusterEnergy"); if (thrusterEnergy <= 0) { player.SetField("thrustersActive", 0); return(true); } Vector3 currentVel = player.GetVelocity(); float vel = currentVel.Z += 75; if (vel > 200) { vel = 200; } player.SetVelocity(new Vector3(currentVel.X, currentVel.Y, vel)); player.SetField("thrusterEnergy", thrusterEnergy - 1); updateThrusterBar(player, thrusterEnergy - 1); if (thrusterSound != null) { thrusterSound.Origin = player.Origin; } //Log.Write(LogLevel.All, "Energy {0}", bird.GetField<int>("thrusterEnergy")); thrusterEnergy = player.GetField <int>("thrusterEnergy"); int time = GSCFunctions.GetTime(); player.SetField("lastThrust", time); bool stopFlying = (thrusterEnergy == 0 || player.GetField <int>("thrustersActive") == 0); if (stopFlying) { if (!player.HasPerk("specialty_quieter") && thrusterSound != null) { thrusterSound.StopLoopSound(); thrusterSound.Delete(); player.UnSetPerk("specialty_radarblip", true); } return(false); } else { return(true); } }); } else { player.SetField("mayThrust", 1); OnInterval(50, () => { bool grounded = player.IsOnGround(); if (grounded) { player.SetField("mayThrust", 0); return(false); } else { return(true); } }); } }
private static void shThrustersDirectional(Entity player) { bool isGrounded = !player.GetField <bool>("mayThrust"); bool hasThrusted = player.GetField <bool>("hasThrustedForward"); int thrustsAvailable = player.GetField <int>("thrusterEnergy"); int lastThrustTime = player.GetField <int>("lastThrust"); int time = GSCFunctions.GetTime(); Vector3 movement = player.GetNormalizedMovement(); if (!isGrounded && !hasThrusted && thrustsAvailable > 0 && time > (lastThrustTime + 200) && player.IsAlive && movement.X > 0) { player.SetField("hasThrustedForward", true); player.SetPerk("specialty_automantle", true, false); player.SetField("thrusterEnergy", player.GetField <int>("thrusterEnergy") - 1); if (player.HasPerk("specialty_quieter")) { player.PlaySound("bullet_mega_flesh"); } else { player.PlaySound("weap_hind_rocket_fire"); } shThrustRadarBlip(player); Vector3 currentVel = player.GetVelocity(); Vector3 angles = player.GetPlayerAngles(); Vector3 forward = GSCFunctions.AnglesToForward(angles); //Log.Debug("X: {0}, Y: {1}, Z: {2}", forward.X, forward.Y, forward.Z); Vector3 newVel = new Vector3(currentVel.X + (forward.X * 250), currentVel.Y + (forward.Y * 250), currentVel.Z); player.SetVelocity(newVel); } else if (!hasThrusted && thrustsAvailable > 0 && time > (lastThrustTime + 200) && player.IsAlive && movement.Y != 0 && movement.X == 0)//Dodge { player.SetField("hasThrustedForward", true); player.SetPerk("specialty_automantle", true, false); player.SetField("thrusterEnergy", player.GetField <int>("thrusterEnergy") - 1); if (player.HasPerk("specialty_quieter")) { player.PlaySound("bullet_mega_flesh"); } else { player.PlaySound("weap_hind_rocket_fire"); } shThrustRadarBlip(player); Vector3 currentVel = player.GetVelocity(); Vector3 angles = player.GetPlayerAngles(); Vector3 right = GSCFunctions.AnglesToRight(angles); //Log.Debug("X: {0}, Y: {1}, Z: {2}", forward.X, forward.Y, forward.Z); Vector3 newVel; if (movement.Y > 0) { newVel = new Vector3(currentVel.X + (right.X * 300), currentVel.Y + (right.Y * 300), currentVel.Z); } else { newVel = new Vector3(currentVel.X + (-right.X * 300), currentVel.Y + (-right.Y * 300), currentVel.Z); } player.SetVelocity(newVel); player.SlideVelocity += newVel; AfterDelay(1000, () => player.SetField("hasThrustedForward", false)); } else if (!hasThrusted && thrustsAvailable == 0) { player.PlayLocalSound("weap_motiontracker_open_plr"); } }