"unexpected token: (" points to }
in
Programming Questions
•
1 year ago
I've gone through the code for about half an hour now and as far as I can tell there are no extraneous parentheses, spelling mistakes or undeclared variables so I'm at a loss for a solution so I'm hoping someone here can see what I'm missing.
- float xpos = 250;
- int dif = 3;
- boolean start = false;
- boolean hit = false;
- ArrayList enemy = new ArrayList();
- void addEnemy(int s) {
- for (int a = 0; a < s; a++){
- enemy.add(new Enemy(random(500)));
- }
- }
- void setup() {
- size (500, 500);
- smooth();
- }
- void draw() {
- addEnemy(dif);
- //background (255);
- if (hit) {
- background (125, 125, 125);
- } else {
- background(255);
- }
- fill (0, 0, 255);
- ellipseMode(CENTER);
- ellipse (xpos, 250, 50, 50);
- }
- void keyPressed() {
- if (key == CODED) {
- if (keyCode == LEFT) {
- xpos-=10;
- if (xpos <= 25) {
- xpos = 25;
- }
- } else if (keyCode == RIGHT) {
- xpos+=10;
- if (xpos >= 475) {
- xpos = 475;
- }
- }
- }
- }
- class Bullet {
- float x;
- float y;
- float speed = 5;
- float direction;
- void Bullet (float _x, float _y, float _z) {
- x = _x;
- y = _y;
- direction = _z;
- }
- void run() {
- display();
- movement();
- }
- void display() {
- fill (0, 0, 255);
- ellipse (x, y, 5, 5);
- }
- void movement() {
- y += speed * direction;
- }
- }
- class Enemy {
- float x;
- float y = 0;
- float speed = 2.5;
- float timer = 200;
- ArrayList bulletE = new ArrayList();
- bulletE.add(new Bullet(x, y, 1));
- Enemy (float _x) {
- x = _x;
- }
- void run() {
- display();
- movement();
- shoot();
- timer--;
- }
- void display() {
- fill(0);
- ellipse (x, y, 50, 50);
- }
- void movement() {
- y += speed;
- }
- void shoot() {
- if (timer <= 0){
- for (int i = bulletE.size()-1; i >= 0; i--) {
- bulletE.get(i).run();
- if (bulletE.get(i).y > height ) {
- bulletE.remove(i);
- } else if ((bulletE.get(i).x >= xpos - 25) && (bulletE.get(i).x <= xpos + 25)) {
- if (bulletE.get(i).y >= 250) {
- bulletE.remove(i);
- hit();
- }
- }
- }
- timer = 200;
- } else {
- break;
- }
- }
- void hit() {
- hit = true;
- }
- }
1