100% found this document useful (2 votes)
19 views

Mac game programming 1st Edition Mark Szymczyk pdf download

The document provides information about the book 'Mac Game Programming' by Mark Szymczyk, which serves as a guide for aspiring Mac game developers. It includes details on various game programming topics, tools, and techniques, along with a CD-ROM containing development resources. Additionally, it features acknowledgments and insights from the author and contributors to the book.

Uploaded by

sinesmuskoik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
19 views

Mac game programming 1st Edition Mark Szymczyk pdf download

The document provides information about the book 'Mac Game Programming' by Mark Szymczyk, which serves as a guide for aspiring Mac game developers. It includes details on various game programming topics, tools, and techniques, along with a CD-ROM containing development resources. Additionally, it features acknowledgments and insights from the author and contributors to the book.

Uploaded by

sinesmuskoik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Mac game programming 1st Edition Mark Szymczyk

download

https://ebookname.com/product/mac-game-programming-1st-edition-
mark-szymczyk/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Linux Game Programming w CD Prima Tech s Game


Development 1st Edition Mark Collins

https://ebookname.com/product/linux-game-programming-w-cd-prima-
tech-s-game-development-1st-edition-mark-collins/

Game Programming With Python Game Development Series


1st Edition Riley

https://ebookname.com/product/game-programming-with-python-game-
development-series-1st-edition-riley/

AI Game Programming Wisdom 1st Edition Steve Rabin

https://ebookname.com/product/ai-game-programming-wisdom-1st-
edition-steve-rabin/

Latino Education An Agenda For Community Action


Research National Latino a Education Research and
Policy Project 1st Edition Melissa Rivera Pedro Pedraza

https://ebookname.com/product/latino-education-an-agenda-for-
community-action-research-national-latino-a-education-research-
and-policy-project-1st-edition-melissa-rivera-pedro-pedraza/
Harry B Smith Dean of American Librettists 1st Edition
John Franceschina

https://ebookname.com/product/harry-b-smith-dean-of-american-
librettists-1st-edition-john-franceschina/

Nationalisms in Japan 1st Edition Naoko Shimazu

https://ebookname.com/product/nationalisms-in-japan-1st-edition-
naoko-shimazu/

Handbook of Collective Intelligence 1st Edition Thomas


W. Malone

https://ebookname.com/product/handbook-of-collective-
intelligence-1st-edition-thomas-w-malone/

Attachment Focused Trauma Treatment for Children and


Adolescents Phase Oriented Strategies for Addressing
Complex Trauma Disorders 1st Edition Niki Gomez-Perales

https://ebookname.com/product/attachment-focused-trauma-
treatment-for-children-and-adolescents-phase-oriented-strategies-
for-addressing-complex-trauma-disorders-1st-edition-niki-gomez-
perales/

Global Leadership Research Practice and Development


Mark E. Mendenhall

https://ebookname.com/product/global-leadership-research-
practice-and-development-mark-e-mendenhall/
Tourism Culture and Regeneration First Edition M. K.
Smith

https://ebookname.com/product/tourism-culture-and-regeneration-
first-edition-m-k-smith/
00 Macgame_FM.qxd 2/21/03 5:02 PM Page i

Mac Game
Programming
00 Macgame_FM.qxd 2/21/03 5:02 PM Page ii

This page intentionally left blank


00 Macgame_FM.qxd 2/21/03 5:02 PM Page iii

Mac Game
Programming

Mark Szymczyk
00 Macgame_FM.qxd 2/21/03 5:02 PM Page iv

© 2002 by Premier Press, Inc. All rights reserved. No part of this book may be reproduced or trans-
mitted in any form or by any means, electronic or mechanical, including photocopying, recording, or
by any information storage or retrieval system without written permission from Premier Press, except
for the inclusion of brief quotations in a review.
The Premier Press logo, top edge printing, and related trade dress are trademarks of Premier
Press, Inc. and may not be used without written permission. All other trademarks are the
property of their respective owners.

Publisher: Stacy L. Hiquet


Marketing Manager: Heather Buzzingham
Managing Editor: Sandy Doell
Acquisitions Editor: Emi Smith
Series Editor: André LaMothe
Editorial Assistant: Margaret Bauer
Marketing Coordinator: Kelly Poffenbarger
Technical Reviewer: Darrell Walisser
Copy Editor: Alice Martina Smith
Interior Layout: LJ Graphics
Cover Design: Mike Tanamachi
CD Producer: Darrell Walisser
Indexer: Johnna VanHoose Dinse
Proofreader: Kim Benbow
Microsoft, Windows, Internet Explorer, Notepad, VBScript, ActiveX, and FrontPage are trademarks or
registered trademarks of Microsoft Corporation. Netscape is a registered trademark of Netscape
Communications Corporation. Macintosh is a registered trademark of Apple Computer, Inc.
Premier Press and the author have attempted throughout this book to distinguish proprietary trade-
marks from descriptive terms by following the capitalization style used by the manufacturer.
Important: Premier Press cannot provide software support. Please contact the appropriate software
manufacturer’s technical support line or Web site for assistance.
Information contained in this book has been obtained by Premier Press from sources believed to be
reliable. However, because of the possibility of human or mechanical error by our sources, Premier
Press, or others, the Publisher does not guarantee the accuracy, adequacy, or completeness of any
information and is not responsible for any errors or omissions or the results obtained from use of
such information. Readers should be particularly aware of the fact that the Internet is an ever-chang-
ing entity. Some facts may have changed since this book went to press.
ISBN: 1-931841-18-7
Library of Congress Catalog Card Number: 2001096218
Printed in the United States of America
02 03 04 05 RI 10 9 8 7 6 5 4 3 2 1
00 Macgame_FM.qxd 2/21/03 5:02 PM Page v

This book is dedicated to the memory of Jeff Bilicki.


00 Macgame_FM.qxd 2/21/03 5:02 PM Page vi

Foreword

S o you want to be a Mac game programmer? This book is a great place to start.
Whether you are interested in how games work, want to learn to write share-
ware games, or want to become the next great commercial game developer, this
book will show you some of the key technologies and techniques required to make
your dream game.
Through the years, I’ve worked on many Mac games, from Duke Nukem 3D to Tomb
Raider and Unreal Tournament. When I began writing Mac games in 1985, I would
have loved to have access to a reference like this one. In those early years, Mac
game developers learned tricks from anywhere they could find them—late nights
pouring over Apple documentation, swapping ideas with other developers, and a
lot of trial and error.
As president of Westlake Interactive, I’m often asked by people how to break into
the Mac game business. My first answer is to get experience any way you can.
Anything from writing simple 2D games to working on flashy demos will show
potential employers that you have the drive and knowledge to make it in the game
business. Mac game programmers are incredibly difficult to find these days, so the
market for people with the interest and talent to work in the industry is very
strong.
Writing Macintosh games can be some of the most exciting, challenging, and
rewarding work a programmer can tackle. You have in your hands the perfect start-
ing point to enter the world of game programming; with hard work and determina-
tion, you’ll be well on your way to writing that next great Mac game!

Glenda Adams
President, Westlake Interactive
May 2002
00 Macgame_FM.qxd 2/21/03 5:02 PM Page vii

Acknowledgments

I t pains me to admit it, but I did not single-handedly create this book. Many people
helped make this book a reality, and I’d like to thank them here.

First, I’d like to thank my editors at Premier Press—and I worked with many editors
on this book. I would like to thank my original acquisitions editor, Jody Kennen, for
discovering me and for putting the book deal together. I would also like to thank my
original project editor, Brian Thomasson, for his help as I wrote the first chapters of
this book. He helped me get up to speed quickly on writing the chapters.

While I was writing this book, both Jody and Brian left to take other positions. Emi
Smith became my new acquisitions editor. I need to thank Emi for gathering all the
permissions necessary to include all the programs on the CD-ROM and for putting
up with delays in the project. Thanks to my copy editor, Alice Martina Smith, for
cleaning up some of my grammar and for bringing up questions that made the text
of this book easier for you to understand. I would also like to thank my Tech Editor,
Darrell Walisser, for reviewing all the source code in this book and making sure it all
runs well.

