December 2019
Made with Processing

This was a magnet-based platformer that I made off of a platformer engine I had been working on. Huge thanks to my friend for designing all of the art for this game.

The magnet effect feels intuitive, but doesn’t translate so well to video…

I’d attempted platformer engines before, but this one had much better physics, and used a relatively simple text-based storage system to create and load levels. This made it a lot easier to prototype gameplay and levels.

The bare bones platforming engine.
g 0 32
t 0 96 64 128
0 496
t 0 544 256 608
t 192 96 576 128
t 384 400 416 544
t 384 544 800 608
t 576 96 608 440
t 750 0 800 700
t 270 470 350 480

This is an example of what the level data text files would look like. The “g” means that the coordinates are for the goal, and the “t” means they’re for terrain. The unmarked third line is the spawn location of the player.

The core mechanic of the game was the idea that the player was an electromagnetic box that could switch polarity at the press of a button. Levels were composed of magnetic obstacles that required switching polarity at the right moments to traverse to the goal.

To simulate the magnetism, I used a force-based physics system which applied a cubic decay on the magnets as the player got farther away.

MagnetCircle mc = (MagnetCircle) m;
float distance = dist(pos.x,pos.y,mc.center.x,mc.center.y);
if(distance < mc.radius){ 
    //if you collide with magnet circle
    PVector force = new PVector(0,0);
    force.x = (mc.center.x-pos.x)/mc.radius;
    force.y = (mc.center.y-pos.y)/mc.radius;
        
    distance /= mc.radius;
    distance = 1-distance;
    distance = map(distance,0,1,m.domain.x,m.domain.y);
    force.x *= m.strength*(pow(distance,3));
    force.y *= m.strength*(pow(distance,3));

    //if on surface, don't push into the surface of magnet
    if(onSurface == 1 && force.y < gravity){
        force.y = 0;
    }
    
    //check player polarity with magnet
    if(polarity == m.polarity){
        //repel (negative force)
        vel.x -= force.x;
        vel.y -= force.y;
    }
    else{
        //attract
        vel.x += force.x;
        vel.y += force.y;
    }
}

I think there was more potential in this idea than I gave it credit for. Perhaps one day, I’ll come back and revamp this to a full-fledged game.