here is the code as it is in the assignment that you have to fill out....
now you can the properties of the bug after line 45:
- pos as x and y.
- color bugColor = color (random(255),random(255),random(255));
- the walk direction of it
- etc.
- // BugHunt
- // CMPS 5J
- // pa7
-
- int n = 100; // number of bugs
- Bug[] B = new Bug[n]; // bug array
- int clickCount = 0;
- int deadCount = 0;
- float killRate;
-
- void setup(){
- size(500,500);
- smooth();
- for(int i=0; i<n; i++){
- B[i] = new Bug(random(20,480),random(20,480),(int)random(1,5));
- }
- }
-
- void draw(){
- background(170);
- for(int i=0; i<n; i++){
- B[i].display();
- B[i].crawl();
- }
- }
-
- void mousePressed(){
- clickCount++;
- for(int i=0; i<n; i++){
- if( B[i].mouseOn() ){
- B[i].squash();
- deadCount++;
- }else if( B[i].scared() ){
- B[i].runAway();
- }
- }
- killRate = float(deadCount)/clickCount;
- println("kill rate = "+killRate);
- }
-
-
- // =========================================
-
- class Bug{
- // fields
-
- // constructor
- Bug(float x, float y, int s){
-
- }
-
- // methods
- void crawl(){
-
- }
-
- void display(){
-
- }
-
- void squash(){
-
- }
-
- void runAway(){
-
- }
-
- boolean mouseOn(){
-
- }
-
- boolean scared(){
-
- }
- }