Try it: every spot has an address
Probier es: Jeder Ort hat eine Adresse
To the game, every place is just a few numbers: its coordinates.
Für das Spiel ist jeder Ort nur ein paar Zahlen: seine Koordinaten.
- x goes left to right, east.
- x geht von links nach rechts, nach Osten.
- z goes top to bottom on this map, south.
- z geht auf dieser Karte von oben nach unten, nach Süden.
- y goes up, towards the sky. (This map is seen from above, so you can't see y here.)
- y geht nach oben, zum Himmel. (Diese Karte ist von oben gesehen, darum siehst du y hier nicht.)
A cube is 16 cells wide, so x and z go from 0 to 16. One cell is exactly 1 long.
Ein Würfel ist 16 Zellen breit, also gehen x und z von 0 bis 16. Eine Zelle ist genau 1 lang.
The hero can stand anywhere, like at x = 4.3. But floors, walls and stairs are built cell by cell. Which cell is the hero in? Round down: Math.floor(4.3) is 4.
Der Held kann überall stehen, zum Beispiel bei x = 4,3. Aber Böden, Wände und Treppen sind Zelle für Zelle gebaut. In welcher Zelle ist der Held? Abrunden: Math.floor(4.3) ist 4.
Try it: arrows from here to there
Probier es: Pfeile von hier nach dort
How do you get from the hero to the spider? Take the spider's numbers minus the hero's numbers:
Wie kommst du vom Helden zur Spinne? Nimm die Zahlen der Spinne minus die Zahlen des Helden:
dx = spider.x − hero.x
dz = spider.z − hero.z
That pair of numbers is an arrow, called a vector. It says which way, and how far: "go 6 right and 5 up".
Dieses Zahlenpaar ist ein Pfeil, ein sogenannter Vektor. Er sagt, in welche Richtung und wie weit: "Geh 6 nach rechts und 5 nach oben."
Vectors are everywhere in the game. The hero's speed is one too: an arrow for how far it moves in one second. Every frame, the game adds a little bit of that arrow to the hero's position.
Vektoren sind überall im Spiel. Das Tempo des Helden ist auch einer: ein Pfeil dafür, wie weit er sich in einer Sekunde bewegt. In jedem Bild zählt das Spiel ein kleines Stück dieses Pfeils zur Position des Helden dazu.
Moving is just adding Bewegen ist nur ZusammenzählenTry it: how far is it?
Probier es: Wie weit ist es?
The arrow and its two numbers make a triangle with a right angle. Over two thousand years ago, Pythagoras found out how long the slanted side is:
Der Pfeil und seine zwei Zahlen bilden ein Dreieck mit einem rechten Winkel. Vor über zweitausend Jahren hat Pythagoras herausgefunden, wie lang die schräge Seite ist:
distance = √(dx² + dz²)
In code that's Math.hypot(dx, dz). The game asks it all the time: has the spider seen me (closer than 3 cells)? Is it close enough to bite? Am I standing on the town portal?
Im Code heißt das Math.hypot(dx, dz). Das Spiel fragt das ständig: Hat die Spinne mich gesehen (näher als 3 Zellen)? Ist sie nah genug zum Beißen? Stehe ich auf dem Stadtportal?
You're on the portal if your height is close (Math.abs drops the minus sign), the distance is small, you stand on the ground, aren't stunned, and aren't running through.
Du bist auf dem Portal, wenn deine Höhe nah dran ist (Math.abs lässt das Minus weg), die Entfernung klein ist, du auf dem Boden stehst, nicht betäubt bist und nicht durchrennst.
Try it: which way to turn?
Probier es: Wohin drehen?
To face the spider, the hero has to turn. By how much? Math.atan2(dx, dz) turns the arrow into an angle. The game calls the way something faces its yaw.
Um die Spinne anzuschauen, muss sich der Held drehen. Um wie viel? Math.atan2(dx, dz) macht aus dem Pfeil einen Winkel. Das Spiel nennt die Richtung, in die etwas schaut, seinen yaw.
Computers measure angles in radians, not degrees: a full turn is 2 × π, about 6.28, instead of 360°.
Computer messen Winkel im Bogenmaß, nicht in Grad: Eine ganze Drehung ist 2 × π, ungefähr 6,28, statt 360°.
Monsters turn towards you with this little machine. It doesn't snap round at once, it turns a bit every frame, and always the short way:
Monster drehen sich mit dieser kleinen Maschine zu dir. Sie schnappen nicht auf einmal herum, sie drehen sich in jedem Bild ein Stück, und immer den kurzen Weg:
The Math.atan2(Math.sin(...), Math.cos(...)) part is a trick: it turns "350° to the left" into "10° to the right".
Der Teil Math.atan2(Math.sin(...), Math.cos(...)) ist ein Trick: Er macht aus "350° nach links" ein "10° nach rechts".
Try it: just the direction
Probier es: nur die Richtung
Sometimes you only want to know which way, not how far. When your sword (or your arrow) hits a spider, it gets pushed away from you. The push should be the same strength, whether the spider was close or a bit further away.
Manchmal willst du nur wissen, in welche Richtung, nicht wie weit. Wenn dein Schwert (oder dein Pfeil) eine Spinne trifft, wird sie von dir weggestoßen. Der Stoß soll gleich stark sein, egal ob die Spinne nah war oder etwas weiter weg.
So the game divides the arrow by its own length. The new arrow points the same way, but is exactly 1 long. Then it multiplies by how hard to push:
Also teilt das Spiel den Pfeil durch seine eigene Länge. Der neue Pfeil zeigt in dieselbe Richtung, ist aber genau 1 lang. Dann nimmt es ihn mal, wie fest gestoßen werden soll:
const dx = e.x - p.x, dz = e.z - p.z, l = Math.hypot(dx, dz) || 1;
const push = ...; // how hard: harder when it dies, less for heavy monsters
e.kbx = dx / l * push; e.kbz = dz / l * push;
|| 1 is a safety net: if the spider stood exactly on you, the length would be 0, and dividing by 0 breaks maths.
|| 1 ist ein Sicherheitsnetz: Wenn die Spinne genau auf dir stünde, wäre die Länge 0, und durch 0 teilen macht die Mathe kaputt.
Addresses for whole cubes
Adressen für ganze Würfel
The hero's x and z only say where it is inside its cube. The cubes need addresses too, like house numbers on a street. Every cube has three whole numbers: X, Y and Z.
x und z des Helden sagen nur, wo er in seinem Würfel ist. Die Würfel brauchen auch Adressen, wie Hausnummern in einer Straße. Jeder Würfel hat drei ganze Zahlen: X, Y und Z.
- The town is at
0,0,0. - Die Stadt ist bei
0,0,0. - Y is the floor: 0 at the surface, −1 one depth down, −20 at the core. So the depth is just −Y.
- Y ist das Stockwerk: 0 an der Oberfläche, −1 eine Tiefe weiter unten, −20 am Kern. Die Tiefe ist also einfach −Y.
- The address is written as text, like
'2,-3,1', so it can be used as a name: the world keeps its cubes under these names. - Die Adresse wird als Text geschrieben, wie
'2,-3,1', damit sie als Name dienen kann: Die Welt hebt ihre Würfel unter diesen Namen auf.
D6 lists the six neighbours as arrows: east, west, south, north, down, up. step takes an address and a direction and gives the neighbour's address: parse turns the text into numbers, it adds the arrow, and key turns it back into text.
D6 listet die sechs Nachbarn als Pfeile auf: Osten, Westen, Süden, Norden, unten, oben. step nimmt eine Adresse und eine Richtung und gibt die Adresse des Nachbarn: parse macht aus dem Text Zahlen, dann wird der Pfeil dazugezählt, und key macht wieder Text daraus.
Your maths toolbox
Dein Mathe-Werkzeugkasten
With these few tools, you can read almost every bit of maths in the game:
Mit diesen paar Werkzeugen kannst du fast jedes Stück Mathe im Spiel lesen:
| TOOL | WERKZEUG | ANSWERS | BEANTWORTET | USED FOR | BENUTZT FÜR |
|---|---|---|---|---|---|
x, y, z | where is it? | wo ist es? | everything that moves | alles, was sich bewegt | |
Math.floor(x) | which cell? | welche Zelle? | floors, walls, the minimap | Böden, Wände, die Minikarte | |
b.x − a.x | how do I get there? | wie komme ich hin? | chasing, aiming, falling | Jagen, Zielen, Fallen | |
Math.hypot(dx, dz) | how far? | wie weit? | noticing, biting, picking things up | Bemerken, Beißen, Aufheben | |
Math.atan2(dx, dz) | which way to face? | wohin schauen? | turning, the sword's arc | Drehen, der Bogen des Schwerts | |
dx / length | just the direction | nur die Richtung | pushing, flying fireballs | Stoßen, fliegende Feuerbälle | |
'X,Y,Z' | which cube? | welcher Würfel? | the world, portals, the map | die Welt, Portale, die Karte |