Nerdy creations with numbers, words, sounds, and pixels

Games, Science

PN Trajectory

PN Trajectory (polynomial trajectory) - 2D math learning game by Anton Hoyer

“PN Trajectory,” with “PN” standing for “polynomial,” is an educational game designed to alleviate anxiety in people who view math as their adversary ever since numbers were replaced by letters. Specifically, as a player, you control a cannon and need to shoot at a target, which strangely resembles the Royal Air Force roundel. The challenge: there are obstacles in the way, so you need to shoot around them using polynomial trajectories—because math is magic.

To provide an example, polynomials are mathematical functions that take this form:

y = a · x² + b · x + c

This simple quadratic equation includes the vertical coordinate y in relation to the horizontal coordinate x, where x has 2 as the highest exponent. It also involves the polynomial coefficients a, b, and c, significantly influencing the shape of the curve. The number of coefficients always matches the highest exponent (or the “degree” of the polynomial) plus one, and your task is to adjust all coefficients so that the missile’s trajectory avoids all obstacles.

Quadratic missile trajectory

The game is played solely with a mouse, requiring you to click on the button of a specific coefficient and use the vertical slider to set its value. Alternatively, you can scroll the mouse wheel while hovering over a button for precise adjustments.

The first levels are straightforward, starting with a constant (no x, coefficient 0), then a line (x, coefficients 0 and 1), then a quadratic function (, coefficients 0, 1, and 2), then a cubic function (, coefficients 0, 1, 2, and 3), all the way to a degree of 5, which is quite challenging as each additional coefficient significantly affects the curve. But do not worry, these are rare, and all subsequent levels are randomly generated. However, the number of obstacles also increases with each level, giving you a lower chance of finding trivial solutions.

I created the ideal trajectories in MATLAB because finding curves that fit the screen without leaving it is much easier to do numerically than analytically. The coefficients of thousands of valid polynomials were then imported into the actual game, programmed in the Processing coding language. The obstacles for each level are dynamically built by a rectangular grid, one block at a time, halting the creation of the current obstacle if they collide with the boundaries or the ideal trajectory. This method reliably fills the map and leaves an irregularly shaped corridor for the missile.

To motivate you, hitting the target is accompanied by an explosion and an affirmation such as “ATTABOY!” or “BULL’S EYE!,” and your score increases according to the polynomial degree. As a penalty for being too slow, the score is continuously decreased by one point per second.

Difficult level with degree 5 beaten

The colors of the obstacles are varied, but since I used the HSB system (hue, saturation, brightness) with a varying degree of randomness, you often see color palettes that work well. I also added an Easter egg, projecting the code of the game itself onto the obstacles if your score reaches zero after a certain level.

Because working with polynomials can be unintuitive at first, I also integrated a help button, although using it costs you additional score points. Simply hovering over it will display plus or minus symbols, depending on whether your coefficients are set too low or too high. Clicking it will even show the exact positions on the sliders that you need to set. Naturally, I also integrated a cheat mode in which you can skip a level or auto-tune your trajectory, but I will leave it up to you to discover.

Assisted aiming with improved sliders

My friend Daniel also created a wonderful sci-fi soundtrack the game would be hard to imagine without now. Unfortunately, it still contains a bug, causing the audio to stutter after about ten minutes of playtime, which likely has to do with how Processing handles multiple concurrent audio tracks. After I fix this bug, I will upload it to itch.io for your personal enjoyment.

← Return to “Graphical”

← Return to “Games”

Leave a Reply