Advertisement
Filipinex

CPufferFish

Mar 19th, 2024
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. import greenfoot.*;
  2.  
  3. public class CPufferFish extends CInterFish
  4.  
  5. {
  6.    
  7.     public CPufferFish(int size)
  8.     {
  9.         super(size);
  10.         Initialize();
  11.     }
  12.    
  13.    
  14.     public CPufferFish()
  15.     {
  16.         super(0);
  17.         Initialize();
  18.        
  19.     }
  20.    
  21.    
  22.     public void Initialize()
  23.     {
  24.         this.Size = 0;
  25.         this.getImage().scale(50, 50);
  26.         this.getImage().mirrorHorizontally();
  27.     }
  28.    
  29.     public void act()
  30.     {    
  31.         MoveAround();          
  32.     }
  33.    
  34.     public void MoveAround()
  35.     {
  36.         this.move(1);
  37.        
  38.         if (this.isAtEdge()) //ak sa dotyka steny
  39.         {
  40.             this.getWorld().removeObject(this); //zmizne
  41.         }
  42.        
  43.        
  44.          if (Greenfoot.getRandomNumber(300)< 1) //v nahodnych intervaloch
  45.         {
  46.             this.IncreaseSize(10); //zvacsi svoju velkost
  47.         }
  48.     }
  49.    
  50.    
  51.     public void IncreaseSize(int increment)
  52.     {
  53.         this.Size += increment; //o kolko sa ma ryba zvacsit
  54.  
  55.         //priradenie momentalnych rozmerov do premennych
  56.         int Width = this.getImage().getWidth();
  57.            
  58.         int Height = this.getImage().getWidth();
  59.            
  60.         this.setImage("NafukovaciaRyba.png"); //najde obrazok v suboroch
  61.         this.getImage().scale(Width + increment, Height + increment); //natstavenie momentalnych
  62.         //rozmerov + o kolko sa ma ryba zvacsit (increment)
  63.        
  64.         this.getImage().mirrorHorizontally();
  65.     }
  66.    
  67.     public void InteractWithFish(CFish fish)
  68.     {
  69.         fish.Accelerate();
  70.         fish.TurnOnEating();
  71.         //Ryba zrychli viac ako ked sa zje hranolky,
  72.         //lebo nafukovacia ryba hned nezmizne a program vidi,
  73.         //ze sa jej stale dotyka a na dalej zrychluje
  74.     }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement