Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import greenfoot.*;
- public class CPufferFish extends CInterFish
- {
- public CPufferFish(int size)
- {
- super(size);
- Initialize();
- }
- public CPufferFish()
- {
- super(0);
- Initialize();
- }
- public void Initialize()
- {
- this.Size = 0;
- this.getImage().scale(50, 50);
- this.getImage().mirrorHorizontally();
- }
- public void act()
- {
- MoveAround();
- }
- public void MoveAround()
- {
- this.move(1);
- if (this.isAtEdge()) //ak sa dotyka steny
- {
- this.getWorld().removeObject(this); //zmizne
- }
- if (Greenfoot.getRandomNumber(300)< 1) //v nahodnych intervaloch
- {
- this.IncreaseSize(10); //zvacsi svoju velkost
- }
- }
- public void IncreaseSize(int increment)
- {
- this.Size += increment; //o kolko sa ma ryba zvacsit
- //priradenie momentalnych rozmerov do premennych
- int Width = this.getImage().getWidth();
- int Height = this.getImage().getWidth();
- this.setImage("NafukovaciaRyba.png"); //najde obrazok v suboroch
- this.getImage().scale(Width + increment, Height + increment); //natstavenie momentalnych
- //rozmerov + o kolko sa ma ryba zvacsit (increment)
- this.getImage().mirrorHorizontally();
- }
- public void InteractWithFish(CFish fish)
- {
- fish.Accelerate();
- fish.TurnOnEating();
- //Ryba zrychli viac ako ked sa zje hranolky,
- //lebo nafukovacia ryba hned nezmizne a program vidi,
- //ze sa jej stale dotyka a na dalej zrychluje
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement