//called every frame public static void run() { Player[] p = players; //because laz for (int i = 0; i < p.Length; i++) { if (p[i].getState() is WorldState) { WorldState w = (WorldState)p[i].getState(); if (w.getWaterPixel() == 16) { w.WALK_SPEED = 1; } else { w.WALK_SPEED = 2; } } if (p[i].isScuba) { if (p[i].breath == 0) { if (i == 0) { lose(new string[] { "Humans aren't built for living underwater.", "The other player forgot how to breath." }); } else { lose(new string[] { "The other player forgot how to breath.", "Humans aren't built for living underwater." }); } } else { p[i].breath--; } } else { if (p[i].breath < Player.MAX_BREATH) { p[i].breath++; } } p[i].run(); } bool canTick = false; //whether or not any worlds can tick, i.e. if any players are outside of menus for (int i = 0; i < p.Length; i++) { if (p[i].getState() is WorldState && !(p[i].getState() is WorldEditor)) { canTick = true; p[i].world.tick(p[i]); } } if (canTick) { if (waterRising) { if (WorldState.drainFrames == 0) { WorldState.waterLevel--; if (WorldState.waterLevel == 0) { lose(new string[] { "Inundation complete. Might want to stop that next time." }); WorldState.waterLevel = WorldState.WATER_SPEED; } else if (WorldState.waterLevel % WorldState.WATER_SPEED == 0) { int level = WorldState.waterLevel / WorldState.WATER_SPEED; if (level >= 0 && level < 4) { WorldState.pipeUsesLeft[level]--; if (WorldState.pipeUsesLeft[level] == 0) { lose(new string[] { "There was no hope for floor " + (level + 1) + "'s pipe any longer." }); } } } } else { WorldState.waterLevel++; WorldState.drainFrames--; } } frames++; List <World> tickedWorlds = new List <World>(); //worlds in this list have already ticked, needed so that they don't double up for (int i = 0; i < p.Length; i++) { if (!tickedWorlds.Contains(p[i].world)) { World w = p[i].world; for (int j = 0; j < w.entities.Count; j++) { Entity e = w.entities[j]; e.tick(); if (e.needsRemoval()) { w.entities.Remove(e); j--; } } tickedWorlds.Add(w); } } } }