New Game (with Code Available to Edit)

edited September 2016 in Share Your Work

I have made a new game, called Invasion Evasion. It does not work well at all online (but you can still see it at http://bleubox.altervista.org/InvasionEvasion.html), but it is available to download at the bottom of this webpage: http://bleubox.altervista.org/productions.html . The downloadable version is far better than the online one. Below, in mutiple comments (the code is very long) , I have posted its code if you would like to edit it in Processing.

Comments

  • import ddf.minim.*;
    Minim minim;
    AudioPlayer player;
    ArrayList penguins;
    ArrayList hsb2s;
    ArrayList planes;
    PVector[] pLocs = {new PVector(1850, 250), new PVector(3400, 50), new PVector(3300, 50), new PVector(3500, 50), new PVector(3600, 50), new PVector(3800, 50), new PVector(3900, 50), new PVector(5150, -300), new PVector(6050, -850), new PVector(6100, -850), new PVector(6150, -850), new PVector(6200, -850), new PVector(6250, -850), new PVector(6300, -850), new PVector(6350, -850), new PVector(6400, -850), new PVector(6450, -850), new PVector(700, -750), new PVector(850, -750), new PVector(825, -1000), new PVector(1600, -850), new PVector(1700, -350), new PVector(2150, -950), new PVector(2950, -1150), new PVector(2980, -1150), new PVector(3610, -1050), new PVector(3700, -1050), new PVector(4070, -1450), new PVector(3900, -1050), new PVector(4000, -1050), new PVector(4600, -2050), new PVector(5650, -3000), new PVector(6500, -2250), new PVector(6650, -2250), new PVector(6700, -2250), new PVector(6500, -4200), new PVector(5900, -4050), new PVector(5200, -1350), new PVector(5300, -1350), new PVector(4200, -4030), new PVector(4100, -4030), new PVector(3400, -5050), new PVector(2500, -4350), new PVector(1900, -4150), new PVector(1500, -3350), new PVector(250, -3250), new PVector(350, -3250)};                                                  
    PVector[] hLocs = {/*new PVector(2700, 225),*/ new PVector(3700, 50), /*new PVector(4000, 675),*/ new PVector(4600, -225), /*new PVector(4800, -225),*/ /*new PVector(5400, -450), new PVector(5400, -400), new PVector(5400, -350), new PVector(5400, -300),*/ new PVector(2549, -1030), /*new PVector(4192, -1730),*/ new PVector(5520, -2130), /*new PVector(6500, -2030),*/ new PVector(4927, -3730), /*new PVector(3880, -4530),*/ new PVector(831, -3150), /*new PVector(1770, -3750),*/ new PVector(2870, -4350)}; 
    PVector[] aLocs = {new PVector(6000, -4055), new PVector(1340, 500), new PVector(3000, 95), new PVector(3100, 95), new PVector(3200, 95), new PVector(5050, -105), new PVector(600, -1005)};
    PFont sFont;
    Ninja n;
    float[] limitsX = {0, 250, 550, 850, 1150, 1450, 1750, 2050, 2350, 2650, 2950, 3250, 3550, 3850, 4150, 4450, 4750, 5050, 5350, 5650, 5950, 6250, 6550};
    float[] tXList = {300, 0, -300, -600, -900, -1200, -1500, -1800, -2100, -2400, -2700, -3000, -3300, -3600, -3900, -4200, -4500, -4800, -5100, -5400, -5700, -6000, -6300}; 
    float[] limitsY = {151, 50, -250, -550, -850, -1150, -1450, -1750, -2050, -2350, -2650, -2950, -3250, -3550, -3850, -4150, -4450, -4750, -5050, -5350, -5650};
    float[] tYList = {0, 300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900, 4200, 4500, 4800, 5100, 5400, 5700};
    float tX = 0;
    float tY = 0;
    boolean alive = true;
    void setup() {
     size(600, 600);
     minim = new Minim(this);
     player = minim.loadFile("Synth(etic) Meatmp3.mp3", 2048);
     sFont = loadFont("SegoePrint-Bold-48.vlw");
     n = new Ninja("Ninja", new PVector(0, 300));
     planes = new ArrayList();
     for(int j= 0; j < aLocs.length; j++) planes.add(new Airplane(aLocs[j], "Airplane_" + j));
     penguins = new ArrayList();
     for(int i = 0; i < (pLocs.length); i++) penguins.add(new Penguin("Penguin_" + i, pLocs[i], int(random(100, 300)), random(0, 1000), int(random(10000))));
     hsb2s = new ArrayList();
     for(int h = 0 ; h < hLocs.length; h++) hsb2s.add(new Hsb2(hLocs[h]));
    }
    void draw() {
    player.play();
    println(player.position(), player.length());
    if(player.position() >= 62040) player.loop();
    PVector[] pLocRefs = {new PVector(1850, 250), new PVector(3400, 50), new PVector(3300, 50), new PVector(3500, 50), new PVector(3600, 50), new PVector(3800, 50), new PVector(3900, 50), new PVector(5150, -300), new PVector(6050, -850), new PVector(6100, -850), new PVector(6150, -850), new PVector(6200, -850), new PVector(6250, -850), new PVector(6300, -850), new PVector(6350, -850), new PVector(6400, -850), new PVector(6450, -850), new PVector(700, -750), new PVector(850, -750), new PVector(825, -1000), new PVector(1600, -850), new PVector(1700, -350), new PVector(2150, -950), new PVector(2950, -1150), new PVector(2980, -1150), new PVector(3610, -1050), new PVector(3700, -1050), new PVector(4070, -1450), new PVector(3900, -1050), new PVector(4000, -1050), new PVector(4600, -2050), new PVector(5650, -3000), new PVector(6500, -2250), new PVector(6650, -2250), new PVector(6700, -2250), new PVector(6500, -4200), new PVector(5900, -4050), new PVector(5200, -1350), new PVector(5300, -1350), new PVector(4200, -4030), new PVector(4100, -4030), new PVector(3400, -5050), new PVector(2500, -4350), new PVector(1900, -4150), new PVector(1500, -3350), new PVector(250, -3250), new PVector(350, -3250)};                                                  
    PVector[] hLocRefs = {/*new PVector(2700, 225),*/ new PVector(3700, 50), /*new PVector(4000, 675),*/ new PVector(4600, -225), /*new PVector(4800, -225),*/ /*new PVector(5400, -450), new PVector(5400, -400), new PVector(5400, -350), new PVector(5400, -300),*/ new PVector(2549, -1030), /*new PVector(4192, -1730),*/ new PVector(5520, -2130), /*new PVector(6500, -2030),*/ new PVector(4927, -3730), /*new PVector(3880, -4530),*/ new PVector(831, -3150), /*new PVector(1770, -3750),*/ new PVector(2870, -4350)}; 
    PVector[] aLocRefs = {new PVector(6000, -4055), new PVector(1340, 500), new PVector(3000, 95), new PVector(3100, 95), new PVector(3200, 95), new PVector(5050, -105), new PVector(600, -1005)};
     background(250);
     for(int i = 0; i < limitsX.length; i++) if(n.loc.x >= limitsX[i] && n.loc.x <= limitsX[i] + 100) tX = tXList[i];
     for(int i = 0; i < limitsY.length; i++) if(n.loc.y <= limitsY[i] && n.loc.y >= limitsY[i] - 100) tY = tYList[i];
     //
     textFont(sFont);
     textSize(80);
     fill(1);
     text("INVASION EVASION", -100 + tX, 200 + tY);
     textSize(18);
     fill(49, 91, 179);
     text("A BLEU BOX Game", 300 + tX, 250 + tY);
     fill(1);
     //link("< How to Play", 0 + tX, 400 + tY);
     textSize(48);
     text("This Way to Play >", 50 + tX, 400 + tY);
     textSize(20);
     text("Keep going!!! You can do it!!! >>>", 800 + tX, 400 + tY);
     textSize(10);
     text("This is not a \n real Penguin. >", -250 + tX, 550 + tY);
     stroke(1);
     fill(#C65672);
     pushMatrix();
     translate(tX - 150, tY + 547);
     beginShape();
        vertex(-3, 32);
        vertex(0, 31);
        vertex(0, 36);
        vertex(-3, 36.5);
        endShape(CLOSE);
        beginShape();
        vertex(20, 31);
        vertex(23, 32);
        vertex(23, 36.5);
        vertex(20, 36);
        endShape(CLOSE);
        //fill(240);
        rect(0, 0, 20, 40);
        fill(#C65672);
        rect(1, 40, 5, 2);
        rect(14, 40, 5, 2);
        noStroke();
        rect(1, 1, 19, 9);
        rect(1, 21, 19, 15);
        stroke(1);
        point(9, 7);
        point(17, 5); 
        popMatrix();
     //
     fill(#F7F2B9);
     stroke(2);
    //This is where you add platforms
     rect(-300 + tX, 590 + tY, 1700, 10);
     rect(0 + tX, -5650 + tY, 1400, -5650);
     rect(1400 + tX, 10 + tY, 400, 690);
     rect(1320 + tX, 550 + tY, 80, 40);
     rect(1800 + tX, 300 + tY, 400, 300);
     rect(2200 + tX, 250 + tY, 600, 350);
     rect(2600 + tX, 200 + tY, 100, 50);
     rect(2800 + tX, 500 + tY, 100, 100);
     rect(2900 + tX, 100 + tY, 50, 500);
     rect(2950 + tX, 150 + tY, 500, 450);
     rect(3450 + tX, 580 + tY, 1050, 20);
     rect(4500 + tX, -200 + tY, 500, 800);
     rect(5100 + tX, -250 + tY, 100, 850);
     rect(5200 + tX, -300 + tY, 100, 900);
     rect(5300 + tX, -350 + tY, 100, 950);
     rect(5400 + tX, -250 + tY, 25, 850);
     rect(5425 + tX, -400 + tY, 75, 1000);
     rect(5500 + tX, -450 + tY, 100, 1050);
     rect(5600 + tX, -500 + tY, 100, 1100);
     rect(5700 + tX, -550 + tY, 1200, 1150);
     rect(6000 + tX, -800 + tY, 500, 25); 
     //
     fill(#E33E54);
     rect(-300 + tX, -800 + tY, 100, 25);
     rect(0 + tX, -700 + tY, 500, 500); 
     rect(500 + tX, -650 + tY, 700, 450);
     rect(600 + tX, -950 + tY, 100, 25);
     rect(1200 + tX, -725 + tY, 200, 475);
     rect(1100 + tX, -900 + tY, 100, 25);
     rect(800 + tX, -925 + tY, 100, 25);
     rect(1400 + tX, -800 + tY, 500, 200);
     rect(1500 + tX, -300 + tY, 400, 25);
     rect(2050 + tX, -900 + tY, 200, 500);
     rect(2400 + tX, -1000 + tY, 200, 500);
     rect(2750 + tX, -1100 + tY, 500, 200);
     rect(3300 + tX, -900 + tY, 800, 25);
     rect(3500 + tX, -1000 + tY, 800, 25);
     rect(4300 + tX, -2000 + tY, 500, 1025);
     rect(4000 + tX, -1400 + tY, 200, 25);
     rect(4100 + tX, -1700 + tY, 200, 25);
     rect(5000 + tX, -2050 + tY, 500, 500);
     rect(5100 + tX, -1300 + tY, 400, 25);
     rect(5500 + tX, -2100 + tY, 100, 500);
     rect(5600 + tX, -2050 + tY, 100, 500);
     rect(5700 + tX, -2100 + tY, 100, 500);
     rect(5800 + tX, -2200 + tY, 50, 600); 
     rect(5850 + tX, -2000 + tY, 1050, 600);
     rect(6350 + tX, -2200 + tY, 550, 25);
     rect(2500 + tX, -2300 + tY, 100, 25);
     rect(2300 + tX, -2100 + tY, 100, 25);
     rect(2100 + tX, -1900 + tY, 100, 25);
     rect(1900 + tX, -1700 + tY, 100, 25);
     rect(1700 + tX, -1500 + tY, 100, 25);
     rect(1500 + tX, -1300 + tY, 100, 25);
     rect(1300 + tX, -1100 + tY, 100, 25);
     //
     fill(#3EB0E3);
     rect(6400 + tX, -4150 + tY, 200, 25);
     rect(5800 + tX, -4000 + tY, 500, 500);
     rect(5600 + tX, -4050 + tY, 200, 550);
     rect(5200 + tX, -3500 + tY, 600, 50);
     rect(5300 + tX, -3000 + tY, 500, 25);
     rect(5100 + tX, -3500 + tY, 50, 50);
     rect(5000 + tX, -3600 + tY, 50, 50); 
     rect(4900 + tX, -3700 + tY, 50, 50);
     rect(4800 + tX, -3800 + tY, 50, 50);
     rect(4700 + tX, -3900 + tY, 50, 50);
     rect(4000 + tX, -4000 + tY, 600, 600); 
     rect(3800 + tX, -4500 + tY, 200, 1100);
     rect(3700 + tX, -3500 + tY, 100, 25);
     rect(3500 + tX, -3300 + tY, 100, 25);
     rect(3300 + tX, -3100 + tY, 100, 25);
     rect(3100 + tX, -2900 + tY, 100, 25);
     rect(2900 + tX, -2700 + tY, 100, 25);
     rect(2700 + tX, -2500 + tY, 100, 25);
     rect(3200 + tX, -5000 + tY, 500, 1300);
     rect(3000 + tX, -3000 + tY, 200, 100);
     //rect(3000, tX, -3050 + tY, 100, 100);//
     rect(2800 + tX, -4300 + tY, 200, 600);
     rect(2400 + tX, -4300 + tY, 250, 25);
     rect(2200 + tX, -4000 + tY, 200, 600);
     rect(1800 + tX, -4100 + tY, 400, 400);
     rect(1600 + tX, -3700 + tY, 400, 400);
     rect(1400 + tX, -3300 + tY, 400, 400);
     rect(1000 + tX, -3000 + tY, 400, 400);
     rect(500 + tX, -3100 + tY, 400, 400);
     rect(0 + tX, -3200 + tY, 500, 400);
     //
     fill(#A461DB);
     rect(-1, -5700 + tY, 601, 50);
     rect(0 + tX, -5000 + tY, 100, 25);
     rect(1000 + tX, -4800 + tY, 100, 25);
     rect(1300 + tX, -4500 + tY, 100, 25);
     rect(1800 + tX, -5300 + tY, 100, 25);
     rect(2100 + tX, 5000 + tY, 100, 25);
     rect(2600 + tX, 5500 + tY, 100, 25);
     rect(3000 + tX, 4700 + tY, 100, 25);
     rect(3500 + tX, 4400 + tY, 100, 25);
     rect(4000 + tX, 4500 + tY, 100, 25);
     rect(4200 + tX, 5100 + tY, 100, 25);
     rect(4700 + tX, 4900 + tY, 100, 25);
     rect(5100 + tX, 5400 + tY, 100, 25);
     //
    
  •  noStroke();
     fill(#7C2CA7);
     rect(10, 100, 5, -player.position()/1000);
     //
     n.run();
     for(Penguin p : penguins) {
       p.run();
       p.setDirection(n);
       //if(p.loc.y + tY >= 50 && p.loc.y + tY <= -50 && p.riding || p.loc.y + tY >= 700 && p.loc.y + tY <= 550) p.vel.y = 3;
       if(dist(n.loc.x + tX, n.loc.y + tY, p.loc.x + tX, p.loc.y + tY) <= 35) alive = false;
       for(Laser l : p.lasers) if(dist(n.loc.x + tX, n.loc.y + tY, l.loc.x + tX, l.loc.y + tY) <= 10) alive = false;
     }
     for(Hsb2 h : hsb2s) {
      h.display();
      h.update(n);
      h.setDirection(n);
      if(dist(n.loc.x + tX, n.loc.y + tY, h.loc.x + tX, h.loc.y + tY) <= 25) alive = false;
     }
     for(Airplane a : planes) {
       a.display();
     }
     for(Penguin p : penguins) {/**This loop requires one or more penguin to run.**/
       for(Airplane a : planes) {
     if(dist(p.loc.x + tX, p.loc.y + tY, a.loc.x + tX, a.loc.y + tY) < 30 && (a.riderID == "" || a.riderID == p.pilotName) && p.stage > 0) {
       a.riderCount++;
       a.rider = true;
       a.riderID = p.pilotName;
       p.loc.x = (a.loc.x + 2.99995);
       p.loc.y = (a.loc.y - 20);
       p.riding = true;
       p.planeID = a.ID;
       a.update(p);
     }
     else if(dist(n.loc.x + tX, n.loc.y + tY, a.loc.x+ tX, a.loc.y + tY) < 30 && (a.riderID == "" || a.riderID == n.pilotName)) {
       a.riderCount++;
       a.rider = true;
       a.riderID = n.pilotName;
       n.loc.x = a.loc.x + 15;
       n.loc.y = a.loc.y - 10;
       n.riding = true;
       n.planeID = a.ID;
       a.update(n);
     }
     else {
       p.riding = false;
       p.planeID = "";
       n.riding = false;
       n.planeID = "";
       a.rider = false;
       a.dis = ' ';
       a.riderID = "";
       a.ae = false;
       a.aw = false;
       a.an = false;
       a.as = false;
       a.vel.x = 0;
     }
       }
     }
     if(!alive) {
       for(int i = 0; i < planes.size(); i++) {
        Airplane a = planes.get(i); 
        a.loc = aLocRefs[i];
       }
       for(int i = 0; i < penguins.size(); i++) {
        Penguin p = penguins.get(i);
        p.stage = 0;
        p.loc = pLocRefs[i];
       }
       for(int i = 0 ; i < hsb2s.size(); i++) {
        Hsb2 h = hsb2s.get(i); 
        h.loc = hLocRefs[i];
       }
       n.loc = new PVector(0, 3+00);
       alive = true;
     }
    }
    class Pilot {
      String pilotName;
      boolean n, e, s, w;
      boolean riding;
      String planeID;
      Pilot(String name) {
       pilotName = name; 
      }
      void display() {}
      void update() {}
      void run() {
       display();
       if(!riding) update();
      }
    }
    class Hsb2 {
      PVector loc, vel;
      boolean n, e, s, w;
      float range = random(100, 1000);
      Hsb2(PVector loc_) {
        loc = loc_;
        vel = new PVector(0, 0);
      }
      void display() {
        pushMatrix();
        translate(loc.x + tX, loc.y + tY);
        stroke(1);
        fill(255);
        rect(0, 0, 15, 15);
        fill(1);
        if(e || w) {
        point(2, 2);
        point(13, 2);
        line(0, 4, 15, 4);
        } 
        else {
         point(2, 11);
         point(13, 11);
         line(0, 13, 15, 13);
        }
        popMatrix();
      }
      void update(Ninja ninja) {
      vel.y = (abs(vel.x) > 0 && n? -abs(vel.x/5) : abs(vel.x) > 5? abs(vel.x/5) : 0);
      if(vel.x == 0 && get(int((loc.x + tX) - 2), int((loc.y + tY) + 15)) == color(250) && get(int((loc.x + tX) + 17), int((loc.y + tY) + 15)) == color(250)) vel.y = 1;
      loc.add(vel);
      vel.limit(10);
      if(w && get(int(loc.x + tX) - 2, int(loc.y + tY)) == color(250) && get(int(loc.x + tX) - 2, int((loc.y + tY) + 17)) == color(250) || w && get(int(loc.x + tX) - 2, int(loc.y + tY)) == 0 && get(int(loc.x + tX) - 2, int(loc.y + tY) + 17) == 0) vel.x = -3;
      else if(e && get(int(loc.x + tX) + 17, int(loc.y + tY)) == color(250) && get(int(loc.x + tX) + 17, int(loc.y + tY) + 17) == color(250)|| e && get(int(loc.x + tX) + 17, int(loc.y + tY)) == 0 && get(int(loc.x + tX) + 17, int(loc.y + tY) + 17) == 0) vel.x = 3;
      else vel.x = 0;
      }
      void setDirection(Ninja n) {
        if((n.loc.x + tX) > loc.x + tX && abs((n.loc.x + tX) - (loc.x + tX)) < range) {
          e = true;
          w = false;
        }
        else if((n.loc.x + tX) < loc.x + tX && abs((n.loc.x + tX) - (loc.x + tX)) < range) {
        w = true;
        e = false;
        }
        if(n.loc.y + tY > loc.y + tY && abs((n.loc.y + tY) - (loc.y + tY)) < range) {
         this.n = false;
         s = true;
        } else if(n.loc.y + tY < loc.y + tY && abs((n.loc.y + tY) - (loc.y + tY)) < range) {
          s = false;
         this.n = true;
        } else if(abs(dist((n.loc.x + tX), n.loc.y + tY, loc.x + tX, loc.y + tY)) > range) {
          e = false;
          w = false;
          this.n = false;
          s = false;
        }
        if(loc.x + tX == n.loc.x + tX) {
         w = false;
         e = false;
        }
        if(loc.y + tY == n.loc.y + tY) {
         this.n = false;
         this.e = false;
        }
      }
    }
    class Penguin extends Pilot {
      ArrayList lasers = new ArrayList();
      PVector loc, vel;
      color[] fills = {255, #F7F2B9/*yellow*/, #F2DC5A/*yellow-orange*/,  #E0A4E8/*pink*/, #A461DB/*purple*/, #E33E54/*red*/, #3EB0E3/*blue*/}; //normal, can jump, can fly, speed increase, can use lasers on planes, range increase, can use lasers anywhere
      color strokeColor;
      boolean jump = false, standing = true, grav = false;
      boolean rand = false;
      int stage = 0;
      float yInc = 2, a = 2;
      float range;
      float nvRange;
      float noiseOff, countOff;
      float type = random(1);
      Penguin(String name, PVector loc_, float r, float noiseOff_, float countOff_) {
       super(name);
       loc = loc_;
       vel = new PVector(1, 1);
       range = r;
       nvRange = r;
       noiseOff = noiseOff_;
       countOff = countOff_;
      }
      void display() {
       if(int(random(10000)) == 99 && stage <= 5) stage++;
       if(stage >= 5) range++;
       if((frameCount + countOff) % 60 == 0 && !rand && stage >= 6 || (frameCount + countOff) % 120 == 0 && !rand && stage >= 4 && stage <= 5) lasers.add(new Laser(new PVector(loc.x, loc.y), (e? 'e' : 'w')));
       for(Laser l : lasers) l.run();
        if(stage == 0) fill(255);
        if(type > 0.999999 && stage > 0) {
          stroke(fills[stage]);
          fill(255);
          strokeColor = fills[stage];
        } else {
          stroke(1);
          fill(fills[stage]);
          strokeColor = 1;
        }
        pushMatrix();
        translate(loc.x + tX, loc.y + tY);
        beginShape();
        vertex(-3, 32);
        vertex(0, 31);
        vertex(0, 36);
        vertex(-3, 36.5);
        endShape(CLOSE);
        beginShape();
        vertex(20, 31);
        vertex(23, 32);
        vertex(23, 36.5);
        vertex(20, 36);
        endShape(CLOSE);
        rect(0, 0, 20, 40);
        rect(1, 40, 5, 2);
        rect(14, 40, 5, 2);
        if(e || !e && !w) {
        point(9, 7);
        point(17, 5);
        } 
        if(w) {
        point(7, 5);
        point(15, 7);
        }
        popMatrix();
      }
      void update() {
      if(int(random(100)) >= 7 && int(random(100)) <= 7 + stage && stage > 0 && loc.y > 0) jump = true;
       if (jump) {
        grav = false;
        yInc--;
        loc.y -= yInc/2;
      } 
      if (grav) {
        loc.y += a;
        a += 0.1;
      } 
      if (standing) grav = false;
      else if (!standing) grav = true;
      if(get(int(loc.x + tX), int((loc.y + tY) + 47/**<-important!*/)) != color(250) && get(int(loc.x + tX), int((loc.y + tY) + 47/**<-important!*/)) != color(strokeColor)) {
        grav = false;
        standing = true;
        jump = false;
        yInc = 20;
      } else standing = false;
      if(get(int(loc.x + tX), int(loc.y + tY - 10)) != color(250) && yInc >= 0) vel.y = 1;
      vel.x = ((e && get(int((loc.x + tX) + 26), int(loc.y + tY)) == color(250))? (int(rand) == 1? 0.3 : 1)*(stage >= 3? 3.5 : 2) : 0) - ((w && get(int((loc.x + tX) - 6), int(loc.y + tY)) == color(250))? (int(rand) == 1? 0.3 : 1)*(stage >= 3? 3.5 : 2) : 0);
      vel.y = (s? 0 : 0) - (n? 0 : 0);//important!
      loc.add(vel);
      }
      void run() {
       super.run(); 
      }
      void setDirection(Ninja n) {
        if(riding) range = 300000;
        else range = nvRange;
        if(n.loc.x + tX > loc.x + tX && abs((n.loc.x + tX) - (loc.x + tX)) < range) {
          e = true;
          w = false;
          rand = false;
        }
        else if(n.loc.x + tX < loc.x + tX && abs((n.loc.x + tX) - (loc.x + tX)) < range) {
        w = true;
        e = false;
        rand = false;
        } else if((n.loc.x + tX) == (loc.x + tX) || abs((n.loc.x + tX) - (loc.x + tX)) > range) {
         if(noise((frameCount/10) + noiseOff) >= 0.7 && noise((frameCount/10) + noiseOff) <= 1.0) {
          w = true;
          e = false;
         } else if(noise((frameCount/10) + noiseOff) < 0.3 && noise((frameCount/10) + noiseOff) >= 0.09) {
           e = true;
           w = false;
           rand = true;
         } else {
          e = false;
          w = false;
          rand = true;
         }
        }
        if((loc.x + tX) == (n.loc.x + tX)) {
         e = false;
         w = false;
        }
        if(n.loc.y + tY > loc.y + tY && abs((n.loc.y + tY) - (loc.y + tY)) < range) {
          s = true;
          this.n = false;
        } else if(n.loc.y + tY < loc.y + tY && abs((n.loc.y + tY) - (loc.y + tY)) < range) {
          this.n = true;
          s = false;
        }
        if(n.loc.y + tY == loc.y + tY) {
         s = false;
         this.n = false;
        }
      }
    }
    
  • edited September 2016
    class Ninja extends Pilot {
      PVector loc, vel;
      boolean jump = false, standing = true, grav = false;
      float yInc = 20, a = 0.1;//yInc controls jump height; a controls falling speed.
      Ninja(String name, PVector loc_) {
       super(name); 
       loc = loc_;
       vel = new PVector(0, 0);
      }
      void display() {
        pushMatrix();
        translate(loc.x + tX, loc.y + tY);
        fill(1);
        stroke(1);
        ellipse(0, 0, 10, 10);
        rect(-3, 5, 6, 10);
        noFill();
        bezier(-3, 10, -3, 10, -3, 30, -3, 25);
        bezier(3, 10, 3, 10, 3, 30, 3, 25);
        bezier(-3, 5, -3, 5, -5, 15, -5,15);
        bezier(3, 5, 3, 5, 5, 15, 5,15);
        fill(255);
        rect(-5, -2, 10, 4);
        fill(0);
        point(-(e? 1 : w? 4 : 3) , 0);
        point((e? 4 : w? 1 : 3), 0);
        popMatrix();
      }
      void update() {
       if(n && (jump == false) && (grav == false)) jump = true;
       if (jump) {
        grav = false;
        yInc -= 1;
        loc.y -= yInc;
      } 
      if (grav) {
        loc.y += a;
        a += 0.1;
      } 
      if (standing) grav = false; 
      else if (!standing) grav = true;
      if(get(int(loc.x + tX) - 6, int((loc.y + tY) + (30))) != color(250) && get(int(loc.x + tX) - 6, int((loc.y + tY) + (30))) != color(1)) {
        grav = false;
        standing = true;
        jump = false;
        yInc = 20;
        a = 0.1;
      } else standing = false;
      vel.x = ((e && get(int((loc.x + tX) + 10), int(loc.y + tY)) == color(250))? 5 : 0) - ((w && get(int((loc.x + tX) - 10), int(loc.y + tY)) == color(250))? 5 : 0);
      vel.y = (s? 0 : 0) - (n? 0 : 0);
      loc.add(vel);
      }
      void run() {
       super.run();
      }
      void setDirection(int k, boolean b) {
      if      (k == UP    | k == 'W')   n = b;
      else if (k == DOWN  | k == 'S')   s = b;
      else if (k == LEFT  | k == 'A')   w  = b;
      else if (k == RIGHT | k == 'D')   e  = b;
      }
    }
    class Airplane {
    PVector loc, vel;
    String ID;
    String riderID = "";
    char dir = 'w', dis = ' ';
    boolean rider = false;
    boolean ae, aw, an, as;
    int riderCount = 0;
    float n = 0.05, m = 0.05;
    Airplane(PVector loc_, String id) {
    loc = loc_;
    vel = new PVector(0, 0);
    ID = id;
    }
    void display() {
     stroke(1);
     fill(250);
     pushMatrix();
     translate(loc.x + tX, loc.y + tY);
     rect(0, 0, 25, 25);
     if(dir == 'e') {
     line(27, -3 + (sin(frameCount) * (4 * int(rider))), 27, 25 - (sin(frameCount) * (4 * int(rider))));
     line(25, 12.5, 28, 12.5);
     rect(-7, 10.5, 7, 12.5);
     rect(-19, -3, 12, 26);
     stroke(255);
     rect(-7, 11, 12, 11);
     stroke(0);
     } else if(dir == 'w') {
       line(-2, -3 + (sin(frameCount) * (4 * int(rider))), -2, 24 - (sin(frameCount) * (4 * int(rider))));
       line(0, 12.5, -3, 12.5);
       rect(25, 10.5, 7, 12.5);
       rect(32, -3, 12, 26);
       stroke(255);
       rect(25, 11, 12, 11);
       stroke(0);
     }
     popMatrix();
     if(!rider) {
     vel.y = (get(int(loc.x + tX), int(loc.y + tY) + 26) == color(250)? 3 * m : 0);
     loc.add(vel);
     }
    }
    void update(Pilot p) {
     ae = p.e;
     aw = p.w;
     an = p.n;
     as = p.s;
     if(aw) dir = 'w';
     else if(ae) dir = 'e';
     if(dis != 'x') {
     vel.x = (ae && get(int((loc.x + tX) + 29), int(loc.y + tY)) == color(250)? 5 * n : 0) - (aw && get(int((loc.x + tX) - 5), int((loc.y + tY))) == color(250)? 5 * n : 0);
     vel.y = (as && get(int(loc.x + tX), int((loc.y + tY) + 26)) == color(250)? 3 * n : 0) - (an && get(int(loc.x + tX), int((loc.y + tY) - 20)) == color(250)? 3 * n : 0) - ((key != CODED || !keyPressed && key == CODED) && get(int(loc.x + tX), int((loc.y + tY) + 26)) == color(250)? -3 * m : 0);
    }
     vel.x *= (riderID.contains("Penguin")? 15 : 1);
     vel.y *= (riderID.contains("Penguin")? 15 : 1);
     loc.add(vel);
     }
    }
    class Laser {
      PVector loc;
      PVector vel = new PVector(0, 0);
      char dir;
     Laser(PVector loc_, char dir_) {
       loc = loc_;
       dir = dir_;
     }
     void run() {
       if(dir == 'e') vel.x = 4;
       else if(dir == 'w') vel.x = -4;
       loc.add(vel);
       stroke(#E33E54);
       strokeWeight(2);
       line((loc.x + tX) + (dir == 'w'? 20 : 0), (loc.y + tY) + 15, (loc.x + tX) + (dir == 'w'? 10 : -10), (loc.y + tY) + 15);
       strokeWeight(1);
       if(get(int((loc.x + tX)), int((loc.y + tY) + 15)) != color(250)) {
         loc.x = -1000;
         vel.x = 0;
       }
       stroke(0);
     }
    }
    void keyPressed() {
     n.setDirection(keyCode, true); 
     if(key == 'r') alive = false;
    }
    void keyReleased() {
     n.setDirection(keyCode, false); 
    }
    
    
  • Funny exploring game, @BleuBox! You should post it @ Reddit too: B-)
    https://www.Reddit.com/r/processing/

Sign In or Register to comment.