![]() 3D 3D Photo Gallery (Part 1) 3D Photo Gallery (Part 2) Audio Poor Man's MIDI Make A Metronome iPod Tricks (Part 1) iPod Tricks (Part 2) iPod Tricks (Part 3) Laugh Track Machine Audio Player with Reverb Shepard Melody RB Phone Home Build a Drum Machine Custom Controls and Windows Double Click Listbox Draggable Metal Window Double Click Canvas Custom Buttons Custom Buttons Part II iTunes-style Listboxes Custom Controls General RB Scrolling Windows Using Mesage Dialogs Case-Sensitive Word Finder Introduction to Stacks Wiggle Window JPEG in PDF Listbox Checkboxes Background Applications Listbox Auto-Find Virtual Volumes Time Tracker Software Distribution (Part 1) Software Distribution (Part 2) Software Distribution (Part 3) Software Distribution (Part 4) Exceptions Tips and Tricks Text Clippings Made Easy Graphics Drawing a Simple Gradient The SpriteSurface: Space Game Image Spinner Cropping Graphics (Part 1) Cropping Graphics (Part 2) Cropping Graphics (Part 3) Cropping Graphics (Part 4) Shimmer Graphics Lissajous Figures Simple Screen Capture Vector Graphics Kaleidoscope Images Stegonography Spirals! Image Table RB Magnifying Lens Screen Capture Color Picker Tutorial Hacks Ghost Grab Speedy Mouse Extension iTunes Plugins iTunes Skinner Mac OS X Global Hot Key Event (Carbon Events) Login Welcomer (Carbon Events) Add/Remove Buttons Resizable Sheets Mac OS X Preferences Window Using Sheets in REALbasic Build a Bundle (Part 1) Build a Bundle (Part 2) Dock Your Passwords Mac OS X Debugging REALbasic Mac OS X Icon Tutorial Animate Your Dock RB and the Command Line Menus Window Menu Templates Menu Listbox Menu Novelty Guessing Game Calendar Trivia Tile Mixer Zip Code Finder Happy Valentine's Day Merlin Simulator (Part 1) Merlin Simulator (Part 2) Merlin Simulator (Part 3) Buzzword Machine AppleSoft BASIC Printing Print to PDF Registration Registration Code Validation Network Registration Codes Resources Picture Extractor (Part 1) Picture Extractor (Part 2) Serial Caller ID (Part 1) Caller ID (Part 2) Caller ID (Part 3) Speech Speech Recognition Socket Communication Easy Peer-to-Peer File Sharing MacPAD Version Checking Display Web Image In Canvas HTML IMG Tags Version Tracking Even Smarter Instant Messaging Web Tiler JavaScript and REALbasic Stock Ticker (Part I) Stock Ticker (Part 2) AIM Mate XML Manipulation Simple XML Introduction Video Big Brother Video Capture Note: All articles without a byline were written by Erick Tejkowski. When cleaning the site I removed them because the code differed from page to page, and I have yet to put them back in.
Tell us about a bad link. |
Back in the late 1970's, Parker Brothers introduced a great handheld electronic game machine called Merlin. This week we continue with Part 2 of our Merlin Simulator project and begin adding functionality to the simulator. Interface If you'd like to start where we left off last week, download the project. Then, launch REALbasic and open Window1. Drag a NotePlayer control from the toolbar and add it to you Window1 interface. It doesn't matter where you drag it to in the interface, since it will be invisible when the application executes. Feel free to adjust the Instrument property. If you leave it set to its default value (1) it will play back as a piano. The remaining instrument numbers are displayed in the Online Reference for the NotePlayer control (press Cmd-1). Add the Code Before you get started writing any code, open the Code Editor for Window1 and add the following properties (by selecting Edit-New Property):
Close Window1 for now. We will return to it in a second. But, first we need to make some alterations to our custom Canvas classes. Open the NumButtonClass and create two new events, by selecting Edit-New Event.
Navigate to the MouseDown and MouseUp events of the NumButtonClass and change the code for each to look like the following:
Now that you have the hang of this, open up the UtilButtonClass and do the same, creating two new events, MouseDown and MouseUp like before. Then, navigate to the MouseDown and MouseUp events of the UtilButtonClass and change the code for each to look like the following:
What we have done here is to give our Window1 controls NumButton and UtilButton the chance to override the default functionality of the class. We will use these new events to respond to actions taken during the game, all from the code of Window1. Before we jump back to coding the games in Window1, create two new methods in the NumButtonClass by selecting Edit-New Method. Name them as follows:
Add the appropriate code to each method: ![]() The custom classes are now complete, so return to the Code Editor of Window1. Create two new methods, by selecting Edit-New Method.
The code for the MusicMachinePlaySong method is:
Since the code for the MusicMachinePlayNote method is so lengthy, I present it to you here in a text box.: As you may have guessed, these two methods play either a note or a song (which we are storing in the NoteArray). The final step for this week is to add some code to the MouseUp events of the NumButton and UtilButton controls. Open the MouseUp for each and add the appropriate code:
These two methods tie in all the other parts we have worked on so far. The utilButton.MouseUp event sits and waits for you to start a new game. When you do, it sets a flag (newgame = TRUE). Since newgame = TRUE, the number keys respond to a new game inquiry. By pressing the "2" key, a new game called "Music Machine" begins play. In this game, you are allowed to enter musical notes by pressing the number keys. As you play them, the notes will sound and be remembered by the Merlin Simulator. When you have completed the song, press "COMP TURN" to play the song back. For orientation purposes, the number button all the way at the top of the machine is "0", while the bottom number button is "10". The actual Merlin machine has numbers molded into the plastic adjacent to each button. Our interface is more simplistic. If you have any problems, be sure to review the Merlin manual. Conclusion Well, that's it for this week. Select Debug-Run to test your work. If you encounter any difficulties with the code or don't feel like entering it all, you can download the completed project and applications. See you next week! |
||||||||||||||||||||||||||||
|
Please support ResExcellence by Visiting our Sponsors. One click makes a difference. |
|||||||||||||||||||||||||||||
|
|