Next, I owe a huge Thank You to Carlos Camacho, the editor of the Mac game pro-
gramming site iDevGames, for two reasons. First, he let me write some articles for his
site, which is how Premier Press found me. Without his Web site, I wouldn’t be writ-
ing this book. Second, he donated artwork, music, and sound effects for the CD-
ROM that accompanies this book. His donation will make it easier for you to make
your own games, improving the book in the process.

I had many programming questions as I wrote the code for the book. I would like to
thank everyone who answered my questions on various mailing lists and message
boards. I don’t have a list of individuals who helped, but you know who you are.
00 Macgame_FM.qxd 2/21/03 5:02 PM Page viii

The CD-ROM that is with this book comes packed with development tools, games,
source code, and game assets. I would like to thank everyone who graciously let me
include their programs on the CD-ROM. You have helped make this book as good as
it can possibly be.

Finally, I want to thank my family for helping keep me sane while I wrote the book.
To my parents Stan and Mary, my brothers Dave and Steve, my sister Kathy, her hus-
band John, and my nephews Zachary and Christian, thank you.
00 Macgame_FM.qxd 2/21/03 5:02 PM Page ix

About the Author


When he graduated with a computer science degree from John Carroll University,
Mark Szymczyk set out on a career in software development. After bouncing
around among various corporate programming positions, he decided to go into
game development, starting his own shareware game company, Black Apple
Software. While working on his first game, he wrote some game development arti-
cles for the iDevGames Web site, which led to a request to write this book. Now that
the book is completed, he can finish up work on his first game.
Mark currently lives in the Cleveland, Ohio area. When he’s away from his Mac, he
enjoys playing basketball, listening to underground music from the 80s and 90s,
and hanging out with his nephews.
00 Macgame_FM.qxd 2/21/03 5:02 PM Page x

Contents at a Glance

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . xxviii
Chapter 1
Introduction to the Mac and to
Game Programming . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 2
Project Builder . . . . . . . . . . . . . . . . . . . . . . . . 27
Chapter 3
C++ for C Programmers. . . . . . . . . . . . . . . . . . . 59
Chapter 4
Introduction to
Macintosh Graphics . . . . . . . . . . . . . . . . . . . . . . 77
Chapter 5
Tiles and Scrolling. . . . . . . . . . . . . . . . . . . . . . 113
Chapter 6
Animation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Chapter 7
InputSprocket. . . . . . . . . . . . . . . . . . . . . . . . . 197
Chapter 8
HID Manager . . . . . . . . . . . . . . . . . . . . . . . . . 233
Chapter 9
Reading the Keyboard and Mouse
Plus Event Handling . . . . . . . . . . . . . . . . . . . . 297
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xi

Contents at a Glance xi

Chapter 10
Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Chapter 11
Physics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Chapter 12
Beginning Artificial Intelligence . . . . . . . . . . . . 455
Chapter 13
Pathfinding . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Chapter 14
DrawSprocket . . . . . . . . . . . . . . . . . . . . . . . . 545
Chapter 15
Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
Chapter 16
Putting It All Together . . . . . . . . . . . . . . . . . . 639
Chapter 17
Understanding the Game’s Source Code . . . . . . . 675
Chapter 18
Optimization . . . . . . . . . . . . . . . . . . . . . . . 717

Chapter 19
Game Development Tips . . . . . . . . . . . . . . . . . . 763
Appendix A
Installing Programs from the CD-ROM . . . . . . . . 797
Appendix B
Game Development Resources . . . . . . . . . . . . . . 801
Appendix C
CD-ROM Contents . . . . . . . . . . . . . . . . . . . . . . 813
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xii

xii

Contents

Foreword . . . . . . . . . . . . . . . . . . . . . . . vi
Letter from the Series Editor. . . . . . . . xxxi
Introduction . . . . . . . . . . . . . . . . . . . xxxiii

Chapter 1
Introduction to the Mac and to
Game Programming . . . . . . . . . . . . 1
A Brief History of the Mac OS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Mac Programming Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Mac Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Carbon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Cocoa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Programming with Carbon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
What to Place in Your System Folder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
What to Place in Your Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
A Description of the Game We Will Develop . . . . . . . . . . . . . . . . . . . 12
Elements of a Computer Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Player Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Physics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Game Event Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xiii

Contents xiii

I Want to Be a Professional Game Developer . . . . . . . . . . . . . . . . . . 16


Landing a Job as a Game Programmer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Making Your Own Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Advice for New Game Developers . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Pick a Project You Can Handle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Choose a Project You Enjoy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Use Placeholder Assets at First . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Design First . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Know the Lingo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Chapter 2
Project Builder . . . . . . . . . . . . . 27
Creating Your First Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Your First Real Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Creating Source Code Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Adding Files to a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Adding Frameworks to a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Contents List Tabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Files Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Classes Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Bookmarks Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Targets Tab. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Breakpoints Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Action Panel Tabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Find Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Build Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Run Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Debug Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xiv

xiv Contents

Compiling a Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Debugging a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
A Debugging Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

Chapter 3
C++ for C Programmers . . . . . . . 59
Structured vs. Object-Oriented Programming . . . . . . . . . . . . . . . . . . 61
Structured Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Data Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Member Functions: Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Member Functions: Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Member Functions: Accessors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Member Functions: General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Virtual Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Private, Protected, and Public Keywords . . . . . . . . . . . . . . . . . . . . . . 71
Dynamic Memory Allocation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Converting the Book Code to C from C++ . . . . . . . . . . . . . . . . . . . . 75
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

Chapter 4
Introduction to
Macintosh Graphics. . . . . . . . . . . 77
Macintosh Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8-Bit Color Pixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xv

Contents xv

16-Bit Color Pixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81


32-Bit Color Pixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
QuickDraw Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Pixel Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Graphics Ports. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
QuickDraw Coordinate System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Graphics Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Offscreen GWorlds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
The GameOffscreenBuffer Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Creating Offscreen GWorlds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Updating Offscreen GWorlds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Drawing a Picture into an Offscreen GWorld . . . . . . . . . . . . . . . . . . . . . . . 98
Disposing of Offscreen GWorlds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Using OS X’s Built-In Double Buffering . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Drawing to the Screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
The CopyBits() Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Boolean Transfer Modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Arithmetic Transfer Modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Steps to Take . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Making CopyBits() Run at Its Best . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

Chapter 5
Tiles and Scrolling. . . . . . . . . . . 113
Introduction to Tiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Storing Tiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Storing Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Finding a Tile’s Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Drawing Tiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xvi

xvi Contents

Scrolling Backgrounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133


The GameContext Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Scrolling Right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Scrolling Left . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Scrolling Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Scrolling Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Tile Layering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Storing the Foreground Tiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Adding Foreground Tiles to a Level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Drawing Foreground Tiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

Chapter 6
Animation . . . . . . . . . . . . . . . . 155
Introduction to Sprites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Generating Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Storing Sprites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Creating Transparency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Drawing Sprites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Sprite Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Creating the AnimationController Class . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Updating the Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Handling Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Handling Attacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Handling Standing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Maneuvering the Sprite through the Game World. . . . . . . . . . . . . . 176
Moving Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Moving Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xvii

Contents xvii

Moving Left . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181


Moving Right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Moving Diagonally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Dirty Rectangle Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
QuickDraw’s Dirty Rectangle Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Creating a Dirty Rectangle Animation System . . . . . . . . . . . . . . . . . . . . . . 192
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195

Chapter 7
InputSprocket. . . . . . . . . . . . . . 197
Introduction to InputSprocket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Setting Up Your Game to Use InputSprocket. . . . . . . . . . . . . . . . . . 200
What to Place in Your System Extensions Folder . . . . . . . . . . . . . . . . . . . . 200
What to Place in Your Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
InputSprocket Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
InputSprocket Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
InputSprocket Terminology. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
The InputController Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Starting InputSprocket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Determining the Version of InputSprocket the Player Has . . . . . . . . . . . . . 210
Initializing InputSprocket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Letting the User Configure the Controls . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Reading Button Presses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Reading Player Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Pausing and Resuming InputSprocket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Quitting InputSprocket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xviii

