the vast expanses of space and the universe by fakeyou
You control to ship with the left and right arrow keys and you can shoot with spacebar. The objective is simply to destroy the enemy ships. Please let me know if you encounter any problems.
You first had planet sprites and star sprites and random objects to draw those scrolling. The enemy code is simple, as is the players. There are 2 bullet types, 1 bullet and 2 bullets. You launch 2 bullets, and when it hits something it is destroyed and replaced with a 1 bullet either to the left or right. The bullets are simply yellow lines rendered by applet code. How did I do?
Every entity is placed into a global array with all entity and when the paint method is called the array is sorted on layer specified in each object, the lowest layers are drawn first.
based on the size and position of each entity I make a rectangle of the size and then check every entity nearby to see if it intersects. Every entity keeps a list of items it intersects with. When for example a enemy intersects with a rocket it will create a new entity: an explosion on that location. It will then also add itself and the rocket to another array of 'died' entities. Every tick the died entities are removed from the global entities array.
I hope that makes sense