1. Trang chủ
  2. » Công Nghệ Thông Tin

Wordware java 1 4 game programming feb 2003 ISBN 1556229631

1.2K 110 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Table of Contents

  • BackCover

  • Java 1.4 Game Programming

  • Chapter 1: Introduction to Java 1.4

    • Introduction to the Java Platform

    • Introduction to Java 2 Standard Edition 1.4

    • What the Future Holds

    • What This Book Covers

    • Who Is This Book For?

    • Installing the J2SE 1.4 SDK

    • A Word on Integrated Development Environments (IDEs)

    • Useful Web Sites

    • Summary

  • Chapter 2: Basics of Java Programming

    • Introduction to Object-Oriented Programming (OOP)

    • HelloJavaWorld--A Simple Console Program

    • Primitive Data Types

    • Simple Arithmetic Operators

    • Operator Precedence

    • Unary, Binary, and Ternary Operators

    • Oh No, More Operators!

    • Arithmetic Assignment Operators

    • The boolean Data Type

    • Bitwise Operators

    • Bit Manipulation

    • Bit Shifting

    • Bit Flags

    • The char Data Type

    • Character Escape Sequences

    • Defining Unicode Characters

    • Constants

    • Conditional Statements and Loops

    • Methods

    • Variable Scope

    • Summary

  • Chapter 3: Arrays and Strings

    • Arrays

    • Strings

    • A Tour of the String Class

    • A Word on Regular Expressions

    • Invocation Chaining

    • A Tour of the StringBuffer Class

    • A Tour of the StringTokenizer Class

    • Summary

  • Chapter 4: Multiple Classes

    • Creating Main Class Objects

    • The Keyword this

    • Using Multiple Classes

    • Inheritance

    • The Keyword super

    • The Keyword final with Classes and Methods

    • Polymorphism

    • Interfaces

    • Defining on the Fly

    • Summary

  • Chapter 5: Packages, Utilities, and Error Handling

    • What is a Package?

    • Importing Packages

    • Creating Your Own Packages

    • Using JARs

    • Exploring Useful Classes

    • Error Handling

    • Summary

  • Chapter 6: Stream I/O

    • Introduction to Streams

    • Console Input

    • Writing Data to a File

    • Reading Data from a File

    • Object Serialization

    • Summary

  • Chapter 7: Threads

    • What Is a Thread?

    • Creating a Thread

    • Extending a Thread

    • Using the Runnable Interface

    • Stopping a Thread

    • Synchronization

    • Wait and Notify

    • Sleeping Threads

    • Interrupting a Thread

    • Daemon Threads

    • Thread Priorities

    • A Final Word on Deadlock

    • Summary

  • Chapter 8: Applications and Applets

    • A Brief Note on Components and Containers

    • Heavyweight and Lightweight Components

    • Introduction to AWT and Swing

    • What Is an Application?

    • What Is an Applet?

    • Look and Feel

    • Summary

  • Chapter 9: Graphics

    • Template Graphics Windowed Application

    • Introducing the Event Dispatch Thread

    • Creation and Initialization

    • Disabling the Layout Manager

    • Pixel Coordinates

    • Sizing with the Window Border

    • Let's See That in an Applet

    • AWT Notice 1

    • Closing a Window

    • Adding Components

    • AWT Notice 2

    • Graphics and Graphics2D Overview

    • Graphics Class Basics

    • Drawing Shapes

    • Affined Transformations

    • Fonts

    • Off-Screen Images

    • Rendering

    • Summary

  • Chapter 10: Using the Mouse and Keyboard

    • Using Listeners

    • Reading Keyboard Input

    • Adapter Classes

    • Reading Mouse Input

    • Integrating Mouse Events with the Main Loop

    • Creating the MouseProcessor

    • Handling Repetitive Key Input

    • An All-Purpose Event Queue

    • Losing Focus

    • Changes for an Application

    • Where's My Tab Key?

    • Summary

  • Chapter 11: Using Sound and Music

    • Supported Sound Formats

    • Applet Simple Sound Example

    • Application Simple Sound Example

    • Using the Java Sound API

    • Creating a Sound Manager

    • Using the Sound Manager

    • Summary

  • Chapter 12: Game Programming Techniques

    • Animation

    • Timing in Java

    • Garbage Collection and Creating Objects

    • Collision Detection

    • Creating a Game Framework

    • Tile Scroller Example

    • Tile Walker Example

    • Summary

  • Chapter 13: Introduction to GUI

    • Using Buttons

    • Using Text Fields

    • GUI Extra Section

    • Setting Images for Buttons

    • Extending the GUI

    • A Recap on the Event Dispatch Thread

    • Creating Your Own GUI System

    • Using Our New GUI System

    • Summary

  • Chapter 14: Introduction to Databases

    • What Is a Database?

    • Why Do I Need To Know about Databases?

    • Database Packages

    • Introduction to SQL

    • Summary

  • Chapter 15: Using SQL with MySQL

    • What Is MySQL?

    • Installing MySQL

    • Starting the MySQL Server Automatically

    • SQL Statements

    • Data Definition Language

    • Data Manipulation Language (DML)

    • Relational Databases

    • Joining Tables

    • Data Import Methods

    • Backing Up and Restoring Data

    • Summary

  • Chapter 16: Using the JDBC

    • What Is the JDBC?

    • Getting the MySQL Driver for the JDBC

    • Creating a Connection to a Database

    • Inserting Data into a Table

    • Retrieving Data from a Table

    • A Sample Windowed Database Application

    • Accessing Database Metadata from a ResultSet

    • Prepared Statements

    • Summary

  • Chapter 17: Introduction to Networking

    • Fundamentals of Networking

    • Networking Applets

    • Example: TCP Echo Server

    • Example: TCP Echo Client

    • Example: UDP Echo Server/Client

    • Creating a Network Framework

    • Multiplayer " I'm a circle! " --A Sample Network Game

    • Summary

  • Chapter 18: Introduction to NIO Networking

    • Why Use NIO?

    • Channels

    • The ByteBuffer Class

    • Creating a Blocking Server

    • Creating a Non-Blocking Server

    • Summary

  • Bonus Chapter: A Tour of the Swing GUI

    • The JButton

    • The JTextField

    • The JPasswordField

    • The JTextArea

    • The JComboBox

    • The JCheckBox

    • The JRadioButton

    • The JProgressBar

    • The JList

    • The JTable

    • The JTree

    • The JEditorPane

    • The JOptionPane

    • The JMenu

    • Using Tool Tips

  • Index

    • Index_B

    • Index_C

    • Index_D

    • Index_E

    • Index_F

    • Index_G

    • Index_H

    • Index_I

    • Index_J

    • Index_K

    • Index_L

    • Index_M

    • Index_N

    • Index_O

    • Index_P

    • Index_R

    • Index_S

    • Index_T

    • Index_U

    • Index_V

    • Index_W

  • List of Figures

  • List of Listings