xviii Contents

Chapter 8
HID Manager . . . . . . . . . . . . . . 233
Introduction to the HID Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Setting Up Your Game to Use the HID Manager . . . . . . . . . . . . . . . 236
Programming with the HID Manager . . . . . . . . . . . . . . . . . . . . . . . . 236
HID Manager Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
HID Manager Version of the InputController Class . . . . . . . . . . . . . . . . . . 245
Finding the Player’s HID-Capable Devices . . . . . . . . . . . . . . . . . . . . . . . . . 247
Creating Device Interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Opening a Connection to the Input Device . . . . . . . . . . . . . . . . . . . . . . . . 252
Reading Button Presses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Reading Digital Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Reading Analog Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Configuring Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Setting Default Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Pausing and Resuming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Cleaning Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296

Chapter 9
Reading the Keyboard and Mouse
Plus Event Handling . . . . . . . . . 297
Reading the Keyboard Directly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Reading the Mouse Directly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Reading the Mouse Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Reading the Mouse Button. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Using the Classic Event Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xix

Contents xix

Looking for Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305


Handling Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Using Carbon Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Installing the Standard Window Event Handler. . . . . . . . . . . . . . . . . . . . . . 329
Installing the Standard Application Event Handler . . . . . . . . . . . . . . . . . . . 329
Defining Menu Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Breaking Out of the Carbon Event Loop . . . . . . . . . . . . . . . . . . . . . . . . . . 332
Creating Your Own Carbon Event Handlers . . . . . . . . . . . . . . . . . . . . . . . 332
Event Loop Timers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344

Chapter 10
Sound. . . . . . . . . . . . . . . . . . . 345
A Sound Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Sound Formats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Sampled Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
Programming Sound with the Sound Manager. . . . . . . . . . . . . . . . . 355
The GameSound Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Playing a Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Sound Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Callback Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Looping a Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Setting a Sound’s Volume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Pausing a Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Resuming a Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Stopping a Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Cleaning Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Low-Level Sound Playing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xx

xx Contents

Programming Sound with QuickTime . . . . . . . . . . . . . . . . . . . . . . . 381


QuickTime Movies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
The GameSong Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Starting QuickTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Reading a Movie from Disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Playing a Movie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Setting a Movie’s Volume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Pausing and Resuming Movies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Stopping a Movie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Giving Your Movie a Chance to Play. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Quitting QuickTime. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390

Chapter 11
Physics . . . . . . . . . . . . . . . . . . 391
Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
Vector Sums and Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Multiplication by a Scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
Dot Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Unit Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Parallel and Orthogonal Vectors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Linear Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
Position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Velocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Acceleration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Force . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Center of Mass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
Calculating the Total Linear Momentum . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xxi

Contents xxi

Calculating the Total Force. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412


Going from Math to Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Angular Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Angular Velocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Angular Acceleration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
Angular Momentum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Torque . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Moment of Inertia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
Calculating the Total Angular Momentum . . . . . . . . . . . . . . . . . . . . . . . . . . 430
Calculating the Total Torque . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
Going from Math to Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Collision Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Bounding Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Pixel-Perfect Collision Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Collision Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
Computing the Linear Velocities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Relative Velocities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
Computing the Impulse’s Magnitude. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
Computing the Angular Velocities for Rotating Bodies . . . . . . . . . . . . . . . . 445
Computing the Impulse’s Magnitude for Rotating Bodies . . . . . . . . . . . . . . 446
Going from Math to Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451

Chapter 12
Beginning Artificial Intelligence . . 455
Introduction to Game AI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
Our AI System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xxii

xxii Contents

Action Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459


Moving an Opponent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Chasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
Evading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
Patrolling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
Finite State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
Our State Machine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
Programming a State Machine with switch Statements . . . . . . . . . . . . . . . 470
Creating Finite State Machine Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
Using the State Machine Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
State Machine Enhancements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
Other AI Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Scripting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Random Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
Expert Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
Cheating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489

Chapter 13
Pathfinding . . . . . . . . . . . . . . . 491
Introduction to Pathfinding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
The A* Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
A* Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
Estimating the Path Cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
Coding the A* Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
Weaknesses of the A* Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
The Iterative Deepening A* Algorithm . . . . . . . . . . . . . . . . . . . . . . . 524
Coding the Iterative Deepening A* Algorithm . . . . . . . . . . . . . . . . . . . . . . 526
Coding the Depth-First Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xxiii

Contents xxiii

The Learning Real-Time A* Algorithm . . . . . . . . . . . . . . . . . . . . . . . 528


LRTA* Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Changes to the Pathfinder Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
Coding LRTA* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Hierarchical Pathfinding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543

Chapter 14
DrawSprocket . . . . . . . . . . . . . 545
Introduction to DrawSprocket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
DrawSprocket vs. QuickTime. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
Draw Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
Setting Up DrawSprocket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
What to Place in Your System Folder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
What to Place in Your Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
Programming with DrawSprocket . . . . . . . . . . . . . . . . . . . . . . . . . . 550
The DrawContext Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
Starting DrawSprocket. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Setting a Draw Context’s Needs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Maintaining the Current Screen Resolution . . . . . . . . . . . . . . . . . . . . . . . . 556
Selecting a Draw Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Multiple Monitor Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560
Making a List of All Draw Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564
Activating a Draw Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
Dealing with Questionable Resolutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
Pausing and Resuming Draw Contexts. . . . . . . . . . . . . . . . . . . . . . . . . . . . 570
Gamma Fades . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
Manipulating Color Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
00 Macgame_FM.qxd 2/21/03 5:02 PM Page xxiv

xxiv Contents

DrawSprocket Buffering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575


Working with the Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
Cleaning Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
Utility Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582

Chapter 15
Files . . . . . . . . . . . . . . . . . . . 585
Introduction to Navigation Services . . . . . . . . . . . . . . . . . . . . . . . . . 586
Opening Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
Navigation Services Dialog Box Options . . . . . . . . . . . . . . . . . . . . . . . . . . 591
Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
Navigation Type Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
After You Get the File to Open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
Saving Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
Data and Resource Forks of a File . . . . . . . . . . . . . . . . . . . . . . . . . . 603
Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
Common Apple-Defined Resource Types . . . . . . . . . . . . . . . . . . . . . . . . . . 605
Creating Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
Writing Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
Reading Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
A Resource Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
Writing to the Data Fork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
Reading from the Data Fork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
Bundles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
A Bundle’s Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
Creating a Bundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
Finding the Application’s Main Bundle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
Extracting Resources from a Bundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
Another Random Document on
Scribd Without Any Related Topics
CHAPTER XXXV

They were in the great sombre dining-room, with the almost black
tapestries, with the almost black panels of the ceiling, with the almost black
oak carvings, with the black, monumental chimney-piece and, above it, the
arms of the family in black marble. The light of two tall silver candle-sticks
on the table merely cast a gleam over the damask and crystal, but left the
remainder of the too large room in a gloomy obscurity of shadow, piled in
the corners into masses of densest shadow, with a fainter shadow
descending from the ceiling like a haze of dark velvet that floated in atoms
above the candlelight. The ancestral antiquity of San Stefano hovered above
them in this room like a palpable sense of awe, blended with a melancholy
of black silence and black pride. Here their words sounded muffled. This
still remained as it always had been, retaining as it were the sacrosanctity of
their aristocratic traditions, in which Urania would never dare to alter
anything, even as she hardly ventured to open her mouth to speak or eat.
They waited for a moment. Then a double door was opened. And there
entered like a spectral shade an old, grey man, with his arm in the arm of
the priest walking beside him. Old Prince Ercole approached with very slow
and stately steps, while the chaplain regulated his pace by that stately
slowness. He wore a long black coat of an old-fashioned, roomy cut, which
hung about him in folds, something like a cassock, and on his silvery grey
hair, which waved over his neck, a black-velvet skull-cap. And the others
approached him with the greatest respect: first the marchesa; then Urania,
whom he kissed on the forehead, very slowly, as though he were
consecrating her; then Gilio, who submissively kissed his father’s hand. The
old man nodded to young Hope, who bowed, and glanced towards Cornélie.
Urania presented her. And the prince said a few amiable words to her, as
though he were granting an audience, and asked her if she liked Italy. When
Cornélie had replied, Prince Ercole sat down and handed his skull-cap to
Giuseppe, who took it with a deep bow. Then they all sat down: the
marchesa and the chaplain opposite Prince Ercole, who sat between
Cornélie and Urania; Gilio next to Cornélie; Bob Hope next to his sister:

