Once we had that done, we added the Tardis. We also added, of course, the declaration for the counter field at the top of the class. Here is the code we wrote in the “Mars” class: public void act() And it’s a nice little piece of logical thinking to get the idea. It shows a different context of a variable and an if statement. This was actually a very nice bit of code (pedagogically speaking) since it reinforced quite nicely what we had done before. Then we can check whether we’re in the first act cycle, and play the sound only then. The trick we used is to use the world’s act method, and to count the act cycles. (Except for the constructor, but that gets executed when the world is created, which is well before the game starts.) The Greenfoot world has an ‘act’ method that gets called on every step of the execution, but it does not have an initialisation method that gets executed only once. Moving the sound file into the scenario sounds folder is easy, playing it is easy as well, but getting it to happen when the game starts is actually a little harder then it might seem. (We had found several Doctor Who sounds by googling around a bit.) So far, we had used her self-made sounds, but Sophie really liked one “THE DOCTOR MUST DIE!” sound clip (spoken by the Daleks!) which she wanted to use at the start of the game. What she was most keen on was using one of the sounds we had found the previous day. We all played the game for a bit (trying to collect the energy pellets), and Sophie was itching to continue. The next day was a Saturday, we were sitting at home, and Sophie showed Feena what she had done. But one thing after the other…Īfter the last programming session, Sophie was really keen to continue. If you just had a play, you might have noticed what we did: more sound, a TARDIS, and counting pellets. To show you upfront what we did: Here is the result of our work today. Thus, without further delay, on to the next task: Reaching the TARDIS with the energy pellets! I have been busy this week, so I haven’t had time to write this up earlier, but there was so much lovely and encouraging feedback on the previous posts that encouraged me to continue writing this up. But this programming session I’d like to record took place five days ago, I have only sparse notes, and I’d like to get it down before I forget too much. I’ll try to make it short today – it’s been a long day, and it’s getting late. If you have read the previous parts, then thank you for sticking with us for so long! (If not, you may like to start reading here: Part I, Part II, Part III). * Use the method aySound( back, dear readers, to the fourth part of Sophie’s journey of writing a DrWho computer game with Greenfoot and Java. When the mouse is click on this object, play the sound. * the 'Act' or 'Run' button gets pressed in the environment. * Act - do whatever the Emoticon wants to do. Use the method setImage( filename ) to set the image.Įmoticon emoticon = new Emoticon(image ,sound ) set the instance variable sound to the value passed by the corresponding parameter set the instance variable image to the value passed by the corresponding parameter Sounds =new String("hello","happy","crying","ohno","raspberry") ĪddObject(new Emoticon(images, sound ), 70*(i+1), 50) Images =new String("smiley1", "smiley2", "smile圓", "smiley4", "smiley5") * The y value can be either hard coded or calculated * Determine the x value using a mathematical calculation * Note: concatinate the ".png" for images and ".wav" for the sounds * It should use the method addObject( Actor object, int x, int y) to add new Emoticons to your world. * It should loop 5 times (you can either hard code 5 or use code) Create a new world with 400x100 cells with a cell size of 1x1 pixels. * Constructor for objects of class HomeworkWorld. * Create two instance varaibles of type String * Write a description of class Emoticon here. Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |