/** * Game 08: "Redivider"
* Cut green circles
* Separate blue circles
* Avoid gray circles
* Creative Commons License
This work by Nathan McCoy is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. */ //CIRCLE TYPES // GREEN : CUT - slashing destroys - must destroy all to complete level // GRAY : AVOID - slashing causes failure // BLUE: DIVIDE - slashing causes failure - cut between to remove smaller group import ddf.minim.*; class ParticleList extends ArrayList { void tick() { Iterator i = iterator(); while(i.hasNext()) { Particle p = (Particle) i.next(); p.tick(); if(p.life <= 0) i.remove(); } } void draw() { Iterator i = iterator(); while(i.hasNext()) { Particle p = (Particle) i.next(); p.draw(); } } } abstract class Particle { PVector pos; PVector vel; PVector accel; int life; int maxlife; Particle(PVector p, PVector v, int lifetime) { this(p, v, new PVector(0, 0), lifetime); } Particle(PVector p, PVector v, PVector a, int lifetime) { accel = new PVector(a.x, a.y); pos = new PVector(p.x, p.y); vel = new PVector(v.x, v.y); life = maxlife = lifetime; } void tick() { vel.add(accel); pos.add(vel); life--; } abstract void draw(); } class TargetBit extends Particle { color col; TargetBit(float x, float y, float r, color c) { super(new PVector(x, y), new PVector(0, 0), new PVector(random(2)-1, random(2)-1), (int)r); col = c; } void draw() { noFill(); stroke(col); ellipse(pos.x, pos.y, life, life); } } PVector proj(PVector src, PVector dest) { return PVector.mult(dest, src.dot(dest)/dest.dot(dest)); } boolean[] keys = new boolean[256]; PVector next_slash_start; PVector next_slash_end; PVector slash_start; PVector slash_end; PFont font; int SLASH_TIME = 6; float MIN_SLASH_LENGTH = 20; int slash_timer; int level; int level_timer; int LEVEL_TIME = 600; int score; boolean failed; boolean victory; boolean title_screen; boolean muted; ArrayList targets; PImage title; ParticleList shrapnel; Minim minim; AudioSample cutSound; AudioSample clearSound; AudioSample failSound; String level_name = ""; void startupAudio() { minim = new Minim(this); cutSound = minim.loadSample("claw.wav", 1024); clearSound = minim.loadSample("thunder.wav", 2048); failSound = minim.loadSample("die.wav", 2048); } void stop() { cutSound.close(); clearSound.close(); failSound.close(); minim.stop(); super.stop(); } void regPoly(float x, float y, float r, int sides, float rot) { beginShape(); for(int i = 0; i < sides; i++) { float segAngle = TWO_PI/sides; vertex(cos(i*segAngle + rot) * r + x, sin(i*segAngle + rot) * r + y); } endShape(CLOSE); } abstract class Target { PVector origin; PVector pos; float rad; float offset; float phase; float speed; abstract color col(); Target(float x, float y, float r) { origin = new PVector(x, y); pos = new PVector(x, y); rad = r; offset = 0; phase = 0; speed = 0; } Target(float x, float y, float r, float o, float p, float s) { this(x, y, r); offset = o; phase = p; speed = s; } void tick() { phase += speed; pos.x = origin.x + cos(phase) * offset; pos.y = origin.y + sin(phase) * offset; } abstract void draw(); int test(PVector p1, PVector p2) { PVector diff = PVector.sub(p2, p1); PVector to = PVector.sub(pos, p1); PVector away = PVector.sub(to, proj(to, diff)); if(away.mag() < rad) return 0; PVector c = to.cross(diff); if(c.z > 0) return 1; else return -1; } void die() { for(int i = 0; i < 8; i++) shrapnel.add(new TargetBit(pos.x, pos.y, rad, col())); } } class Green extends Target { color col1 = color(64, 255, 100); color col2 = color(red(col1) * 0.75, green(col1) * 0.75, blue(col1) * 0.75); Green(float x, float y, float r) { super(x, y, r); } Green(float x, float y, float r, float o, float p, float s) { super(x, y, r, o, p, s); } void draw() { fill(col1); noStroke(); ellipse(pos.x, pos.y, rad, rad); fill(col2); regPoly(pos.x, pos.y, rad * 0.8, 3, phase); } color col() { return col1; } } class Blue extends Target { color col1 = color(64, 100, 255); color col2 = color(red(col1) * 0.75, green(col1) * 0.75, blue(col1) * 0.75); Blue(float x, float y, float r) { super(x, y, r); } Blue(float x, float y, float r, float o, float p, float s) { super(x, y, r, o, p, s); } void draw() { fill(col1); noStroke(); ellipse(pos.x, pos.y, rad, rad); fill(col2); regPoly(pos.x, pos.y, rad * 0.8, 4, phase); } color col() { return col1; } } class Gray extends Target { color col1 = color(192, 192, 212); color col2 = color(red(col1) * 0.75, green(col1) * 0.75, blue(col1) * 0.75); Gray(float x, float y, float r) { super(x, y, r); } Gray(float x, float y, float r, float o, float p, float s) { super(x, y, r, o, p, s); } void draw() { fill(col1); noStroke(); ellipse(pos.x, pos.y, rad, rad); fill(col2); regPoly(pos.x, pos.y, rad * 0.8, 6, phase); } color col() { return col1; } } Target test; void reset(int lev) { level = lev; score = 0; level_timer = LEVEL_TIME; loadLevel(lev); victory = false; failed = false; slash_timer = 0; shrapnel = new ParticleList(); } void setup() { size(720, 480); frameRate(60); font = loadFont("PressStartK-64.vlw"); startupAudio(); ellipseMode(RADIUS); targets = new ArrayList(); slash_start = new PVector(0, 0); next_slash_start = new PVector(0, 0); slash_end = new PVector(0, 0); next_slash_end = new PVector(0, 0); title = loadImage("redivider.png"); //reset(1); title_screen = true; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////// void loadLevel(int l) { level = l; level_timer = LEVEL_TIME; targets = new ArrayList(); if(l == 1) { level_name = "cut"; targets.add(new Green(width * 0.5, height * 0.5, 50, 0, 0, 0.03)); } else if(l == 2) { level_name = "divide"; targets.add(new Blue(width * 0.5 + 100, height * 0.5, 50, 0, 0, 0.03)); targets.add(new Blue(width * 0.5 - 100, height * 0.5, 50, 0, 0, 0.03)); } else if(l == 3) { level_name = "avoid"; targets.add(new Green(width * 0.5, height * 0.5, 50, 0, 0, 0.03)); for(int i = 0; i < 4; i++) { targets.add(new Gray(width * 0.5, height * 0.5, 50, 100, i * HALF_PI, 0.0)); } } else if(l == 4) { level_name = "a few cuts"; targets.add(new Green(width * 0.5, height * 0.5, 30, 0, 0, 0.00)); for(int i = 0; i < 6; i++) { targets.add(new Green(width * 0.5, height * 0.5, 30, 100, i * (TWO_PI/6), 0.0)); } } else if(l == 5) { level_name = "a few divisions"; targets.add(new Blue(width * 0.5, height * 0.5, 30, 0, 0, 0.00)); for(int i = 0; i < 6; i++) { targets.add(new Blue(width * 0.5, height * 0.5, 30, 100, i * (TWO_PI/6), 0.0)); } } else if(l == 6) { level_name = "simpler"; targets.add(new Green(width * 0.5, height * 0.5, 30, 0, 0, 0.00)); for(int i = 0; i < 6; i++) { targets.add(new Blue(width * 0.5, height * 0.5, 30, 100, i * (TWO_PI/6), 0.0)); } } else if(l == 7) { level_name = "movement"; targets.add(new Green(width * 0.5, height * 0.5, 50, 0, 0, 0.00)); targets.add(new Gray(width * 0.5, height * 0.5, 50, 100, 0, 0.02)); targets.add(new Gray(width * 0.5, height * 0.5, 50, 100, PI, 0.02)); targets.add(new Green(width * 0.5, height * 0.5, 50, 100, HALF_PI, 0.02)); targets.add(new Green(width * 0.5, height * 0.5, 50, 100, PI+HALF_PI, 0.02)); } else if(l == 8) { level_name = "convergence"; for(int i = 0; i < 4; i++) { targets.add(new Gray(width * 0.5, height * 0.5, 50, 150, i * HALF_PI, -0.025)); targets.add(new Green(width * 0.5 + cos(i*HALF_PI)*150, height * 0.5+ sin(i*HALF_PI)*150, 50, 150, i * HALF_PI, 0.025)); } } else if(l == 9) { level_name = "counter-rotation"; targets.add(new Green(width * 0.5, height * 0.5, 30, 0, 0, 0.00)); targets.add(new Gray(width * 0.5, height * 0.5, 30, 60, 0, 0.01)); targets.add(new Gray(width * 0.5, height * 0.5, 30, 60, PI, 0.01)); targets.add(new Green(width * 0.5, height * 0.5, 30, 60, HALF_PI, 0.01)); targets.add(new Green(width * 0.5, height * 0.5, 30, 60, PI+HALF_PI, 0.01)); targets.add(new Gray(width * 0.5, height * 0.5, 30, 120, 0, -0.02)); targets.add(new Gray(width * 0.5, height * 0.5, 30, 120, PI, -0.02)); targets.add(new Green(width * 0.5, height * 0.5, 30, 120, HALF_PI, -0.02)); targets.add(new Green(width * 0.5, height * 0.5, 30, 120, PI+HALF_PI, -0.02)); } else if(l == 10) { level_name = "checkers"; targets.add(new Gray(width * 0.5, height * 0.5, 50, 0, 0, 0.00)); targets.add(new Gray(width * 0.5 - 100, height * 0.5 - 100, 50, 0, 0, 0.00)); targets.add(new Gray(width * 0.5 + 100, height * 0.5 - 100, 50, 0, 0, 0.00)); targets.add(new Gray(width * 0.5 - 100, height * 0.5 + 100, 50, 0, 0, 0.00)); targets.add(new Gray(width * 0.5 + 100, height * 0.5 + 100, 50, 0, 0, 0.00)); targets.add(new Green(width * 0.5 + 00, height * 0.5 + 100, 50, 0, 0, 0.00)); targets.add(new Green(width * 0.5 + 100, height * 0.5 + 00, 50, 0, 0, 0.00)); targets.add(new Green(width * 0.5 + 00, height * 0.5 - 100, 50, 0, 0, 0.00)); targets.add(new Green(width * 0.5 - 100, height * 0.5 + 00, 50, 0, 0, 0.00)); } else if(l == 11) { level_name = "say when"; for(int i = 0; i < 4; i++) { targets.add(new Blue(width * 0.5, height * 0.5, 50, 120, i * HALF_PI, 0.0)); targets.add(new Blue(width * 0.5 + cos(i*HALF_PI)*120, height * 0.5+ sin(i*HALF_PI)*120, 50, 120, 0, 0.025)); } } else if(l == 12) { level_name = "trapped"; targets.add(new Gray(width * 0.5 - 30, height * 0.5 - 60, 30, 0, 0, 0.00)); targets.add(new Gray(width * 0.5 + 30, height * 0.5 - 60, 30, 0, 0, 0.00)); targets.add(new Gray(width * 0.5 - 120, height * 0.5, 30, 0, 0, 0.00)); targets.add(new Gray(width * 0.5 - 30, height * 0.5 + 60, 30, 0, 0, 0.00)); targets.add(new Gray(width * 0.5 + 30, height * 0.5 + 60, 30, 0, 0, 0.00)); targets.add(new Gray(width * 0.5 + 120, height * 0.5, 30, 0, 0, 0.00)); targets.add(new Green(width * 0.5, height * 0.5, 30, 0, 0, 0.05)); targets.add(new Green(width * 0.5 - 60, height * 0.5, 30, 0, 0, 0.05)); targets.add(new Green(width * 0.5 + 60, height * 0.5, 30, 0, 0, 0.05)); } else if(l == 13) { level_name = "gears"; targets.add(new Gray(width * 0.5 - 120, height * 0.5, 100, 0, 0, 0.02)); targets.add(new Gray(width * 0.5 + 120, height * 0.5, 100, 0, 0, -0.02)); for(int i = 0; i < 6; i++) { targets.add(new Green(width * 0.5 - 120, height * 0.5, 20, 120, i * (TWO_PI/6), 0.02)); targets.add(new Green(width * 0.5 + 120, height * 0.5, 20, 120, i * (TWO_PI/6) + TWO_PI/12, -0.02)); } } else if(l == 14) { level_name = "eclipse"; targets.add(new Green(width * 0.5, height * 0.5 + 1000, 95, 1000, -HALF_PI, 0.000)); targets.add(new Gray(width * 0.5, height * 0.5 + 1000, 100, 1000, -HALF_PI + 0.02, -0.0001)); } else if(l == 15) { level_name = "quick draw"; targets.add(new Green(width * 0.5, height * 0.5 + 1000, 95, 1000, 0, -0.03)); } else if(l == 16) { level_name = "gears redux"; targets.add(new Gray(width * 0.5 - 120, height * 0.5, 100, 0, 0, 0.02)); targets.add(new Gray(width * 0.5 + 120, height * 0.5, 100, 0, 0, -0.02)); for(int i = 0; i < 6; i++) { if(i == 3) { targets.add(new Gray(width * 0.5 - 120, height * 0.5, 20, 120, i * (TWO_PI/6), 0.02)); targets.add(new Gray(width * 0.5 + 120, height * 0.5, 20, 120, i * (TWO_PI/6) + TWO_PI/12, -0.02)); } else { targets.add(new Green(width * 0.5 - 120, height * 0.5, 20, 120, i * (TWO_PI/6), 0.02)); targets.add(new Green(width * 0.5 + 120, height * 0.5, 20, 120, i * (TWO_PI/6) + TWO_PI/12, -0.02)); } } } else if (l == 17) { level_name = "it's a trap"; targets.add(new Green(width * 0.5, height * 0.5, 30, 0, 0, 0.03)); targets.add(new Blue(width * 0.5 - 60, height * 0.5, 30, 0, 0, 0.03)); targets.add(new Blue(width * 0.5 + 60, height * 0.5, 30, 0, 0, 0.03)); for(int i = 0; i < 6; i++) { if(i % 3 == 0) targets.add(new Blue(width * 0.5 - 200, height * 0.5, 20, 60, i * (TWO_PI/6), 0.0)); else targets.add(new Gray(width * 0.5 - 200, height * 0.5, 20, 60, i * (TWO_PI/6), 0.0)); } targets.add(new Gray(width * 0.5 - 200, height * 0.5, 20, 0, 0, 0.0)); for(int i = 0; i < 6; i++) { targets.add(new Gray(width * 0.5 + 200, height * 0.5, 20, 60, i * (TWO_PI/6), 0.0)); } targets.add(new Gray(width * 0.5 + 200, height * 0.5, 20, 0, 0, 0.0)); } else if (l == 18) { level_name = "use bombs wisely"; for(int x = 0; x < 7; x++) for(int y = 0; y < 5; y++) { if(x % 2 == 1 && y % 2 == 1) targets.add(new Gray(width * 0.5 - 120 + x*40, height * 0.5 - 80 + y * 40, 20, 0, 0, 0)); else targets.add(new Green(width * 0.5 - 120 + x*40, height * 0.5 - 80 + y * 40, 20, 0, 0, 0)); } } else if (l == 19) { level_name = "paranoia"; targets.add(new Green(width * 0.5, height * 0.5, 50, 0, 0, 0.003)); } else if(l == 20) { level_name = "jammed"; targets.add(new Gray(width * 0.5 - 120, height * 0.5, 100, 0, 0, 0.00)); targets.add(new Gray(width * 0.5 + 120, height * 0.5, 100, 0, 0, 0.00)); for(int i = 0; i < 6; i++) { targets.add(new Green(width * 0.5 - 120, height * 0.5, 20, 120, i * (TWO_PI/6), 0.0)); targets.add(new Green(width * 0.5 + 120, height * 0.5, 20, 120, i * (TWO_PI/6) + TWO_PI/12, -0.0)); } } else if(l == 21) { level_name = "there will be cake"; targets.add(new Blue(width * 0.5, height * 0.5, 20, 0, 0, 0.00)); for(int i = 0; i < 6; i++) { targets.add(new Blue(width * 0.5, height * 0.5, 20, 100, i * (TWO_PI/6), 0.0)); } for(int i = 0; i < 12; i++) { targets.add(new Blue(width * 0.5, height * 0.5, 20, 200, i * (TWO_PI/12), 0.0)); } } else if(l == 22) { level_name = "it all comes together"; targets.add(new Green(width * 0.5, height * 0.5, 20, 0, 0, 0.01)); for(int i = 1; i < 7; i++) { targets.add(new Green(width * 0.5, height * 0.5, 20, i * 40, -i*3.0/5, i / 500.0)); targets.add(new Green(width * 0.5, height * 0.5, 20, i * 40, -i*3.0/5 + PI, i / 500.0)); } } else if (l == 23) { level_name = "use bombs wiselier"; for(int x = 0; x < 7; x++) for(int y = 0; y < 5; y++) { if((x % 2 == 1 && y % 2 == 1 ) || ((y == 0 || y == 4) && (x == 2 || x == 3 || x == 4))) targets.add(new Gray(width * 0.5 - 120 + x*40, height * 0.5 - 80 + y * 40, 20, 0, 0, 0)); else targets.add(new Green(width * 0.5 - 120 + x*40, height * 0.5 - 80 + y * 40, 20, 0, 0, 0)); } } else if (l == 24) { level_name = "paranoia part 2"; targets.add(new Gray(width * 0.5, height * 0.5, 50, 0, 0, 0.003)); } else if(l == 25) { level_name = "wait what"; targets.add(new Green(width * 0.5 - 120, height * 0.5, 100, 0, 0, 0.02)); targets.add(new Green(width * 0.5 + 120, height * 0.5, 100, 0, 0, -0.02)); for(int i = 0; i < 6; i++) { targets.add(new Gray(width * 0.5 - 120, height * 0.5, 20, 120, i * (TWO_PI/6), 0.02)); targets.add(new Gray(width * 0.5 + 120, height * 0.5, 20, 120, i * (TWO_PI/6) + TWO_PI/12, -0.02)); } } else if(l == 26) { level_name = "the cake is alive"; targets.add(new Blue(width * 0.5, height * 0.5, 20, 0, 0, 0.00)); for(int i = 0; i < 6; i++) { targets.add(new Blue(width * 0.5, height * 0.5, 20, 100, i * (TWO_PI/6), 0.002)); } for(int i = 0; i < 12; i++) { targets.add(new Blue(width * 0.5, height * 0.5, 20, 200, i * (TWO_PI/12), -0.002)); } } else if(l == 27) { level_name = "enough already"; targets.add(new Green(width * 0.5 - 120, height * 0.5, 100, 0, 0, 0.02)); targets.add(new Green(width * 0.5 + 120, height * 0.5, 100, 0, 0, -0.02)); for(int i = 0; i < 6; i++) { targets.add(new Blue(width * 0.5 - 120, height * 0.5, 20, 120, i * (TWO_PI/6), 0.02)); targets.add(new Blue(width * 0.5 + 120, height * 0.5, 20, 120, i * (TWO_PI/6) + TWO_PI/12, -0.02)); } } else if(l == 28) { level_name = "split twist"; //targets.add(new Green(width * 0.5, height * 0.5, 20, 0, 0, 0.01)); for(int i = 1; i < 7; i++) { targets.add(new Blue(width * 0.5, height * 0.5, 20, i * 40, 0, i / 50.0)); targets.add(new Blue(width * 0.5, height * 0.5, 20, i * 40, 0 + PI, i / 50.0)); } } else if(l == 29) { level_name = "noblesse oblique"; { for(int x = 0; x < 5; x++) for(int y = 0; y < 5; y++) { if((x * 3 + y * 2) % 4 == 0 ) targets.add(new Green(width * 0.5 - 140 + x*70, height * 0.5 - 140 + y * 70, 20, 0, 0, 0)); else targets.add(new Gray(width * 0.5 - 140 + x*70, height * 0.5 - 140 + y * 70, 20, 0, 0, 0)); } } } else if(l == 30) { level_name = "i give up"; targets.add(new Blue(width * 0.5 - 120, height * 0.5, 100, 0, 0, 0.02)); targets.add(new Blue(width * 0.5 + 120, height * 0.5, 100, 0, 0, -0.02)); for(int i = 0; i < 6; i++) { if(i == 4) { targets.add(new Green(width * 0.5 - 120, height * 0.5, 20, 120, i * (TWO_PI/6), 0.02)); targets.add(new Green(width * 0.5 + 120, height * 0.5, 20, 120, i * (TWO_PI/6) + TWO_PI/12, -0.02)); } else { targets.add(new Blue(width * 0.5 - 120, height * 0.5, 20, 120, i * (TWO_PI/6), 0.02)); targets.add(new Blue(width * 0.5 + 120, height * 0.5, 20, 120, i * (TWO_PI/6) + TWO_PI/12, -0.02)); } } } else { victory = true; } } void tickTargets() { for(int i = 0; i < targets.size(); i++) { Target t = (Target) targets.get(i); t.tick(); } } void drawTargets() { for(int i = 0; i < targets.size(); i++) { Target t = (Target) targets.get(i); t.draw(); } } void testTargets(PVector start, PVector end) { int left_blue = 0; int right_blue = 0; Iterator ti = targets.iterator(); while(ti.hasNext()) { Target t = (Target) ti.next(); int test = t.test(start, end); if(test == 0) { if(t instanceof Green) { t.die(); ti.remove(); } else { if(!muted && !failed) failSound.trigger(); failed = true; } } if(t instanceof Blue) { if(test > 0) left_blue++; if(test < 0) right_blue++; } } ti = targets.iterator(); while(ti.hasNext()) { Target t = (Target) ti.next(); int test = t.test(start, end); if(t instanceof Blue) { if(left_blue >= right_blue && test < 0) { t.die(); ti.remove(); } if(left_blue <= right_blue && test > 0) { t.die(); ti.remove(); }; } } boolean done = true; ti = targets.iterator(); while(ti.hasNext()) { Target t = (Target) ti.next(); if(!(t instanceof Gray)) done = false; } if(done && !failed) { score += level_timer/6; loadLevel(level + 1); if(!muted) clearSound.trigger(); } } void draw() { if(title_screen) { background(0); textFont(font, 32); textAlign(CENTER, TOP); fill(255); imageMode(CENTER); image(title, width/2, height/2); text("click to start", width/2, height/2 + 64); } else { if(victory) { background(255); textFont(font, 32); textAlign(CENTER, BOTTOM); fill(0); text("GAME COMPLETE", width/2, height/2); textAlign(CENTER, TOP); text("Final score: "+score, width/2, height/2); } else { background(0); if(level_timer >= LEVEL_TIME - 2) background(255); textFont(font, 64); fill(255); textAlign(RIGHT, TOP); text(""+ (level_timer / 60) + "." + ((level_timer / 6)%6), width - 8, 8); textFont(font, 32); fill(255); textAlign(LEFT, TOP); text("Score: "+ score + "\nLevel: "+level, 8, 8); { textFont(font, 32); textAlign(CENTER, BOTTOM); fill(60); if(!failed) text(level_name, width/2, height - 8); } textFont(font, 16); textAlign(LEFT, BOTTOM); fill(128); if(muted) text("MUTE", 8, height-8); strokeWeight(1); if(!failed) { tickTargets(); shrapnel.tick(); } drawTargets(); shrapnel.draw(); if(slash_timer == SLASH_TIME && !failed) { testTargets(slash_start, slash_end); if(!muted) cutSound.trigger(); } stroke(255); if(slash_timer > 0) { strokeWeight(slash_timer * 2 - 1); line(slash_start.x, slash_start.y, slash_end.x, slash_end.y); } if(!failed) { slash_timer--; if(mousePressed) { strokeWeight(1); line(next_slash_start.x - 5, next_slash_start.y, next_slash_start.x + 5, next_slash_start.y); line(next_slash_start.x, next_slash_start.y - 5, next_slash_start.x, next_slash_start.y + 5); line(mouseX - 4, mouseY - 4, mouseX + 4, mouseY + 4); line(mouseX + 4, mouseY - 4, mouseX - 4, mouseY + 4); } level_timer --; if(level_timer <= 0) { failed = true; if(!muted) failSound.trigger(); } } if(failed) { textFont(font, 32); textAlign(CENTER, BOTTOM); fill(255); text("LEVEL FAILED\nR to retry\nQ to quit", width/2, height - 8); loadPixels(); for(int i = 0; i < pixels.length; i++) { if(red(pixels[i])+green(pixels[i])+blue(pixels[i]) > 253*3) pixels[i] = color(0); else pixels[i] = color(128 + brightness(pixels[i])*0.5, brightness(pixels[i]), brightness(pixels[i])); } updatePixels(); } } } } void mousePressed() { if(title_screen) { //title_screen = false; //reset(1); } else { // if(slash_timer <=0) //if(failed) reset(level); { next_slash_start.x = mouseX; next_slash_start.y = mouseY; } } // else reset(level); } void mouseReleased() { //if(slash_timer <= 0) if(title_screen) { title_screen = false; reset(1); } else if(victory) { title_screen = true; victory = false; } else { if(!failed) { next_slash_end.x = mouseX; next_slash_end.y = mouseY; if(PVector.dist(next_slash_start, next_slash_end) > MIN_SLASH_LENGTH) { slash_timer = SLASH_TIME; slash_start.x = next_slash_start.x; slash_start.y = next_slash_start.y; slash_end.x = next_slash_end.x; slash_end.y = next_slash_end.y; PVector slash_dir = PVector.sub(slash_end, slash_start); slash_dir.normalize(); slash_end = PVector.add(slash_start, PVector.mult(slash_dir, 600)); slash_start = PVector.add(slash_start, PVector.mult(slash_dir, -600)); } } } } void keyPressed() { if(!keys[keyCode]) { keys[keyCode] = true; down(keyCode); } } void keyReleased() { if(keys[keyCode]) { keys[keyCode] = false; up(keyCode); } } void down(int theKey) { println(theKey + " down"); if(failed && theKey == 'R') reset(level); if(theKey == 'Q') title_screen = true; if(theKey == 'M') muted = !muted; } void up(int theKey) { println(theKey + " up"); }