Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 541 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
541
Dung lượng
3,32 MB
Nội dung
i Contents Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 ProgrammingWindows GameswithBorland C++ ii ProgrammingWindowsGameswithBorlandC++ Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 iii Contents Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 A Division of Prentice Hall Computer Publishing 11711 North College, Carmel, Indiana, 46032 USA PUBLISHING S MS ProgrammingWindows GameswithBorland C++ Nabajyoti Barkakati iv ProgrammingWindowsGameswithBorlandC++ Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 To Leha, Ivy, Emily, and Ashley Copyright 1993 by Sams Publishing FIRST EDITION All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, record- ing, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. For information, address Sams Publishing, 11711 N. College Ave., Carmel, IN 46032. International Standard Book Number: 0-672-30292-6 Library of Congress Catalog Card Number: 92-82084 96 95 94 93 4 3 2 1 Interpretation of the printing code: the rightmost double-digit number is the year of the book’s printing; the rightmost single-digit, the number of the book’s printing. For example, a printing code of 93-1 shows that the first printing of the book occurred in 1993. Composed in Palatino and MCPdigital by Prentice Hall Computer Publishing Printed in the United States of America Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. BorlandC++ is a registered trademark of Borland International, Inc. Windows is a trademark of Microsoft Corporation. v Contents Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 Publisher Richard K. Swadley Acquisitions Manager Jordan Gold Acquisitions Editor Stacy Hiquet Development Editor Dean Miller Senior Editor Tad Ringo Production Editor Nancy Albright Editorial Coordinators Rebecca S. Freeman Bill Whitmer Editorial Assistants Rosemarie Graham Sharon Cox Technical Reviewer Tim Moore Marketing Manager Greg Wiegand Cover Designers Tim Amrhein Kathy Hanley Director of Production and Manufacturing Jeff Valler Production Manager Corinne Walls Imprint Manager Matthew Morrill Book Designer Michele Laseau Production Analyst Mary Beth Wakefield Proofreading/Indexing Coordinator Joelynn Gifford Graphics Image Specialists Dennis Sheehan Sue VandeWalle Production Christine Cook Mitzi F. Gianakos Howard Jones John Kane Sean Medlock Roger Morgan Juli Pavey Angela M. Pozdol Linda Quigley Michelle M. Self Suzanne Tully Barbara Webster Phil Worthington Indexer John Sleeva vi ProgrammingWindowsGameswithBorlandC++ Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 Overview Preface xiii Introduction xvii Part I Basics of Game ProgrammingwithBorland C+ 1 Game Programming for Windows 3 2 WindowsProgrammingwithBorlandC++ 21 3 Graphics Programmingwith the Windows API 57 4 Understanding Image File Formats 95 5 Animating Images 149 6 Generating Sound 189 Part II Sample Games 7 SPUZZLE—A Spelling Puzzle 205 8 3-D Graphics 275 9 BLOCKADE—A Game of Modern Naval Simulation 317 Index 495 vii Contents Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 Contents Introduction xvii Part I Basics of Game ProgrammingwithBorlandC++ 1 Game Programming for Windows 3 An Overview of Computer Games 5 Common Themes in Computer Games 8 Common Elements of Computer Games 15 Issues in Game Programming for Windows 18 Color 18 Multimedia Games for Windows 19 Summary 20 Further Reading 20 2 WindowsProgrammingwithBorlandC++ 21 Microsoft WindowsProgrammingwithBorlandC++ Classes 23 Model-View-Controller (MVC) Architecture 24 A Windows Application Using OWL and CLASSLIB 26 BorlandC++ Class Libraries 40 Breakdown of the CLASSLIB Classes 41 Template-Based Container Classes 46 OWL Classes 50 Summary 54 Further Reading 54 3 Graphics Programmingwith the Windows API 57 Windows Graphics Device Interface 58 Device Context 59 GDI Coordinate Systems 65 viii ProgrammingWindowsGameswithBorlandC++ Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 Drawing with GDI Functions 68 Drawing Points 69 Drawing Lines 69 Drawing Closed Figures 70 Manipulating Rectangles 72 Regions 74 Drawing Mode 76 Text Output 77 Handling Color 80 System Palette 81 Logical Palette 81 Bitmaps 86 Device-Dependent Bitmaps 86 Device-Independent Bitmap (DIB) Format 92 Summary 93 Further Reading 94 4 Understanding Image File Formats 95 Image File Formats 96 Common Characteristics of Image Files 97 Some Common Formats 99 C++ Classes for Handling Image Files 100 ImageData Class 101 Image Class 105 BMPImage Class 113 TGAImage Class 119 PCXImage Class 125 ImageView—A Windows Image Viewer 136 Running ImageView 136 ImageViewApp Class 136 ImageViewFrame and ImageViewWindow Classes 139 Building ImageView 145 Summary 146 Further Reading 146 5 Animating Images 149 Animation Techniques 150 Sprite Animation 150 ix Contents Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 C++ Classes for Sprite Animation 152 Sprite Class 152 SpriteAnimation Class 162 A Sample Animation Program 178 AnimationWindow Class 178 The ANIMATE Application 186 Building ANIMATE.EXE 187 Summary 188 Further Reading 188 6 Generating Sound 189 Sound under Windows 190 Programming for Sound 190 A Sample Program 197 Summary 201 Further Reading 201 Part II Sample Games 7 SPUZZLE—A Spelling Puzzle 205 Playing SPUZZLE 206 Starting SPUZZLE 207 Building a Puzzle 208 Keeping Score 209 Controlling Sound Output 209 Adding a New Word 210 Designing SPUZZLE 211 Window Hierarchy 212 Assigning the Responsibilities 213 Maintaining Information about the Puzzles 213 Implementing SPUZZLE 214 SpuzzleApp Class 214 PuzzleFrame Class 216 PuzzleWindow Class 232 LetterWindow Class 245 ToolWindow Class 252 StatusWindow Class 259 Data Structures for Puzzle Information 265 x ProgrammingWindowsGameswithBorlandC++ Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 High Scores Dialog Box 267 Resources for SPUZZLE 271 Help File 272 Other Files 273 Summary 273 8 3-D Graphics 275 Modeling 3-D Objects 276 3-D Cartesian Coordinates 276 Boundary Representation of 3-D Objects 277 Constructing Objects with Polygons 278 3-D Coordinate Transformations 280 Rotation 282 A Few More Vector Operations 283 Viewing a 3-D Scene 284 Transforming to View Coordinates 285 Perspective Projection 285 C++ Classes for 3-D Modeling 286 Defining the Primitive 3-D Classes 286 Defining the 3-D Scene 301 Loading a 3-D Scene from a File 311 Viewing a 3-D Scene 313 Summary 314 Further Reading 315 9 BLOCKADE—A Game of Modern Naval Simulation 317 Playing BLOCKADE 318 Overview of BLOCKADE 318 Starting BLOCKADE 319 Terminology of BLOCKADE 320 Components of the BLOCKADE Screen 321 Views in BLOCKADE 321 Controlling Simulation Speed 324 Launching Weapons 325 Designing BLOCKADE 325 Simulating the Scenario 326 Viewing the Scenario 326 Game Definition Files 327 Implementing BLOCKADE 327 [...]... Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 ProgrammingWindowsGameswithBorlandC++ xx Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 PART I Basics of Game ProgrammingwithBorlandC++ 1 D2 Prog Win GamesBorlandC++ 30292-6 MAL 3-24-93 Sample Part LP#1 2 D2 Prog Win GamesBorlandC++ 30292-6 MAL 3-24-93 Sample Part LP#1 Chapter Game Programming for Windows 1 Chapter... among strategy enthusiasts 10 TWO/NS6 Prog Win GamesBorlandC++ 30292-6 angela 4-1-93 CH 01 LP#5 Chapter Game Programming for Windows 1 Figure 1.4 Opening screen of SimCity for Windows Figure 1.5 View of Boston in SimCity for Windows 11 TWO/NS6 Prog Win GamesBorlandC++ 30292-6 angela 4-1-93 CH 01 LP#5 Programming Windows Games withBorlandC++ SimCity for Windows has good maplike views, but there are... Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 ProgrammingWindowsGameswithBorlandC++ xii Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 Contents Preface Computer games are by far the most popular type of software The market for game software is huge—practically anyone with a PC can use games If you are like me, you probably play your share of computer games and have... program games is to see working examples that illustrate how an imaginative idea can come alive in a computer game with graphics and sound ProgrammingWindowsGameswithBorlandC++ teaches intermediate to advanced level C++ programmers how to use object-oriented programming techniques to write computer gamesBorlandC++ offers exceptional support for Microsoft Windows programming, includes the ObjectWindows... including X Window System Programming; Object-Oriented Programming in C++; The Waite Group’s Microsoft C Bible, Second Edition; The Waite Group’s Turbo C++ Bible, Second Edition; and Microsoft C /C++ 7 Developer’s Guide xvi Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 Contents Introduction ProgrammingWindowsGameswithBorlandC++ is a book for intermediate-toadvanced C++ programmers that... How to Use This Book If you are a newcomer to BorlandC++ and Windows programming, you should first get up to speed by using other resources such as Borland s manuals or one of the many books on Windows programmingwith Borland C++ Once you are comfortable with Windows programming, you should browse through Chapters 1 through 3 to see how to use BorlandC++ and the OWL classes Chapter 1, in particular,... programming tools such as MAKE, TLINK, TLIB, and the Turbo Debugger The games presented in this book are meant to run under Microsoft Windows 3.1 because Windows offers a rich graphical user interface for the games and, more importantly, because there is a shortage of games that run under Windows xiii Two/NRS6 Prog Win GamesBorlandC++ 30292-6 angela 4-2-93 FM LP#6 ProgrammingWindowsGameswith Borland. .. GameswithBorlandC++ProgrammingWindowsGameswithBorlandC++ features the following: A quick overview of Windows programmingwith Borland C++ and ObjectWindows Library (OWL) C++ classes for image animation and sound generation Full source code for SPUZZLE, a spelling puzzle for young children Full source code for BLOCKADE, a game of strategy that simulates a naval blockade Disk with source and executable... backyard 7 TWO/NS6 Prog Win GamesBorlandC++ 30292-6 angela 4-1-93 CH 01 LP#5 ProgrammingWindowsGameswithBorlandC++ Common Themes in Computer Games All computer games have two common elements: graphics and sound Here is a quick look at some of the popular games from the real-time and strategy simulation categories I selected games from these two categories because simulation games have some of the... BLOCKADE ProgrammingWindowsGameswithBorlandC++ starts with an overview of Windows programmingwith Borland C++ and OWL followed by several chapters on graphics, image manipulation, and sound generation under Windows Then the book presents SPUZZLE—an educational spelling puzzle for young children This game teaches spelling through a simple jigsaw puzzle that has one or more letters associated with . Prog Win Games Borland C++ 30292-6 angela 4-2-93 FM LP#6 Programming Windows Games with Borland C++ ii Programming Windows Games with Borland C++ Two/NRS6 Prog Win Games Borland C++ 30292-6. shortage of games that run under Windows. xiv Programming Windows Games with Borland C++ Two/NRS6 Prog Win Games Borland C++ 30292-6 angela 4-2-93 FM LP#6 Programming Windows Games with Borland C++ features. Programming for Windows 18 Color 18 Multimedia Games for Windows 19 Summary 20 Further Reading 20 2 Windows Programming with Borland C++ 21 Microsoft Windows Programming with Borland C++ Classes