ebook img

Swift Game Programming for Absolute Beginners PDF

353 Pages·2015·5.42 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Swift Game Programming for Absolute Beginners

Books for professionals By professionals® Design and code fun games for iOS s S e l tit Swift Game Programming for Absolute Beginners teaches Apple’s w d e Swift language in the context of four, fun and colorful games. at i el Learn the Swift 2.0 language, and learn to create game apps for f R t iOS at the same time – a double win! G The four games you’ll develop while reading this book are a mobile games representing the aim-and-shoot, casual, puzzle, m and platform styles of game play. Professionally developed game assets form part of the book download. You’ll get profession- e ally drawn sprites and imagery that’ll have you proud to show P your learning to friends and family. r o The approach in Swift Game Programming for Absolute Beginners g follows the structure of a game rather than the syntax of a language. You’ll learn to create game worlds, manage game r a objects and game states, define levels for players to pass through, m implement animations based upon realistic physics, and much more. Along the way you’ll learn the language, but always in the m context of fun and games. i Swift is Apple’s new programming language introduced in 2014 n to replace Objective-C as the main programming language for g iOS devices and Mac OS X. Swift is a must learn language for f anyone targeting Apple devices, and Swift Game Programming o Swift Game r for Absolute Beginners provides the most fun you’ll ever have A in stepping over the threshold toward eventual mastery of the b language. s o l u t e Programming B e g i n n e r s for Absolute Beginners E g g e s Arjan Egges ISBN 978-1-4842-0651-5 US $44.99 54499 Shelve in: Macintosh/Programming SOURCE CODE ONLINE User level: www.apress.com Beginning 9781484206515 www.it-ebooks.info For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. www.it-ebooks.info Swift Game Programming for Absolute Beginners Arjan Egges www.it-ebooks.info Swift Game Programming for Absolute Beginners Copyright © 2015 by Arjan Egges Portions of the text are from Learning C# by Programming Games, Egges, Arjan, Fokker, Jeroen D., Overmars, Mark H., © Springer-Verlag Berlin Heidelberg 2013, and are used by permission. This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. ISBN-13 (pbk): 978-1-4842-0651-5 ISBN-13 (electronic): 978-1-4842-0650-8 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director: Welmoed Spahr Lead Editor: Jonathan Gennick Development Editor: Douglas Pundick Technical Reviewer: Stefan Kaczmarek Editorial Board: Steve Anglin, Mark Beckner, Gary Cornell, Louise Corrigan, Jim DeWolf, Jonathan Gennick, Robert Hutchinson, Michelle Lowman, James Markham, Susan McDermott, Matthew Moodie, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing, Matt Wade, Steve Weiss Coordinating Editor: Jill Balzano Copy Editor: Mary Behr Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this text is available to readers at www.apress.com. For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/. www.it-ebooks.info To Yfa www.it-ebooks.info Contents at a Glance About the Author ���������������������������������������������������������������������������������������������������xvii About the Technical Reviewer ��������������������������������������������������������������������������������xix Acknowledgments ��������������������������������������������������������������������������������������������������xxi Introduction ����������������������������������������������������������������������������������������������������������xxiii ■ Part I: Getting Started �������������������������������������������������������������������������1 ■ Chapter 1: The Swift Language ������������������������������������������������������������������������������3 ■ Chapter 2: Game Programming Basics ����������������������������������������������������������������17 ■ Chapter 3: Creating a Game World ����������������������������������������������������������������������29 ■ Chapter 4: Game Assets ��������������������������������������������������������������������������������������41 ■ Part II: Painter ����������������������������������������������������������������������������������55 ■ Chapter 5: Reacting to Player Input ��������������������������������������������������������������������57 ■ Chapter 6: A Flying Ball ���������������������������������������������������������������������������������������73 ■ Chapter 7: Game Object Types �����������������������������������������������������������������������������93 ■ Chapter 8: Colors and Collisions �����������������������������������������������������������������������111 ■ Chapter 9: Limited Lives ������������������������������������������������������������������������������������123 ■ Chapter 10: Organizing Game Objects ���������������������������������������������������������������139 ■ Chapter 11: Finishing the Painter Game ������������������������������������������������������������155 v www.it-ebooks.info vi Contents at a Glance ■ Part III: Tut’s Tomb ��������������������������������������������������������������������������165 ■ Chapter 12: Advanced Input Handling ���������������������������������������������������������������167 ■ Chapter 13: Game Physics ���������������������������������������������������������������������������������183 ■ Chapter 14: Gameplay Programming ����������������������������������������������������������������191 ■ Chapter 15: Game States �����������������������������������������������������������������������������������203 ■ Chapter 16: Finishing the Tut’s Tomb Game ������������������������������������������������������213 ■ Part IV: Penguin Pairs ���������������������������������������������������������������������223 ■ Chapter 17: Menus and Grids ����������������������������������������������������������������������������225 ■ Chapter 18: Game State Management ���������������������������������������������������������������239 ■ Chapter 19: Storing and Recalling Game Data ��������������������������������������������������247 ■ Chapter 20: Interaction Between Game Objects ������������������������������������������������263 ■ Chapter 21: Finishing the Penguin Pairs Game �������������������������������������������������275 ■ Part V: Tick Tick ������������������������������������������������������������������������������283 ■ Chapter 22: The Main Game Structure ��������������������������������������������������������������285 ■ Chapter 23: Animation ���������������������������������������������������������������������������������������293 ■ Chapter 24: Platform Game Physics ������������������������������������������������������������������303 ■ Chapter 25: Intelligent Enemies ������������������������������������������������������������������������313 ■ Chapter 26: Adding Player Interaction ��������������������������������������������������������������323 ■ Chapter 27: Finishing the Tick Tick Game ���������������������������������������������������������333 Index ���������������������������������������������������������������������������������������������������������������������345 www.it-ebooks.info Contents About the Author ���������������������������������������������������������������������������������������������������xvii About the Technical Reviewer ��������������������������������������������������������������������������������xix Acknowledgments ��������������������������������������������������������������������������������������������������xxi Introduction ����������������������������������������������������������������������������������������������������������xxiii ■ Part I: Getting Started �������������������������������������������������������������������������1 ■ Chapter 1: The Swift Language ������������������������������������������������������������������������������3 Computers and Programs3 Processors and Memory 3 Programs 4 Programming Languages 4 Programming Games 5 Developing Games 6 Small Scale: Edit-Compile-Run 7 Large Scale: Design-Specify-Implement 7 Building Your First Swift Program 8 Building Your First Swift Game 11 A Few Observations14 What You Have Learned 15 vii www.it-ebooks.info viii Contents ■ Chapter 2: Game Programming Basics ����������������������������������������������������������������17 Building Blocks of a Game 17 The Game World 17 The Game Loop 18 The Game Loop in Swift 19 The Structure of a Program 21 Types of Applications 21 Functions 22 Syntax Diagrams 23 Calling a Function 24 Program Layout 25 Comments 25 Instructions vs Lines 25 Whitespace and Indentation 26 What You Have Learned 27 ■ Chapter 3: Creating a Game World ����������������������������������������������������������������������29 Basic Types and Variables 29 Types 29 Declaration and Assignment of Variables 30 Instructions and Expressions 33 Operators and More Complex Expressions34 Arithmetic Operators 34 Priority of Operators 34 Other Numeric Types 35 The DiscoWorld Game 37 Scope of Variables 39 What You Have Learned 40 www.it-ebooks.info Contents ix ■ Chapter 4: Game Assets ��������������������������������������������������������������������������������������41 Locating Sprites 42 Loading and Drawing Sprites 42 Resolutions and Aspect Ratios 43 Moving Sprites 47 Loading and Drawing Multiple Sprites 48 Configuring the Device Orientation 50 Music and Sounds 51 What You Have Learned 53 ■ Part II: Painter ����������������������������������������������������������������������������������55 ■ Chapter 5: Reacting to Player Input ��������������������������������������������������������������������57 Dealing With Touch Input 57 Using the Touch Location to Change the Game World 60 Conditional Execution Based on Touch 62 Testing for Alternatives 63 Comparison Operators 65 Logic Operators 66 The Boolean Type 66 Changing the Color of the Cannon 68 A Few Final Remarks 71 What You Have Learned 72 ■ Chapter 6: A Flying Ball ���������������������������������������������������������������������������������������73 Methods 73 Parameter Names and Labels 76 Default Parameter Values 79 Reorganizing Instructions into Methods 80 Moving Between Local and World Coordinates 82 www.it-ebooks.info

Description:
Swift Game Programming for Absolute Beginners teaches Apple's Swift language in the context of four, fun and colorful games. Learn the Swift 2.0 language, and learn to create game apps for iOS at the same time – a double win! These four games are casual, arcade-style games representing the aim-and
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.