You are previewing Coding4Fun.
O'Reilly logo
Coding4Fun

Book Description

How would you like to build an Xbox game, use your Nintendo Wiimote to create an electronic whiteboard, or build your own peer-to-peer application? Coding4Fun helps you tackle some cool software and hardware projects using a range of languages and free Microsoft software. Now you can code for fun with C#, VB, ASP.NET, WPF, XNA Game Studio, Popfly, as well as the Lua programming language. If you love to tinker, but don't have time to figure it all out, this book gives you clear, step-by-step instructions for building ten creative projects, including:

  • Alien Attack: Create a 2D clone of Space Invaders with XNA for the PC, Xbox 360, and Zune

  • LEGO Soldier: Create an action game using Popfly with a custom-built virtual LEGO character

  • World of Warcraft RSS Feed Reader: Use WoW's customizable interface to have feeds pop up while you're gaming

  • InnerTube: Download YouTube videos automatically and convert them to a file format for off-line viewing

  • PeerCast: Stream video files from any PC

  • TwitterVote: Create custom online polls on Twitter

  • WHSMail: Build a website with ASP.NET for Windows Home Server that lets you view the messages stored on a computer with Outlook

  • "Wiimote" Controlled Car: Steer your remote-controlled car by tilting the Wii Remote controller left and right

  • Wiimote Whiteboard: Create an interactive whiteboard using a Wii Remote

  • Holiday Lights: Synchronize your holiday light display with music to create your own light show

The perfect gift for any developer, Coding4Fun shows you how to use your programming skills in new and fun ways.

"This book is amazing! The scope is so wonderfully broad that anyone who has an interest in designing games at any level should read this book."

-- Alex Albrecht, Creator of Diggnation / Totally Rad Show / Project Lore

