float dangerZonePositionModifier = 1.255f; // hardcoded number, how much the x position of the zone is divded public override void _Ready() { if (laneImg == null) { GD.PushError("You must set laneImg for Lane!"); GD.PrintStack(); GetTree().Quit(1); } TextureButton button = GetNode <TextureButton>("Button"); spawnPoint = button.RectGlobalPosition + new Vector2(70, 30); GetNode <Sprite>("Sprite").Texture = laneImg; Events.roundWon += OnRoundWon; Events.dinoDiedInstance += OnDinoDiedInstance; // we're an empty lane, don't allow deploys if (Curve.GetPointCount() == 0) { button.Hide(); return; } dangerZoneCollision = GetNode("DangerZone").GetNode <CollisionShape2D>("DangerZoneCollision"); var dangerBox = new RectangleShape2D(); // make a hitbox for the danger zone dangerZoneCollision.Shape = dangerBox; // divide by 1/2 since that's how extents work // divide x by 1/3 since we want it to be that big dangerBox.Extents = new Vector2(laneImg.GetSize().x / 2 / 3, laneImg.GetSize().y / 2 * GetNode <Sprite>("Sprite").Scale.y); dangerZoneCollision.Position = new Vector2(this.GlobalPosition.x / dangerZonePositionModifier, 0); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { _spawnArea = GetNode <CollisionShape2D>("SpawnArea/Area"); _shape = _spawnArea.Shape as RectangleShape2D; areaStart = _spawnArea.Position - _shape.Extents; areaEnd = _spawnArea.Position + _shape.Extents; }
public Shape2D GetShape() { var shape = new RectangleShape2D(); shape.SetExtents(new Vector2(Width / 2, Height / 2)); return(shape); }
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"); }
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 _Ready() { _currentZoomFactor = DefaultZoom; _player = GetNode <KinematicBody2D>("/root/MainScene/Player"); _camera = _player.GetNode <Camera2D>("Camera2D"); _box = GetNode <CollisionShape2D>("CollisionShape2D"); _rectangle = _box.GetShape() as RectangleShape2D; _rect = new Rect2(_box.GlobalPosition - _rectangle.Extents, _rectangle.Extents * 2); }
private Vector2 GetRandomSpawnPoint() { RectangleShape2D spawnShape = (RectangleShape2D)this.spawnPlatform.Shape; int spawnPlatformExtentX = (int)spawnShape.Extents.x; int spawnPlatformExtentY = (int)spawnShape.Extents.y; Random random = new Random(); int x = random.Next(-spawnPlatformExtentX, spawnPlatformExtentX); int y = random.Next(-spawnPlatformExtentY, spawnPlatformExtentY); return(new Vector2(x, y)); }
public override void _Ready() { SetProcessInput(true); dialogText = GetTree().Root.GetNode <RichTextLabel>("MainScene/HUDLayer/DialogBox/DialogText"); Connect(nameof(SendTextToDialog), dialogText, "_ReceiveText"); dialogText.Connect("SignalDialogActive", this, "SetDialog"); player = GetTree().Root.GetNode <KinematicBody2D>("MainScene/Player"); collisionShape = GetNode <CollisionShape2D>("CollisionShape2D"); rectangleShape = (RectangleShape2D)collisionShape.Shape; rect = new Rect2(collisionShape.GlobalPosition.x - rectangleShape.Extents.x, collisionShape.GlobalPosition.y - rectangleShape.Extents.y, rectangleShape.Extents.x * 2, rectangleShape.Extents.y * 2); }
public override void _Ready() { rectangleShape2D = new RectangleShape2D() { Extents = Extents }; collisionShape2D = new CollisionShape2D() { Shape = rectangleShape2D }; AddChild(collisionShape2D); }
StaticBody2D loadRectBody(StadiumObject stadiumObject, StaticBody2D body) { CollisionShape2D collider = new CollisionShape2D(); RectangleShape2D shape = new RectangleShape2D(); RectStruct rectStruct = (RectStruct)stadiumObject.ShapeStruct; shape.Extents = new Godot.Vector2((float)rectStruct.Position.X / 2, (float)rectStruct.Position.Y / 2); collider.Shape = shape; body.AddChild(collider); return(body); }
float spawnOffset = 350f; // how many pixels to the right guards spawn in so that they're off-screen initially public override void _Ready() { CollisionShape2D collisionShape = GetNode <CollisionShape2D>("CollisionShape2D"); RectangleShape2D newShape = new RectangleShape2D(); collisionShape.Shape = newShape; newShape.Extents = areaExtents; armySoldierScene = GD.Load <PackedScene>("res://src/combat/army/CombatArmySoldier.tscn"); armySoldiers = GetNode <Node2D>("ArmySoldiers"); tween = GetNode <Tween>("Tween"); }
private async void UpdateType(Items val) { _type = val; if (!Engine.EditorHint) { await ToSignal(this, "ready"); } sprite.RegionRect = (Rect2)regions[_type]; var rect = new RectangleShape2D(); rect.Extents = sprite.RegionRect.Size / 2; shape.Shape = rect; }
public override void _Ready() { bodyCollisionShape = new CollisionShape2D(); bodyShape = new RectangleShape2D() { Extents = new Vector2(10, 20) }; bodyCollisionShape.Shape = bodyShape; AddChild(bodyCollisionShape); headCollisionShape = new CollisionShape2D(); headShape = new CircleShape2D() { Radius = 15 }; headCollisionShape.Position = new Vector2(0, -30); headCollisionShape.Shape = headShape; AddChild(headCollisionShape); }
public override void _Ready() { lvl = (level)GetNode("/root/level"); if (lvl != null) { difficulty_coef = lvl.get_difficulty(); } polygon = GetNode <Polygon2D>("polygon_2d"); collision_shape_2d = GetNode <CollisionShape2D>("collision_shape_2d"); polygon.Color = new Color(color_name); //draw square var vectors = polygon.Polygon; vectors[0].x = (-(width / 2)); vectors[0].y = (-(height / 2)); vectors[1].x = width / 2; vectors[1].y = (-(height / 2)); vectors[2].x = width / 2; vectors[2].y = height / 2; vectors[3].x = (-(width / 2)); vectors[3].y = height / 2; //vectors[0].Set(-(width / 2), -(height / 2)); // old api (before 3.2) //vectors[1].Set((width / 2), -(height / 2)); //vectors[2].Set((width / 2), (height / 2)); //vectors[3].Set(-(width / 2), (height / 2)); polygon.Polygon = vectors; //set collision shape RectangleShape2D shape = new RectangleShape2D(); shape.Extents = new Vector2(width / 2, height / 2); collision_shape_2d.Shape = shape; }
private void GetCollisions() { if (CurrentState == State.HURT) { return; } for (int i = 0; i < GetSlideCount(); i++) { var collision = GetSlideCollision(i); if (collision.Collider is TileMap) { TileMap t = (TileMap)collision.Collider; if (t.Name == "Danger") { Hurt(); } } if (collision.Collider is Enemy) { Enemy enemy = (Enemy)collision.Collider; RectangleShape2D shape = (RectangleShape2D)enemy.GetNode <CollisionShape2D>("CollisionShape2D").Shape; var playerFeet = (Position + shape.Extents).y; if (playerFeet < enemy.Position.y) { enemy.TakeDamage(); _velocity.y = -200; } else { Hurt(); } } } }
public void OnLeftMouseClick() { var SpaceState = GetWorld2d().DirectSpaceState; Vector2 MousePos = GetGlobalMousePosition(); Physics2DShapeQueryParameters Parameters = new Physics2DShapeQueryParameters(); RectangleShape2D Shape = new RectangleShape2D(); Shape.Extents = new Vector2(16, 16); // Don't hate me. Parameters.SetShape(Shape); Parameters.Transform = new Transform2D(0.0f, MousePos); //Need to trace up/down and left/right based on the size of the object we are placing aka pot var result = SpaceState.IntersectShape(Parameters); if (result.Count == 0) { Node SunPotNode = SunPotScene.Instance(); Node2D SunPotNode2D = (Node2D)SunPotNode; SunPotNode2D.Position = MousePos; AddChild(SunPotNode2D); } }
public override void _Ready() { RectangleShape2D collisionShape = (RectangleShape2D)GetNode <CollisionShape2D>("CollisionShape2D").Shape; Extents = collisionShape.Extents; }
public virtual void Initialize(Vector2 position, int size = 8) { Position = position; this.size = size; deathTween.InterpolateProperty(this, "modulate", new Color(1f, 1f, 1f, 1f), new Color(1f, 1f, 1f, 0f), 1); deathTween.InterpolateCallback(this, 1, nameof(Die)); AddChild(deathTween); var moveShape = new RectangleShape2D(); moveCollider.Shape = moveShape; moveCollider.Position = new Vector2(0, size / 3f); if (size == 8) { shadow.Texture = ResourceLoader.Load("res://assets/sprites/shadow.png") as Texture; shadow.Position = new Vector2(0, 1); moveShape.Extents = new Vector2(1, 2); healthBar.TextureUnder = ResourceLoader.Load("res://assets/gradients/RedGradient_6.tres") as Texture; healthBar.TextureProgress_ = ResourceLoader.Load("res://assets/gradients/GreenGradient_6.tres") as Texture; healthBar.MarginBottom = -5; healthBar.MarginTop = -6; healthBar.MarginRight = 3; healthBar.MarginLeft = -3; } else if (size == 12) { shadow.Texture = ResourceLoader.Load("res://assets/sprites/shadow_12.png") as Texture; shadow.Position = new Vector2(0, 2); moveShape.Extents = new Vector2(3, 2); healthBar.TextureUnder = ResourceLoader.Load("res://assets/gradients/RedGradient_12.tres") as Texture; healthBar.TextureProgress_ = ResourceLoader.Load("res://assets/gradients/GreenGradient_12.tres") as Texture; healthBar.MarginBottom = -7; healthBar.MarginTop = -8; healthBar.MarginRight = 7; healthBar.MarginLeft = -7; } else if (size == 24) { shadow.Texture = ResourceLoader.Load("res://assets/sprites/shadow_24.png") as Texture; shadow.Position = new Vector2(0, 4); moveShape.Extents = new Vector2(5, 3); healthBar.TextureUnder = ResourceLoader.Load("res://assets/gradients/RedGradient_16.tres") as Texture; healthBar.TextureProgress_ = ResourceLoader.Load("res://assets/gradients/GreenGradient_16.tres") as Texture; healthBar.MarginBottom = -13; healthBar.MarginTop = -14; healthBar.MarginRight = 8; healthBar.MarginLeft = -8; } shadow.ZIndex = -1; healthBar.RectPosition = new Vector2(healthBar.MarginLeft, -size / 2 - 1); healthBar.Hide(); SetCollisionLayerBit(0, false); SetCollisionMaskBit(0, false); SetCollisionMaskBit(1, true); AddChild(sprite); AddChild(healthBar); AddChild(moveCollider); AddChild(shadow); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { box = GetNode <CollisionShape2D>("CollisionShape2D").Shape as RectangleShape2D; }
public Vector2 GetCollisionExtents() { RectangleShape2D shape = (RectangleShape2D)motionCollisionShape.Shape; return(shape.Extents); }