Build a 2D Platformer
Total Page:16
File Type:pdf, Size:1020Kb
March 30, 2014 [BUILD A 2D PLATFORMER - JAVA] inpu tparallaxscrollingsoundsenmiesobstac lesrgbjumpingrunningblocksvideogameav atarplatformsgameloopslick2Dmousesides crollingdoublejumpsinglescreenvectorjoys tickspritecollisiondetectionbackgroundfraBuild a 2D Platformer merategravityanimationprojectsinmovemeUsing Java ntpaddlescriptingroleplayi03/22/2014 ngobjectsmusic keyboardgameengineimagespaint.netrendnyguerrillagirl@brainycode.com eringgrapicspageflippingprototypenetworlafigueroa@brainycode.com kprogrammingmutltiplayeraudioshadowst ransparencyalphadonkeykonggamemaker mechanicsartificialintelligencepuzzlesgam eplayactionshumpresourcestileslevelscont rolscoreclockapispritesheetrasterraycastin gphysicslevelbuilderdatauihuddesigncode1 March 30, 2014 [BUILD A 2D PLATFORMER - JAVA] Note: This is a working/draft version Copyright © 2014 brainycode.com All rights reserved. Permission is not granted to copy and distribute an electronic version of this document. Please direct links to this website or request permission. Permission is NOT granted for commercial use. 2 March 30, 2014 [BUILD A 2D PLATFORMER - JAVA] Contents Chapter 1 – Getting Started/Introduction ...................................................................................................... 6 Purpose ...................................................................................................................................................... 6 What do I bring to this endeavor? ............................................................................................................. 7 What do you bring to this endeavor? ........................................................................................................ 7 Why build your own game engine? .......................................................................................................... 8 Does it make sense to develop games using Java? ................................................................................... 9 Best Practices - revisited ......................................................................................................................... 33 Quick History of 2D Games and Platformers ......................................................................................... 10 How can I play older games (no longer available for sale) or in the arcades? .................................... 24 Writing a Design Document ................................................................................................................... 31 Game Design Document Outline ........................................................................................................ 31 Using Best Practices ............................................................................................................................... 33 What is JUnit? ..................................................................................................................................... 33 What is Ant and Maven? ..................................................................................................................... 33 What’s the plan for learning how to use these tools? .......................................................................... 34 Game Engines ......................................................................................................................................... 34 The Plan .................................................................................................................................................. 34 Overview of the Plan .............................................................................................................................. 34 Exercises ................................................................................................................................................. 35 Chapter 2 – Graphics .................................................................................................................................. 37 Applications vs. Applets ......................................................................................................................... 37 Organizing the code ............................................................................................................................ 37 Lab 2-1: Creating a program that displays a window and runs as either an application or applet ...... 38 Drawing .................................................................................................................................................. 53 Color ................................................................................................................................................... 53 drawstring() ......................................................................................................................................... 54 Centering the Text ............................................................................................................................... 55 Lab 2-1: continued .............................................................................................................................. 56 Drawing Lines ..................................................................................................................................... 57 Fonts .................................................................................................................................................... 58 Lab 2-2: Drawing a Star Field ............................................................................................................. 59 Random Number Generation .............................................................................................................. 61 3 March 30, 2014 [BUILD A 2D PLATFORMER - JAVA] Drawing Ellipses and Circles .............................................................................................................. 62 Drawing Rectangles ............................................................................................................................ 62 Additional draw methods ........................................................................................................................ 63 drawArc............................................................................................................................................... 63 Lab 2-3: Draw a Happy Face .............................................................................................................. 65 Drawing Polygons ............................................................................................................................... 66 Drawing Images .................................................................................................................................. 68 Lab 2-4: Drawing an Image ................................................................................................................ 69 Clipping............................................................................................................................................... 71 Graphics2D ......................................................................................................................................... 72 Making changes to the objects we draw ................................................................................................. 72 Alpha ................................................................................................................................................... 72 Anti-aliasing ........................................................................................................................................ 72 Scaling Images .................................................................................................................................... 72 Chapter 3 - Introducing the Game Loop ..................................................................................................... 73 Process Input ....................................................................................................................................... 73 Simulate Game World ......................................................................................................................... 74 Render ................................................................................................................................................. 74 What are Threads? .................................................................................................................................. 74 Why do we need Threads in our game program? ............................................................................... 75 Creating a Thread ................................................................................................................................ 77 Lab 3-1: A Quick Introduction to Using Ant ...................................................................................... 79 Lab 3-2: Bouncing Ball ....................................................................................................................... 84 Lab 3-3: Displaying an animated GIF ............................................................................................... 102 Keyboard Processing ............................................................................................................................ 122 Creating Pong.......................................................................................................................................