Table of Contents

  1. Dedications
  2. Special Upgrade Offer
  3. A Note Regarding Supplemental Files
  4. Preface
    1. Who This Book Is For
    2. What You Need to Use This Book
    3. How This Book Is Organized
    4. Conventions Used in This Book
    5. About the Code
    6. Using Code Examples
    7. Comments and Questions
    8. Safari® Books Online
    9. Acknowledgments
      1. From Dan Fernandez
      2. From Brian Peek
  5. I. Gaming
    1. 1. Alien Attack
      1. Overview
      2. Setup
      3. Windows Version
        1. Screens
          1. Title screen
          2. InputManager
        2. Back to the Game
        3. Seeing the Title Screen
        4. Game Screen
          1. Adding GameScreen to the main game
          2. Sound engine
          3. Player ship and sprites
          4. Player shots
          5. Scoring and lives remaining
          6. Enemies
          7. EnemyGroup
          8. Collision detection and explosions
        5. Running the Application
      4. Xbox 360 and Zune Support
        1. Xbox 360
        2. Zune
      5. Final Thoughts
    2. 2. LEGO Soldier: A 2-D LEGO Side-Scroller Popfly Game
      1. Overview
      2. Popfly Game Creator Terms
      3. Building LEGO Soldier Step-by-Step
      4. Building the Popfly Game
      5. Designing Custom Actors
        1. Designing a LEGO Model Using LEGO Digital Designer
        2. Exporting a LEGO Model
        3. Cropping out Empty Space
        4. Upload Images to Popfly
        5. Building an Actor in the Actor Designer
        6. Adding a Health Bar and a Scoreboard
      6. Importing Actors
      7. Designing the Main Scene
        1. Designing the Main Scene
        2. Adding the Two Cave Background Actor Files
        3. Tiling the Background
        4. Tiling the Ground Floor
        5. Designing the First Half of the Scene
        6. Designing the Second Half of Our Scene
      8. Building Game Properties
      9. Building Behaviors
        1. Renaming Behaviors
      10. Building the Main Scene Behaviors
        1. Using Shortcuts to Build the Main Scene Behaviors
        2. Building a Property Change Behavior to Reset the Health Property
        3. Creating a Custom Code Behavior
        4. Adding Main Actor Behaviors Using Shortcuts
        5. Building the Catapult Behavior
      11. Building the LEGO Security Actor Behaviors
        1. Adding Gravity and Jump Behaviors Using Shortcuts
        2. Setting a Random Jump Behavior
        3. Adding a Random Motion Behavior
        4. Adding a Shooting Behavior
        5. Adding a Disappear Behavior
      12. Building the Fire Bullet Projectile Behaviors
        1. Updating the DisappearOnCollision Behavior
        2. Creating a Custom Code Behavior to Lower the Health Property
      13. Building the LEGO Skeleton Behavior
        1. Adding Gravity and Jump Behaviors Using Shortcuts
        2. Updating the Jump Behavior
        3. Creating a Behavior to Follow the Main Actor
        4. Setting the Skeleton Disappear Behavior
        5. Creating a Custom Code Behavior to Lower the Health Value
      14. Adding Behaviors for the Barrel Actor
        1. Adding the Gravity Shortcut for the Barrel Actor
        2. Adding the Disappear Behavior
      15. Building the HealthBar Behaviors
        1. Building a Custom Code Behavior for Updating the HealthBar’s HealthValue
        2. Creating a Scene Change Behavior to End the Game
      16. Adding the Blind Scientist Behaviors
        1. Adding a Custom Code Behavior to Call the Grow Animation Storyboard
        2. Adding Random Left and Right Motion Behaviors
        3. Adding a Behavior to Lower the Health Value
        4. Adding the Scene Change Behavior to Win the Game
      17. Publishing Your Game
        1. Publishing to Facebook
      18. Final Thoughts
    3. 3. FEED READER: An In-Game RSS Reader for World of Warcraft
      1. Overview
        1. Running Feed Grabber
        2. Feed Reader
        3. Feed Reader Slash Commands
      2. Before We Get Started
        1. A Quick Tour of the Lua Programming Language
          1. Lua types
          2. Variable scopes
          3. Lua functions
          4. Understanding Lua tables
          5. Feed Reader’s Lua table
        2. FrameXML 101
          1. Layout
          2. AddOn Studio for designing FrameXML
          3. Templates
          4. Events
      3. Understanding the Feed Reader Addon
        1. Dissecting Feed Reader
        2. How Feed Reader and Feed Grabber Work
        3. The Feed Reader UI
          1. Frames
        4. Adding Code for Frame.xml
          1. Global variables
          2. Defining a variable as a saved variable
          3. Registering for Warcraft events
          4. The SelectFeed and SelectFeedItems functions
          5. The SelectFeedItem function
          6. The UpdateFeeds and UpdateFeedItems functions
          7. The UpdateFeeds function
          8. The UpdateFeedItems function
          9. Updating the summary
          10. OnClick event for Feed buttons
          11. OnClick event for FeedItem buttons
          12. Adding a basic slash command
      4. Feed Grabber
        1. Common Feed List
          1. Programmatically getting feeds
          2. Serializing to Lua
          3. Sneaking in data updates by monitoring the Saved Variables file
      5. Final Thoughts
  6. II. Software and Web
    1. 4. InnerTube: Download, Convert, and Sync YouTube Videos
      1. Overview
        1. InnerTube’s Main UI
        2. Running InnerTube for the First Time
        3. Adding Videos
      2. How InnerTube Works
      3. How YouTube’s API Works
        1. Standard YouTube Feeds
        2. User-Specific YouTube Feeds
        3. YouTube Search
        4. Optional Query String Parameters
        5. Other Important YouTube URLs
      4. Building Classes for YouTube Feeds and Videos
      5. Calling the InnerTubeService Class
        1. Converting YouTube XML into .NET Objects
      6. Downloading Videos from YouTube
        1. Downloading a YouTube Video with Your Browser
        2. YouTube Blocks You (by Design)
        3. Getting a Session Token from JavaScript
        4. Houston, We Have a Token!
        5. Getting a Token Programmatically
        6. Downloading the Video
        7. Downloading a Video’s Thumbnail Image
      7. Converting YouTube Videos Using ffmpeg
      8. Syncing YouTube Videos to iTunes and Zune
        1. Syncing Videos to iTunes
        2. Syncing Videos to Zune
          1. Zune monitored folders
      9. Putting It All Together
        1. Calling InnerTubeFeedWorker
      10. Setting Up the InnerTube WPF Application
        1. Global Variables
        2. Application Settings
      11. Building the InnerTube UI
      12. InnerTube Skeleton
      13. Dissecting MainWindow.xaml
        1. Setting the MainWindow.xaml data context
        2. Part 1: The Feed List ListBox
          1. Data binding the feedList ListBox
        3. Part 2: The VideoList ListBox
        4. The Data Template UI
        5. Data Binding the Video List ListBox
        6. Binding to an Image
        7. Building the Image Value Converter
        8. Setting Up a Class As a Static Resource
        9. Part 3: The Details Pane
        10. Formatting Numbers in WPF
        11. Data Binding in the Details Pane
        12. Data Binding to User Controls
        13. MediaPlayer User Control UI
        14. MediaPlayer Data Binding
        15. Playing and Pausing Video
      14. Final Thoughts
    2. 5. PeerCast: Watch Videos on Your PC Anywhere in the World
      1. Overview
      2. A Tour of PeerCast
        1. Client or Server Mode
          1. Server mode
          2. Client mode
      3. How PeerCast Works
        1. How Peer Channel Applications Work
          1. Key P2P terms
          2. Peer Channel by example
        2. Building a Peer Channel Application
          1. Listening to P2P messages asynchronously
          2. Structuring messages from the background thread to the UI thread
        3. The NetworkManager Class
          1. NetworkManager variables and constructor
          2. Starting a connection
          3. Running on a background thread
          4. Subscribing to P2PLib events
          5. Reporting progress to the UI thread while we wait for a connection
          6. Keeping the BackgroundWorker thread alive
        4. Listening to P2P Events Using Network Manager
          1. Understanding how the login process works
          2. The StatusChanged event
          3. Sending commands using chat messages
          4. Understanding how chat messages work
          5. Receiving chat messages in the ChatChanged event handler
          6. Processing commands on the server
          7. The GetList ChatCommand
        5. Using C4FP2P to Stream Videos
          1. Understanding how video streaming works
          2. Setting up a video stream
          3. Two different StreamChanged events
          4. The P2PLib StreamChanged event
          5. Logging messages when streaming a video
          6. Finished streaming a video
          7. Ending a connection
      4. Building the Application UI
        1. Choosing the Application Mode
          1. Storing the PeerCast mode
        2. Building the MainWindow.xaml UI
          1. Defining the four-cell grid
          2. The login cell
          3. The Message cell
          4. The Client controls cell
          5. Server controls and the media player cell
        3. Adding the MainWindow.xaml Code
          1. MainWindow properties
          2. MainWindow constructor
          3. Signing in
          4. Receiving UI updates from ProgressChanged
          5. Toggling the UI
          6. Receiving a video list
          7. Deserializing the file list
          8. Playing a video
          9. Sending a Play message
          10. Sending a full-screen play message
          11. Getting a list of videos from the server
          12. Selecting the video streaming directory
          13. When P2pWorker completes
      5. Final Thoughts
    3. 6. TwitterVote
      1. Overview
        1. Twitter Rules and Limitations
      2. Building TwitterVote
        1. Twitter: Under the Hood
        2. The Twitter API
        3. Twitter Implementation
        4. Voting Implementation
      3. Displaying Results with Popfly
        1. Embedding the Popfly Results Graph
        2. Running the Application
        3. Sample Poll and Results
      4. Final Thoughts
    4. 7. WHSMail: An Outlook Webmail Add-in for Windows Home Server
      1. Overview
      2. Understanding the Setup
      3. Architecture
      4. Building the Host Application
      5. Windows Communication Foundation (WCF)
        1. Contracts and Entities
        2. Configuration
      6. Using Outlook and MAPI
      7. ASP.NET “Client”
      8. Deployment
        1. WHSMailWeb
      9. Running the Application
      10. Final Thoughts
  7. III. Hardware
    1. 8. Wiimote-controlled Car
      1. Overview
      2. Building the Hardware
        1. Phidgets
        2. Phidget 0/0/4 Interface Kit
        3. Phidget 0/16/16 Interface Kit
      3. Building the Software
        1. Software Requirements
        2. Software Implementation
          1. Special steps for 64-bit Windows users
      4. Using the Application
        1. Pairing the Wiimote
        2. Installing the Phidget Interface Kit
        3. Driving the Car
      5. Final Thoughts
    2. 9. Wiimote Whiteboard
      1. Overview
      2. Defining an Interactive Whiteboard
      3. Using the Wii Remote Infrared Camera
      4. Using IR Pens
        1. Building the Circuit
        2. Preparing the Dry-Erase Marker
      5. Setting Up Your Project
      6. Warping the Camera Coordinates
      7. Touch Calibration
      8. Putting It All Together
        1. Parsing Data from the IR Camera
      9. Using the Software
      10. Final Thoughts
    3. 10. Animated Musical Holiday Lights
      1. Overview
      2. Building the Hardware
        1. Information on Amperages
      3. Writing the Software
        1. Software Requirements
        2. Software Implementation
          1. Sequence
          2. Grid display
          3. Playing music
          4. Recording data
          5. Playing a sequence
        3. Creating a Show
      4. Final Thoughts
  8. A. Using the C4fStyle File for WPF Projects
    1. C4fStyle Overview
      1. Adding the C4fStyle File to Your Application
        1. Generic and named styles
        2. Style reference
        3. Before and after
  9. Index
  10. About the Authors
  11. Colophon
  12. Special Upgrade Offer
  13. Copyright