public void UpdateMap() { bool mapHasBeenUpdate = false; for (int y = 0; y < 20; y++) { for (int x = 0; x < 20; x++) { if (map.chunkNeedTextureUpdate[x, y] || map.chunkNeedMeshUpdate[x, y]) { if (map.chunkNeedMeshUpdate[x, y]) { MeshGenerator.AsyncGenerateChunk(new Vector2Int(x, y), map, gfxsMap[x, y]); map.chunkNeedMeshUpdate[x, y] = false; } if (map.chunkNeedTextureUpdate[x, y]) { TextureGenerator.AsyncGenerateTextureChunk(new Vector2Int(x, y), map, gfxsMap[x, y]); map.chunkNeedTextureUpdate[x, y] = false; } mapHasBeenUpdate = true; } } } if (mapHasBeenUpdate) { MapUpdateEvent?.Invoke(); } }
public void BodyEntered(Node body) { //GD.Print("body.Name = " + body.Name); //Check if it hit a map element first if (body.IsInGroup("Map")) { MapUpdateEvent muei = new MapUpdateEvent(); //Add one more step of velocity to the colliders position so that we make sure the bullet is inside the tile before we //return the bullets position to the map for refferencing the tile that was hit velocity = new Vector2(Mathf.Cos(Rotation), Mathf.Sin(Rotation)) * speed / 2; muei.CollisionPos = Position; muei.FireEvent(); QueueFree(); } //If the collider was not a wall or in the same group as the object that fired it call the hit event else if (body != GetParent().GetParent()) { //Fire of the hit event HitEvent hei = new HitEvent(); hei.target = (Node2D)body; hei.attacker = (Node2D)GetParent().GetParent(); hei.damage = 100; hei.FireEvent(); QueueFree(); } }
// // Called every frame. 'delta' is the elapsed time since the previous frame. // public override void _Process(float delta) // { // // } private void UpdateMap(MapUpdateEvent muei) { //I we hit a wall we just return out of the tile check if (GetCell((int)muei.CollisionPos.x / 32, (int)muei.CollisionPos.y / 32) == 3) { return; } //Convert the position from the collision passed in to intiger to use in the tile map int tileX = (int)muei.CollisionPos.x / 32; int tileY = (int)muei.CollisionPos.y / 32; //Run through all the surrounding tiles in the collision for (int x = tileX - 1; x < tileX + 1; x++) { for (int y = tileY - 1; y < tileY + 1; y++) { if (GetCell(x, y) == 4) { SetCell(x, y, 5); } } } }
public override void _ExitTree() { MapUpdateEvent.UnregisterListener(UpdateMap); }
// Declare member variables here. Examples: // private int a = 2; // private string b = "text"; // Called when the node enters the scene tree for the first time. public override void _Ready() { MapUpdateEvent.RegisterListener(UpdateMap); }