June 2015
Intermediate to advanced
388 pages
7h 31m
English
Implementing our space dust is going to be really quick and easy. All we will do is create a SpaceDust class with very similar properties to our other game objects. Spawn them into the game at a random location, move them toward the player at a random speed, and respawn them on the far right of the screen, again with a random speed and y coordinate.
Then in our TDView class, we can declare a whole array of these objects, update, and draw them each frame.
Create a new class and call it SpaceDust. Now enter this code:
public class SpaceDust { private int x, y; private int speed; // Detect dust leaving the screen private int maxX; private int maxY; private int minX; private int minY; // Constructor public ...Read now
Unlock full access