“My legs don’t show,” he whispered.

“Ssh!” said Urania.

Giuseppe, revivified in his former dignity, standing at a sideboard, solemnly


filled the plates with soup. He was back in his element; he was obviously
grateful to Urania; he wore a distinguished air, as of one whose mind is at
peace, and looked like an elderly diplomatist in his dress-coat. He amused
Cornélie, who thought of Belloni’s, where he used to become impatient
when the visitors were late at meals and to rail at the young greenhorns of
waiters whom the marchesa engaged for economy’s sake. When the two
footmen had handed round the soup, the chaplain stood up and said grace.
Not a word had been spoken yet. They ate the soup in silence, while the
three servants stood motionless. The spoons clinked against the plates and
the marchesa smacked her lips. The candles flickered now and again; and
the shadow fell more oppressively, like a haze of black velvet. Then Prince
Ercole addressed the marchesa. And turn by turn he addressed them all,
with a kindly, condescending dignity, in French and Italian. The
conversation became a little more general, but the old prince continued to
lead it. And Cornélie noticed that he was very civil to Urania. But she
remembered Gilio’s words:

“Papa nearly had a stroke, because old Hope haggled over Urania’s dowry.
Ten millions? Five millions? Not three millions! Dollars? No, lire!”

And the prince suddenly struck her as the grey-haired egoism of San
Stefano’s glory and aristocratic pride, struck her as the living shade of the
past that loomed behind him, as she had felt it that afternoon, when she
stood gazing with Urania into the deep, blue lake: an exacting shade; a
shade demanding millions; a shade demanding a new increment of vitality;
a spectral parasite who had sold his depreciated symbols to gratify the
vanity of a new commercial house, but who, in his distinction, had been no
match for the merchant’s cunning. Their title of princess and duchess for
less than three million lire! Papa had almost had a stroke, Gilio had said.
And Cornélie, during the measured, affable stiffness of the conversation led
by Prince Ercole, looked from the old prince and duke, seventy years of
age, to the breezy young Far-Westerner, aged eighteen, and from him to
Prince Gilio, the hope of the old house, its only hope. Here, in the gloom of
this dining-room, where he was bored and moreover still out of temper, he
seemed small, insignificant, shrunken, a paltry, distinguished little viveur;
and his carbuncle eyes, which could sparkle merrily with wit and depravity,
now looked dully, from under their drooping lids, upon his plate, at which
he picked without appetite.

She felt sorry for him; and her mind went back to the golden bridal
chamber. She despised him a little. She looked upon him not so much as a
man who could not obtain what he wanted but rather as a naughty boy. And
he must feel jealous of Bob, she reflected: jealous of his young blood,
which tingled in his cheeks, of his broad shoulders and his broad chest. But
still he amused her. He could be very agreeable, gay and witty and
vivacious, when in the mood, vivacious in his words and in his wits. She
liked him, when all was said. And then he was good-hearted. She thought of
the bracelet and especially the thousand lire, always remembered, with a
certain emotion, how touched she had been during that walk up and down
past the post-office, how touched by his letter and his generous assistance.
He had no backbone, he was not a man to her; but he was witty and he had
a very good heart. She liked him as a friend and a pleasant companion. How
dejected and moody he was! But then why would he venture on those silly
enterprises?...

She spoke to him now and again, but could not succeed in rousing him from
his depression. For the rest, the conversation dragged on stiffly and affably,
always led by Prince Ercole. The dinner came to an end; and Prince Ercole
rose from his chair. Giuseppe handed him his skull-cap; every one said
good-night to him; the doors were opened and Prince Ercole withdrew,
leaning on his chaplain’s arm. Gilio, still angry, disappeared. The marchesa,
still terrified of Cornélie, also disappeared, making the jettatura at her in
the folds of her dress. And Urania took Cornélie and Bob back with her to
her own drawing-room. They all three breathed again. They all talked
freely, in English: the boy said in despair that he wasn’t getting enough to
eat, that he dared not eat enough to stay his hunger; and Cornélie laughed,
thinking him jolly, because of his wholesomeness, while Urania hunted out
some biscuits for him and a piece of cake left over from tea and promised
that he should have some cold meat and bread before they went to bed. And
they relaxed their minds after the pompous, stately meal. Urania said that
the old prince never appeared except at dinner, but that she always looked
him up in the morning and sat talking to him for an hour or playing chess
with him. At other times he played chess with the chaplain. She was very
busy, Urania. The reorganizing of the housekeeping, which used to be left to
a poor relation, who now lived at a pension in Rome, took up a lot of her
time. In the mornings, she discussed a host of details with Prince Ercole,
who, notwithstanding his secluded life, knew about everything. Then she
had consultations with her architect from Rome about the restorations to be
effected in the castle: these consultations were sometimes held in the old
prince’s study. Then she was having a big hostel built in the town, an
albergo dei poveri, a hostel for old men and women, for which old Hope
had given her a separate endowment. When she first came to San Stefano
she had been struck by the ruinous, tumbledown houses and cottages of the
poorer quarters, leprous and scabby with filth, eaten up by their own
poverty, in which a whole population vegetated like toadstools. She was
now building the hostel for the old people, finding work on the estate for
the young and healthy and looking after the neglected children; she had
built a new school-house. She talked about all this very simply, while
cutting cake for her brother Bob, who was tucking in after his formal
dinner. She asked Cornélie to come with her one morning to see how the
albergo was progressing, to see the new school, run by two priests who had
been recommended to her by the monsignori.

Through the pointed windows the town loomed faintly in the depths below;
and the lines of the cathedral rose high into the sultry, star-spangled night.
And Cornélie thought to herself:
“It was not only for a shadow and an unsubstantial shade that she came
here, the rich American who thought titles ‘so nice,’ the child who used to
collect patterns of the queen’s ball-dresses—she hides the album now that
she is a ‘black’ princess—the girl who used to trip through the Forum in her
white-serge tailor-made, without understanding either ancient Rome or the
dawn of the new future.”

And, as Cornélie went to her own room through the silent heavy darkness
of the Castle of San Stefano, she thought:

“I write, but she acts. I dream and think; but she teaches the children,
though it be with the aid of a priest; she feeds and houses old men and
women.”

Then, in her room, looking out at the lake under the summer night all
dusted with stars, she reflected that she too would like to be rich and to
have a wide field of labour. For now she had no field, now she had no
money and now ... now she longed only for Duco; and he must not leave
her too long alone in this castle, amid all this sombre greatness, which
oppressed her as with the weight of the centuries.
CHAPTER XXXVI

Next morning Urania’s maid was showing Cornélie through a maze of


galleries to the garden, where breakfast was to be served, when she met
Gilio on the stairs. The maid turned back.

“I still need a guide to find my way,” Cornélie laughed.

He grunted some reply.

“How did you sleep, prince?”

He gave another grunt.

“Look here, prince, there must be an end of this ill-temper of yours. Do you
hear? It’s got to finish. I insist. I won’t have any more sulking to-day; and I
hope that you’ll go back to your cheerful, witty style of conversation as
soon as possible, for that’s what I like in you.”

He mumbled something.

“Good-bye, prince,” said Cornélie, curtly.

And she turned to go away.

“Where are you going?” he asked.

“To my room. I shall breakfast in my room.”

“But why?”
“Because I don’t care for you as a host.”

“Me?”

