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

2014/5/5

Has anyone here ever done the "FatCat" project?

iSuckAtGreenfoot iSuckAtGreenfoot

2014/5/5

#
Shot in the dark here but if anyone has the code or knows how to code it please post below. Not trying to get a C in my programming class.
AIMrOrange AIMrOrange

2014/5/5

#
I dont know the scenario, maybe you can try to describe it? by using the searchbar i found this, maybe it can help you: FatCat
iSuckAtGreenfoot iSuckAtGreenfoot

2014/5/5

#
Basically a scenario where you need to move a cat left and right with the arrow keys while switching images to make the cat look like it is actually moving. At the same time pizza is falling and rotating from the sky at different speeds. Every time the cat catches one you have to switch images to make it look like he is eating it. Once the cat eats 10 the game ends. I can't even do the first step which is storing the images into variable lmao.
AIMrOrange AIMrOrange

2014/5/5

#
Ok I think I understand now^^ Well, how many pictures you have depends on your decision. What I can tell is how to make these "object variables", you call it different images, and how to make them change. At first you need the images you want to use in your images folder of your project. Lets say you got 3 changing pictures for your cat for moving. So what you need is some variables to rely on when you change the images. You need a counter, lets call it counter, which increments every frame (counter = counter++;) so you start at 0 at add +1 every frame. Now you can start to make some conditions to tell your programm when to change images. For example you can make it with switch case or if else, but id recommend switch case, it is just faster. I dont want to make your task for you, so ill just give you an example for code:
1
2
3
4
5
6
7
8
9
10
11
switch(counter)
{
case 20: setImage(CatMoving1.png);
break;
case 40: setImage(CatMoving2.png);
break;
case 60: setImage(CatMoving3.png);
break;
case 80: setImage(Cat.png);
break;
}
where Cat.png is your default image. What your programm does now is to count the counter every frame. At count 20, 40 and 60 your image gets changed, you can change these numbers to whatever you like. All you have to do now is to set your counter back to 0 when it has reached 80. Important! To your question, you can store images for example like that:
1
GreenfootImage imagename  = new GreenfootImage(yourimage.png);
with setImage() and getImage() you can change and refer the image of your objects. For more detailed information check out the API of GreenfooImage. I hope i was able to help ;)
iSuckAtGreenfoot iSuckAtGreenfoot

2014/5/5

#
Thanks so much for your help! I really appreciate it :)
You need to login to post a reply.