public void ImpactBON(Vector2 direction, ImpactBON_SO motionData, bool flipGradient = false) { float radiens = -Mathf.PI * motionData.gradient / 2 * (flipGradient?-1:1); Vector2 calculatedDir = GTM.CalculateRotatedDirection(direction, radiens); _rigidbody.AddForce(calculatedDir * motionData.thrust, ForceMode2D.Impulse); }
public LightSensorSampler(GTM.GHIElectronics.LightSensor lightSensor, SamplerBag samplers) { _lightSensor = lightSensor; _lightSensorPercentageSampler = new DoubleSampler(SampleLightSensorPercentage, "light_sensor_percentage"); samplers.Add(_lightSensorPercentageSampler); _lightSensorVoltageSampler = new DoubleSampler(SampleLightSensorVoltage, "light_sensor_voltage"); samplers.Add(_lightSensorVoltageSampler); }
public ButtonSampler(GTM.GHIElectronics.Button button, SamplerBag samplers) { _buttonPressedSampler = new LongSampler(null, "button_pressed"); samplers.Add(_buttonPressedSampler); _buttonReleasedSampler = new LongSampler(null, "button_released"); samplers.Add(_buttonReleasedSampler); button.ButtonPressed += new GTM.GHIElectronics.Button.ButtonEventHandler(button_ButtonPressed); button.ButtonReleased += new GTM.GHIElectronics.Button.ButtonEventHandler(button_ButtonReleased); }
public void Attack(Vector2 __direction) { if (_inCoolDown || _isFreezing) { return; } #region Hitbox Position Vector2 hitBoxPosition = __direction.normalized * _data.stretch; hitBoxPosition.x += _transform.position.x + _data.offset.x; hitBoxPosition.y += _transform.position.y + _data.offset.y; #endregion #region Get Valid Target List <GameObject> validTargets = new List <GameObject>(); if (!_data.atkMultiple) // attack single { List <GameObject> filteredTargets = new List <GameObject>(); // get all the targets in hitbox List <GameObject> targets = new List <GameObject>(); foreach (var targetCollider in Physics2D.OverlapCircleAll(hitBoxPosition, _data.radius, _data.targetLayer)) { targets.Add(targetCollider.gameObject); } // filter out targets which is blocked foreach (var target in targets) { Vector2 direction = new Vector2(); direction.x = target.transform.position.x - hitBoxPosition.x; direction.y = target.transform.position.y - hitBoxPosition.y; RaycastHit2D hit2D = Physics2D.Raycast(_data.damageFromCentreOfHitBox ? hitBoxPosition : (Vector2)_attacker.transform.position, direction.normalized, Vector2.Distance(hitBoxPosition, target.transform.position), _data.blockingLayer); if (!hit2D) { filteredTargets.Add(target); } } validTargets.Add(GTM.GetClosestGameObject(filteredTargets, _data.damageFromCentreOfHitBox ? hitBoxPosition : (Vector2)_attacker.transform.position)); } else // attack multiple { // get all the data List <GameObject> targets = new List <GameObject>(); foreach (var targetCollider in Physics2D.OverlapCircleAll(hitBoxPosition, _data.radius, _data.targetLayer)) { targets.Add(targetCollider.gameObject); } // get target that is not blocked foreach (var target in targets) { Vector2 direction = new Vector2(); direction.x = target.transform.position.x - hitBoxPosition.x; direction.y = target.transform.position.y - hitBoxPosition.y; RaycastHit2D hit2D = Physics2D.Raycast(_data.damageFromCentreOfHitBox ? hitBoxPosition : (Vector2)_attacker.transform.position, direction.normalized, Vector2.Distance(hitBoxPosition, target.transform.position), _data.blockingLayer); if (!hit2D) { validTargets.Add(target); } } } #endregion #region Apply Attack // apply attack foreach (var target in validTargets) { try { #region Apply Damage if (target.GetComponent <HealthSystem>()) { HealthSystem targetHealth = target.GetComponent <HealthSystem>(); if (_data.reduceHealthOnly) { targetHealth.health.ReduceHealth(_data.damage); } else { Damage damageData = new Damage(_data.damage, _attacker, new Vector2(target.transform.position.x - hitBoxPosition.x, target.transform.position.y - hitBoxPosition.y)); targetHealth.health.Damage(damageData); } } else { StaticHealthSystem targetHealth = target.GetComponent <StaticHealthSystem>(); if (_data.reduceHealthOnly) { targetHealth.health.ReduceHealth(_data.damage); } else { Damage damageData = new Damage(_data.damage, _attacker, new Vector2(target.transform.position.x - hitBoxPosition.x, target.transform.position.y - hitBoxPosition.y)); targetHealth.health.Damage(damageData); } } #endregion } catch (System.Exception) { Debug.LogError(string.Format("Enemy '{0}' is do not attach Health System script", target.name)); } #region Debug // WARNING: POORLY DESIGNED CODE Debug.DrawLine(_data.damageFromCentreOfHitBox ? hitBoxPosition : (Vector2)_attacker.transform.position, target.transform.position, Color.red, 3f); #endregion } #endregion // start cooldown StartCoolDown(); #region Debug // WARNING: POORLY DESIGN CODE (but it is for debugging so don't worry) if (_debugSphere == null) { _debugSphere = new GizSphereData(hitBoxPosition, _data.radius, Color.red); } else { _debugSphere.ChangePosition(hitBoxPosition); _debugSphere.ChangeRadius(_data.radius); } #endregion }
void button_ButtonReleased(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state) { _buttonReleasedSampler.Sample(1); }
void _barometer_MeasurementComplete(GTM.Seeed.Barometer sender, GTM.Seeed.Barometer.SensorData sensorData) { _pressureSampler.Sample(sensorData.Pressure); _temperatureSampler.Sample(sensorData.Temperature); }
public BarometerSampler(GTM.Seeed.Barometer barometer, SamplerBag samplers) { _barometer = barometer; _pressureSampler = new DoubleSampler(null, "barometer_pressure"); samplers.Add(_pressureSampler); _temperatureSampler = new DoubleSampler(null, "barometer_temperature"); samplers.Add(_temperatureSampler); _barometer.MeasurementComplete += new GTM.Seeed.Barometer.MeasurementCompleteEventHandler(_barometer_MeasurementComplete); }
void _temperatureHumidity_MeasurementComplete(GTM.Seeed.TemperatureHumidity sender, double temperature, double relativeHumidity) { _temperatureSampler.Sample(temperature); _humiditySampler.Sample(relativeHumidity); }