“Yes, you. Yesterday you insult me. I defend myself, you go on being rude,
I at once become as amiable as ever, I give you my hand, I even give you a
kiss. At dinner you sulk with me in the most uncivil fashion. You go to bed
without bidding me good-night. This morning you meet me without a word
of greeting. You grunt, sulk and mumble like a naughty child. Your eyes are
blazing with anger, you are yellow with spleen. Really, you’re looking very
bad. It doesn’t suit you at all. You are most unpleasant, rough, rude and
petty. I have no inclination to breakfast with you in that mood. And I’m
going to my room.”

“No,” he implored.

“Yes, I am.”

“No, no!”

“Then be different. Make an effort, don’t think any more about your defeat
and be nice to me. You’re behaving as the offended party, whereas it is I
who ought to take offence. But I don’t know how to sulk and I am not petty.
I can’t behave pettily. I forgive you; do you forgive me too. Say something
nice, say something pleasant.”

“I am mad about you.”

“You don’t show it. If you’re mad about me, be pleasant, civil, gay and
witty. I demand it of you as my host.”

“I won’t sulk any longer ... but I do love you so! And you struck me!”

“Will you never forget that act of self-defence?”

“No, never!”

“Then good-bye.”
She turned to go.

“No, no, don’t go back. Come to breakfast in the pergola. I apologize, I beg
your pardon. I won’t be rude again, I won’t be petty. You are not petty. You
are the most wonderful woman I ever met. I worship you.”

“Then worship in silence and amuse me.”

His eyes, his black carbuncle eyes, began to light up again, to laugh; his
face lost its wrinkles and cheered up.

“I am too sad to be amusing.”

“I don’t believe a word of it.”

“Honestly, I am full of sorrow and suffering....”

“Poor prince!”

“You just won’t believe me. You never take me seriously. I have to be your
clown, your buffoon. And I love you and have nothing to hope for. Tell me,
mayn’t I hope?”

“Not much.”

“You are inexorable ... and so severe!”

“I have to be severe with you: you are just like a naughty boy.... Oh, I see
the pergola! Do you promise to improve?”

“I shall be good.”

“And amusing?”

He heaved a sigh:

“Poor Gilio!” he sighed. “Poor buffoon!”


She laughed. In the pergola were Urania and Bob Hope. The pergola,
overgrown with creeping vine and rambler roses hanging in crimson
clusters, displayed a row of marble caryatides and hermes—nymphs, satyrs
and fauns—whose torsos ended in slender, sculptured pedestals, while their
raised hands supported the flat roof of leaves and flowers. In the middle
was an open rotunda like an open temple; the circular balustrade was also
supported by caryatides; and an ancient sarcophagus had been adapted to
serve as a cistern. A table was laid for breakfast in the pergola; and they
breakfasted without old Prince Ercole or the marchesa, who broke her fast
in her room. It was eight o’clock; a morning coolness was still wafted from
the lake; a haze of blue gossamer floated over the hills, in the heart of
which, as though surrounded by a gently fluted basin, the lake was sunk like
an oval goblet.

“Oh, how beautiful it is here!” cried Cornélie, delightedly.

Breakfast was a sunny and cheerful meal, after yesterday’s dark and gloomy
dinner. Urania talked vivaciously about her albergo, which she was going to
visit presently with Cornélie, Gilio recovered his amiability and Bob ate
heartily. And, when Bob went off bicycling, Gilio even accompanied the
ladies to the town. They drove at a foot-pace in a landau down the castle
road. The sun grew hotter and the little old town lit up, with whitish-grey
and creamy-white houses like stone mirrors, in which the sun reflected
itself, and little open spaces like walls, into which the sun poured its light.
The coachman pulled up outside the partly-finished albergo. They all
alighted; the contractor approached ceremoniously; the perspiring masons
looked round at the prince and princess. The heat was stifling. Gilio kept on
wiping his forehead and sheltered under Cornélie’s parasol. But Urania was
all vivacity and interest; quick and full of energy in her white-piqué
costume, with her white sailor-hat under her white sun-shade, she tripped
along planks, past heaps of bricks and cement and tubs full of mortar,
accompanied by her contractor. She made him explain things, proffered
advice, disagreed with him at times and pulled a wise face, saying that she
did not like certain measurements and refused to accept the contractor’s
assurance that she would like the measurements as the building progressed;
she shook her head and impressed this and that upon him, all in a quick,
none too correct, broken Italian, which she chewed between her teeth. But
Cornélie thought her charming, attractive, every inch the Princess di Forte-
Braccio. There was not a doubt about it. While Gilio, fearful of dirtying his
light flannel suit and brown shoes with the mortar, remained in the shadow
of her parasol, puffing and blowing with the heat and taking no interest
whatever, his wife was untiring, did not trouble to think that her white skirt
was becoming soiled at the hem and spoke to the contractor with a lively
and dignified certainty which compelled respect. Where had the child learnt
that? Where had she acquired her powers of assimilation? Where did she
get this love for San Stefano, this love for its poor? How had the American
girl picked up this talent for filling her new and exalted position so
worthily? Gilio thought her admirabile and whispered as much to Cornélie.
He was not blind to her good qualities. He thought Urania splendid,
excellent; she always astounded him. No Italian woman of his own set
would have been like that. And they liked her. The servants at the castle
loved her. Giuseppe would have gone through fire and water for her; that
contractor admired her; the masons followed her respectfully with their
eyes, because she was so clever and knew so much and was so good to
them in their poverty.

“Admirabile!” said Gilio.

But he puffed and blowed. He knew nothing about bricks, beams and
measurements and did not understand where Urania had got that technical
sense from. She was indefatigable. She went all over the works, while he
cast up his eyes to Cornélie in entreaty. And at last, speaking in English, he
begged his wife in Heaven’s name to come away. They went back to the
carriage; the contractor took off his hat, the workmen raised their caps with
an air of mingled gratitude and independence. And they drove to the
cathedral, which Cornélie wanted to see. Urania showed her round. Gilio
asked to be excused and went and sat on the steps of the altar, with his
hands hanging over his knees, to cool himself.
CHAPTER XXXVII

A week had passed. Duco had arrived. After the solemn dinner in the
gloomy dining-room, where Duco had been presented to Prince Ercole, the
summer evening, when Cornélie and Duco went outside, was like a dream.
The castle was already wrapped in heavy repose; but Cornélie had made
Giuseppe give her a key. And they went out, to the pergola. The stars dusted
the night sky with a pale radiance; and the moon crowned the hill-tops and
shimmered faintly in the mystic depths of the lake. A breath of sleeping
roses was wafted from the flower-garden beyond the pergola; and below, in
the flat-roofed town, the cathedral, standing in its moonlit square, lifted its
gigantic fabric to the stars. And sleep hung everywhere, over the lake, over
the town and behind the windows of the castle; the caryatides and hermes—
the satyrs and nymphs—slept, as they bore the leafy roof of the pergola, in
the enchanted attitudes of the servants of the Sleeping Beauty. A cricket
chirped, but fell silent the moment that Duco and Cornélie approached. And
they sat down on an antique bench; and she flung her arms about his body
and nestled against him:

“A week!” she whispered. “A whole week since I saw you, Duco, my


darling. I cannot do so long without you. At everything that I thought and
saw and admired I thought of you, of how lovely you would think it here.
You have been here once before on an excursion. Oh, but that is so
different! It is so beautiful just to stay here, not just to go on, but to remain.
That lake, that cathedral, those hills! The rooms indoors: neglected but so
wonderful! The three courtyards are dilapidated, the fountains are
crumbling to pieces ... but the style of the atrio, the sombre gloom of the
dining-room, the poetry of this pergola!... Duco, doesn’t the pergola remind
you of a classic ode? You know how we used to read Horace together: you
translated the verses so well, you improvised so delightfully. How clever
you are! You know so much, you feel things so beautifully. I love your eyes,
your voice, I love you altogether, I love everything that is you ... I can’t tell
you how much, Duco. I have gradually surrendered myself to every word of
you, to every sensation of you, to your love for Rome, to your love for
museums, to your manner of seeing the skies which you put into your
drawings. You are so deliriously calm, almost like this lake. Oh, don’t
laugh, don’t make a jest of it: it’s a week since I saw you, I feel such a need
to talk to you! Is it exaggerated? I don’t feel quite normal here either: there
is something in that sky, in that light, that makes me talk like this. It is so
beautiful that I can hardly believe that all this is ordinary life, ordinary
reality.... Do you remember, at Sorrento, on the terrace of the hotel, when
we looked out over the sea, over that pearl-grey sea, with Naples lying
white in the distance? I felt like this then; but then I dared not speak like
this: it was in the morning; there were people about, whom we didn’t see
but who saw us and whom I suspected all around me; but now we are alone
and now I want to tell you, in your arms, against your breast, how happy I
am! I love you so! All my soul, all that is finest in me is for you. You laugh,
but you don’t believe me. Or do you? Do you believe me?”

