Facebook
From Commodious Water Vole, 4 Weeks ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 30
  1. float xlocation;
  2. float ylocation;
  3. int laserxv;
  4.  
  5. //starclass
  6. stars[] mystarclass = new stars [100];
  7. //laserclass
  8. lasers[] mylasers = new lasers [1];
  9.  
  10. //custom functions
  11. void playership(float xLoc, float yLoc) {
  12.   xlocation = xLoc;
  13.   ylocation = yLoc;
  14.   noStroke();
  15.   fill(100);
  16.   circle(xLoc, yLoc, 100);
  17.   triangle(xLoc, yLoc - 50, xLoc +50, yLoc - 100, xLoc - 50, yLoc - 100);
  18.   triangle(xLoc, yLoc + 50, xLoc +50, yLoc + 100, xLoc - 50, yLoc + 100);
  19.   fill(50);
  20.   circle(xLoc - 15, yLoc, 75);
  21.   fill(0);
  22.   circle(xLoc - 15, yLoc, 50);
  23. }
  24.  
  25. void setup() {
  26.   size(1280, 720);
  27.   background(0);
  28.  
  29.   //starclass setup
  30.   for (int n = 0; n < mystarclass.length; n++) {
  31.     float newX = random (1280);
  32.     float newY = random (720);
  33.     float newwidth = random (2, 10);
  34.     mystarclass[n] = new stars(newX, newY, newwidth);
  35.   }
  36.  
  37.   //laserclass setup
  38.   for (int n=0; n< mylasers.length; n++) {
  39.     float newX = xlocation;
  40.     float newY = ylocation;
  41.     float newwidth = 30;
  42.     float newheight = 10;
  43.     mylasers[n] = new lasers(newX, newY, newwidth, newheight);
  44.   }
  45. }
  46.  
  47. void draw() {
  48.   background (0);
  49.   //text
  50.   fill(255,255,255);
  51.   text ("Move the Mouse to move the Space Ship", 10, 15);
  52.   text("Press SPACE to shoot lasers and then ...", 10, 35);
  53.   text("Press A to change the laser's color", 10, 55);
  54.   text ("Press B to change the laser's size", 10, 75);
  55.  
  56.   //starclass draw
  57.   for (int n=0; n < mystarclass.length; n++) {
  58.     mystarclass[n].draw();
  59.   }
  60.  
  61.  
  62.   for (int n=0; n < mylasers.length; n++) {
  63.     mylasers[n].drawme();
  64.     mylasers[n].keyPressed();
  65.     mylasers[n].update();
  66.   }
  67.  
  68.  
  69.  
  70.   playership(1100, mouseY);
  71. }
  72.  
  73. //laser class
  74. public class lasers {
  75.   float x;
  76.   float y;
  77.   float vx;
  78.   float lw;
  79.   float lh;
  80.   color red = color (255, 0, 0);
  81.  
  82.   lasers(float laserx, float lasery, float laserw, float laserh) {
  83.     x = laserx;
  84.     y = lasery;
  85.     lw = laserw;
  86.     lh = laserh;
  87.     vx = -12;
  88.   }
  89.  
  90.   void drawme() {
  91.     noStroke();
  92.     fill(red);
  93.     rect(x, y, lw, lh);
  94.   }
  95.   void keyPressed() {
  96.     if (keyPressed) {
  97.       if (key == ' ') {
  98.         x = xlocation;
  99.         y = ylocation;
  100.         lw = 30;
  101.         lh = 10;
  102.         red = color (255,0,0);
  103.       }
  104.     }
  105.   }
  106.   void update() {
  107.     x += vx;
  108.     if (key == 'a') {
  109.       red = color (random(150, 255), random (150, 255), random (150, 255));
  110.       lw = 30;
  111.       lh = 10;
  112.     }
  113.     if (key == 's') {
  114.       lw += 1;
  115.       lh += 1;
  116.       red = color (255,0,0);
  117.     }
  118.   }
  119. }
  120.  
  121. //star class
  122. public class stars {
  123.   float x;
  124.   float y;
  125.   float vx;
  126.   float swidth;
  127.   color white = color(255, 255, 255);
  128.  
  129.   stars(float starx, float stary, float starwidth) {
  130.     x = starx;
  131.     y= stary;
  132.     vx = random (10);
  133.     swidth = starwidth;
  134.   }
  135.  
  136.   void draw() {
  137.     noStroke();
  138.     fill(white);
  139.     square(x, y, swidth);
  140.     x += vx;
  141.    
  142.     //wrap
  143.     if(x > 1300){
  144.       x = 0;
  145.     }
  146.   }
  147. }