![]() It looked like this: if (touches (EnergyPellet. We already had code that checked whether the Doctor ran into an energy pellet. If he gets there, a “Tardis sound” (which we also found on the web) should be played, and the Doctor gets to the next level.įirst, we needed code to check whether the Doctor had reached the Tardis. We then wanted to get the first game task complete: the Doctor should collect all six energy pellets, and then get to the Tardis. This is easy by now: The Tardis is an entirely passive object in our game at the moment, so it was just a question of finding an image (easy with Google), creating an Actor subclass named “Tardis” and using the image (also easy). 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). You could probably eliminate either the 'soundFiles' or the 'songNames' array and use the same data for both creating the sound objects and displaying their names.Welcome back, dear readers, to the fourth part of Sophie’s journey of writing a DrWho computer game with Greenfoot and Java. ![]() It seems a bit redundant to have two arrays with exactly the same data. But, the above should get your fields (which I renamed to more properly fit what they represent) and their references set up properly. I am quite sure that things will need to be tended to there as well. This also does not presume that the rest of the class is fine and correct. I presumes that your sound files are ".mp3" files - if not, you need to make the necessary correction. ![]() If(!selected & Greenfoot.mouseClicked(this)) This shows the adjustments to the beginning of your class. ![]() Public PlayMusicButton(String soundFiles, String songNames, Color colors) Public class PlayMusicButton extends Actor
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |