Momentan verwende ich eine nicht so optimale Lösung, die feine Levels laufen lässt und keine Verzögerung hat, die das Problem erzeugt, ist eine Menge Code und mit steigendem Level wird dieser Code immer größer schwierig zu verwalten, also suche ich nach einer besseren Lösung.LevelGenerator nicht optimal
Wie kann ich meine Levels besser erstellen? Sind sie bessere Systeme? Bitarray? Was ist eine bessere Richtung, um hineinzugehen?
#region Level Generator
private void LevelCreator(int level){
if (level == 1) {
Vector3 pos = new Vector3 (0, 0, 0);
Vector3 pos2 = new Vector3 (-1, 0, 0);
Vector3 pos3 = new Vector3 (-2, 0, 0);
Vector3 pos4 = new Vector3 (-3, 0, 0);
Vector3 pos5 = new Vector3 (-4, 0, 0);
Vector3 pos6 = new Vector3 (-5, 0, 0);
Vector3 pos7 = new Vector3 (-6, 0, 0);
Vector3 pos8 = new Vector3 (-7, 0, 0);
Instantiate (startCube, pos, Quaternion.identity);
Instantiate (fallCube, pos2, Quaternion.identity);
Instantiate (fallCube, pos3, Quaternion.identity);
Instantiate (fallCube, pos4, Quaternion.identity);
Instantiate (fallCube, pos5, Quaternion.identity);
Instantiate (fallCube, pos6, Quaternion.identity);
Instantiate (fallCube, pos7, Quaternion.identity);
Instantiate (endCube, pos8, Quaternion.identity);
player.transform.position = pos + Vector3.up;
} else if (level == 2) {
Vector3 pos = new Vector3 (0, 0, 0);
Vector3 pos2 = new Vector3 (0, 0, 1);
Vector3 pos3 = new Vector3 (0, 0, 2);
Vector3 pos4 = new Vector3 (-1, 0, 2);
Vector3 pos5 = new Vector3 (-2, 0, 2);
Vector3 pos6 = new Vector3 (-2, 0, 1);
Vector3 pos7 = new Vector3 (-2, 0, 0);
Vector3 pos8 = new Vector3 (-3, 0, 0);
Vector3 pos9 = new Vector3 (-4, 0, 0);
Vector3 pos10 = new Vector3 (-4, 0, 1);
Vector3 pos11 = new Vector3 (-4, 0, 2);
Vector3 pos12 = new Vector3 (-5, 0, 2);
Instantiate (startCube, pos, Quaternion.identity);
Instantiate (fallCube, pos2, Quaternion.identity);
Instantiate (fallCube, pos3, Quaternion.identity);
Instantiate (fallCube, pos4, Quaternion.identity);
Instantiate (fallCube, pos5, Quaternion.identity);
Instantiate (fallCube, pos6, Quaternion.identity);
Instantiate (fallCube, pos7, Quaternion.identity);
Instantiate (fallCube, pos8, Quaternion.identity);
Instantiate (fallCube, pos9, Quaternion.identity);
Instantiate (fallCube, pos10, Quaternion.identity);
Instantiate (fallCube, pos11, Quaternion.identity);
Instantiate (endCube, pos12, Quaternion.identity);
player.transform.position = pos + Vector3.up;
} else if (level == 3) {
Vector3 pos = new Vector3 (0, 0, 0);
Vector3 pos2 = new Vector3 (0, 0, 1);
Vector3 pos3 = new Vector3 (0, 0, 2);
Vector3 pos4 = new Vector3 (-1, 0, 2);
Vector3 pos5 = new Vector3 (-1, 0, 3);
Vector3 pos6 = new Vector3 (-1, 0, 4);
Vector3 pos7 = new Vector3 (0, 0, 4);
Vector3 pos8 = new Vector3 (1, 0, 4);
Vector3 pos9 = new Vector3 (1, 0, 5);
Vector3 pos10 = new Vector3 (1, 0, 6);
Vector3 pos11 = new Vector3 (1, 0, 7);
Vector3 pos12 = new Vector3 (0, 0, 7);
Vector3 pos13 = new Vector3 (-1, 0, 7);
Vector3 pos14 = new Vector3 (-2, 0, 7);
Vector3 pos15 = new Vector3 (-3, 0, 7);
Vector3 pos16 = new Vector3 (-4, 0, 7);
Vector3 pos17 = new Vector3 (-4, 0, 6);
Vector3 pos18 = new Vector3 (-4, 0, 5);
Vector3 pos19 = new Vector3 (-4, 0, 4);
Vector3 pos20 = new Vector3 (-3, 0, 4);
Vector3 pos21 = new Vector3 (-2, 0, 4);
Vector3 pos22 = new Vector3 (-2, 0, 3);
Vector3 pos23 = new Vector3 (-2, 0, 2);
Vector3 pos24 = new Vector3 (-2, 0, 1);
Vector3 pos25 = new Vector3 (-2, 0, 0);
Instantiate (startCube, pos, Quaternion.identity);
Instantiate (fallCube, pos2, Quaternion.identity);
Instantiate (fallCube, pos3, Quaternion.identity);
Instantiate (fallCube, pos4, Quaternion.identity);
Instantiate (fallCube, pos5, Quaternion.identity);
Instantiate (fallCube, pos6, Quaternion.identity);
Instantiate (fallCube, pos7, Quaternion.identity);
Instantiate (fallCube, pos8, Quaternion.identity);
Instantiate (fallCube, pos9, Quaternion.identity);
Instantiate (fallCube, pos10, Quaternion.identity);
Instantiate (fallCube, pos11, Quaternion.identity);
Instantiate (fallCube, pos12, Quaternion.identity);
Instantiate (fallCube, pos13, Quaternion.identity);
Instantiate (fallCube, pos14, Quaternion.identity);
Instantiate (fallCube, pos15, Quaternion.identity);
Instantiate (fallCube, pos16, Quaternion.identity);
Instantiate (fallCube, pos17, Quaternion.identity);
Instantiate (fallCube, pos18, Quaternion.identity);
Instantiate (fallCube, pos19, Quaternion.identity);
Instantiate (fallCube, pos20, Quaternion.identity);
Instantiate (fallCube, pos21, Quaternion.identity);
Instantiate (fallCube, pos22, Quaternion.identity);
Instantiate (fallCube, pos23, Quaternion.identity);
Instantiate (fallCube, pos24, Quaternion.identity);
Instantiate (endCube, pos25, Quaternion.identity);
player.transform.position = pos + Vector3.up;
} else if (level == 4) {
Vector3 pos = new Vector3 (0, 0, 0);
Vector3 pos2 = new Vector3 (-1, 0, 0);
Vector3 pos3 = new Vector3 (-2, 0, 0);
Vector3 pos4 = new Vector3 (-2, 0, -1);
Vector3 pos5 = new Vector3 (-3, 0, 0);
Vector3 pos6 = new Vector3 (-4, 0, 0);
Vector3 pos7 = new Vector3 (-4, 0, 1);
Vector3 pos8 = new Vector3 (-5, 0, 0);
Vector3 pos9 = new Vector3 (-6, 0, 0);
Vector3 pos10 = new Vector3 (-7, 0, 0);
Vector3 pos11 = new Vector3 (-6, 0, 1);
Vector3 pos12 = new Vector3 (-6, 0, 2);
Vector3 pos13 = new Vector3 (-5, 0, 2);
Vector3 pos14 = new Vector3 (-7, 0, 2);
Instantiate (startCube, pos, Quaternion.identity);
Instantiate (fallCube, pos2, Quaternion.identity);
Instantiate (permCube, pos3, Quaternion.identity);
Instantiate (fallCube, pos4, Quaternion.identity);
Instantiate (fallCube, pos5, Quaternion.identity);
Instantiate (permCube, pos6, Quaternion.identity);
Instantiate (fallCube, pos7, Quaternion.identity);
Instantiate (fallCube, pos8, Quaternion.identity);
Instantiate (permCube, pos9, Quaternion.identity);
Instantiate (fallCube, pos10, Quaternion.identity);
Instantiate (fallCube, pos11, Quaternion.identity);
Instantiate (permCube, pos12, Quaternion.identity);
Instantiate (fallCube, pos13, Quaternion.identity);
Instantiate (endCube, pos14, Quaternion.identity);
player.transform.position = pos + Vector3.up;
} else if (level == 5) {
Vector3 pos = new Vector3 (0, 0, 0);
Vector3 pos1 = new Vector3 (0, 0, 1);
Vector3 pos2 = new Vector3 (-1, 0, 1);
Vector3 pos3 = new Vector3 (-2, 0, 1);
Vector3 pos4 = new Vector3 (-3, 0, 1);
Vector3 pos5 = new Vector3 (-3, 0, 2);
Vector3 pos6 = new Vector3 (-2, 0, 2);
Vector3 pos7 = new Vector3 (-1, 0, 2);
Vector3 pos8 = new Vector3 (0, 0, 2);
Vector3 pos9 = new Vector3 (0, 0, 3);
Vector3 pos10 = new Vector3 (0, 0, 4);
Vector3 pos11 = new Vector3 (0, 0, 5);
Vector3 pos12 = new Vector3 (0, 0, 6);
Vector3 pos13 = new Vector3 (0, 0, 7);
Vector3 pos14 = new Vector3 (0, 0, 8);
Vector3 pos15 = new Vector3 (-1, 0, 8);
Vector3 pos16 = new Vector3 (-1, 0, 7);
Vector3 pos17 = new Vector3 (-1, 0, 6);
Vector3 pos18 = new Vector3 (-1, 0, 5);
Vector3 pos19 = new Vector3 (-1, 0, 4);
Vector3 pos20 = new Vector3 (-2, 0, 4);
Vector3 pos21 = new Vector3 (-3, 0, 4);
Vector3 pos22 = new Vector3 (-4, 0, 4);
Vector3 pos23 = new Vector3 (-4, 0, 5);
Vector3 pos24 = new Vector3 (-4, 0, 6);
Vector3 pos25 = new Vector3 (-4, 0, 7);
Vector3 pos26 = new Vector3 (-4, 0, 8);
Vector3 pos27 = new Vector3 (-3, 0, 8);
Vector3 pos28 = new Vector3 (-3, 0, 7);
Vector3 pos29 = new Vector3 (-5, 0, 8);
Vector3 pos30 = new Vector3 (-5, 0, 7);
Vector3 pos31 = new Vector3 (-5, 0, 6);
Vector3 pos32 = new Vector3 (-5, 0, 5);
Vector3 pos33 = new Vector3 (-5, 0, 4);
Vector3 pos34 = new Vector3 (-5, 0, 3);
Vector3 pos35 = new Vector3 (-5, 0, 2);
Vector3 pos36 = new Vector3 (-5, 0, 1);
Vector3 pos37 = new Vector3 (-5, 0, 0);
Instantiate (startCube, pos, Quaternion.identity);
Instantiate (fallCube, pos1, Quaternion.identity);
Instantiate (fallCube, pos2, Quaternion.identity);
Instantiate (fallCube, pos3, Quaternion.identity);
Instantiate (fallCube, pos4, Quaternion.identity);
Instantiate (fallCube, pos5, Quaternion.identity);
Instantiate (fallCube, pos6, Quaternion.identity);
Instantiate (fallCube, pos7, Quaternion.identity);
Instantiate (fallCube, pos8, Quaternion.identity);
Instantiate (fallCube, pos9, Quaternion.identity);
Instantiate (fallCube, pos10, Quaternion.identity);
Instantiate (fallCube, pos11, Quaternion.identity);
Instantiate (fallCube, pos12, Quaternion.identity);
Instantiate (fallCube, pos13, Quaternion.identity);
Instantiate (fallCube, pos14, Quaternion.identity);
Instantiate (fallCube, pos15, Quaternion.identity);
Instantiate (fallCube, pos16, Quaternion.identity);
Instantiate (fallCube, pos17, Quaternion.identity);
Instantiate (fallCube, pos18, Quaternion.identity);
Instantiate (fallCube, pos19, Quaternion.identity);
Instantiate (fallCube, pos20, Quaternion.identity);
Instantiate (fallCube, pos21, Quaternion.identity);
Instantiate (fallCube, pos22, Quaternion.identity);
Instantiate (fallCube, pos23, Quaternion.identity);
Instantiate (fallCube, pos24, Quaternion.identity);
Instantiate (fallCube, pos25, Quaternion.identity);
Instantiate (fallCube, pos26, Quaternion.identity);
Instantiate (fallCube, pos27, Quaternion.identity);
Instantiate (fallCube, pos28, Quaternion.identity);
Instantiate (fallCube, pos29, Quaternion.identity);
Instantiate (fallCube, pos30, Quaternion.identity);
Instantiate (fallCube, pos31, Quaternion.identity);
Instantiate (fallCube, pos32, Quaternion.identity);
Instantiate (fallCube, pos33, Quaternion.identity);
Instantiate (fallCube, pos34, Quaternion.identity);
Instantiate (fallCube, pos35, Quaternion.identity);
Instantiate (fallCube, pos36, Quaternion.identity);
Instantiate (endCube, pos37, Quaternion.identity);
player.transform.position = pos + Vector3.up;
} else if (level == 6) {
Vector3 pos = new Vector3 (0, 0, 0);
Vector3 pos2 = new Vector3 (1, 0, -1);
Vector3 pos3 = new Vector3 (1, 0, -2);
Vector3 pos4 = new Vector3 (0, 0, -2);
Vector3 pos5 = new Vector3 (0, 0, -1);
Vector3 pos6 = new Vector3 (0, 0, -3);
Vector3 pos7 = new Vector3 (0, 0, -4);
Vector3 pos8 = new Vector3 (0, 0, -5);
Vector3 pos9 = new Vector3 (0, 0, -6);
Vector3 pos10 = new Vector3 (1, 0, -5);
Vector3 pos11 = new Vector3 (1, 0, -6);
Vector3 pos12 = new Vector3 (-1, 0, -6);
Vector3 pos13 = new Vector3 (-2, 0, -6);
Vector3 pos14 = new Vector3 (-3, 0, -6);
Vector3 pos15 = new Vector3 (-4, 0, -6);
Vector3 pos16 = new Vector3 (-3, 0, -5);
Vector3 pos17 = new Vector3 (-4, 0, -5);
Vector3 pos18 = new Vector3 (-4, 0, -4);
Vector3 pos19 = new Vector3 (-4, 0, -3);
Vector3 pos20 = new Vector3 (-4, 0, -2);
Vector3 pos21 = new Vector3 (-4, 0, -1);
Vector3 pos22 = new Vector3 (-3, 0, -1);
Vector3 pos23 = new Vector3 (-3, 0, -2);
Vector3 pos24 = new Vector3 (-2, 0, -2);
Vector3 pos25 = new Vector3 (-1, 0, -2);
Vector3 pos26 = new Vector3 (-4, 0, 0);
Instantiate (startCube, pos, Quaternion.identity);
Instantiate (permCube, pos2, Quaternion.identity);
Instantiate (permCube, pos3, Quaternion.identity);
Instantiate (permCube, pos4, Quaternion.identity);
Instantiate (permCube, pos5, Quaternion.identity);
Instantiate (fallCube, pos6, Quaternion.identity);
Instantiate (fallCube, pos7, Quaternion.identity);
Instantiate (permCube, pos8, Quaternion.identity);
Instantiate (permCube, pos9, Quaternion.identity);
Instantiate (permCube, pos10, Quaternion.identity);
Instantiate (permCube, pos11, Quaternion.identity);
Instantiate (fallCube, pos12, Quaternion.identity);
Instantiate (fallCube, pos13, Quaternion.identity);
Instantiate (permCube, pos14, Quaternion.identity);
Instantiate (permCube, pos15, Quaternion.identity);
Instantiate (permCube, pos16, Quaternion.identity);
Instantiate (permCube, pos17, Quaternion.identity);
Instantiate (fallCube, pos18, Quaternion.identity);
Instantiate (fallCube, pos19, Quaternion.identity);
Instantiate (permCube, pos20, Quaternion.identity);
Instantiate (permCube, pos21, Quaternion.identity);
Instantiate (permCube, pos22, Quaternion.identity);
Instantiate (permCube, pos23, Quaternion.identity);
Instantiate (fallCube, pos24, Quaternion.identity);
Instantiate (fallCube, pos25, Quaternion.identity);
Instantiate (endCube, pos26, Quaternion.identity);
player.transform.position = pos + Vector3.up;
}
}
#endregion
Sie mit 'Array' oder' list' Wurden in Betracht gezogen?Auf diese Weise müssen Sie nicht für jede neu erstellte Position eine neue Codezeile generieren. Sie müssen lediglich das Element in der Array - oder Listenliste hinzufügen. – Ian
nicht sicher, wie ich sie implementieren würde Liste, um durch die Ebenen zu durchlaufen, aber es zu codieren erkannte ich, dass es mehr Code als die If/Else-Anweisungen –
machte Lesen Sie Ihre Ebenen durch externe Dateien wie XML-Dateien, und machen Sie Ihre eigenen Level-Designer, die die Level-Dateien lesen und schreiben können, oder Sie können es manuell selbst im Code tun :(. – Xela