public void Render(Perimeter worldSize) { skybox.Center = new TGCVector3(FastMath.Clamp(Camera.Position.X, worldSize.xMin + Radius, worldSize.xMax - Radius), skybox.Center.Y, FastMath.Clamp(Camera.Position.Z, worldSize.zMin + Radius, worldSize.zMax - Radius)); skybox.Render(); }
private TGCVector3 clampPickingResult(TGCVector3 v) { v.X = FastMath.Clamp(v.X, -BIG_VAL, BIG_VAL); v.Y = FastMath.Clamp(v.Y, -BIG_VAL, BIG_VAL); v.Z = FastMath.Clamp(v.Z, -BIG_VAL, BIG_VAL); return(v); }
public void play(int volume) { var clampedVolume = FastMath.Clamp(volume, (int)Volume.Min, (int)Volume.Max); this.sound.SoundBuffer.Volume = clampedVolume; this.sound.play(this.loop); }
private void propulsion(float elapsedTime) { if (GameInput._Speed.IsDown(Input) && this.Character.ActualStats.Oxygen > 0) { this.propulsionValue += elapsedTime * 12; this.GameState.character.UpdateStats(new Stats(-elapsedTime * 8, 0)); } else { this.propulsionValue -= elapsedTime * 8; } var maxValue = 6; var variation = (int)Volume.Min / maxValue; this.propulsionValue = FastMath.Clamp(this.propulsionValue, 1, maxValue); if (this.propulsionValue <= 1) { SoundManager.Stop(SoundManager.MotorSound); } else { SoundManager.Play(SoundManager.MotorSound, (int)Volume.Min - (int)Math.Ceiling(this.propulsionValue * variation)); } this.Camera.MovementSpeed = this.baseCameraSpeed * this.propulsionValue; }
private void Rotation() { Latitude -= -Input.XposRelative * Constants.ROTATION_SPEED; Longitude -= Input.YposRelative * Constants.ROTATION_SPEED; Longitude = FastMath.Clamp(Longitude, Constants.LIMIT_MIN, Constants.LIIMIT_MAX); CameraRotation = TGCMatrix.RotationX(Longitude) * TGCMatrix.RotationY(Latitude); }
public override void Update(Camera camera) { Mesh.Position = camera.LookAt + TGCVector3.TransformNormal(new TGCVector3(-10, -4, -9f), camera.cameraRotation); Mesh.Rotation = new TGCVector3( FastMath.QUARTER_PI * 0.05f + FastMath.Clamp(camera.updownRot, -FastMath.QUARTER_PI * 0.2f, FastMath.QUARTER_PI * 0.2f), camera.leftrightRot + FastMath.QUARTER_PI * 0.9f, -FastMath.QUARTER_PI * 1.4f + FastMath.Clamp(camera.updownRot, -FastMath.QUARTER_PI * 0.2f, FastMath.QUARTER_PI * 0.2f) ); }
public TGCMatrix CalculateCameraRotation() { if (ConsideringInput) { leftrightRot += Input.XposRelative * RotationSpeed; updownRot = FastMath.Clamp(updownRot - Input.YposRelative * RotationSpeed, -FastMath.PI_HALF, FastMath.PI_HALF); } return(TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot)); }
private void CalculateShoppingChance(float currentHour) { float minShoppingChanceEndHour = Math.Min(config.WakeUpHour, EarliestWakeUp); float maxShoppingChanceStartHour = Math.Max(config.WorkBegin, config.WakeUpHour); if (minShoppingChanceEndHour == maxShoppingChanceStartHour) { minShoppingChanceEndHour = FastMath.Clamp(maxShoppingChanceStartHour - 1f, 2f, maxShoppingChanceStartHour - 1f); } #if DEBUG uint oldChance = shoppingChances[(int)Citizen.AgeGroup.Adult]; #endif float chance; bool isNight; float maxShoppingChanceEndHour = Math.Max(config.GoToSleepHour, config.WorkEnd); if (currentHour < minShoppingChanceEndHour) { isNight = true; chance = NightShoppingChance; } else if (currentHour < maxShoppingChanceStartHour) { isNight = true; chance = NightShoppingChance + ((100u - NightShoppingChance) * (currentHour - minShoppingChanceEndHour) / (maxShoppingChanceStartHour - minShoppingChanceEndHour)); } else if (currentHour < maxShoppingChanceEndHour) { isNight = false; chance = 100; } else { isNight = true; chance = NightShoppingChance + ((100u - NightShoppingChance) * (24f - currentHour) / (24f - maxShoppingChanceEndHour)); } uint roundedChance = (uint)Math.Round(chance); shoppingChances[(int)Citizen.AgeGroup.Child] = isNight ? 0u : roundedChance; shoppingChances[(int)Citizen.AgeGroup.Teen] = isNight ? 0u : roundedChance; shoppingChances[(int)Citizen.AgeGroup.Young] = roundedChance; shoppingChances[(int)Citizen.AgeGroup.Adult] = roundedChance; shoppingChances[(int)Citizen.AgeGroup.Senior] = isNight ? (uint)Math.Round(chance * 0.1f) : roundedChance; #if DEBUG if (oldChance != roundedChance) { Log.Debug(LogCategory.Simulation, $"SHOPPING CHANCES for {timeInfo.Now}: child = {shoppingChances[0]}, teen = {shoppingChances[1]}, young = {shoppingChances[2]}, adult = {shoppingChances[3]}, senior = {shoppingChances[4]}"); } #endif }
/// <summary>Gets an estimated travel time (in hours) between two specified buildings.</summary> /// <param name="building1">The ID of the first building.</param> /// <param name="building2">The ID of the second building.</param> /// <returns>An estimated travel time in hours.</returns> public float GetEstimatedTravelTime(ushort building1, ushort building2) { if (building1 == 0 || building2 == 0 || building1 == building2) { return(0); } float distance = buildingManager.GetDistanceBetweenBuildings(building1, building2); return(FastMath.Clamp(distance / OnTheWayDistancePerHour, MinTravelTime, MaxTravelTime)); }
public virtual void Update() { //if (!colisionaEnY) //{ VelocidadY = FastMath.Clamp(VelocidadY + Gravedad * Context.ElapsedTime, VelocidadTerminal, -VelocidadTerminal); movimiento += new TGCVector3(0, FastMath.Clamp(VelocidadY * Context.ElapsedTime, -DesplazamientoMaximoY, DesplazamientoMaximoY), 0); moving = true; //} //this.colisionaEnY = false; }
/// <summary>Validates this instance and corrects possible invalid property values.</summary> public void Validate() { MaxWaitingPassengersBus = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersBus, 10, 500), 5); MaxWaitingPassengersTouristBus = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersTouristBus, 10, 500), 5); MaxWaitingPassengersEvacuationBus = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersEvacuationBus, 10, 500), 5); MaxWaitingPassengersTram = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersTram, 10, 500), 5); MaxWaitingPassengersMetro = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersMetro, 50, 2000), 25); MaxWaitingPassengersTrain = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersTrain, 50, 2000), 25); MaxWaitingPassengersMonorail = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersMonorail, 50, 2000), 25); MaxWaitingPassengersAirplane = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersAirplane, 50, 1000), 10); MaxWaitingPassengersShip = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersShip, 50, 1000), 10); MaxWaitingPassengersCableCar = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersCableCar, 10, 500), 5); MaxWaitingPassengersHotAirBalloon = RoundToNearest(FastMath.Clamp(MaxWaitingPassengersHotAirBalloon, 10, 500), 5); }
public override void Update(float ElapsedTime) { var desplazamiento = Velocidad; float dist; desplazamiento *= ElapsedTime; if (!Sentido) { desplazamiento *= -1f; } if (EjeX) { dist = Mesh.Position.X - Pos.X; } else if (EjeY) { dist = Mesh.Position.Y - Pos.Y; } else { dist = Mesh.Position.Z - Pos.Z; } //var dist = EjeX ? Mesh.Position.X - Pos.X : Mesh.Position.Z - Pos.Z; desplazamiento = FastMath.Clamp(desplazamiento, -Rango - dist, Rango - dist); TGCVector3 movimiento; if (EjeX) { movimiento = new TGCVector3(desplazamiento, 0, 0); } else if (EjeY) { movimiento = new TGCVector3(0, desplazamiento, 0); } else { movimiento = new TGCVector3(0, 0, desplazamiento); } //var movimiento = EjeX ? new TGCVector3(desplazamiento, 0, 0) : new TGCVector3(0, 0, desplazamiento); var old = Mesh.Position; Mesh.Position += movimiento; if (FastMath.Abs(EjeX ? Mesh.Position.X - Pos.X : EjeY?Mesh.Position.Y - Pos.Y: Mesh.Position.Z - Pos.Z) >= Rango) { Sentido = !Sentido; } Delta = movimiento; }
/// <summary>Gets an estimated travel time (in hours) between two specified buildings.</summary> /// <param name="building1">The ID of the first building.</param> /// <param name="building2">The ID of the second building.</param> /// <returns>An estimated travel time in hours.</returns> public float GetEstimatedTravelTime(ushort building1, ushort building2) { if (building1 == 0 || building2 == 0 || building1 == building2) { return(0); } float distance = buildingManager.GetDistanceBetweenBuildings(building1, building2); if (distance == 0) { return(MinTravelTime); } return(FastMath.Clamp(distance / averageCitizenSpeed, MinTravelTime, MaxTravelTime)); }
private void UpdateRotation(float ElapsedTime) { cam_angles += new TGCVector2(Input.YposRelative, Input.XposRelative) * sensitivity * ElapsedTime; cam_angles.X = FastMath.Clamp(cam_angles.X, -CAMERA_MAX_X_ANGLE, CAMERA_MAX_X_ANGLE); cam_angles.Y = cam_angles.Y > 2 * FastMath.PI || cam_angles.Y < -2 * FastMath.PI ? 0 : cam_angles.Y; TGCQuaternion rotationY = TGCQuaternion.RotationAxis(new TGCVector3(0f, 1f, 0f), cam_angles.Y); TGCQuaternion rotationX = TGCQuaternion.RotationAxis(new TGCVector3(1f, 0f, 0f), -cam_angles.X); rotation = rotationX * rotationY; var init_offset = new TGCVector3(0f, 0f, 1f); TGCMatrix camera_m = TGCMatrix.Translation(init_offset) * TGCMatrix.RotationTGCQuaternion(rotation) * TGCMatrix.Translation(Player.Position()); TGCVector3 pos = new TGCVector3(camera_m.M41, camera_m.M42, camera_m.M43); Camara.SetCamera(pos, Player.Position()); }
/// <summary>Validates this instance and corrects possible invalid property values.</summary> public void Validate() { WakeUpHour = FastMath.Clamp(WakeUpHour, 4f, 8f); GoToSleepHour = FastMath.Clamp(GoToSleepHour, 20f, 23.75f); DayTimeSpeed = FastMath.Clamp(DayTimeSpeed, 1u, 6u); NightTimeSpeed = FastMath.Clamp(NightTimeSpeed, 1u, 6u); VirtualCitizens = (VirtualCitizensLevel)FastMath.Clamp((int)VirtualCitizens, (int)VirtualCitizensLevel.None, (int)VirtualCitizensLevel.Vanilla); ConstructionSpeed = FastMath.Clamp(ConstructionSpeed, 1u, 100u); SwitchOffLightsMaxHeight = FastMath.Clamp(SwitchOffLightsMaxHeight, 0f, 100f); SecondShiftQuota = FastMath.Clamp(SecondShiftQuota, 1u, 25u); NightShiftQuota = FastMath.Clamp(NightShiftQuota, 1u, 25u); LunchQuota = FastMath.Clamp(LunchQuota, 0u, 100u); LocalBuildingSearchQuota = FastMath.Clamp(LocalBuildingSearchQuota, 0u, 100u); ShoppingForFunQuota = FastMath.Clamp(ShoppingForFunQuota, 0u, 50u); OnTimeQuota = FastMath.Clamp(OnTimeQuota, 0u, 100u); EarliestHourEventStartWeekday = FastMath.Clamp(EarliestHourEventStartWeekday, 0f, 23.5f); LatestHourEventStartWeekday = FastMath.Clamp(LatestHourEventStartWeekday, 0f, 23.5f); if (LatestHourEventStartWeekday < EarliestHourEventStartWeekday) { LatestHourEventStartWeekday = EarliestHourEventStartWeekday; } EarliestHourEventStartWeekend = FastMath.Clamp(EarliestHourEventStartWeekend, 0f, 23.5f); LatestHourEventStartWeekend = FastMath.Clamp(LatestHourEventStartWeekend, 0f, 23.5f); if (LatestHourEventStartWeekend < EarliestHourEventStartWeekend) { LatestHourEventStartWeekend = EarliestHourEventStartWeekend; } WorkBegin = FastMath.Clamp(WorkBegin, 4f, 11f); WorkEnd = FastMath.Clamp(WorkEnd, 12f, 20f); LunchBegin = FastMath.Clamp(LunchBegin, 11f, 13f); LunchEnd = FastMath.Clamp(LunchEnd, 13f, 15f); SchoolBegin = FastMath.Clamp(SchoolBegin, 4f, 10f); SchoolEnd = FastMath.Clamp(SchoolEnd, 11f, 16f); MaxOvertime = FastMath.Clamp(MaxOvertime, 0f, 4f); MaxVacationLength = FastMath.Clamp(MaxVacationLength, 0u, 7u); }
private void CalculateDefaultChances(float currentHour, uint weekdayModifier) { float latestGoingOutHour = config.GoToSleepHour - simulationCycle; bool isDayTime = currentHour >= config.WakeUpHour && currentHour < latestGoingOutHour; float timeModifier; if (isDayTime) { timeModifier = FastMath.Clamp(currentHour - config.WakeUpHour, 0, 4f); } else { float nightDuration = 24f - (latestGoingOutHour - config.WakeUpHour); float relativeHour = currentHour - latestGoingOutHour; if (relativeHour < 0) { relativeHour += 24f; } timeModifier = 3f / nightDuration * (nightDuration - relativeHour); } float chance = (timeModifier + weekdayModifier) * timeModifier; uint roundedChance = (uint)Math.Round(chance); #if DEBUG bool dump = defaultChances[(int)Citizen.AgeGroup.Adult] != roundedChance; #endif defaultChances[(int)Citizen.AgeGroup.Child] = isDayTime ? roundedChance : 0; defaultChances[(int)Citizen.AgeGroup.Teen] = isDayTime ? (uint)Math.Round(chance * 0.9f) : 0; defaultChances[(int)Citizen.AgeGroup.Young] = (uint)Math.Round(chance * 1.3f); defaultChances[(int)Citizen.AgeGroup.Adult] = roundedChance; defaultChances[(int)Citizen.AgeGroup.Senior] = isDayTime ? (uint)Math.Round(chance * 0.8f) : 0; #if DEBUG if (dump) { Log.Debug(LogCategory.Simulation, $"DEFAULT GOING OUT CHANCES for {timeInfo.Now}: child = {defaultChances[0]}, teen = {defaultChances[1]}, young = {defaultChances[2]}, adult = {defaultChances[3]}, senior = {defaultChances[4]}"); } #endif }
private void CheckColisionY(float ElapsedTime) { TgcBoundingAxisAlignBox Collider = Env.Escenario.ColisionY(Mesh.BoundingBox); if (Collider != null) { Mesh.Position = new TGCVector3(Mesh.Position.X, FastMath.Clamp(Mesh.Position.Y, Collider.PMax.Y, Collider.PMax.Y + 2), Mesh.Position.Z); CanJump = VelocidadY < 0; } if (TipoColisionActual == TiposColision.Pozo) { Pozo(); } else if (TipoColisionActual == TiposColision.Caja) { Mesh.Move(posicionPlataforma); } else if (TipoColisionActual == TiposColision.Techo) { Mesh.Position = new TGCVector3(oldPos.X, posicionPlataforma.Y, oldPos.Z); VelocidadY = 0; } }
public void Update() { var velocidadCaminar = 300f; var velocidadSalto = 100f; var velocidadRotacion = 120f; vectorDesplazamiento = TGCVector3.Empty; vectorColision = TGCVector3.Empty; //Calcular proxima posicion de personaje segun Input var Input = GModel.Input; var moveForward = 0f; var moveJump = 0f; float rotate = 0; var moving = false; var rotating = false; var lastPos = personaje.Position; desplazamientoDePlataforma = TGCVector3.Empty; //Adelante if (Input.keyDown(Key.W)) { moveForward = velocidadCaminar * GModel.ElapsedTime; moving = true; } //Atras if (Input.keyDown(Key.S)) { moveForward = -velocidadCaminar * GModel.ElapsedTime; moving = true; } //Derecha if (Input.keyDown(Key.D)) { rotate = velocidadRotacion; rotating = true; } //Izquierda if (Input.keyDown(Key.A)) { rotate = -velocidadRotacion; rotating = true; } //Si hubo rotacion if (rotating) { //Rotar personaje y la camara, hay que multiplicarlo por el tiempo transcurrido para no atarse a la velocidad el hardware var rotAngle = FastMath.ToRad(rotate * GModel.ElapsedTime); matrizRotacionPersonajeY *= TGCMatrix.RotationY(rotAngle); GModel.camaraInterna.rotateY(rotAngle); anguloDeRotacion += rotAngle; //Ajustar la matriz de rotacion segun el angulo de rotacion (sobre el sentido de la orientacion) //Lo que se desplaza en cada eje depende del angulo de rotacion //Cada componente podria separarse en funcion del seno y coseno orientacion.X = FastMath.Sin(anguloDeRotacion); orientacion.Z = FastMath.Cos(anguloDeRotacion); } if (moving) { //Activar animacion de caminando personaje.playAnimation("Caminando", true); //Ajustar el vector desplazamiento en base a lo que se movio y la orientacion que tiene vectorDesplazamiento.X += moveForward * orientacion.X; vectorDesplazamiento.Z += moveForward * orientacion.Z; } //Si no se esta moviendo, activar animacion de Parado else { personaje.playAnimation("Parado", true); } //----------Salto //Por el momento solamente parece que flota if (Input.keyDown(Key.Space) /*&& colliderY != null*/) { moveJump = velocidadSalto * GModel.ElapsedTime; vectorDesplazamiento.Y += moveJump; } //---------prueba gravedad---------- vectorDesplazamiento.Y += FastMath.Clamp(gravedad * GModel.ElapsedTime, -10, 10); //--------Colision con el piso a nivel triangulo TgcBoundingAxisAlignBox colliderPlano = null; foreach (var obstaculo in GModel.escenario1.getPiso()) { if (TgcCollisionUtils.testAABBAABB(personaje.BoundingBox, obstaculo.BoundingBox)) { colliderPlano = obstaculo.BoundingBox; //No le afecta la gravedad si está en el piso vectorDesplazamiento.Y -= FastMath.Clamp(gravedad * GModel.ElapsedTime, -10, 10); break; } } this.posicion = posicion + vectorDesplazamiento; //Reseteo el vector desplazamiento una vez que lo sume vectorDesplazamiento = TGCVector3.Empty; //---------Colisiones objetos-------------------------- var collide = false; foreach (var obstaculo in GModel.escenario1.getAABBDelEscenario() /*GModel.escenario1.getPared1()*/) { if (TgcCollisionUtils.testAABBAABB(personaje.BoundingBox, obstaculo)) { collide = true; collider = obstaculo; break; } } //Una buena idea seria diferenciar las plataformas del resto de los objetos foreach (var plataforma in GModel.escenario1.getPlataformasDelEscenario()) { if (TgcCollisionUtils.testAABBAABB(personaje.BoundingBox, plataforma)) { collide = true; collider = plataforma; //Pensamos en calcular cuanto se desplaza la plataforma y mandarselo al personaje para que se muevan juntos //Todavia no funciona como esperamos desplazamientoDePlataforma = GModel.escenario1.desplazamientoDePlataforma(collider); break; } } if (collide) { var movementRay = lastPos - posicion; //Cuando choca con algo que se ponga rojo, nos sirve para probar collider.setRenderColor(Color.Red); var rs = TGCVector3.Empty; if (((personaje.BoundingBox.PMax.X > collider.PMax.X && movementRay.X > 0) || (personaje.BoundingBox.PMin.X < collider.PMin.X && movementRay.X < 0)) && ((personaje.BoundingBox.PMax.Z > collider.PMax.Z && movementRay.Z > 0) || (personaje.BoundingBox.PMin.Z < collider.PMin.Z && movementRay.Z < 0)) && ((personaje.BoundingBox.PMax.Y > collider.PMax.Y && movementRay.Y > 0) || (personaje.BoundingBox.PMin.Y < collider.PMin.Y && movementRay.Y < 0))) { if (personaje.Position.X > collider.PMin.X && personaje.Position.X < collider.PMax.X) { //El personaje esta contenido en el bounding X rs = new TGCVector3(movementRay.X, movementRay.Y, 0); } if (personaje.Position.Z > collider.PMin.Z && personaje.Position.Z < collider.PMax.Z) { //El personaje esta contenido en el bounding Z rs = new TGCVector3(0, movementRay.Y, movementRay.Z); } if (personaje.Position.Y > collider.PMin.Y && personaje.Position.Y < collider.PMax.Y) { //El personaje esta contenido en el bounding Y rs = new TGCVector3(movementRay.X, 0, movementRay.Z); } } else { if ((personaje.BoundingBox.PMax.X > collider.PMax.X && movementRay.X > 0) || (personaje.BoundingBox.PMin.X < collider.PMin.X && movementRay.X < 0)) { rs = new TGCVector3(0, movementRay.Y, movementRay.Z); } if ((personaje.BoundingBox.PMax.Z > collider.PMax.Z && movementRay.Z > 0) || (personaje.BoundingBox.PMin.Z < collider.PMin.Z && movementRay.Z < 0)) { rs = new TGCVector3(movementRay.X, movementRay.Y, 0); } if ((personaje.BoundingBox.PMax.Y > collider.PMax.Y && movementRay.Y > 0) || (personaje.BoundingBox.PMin.Y < collider.PMin.Y && movementRay.Y < 0)) { //Si esta sobre un plano XZ tampoco deberia afectarle la gravedad vectorDesplazamiento.Y -= FastMath.Clamp(gravedad * GModel.ElapsedTime, -10, 10); rs = new TGCVector3(movementRay.X, 0, movementRay.Z); } } //El vector rs actua como "freno" al movimiento del personaje //Le "descuento" la gravedad si es que colisiona con el plano XZ personaje.Position = lastPos - rs + new TGCVector3(0, vectorDesplazamiento.Y, 0); posicion = personaje.Position; } personaje.Position = posicion; //Una forma de reiniciar, que se active con R o cuando el personaje muere //Por ahora el personaje muere solamente si su coordenada en Y es inferior a un valor determinado if (Input.keyDown(Key.R) || this.estaMuerto()) { posicion = this.checkpoint; } matrizPosicionamientoPersonaje = TGCMatrix.Translation(posicion /*+ desplazamientoDePlataforma*/); GModel.camaraInterna.Target = GModel.tgcPersonaje.getPosicion(); }
public static void Update(TgcD3dInput Input) { bool up = Input.keyDown(Key.Up); bool down = Input.keyDown(Key.Down); bool left = Input.keyDown(Key.Left); bool right = Input.keyDown(Key.Right); bool enter = Input.keyDown(Key.Return); if (up) { up = false; presionoUp = true; } else { if (presionoUp) { up = true; presionoUp = false; } } if (down) { down = false; presionoDown = true; } else { if (presionoDown) { down = true; presionoDown = false; } } if (left) { left = false; presionoLeft = true; } else { if (presionoLeft) { left = true; presionoLeft = false; } } if (right) { right = false; presionoRight = true; } else { if (presionoRight) { right = true; presionoRight = false; } } if (enter) { enter = false; presionoEnter = true; } else { if (presionoEnter) { enter = true; presionoEnter = false; } } bool anyKey = up || down || left || right || enter; //Reset effect when any key is pressed if (anyKey) { SelectedText.Color = Color.White; } ///// si tocas enter volver al menu //Update selection var if (CurrentStatus == Status.Gameplay) { var health = Player.Health(); var maxHealth = Player.MaxHealth(); var oxygen = Player.Oxygen(); var maxOxygen = Player.MaxOxygen(); HealthBar.Scaling = new TGCVector2(health / maxHealth, 1); OxygenBar.Scaling = new TGCVector2(oxygen / maxOxygen, 1); } else if (CurrentStatus == Status.MainMenu) { if (up) { if (SelectedText == Start) { SelectedText = Exit; } else if (SelectedText == Instruccion) { SelectedText = Start; } else if (SelectedText == Exit) { SelectedText = Instruccion; } } else if (down) { if (SelectedText == Start) { SelectedText = Instruccion; } else if (SelectedText == Instruccion) { SelectedText = Exit; } else if (SelectedText == Exit) { SelectedText = Start; } } else if (enter) { if (SelectedText == Start) { ChangeStatus(Status.Gameplay); } else if (SelectedText == Exit) { Application.Exit(); } else if (SelectedText == Instruccion) { CurrentStatus = Status.Instructions; } } } else if (CurrentStatus == Status.Instructions) { if (enter) { CurrentStatus = Status.MainMenu; } } else if (CurrentStatus == Status.Inventory || CurrentStatus == Status.Crafting) { if (LastStatus != Status.Inventory && LastStatus != Status.Crafting) { UpdateIconSprites(); } CraftingItems[SelectedItemIndex].background.Color = Color.CadetBlue; if (CurrentStatus == Status.Crafting) { //Change selected item if (left) { SelectedItemIndex--; } else if (right) { SelectedItemIndex++; } if (left || right) { sonido.play(); } SelectedItemIndex = FastMath.Clamp(SelectedItemIndex, 0, MAX_CRAFTING_ITEMS - 1); CraftingItems[SelectedItemIndex].background.Color = Color.Orange; //Check for crafting if (enter) { bool SelectedItemExists = SelectedItemIndex < Inventory.Instance().GetCraftings().Count; if (SelectedItemExists) { var SelectedItem = Inventory.Instance().GetCraftings()[SelectedItemIndex]; if (SelectedItem.EstoyHabilitado()) { sonido.play(); SelectedItem.Craftear(); UpdateIconSprites(); } } } } } else if (CurrentStatus == Status.GameOver || CurrentStatus == Status.Win) { if (enter) { Application.Exit(); } } //Update last status so it doesn't UpdateIconSprites() multiple times LastStatus = CurrentStatus; }
public void SetTime(float value) => Time = FastMath.Clamp(Time + value, 0, 10);
public override void Update() { Mesh.BoundingBox = Mesh.Animations["Walk"].BoundingBox; var ElapsedTime = Env.ElapsedTime; var Input = Env.Input; float VelocidadAdelante = 0f; var Diff = Env.NuevaCamara.LookAt - Env.NuevaCamara.Position; Diff.Y = 0; TipoColisionActual = TiposColision.SinColision; if (CanJump && Input.keyPressed(Key.Space)) { VelocidadY = VelocidadSalto; CanJump = false; } D3DDevice.Instance.Device.RenderState.FillMode = Input.keyDown(Key.F4) ? FillMode.WireFrame : FillMode.Solid; if ((Input.keyDown(Key.W) || Input.keyDown(Key.UpArrow)) && Input.keyDown(Key.LeftShift)) { VelocidadAdelante += VelocidadMovimiento * 2; } else if (Input.keyDown(Key.W) || Input.keyDown(Key.UpArrow)) { VelocidadAdelante += VelocidadMovimiento; } if (Input.keyDown(Key.S) || Input.keyDown(Key.DownArrow)) { VelocidadAdelante -= VelocidadMovimiento; } if (Input.keyDown(Key.F8)) { VelocidadMovimiento += 10 * ElapsedTime; } if (Input.keyDown(Key.F9)) { VelocidadMovimiento -= 10 * ElapsedTime; } if (Input.keyDown(Key.M)) { Env.CambiarEscenario("Menu"); } if (Input.keyPressed(Key.G)) { if (!modoGod) { VelocidadMovimiento = 250; VelocidadSalto = 250; VelocidadTerminal = -150; modoGod = true; } else { restaurarVelocidades(); } } if (Input.keyPressed(Key.H)) { ShowHelp = !ShowHelp; } if (Input.keyDown(Key.F10)) { VelocidadSalto += 10 * ElapsedTime; VelocidadTerminal -= 2 * ElapsedTime; } if (Input.keyDown(Key.F11)) { VelocidadSalto -= 10 * ElapsedTime; VelocidadTerminal += 2 * ElapsedTime; } Env.NuevaCamara.keyboardMovement = 0; if (Input.keyDown(Key.D) || Input.keyDown(Key.RightArrow)) { Env.NuevaCamara.keyboardMovement += 1; } if (Input.keyDown(Key.A) || Input.keyDown(Key.LeftArrow)) { Env.NuevaCamara.keyboardMovement -= 1; } if (Input.keyDown(Key.R)) { Mesh.Position = new TGCVector3(0, 1, 0); } var versorAdelante = TGCVector3.Normalize(Diff); VelocidadY = FastMath.Clamp(VelocidadY + Gravedad * ElapsedTime, VelocidadTerminal, -VelocidadTerminal); var LastPos = Mesh.Position; // Colision en Y oldPos = Mesh.Position; Mesh.Position += new TGCVector3(0, FastMath.Clamp(VelocidadY * ElapsedTime, -DesplazamientoMaximoY, DesplazamientoMaximoY), 0); CheckColisionY(ElapsedTime); if (UltimoTipoColision == TiposColision.PisoResbaloso) { VelocidadAdelante += ultimoDesplazamientoAdelante; } else { ultimoDesplazamientoAdelante = 0; } MoveXZ(versorAdelante * FastMath.Clamp(VelocidadAdelante * ElapsedTime, -DesplazamientoMaximoXZ, DesplazamientoMaximoXZ)); UltimoTipoColision = TipoColisionActual; ultimoDesplazamientoAdelante += VelocidadAdelante * ElapsedTime; updateAnimation = true; if (Mesh.Position.Y != LastPos.Y) { SetAnimation("Jump", false); } else if (Input.keyDown(Key.LeftShift) || Input.keyDown(Key.RightShift)) { SetAnimation("Run"); updateAnimation = VelocidadAdelante != 0; emitter.Position = Mesh.Position; } else if (Input.keyDown(Key.C)) { SetAnimation("CrouchWalk"); updateAnimation = VelocidadAdelante != 0; } else if (VelocidadAdelante != 0) { SetAnimation("Walk"); } else { SetAnimation("StandBy"); } Env.NuevaCamara.Target = Mesh.Position; Mesh.Rotation = new TGCVector3(0, Env.NuevaCamara.rotY + FastMath.PI, 0); if (updateAnimation) { Mesh.updateAnimation(ElapsedTime); } emitter.Position = Mesh.Position; }
protected void AddHealth(int quantity) { health = FastMath.Clamp(health + quantity, 0, maxHealth); }
private void UpdateLife(float value) => Life = FastMath.Clamp(Life + value, Constants.LIFE_MIN, Constants.LIFE_MAX);