//Ship: position, speed, ability to draw and move, color, health, inventory class Ship { float x, y, sx, sy; //Physics variables to move and stuff int red, green, blue; //The rgb for the colour of the ship int targX, targY; //Target coordinates to home in on int health; //The health of the ship, its unsed right now because the game is simple-ish so far int timer; //Timer that counts down so the ship get new target coordinates ArrayList inventory; //Unsed inventory system, again just not implemented yet //Constructor, rember it must be the same name as the class Ship (float a, float b) { //I used a and b as temp variables so the ship location can be assigned when we instaniate the ship this.x = a; this.y = b; this.sx = 0; //Default speeds of 0 this.sy = 0; this.health = 100; //Default health this.inventory = new ArrayList(); //Default empty inventory this.red = 100; //Default gray colour this.green = 100; this.blue = 100; this.targX = width/2; //Default target coordinates this.targY =height/2; this.timer = 200; //Default timer } void render() { fill(this.red, this.green, this.blue); //Set the colour rect(this.x, this.y, 50, 50); //Draw the ship //Count down and get a new target location if (this.timer < 0) { this.timer = 200 + rando(100); //Reset the timer this.targX = rando(width); //Get those new coordinates this.targY = rando(height); } else timer--; //Count down the timer //Home in on the target coordinates //By adding to the sx, sy variables we get a smooth acceleration for the movement if (this.x < this.targX) this.sx += 0.5; else if (this.x > this.targX) this.sx -= 0.5; if (this.y < this.targY) this.sy += 0.5; else if (this.y > this.targY) this.sy -= 0.5; //Set the maximum speeds so they don't go off the screen so much if (this.sx > 3) this.sx = 3; else if (this.sx < -3) this.sx= -3; if (this.sy > 3) this.sy = 3; else if (this.sy < -3) this.sy= -3; //Actually apply the speed now that all the other code has set the values this.x += this.sx; this.y += this.sy; stroke(255, 0, 0);//Set a line colour line(this.targX, this.targY, this.x, this.y); //Draws a line from the target coordinates to the ship } void paintJob(int r, int g, int b) { //Lets us set the colour this.red = r; this.blue = b; this.green = g; } } //Declares the array of ships Ship[] ships = new Ship[10]; //We picked 10 of them because reasons. void setup() { size(500, 500); //Size of screen for (int i=0; i < 10; i++) { //For all 10 ships ships[i] = new Ship(random(width), random(height)); //Make a ship ships[i].paintJob(rando(255), rando(255), rando(255)); //Give it a cool colour } } //I need this function in so many programs because random integers are useful int rando(int n) { return floor(random(n)); } //Entire game engine void draw() { background(0); //Make the background black like space for (int i=0; i < 10; i++) ships[i].render(); //Tells the ships to do their thing! } Build a class called Note ==> int x,y, sy ==> render code to draw and move the note down ==> if the y goes greater than height, set it to zero, and randomize the x -> create and operate 4 Notes