- float xlocation;
- float ylocation;
- int laserxv;
- //starclass
- stars[] mystarclass = new stars [100];
- //laserclass
- lasers[] mylasers = new lasers [1];
- //custom functions
- void playership(float xLoc, float yLoc) {
- xlocation = xLoc;
- ylocation = yLoc;
- noStroke();
- fill(100);
- circle(xLoc, yLoc, 100);
- triangle(xLoc, yLoc - 50, xLoc +50, yLoc - 100, xLoc - 50, yLoc - 100);
- triangle(xLoc, yLoc + 50, xLoc +50, yLoc + 100, xLoc - 50, yLoc + 100);
- fill(50);
- circle(xLoc - 15, yLoc, 75);
- fill(0);
- circle(xLoc - 15, yLoc, 50);
- }
- void setup() {
- size(1280, 720);
- background(0);
- //starclass setup
- for (int n = 0; n < mystarclass.length; n++) {
- float newX = random (1280);
- float newY = random (720);
- float newwidth = random (2, 10);
- mystarclass[n] = new stars(newX, newY, newwidth);
- }
- //laserclass setup
- for (int n=0; n< mylasers.length; n++) {
- float newX = xlocation;
- float newY = ylocation;
- float newwidth = 30;
- float newheight = 10;
- mylasers[n] = new lasers(newX, newY, newwidth, newheight);
- }
- }
- void draw() {
- background (0);
- //starclass draw
- for (int n=0; n < mystarclass.length; n++) {
- mystarclass[n].draw();
- }
- for (int n=0; n < mylasers.length; n++) {
- mylasers[n].drawme();
- mylasers[n].keyPressed();
- mylasers[n].update();
- }
- playership(1100, mouseY);
- }
- //laser class
- public class lasers {
- float x;
- float y;
- float vx;
- float lw;
- float lh;
- color red = color (255, 0, 0);
- lasers(float laserx, float lasery, float laserw, float laserh) {
- x = laserx;
- y = lasery;
- lw = laserw;
- lh = laserh;
- vx = -12;
- }
- void drawme() {
- noStroke();
- fill(red);
- rect(x, y, lw, lh);
- }
- void keyPressed() {
- if (keyPressed) {
- if (key == ' ') {
- x = xlocation;
- y = ylocation;
- lw = 30;
- lh = 10;
- red = color (255,0,0);
- }
- }
- }
- void update() {
- x += vx;
- if (key == 'a') {
- red = color (random(150, 255), random (150, 255), random (150, 255));
- }
- if (key == 's') {
- lw += 1;
- lh += 1;
- }
- }
- }
- //star class
- public class stars {
- float x;
- float y;
- float vx;
- float swidth;
- color white = color(255, 255, 255);
- stars(float starx, float stary, float starwidth) {
- x = starx;
- y= stary;
- vx = random (10);
- swidth = starwidth;
- }
- void draw() {
- noStroke();
- fill(white);
- square(x, y, swidth);
- x += vx;
- //wrap
- if(x > 1300){
- x = 0;
- }
- }
- }