# Cartesian coordinates in I7

Does anybody happen to have some nice way of working with cartesian (x, y) coordinates in I7?

I did something using a special kind with x and y fields:

``````A cartesian coordinate is a kind of object.
A cartesian coordinate has a number called x.
A cartesian coordinate has a number called y. ``````

I think that will work.

But maybe you can do this with Inform’s units stuff, something like

``````A cartesian coordinate is a kind of value.
(10000, 10000) specifies a cartesian coordinate with parts x and y.``````

But I just can’t figure out how to do that so it allows negative values in a way that actually works and looks decently nice.

Any ideas, anybody?

Or perhaps there already is some code somewhere for “endless” maps with x,y locations of objects?
It feels like somebody must have done this already.

What do you want to do with Cartesian coordinates? My ParserComp entry takes place on a grid and its source code is available. The grid is limited to 18 by 18, partly because I wanted to load it all into a table.

Anyway as far as handling the coordinates goes I just gave everything an x-coordinate property and a y-coordinate property. But I would be happy, nay overly enthusiastic, to talk more about this stuff.

Oooh, nice. I’ll check that out.

My idea was basically an ocean with a few isolated islands, so a very sparse matrix with mostly just water. Normally there would be better ways to navigate than actually going around on that grid, but I thought it would make sense if you could in fact sail using compass directions too. But it sounds hard to make that interesting so maybe I’ll just skip it and just “teleport” between the good spots.

So my idea was to have the player in one Room, but keeping tabs of traveling “inside” the room with rules that fire when the player reaches certain coordinates.

I used lists of numbers for Glimmr, e.g.:

{-10, 10}

Using Inform’s built in units system didn’t quite work for multiple reasons, though I think the primary one was negative numbers.

Anyway, you can find quite a few utility functions for composing and decomposing and doing other things with list-of-numbers coordinate pairs in the Glimmr extensions (primarily Glimmr Drawing Commands, I think).

In Kerkerkruip, we just define coordinates for rooms like this:

```A room has a number called the x-coordinate. [north] A room has a number called the y-coordinate. [east] A room has a number called the z-coordinate. [up]```
And then we have a bunch of phrases like so:

[code]To decide which number is the integer absolute value of (N - a number):
if N is less than 0:
let N be 0 minus N;
decide on N.

To decide which number is the absolute distance between (a - a room) and (b - a room):
let count be 0;
let temp be x-coordinate of a minus x-coordinate of b;
increase count by the integer absolute value of temp;
let temp be y-coordinate of a minus y-coordinate of b;
increase count by the integer absolute value of temp;
let temp be z-coordinate of a minus z-coordinate of b;
increase count by the integer absolute value of temp;
decide on count.[/code]
and so on – you can see more here.

Oblique suggestion: To create the feel of an ocean dotted with islands, maybe use keyword navigation (A la Castle of the Red Prince) instead of directions. Such that you’re sailing by landmarks, following the contours of coastlines or the stretches of island chains.