← Tricks Of The Mac Game Programming Gurus 1995

Tricks Of The Mac Game Programming Gurus 1995

From the originals

13 scans

Machine-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

Master the Techniques You Need to Create Your Own Games TRICKS OF THE MAC GAME PROGRAMMING GURUS Secrets and techniques from expert game programmers! Covers QuickDraw 3D, porting, networking, Power Macs and more! CD-ROM includes programming tools and utilities, sample code, games, demos, and more! Jamie McCornack, Ingemar Ragnemalm, Paul Celestin, and many more game programming gurus The Don Crabb Macintosh Library

A book cover with a glowing orange and red dotted 3D wireframe arena image across the top, large blue-and-orange block lettering for the title, and a small CD-ROM disc graphic beside the right-hand text on a black background.

Reading notes: The top headline is partly cropped at the left edge, so the first letter appears as 'laster' with the M cut off; reconstructed as 'Master'. QuickDraw™ trademark symbol rendered as superscript TM; transcribed as QuickDraw 3D without the symbol. Reading order of the title lines is inferred from layout: 'TRICKS OF THE MAC' then 'GAME PROGRAMMING' then 'GURUS'.

Printed product names
Tricks of the Mac Game Programming Gurus · QuickDraw 3D
Languages
English
PDF page 1

Tricks of the Mac Game Programming Gurus

Master the Techniques You Need to Create Your Own Games TRICKS OF THE MAC GAME PROGRAMMING GURUS Secrets and techniques from expert game programmers! Covers QuickDraw™ 3D, porting, networking, Power Macs and more! CD-ROM includes programming tools and utilities, sample code, games, demos, and more! Jamie McCornack, Ingemar Ragnemalm, Paul Celestin, and many more game programming gurus The Don Crabb Macintosh Library

A book cover with a glowing orange-and-red abstract 3D grid and ring illustration across the top, black background, large blue and yellow condensed block lettering, and a small CD-ROM disc graphic beside the text.

Reading notes: The first word of the top banner is cut off at the left edge and appears as 'laster'; it is likely 'Master' but is partially cropped. The word 'MAC' is printed in red while 'TRICKS OF THE' is blue; reading order for the title block is inferred from layout. Ragnemalm and Celestin spellings are read from the image and should be confirmed against the source.

Printed product names
Tricks of the Mac Game Programming Gurus
Languages
English
PDF page 2

Fellow Game Programmers

Fellow Game Programmers\ P<ogr.unm;ng top-quality game' i' "'°more fun than playing lltem- Every time a - grune prog<.mm« gcl'' paycheck, <oy"1ty p,ymen<. o< re&i'uation fee, a g<in c<nne' ,1ong wilh iL "Can you believe it, l get to do thi' nW """· pU'h what'' po"ible on lhe M", exe<eit;<• my bnlln, and ).ugh while I'm doing it - and they give me money, too!" lf you ate on< of the'e people, OL you want to be, thi' book i' fo< you. ThIB IB a "h"'d'- on" book - not too much theo<Y ,.d a whole lot of pmcti<>C- You< guide' h.ve ,peot lhe" time in me uenche,, and they know the diffe<ence between truking •bout prog<""'- ming ond ,ol\ing up thei< ,ieeve' and doing it. Grune p<og"mnUng i' oomplex, and wilh me Macin""h G•" like the oiliet p"'tfotm' ), garo<' "e where me cutting-edge of me prog"mming art i' honed. Grune''"' where the Mac ,hnW' its "uff- how quickly it "n mainpulate d.ta. how ,mooilily it oan P'"""t moving Un•g<'. how deatlY it can tep<oduce ,ouni\, and mufilc, how compaclly it can ,tore complex iofonnatioo. lf you oan m""' Macinto'h grune p<Og"-nuning, "mund"'e" pro"""'°"ing will be a piece of c"1<e- The technique' u'"'1 in gume' tod,Y will be u.,d in multimedia next ye><. and will be found in business presentations the year after that. Out ,uilio<' have encl> .,lected a ,peciol topic to oove< in depili You won' t trreeze through thi• book - it'• too jam-packed full of ioloon•tion - but you will find me infmmation ea'Y to integ<ate into yom own p<ojocts. The CD-ROM i' full ofU'eful code- mud> of it wriuen e,pecially fo< thi' book, and .,me of it taken direct ftom popu- l" gum<' ftom top pubU,he"- But don't wo<<Y. we got lhe prog<anun«'' penni"ion to use the code - we got the programmers to write the book! Ple"" ""d you< oonunents on iliIB boOk. ,.d you< ,uggeati-OR' lo< ou< next book on Mac grune developmen4 di,-ectly to me, o< to <he publi,het. We k•OW you'll find thi' book ""'fol and infonnative, and we hope you have Ion wiili it, too- We hope you hav as much fun using this book as we did writing it! Sincerely, :5~)/_c-t Jamie McCornack Project Editor MacGameDev on America Online macgamedev@aol.com