“Yes, I believe you, I am not laughing at you, I am only just laughing....


Yes, it is beautiful here.... I also feel happy. I am so happy in you and in my
art. You taught me to work, you roused me from my dreams. I am so happy
about The Banners: I have heard from London; I will show you the letters
to-morrow. I have you to thank for everything. It is almost incredible that
this is ordinary life. I have been so quiet too in Rome. I saw nobody; I just
worked a bit, not very much; and I had my meals alone in the osteria. The
two Italians—you know the men I mean—felt sorry for me, I think. Oh, it
was a terrible week! I can no longer do without you.... Do you remember
our first walks and talks in the Borghese and on the Palatine? How strange
we were to each other then, not a bit in unison. But I believe I felt at once
that all would be well and beautiful between us....”

She was silent and lay against his breast. The cricket chirped again, with a
long quaver. But everything else slept....
“Between us,” she repeated, as though in a fever; and she embraced him
passionately.

The whole night slept; and, while they breathed their life in each other’s
arms, the enchanted caryatides—fauns and nymphs—lifted the leafy roof of
the pergola above their heads, between them and the star-spangled sky.
CHAPTER XXXVIII

Gilio hated the villeggiatura at San Stefano. Every morning he had to be up


and dressed by six o’clock, with Prince Ercole, Urania and the marchesa, to
hear mass said by the chaplain in the private chapel of the castle. After that,
he did not know what to do with his time. He had gone bicycling once or
twice with Bob Hope, but the young Far-Westerner had too much energy for
him, like Bob’s sister, Urania. He flirted and argued a little with Cornélie,
but secretly he was still offended and angry with himself and her. He
remembered her first arrival that evening at the Palazzo Ruspoli, when she
came and disturbed his rendez-vous with Urania. And in the camera degli
sposi she had for the second time been too much for him! He seethed with
fury when he thought of it and he hated her and swore by all his gods to be
revenged. He cursed his own lack of resolution. He had been too weak to
use violence or force and there ought never to have been any need to resort
to force: he was accustomed to a quick surrender. And he had to be told by
her, that Dutchwoman, that his temperament did not respond to hers! What
was there about that woman? What did she mean by it? He was so
unaccustomed to thinking, he was such a thoughtless, easy-going, Italian
child of nature, so accustomed to let his life run on according to his every
whim and impulse, that he hardly understood her—though he suspected the
meaning of her words—hardly understood that reserve of hers. Why should
she behave so to him, this foreigner with her demoniacal new ideas, who
cared nothing about the world, who would have nothing to do with
marriage, who lived with a painter as his mistress! She had no religion and
no morals—he knew about religion and morals—she belonged to the devil;
demoniacal was what she was: didn’t she know all about Aunt Lucia
Belloni’s manœuvres? And hadn’t Aunt Lucia warned him lately that she
was a dangerous woman, an uncanny woman, a woman of the devil? She
was a witch! Why should she refuse? Hadn’t he plainly seen her figure last
night going through the courtyard in the moonlight, beside Van der Staal’s
figure, and hadn’t he seen them opening the door that led to the terrace by
the pergola? And hadn’t he waited an hour, two hours, without sleeping,
until he saw them come back and lock the door after them? And why did
she love only him, that painter? Oh, he hated him, with all the blazing
hatred of his jealousy; he hated her, for her exclusiveness, for her disdain,
for all her jesting and flirting, as though he were a buffoon, a clown! What
was it that he asked? A favour of love, such as she granted her lover! He
was not asking for anything serious, any oath or lifelong tie; he asked for so
little: just one hour of love. It was of no importance: he had never looked
upon that as of much importance. And she, she refused it to him! No, he did
not understand her, but what he did understand was that she disdained him;
and he, he hated the pair of them. And yet he was enamoured of her with all
the violence of his thwarted passion. In the boredom of that villeggiatura, to
which his wife forced him in her new love for their ruined eyrie, his hatred
and the thought of his revenge formed an occupation for his empty brains.
Outwardly he was the same as usual and flirted with Cornélie, flirted even
more than usual, to annoy Van der Staal. And, when his cousin, the
Countess di Rosavilla—his “white” cousin, the lady-in-waiting to the queen
—came to spend a few days with them, he flirted with her too and tried to
provoke Cornélie’s jealousy. He failed in this, however, and consoled
himself with the countess, who made up to him for his disappointment. She
was no longer a young woman, but represented the cold, sculptured Juno
type, with a rather foolish expression; she had Juno eyes, protruding from
their sockets; she was a leader of fashion at the Quirinal and in the “white”
world; and her reputation for gallantry was generally known. She had never
had a liaison with Gilio that lasted for longer than an hour. She had very
simple ideas on love, without much variety. Her light-hearted depravity
amused Gilio. And, flirting in the corners, with his foot on hers under her
skirt, Gilio told her about Cornélie, about Duco and about the adventure in
the camera degli sposi and asked his cousin whether she understood. No,
the Countess di Rosavilla did not understand it any too well either.
Temperament? Oh, yes, perhaps she—questa Cornelia—preferred fair men
to dark: there were women who had a preference! And Gilio laughed. It was
so simple, l’amore; there wasn’t very much to be said about it.
Cornélie was glad that Gilio had the countess to amuse him. She and Duco
interested themselves in Urania’s plans; Duco had long talks with the
architect. And he was indignant and advised them not to rebuild so much in
that undistinguished restoration manner: it was lacking in style, cost heaps
of money and spoilt everything.

Urania was disconcerted, but Duco went on, interrupted the architect,
advised him to build up only what was actually falling to pieces, and, so far
as possible, to confine himself to underpinning, reinforcing and preserving.
And one morning Prince Ercole deigned to walk through the long rooms
with Duco, Urania and Cornélie. There was a great deal to be done, Duco
considered, by merely repairing and artistically arranging what at present
stood thoughtlessly huddled together.

“The curtains?” asked Urania.

“Let them be,” Duco considered. “At the most, new window-curtains; but
the old red Venetian damask; oh, let it be, let it be!”

It was so beautiful; here and there it might be patched, very carefully. He


was horrified at Urania’s notion: new curtains! And the old prince was
enraptured, because in this way the restoration of San Stefano would cost
thousands less and be much more artistic. He regarded his daughter-in-law’s
money as his own and preferred it to her. He was enraptured: he took Duco
with him to his library, showed him the old missals, the old family books
and papers, charters and deeds of gift, showed him his coins and medals. It
was all out of order and neglected, first from lack of money and then from
slighting indifference; but now Urania wanted to reorganize the family
museum with the aid of experts from Rome, Florence and Bologna. The old
prince’s interest revived, now that there was money. And the experts came
and stayed at the castle and Duco spent whole mornings in their company.
He enjoyed every moment of it. He lived in his enchantment of the past, no
longer in the days of antiquity, but in the middle ages and the Renascence.
The days were too short. And his love for San Stefano became such that one
day an archivist took him for the young prince, for Prince Virgilio. At
dinner that evening Prince Ercole told the story. And everybody laughed,
but Gilio thought the joke beyond price, whereas the archivist, who was
there at dinner, did not know how to apologize sufficiently.
CHAPTER XXXIX

