WASD - Move camera Space - Faster camera Scroll - Zoom in/out G - Show asteroid grid E - Spawn ships R - Reset (Reload page to get the pre-made setup) H - Reset camera Click "reset physics speed" if ships stop colliding
SOON TO COME: Missing commands for ships and Upgrades! This uses a combination of things I've learned. RANDOMIZATION: Multiplying a lot of values together then squaring them, then getting the modulo of them is a great pseudo randomization technique. This is used to decide if an asteroid spawns at a grid location or not, so zooming out checks more positions and can lag more, though it's optimized to work well. RENDERING: Each frame, a sprite goes through a grid over the screen and checks valid asteroid positions, stamping the ones that are valid. It saves up to 200 unmodified asteroids for faster rendering too, and permanently saves modified ones. Ships are treated differently. Each frame, it's checked if each ship in memory is in the bounds of the viewing area. COLLISSION: Collision uses a basic particle simulation technique. -Calculate the distance between 2 objects: sqrt(X distance * X distance + Y distance * Y distance) -Calculate their combined radiuses -If distance less then radiuses, proceed: -Magic number = (Radiuses - Distance) / (2 * Distance) -Change the X and Y of each by the X and Y differences multiplied by the magic number, and the objects will move apart until they are exactly touching. This process is done many times per frame to make more realistic repulsion, but to keep the framerate high, my program detects lag and reduces the physics speed. SHIP AI: This is completely homebrewed. Making a memory pool that allowed ships to efficiently store their commands in one list was a headache, and each command is a story of its own.