Simple Code Error
in
Programming Questions
•
11 months ago
This code always returns the same error:
- int foodNum = 50; //How much food is created initially
- int foodInterval = 3000; //The at which food is created after the start
- int initialOrganismNum = 10; //How many organisms are initially created
- int startingEnergyLevel = 100; //The energy each organism starts with
- int i = 0;
- ArrayList food;
- //ArrayList organism;
- void setup() {
- size(700,500);
- food = new ArrayList(foodNum);
- while (i < foodNum) {
- food.add(new Food(15,10));
- i++;
- }
- foodNum = food.size();
- i = 0;
- while (i < foodNum) {
- Food foodie = (Food) food.get(i);
- foodie.place();
- foodie.display();
- i++;
- }
- }
- void draw() {
- background(255);
- foodNum = food.size();
- i = 0;
- while (i < foodNum) {
- Food foodie = (Food) food.get(i);
- foodie.display();
- i++;
- }
- }
- class Food() {
- int x;
- int y;
- int r;
- int energy;
- Food (int rad, int ie) {
- r = rad;
- energy = ie;
- }
- void place() {
- x = random(r, width-r);
- y = random(r, height-r);
- }
- void display() {
- ellipse(x,y,r*2,r*2);
- }
- }
It is the beginning of a natural selection simulator I am writing. I am sure there is just something stupid that I have done wrong, but it always returns this error:
- Unexpected token: (
Thanks!
1