//This is a basic class that holds lots of variables and methods that other classes would //normally have in common. //Once you extend and run the super, everything works exactly the same as ever. //The this.'s don't change, the arraylists draw code etc is all the same class Mover { int x, y; float sx, sy, ax, ay; Mover (int a, int b) { this.x = a; this.y = b; this.sx = 0; this.sy = 0; this.ax = 0; this.ay = 0; } void move() { this.sx += this.ax; this.sy += this.ay; this.x += this.sx; this.y += this.sy; } } //This class needs all the information from the Mover class so it can add to that information to be //something better class Ship extends Mover { //Extends tells the system to copy everything from the extended class int health; Ship(int tempx, int tempy, int h) { super(tempx, tempy); //This runs the Constructor from the extended class this.health = h; //Just adding some more info to make Ships better than Movers } void render() { this.move(); //I get to use the move code from Mover! fill(0, 255, 0); rect(this.x, this.y, 50, 10); //Look at all these variables I don't have to declare anymore! if (this.ax > 0) { fill(255, 0, 0); rect(this.x - 10, this.y, 10, 10); } } } class Laser extends Mover { int damage; Laser(int a, int b) { super(a, b); this.sx = 5; this.damage = 5; } void render() { this.move(); stroke(255, 0, 0); line(this.x, this.y, this.x + 20, this.y); for (int i=0; i < badguys.size(); i++) { if (dist(this.x, this.y, badguys.get(i).x, badguys.get(i).y) < 50) { this.x = width; badguys.get(i).health--; } } } } class Enemy extends Mover { int health; Enemy(int a, int b) { super(a, b); this.health = 10; this.sx = -5; this.sy = floor(random(10) - 5); } void render() { this.move(); fill(255, 0, 0); rect(this.x, this.y, 50, 50); } void reset() { this.x = width + 100; this.health = 10; this.y = height /2; this.sy = floor(random(10) - 5); } } Ship player; ArrayList badguys = new ArrayList(); ArrayList lasers = new ArrayList(); void setup() { size(800, 600); player = new Ship(200, 400, 8); badguys.add(new Enemy(width + 100, height /2)); } void draw() { fill(0); rect(0, 0, width, height); if (player.x < mouseX) player.ax = 0.05; else player.ax = -0.1; if (player.y < mouseY) player.ay = 0.05; else player.ay = -0.05; player.render(); for (int i=0; i < badguys.size(); i++) badguys.get(i).render(); for (int i=0; i < badguys.size(); i++) { if (badguys.get(i).health <= 0 || badguys.get(i).x < 0) { badguys.get(i).reset(); } } for (int i=0; i < lasers.size(); i++) lasers.get(i).render(); } void keyPressed() { lasers.add(new Laser(player.x + 50, player.y)); } /* =========== == Part 1 =========== Make 2 classes. 1 class extends from the other. Class 1 Mover: Basic Mover Class 2 Ship: Mover with collision detection and some drawing / visualisation. Add health variable =========== == Part 2 =========== Make a new class called Weapon. Extend it from the Mover class. =========== Part 3 =========== Make an instance of Ship called PLAYER Make arraylist of Ship called enemies Make arraylist of Weapon called lasers On space key add to the lasers list at player coordinates Add controls to the PLAYER =========== Part 4 =========== Make the laser collide with the enemies list. Spawn enemies wherever and constantly so the player doesnt get bored. */