added simple activeElements list
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FOU.Scripts.Elements;
|
||||
using Godot;
|
||||
|
||||
@@ -15,6 +16,7 @@ public class Chunk {
|
||||
private readonly Image image;
|
||||
private readonly int sizeX;
|
||||
private readonly int sizeY;
|
||||
private readonly List<Element> activeElements = new List<Element>();
|
||||
|
||||
public Chunk(int x, int y, int index) {
|
||||
Index = index;
|
||||
@@ -33,11 +35,14 @@ public class Chunk {
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
for (int x = 0; x < sizeX; x++) {
|
||||
for (int y = 0; y < sizeY; y++) {
|
||||
if (Elements[x,y] != null)
|
||||
Elements[x,y].Update();
|
||||
}
|
||||
// for (int x = 0; x < sizeX; x++) {
|
||||
// for (int y = 0; y < sizeY; y++) {
|
||||
// if (Elements[x,y] != null)
|
||||
// Elements[x,y].Update();
|
||||
// }
|
||||
// }
|
||||
foreach (Element e in activeElements) {
|
||||
e.Update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,12 +57,15 @@ public class Chunk {
|
||||
int Y = Mathf.Clamp(y + j, 0, sizeY-1);
|
||||
object o = Activator.CreateInstance(type, X, Y, this);
|
||||
|
||||
if (Elements[X,Y].GetType() != type)
|
||||
Elements[X,Y] = o as Element;
|
||||
if (Elements[X,Y].GetType() != type) {
|
||||
Elements[X, Y] = o as Element;
|
||||
activeElements.Add(Elements[X, Y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: use this function and stitch together partial images in Level
|
||||
public Image DrawLevel() {
|
||||
for (int x = 0; x < sizeX; x++) {
|
||||
for (int y = 0; y < sizeY; y++) {
|
||||
@@ -67,6 +75,15 @@ public class Chunk {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void SetElementActive(Element e, bool active) {
|
||||
if (e.Active == active) return;
|
||||
|
||||
if (active)
|
||||
activeElements.Add(e);
|
||||
else
|
||||
activeElements.Remove(e);
|
||||
}
|
||||
|
||||
public void Swap(Element what, Vector2I pos) {
|
||||
Swap(what, Get(pos));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user