Gilio had followed the advice of his cousin, the Countess di Rosavilla.
Immediately after dinner, he had stolen outside; and he walked along the
pergola to the rotunda, into which the moonlight fell as into a white beaker.
But there was shadow behind a couple of caryatides; and here he hid. He
waited for an hour. But the night slept, the caryatides slept, standing
motionless and supporting the leafy roof. He uttered a curse and stole
indoors again. He walked down the corridors on tiptoe and listened at Van
der Staal’s door. He heard nothing, but perhaps Van der Staal was asleep?...

Gilio, however, crept along another corridor and listened at Cornélie’s door.
He held his breath.... Yes, there was a sound of voices. They were together!
Together! He clenched his fists and walked away. But why did he excite
himself? He knew all about their relations. Why should they not be together
here? And he went on and tapped at the countess’ door....

Next evening he again waited in the rotunda. They did not come. But, a few
evenings later, as he sat waiting, choking with annoyance, he saw them
come. He saw Duco lock the terrace-door behind him: the rusty lock grated
in the distance. Slowly he saw them walk along and approach in the light,
disappearing from view in the shadow, reappearing in the moonlight. They
sat down on the marble bench....

How happy they seemed! He was jealous of their happiness, jealous above
all of him. And how gentle and tender she was, she who considered him,
Gilio, only good enough for her amusement, to flirt with, a clown: she, the
devilish woman, was angelic to the man she loved! She bent towards her
lover with a smiling caress, with a curve of her arm, with a proffering of her
lips, with something intensely alluring, with a velvety languor of love
which he would never have suspected in her, after her cold, jesting flirtation
with him, Gilio. She was now leaning on Duco’s arms, on his breast, with
her face against his.... Oh, how her kiss filled Gilio with flame and fury!
This was no longer her icy lack of sensuous response towards him, Gilio, in
the camera degli sposi. And he could restrain himself no longer: he would
at least disturb their moment of happiness. And, quivering in every nerve,
he stepped from behind the caryatides and went towards them, through the
rotunda. Lost in each other’s eyes, they did not see him at once. But,
suddenly, simultaneously, they both started; their arms fell apart then and
there; they sprang up in one movement; they saw him approaching but
evidently did not at once recognize him. Not until he was closer did they
perceive who he was; and they looked at him in startled silence, wondering
what he would say. He made a satirical bow:

“A delightful evening, isn’t it? The view is lovely, like this, at night, from
the pergola. You are right to come and enjoy it. I hope that I am not
disturbing you with my unexpected company?”

His tremulous voice sounded so spiteful and aggressive that they could not
doubt the violence of his anger.

“Not at all, prince!” replied Cornélie, recovering her composure. “Though I


can’t imagine what you are doing here, at this hour.”

“And what are you doing here, at this hour?”

“What am I doing? I am sitting with Van der Staal....”

“At this hour?”

“At this hour! What do you mean, prince, what are you suggesting?”

“What am I suggesting? That the pergola is closed at night.”

“Prince,” said Duco, “your tone is offensive.”

“And you are altogether offensive.”


“If you were not my host, I would strike you in the face....”

Cornélie caught Duco by the arm; the prince cursed and clenched his fists.

“Prince,” she said, “you have obviously come to pick a quarrel with us.
Why? What objection can you have to my meeting Van der Staal here in the
evening? In the first place, our relation towards each other is no secret for
you. And then I think it unworthy of you to come spying on us.”

“Unworthy? Unworthy?” He had lost all self-control. “I am unworthy, am I,


and petty and rude and not a man and my temperament doesn’t suit you?
His temperament seems to suit you all right! I heard the kiss you gave him!
She-devil! Demon! Never have I been insulted as I have by you. I have
never put up with so much from anybody. I will put up with no more. You
struck me, you demon, you she-devil! And now he’s threatening to strike
me! My patience is at an end. I can’t bear that in my own house you should
refuse me what you give to him.... He’s not your husband! He’s not your
husband! I have as much right to you as he; and, if he thinks he has a better
right than I, then I hate him, I hate him!...”

And, blind with rage, he flew at Duco’s throat. The attack was so
unexpected that Duco stumbled. They both wrestled furiously. All their
hidden antipathy broke forth in fury. They did not hear Cornélie’s
entreaties, they struck each other with their fists, they grappled with arms
and legs, breast to breast. Then Cornélie saw something flash. In the
moonlight she saw that the prince had drawn a knife. But the very
movement was an advantage to Duco, who gripped his wrist as in a vice,
forced him to the ground and, pressing his knee on Gilio’s chest, took him
by the throat with his other hand.

“Let go!” yelled the prince.

“Let go that knife!” yelled Duco.

The prince obstinately persisted:

“Let go!” he yelled once more.


“Let go that knife.”

The knife dropped from his fingers. Duco grasped it and rose to his feet:

“Get up,” he said, “we can continue this fight, if you like, to-morrow, under
less primitive conditions: not with a knife, but with swords or pistols.”

The prince stood panting, blue in the face.... When he came to himself, he
said, slowly:

“No, I will not fight a duel. Unless you want to. But I don’t. I am defeated.
She has a demoniacal force which would always make you win, whatever
game we played. We’ve had our duel. This struggle tells me more than a
regular duel would. Only, if you want to fight me, I have no objection. But I
now know for certain that you would kill me. She protects you.”

“I don’t want to fight a duel with you,” said Duco.

“Then let us look on this struggle as a duel and now give me your hand.”

Duco put out his hand; Gilio pressed it:

“Forgive me,” he said, bowing before Cornélie. “I have insulted you.”

“No,” said she, “I do not forgive you.”

“We have to forgive each other. I forgive you the blow you struck me.”

“I forgive you nothing. I shall never forgive you this evening’s work: not
your spying, nor your lack of self-control, nor the rights which you try to
claim from me, an unmarried woman—whereas I allow you no rights
whatever—nor your attack, nor your knife.”

“Are we enemies then, for good?”

“Yes, for good. I shall leave your house to-morrow.”


“I have done wrong,” he confessed, humbly. “Forgive me. I am hot-
blooded.”

“Until now I looked upon you as a gentleman....”

“I am also an Italian.”

“I do not forgive you.”

“I once proved to you that I could be a good friend.”

“This is not the moment to remind me of it.”

“I remind you of everything that might make you more gently disposed
towards me.”

“It is no use.”

“Enemies then?”

“Yes. Let us go indoors. I shall leave your house to-morrow.”

“I will do any penance that you inflict upon me.”

“I inflict nothing. I want this conversation to end and I want to go indoors.”

“I will go ahead of you.”

They walked up the pergola. He himself opened the terrace-door and let
them in before him.

They went in silence to their rooms. The castle lay asleep in darkness. The
prince struck a match to light the way. Duco was the first to reach his room.

“I will light you to your room,” said the prince, meekly.

He struck a second match and accompanied Cornélie to her door. Here he


fell on his knees:
“Forgive me,” he whispered, with a sob in his throat.

“No,” she said.

And without more she locked the door behind her. He remained on his
knees for another moment. Then he slowly rose to his feet. His throat hurt
him. His shoulder felt as though it were dislocated.

“It’s over,” he muttered. “I am defeated. She is stronger now than I, but not
because she is a devil. I have seen them together. I have seen their embrace.
She is stronger, he is stronger than I ... because of their happiness. I feel
that, because of their happiness, they will always be stronger than I....”

He went to his room, which adjoined Urania’s bedroom. His chest heaved
with sobs. Dressed as he was, he flung himself sobbing on his bed,
swallowing his sobs in the slumbering night that hung over the castle. Then
he got up and looked out of the window. He saw the lake. He saw the
pergola, where they had been fighting. The night was sleeping there; the
caryatides, sleeping, stood out white against the shadow. And his eyes
sought the exact spot of their struggle and of his defeat. And, with his
superstitious faith in their happiness, he became convinced that there would
be no fighting against it, ever.

Then he shrugged his shoulders, as if he were flinging a load off his back:

“Fa niente!” he said to console himself. “Domani megliore....”

