Advertisement
MrsMcLead

Untitled

Nov 11th, 2015
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. // Keep this line as is, except for renaming the class
  2. class KatiemObj extends AnimatedObject {
  3.   float fishSize;
  4.   float xC;
  5.   float yC;
  6.   int direction;
  7.   int sink;
  8.  
  9.   // Constructor
  10.   KatiemObj(float size) {
  11.     fishSize = size;
  12.     xC = random(1,800-fishSize);
  13.     yC = random(1,600-fishSize);
  14.     direction = (int)random(0,2);
  15.     sink = (int)random(0,2);
  16.   }
  17.  
  18.   // Displays the creature
  19.   void display() {
  20.  
  21.     fill(#FF8D8C);
  22.     if(direction == 0) //rightFish
  23.     {
  24.     ellipse(xC,yC,fishSize,fishSize/2);
  25.     fill(0);
  26.     ellipse(xC + fishSize/4,yC, fishSize/10,fishSize/10);
  27.     }
  28.     else
  29.     {
  30.     ellipse(xC,yC,fishSize,fishSize/2);
  31.     fill(0);
  32.     ellipse(xC - fishSize/4,yC, fishSize/10,fishSize/10);
  33.     }
  34.    
  35.   }
  36.  
  37.  
  38.   // Moves the creature
  39.   void move() {
  40.        
  41.     if(sink == 0)
  42.     {
  43.          yC = yC - random(.25);
  44.         if(yC < fishSize/4)
  45.           sink = 1;
  46.     }
  47.     else
  48.     {
  49.        yC = yC + random(.25);
  50.         if(yC >height - fishSize/4-40)
  51.        
  52.           sink = 0;
  53.     }
  54.    
  55.     if(direction == 0)
  56.     {
  57.         xC = xC + .5;
  58.         if(xC > width - fishSize)
  59.           direction = 1;
  60.     }
  61.     else
  62.     {
  63.         xC = xC - .5;
  64.         if(xC < fishSize)
  65.           direction = 0;
  66.     }
  67.   }
  68.    
  69.  
  70.  
  71. }
  72.  
  73. /** If you want to enhance the tank background
  74.  *  to showcase your own project, you can put
  75.  *  drawing code in this function, which is called
  76.  *  near the start of the draw() function above.
  77.  */
  78. void drawTankBackground() {
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement