public void Initialize(Vector2 position) { base.Initialize(position); SetCollisionMaskBit(1, true); sprite.Frames = ResourceLoader.Load("res://entities/player/Player.tres") as SpriteFrames; sprite.Play("default"); ChangeState(state); var hurtArea = new Area2D(); var hurtCollider = new CollisionShape2D(); var hurtBoxShape = new RectangleShape2D(); hurtArea.SetCollisionLayerBit(19, true); hurtArea.SetCollisionLayerBit(0, false); hurtArea.CollisionMask = 0; hurtArea.Name = "HurtBox"; hurtBoxShape.Extents = new Vector2(2f, 4f); hurtCollider.Shape = hurtBoxShape; hurtArea.AddChild(hurtCollider); hurtArea.Connect("body_entered", this, "OnTouchedByEnemy"); AddChild(hurtArea); Texture gradient = ResourceLoader.Load("res://assets/gradients/radial.png") as Texture; _light.Texture = gradient; _light.Scale = _baseLightScale; _light.Color = new Color(1f, 1f, 1f, .3f); AddChild(_light); AddChild(_lightTween); AddToGroup("Players"); }
public override void Initialize(Vector2 position, int size = 8) { base.Initialize(Position, size: size); SetCollisionMaskBit(1, true); CollisionLayer = 0; CollisionShape2D hurtCollider = new CollisionShape2D(); RectangleShape2D hurtBoxShape = new RectangleShape2D(); _hurtArea.SetCollisionLayerBit(0, false); _hurtArea.SetCollisionLayerBit(2, true); _hurtArea.SetCollisionMaskBit(19, true); _hurtArea.SetCollisionMaskBit(0, false); _hurtArea.Name = "HurtBox"; hurtBoxShape.Extents = new Vector2(size / 2f, size / 2f); hurtCollider.Shape = hurtBoxShape; _hurtArea.AddChild(hurtCollider); AddChild(_hurtArea); CollisionShape2D alertCollider = new CollisionShape2D(); CircleShape2D alertBoxShape = new CircleShape2D(); _alertArea.Name = "AlertCircle"; _alertArea.SetCollisionMaskBit(19, true); _alertArea.SetCollisionMaskBit(0, false); _alertArea.CollisionLayer = 0; alertBoxShape.Radius = 35; alertCollider.Shape = alertBoxShape; _alertArea.AddChild(alertCollider); AddChild(_alertArea); _alertArea.Connect("area_entered", this, "_OnPlayerEnter"); _hurtArea.Connect("area_entered", this, "_OnPlayerTouch"); AddToGroup("Enemies"); }
private Sprite CreatePoint(float x, float y) { Sprite newPoint = (Sprite)point.Instance(); newPoint.Position = new Vector2(x, y); plot.AddChild(newPoint); return(newPoint); }
public override void Initialize(Vector2 position, int size = 24) { base.Initialize(position, size: size); findTargetSfx.Stream = ResourceLoader.Load("res://assets/audio/boss_golem_find_target.wav") as AudioStreamSample; sprite.Frames = ResourceLoader.Load("res://entities/enemies/bosses/golem/Golem.tres") as SpriteFrames; ChangeState(EEnemyState.STATE_IDLE); MaxVelocity = 40f; // Overload material setup vent.ProcessMaterial = mat; vent.SpeedScale = 2; vent.Amount = 2500; vent.Emitting = false; mat.InitialVelocity = overloadRange; // Overload area setup Vector2[] points = { new Vector2(-10, -3), new Vector2(75, -80), new Vector2(110, -45), new Vector2(120, 0), new Vector2(110, 45), new Vector2(75, 80), new Vector2(-10, 3) }; polygon.Polygon = points; polygon.Disabled = true; overloadArea.CollisionLayer = 0; overloadArea.SetCollisionMaskBit(0, false); overloadArea.SetCollisionMaskBit(19, true); overloadArea.Connect("area_entered", this, "_OnPlayerEnter_OverloadVent"); lurchTimer.OneShot = true; lurchTimer.Connect("timeout", this, "FindLurchTarget"); tween.Connect("tween_completed", this, "OverloadVent"); overloadArea.AddChild(vent); overloadArea.AddChild(polygon); AddChild(overloadArea); AddChild(tween); AddChild(lurchTimer); AddChild(findTargetSfx); }
public override void _Ready() { _controllable = GetNode <Controllable>(".."); _sight = GetNode <Area2D>("Sight"); _sight.AddChild(new CollisionShape2D { Shape = new CircleShape2D { Radius = _controllable.SightRadius } }); }
public void AddStaticBodyCollider(Area2D prop) { var shape = prop.GetNode <CollisionShape2D>("Shape"); var body = new StaticBody2D(); body.AddChild(shape.Duplicate()); body.CollisionLayer = 1024; prop.AddChild(body); }
/// <summary> /// Parameters: /// - caller: The node creating this Collision. /// - callback: Method that will be called when the caller detects a collision with the given type. This method must have /// one parameter with type <T>. /// - area2DPath: Path to the caller's Area2D node that's detecting this collision. /// </summary> public Collision(Node caller, Action <T> callback, string area2DPath = "Area2D") { Area2D area2D = caller.GetNodeOrNull <Area2D>(area2DPath); if (area2D == null) { return; } Callback = callback; area2D.Connect("area_entered", this, nameof(OnCollision)); area2D.AddChild(this); }
private void OnAsteroidImpact(int asteroidId, Vector2 impactPoint, int explosionRadius) { var explosionArea = new Area2D(); var shape = new CircleShape2D(); shape.Radius = explosionRadius; var collision = new CollisionShape2D(); collision.Shape = shape; explosionArea.AddChild(collision); explosionArea.GlobalPosition = impactPoint; CallDeferred(nameof(ImpactDeferred), explosionArea); }
public override void _Ready() { base._Ready(); _base = GetNode <Sprite>("Base"); _tower = GetNode <Node2D>("Tower"); _trigger = GetNode <Area2D>("Trigger"); _firePoint = GetNode <Node2D>("Tower/FirePoint"); _bullet = ResourceLoader.Load <PackedScene>("res://src/Projectiles/Bullet.tscn"); _reloadElapsed = 0; _trigger.AddChild(CreateReadiusArea(_trigger.Position, Radius)); _trigger.Connect("body_entered", this, nameof(OnTriggerAdd)); _trigger.Connect("body_exited", this, nameof(OnTriggerRemove)); }
public Pyroblast(Vector2 _direction, Vector2 _pos, int _targetLayer) : base(_direction, _pos, _targetLayer) { maxPierces = 3; damage = 1000f; knockbackStrength = 200f; maxVelocity = 100; acceleration = 10; effectRadius = 30f; cooldown = 3f; Position = Position + direction * 15f; Rotate(GetAngleTo(Position + direction)); VisibilityNotifier2D onScreenNotifier = new VisibilityNotifier2D(); onScreenNotifier.Connect("screen_exited", this, "queue_free"); AddChild(onScreenNotifier); // Sprite sprite.Texture = spriteImage; AddChild(sprite); // Collider hitArea.SetCollisionMaskBit(targetLayer, true); AddChild(hitArea); CollisionShape2D shape = new CollisionShape2D(); shape.Transform = new Godot.Transform2D(0f, new Vector2(-1, 0f)); CircleShape2D circle = new CircleShape2D(); circle.Radius = 6; shape.Shape = circle; hitArea.AddChild(shape); hitArea.Connect("area_entered", this, "_OnHurtAreaEnter"); // Emitters explosionEmitter.Emitting = false; explosionEmitter.Amount = 300; explosionEmitter.Lifetime = 4; explosionEmitter.OneShot = true; explosionEmitter.SpeedScale = 2; explosionEmitter.Explosiveness = 1; AddChild(explosionEmitter); smokeTrailEmitter.Amount = 200; smokeTrailEmitter.Preprocess = 0.5f; smokeTrailEmitter.ProcessMaterial = smokeTrailMaterial; AddChild(smokeTrailEmitter); fireTrailEmitter.Amount = 200; fireTrailEmitter.Preprocess = 0.5f; fireTrailEmitter.SpeedScale = 1.5f; fireTrailEmitter.Explosiveness = .1f; fireTrailEmitter.Randomness = 1; fireTrailEmitter.ProcessMaterial = fireTrailMaterial; fireTrailEmitter.Transform = new Godot.Transform2D(0f, new Vector2(-1, 0f)); AddChild(fireTrailEmitter); // Timers explosionCompleteTimer.WaitTime = 1f; explosionCompleteTimer.OneShot = true; explosionCompleteTimer.Connect("timeout", this, "queue_free"); AddChild(explosionCompleteTimer); initialBoomVelocityTimer.WaitTime = 0.2f; initialBoomVelocityTimer.OneShot = true; initialBoomVelocityTimer.Connect("timeout", this, "_RemoveInitialBoomVelocity"); AddChild(initialBoomVelocityTimer); Scale = new Vector2(1.7f, 1.7f); }
public Fireball(Vector2 direction, Vector2 position, int targetLayer) : base(direction, position, targetLayer) { damage = 100f; knockbackStrength = 50f; Acceleration = 200; effectRadius = 30f; LifetimeTotal = 1f; Texture gradient = ResourceLoader.Load("res://assets/gradients/radial.png") as Texture; light.Texture = gradient; light.Scale = new Vector2(.1f, .1f); light.Color = new Color(1f, .7f, .7f, .2f); AddChild(light); VisibilityNotifier2D onScreenNotifier = new VisibilityNotifier2D(); onScreenNotifier.Connect("screen_exited", this, "queue_free"); AddChild(onScreenNotifier); Position = Position + Direction * 10f; // Sprite sprite.Texture = spriteImage; AddChild(sprite); // Collider hitArea.CollisionLayer = 0; hitArea.SetCollisionMaskBit(0, false); hitArea.SetCollisionMaskBit(targetLayer, true); AddChild(hitArea); CollisionShape2D shape = new CollisionShape2D(); shape.Transform = new Godot.Transform2D(0f, new Vector2(-1, 0f)); CircleShape2D circle = new CircleShape2D(); circle.Radius = 6; shape.Shape = circle; hitArea.AddChild(shape); hitArea.Connect("area_entered", this, "_OnHurtAreaEnter"); // Emitters explosionEmitter.ProcessMaterial = explosionMaterial; explosionEmitter.Emitting = false; explosionEmitter.Amount = 150; explosionEmitter.Lifetime = 4; explosionEmitter.OneShot = true; explosionEmitter.SpeedScale = 2; explosionEmitter.Explosiveness = 1; explosionEmitter.ZIndex = -100; AddChild(explosionEmitter); smokeTrailEmitter.Amount = 200; smokeTrailEmitter.Preprocess = 0.5f; smokeTrailEmitter.ProcessMaterial = smokeTrailMaterial; AddChild(smokeTrailEmitter); fireTrailEmitter.Amount = 100; fireTrailEmitter.Preprocess = 0.5f; fireTrailEmitter.SpeedScale = 1.5f; fireTrailEmitter.Explosiveness = .1f; fireTrailEmitter.Randomness = 1; fireTrailEmitter.ProcessMaterial = fireTrailMaterial; fireTrailEmitter.Transform = new Godot.Transform2D(0f, new Vector2(-1, 0f)); AddChild(fireTrailEmitter); // Timers Color targetColor = new Color(light.Color.r, light.Color.g, light.Color.b, light.Color.a * 2); Color targetColorNone = new Color(light.Color.r, light.Color.g, light.Color.b, 0); Vector2 targetScale = light.Scale * 3 * Mathf.Clamp((float)new Random().NextDouble(), .5f, 1f); onHitTween.InterpolateProperty(light, "color", light.Color, targetColor, .2f, easeType: Tween.EaseType.Out); onHitTween.InterpolateProperty(light, "color", targetColor, targetColorNone, .1f, easeType: Tween.EaseType.Out, delay: .2f); onHitTween.InterpolateProperty(light, "scale", light.Scale, targetScale, .1f); onHitTween.InterpolateProperty(explosionMaterial, "gravity", explosionMaterial.Gravity, default(Vector3), 0.1f, delay: .2f); onHitTween.InterpolateCallback(this, 1f, "queue_free"); AddChild(onHitTween); lifetime.Connect("timeout", this, nameof(Explode)); }