Uncaught TypeError with Processing.js
in
Processing with Other Languages
•
6 months ago
TL;DR: weird error, what's going on?
Uncaught TypeError: boolean is not a function
First of all, it points to line 148, where I call display(). Maybe I'm looking at the wrong file? What's going on?!
P.S. I was working on an XML import/export thing, but I don't think it's the problem. Ignoring it might be a better option.
- /* @pjs font="Impact.ttf"; */
- /*
- [ ] Framerate
- [ ] Mouse collision
- [x] Equalize lengths
- [ ] Win screen
- */
- ArrayList<Poly> polys = new ArrayList<Poly>();
- int score = 0;
- int highscore = 0;
- float padding = 100;
- int currentBatch = 0;
- ArrayList<ArrayList<Poly>> batches = new ArrayList<ArrayList<Poly>>();
- boolean random = true;
- boolean winnable = false;
- boolean hasWon = false;
- void setup() {
- //Settings
- size(800, 500);
- smooth();
- noStroke();
- textAlign(CENTER);
- //textFont(loadFont("Impact.ttf"), 36);
- if (!random) {
- loadLevels();
- }
- newBatch();
- }
- void draw() {
- println((int)frameRate);
- background(200);
- fill(0);
- text(score, width/2, height/5);
- text("Highscore: "+highscore, width/2, height-height/5);
- fill(#CC2AD8);
- for (Poly p : polys) {
- p.update();
- }
- }
- ArrayList<Poly> newShapes(int howMany) {
- ArrayList<Poly> newShapes = new ArrayList<Poly>();
- for (int i = 0; i < howMany; i++) {
- newShapes.add(new Poly(getSpacing(i, howMany), height/2, getNonOctagon()));
- }
- int theOctagon = (int)random(0, newShapes.size());
- newShapes.set(theOctagon, new Poly(newShapes.get(theOctagon).loc.x, newShapes.get(theOctagon).loc.y, 8));
- return newShapes;
- }
- void mouseClicked() {
- for (Poly p : polys) {
- if (p.isClicked()) {
- if (p.sides == 8) {
- correct();
- }
- else {
- uncorrect();
- }
- }
- }
- }
- void correct() {
- score += 10;
- if (score > highscore) {
- highscore = score;
- }
- newBatch();
- }
- void uncorrect() {
- score = 0;
- newBatch();
- }
- void newBatch() {
- if (random || (currentBatch >= batches.size() && !winnable)) {
- polys = newShapes((int)random(3, 6));
- }
- else {
- polys = batches.get(currentBatch);
- currentBatch++;
- }
- }
- int getNonOctagon() {
- int numSides = (int)random(3, 9);
- if (numSides == 8) {
- return getNonOctagon();
- }
- else {
- return numSides;
- }
- }
- float getSpacing(int whichOne, int howMany) {
- return (((width-padding)/(howMany-1))*whichOne)+padding/2;
- }
- void loadLevels() {
- XML[] batchesXML = loadXML("levels.xml").getChildren("batch");
- for (XML b : batchesXML) {
- ArrayList<Poly> batch = new ArrayList<Poly>();
- XML[] polysXML = b.getChildren("poly");
- for (int i = 0; i < polysXML.length; i++) {
- batch.add(new Poly(getSpacing(i, polysXML.length), height/2, polysXML[i].getInt("sides"), polysXML[i].getInt("turn")));
- println(polysXML[i].getInt("sides"));
- }
- batches.add(batch);
- }
- }
- class Poly {
- private PVector loc;
- private int sides;
- private float r;
- private float angle;
- private float turnSpeed;
- private float size = 50;
- color c;
- final float SHORTEST_RADIUS;
- final float LONGEST_RADIUS;
- Poly(float x, float y, int sides) {
- loc = new PVector(x, y);
- this.sides = sides;
- r = size*tan((TWO_PI/sides)/2)*2; //Reverse engineered from SHORTEST_RADIUS
- SHORTEST_RADIUS = (r/2)/tan((TWO_PI/sides)/2);
- LONGEST_RADIUS = sqrt(sq(r/2)+sq(SHORTEST_RADIUS));
- turnSpeed = (int)random(-8, 8)^2;
- }
- Poly(float x, float y, int sides, float turnSpeed) {
- loc = new PVector(x, y);
- this.sides = sides;
- r = size*tan((TWO_PI/sides)/2)*2; //Reverse engineered from SHORTEST_RADIUS
- SHORTEST_RADIUS = (r/2)/tan((TWO_PI/sides)/2);
- LONGEST_RADIUS = sqrt(sq(r/2)+sq(SHORTEST_RADIUS));
- this.turnSpeed = turnSpeed;
- }
- void update() {
- angle += turnSpeed;
- display();
- }
- private void display() {
- float a = 0;
- PVector cVertex = new PVector(-r/2, SHORTEST_RADIUS); //These weird #s are to offset it into center
- pushMatrix(); //Manipulate the shape
- translate(loc.x, loc.y);
- rotate(radians(angle));
- beginShape(); //Draw the shape
- for (int i = 0; i <= sides; i++) { //Draw each vertex
- vertex(cVertex.x, cVertex.y);
- cVertex.add(r*cos(a), r*sin(a), 0);
- a-=radians(360/sides);
- }
- endShape(CLOSE);
- popMatrix();
- }
- private boolean isClicked() {
- boolean mouseOver = dist(loc.x, loc.y, mouseX, mouseY) < SHORTEST_RADIUS;
- return mouseOver;
- }
- }
1