And he meant that to-morrow he would achieve, if not this victory, another.
Then, with eyes still moist, he fell asleep like a child.
CHAPTER XL

Urania sobbed nervously in Cornélie’s arms when she told the young
princess that she was leaving that morning. She and Duco were alone with
Urania in Urania’s own drawing-room.

“What has happened?” she sobbed.

Cornélie told her of the previous evening:

“Urania,” she said, seriously, “I know I am a coquette. I thought it pleasant


to talk with Gilio; call it flirting, if you like. I never made a secret of it,
either to Duco or to you. I looked upon it as an amusement, nothing more.
Perhaps I did wrong; I know it annoyed you once before. I promised not to
do it again; but it seems to be beyond my control. It’s in my nature; and I
shall not attempt to defend myself. I looked upon it as a trifle, as a
diversion, as fun. But perhaps it was wrong. Do you forgive me? I have
grown so fond of you: it would hurt me if you did not forgive me.”

“Make it up with Gilio and stay on.”

“That’s impossible, my dear girl. Gilio has insulted me, Gilio drew his knife
against Duco; and those are two things which I can never forgive him. So it
is impossible for us to remain.”

“I shall be so lonely!” she sobbed. “I also am so fond of you, I am fond of


you both. Is there no way out of it? Bob is going to-morrow too. I shall be
all alone. And I have nothing here, nobody who is fond of me....”
“You have a great deal left, Urania. You have an object in life; you can do
any amount of good in your surroundings. You are interested in the castle,
which is now your own.”

“It’s all so empty!” she sobbed. “It means nothing to me. I need affection.
Who is there that is fond of me? I have tried to love Gilio and I do love him,
but he doesn’t care for me. Nobody cares for me.”

“Your poor are devoted to you. You have a noble aim in life.”

“I’m glad of it, but I am too young to live only for an aim. And I have
nothing else. Nobody cares for me.”

“Prince Ercole, surely?”

“No, he despises me. Listen. I told you once before what Gilio said ... that
there were no family-jewels, that they were all sold: you remember, don’t
you? Well, there are family-jewels. I gathered that from something the
Countess di Rosavilla said. There are family-jewels. But Prince Ercole
keeps them in the Banco di Roma. They despise me; and I am not thought
good enough to wear them. And to me they pretend that there are none left.
And the worst of it is that all their friends, all their set know that the jewels
are there, in the bank, and they all say that Prince Ercole is right. My money
is good enough for them, but I am not good enough for their old jewels, the
jewels of their grandmother!”

“That’s a shame!” said Cornélie.

“It’s the truth!” sobbed Urania. “Oh, do make it up, stay a little longer, for
my sake!...”

“Judge for yourself, Urania: we really can’t.”

“I suppose you’re right,” she admitted, with a sigh.

“It’s all my fault.”


“No, no, Gilio is sometimes so impetuous....”

“But his impetuousness, his anger, his jealousy are my fault. I am sorry
about it, Urania, because of you. Forgive me. Come and look me up in
Rome when you go back. Don’t forget me; and write, won’t you?... Now I
must go and pack my trunk. What time is the train?”

“Ten twenty-five,” said Duco. “We shall go together.”

“Can I say good-bye to Prince Ercole? Send and ask if he can see me.”

“What shall I tell him?”

“The first thing that comes into your head: that a friend of mine in Rome is
ill, that I am going to look after her and that Van der Staal is taking me back
because I am nervous travelling. I don’t care what Prince Ercole thinks.”

“Cornélie....”

“Darling, I really haven’t another moment. Kiss me and forgive me. And
think of me sometimes. Good-bye. We have had a delightful time together
and I have grown very fond of you.”

She tore herself from Urania’s embrace; Duco also said good-bye. They left
the princess sobbing by herself. In the passage they met Gilio.

“Where are you going?” he asked, in his humble voice.

“We are going by the ten twenty-five.”

“I am very, very sorry....”

But they went on and left him standing there, while Urania sat sobbing in
the drawing-room.
CHAPTER XLI

In the train, in the scorching morning heat, they were silent; and they found
Rome as it were bursting out of its houses in the blazing sunshine. The
studio, however, was cool, solitary and peaceful.

“Cornélie,” said Duco, “tell me what happened between you and the prince.
Why did you strike him?”

She pulled him down on the sofa, threw herself on his neck and told him the
incident of the camera degli sposi. She told him of the thousand lire and the
bracelet. She explained that she had said nothing about it before, so as not
to speak to him of financial worries while he was finishing his water-colour
for the exhibition in London:

“Duco,” she continued, “I was so frightened when I saw Gilio draw that
knife yesterday. I felt as if I was going to faint, but I didn’t. I had never seen
him like that, so violent, so ready to do anything.... It was then that I really
felt how much I loved you. I should have murdered him if he had wounded
you.”

“You ought not to have played with him,” he said, severely. “He loves you.”

But, in spite of his stern voice, he drew her closer to him.

Filled with a certain consciousness of guilt, she laid her head coaxingly on
his chest:

“He is only a little in love,” she said, defending herself feebly.


“He is very passionately in love. You ought not to have played with him.”

She made no further reply, merely stroked his face with her hand. She liked
him all the better for reproaching her as he did; she loved that stern, earnest
voice, which he hardly ever adopted towards her. She knew that she had
that need for flirting in her, that she had had it ever since she was a very
young girl; it did not count with her, it was only innocent fun. She did not
agree with Duco, but thought it unnecessary to go over the whole ground: it
was as it was, she didn’t think about it, didn’t dispute it; it was like a
difference of opinion, almost of taste, which did not count. She was lying
against him too comfortably, after the excitement of last evening, after a
sleepless night, after a precipitate departure, after a three hours’ railway-
journey in the blazing heat, to argue to any extent. She liked the silent
coolness of the studio, the sense of being alone with him, after her three
weeks at San Stefano. There was a peacefulness here, a return to herself,
which filled her with bliss. The tall window was open and the warm air
poured in beneficently and was tempered by the natural chilliness of the
north room. Duco’s easel stood empty, awaiting him. This was their home,
amid all that colour and form of art which surrounded them. She now
understood that colour and form; she was learning Rome. She was learning
it all in dreams of happiness. She gave little thought to the woman question
and hardly glanced at the notices of her pamphlet, taking but a scanty
interest in them. She admired Lippo’s angel, admired the panel of Gentile
da Fabriano and the resplendent colours of the old chasubles. It was very
little, after the treasures at San Stefano, but it was theirs and it was home.
She did not speak, felt happy and contented resting on Duco’s breast and
passing her fingers over his face.

“The Banners is as good as sold,” he said. “For ninety pounds. I shall


telegraph to London to-day. And then we shall soon be able to pay the
prince back that thousand lire.”

“It’s Urania’s money,” she said, feebly.

“But I won’t have that debt hanging on.”


She felt that he was a little angry, but she was in no mood to discuss money
matters and she was filled with a blissful languor as she lay on his breast....

“Are you cross, Duco?”

“No ... but you oughtn’t to have done it.”

He clasped her more tightly, to make her feel that he did not want to
grumble at her, even though he thought that she had done wrong. She
thought that she had done right not to mention the thousand lire to him, but
she did not defend herself. It meant useless words; and she felt too happy to
talk about money.

“Cornélie,” he said, “let us get married.”

She looked at him in dismay, startled out of her blissfulness:

“Why?”

“Not because of ourselves. We are just as happy unmarried. But because of


the world, because of people.”

“Because of the world? Because of people?”

“Yes. We shall be feeling more and more isolated. I discussed it once or


twice with Urania. She was very sorry about it, but she sympathized with us
and wasn’t shocked. She thought it an impossible position. Perhaps she is
right. We can’t go anywhere. At San Stefano they still acted as though they
did not know that we were living together; but that is over now.”

“What do you care about the opinion of ‘small, insignificant people, who
chance to cross your path,’ as you yourself say?”

“It’s different now. We owe the prince money; and Urania is the only friend
you have.”

“I have you: I don’t want any one else.”


Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like