Nội dung

Java 1.4 Game Programming ISBN:1556229631 by Andrew Mulholland and Glen Murphy Wordware Publishing © 2003 (647 pages) This text covers all of the key elements in Java which are required for creating games, as well as significant new features which have become available with the release of the latest version 1.4 from Sun Table of Contents Java 1.4 Game Programming Introduction to Java Chapter 1 1.4 Basics of Java Chapter 2 Programming Chapter 3 - Arrays and Strings Chapter 4 - Multiple Classes Packages, Utilities, Chapter 5 and Error Handling Chapter 6 - Stream I/O Chapter 7 - Threads Applications and Chapter 8 Applets Chapter 9 - Graphics Using the Mouse and Chapter 10 Keyboard Using Sound and Chapter 11 Music Game Programming Techniques Chapter 13 - Introduction to GUI Introduction to Chapter 14 Databases Using SQL with Chapter 15 MySQL Chapter 16 - Using the JDBC Introduction to Chapter 17 Networking Introduction to NIO Chapter 18 Networking A Tour of the Swing Bonus Chapter GUI Index List of Figures List of Listings Chapter 12 - Back Cover With the release of Java 1.4, it is now possible to develop more advanced computer games using the Java language than ever before Java 1.4 Game Programming focuses on the technical aspects of game programming using the latest release of Java, beginning with an introduction to the Java programming language and building upon that knowledge by exploring the key elements required to develop games, such as graphics, input, sound, and networking Features new in Java 1.4, including fullscreen exclusive mode, new graphics features, and NIO networking, are also covered Gain a solid foundation in the Java 1.4 language Learn key issues associated with graphics programming in Java Understand the importance of threads throughout all related topics Find out how to handle mouse and keyboard input correctly in a game environment Develop a reusable sound manager for your games Learn about animation, collision detection, and high-resolution timing See how to create your own in-game GUI system Create a solid game framework for use in your own game projects Learn how to develop multiplayer games in Java About the Authors Andrew Mullholland and Glenn Murphy have each been programming games for more than six years and have several years of experience with Java They are both in the final year of the Computer Games Technology program at the University of Abertay in Dundee, Scotland Andrew is also a co-author of Developer’s Guide to Multiplayer Games from Wordware Publishing Java 1.4 Game Programming Andrew Mulholland and Glenn Murphy Library of Congress Cataloging-in-Publication Data Mulholland, Andrew Java 1.4 game programming / by Andrew Mulholland and Glenn Murphy p cm ISBN 1-55622-963-1 Java (Computer program language) 2 Computer games— Programming I Murphy, Glenn, 1908- II Title QA76.73.J38 M849 2003 794.8'152762—dc21 2002155485 CIP © 2003, Wordware Publishing, Inc All Rights Reserved 2320 Los Rios Boulevard Plano, Texas 75074 No part of this book may be reproduced in any form or by any means without permission in writing from Wordware Publishing, Inc ISBN 1-55622-963-1 10 0301 Java is a trademark of Sun Microsystems, Inc All brand names and product names mentioned in this book are trademarks or service marks of their respective companies Any omission or misuse (of any kind) of service marks or trademarks should not be regarded as intent to infringe on the property of others The publisher recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish their products All inquiries for volume purchases of this book should be addressed to Wordware Publishing, Inc., at the above address Telephone inquiries may be made by calling: (972) 423-0090 About the Authors This for me is probably the easiest part of the book to write I really have a liking for writing about myself as I always feel it will sound boastful and conceited, which I am Well, I started life as a baby and I'm afraid that's where it all began I started programming at around 16 years of age while attending college in my hometown of Manchester, England I use the term "attended" loosely, however, because as soon as the programming began, I was hooked, and ducked out of many a lecture to create a variety of games, albeit on an 80x25 ASCII character resolution and a useful gotoxy(x, y) method In the second year of college, a friend and programming buddy, Nick Kitson, and I co-wrote a 16,000-line soccer management game in Pascal called ESM European Soccer Manager, where you could actually watch the matches in an overhead view Working on this taught me more than anything about programming My advice—pick a goal and go for it After college, I made it into the Computer Games Technology program at the University of Abertay Dundee and am now midway through the (honours) 4th year While "attending" university I have furthered my knowledge from Pascal to C/C++ and then on to Java The ability to make web games playable in a browser (applets) was what originally made Java so appealing to me, and had been a mystery to me for long enough There began my introduction to Java Before Java, I was mainly a procedural programmer, and not that well tuned to object-oriented programming (OOP) The good thing about Java, in this sense, is that it is completely OOP, so there was no choice but to program in this style For this I think learning Java is the best guide to OOP you can get And then came the book After working on a Java game over the summer of 2000, I teamed up with my now co-author Andrew, who has been my flatmate and friend since the first year of university The university's random accommodation allocation for freshers can take the credit for us meeting in the student halls We began work on the book in late 2001, while both juggling our honours degree courses at the same time Besides losing my virginity and trying to complete Jet Set Willy, this book has been the most grueling experience of my life, but it was all worth it in the end (I hope this last sentence makes it to publication.) My primary hope for this book is that it makes me as much money as possible My secondary hope, besides programming games in Java, is that the book indicates the difficulties that we came across when researching Java for games programming in a clear manner, especially those surrounding threads, input, and graphics that we put a lot of work into I think to become a good programmer you have to enjoy it; otherwise it's little use Most of the enjoyment I find is in showing off what I have done, which there is no harm in now and again (and again and again J) One thing I am aware of is that in actually challenging yourself to do something, and believing that you can do it, there seems to be a fear factor where you often do not even attempt to code something, because you have never done it before In buying this book, you have made a solid move in conquering this fear My interests mostly revolve around playing pool, watching films, and occasionally programming the night away, and there is still no better feeling than "7-balling" someone in a crowded club I also collect Star Wars costumes and wear them out clubbing regularly As a final word, I hope this book is as useful to you as it was for me in writing it, and wish you luck in your quest of knowledge Glenn Murphy glenn@chopsewage.com This for me is probably one of the hardest parts of the book to write I really have a dislike for writing about myself as I always feel it will sound boastful or conceited Nevertheless, here goes… Well, I am currently 21 years old and halfway through my 4th (honours) year of university studying BSc (Hons) Computer Games Technology at the University of Abertay in Dundee, Scotland I would say I have been coding for around six years now and have obtained quite a broad range of skills within this time My first real stab at game programming was about a year and a half before I left home to go to university when I downloaded the DJGPP DOS compiler (http://www.delorie.com/djgpp) and the Allegro game library (http://www.talula.demon.co.uk/allegro) originally started by Shawn Hargreaves After starting and never finishing a few projects, the next logical step was to move onto looking at OpenGL and DirectX As well as looking at the 3D side of games programming however, I also invested time in learning Perl and MySQL, although I have recently switched to using PHP4 as it is sooo much nicer than Perl ;) From there, I then progressed onto Java and to be honest it is probably the best thing I have ever done Java really is such a great language Don't get me wrong—it does have some issues, but the structure of the language and also the documentation is really excellent (ever tried using MSDN? Urgh.) One thing that deceived me, however, when I started to use Java was the simplicity When you start looking into Java properly, you think—ah great, all the libraries have been written for me However, as you will see as you progress through the book, these libraries are excellent for business application development, but there are some pitfalls and serious issues to consider when looking at the language and libraries (packages) from a game development point of view Probably now is a good time for a plug Previously to this book, I coauthored Developer's Guide to Multiplayer Games, which focuses in detail on using sockets in C/C++ to create client-server games That book has a large tutorial section that takes you through the process of writing a reusable network library and a multiplayer game, which also includes a signup/login and lobby system What the book does not cover, however, is DirectPlay as we remain platform independent throughout the book, so your game server will compile as easily on the Linux platform as it will on the Windows platform If you are interested, you can find out more information (and buy it J) at the following Amazon.com link: http://www.amazon.com/exec/obidos/tg/detail/-/1556228686 On a final note, I hope you enjoy reading this book and find the information within it useful If you have any questions or problems with anything in the book, do not hesitate to e-mail either myself or Glenn and we will try to help you as best we can! Andrew Mulholland andrew@hfplimited.com Chapter 1: Introduction to Java 1.4 "Everywhere is walking distance if you have the time." —Steven Wright Chapter 4: Multiple Classes Code Listing 4-1: Alien.java Code Listing 4-2: Universe.java Code Listing 4-3: MainApp.java Code Listing 4-4: Creatures.java Code Listing 4-5: Alien.java Code Listing 4-6: Human.java Code Listing 4-7: Beings.java Chapter 5: Packages, Utilities, and Error Handling Code Listing 5-1: Addition.java Code Listing 5-2: Subtraction.java Code Listing 5-3: compile.bat Code Listing 5-4: The test application (TestApp.java) Code Listing 5-5: MyApp.java Code Listing 5-6: MyApplet.java Code Listing 5-7: view.html Code Listing 5-8: ArrayListExample.java Code Listing 5-9: ArrayListSearchRemove.java Code Listing 5-10: LinkedListExample.java Code Listing 5-11: StackExample.java Code Listing 5-12: BrokenArray.java Code Listing 5-13: BrokenArrayHandled.java Code Listing 5-14: BrokenArrayThrow.java Code Listing 5-15: MyException.java Code Listing 5-16: TestApp.java Code Listing 5-17: TestApp.java Chapter 6: Stream I/O Code Listing 6-1: Console input Code Listing 6-2: Tic-tac-toe example Code Listing 6-3: Writing data to a file Code Listing 6-4: Reading data from a file Code Listing 6-5: The PlayerData class Code Listing 6-6: Object serialization Chapter 7: Threads Code Listing 7-1: SimpleThread1.java Code Listing 7-2: SimpleThread2.java Code Listing 7-3: StoppingThread.java Code Listing 7-4: Countdown.java Code Listing 7-5: DaemonThread.java Chapter 8: Applications and Applets Code Listing 8-1: Simple application (extending a JFrame) Code Listing 8-2: Simple application (JFrame as a member) Code Listing 8-3: Simple applet Code Listing 8-4: view.html (used to view the applet) Code Listing 8-5: view.html Code Listing 8-6: AppletParam.java Code Listing 8-7: Look and feel example Chapter 9: Graphics Code Listing 9-1: TemplateGraphicsApplication.java Code Listing 9-2: TemplateGraphicsApplet.java Code Listing 9-3: DrawingShapes.java Code Listing 9-4: AffinedTransformer.java Code Listing 9-5: UsingFonts.java Code Listing 9-6: OffScreenSprite.java Code Listing 9-7: TransparentSprite.java Code Listing 9-8: BlendingTest.java Code Listing 9-9: RandomImage.java Code Listing 9-10: TrackerImageLoadingApplication.java Code Listing 9-11: TrackerImageLoadingApplet.java Code Listing 9-12: ImageIOLoadingApplication.java Code Listing 9-13: PassiveRendering.java Code Listing 9-14: ActiveRendering.java Code Listing 9-15: ActiveRenderingApplet.java Code Listing 9-16: ActivelyPassiveRenderingRepaints.java Code Listing 9-17: VolatileImageRendering.java Code Listing 9-18: FullScreenDemo.java Chapter 10: Using the Mouse and Keyboard Code Listing 10-1: SimpleMouse.java Code Listing 10-2: MouseProcessable Code Listing 10-3: MouseProcessor Code Listing 10-4: AdvancedMouse.java Code Listing 10-5: KeyProcessable Code Listing 10-6: KeyProcessor Code Listing 10-7: Animator Code Listing 10-8: AdvancedKeyboard.java Code Listing 10-9: EventProcessable Code Listing 10-10: EventProcessor Code Listing 10-11: Animator.java Code Listing 10-12: EventAndFocusHandling.java Chapter 11: Using Sound and Music Code Listing 11-1: Loading and playing a sound in an applet Code Listing 11-2: HTML for viewing the applet Code Listing 11-3: Loading and playing a sound in an application Code Listing 11-4: Playing samples in the Java Sound API Code Listing 11-5: Streaming audio Code Listing 11-6: Playing MIDI music with the Java Sound API Code Listing 11-7: The sound manager Code Listing 11-8: Sound manager example application Chapter 12: Game Programming Techniques Code Listing 12-1: AnimatedNumbers.java Code Listing 12-2: StickWalker.java Code Listing 12-3: HiresTimeExample Listing 12-4: Bounding circle example Listing 12-5: Bounding box example Code Listing 12-6: TemplateScreen.java Code Listing 12-7: Globals.java Code Listing 12-8: SampleScreen.java Code Listing 12-9: Keyboard.java Code Listing 12-10: Mouse.java Code Listing 12-11: GameFramework.java Code Listing 12-12: DemoScreen1.java Code Listing 12-13: DemoScreen2.java Code Listing 12-14: DemoScreen3.java Code Listing 12-15: PauseScreen.java Listing 12-16: Tile Scroller example (works with the framework) Code Listing 12-17: Tile Walker example (works with the framework) Chapter 13: Introduction to GUI Code Listing 13-1: Using the JButton object Code Listing 13-2: Using the JTextField Code Listing 13-3: Using the JButton object Code Listing 13-4: The GUIComponent class Code Listing 13-5: The GUIContainer class Code Listing 13-6: The GUISystem class Code Listing 13-7: The GUIButton class Code Listing 13-8: Using the custom GUI system Chapter 16: Using the JDBC Code Listing 16-1: Connecting to a database Code Listing 16-2: Inserting data into a table from Java Code Listing 16-3: Retrieving data from a table into Java Code Listing 16-4: The skeleton application frame Code Listing 16-5: The skeleton application frame with GUI objects Code Listing 16-6: The TableHandler class Code Listing 16-7: The final Highscore class Code Listing 16-8: Accessing database metadata Code Listing 16-9: Using prepared statements Chapter 17: Introduction to Networking Code Listing 17-1: TCP echo server Code Listing 17-2: TCP echo client Code Listing 17-3: UDP echo server Code Listing 17-4: UDP echo client Code Listing 17-5: SampleServer.java Code Listing 17-6: ClientHandler.java Code Listing 17-7: Player.java Code Listing 17-8: Protocol.java Code Listing 17-9: NetworkEvent.java Code Listing 17-10: NetworkListener.java Code Listing 17-11: NetworkHandler.java Code Listing 17-12: SampleClient.java Chapter 18: Introduction to NIO Networking Code Listing 18-1: ByteBufferExample.java Code Listing 18-2: BlockingServer.java Code Listing 18-3: BlockingClient.java Code Listing 18-4: NonBlockingServer.java Code Listing 18-5: NonBlockingClient.java Bonus Chapter: A Tour of the Swing GUI Code Listing 1: Using the JLabel Code Listing 2: Using the JButton object Code Listing 3: Using the JButton object Code Listing 4: Using the JTextField Code Listing 5: Using the JPasswordField Code Listing 6: Using the JTextArea Code Listing 7: Adding in a JTextArea to a JScrollPane Code Listing 8: Using the JComboBox Code Listing 9: Using the JCheckBox Code Listing 10: Creating image check boxes Code Listing 11: Using the JRadioButton Code Listing 12: Image radio buttons Code Listing 13: Using the JProgressBar Code Listing 14: Using the JList Code Listing 15: Implementing a scrollable JList Code Listing 16: Using the JTable Code Listing 17: Using the JTree Code Listing 18: Using the JEditorPane to load HTML Code Listing 19: Using the JOptionPane Code Listing 20: Using the JMenu Code Listing 21: Using tool tips ... p cm ISBN 1- 55622-963 -1 Java (Computer program language) 2 Computer games— Programming I Murphy, Glenn, 19 08- II Title QA76.73.J38 M 849 2003 7 94. 8 '15 2762—dc 21 200 215 548 5 ... Guide to Multiplayer Games from Wordware Publishing Java 1. 4 Game Programming Andrew Mulholland and Glenn Murphy Library of Congress Cataloging-in-Publication Data Mulholland, Andrew Java 1. 4 game programming / by Andrew Mulholland and Glenn... develop more advanced computer games using the Java language than ever before Java 1. 4 Game Programming focuses on the technical aspects of game programming using the latest release of Java, beginning with an introduction to the Java

Ngày đăng: 26/03/2019, 16:30