SlideShare a Scribd company logo
How to Build an HTML5 Game in Half Day
                      with help of processing.js

                                     Wu Zhe (wu@madk.org)



                                          Sep 3, 2010




Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
What’s new about HTML5?




             semantic tags: <nav>, <footer>, <section> ...
             multimedia:             <video>, <audio>
             2D drawing:             <canvas>




Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
<canvas>



      HTML:
        <canvas id="example" width="200" height="200"></canvas>

      JS:
        var example = document.getElementById(’example’);
        var context = example.getContext(’2d’);
        context.fillStyle = "rgb(255,0,0)";
        context.fillRect(30, 30, 50, 50);




Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
processing.js




             a port of Processing programming language to Javascript
             a thin wrapper of 2D js drawing operations on <canvas>
      API doc: http://processingjs.org/reference




Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
let’s build an HTML5 game




             HTML5 clone of a classic game I built during a weekend
             play at http://nuwa.madk.org/game/floor.html




Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
let’s build an HTML5 game – code structure




             some global variables
             setup()
             draw()




Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
let’s build an HTML5 game – logic




             OO
             class Person
             class Block




Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
let’s build an HTML5 game – inside draw()

      void draw() {
        background(#223322); // clear screen
        // update and redraw every block
        for (byte i = blks.length-1; i >= 0; i--) {
          blks[i].move();
          if (blks[i].outofscreen()) {
            blks[i] = new Block(random(width), height, blk_speed,
            p.level += 1;
          }
          blks[i].render();
        }
        p.move(); p.update_mode(); p.render(); // update person
      }
Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
let’s build an HTML5 game – inside class Person

      methods:
             Person(float x, float y, float vx, float vy, byte
             on blk)
             boolean x on blk(byte i)
             boolean person on blk(byte i)
             void update mode()
             void step into air()
             void land on blk(byte i)
             void move()
             void render()


Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
let’s build an HTML5 game – inside class Block



      methods:
             Block(float x, float y, float vy, byte type)
             void decrease timer()
             boolean outofscreen()
             void move()
             void render()




Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
Summary




             think of a game idea (what to build)
             build
             get better artwork
             spread the world




Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day
Source code




      source code at
      http://nuwa.madk.org/game/floor.pjs




Wu Zhe (wu@madk.org)
Building an HTML5 Game in Half Day

More Related Content

PDF
Dev chrome tools tips and tricks
KEY
Dojo, from scratch to result
PDF
3D everywhere
PPT
Game Development With HTML5
PPTX
WebGL and three.js - Web 3D Graphics
ODP
Clojure cnclojure-meetup
PDF
Clojure Web Development
PDF
Hypnotherapy Induction - Candle Breathing
Dev chrome tools tips and tricks
Dojo, from scratch to result
3D everywhere
Game Development With HTML5
WebGL and three.js - Web 3D Graphics
Clojure cnclojure-meetup
Clojure Web Development
Hypnotherapy Induction - Candle Breathing

Viewers also liked (20)

DOCX
Job Interview Questions Answered
DOCX
Lágrimas en la Lluvia
PDF
UltiMotion Motion Control | Hurco IMTS 2012
PPT
Prueba 1
PPSX
Magnolia residences @new manila
PDF
WinMax Version 9 | Hurco IMTS 2012
PPT
Arch north staffs
PDF
Insomnia Induction and Script
PDF
Hypnotherapy Inductions - Sunset and mist
PDF
Prayan 2012 prelims
PPS
Philosophy for old_age
PPTX
Plágio na era digital edna e edgleide
PDF
rand() + LinkN Crack
PDF
43 molekullerkatilar
PDF
R2 !ncredible India
PDF
Birrul walidain
PDF
Missilleaneous
PDF
R1 Hello world
PDF
TaeKwonDo Patterns
Job Interview Questions Answered
Lágrimas en la Lluvia
UltiMotion Motion Control | Hurco IMTS 2012
Prueba 1
Magnolia residences @new manila
WinMax Version 9 | Hurco IMTS 2012
Arch north staffs
Insomnia Induction and Script
Hypnotherapy Inductions - Sunset and mist
Prayan 2012 prelims
Philosophy for old_age
Plágio na era digital edna e edgleide
rand() + LinkN Crack
43 molekullerkatilar
R2 !ncredible India
Birrul walidain
Missilleaneous
R1 Hello world
TaeKwonDo Patterns
Ad

Similar to How to Build an HTML5 Game in Half a day (20)

PDF
HTML5 & JavaScript Games
PDF
W3C HTML5 KIG-The complete guide to building html5 games
ODP
HTML5 Game Development frameworks overview
KEY
Seattle javascript game development - Overview
PPTX
A Holistic Approach to HTML5 Game Design & Development
PPTX
Presentation3
PPTX
Chap1.pptx
PDF
One codebase, multiple platforms; Using HTML5/js for game dev
PDF
Intro to HTML5 Game Programming
PDF
mloc.js 2014 - JavaScript and the browser as a platform for game development
PDF
Intro to HTML5
PDF
course1-Intrduction-to-the-game-industry.pdf
PPTX
WebGL For Game Development Spring 2013
PPTX
WebGL For Game Development 2012
PDF
Building a game engine with jQuery
PDF
HTML5 Games Status and issues
PPTX
Html5 (games)
PDF
Game Development Using HTML 5
ODP
HTML5 as a game console
PPT
WebGL: GPU acceleration for the open web
HTML5 & JavaScript Games
W3C HTML5 KIG-The complete guide to building html5 games
HTML5 Game Development frameworks overview
Seattle javascript game development - Overview
A Holistic Approach to HTML5 Game Design & Development
Presentation3
Chap1.pptx
One codebase, multiple platforms; Using HTML5/js for game dev
Intro to HTML5 Game Programming
mloc.js 2014 - JavaScript and the browser as a platform for game development
Intro to HTML5
course1-Intrduction-to-the-game-industry.pdf
WebGL For Game Development Spring 2013
WebGL For Game Development 2012
Building a game engine with jQuery
HTML5 Games Status and issues
Html5 (games)
Game Development Using HTML 5
HTML5 as a game console
WebGL: GPU acceleration for the open web
Ad

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PDF
KodekX | Application Modernization Development
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
MYSQL Presentation for SQL database connectivity
Approach and Philosophy of On baking technology
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Spectroscopy.pptx food analysis technology
Digital-Transformation-Roadmap-for-Companies.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MIND Revenue Release Quarter 2 2025 Press Release
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
KodekX | Application Modernization Development
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
MYSQL Presentation for SQL database connectivity

How to Build an HTML5 Game in Half a day

  • 1. How to Build an HTML5 Game in Half Day with help of processing.js Wu Zhe (wu@madk.org) Sep 3, 2010 Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 2. What’s new about HTML5? semantic tags: <nav>, <footer>, <section> ... multimedia: <video>, <audio> 2D drawing: <canvas> Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 3. <canvas> HTML: <canvas id="example" width="200" height="200"></canvas> JS: var example = document.getElementById(’example’); var context = example.getContext(’2d’); context.fillStyle = "rgb(255,0,0)"; context.fillRect(30, 30, 50, 50); Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 4. processing.js a port of Processing programming language to Javascript a thin wrapper of 2D js drawing operations on <canvas> API doc: http://processingjs.org/reference Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 5. let’s build an HTML5 game HTML5 clone of a classic game I built during a weekend play at http://nuwa.madk.org/game/floor.html Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 6. let’s build an HTML5 game – code structure some global variables setup() draw() Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 7. let’s build an HTML5 game – logic OO class Person class Block Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 8. let’s build an HTML5 game – inside draw() void draw() { background(#223322); // clear screen // update and redraw every block for (byte i = blks.length-1; i >= 0; i--) { blks[i].move(); if (blks[i].outofscreen()) { blks[i] = new Block(random(width), height, blk_speed, p.level += 1; } blks[i].render(); } p.move(); p.update_mode(); p.render(); // update person } Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 9. let’s build an HTML5 game – inside class Person methods: Person(float x, float y, float vx, float vy, byte on blk) boolean x on blk(byte i) boolean person on blk(byte i) void update mode() void step into air() void land on blk(byte i) void move() void render() Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 10. let’s build an HTML5 game – inside class Block methods: Block(float x, float y, float vy, byte type) void decrease timer() boolean outofscreen() void move() void render() Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 11. Summary think of a game idea (what to build) build get better artwork spread the world Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day
  • 12. Source code source code at http://nuwa.madk.org/game/floor.pjs Wu Zhe (wu@madk.org) Building an HTML5 Game in Half Day