# Macintosh Game Programming Techniques 1996 — source transcripts, page 1

[Canonical transcript page](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1)

## Transcribed source material

Machine transcriptions and image descriptions; uncertain copy may be marked [illegible]. Verify against the linked originals. Historical rights remain with the original owners.

These are transcribed excerpts, not the full publications. Open the originals for remaining pages.

### Image 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-e180a4c39c8d46efc8b8d17b94bf31ec28d847ba4880fa4f2f2ce1bceb71ae24)

Macintosh Game Programming Techniques

Transcribed text:

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

Image description: 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

[Original Image 1](https://www.vintageapple.net/files/6f1a56588d36111ad2dcc7b6f9d6ab3453f415a2741bb6ea3473e66499532ecc/3a659d1d2ef830e0647d970f.webp)

### PDF page 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-cf84e2a560eefa5ac19f94ffc5c9710bb73fe08c5abb5b30bcb38472706a7cfd)

Transcribed text:

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

Image description: 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

[Original PDF page 1](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=1)

### PDF page 2

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-cecc401b2ce0730cd65725e22f1d744140643c53415e44ed086e6056a7eab328)

Image description: The image is a plain, entirely blank white page with no visible artwork, layout elements, or text.

[Original PDF page 2](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=2)

### PDF page 3

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-6ea69531f8536b5be04b051ea46f691837edee7b3114a827fa22a24c3a488bc5)

Transcribed text:

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

[Original PDF page 3](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=3)

### PDF page 4

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-dad21f0030156127631cfdcc4fe7d45d1a61d4283c1a6f6273440e5c96794135)

Transcribed text:

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

[Original PDF page 4](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=4)

### PDF page 5

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-d7ae8a736da25d2433a0a3a06829ddeed3a0ce151abddd16ff795858adb166cc)

Transcribed text:

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

[Original PDF page 5](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=5)

### PDF page 6

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-cf6d211436352b6209d3e75f46e5e4c4c059aed65a7649d8493209f7de65e64c)

Transcribed text:

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

[Original PDF page 6](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=6)

### PDF page 7

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-e1dca350b3f0b043b5dbcca6b9e1addd47923bfefdb86564c25df40284e6ea72)

Transcribed text:

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

[Original PDF page 7](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=7)

### PDF page 8

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-28c0613975d00daeffc1b7bbf60d3c0e21c172e7df905b98b39549fcafa7fae4)

Transcribed text:

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

[Original PDF page 8](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=8)

### PDF page 9

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-62fc282c93a46dcec9f3a6c9387854b175155690dc572b6020daf493e8826ef6)

Transcribed text:

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

[Original PDF page 9](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=9)

### PDF page 10

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-2d61d9a222c165e1b7a08be1e2226963444d2bb6ec3908dc0eec347340177788)

Transcribed text:

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

[Original PDF page 10](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=10)

### PDF page 11

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/1#scan-639eb0fc605a9ac12227120434b4ff6150a53f975793e5324094ccd4fdbb2f2f)

Transcribed text:

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

[Original PDF page 11](https://www.vintageapple.net/files/8655df24f0a7131e0a4f7803264d8dfcd75182d299124043d47a66cd3109c6e4/Macintosh_Game_Programming_Techniques_1996.pdf#page=11)

[Next transcribed scans](https://www.vintageapple.net/transcripts/media/va-macintosh-game-programming-techniques-1996-8992b3/2.md)
