Unexpected Token in void setup()
in
Programming Questions
•
5 months ago
Hey guys. I'm sort of new to processing and was wondering if someone could help me out with what seems to be a syntax error. I'm getting an unexpected token error but can't seem to find the problem. I recently converted one program to another which consist of methods now. The problem is probably obvious but I'm apparently blind right now. I'll post my code below. Thanks!
MainGame Code
- public class MainGame
- {
- public static void main (String[] args)
- {
- float rando;
- void setup()
- {
- size(1000,1000);
- int lives=3;
- smooth();
- }
- void draw()
- {
- background(100, 50, 100);
- drawplayer();
- drawenemy();
- if(nlives==0)
- {
- println("GAME OVER");
- }
- if(dist(nlives==0))
- {
- println(frameCount);
- }
- if(nlives==0)
- {
- exit();
- }
- }
- void drawplayer()
- {
- float xspeedpos=0;
- float yspeedpos=0;
- float xpos=mousex;
- float ypos=mousey;
- int lives=3;
- Player play = new Player( double xpos, double ypos, int lives);
- play.setY(ypos);
- play.getY();
- play.setX(xpos);
- play.getX();
- play.moves(xpos, ypos);
- play.display();
- }
- void drawenemy()
- {
- Enemy enemies = new Enemy[2];
- rando=random(400);
- enemy[0]= new Enemy (900,500,1,3, rando);
- rando= random(400);
- enemy[1]= new Enemy(900,500,1,3,rando);
- rando= random(400);
- enemy[2]= new Enemy(900,500,1,3,rando);
- xpos=900;
- ypos=500;
- xspeedpos=1;
- yspeedpos=3;
- enemies.getYspeed(yspeedpos);
- enemies.setYspeed();
- enemies.setXspeed(xspeedpos);
- enemies.getXspeedpos();
- enemies.setY(ypos);
- enemies.getY();
- enemies.setX(xpos);
- enemies.getX();
- enemies.moves();
- enemies.display();
- if(dist(mouseX-100, mouseY-100, x, y + rand) < 150)
- {
- nlives=nlives-1;
- rando=random(400);
- enemy[0]= new Enemy (900,500,1,3, rando);
- rando= random(400);
- enemy[1]= new Enemy(900,500,1,3,rando);
- rando= random(400);
- enemy[2]= new Enemy(900,500,1,3,rando);
- }
- }
- }
- }
- public class Characters
- {
- protected float x;
- protected float y;
- protected float xspeed;
- protected float yspeed;
- public Characters(float xspeedpos,float yspeedpos,float xpos, float ypos)
- {
- x=xpos;
- y=ypos;
- xspeed=xspeedpos;
- yspeed=yspeedpos;
- }
- public float getX ()
- {
- return x;
- }
- public void setX(float xpos)
- {
- x=xpos;
- }
- public float getY ()
- {
- return y;
- }
- public void setY(float ypos)
- {
- y=ypos;
- }
- public float getXspeed ()
- {
- return xspeed;
- }
- public void setXspeed(float xspeedpos)
- {
- xspeed=xspeedpos;
- }
- public float getYspeed ()
- {
- return yspeed;
- }
- public void setYspeed(float yspeedpos)
- {
- yspeed=yspeedpos;
- }
- public void display()
- {
- rect(x,y, 10,10);
- }
- public void moves()
- {
- y = y + yspeed;
- x = x + xspeed;
- }
- }
- public class Enemy extends Characters
- {
- public Enemy (float xpos, float ypos, float xspeed, float yspeed,float rando)
- {
- super(xpos,ypos, xspeed,yspeed);
- rand = rando;
- }
- public void display()
- {
- rect(x,y + rand, 200,200);
- fill(100,100, 200);
- rect(x+ 40, y + rand + 40, 20, 10);
- rect(x+ 140, y + rand + 40, 20, 10);
- fill(200);
- rect(x + 50, y + rand + 140, 100, 10);
- }
- public void moves()
- {
- y = y + yspeed;
- if((y + rand > width) || (y + rand < 0 ))
- {
- yspeed = yspeed * -1;
- }
- x = x + xspeed;
- if ((x > width) ||(x < 0))
- {
- xspeed = xspeed * -1;
- }
- }
- }
- public class Player extends Characters
- {
- protected int nlives;
- public Player (float xpos, float ypos, int lives)
- {
- super(xpos,ypos);
- nlives=lives;
- }
- public void moves(float xpos, float ypos)
- {
- x=xpos;
- y=ypos;
- }
- public void display()
- {
- fill(255);
- ellipse(x, y, 50, 100);
- fill(20);
- ellipse(x - 10, y - 15, 10, 10);
- ellipse(x + 10, y - 15, 10, 10);
- ellipse(x, y + 20, 10, 30);
- }
- }
1