Facebook
From Red Ostrich, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 86
  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.  
  50.   //starclass draw
  51.   for (int n=0; n < mystarclass.length; n++) {
  52.     mystarclass[n].draw();
  53.   }
  54.  
  55.  
  56.   for (int n=0; n < mylasers.length; n++) {
  57.     mylasers[n].drawme();
  58.     mylasers[n].keyPressed();
  59.     mylasers[n].update();
  60.   }
  61.  
  62.  
  63.  
  64.   playership(1100, mouseY);
  65. }
  66.  
  67. //laser class
  68. public class lasers {
  69.   float x;
  70.   float y;
  71.   float vx;
  72.   float lw;
  73.   float lh;
  74.   color red = color (255, 0, 0);
  75.  
  76.   lasers(float laserx, float lasery, float laserw, float laserh) {
  77.     x = laserx;
  78.     y = lasery;
  79.     lw = laserw;
  80.     lh = laserh;
  81.     vx = -12;
  82.   }
  83.  
  84.   void drawme() {
  85.     noStroke();
  86.     fill(red);
  87.     rect(x, y, lw, lh);
  88.   }
  89.   void keyPressed() {
  90.     if (keyPressed) {
  91.       if (key == ' ') {
  92.         x = xlocation;
  93.         y = ylocation;
  94.         lw = 30;
  95.         lh = 10;
  96.         red = color (255,0,0);
  97.       }
  98.     }
  99.   }
  100.   void update() {
  101.     x += vx;
  102.     if (key == 'a') {
  103.       red = color (random(150, 255), random (150, 255), random (150, 255));
  104.     }
  105.     if (key == 's') {
  106.       lw += 1;
  107.       lh += 1;
  108.     }
  109.   }
  110. }
  111.  
  112. //star class
  113. public class stars {
  114.   float x;
  115.   float y;
  116.   float vx;
  117.   float swidth;
  118.   color white = color(255, 255, 255);
  119.  
  120.   stars(float starx, float stary, float starwidth) {
  121.     x = starx;
  122.     y= stary;
  123.     vx = random (10);
  124.     swidth = starwidth;
  125.   }
  126.  
  127.   void draw() {
  128.     noStroke();
  129.     fill(white);
  130.     square(x, y, swidth);
  131.     x += vx;
  132.    
  133.     //wrap
  134.     if(x > 1300){
  135.       x = 0;
  136.     }
  137.   }
  138. }
  139.