// Called when the node enters the scene tree for the first time. public override void _Ready() { _sizeConstants = GetNode <SizeConstants>("/root/SizeConstants"); _colorRect = GetNode <ColorRect>("ColorRect"); // set teh size of the cell to the one defined in the constants file _colorRect.SetSize(new Vector2(_sizeConstants.CellSize, _sizeConstants.CellSize)); }
public override void HandleResize() { background.SetSize(GetViewportDimensions()); youAreDead.SetPosition(GetViewportDimensions() / 2); textScale = BASE_TEXT_SCALE; }
public void _addTraversableTiles(Godot.Collections.Array tiles) { foreach (Vector2 tile in tiles) { int id = getPointID((int)tile.x, (int)tile.y); if (!_aStar.HasPoint(id)) { _aStar.AddPoint(id, tile, 1); _tilestoWorld.Add(id, _tileMap.MapToWorld(tile) + _halfCellSize); ColorRect colorRect = new ColorRect(); _grid.AddChild(colorRect); colorRect.Color = _enableColor; colorRect.Modulate = new Color(1, 1, 1, 0.5f); _gridRects.Add(id, colorRect); colorRect.MouseFilter = Control.MouseFilterEnum.Ignore; colorRect.SetSize(_tileMap.CellSize); // Color Rect's x calculation is lightly different, so need to add 1.5f to position correctly colorRect.RectPosition = new Vector2(_tileMap.MapToWorld(tile).x + (_tileMap.CellSize.x * 1.5f), _tileMap.MapToWorld(tile).y); } } }
public override void _Process(float delta) { if (_health <= 0) { ((game)this.GetNode("../..")).EnemyDead(); QueueFree(); return; } KinematicBody2D player = (KinematicBody2D)GetParent().GetNode("player"); Vector2 directionToPlayer = (player.Position - this.Position).Normalized(); MoveAndSlide(speed * directionToPlayer); ColorRect healthRect = (ColorRect)GetNode("health"); healthRect.SetSize(new Vector2(_health, healthRect.GetSize().y)); }
public void execHit(Vector2 dir, int hitPoints, int defense) { GD.Print("Unit. hp loss:" + hitPoints); hp -= hitPoints; flipH = (dir.x < 0); animation.Play("Hit"); //hit text lblHitPoints.Visible = (true); lblHitPoints.Text = ("-" + hitPoints); //hp Barr float value = ((float)hp) / hpMax; value = Mathf.Clamp(value, 0, 1f); hpBarr.Visible = (value < 1f); crLevelHp.SetSize(new Vector2(value * crMaxSize, crLevelHp.RectSize.y)); }