Reading notes: OCR damage throughout body text, e.g. 'P<ogr.unm;ng' and 'lltem-' in the opening paragraph Headline reading order uncertain given the column-split layout of the copy

Printed product names
CD-ROM · America Online
Languages
English
PDF page 3

Read this book and no longer will you wonder wliat it 1 1J Mac game. You'll know how to make graphics and so the Mac Game Programming Gurus tells you what to and why to do it, and a whole lot more, besides gi · the game gurus use. Plus, you get the tools (don't fotg the book!) you need to get the job done. But don't take my word for it Read the book and tell Mac Game Programming Gurus lives in the Don cf8 delivers the inside goods on game programming games. Let it be your companion for finding and* in your gray matter. See you on the ether,

Reading notes: OCR damage in several words (e.g., 'wliat', 'fotg', 'cf8', 'Don') Reading order of fragmented lines is uncertain

Printed product names
Mac Game Programming Gurus
Languages
English
PDF page 4

U~~©~~ @il U[fo~ rnvtJ~©® @ @. [fffiJ @ ~ ~@ ~ ~@ ITffiJ ITffiJ ~ ITU ~ @J 01J ~ 01J ~ by Mccornack, Ragnemalm, Celestin, et al.

Reading notes: Most characters in the source text are garbled or damaged and cannot be reliably read. Legible fragment 'by Mccornack, Ragnemalm, Celestin, et al.' appears to be an attribution line; its role in the printed copy is uncertain.

PDF page 5

Tricks of the Mac® Game Programming Gurus ©1995 Hayden Books, a division of Macmillan Computer Publishing All rights reserved. Printed in the United States of America. No part of this book may be used or reproduced in any form or by any means, or stored in a database or retrieval system, without prior written permission of the publisher except in the case of brief quotations embodied in critical articles and reviews. Making copies of any part of this book for any purpose other than your own personal use is a violation of United States copyright laws. For information, address Hayden Books, 201W.103rd Street, Indianapolis, Indiana 46290. Library of Congress Catalog Number: 95-60416 ISBN: 1-56830-183-9 This book is sold as is, without warranty of any kind, either express or implied. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information or instructions contained herein. It is further stated that the publisher and author are not respon- sible for any damage or loss to your data or your equipment that results directly or indirectly from your use of this book. 97 96 95 4 3 2 Interpretation of the printing code: The rightmost double-digit number is the year of the book's printing; the rightmost single-digit number is the number of the book's printing. For example, a printing code of 95-1 shows that the first printing of the book occurred in 1995. Trademark Acknowledgments: All products mentioned in this book are either trademarks of the companies referenced in this book, registered trademarks of the companies referenced in this book, or neither. We strongly advise that you investi- gate a particular product's name thoroughly before you use the name as your own. Apple, Mac, and Macintosh are registered trademarks of Apple Computer, Inc.

Reading notes: Printing code interpretation example refers to '95-1' and the catalog number '95-60416' is listed separately; dates may be ambiguous as printed years.

Printed product names
Mac · Macintosh
Printed dates
1995 · 95-60416 · 95-1
Languages
English
PDF page 6

The Hayden Books Team Publisher David Rogelberg Product Development Manager Patrick Gibbons Acquisitions Editor Stacy Kaplan Development Editor Brad Miser Copy/Production Editor Steve Mulder Technical Reviewers · MarkAdams Stuart Cheshire Dennis Cohen Brian Greenstone Jake Hoelter Interviewer Tom Thompson Publishing Coordinator Rosemary Lewis Interior Designer Fred Bower Cover Designer Jay Corpus Production Angela Calvert, Dan Caparo, Kim Cofer, Kevin Foltz, David Garratt, Shawn MacDonald, Joe Millay, Erika Millen, Beth Rago, Regina Rexrode, Erich J. · Richter, Christine Tyner, Karen Walsh, Robert Wolf Indexer Bront Davis

Languages
English
PDF page 7

To Our Readers

To Our Readers Dear Friend, Thank you on behalf of everyone at Hayden Books for choosing Tricks of the Mac Game Programming Gurus to enable you to explore game programming on the Macintosh. For many reasons, the Mac is the best platform for games, and fortunately games on the Mac are exploding in both quality and popular- ity. This book will help you make your own contribution to this growth. We'd love to see any games that this book helps you with. Please write and let us know. What you think of this book is important to our ability to better serve you in the future. If you have any comments, no matter how great or small, we'd appreciate you taking the time to send us email or a note by snail mail. Of course, we'd love to hear your book ideas. Sincerely yours, - J/_:.t You can reach Hayden Books at the following: Hayden Books 201West103rd Street Indianapolis, IN 46290 (800) 428-5331 voice (800) 448-3804 fax Email addresses: America Online: Hayden Bks Apple Link: hayden.books CompuServe: 76350,3014 Internet: hayden@hayden.com

Reading notes: Signature line is illegible and cannot be transcribed. Reading order of the mailing address block and contact list is inferred from layout of extracted text.

Printed product names
Tricks of the Mac Game Programming Gurus
Languages
English
PDF page 8

Contents at a Glance

Contents at a Glance 0 A Game Programming Primer ........................................................... 1 1 Your First Game ............................................................................... 41 2 Basic Game Graphics ....................................................................... 87 3 Advanced Graphics ........................................................................ 121 4 File Management ........................................................................... 209 5 User Interaction .............................................................................. 265 6 Audio .............................................................................................. 327 7 Game Mechanics: Environments and Entities ............................... 389 8 Game Mechanics: Behavior ........................................................... 433 9 QuickDraw 3D ............................................................................... 491 10 Networking .................................................................................... 547 11 Porting ............................................................................................ 627 12 Game Aesthetics ............................................................................. 709 13 Optimizing Game Code for PowerPC ............................................ 731 14 Glypha III: A Case Study ............................................................... 749 A Top Speed-or Not? ...................................................................... 797 B Macintosh Environments ............................................................... 811 Index .............................................................................................. 843

Reading notes: Page numbers and chapter titles are dotted-leader contents entries; the 'Top Speed-or Not?' and 'Macintosh Environments' appendix titles were read as printed.

Languages
English
PDF page 9

Table of Contents

Table of Contents 0 A Grune Programming Primer ........................................................... 1 Animation Basics ........................................................................ 2 What's Animation? ............................................................... 2 How Quick Is Quick Enough? ............................................. 2 How Smooth Is Smooth Enough? ........................................ 4 How Fast Is Too Fast? .......................................................... 5 The Hello World Code .............................................. · ................... 6 HelloWorldl: Bare Bones .................................................... 6 HelloWorld2: Color and Complexity ................................. 16 HelloWorld3: Clams in Formation ..................................... 23 HelloWorld4: Clruns in Collision ....................................... 25 HelloWorld5: Clruns in Multibit ........................................ 26 HelloWorld6: 8 Bits Preferred ........................................... 28 HelloWorld6. l: No Brakes ................................................. 30 Some Sound Advice .................................................................. 30 Sound Markers ................................................................... 31 Synchronous vs. Asynchronous Sound .............................. 32 MGWSound.c .................................................................... 32 What Do I Do Next? ................................................................. 39 1 Your First Game ............................................................................... 41 Dungeon I ................................................................................. 41 Graphics ............................................................................. 42 Sounds ................................................................................ 43 Moving Around and Fighting ............................................. 44 Random Numbers .............................................................. 45 Let's See Some Source Code! ................................................... 45 Building Dungeon .............................................................. 46 Understanding Dungeon .................................................... 46 Declarations, Constants, and Variables .............................. 46 Subroutines ........................................................................ 49 The Main Progrrun ............................................................. 58 But How about My Own First Game? ...................................... 59 Problem 1: A Good Idea .................................................... 60 Can You Do It? ................................................................... 61 Can the Computer Do It? ................................................... 61 Can Your Players Do It? ..................................................... 64

Reading notes: Several characters in headings appear garbled, e.g. 'Clruns' and 'Progrrun'. Dotted-leader page numbers and reading order of some entries are uncertain.

Languages
English
PDF page 10

All Those Games ....................................................................... 65 2-D Space Games ............................................................... 65 Platform Games ................................................................. 66 Side-Scrollers ..................................................................... 67 Board Games and Puzzle Games ....................................... 69 Card Games ........................................................................ 70 First-Person 3-D Action Games ......................................... 71 Adventure Games ............................................................... 72 Dungeon-Digging Games .................................................. 74 Abstract Action Games ...................................................... 75 Simulation Games .............................................................. 77 Strategy Games .................................................................. 77 Programmer's Games ......................................................... 79 Dungeon 1 Plus ......................................................................... 80 Map Generation ................................................................. 80 Source Code Additions ...................................................... 80 Leaving the Game .............................................................. 85 2 Basic Game Graphics ....................................................................... 87 Color Theory ............................................................................. 87 How to Dress Better ........................................................... 88 Comparing RGB and RYB ................................................. 89 The Color Wheel ................................................................ 90 Using Color Wisely ............................................................ 91 HSV and the Color Picker .................................................. 92 Indexed and Direct Graphics Hardware .................................... 96 Direct Devices .................................................................... 96 Fixed Devices ..................................................................... 96 Indexed Devices and Color Tables ..................................... 96 Palettes and the Palette Manager ............................................... 99 Using Palettes ................................................................... 102 Drawing with Palettes ...................................................... 105 Palette Animation ............................................................. 106 Of GWorlds and GDevices ...................................................... 108 A Graphic Buffer, Pixmap, and CopyBi ts () Primer ....... 108 Why Use an Off-Screen? ................................................. 109 GWorlds ........................................................................... 110 GDevices .......................................................................... 113 Game Graphics Programming ................................................. 116 Multiple Monitor Tactics ................................................. 116 Fading Strategies .............................................................. 117 Hiding the Menu Bar Suavely .......................................... 118 Your Friend, CopyBits() ................................................. 118

Reading notes: Source is a table of contents with dot leaders; no primary headline or advertised products, prices, or dates are present. Some characters are split or spaced (e.g., 'Dungeon 1 Plus', 'CopyBi ts ()', 'Of GWorlds'), possibly from extraction damage.

Languages
English
PDF page 11

3 Advanced Graphics ........................................................................ 121 The Theory .............................................................................. 121 The Practice ............................................................................. 122 Example 1: A Very Simple Scene .................................... 122 Example 2: CopyMask() ................................................... 144 Example 3: A Clear Color Sprite Draw ........................... 150 Example 4: Encoded Sprites ............................................ 159 Example 5: Dirty Rectangle ............................................. 179 Example 6: An Update Rectangle List ............................. 188 Example 7: The Background ........................................... 195 4 File Management ........................................................................... 209 The File Manager and the Resource Manager ........................ 209 The Two Forks ................................................................. 210 A Quick Look into the File Manager ............................... 211 Resources and Handles .................................................... 211 Loading and Creating Resources ..................................... 213 Using Resources and Handles .......................................... 214 Storing Pregenerated Data ....................................................... 215 Saving Settings ........................................................................ 220 Switching between Several Resource Files ............................. 223 Saving High Score Lists .......................................................... 226 Saving the Player's "Save" Files ............................................. 232 Save Files .........................•............................................... 232 Internally Recorded Game State ...................................... 233 Passwords ......................................................................... 233 Dungeon 3 ........................................................................ 233 Dungeon 3's Save File Management Routines ................ 235 Apple Events in Dungeon 3 ............................................. 238 Other Changes in the Dungeon Source ............................ 241 Using Data Formats ................................................................ 243 Putting Together Your Resource File with ResEdit ......... 243 Navigating in ResEdit ...................................................... 244 'STR#' Resources ............................................................ 246 Adding String Lists .......................................................... 246 'STR' Resources ............................................................. 247 'TEXT' /'styl' Resources .................................................. 247 Balloon Help Resources ................................................... 248 Resources for the OS and the Finder ............................... 250 Menu Resources ............................................................... 253

Reading notes: Table of contents format with page numbers; headline not identifiable as a primary printed heading Some characters and spacing are irregular (e.g. 'Using Resources'), possibly from extraction

Languages
English