discovering new features in html5 · installing the box2d javascript library . drawing the physics...

85
1 Introducing HTML5 Games Discovering new features in HTML5 Offline applications

Upload: others

Post on 21-Aug-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

1 Introducing HTML5 Games

Discovering new features in HTML5

Offline applications

Page 2: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Discovering new features in CSS3

CSS3 animation

Page 3: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

The benefit of creating HTML5 games

Breaking the boundary of usual browser games

Page 4: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

What others are playing with HTML5

Coca-Cola's Ahh campaign

Page 5: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Asteroid-styled bookmarklet

Page 6: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

X-Type

Page 7: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Cursors.io

Page 8: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

What we are going to create in this book

Page 9: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

2 Getting Started with DOM-based Game

Development

Preparing the HTML documents for a DOM-based game

Page 10: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Downloading the image assets

Setting up the Ping Pong game elements

Page 11: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Understanding the behavior of absolute position

Getting mouse input

Checking the console window

Page 12: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Beginning collision detection

Page 13: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 14: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

3 Building a Card Matching Game in CSS3

Moving game objects with CSS3 transition

Creating a card-flipping effect

Page 15: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Introducing CSS' perspective property

Page 16: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Introducing backface-visibility

Creating a card-matching memory game

Downloading the sprites sheet of playing cards

Page 17: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Setting up the game environment

Page 18: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Using CSS sprite with a background position

Page 19: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 20: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Adding game logic to the matching game

Page 21: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Embedding web fonts into our game

Page 22: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 23: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

4 Building the Untangle Game with Canvas

and the Drawing API

Page 24: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Drawing a circle in the Canvas

Closing a path

Page 25: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Wrapping the circle drawing in a function

Page 26: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Drawing lines in the Canvas

Using mouse events to interact with objects drawn in the Canvas

Page 27: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Detecting mouse events in circles in the Canvas

Detecting line intersection in Canvas

Determining whether two line segments intersect

Page 28: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 29: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

5 Building a Canvas Game's Masterclass

Page 30: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Making the Untangle puzzle game

Page 31: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Using embedded web font inside the Canvas

Page 32: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Drawing images in the Canvas

Page 33: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Decorating the Canvas-based game

Animating a sprite sheet in Canvas

Page 34: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 35: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 36: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 37: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Creating a multi-layer Canvas game

Page 38: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 39: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

6 Adding Sound Effects to Your Games

Page 40: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Adding a sound effect to the Play button

Page 41: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Defining an audio element

Building a mini piano musical game

Page 42: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Creating scenes in games

Page 43: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Creating a slide-in effect in CSS3

Page 44: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Visualizing the music playback

Page 45: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 46: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Getting the elapsed time of the game

Page 47: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Moving the music dots

Page 48: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Creating a keyboard-driven mini piano musical game

Hitting the three music lines by key down

Page 49: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Adding additional features to the mini piano game

Recording music notes as level data

Page 50: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

7 Saving the Game's progress

Page 51: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Storing data using HTML5 local storage

Creating a game over dialog

Saving scores in the browser

Page 52: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Saving objects in the local storage

Page 53: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Loading a stored object from a JSON string

Page 54: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Inspecting the local storage in a console window

Page 55: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Notifying players when they break a new record with a nice ribbon effect

Saving the entire game progress

Page 56: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Resuming the game progress

Caching the game for offline access

Page 57: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

8 Building a Multiplayer Draw-and-Guess

Game with WebSockets

Page 58: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Installing a WebSocket's server

Creating a client that connects to a WebSocket server and getting the total connections count

Sending a message to all connected browsers

Page 59: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Building a chatting application with WebSockets

Sending a message to the server

Page 60: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Sending every received message on the server side to create a chat room

Comparing WebSockets with polling approaches

Page 61: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 62: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Making a shared drawing whiteboard with Canvas and WebSockets

Building a local drawing sketchpad

Sending the drawing to all the connected browsers

Page 63: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Building a multiplayer draw-and-guess game

Page 64: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

9 Building a Physics Car Game with Box2D

and Canvas

Page 65: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Installing the Box2D JavaScript library

Page 66: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Drawing the physics world in the canvas

Creating a dynamic box in the physics world

Page 67: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Advancing the world time

Adding wheels to the game

Page 68: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Creating a physical car

Using a revolute joint to create an anchor point between two bodies

Page 69: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Adding force to the car with a keyboard input

Adding ramps to our game environment

Page 70: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Checking collisions in the Box2D world

Page 71: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Adding a level support to our car game

Replacing the Box2D outline drawing with graphics

Page 72: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Adding a final touch to make the game fun to play

Page 73: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 74: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Presenting the remaining fuel in a CSS3 progress bar

Page 75: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Adding touch support for tablets

Page 76: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

10 Deploying HTML5 Games

Building an HTML5 game into a Mac OS X app

Page 77: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 78: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 79: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 80: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 81: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 82: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 83: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 84: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the
Page 85: Discovering new features in HTML5 · Installing the Box2D JavaScript library . Drawing the physics world in the canvas Creating a dynamic box in the physics world . Advancing the

Building with PhoneGap build