This site requires JavaScript, please enable it in your browser!
Greenfoot back
Rovsneglen
Rovsneglen wrote ...

2015/9/15

Greenfoot Growing when eating

Rovsneglen Rovsneglen

2015/9/15

#
So i got this school project where i have to make my own game and i came up with the idea of a fish swimming around and eating smaller fish and then growing when eating but i cant seem to figure out how i came up with the idea that if i made a score system like public void Eat() { Actor prey; prey = getOneObjectAtOffset(0, 0, Prey.class); if (prey != null) { World world; world = getWorld(); world.removeObject(prey); EatenFish = EatenFish +1; } I could say that if ((int EatenFish == 1) == true); { GreenfootImage image = getImage(); image.scale(30, 30); setImage(image); } so it would grow and when the score hit 2 to grow if ((EatenFish == 1) == true); { GreenfootImage image = getImage(); image.scale(90, 90); setImage(image); } But it just starts out with being 90 x 90 instead
Super_Hippo Super_Hippo

2015/9/15

#
Maybe it should be 'EatenFish==2' and you have to remove the semicolons after the 'if (...)'.
danpost danpost

2015/9/15

#
You say you are checking for different score values, but the coding for both check for a value of '1'. I will suggest that you scale the original image each time. Scaling an image multiple times will cause unwanted effects on the image. Keep a reference to the original image and use the GreenfootImage constructor that copies an image to create a separate image that you can scale:
Rovsneglen Rovsneglen

2015/9/16

#
All i had to do was to remove the semicolons... :| Ty guys
You need to login to post a reply.