Macintosh Game Programming Techniques 1996
From the originals
13 scansMachine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.
These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.
Image 1
Macintosh Game Programming Techniques
Macintosh Game PROGRAMMING Techniques • A complete guide to creating games for the Macintosh • Covers sound, animation, and game intelligence • Includes complete source code and guidelines for building Desert Trek • CD-ROM also contains a limited version of Symantec C++ for the Power Macintosh CD-ROM INCLUDED CARY TORKELSON
A book cover with a dark background split into angled color panels, a large stylized multicolored title reading Game between italic Macintosh and Techniques, a row of stylized face icons along the top and bottom edges, a round gold CD-ROM INCLUDED badge, and the author name at the bottom.
Reading notes: Title words are set in stylized display type; spacing and reading order of the stacked title lines are inferred from layout.
- Printed product names
- Symantec C++ · Desert Trek
- Languages
- English
PDF page 1
Macintosh Game Programming Techniques • A complete guide to creating games for the Macintosh • Covers sound, animation, and game intelligence • Includes complete source code and guidelines for building Desert Trek • CD-ROM also contains a limited version of Symantec C++ for the Power Macintosh CD-ROM INCLUDED CARY TORKELSON
A book cover with a dark, angular background in gray, maroon, and brown tones, featuring a repeated blue-and-white face graphic at top and bottom, large stylized title lettering with 'Game' in multicolored pink, orange, yellow, and blue, a round 'CD-ROM INCLUDED' badge, and the author name in orange at the bottom.
Reading notes: Title is split across several styled type treatments; reading order follows top-to-bottom layout. Bullet points are rendered as small dots and were transcribed as bullet markers. The 'CD-ROM INCLUDED' badge text is curved and was transcribed as a single phrase.
- Printed product names
- Desert Trek · Symantec C++
- Languages
- English
PDF page 2
The image is a plain, entirely blank white page with no visible artwork, layout elements, or text.
PDF page 3
M&f ll M&T Books D~ A Division of MIS:Press, Inc. A Subsidiary of Henry Holt and Company, Inc. 115 West 18th Street New York, New York 10011 © 1996 by M&T Books Printed in the United States of America All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without prior written permission from the Publisher. Contact the Publisher for information on foreign rights. Limits of Liability and Disclaimer of Warranty The Author and Publisher of this book have used their best efforts in preparing the book and the programs contained in it. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The Author and Publisher make no warranty of any kind, expressed or implied, with regard to these programs or the documentation contained in this book. The Author and Publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs. All products, names and services are trademarks or registered trademarks of their respective companies. Library of Congress Cataloging-in-Publication Data Torkelson, Cary. Macintosh games programning I Cary Torkelson. p. cm. ISBN 1-55851-461-9 1. Computer games--Programming. 2. Macintosh (Computer)- -Programming. I. Title. QA76.76.C672T67 1996 794.8'15265--dc20 96-19483 10 9 8 7 6 s 4 3 2 1 Associate Publisher: Paul Farrell Managing Editor: Cary Sullivan Editor: Michael Sprague CIP Copy Editor: Suzanne lngrao Copy Edit Manager: Shari Chappell Production Editor: Joseph McPartland
Reading notes: OCR spacing and character errors such as 'programning', 'lngrao', and 'M&f ll M&T' in front matter Catalog number '96-19483' and '1996' date fragments may be ambiguous in the cataloging block
- Printed dates
- 1996 · 96-19483 · 1
- Languages
- English
PDF page 4
CONTENTS INTRODUCTION ........................................ 1 Who Will Want to Read this Book? .............................. 1 Why Write a Game? ........................................... 2 The Macintosh Game Market ................................... 3 What Are You Going to Learn? ............... . ....... .. ... . . . .. .4 C Programming Techniques ............... . ... ............ ... 4 Program Design and Marketing ..................... . ..........4 The Tools Needed to Write Mac Games . .......................4 Macintosh Toolbox Essentials ....... . . . ..... .. ................ 5 Resources ................................................. 5 Where to Get Additional Information ........................... 5 The Bottom Line .................................... . .. . ... 6 iii
Reading notes: Page numbers after the table-of-contents entries are partly garbled by dot leaders and spacing
- Languages
- English
PDF page 5
Contents iv CHAPTER l : GETTING STARTED ......................•.•.•..• 7 "" :'~" ,.;_' Programming Style ............................................ 8 C versus C++ ............................................... 8 Structure of an "Object-Oriented" C Program ....................9 Additional Programming Conventions ......................... 11 What do You Need to Write a Game? ............................ 13 Macintosh Computer ....................................... 13 Compiler/Development Environment ......................... 14 Additional Tools ........................................... 14 Internet or Online Service Access ............................. 15 Game Design ............................................... .16 Defining Your Target Market ................................. 16 Which Mac Platforms to Support ............................. 16 Make it Macintosh ......................................... 17 Pick a Project You Can Finish ................................ 18 Reusing Code from Previous Projects .......................... 18 Finish the Design Before You Code ........................... .19 The Design of Desert Trek ..................................... 19 A Game Idea is Born ....................................... 19 Game Rules ............................................... 20 Internal Design Issues ...................................... 21 Skill Levels ............................................... 21 Other Features ............................................ 23 Screen Layout .............................................24 CHAPTER 2: MAC TOOLBOX BASICS: MEMORY AND EVENTS ....••.• 27 Pascal Considerations ........................................ .30 Pascal Calling Conventions ................................... 30 Pascal Strings ............................................ .32
Reading notes: Table of contents with dotted leaders; some characters appear damaged (e.g., stray quotation marks and symbols near Chapter 1 entry) Page numbers are inconsistently recognized in the extracted text
- Languages
- English
PDF page 6
Contents Architecture of a Mac Program ................................. 33 Initializing the Toolbox Managers .............................. .34 Memory ................................................... .35 The Stack and Heap ....................................... .35 NIL versus NULL ........................................ .38 Pointers ................................................. .39 Determining Memory Errors ................................ .39 Handles .................................................. 40 Memory Management Routines ..............................46 Strings .....................................................48 String/Number Conversion Toolbox Routines ................... 50 Events .................................................... .51 Waiting for and Getting Events .............................. .51 Determining "What Event Occurred ........................... 56 Handling Mouse Events ..................................... 58 Handling Keyboard Events ..................................61 Handling Update Events ....................................64 Handling Activate Events ....................................65 Handle Operating System Events .............................66 General Event Toolbox Routines ..............................66 Random Numbers .........................................68 CHAPTER 3: RESOURCES ••••••••••••••••..•••••••.••••••• 71 The Resource Fork ........................................... 72 ResEdit .................................................... 73 Using ResEdit ............................................... 74 Creating a Resource File .................................... 74 Creating a Resource ........................................ 74 'MENU' and 'MBAR' Resources ................................76 Creating a 'MENU' Resource ................................ 77
Reading notes: Source is a table of contents with dot leaders; headline not identifiable as a primary heading
- Languages
- English
PDF page 7
Contents Creating an 'MBAR' Resource ................................ 79 'ICON' and 'cicn' Resources ................................... 80 'PICT' Resources ............................................ 80 Finder Icons for Your Game .................................... 80 File Types and Creators ..................................... 81 Resource Types Needed for Finder Icons ....................... 82 Creating the Finder Icons for your Game ....................... 83 Owner Resource ........................................... 84 Creating Dialog Boxes for Your Game ............................ 85 The 'DLOG' Resource .....................................85 The 'DITIJ Resource ....................................... 87 3D Buttons Using a 'CDEF' ................................. 88 'CNTIJ Resources ......................................... 89 Using 'CNTIJ Resources in Your Dialog Boxes ..................92 Final Notes on Using the 3D Button 'CDEF' ...................92 Custom Colors and Font Styles for Dialog Box Items ............. 93 'WIND' Resources .......................................... 106 'TEXT' and 'styl' Resources for Styled Text ...................... 106 The 'SIZE' Resource ....................................... .106 The Version (vers) Resource ................................... 107 'STR#' Resources ........................................... 109 Custom Resources ........................................... 112 Creating a Custom Resource Programmatically ................. 113 Using a Custom Resource .................................. 116 Vegas Trek Resource Example ................................. 117 Summary .................................................. 118 CHAPTER 4: WORKING WITH WINDOWS ....•......•.•...••.. 119 Anatomy of a Window .... : .................................. 120 Window Pointers and Records ................................. 122
Reading notes: Table of contents page numbers are partially ambiguous due to OCR-style spacing and punctuation (e.g., 'DITIJ', 'CNTIJ', '.106').
- Languages
- English
PDF page 8
Contents Loading a Window .......................................... 12 3 Showing and Hiding Wmdows ................................. 125 Moving and Sizing Windows .................................. 125 The Active Wmdow ......................................... 126 Changing the Z-Order ofWmdow ............................. 128 Setting Window Properties ................................... 128 Examples .................................................. 129 Update Events .............................................. 131 Examples ................................................ 134 Handling Mouse Click Events in the Content Region of a Window ... 136 Global and Local Coordinates ............................... 13 7 CHAPTER 5: DISPLAYING AND USING MENUS ...••..•..••.••..• 143 Menu Bars, Menus, and Menu Items ............................ 144 Adding the Apple Menu Items to the Apple Menu ................. 145 Loading a 'MBAR' Resource .................................. 146 Setting and Drawing the Menu Bar ............................. 146 Example Loading and Setting a Menu Bar ....................... 147 Loading a Menu Resource .................................... 148 Handling Menu Events ....................................... 149 Menu Processing For Mouse Down Events .................... 149 Highlighting Menus ....................................... 150 Menu Processing For Keyboard Events ....................... 152 Example of How to Determine which Menu was Selected ......... 152 Handling Apple Menu Selections ............................... 154 Manually Inserting and Removing Menus from the Menu Bar ....... 156 Hierarchical Menus .......................................... 157 Pop-up Menus .............................................. 158 Inserting and Deleting Menu Items ............................. 160 Getting and Setting a Menu Items Text .......................... 162
Reading notes: Several words contain OCR-like substitutions (e.g., 'Wmdow', 'Wmdows'), likely damaged characters. Table of contents page numbers and dot leaders may be misaligned in reading order.
- Languages
- English
PDF page 9
Contents Enabling and Disabling Menus and Menu Items ................... 162 Checking Menu Items ........................................ 163 CHAPTER 6: USING DIALOG BOXES AND CONTROLS ............ 165 Controls ................................................... 166 Types of Controls ......................................... 166 Control Parts ..................... , ...................... 167 Control Records and Control Handles ........................ 168 Creating, Loading, and Destroying Controls ................... 171 Moving and Sizing Controls ................................ 172 Showing, Hiding, and Drawing Controls ...................... 173 Changing a Control's Highlight State ......................... 174 Changing Control Values ................................... 17 5 Changing Control Properties ................................ 17 6 Determining Which Control Was Clicked ..................... 177 Scroll Bar Example ........................................ 179 Dialog Boxes ............................................. 185 Types of Dialog Boxes ..................................... 186 Application Modal Dialog Boxes ............................. 187 Dialog Box Records and Pointers ............................ 188 Item Types .............................................. 189 Static Text and Text Edit Dialog Box Items ..................... 190 Loading and Closing Dialog Boxes ........................... 191 Accessing Dialog Box Items ................................. 192 Getting and Setting Text for Static Text Items and Text Edit Fields .194 Parameterized Text ........................................ 19 5 Showing and Hiding Dialog Box Items ........................ 196 Finding an Item Based on the Mouse Location ................. 196 Drawing Dialog Boxes ..................................... 196 Using Alerts ............................................. 197
Reading notes: Table of contents page numbers and some characters appear spaced or irregular, possibly from extraction
- Languages
- English
PDF page 10
Contents Using Modal Dialog Boxes .................................. 198 Using Modeless Dialog Boxes ............................... 201 Modeless Dialog Box Example ............................... 203 Supporting Application Modal Dialog Boxes ................... 208 Supporting Application Modal Alerts ......................... 217 CHAPTER 7: Qu1cKDRAW ..............................223 Points, Rectangles, and Regions ................................ 224 Operations on Points ...................................... 227 Operations on Rectangles ................................... 228 Operations on Regions ..................................... 229 Graphics Ports .............................................. 229 Offscreen Graphics Ports ................................... 231 Bitmaps ................................................. 232 Creating and Destroying Graphics Ports ...................... 2 3 5 Associating Bitmaps with Graphics Ports ...................... 236 Setting and Getting the Current Graphics Port ................. 2 37 Setting a Port's Clipping Region ............................. 2 37 QuickDraw Globals .......................................2 38 Offscreen Graphics Port Example ............................239 Offscreen Graphics Worlds ................................... 241 Creating an Offscreen Graphics World ........................242 Setting the Current Graphics World .......................... 243 Locking a Graphics World's Pixmap .......................... 244 Destroying an Offscreen Graphics World ......................244 Offscreen Graphics World Example ..........................245 Determining the Macintosh's Graphics Environment ...............247 32-bit Color QuickDraw or Not .............................248 Determining the Monitor's Pixel Depth .......................249 Reacting to Changes in the Monitor's Pixel Depth ...............249
Reading notes: Source appears to be a table of contents rather than advertising copy; no headline or advertised products identified.
- Languages
- English
PDF page 11
Contents •XI .. Drawing Graphics ...........................................253 Patterns .................................................254 Transfer Modes ...........................................2 56 Pens .................................................... 261 Color ...................................................263 Drawing Lines ...........................................268 Drawing Rectangles ....................................... 270 Drawing Rounded Rectangles ...............................271 Drawing Ovals ...........................................275 Drawing Icons ............................................2 76 Drawing Pictures .........................................277 Drawing Text ...............................................281 Bitmap Operations ..........................................286 CopyBits ................................................287 Example ................................................ 287 CopyMask ............................................... 288 Bitmap Copy Speed Considerations .......................... 290 Drawing Directly to the Screen ..............................291 Desert Trek's View Transition Special Effect Example ..............292 CHAPTER 8: INCORPORATING TEXT ...•....••......•......•. 295 Text Edit Records ...........................................296 Creating and Destroying Text Edit Records ......................298 Updating Text Edit Records .................................. .300 TextJustification ........................................... .300 Line Height ................................................ 301 Character Coordinates ...................................... .301 Selecting Text .............................................. 302 Adding Text ................................................ 303 Deleting Text .............................................. .305
Reading notes: Table of contents with page numbers; some line-break hyphenation and spacing artifacts in source (e.g., 'Drawing Graphics', '2 56')
- Languages
- English