Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| gf2:projekte:2024:minecraft:2d2gruppe3 [2025/04/08 12:05] – bluml | gf2:projekte:2024:minecraft:2d2gruppe3 [2025/04/15 11:03] (aktuell) – marroc | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| Gruppe 3 | Gruppe 3 | ||
| + | |||
| Idee: Eine Burg mit Türmchen; siehe Bild in Teamschat | Idee: Eine Burg mit Türmchen; siehe Bild in Teamschat | ||
| - | Innen: | ||
| - | - Verwinkelte Räume mit automatischem Licht | ||
| - | - Interaktionen: | ||
| - | **Code** | ||
| - | blablabla | ||
| + | Ziel: Den versteckten Schatz finden, welcher in der Burg versteckt ist. | ||
| + | - Verwinkelte Räume (Labyrinth) | ||
| + | <code python> | ||
| + | **Code** | ||
| + | # ------------------------------------------------------------------------------ | ||
| + | # Nutzung | ||
| + | # In der Burg ist ein Schatz versteckt, den es zu finden gilt! | ||
| + | # | ||
| + | # Befehle | ||
| + | # • " | ||
| + | # • " | ||
| + | # ------------------------------------------------------------------------------ | ||
| + | MIN_PADDING = 3 # Mindestabstand zwischen Räumen und Aussenwand | ||
| + | SIMPLIFY = 0 # Burg vereinfachen um sie schneller zu generieren | ||
| + | TOWERS = True # Türme generieren | ||
| + | T_RADIUS = 3 # Radius der Türme | ||
| + | seed = 54321 # Startwert für Pseudozufallszahlen | ||
| + | # ------------------------------------------------------------------------------ | ||
| + | # Die Koordinaten im Code folgen der Einteilung von Minecraft, nach der y die | ||
| + | # Höhe ist. | ||
| + | # Bei blocks.fill wurde FillOperation.REPLACE zwecks Leserlichkeit weggelassen, | ||
| + | # da es sich um den Standartwert handelt. | ||
| + | # ------------------------------------------------------------------------------ | ||
| + | CHUNK_HEIGHT = 6 # Festgelegt durch Höhe der Burgsegmente | ||
| + | L = 0 | ||
| + | materials = [STONE_BRICKS, | ||
| + | start_pos = player.position() | ||
| - | **Oberer Teil:** | + | # |
| - | start_pos = pos(0, | + | # Hilfsfunktionen |
| - | to_pos = pos(0, 0, 0) | + | # |
| - | selector_pos = start_pos | + | |
| - | + | # Relative Koordinaten unabhängig von der Bewegung des Spielers während der Ausführung | |
| def position(x, y, z): | def position(x, y, z): | ||
| - | | + | |
| - | | + | |
| - | | + | # Funktion um Wert eine Position zu erhalten (da die Funktion position() mit .get_value() sonst nur Weltkoordinaten ausgibt) |
| - | | + | def get(pos: Position, axis): |
| - | + | return pos.to_world().get_value(axis) - start_pos.get_value(axis) | |
| - | def ObererTeil(pos, l, h): | + | |
| - | | + | # Pseudozufallszahlengenerator https:// |
| - | | + | def lcg(value=0): |
| - | | + | global seed |
| - | | + | a, c, m = 1664525, 1013904223, 2**32 # Werte aus https:// |
| - | | + | |
| - | blocks.fill(98, world(x, y, z), world(x + l, y + h, z + l), FillOperation.HOLLOW) | + | if value == 0: |
| - | + | seed = (seed * a + c) % m | |
| - | ObererTeil(position(2, | + | return seed / m |
| - | + | else: | |
| + | return ((value * a + c ) % m) / m | ||
| + | |||
| + | # | ||
| + | # Burg | ||
| + | # | ||
| + | |||
| + | # Funktion zum bauen der Segmente | ||
| + | def chunk_builder(): | ||
| + | blocks.saveStructure(" | ||
| + | |||
| + | blocks.fill(AIR, | ||
| + | |||
| + | for i in range(2): | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | |||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | blocks.fill(materials[0], | ||
| + | |||
| + | # Öffnungen für Durchgänge | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | blocks.fill(AIR, | ||
| + | |||
| + | # Stufen zur Verschönerung der Durchgänge | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | |||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | |||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | |||
| + | blocks.fill(blocks.block_with_data(materials[2], | ||
| + | blocks.fill(blocks.block_with_data(materials[2], | ||
| + | |||
| + | for x in range(16): | ||
| + | if x % 3 == 0: | ||
| + | for z in range(16): | ||
| + | if z % 3 == 0: | ||
| + | player.execute("/ | ||
| + | |||
| + | |||
| + | # Treppen-Segment | ||
| + | blocks.fill(materials[1], | ||
| + | blocks.fill(AIR, | ||
| + | |||
| + | for step in range(2, 14): # Treppenstufen erstellen | ||
| + | material = materials[3] if step % 2 == 0 else materials[0] | ||
| + | blocks.fill(material, | ||
| + | |||
| + | # Speichern der Strukturen | ||
| + | blocks.saveStructure(" | ||
| + | blocks.loadStructure(" | ||
| + | blocks.saveStructure(" | ||
| + | |||
| + | blocks.place(IRON_BLOCK, | ||
| + | blocks.place(GOLD_BLOCK, | ||
| + | blocks.place(GOLD_BLOCK, | ||
| + | blocks.place(EMERALD_BLOCK, | ||
| + | blocks.place(EMERALD_BLOCK, | ||
| + | blocks.place(DIAMOND_BLOCK, | ||
| + | blocks.place(DIAMOND_BLOCK, | ||
| + | blocks.place(DIAMOND_BLOCK, | ||
| + | blocks.place(DIAMOND_BLOCK, | ||
| + | |||
| + | # Schatz-Segment speichern | ||
| + | blocks.saveStructure(" | ||
| + | |||
| + | blocks.loadStructure(" | ||
| + | return 1 | ||
| + | |||
| + | |||
| + | # Funktion zum Zusammensetzen der Segmente | ||
| + | def build_core(length, | ||
| + | treasure = Math.round(lcg() * length * width * height) | ||
| + | for x in range(length): | ||
| + | for y in range(height): | ||
| + | for z in range(width): | ||
| + | |||
| + | x_now = x * 16 + get(start_pos, | ||
| + | y_now = y * 6 + get(start_pos, | ||
| + | z_now = z * 16 + get(start_pos, | ||
| + | |||
| + | if x != Math.floor(length / 2) or z != Math.floor(width / 2): | ||
| + | if treasure | ||
| + | blocks.loadStructure(" | ||
| + | else: | ||
| + | blocks.loadStructure(" | ||
| + | else: | ||
| + | if treasure == x + y + z: | ||
| + | treasure += 1 | ||
| + | blocks.loadStructure(" | ||
| + | if y == 0: | ||
| + | blocks.fill(materials[0], | ||
| + | |||
| + | |||
| + | |||
| + | # Burgmauern | ||
| + | def wall(start_pos: | ||
| + | | ||
| + | ex, ey, ez = get(end_pos, | ||
| + | dir_x = 0 | ||
| + | dir_z = 0 | ||
| + | |||
| + | outside = 1 if mirror == False else -1 # Bestimmen auf welcher Seite (+ oder -) der Mauer sich die Aussenseite befindet. 1 wenn mirror == False, sonst -1. | ||
| + | | ||
| + | height = abs(sy - ey) | ||
| + | |||
| + | # Überprüfen welche Koordinaten identisch sind um Richtung zu bestimmen | ||
| + | if sx == ex: | ||
| + | dir_x = outside | ||
| + | length = abs(sz - ez) | ||
| + | else: | ||
| + | dir_z = outside | ||
| + | length = abs(sx - ex) | ||
| + | |||
| + | blocks.fill(materials[0], start_pos, end_pos) | ||
| + | |||
| + | # Deko | ||
| + | blocks.fill(materials[0], | ||
| + | | ||
| + | if i % (2 + SIMPLIFY) | ||
| + | stair_data = 0 | ||
| + | if dir_x != 0: | ||
| + | stair_data = 4 if mirror else 5 # EAST oder WEST | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | | ||
| + | # Fenster | ||
| + | for j in range(height): | ||
| + | if j % CHUNK_HEIGHT | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | | ||
| + | stair_data | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | blocks.place(materials[3], | ||
| + | # Fenster | ||
| + | for j in range(height): | ||
| + | if j % CHUNK_HEIGHT == 3: | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | |||
| + | |||
| + | # Türme | ||
| + | def tower(location: | ||
| + | | ||
| + | |||
| + | for i in range(height): | ||
| + | mat = base_materials[randint(0, | ||
| + | shapes.circle(mat, location.add(pos(0, | ||
| + | |||
| + | | ||
| + | if j % 2 == 0: | ||
| + | r = radius - j / 2 | ||
| + | shapes.circle(materials[4], | ||
| + | |||
| + | def outside(length, | ||
| + | | ||
| + | for i in range(4): # 4 Wände | ||
| + | |||
| + | # Festlegen Start- und Endpositionen der aktuellen Wand (1 oder 0) | ||
| + | |||
| + | # | ||
| + | # | ||
| + | # | ||
| + | |||
| + | x1 = length if i in(1,2) else 0 # Wenn i == 1 oder i == 3: x1 = length, sonst x1 = 0 | ||
| + | y1 = 0 | ||
| + | z1 = width if i in(2,3) else 0 | ||
| + | |||
| + | x2 = length if i in(0,1) else 0 | ||
| + | y2 = height // CHUNK_HEIGHT * CHUNK_HEIGHT | ||
| + | z2 = width if i in(1,2) else 0 | ||
| + | |||
| + | invert = i in(0,3) # True oder False, abhängig davon ob i 1 oder 2 ist | ||
| + | |||
| + | wall(position(x1, | ||
| + | |||
| + | if TOWERS == True: | ||
| + | tower(position(x1, | ||
| + | |||
| + | # Eingangstor | ||
| + | | ||
| + | blocks.fill(DARK_OAK_FENCE, | ||
| + | blocks.place(blocks.block_with_data(materials[2], 5), position(length // 2 - 1, 4, 0)) | ||
| + | blocks.place(blocks.block_with_data(materials[2], | ||
| + | |||
| + | # Böden | ||
| + | for i in range(height + 1): | ||
| + | if i % CHUNK_HEIGHT == 0: | ||
| + | blocks.fill(materials[0], | ||
| + | |||
| + | def tor_auf(a, b): | ||
| + | blocks.fill(AIR, | ||
| + | |||
| + | def tor_zu(a, b): | ||
| + | blocks.fill(DARK_OAK_FENCE, | ||
| + | |||
| + | def main(length, | ||
| + | global L # Global, da sonst die auf() und zu() Funktionen des Eingangstors nicht verwendet weden können. | ||
| + | L = length | ||
| + | |||
| + | if length < 16 + 2 * MIN_PADDING + 4 or width < 16 + 2 * MIN_PADDING + 4 or height < CHUNK_HEIGHT: | ||
| + | player.execute("""/ | ||
| + | return 0 | ||
| + | |||
| + | player.execute("""/ | ||
| + | # Chatbefehle | ||
| + | player.on_chat(" | ||
| + | player.on_chat(" | ||
| + | | ||
| + | # Burg bauen | ||
| + | chunk_builder() | ||
| + | | ||
| + | outside(length, | ||
| + | | ||
| + | core_chunks_x = (length - 2 * MIN_PADDING) // 16 | ||
| + | core_chunks_z = (width - 2 * MIN_PADDING) // 16 | ||
| + | core_start_x = (length - core_chunks_x * 16) // 2 | ||
| + | core_start_z = (width - core_chunks_z * 16) // 2 | ||
| - | **Türmchen: | + | build_core(core_chunks_x, height // CHUNK_HEIGHT, core_chunks_z, position(core_start_x, 0, core_start_z)) |
| - | Türmchen Fuktion | + | |
| - | def Türmchen(): | + | |
| - | material=[STONE_BRICKS, MOSSY_STONE_BRICKS, CRACKED_STONE_BRICKS] | + | |
| - | shapes.sphere(RED_STAINED_GLASS, world(-152, -55, -259), 5, ShapeOperation.HOLLOW) | + | |
| - | | + | |
| - | | + | |
| - | + | ||
| - | Türmchen() | + | |
| + | main(54, 18, 38, position(0, 0, 0)) | ||
| + | </ | ||