SlideShare una empresa de Scribd logo
1 de 21
Modeling Patterns for JavaScript Browser-Based Games JarodLong           Ray Toal Loyola Marymount University Los Angeles, CA USA 2011-05-16
Topics	 Overview of Contributions Challenges for Browser-Based Games What’s new with JavaScript Patterns vs. Frameworks Contributions in Detail JavaScript and HTML5 Game Engines Summary
Contributions Development of JavaScript design patterns specifically for modules and types Note: patterns, not frameworks Patterns are independent of game engine Application of these patterns in a 2-D, physics-based, HTML5 game Survey of JavaScript game engines
Browser-Based Game Issues Rich domain models  OOP was motivated by graphical applications Graphics and physics engines Can mix Canvas and the DOM  don’t forget CSS! (esp. CSS3) Full source code visibility Ajax High score lists difficult to implement
JavaScript The most popular language for programming the client-side web (competes with Flash and Java) Created in 1996 but only “understood” in mid 2000s Recent Advances ECMAScript 5 V8 and other modern engines (>100x faster) Server-side (e.g., node.js) (BIG FUTURE IN THIS)
JavaScript Overview Array and object literals varx = [3, “true”, 2.2]; var point = {lat: 27.95, lon: -140.4}; A functional programming language -- closer to Scheme than C myArray.map(function (x) {return x * x;}); data.map(square).filter(isOdd).reduce(plus); Prototypes, not classes varmyCircle = Object.create(yourCircle); myCircle.color = “rgb(23,100, 122)”;
Software Modeling Games are naturally event-driven and feature an object-oriented architecture Modules and Types Common types: vector, sprite, fortress, level, weapon, enemy, projectile, … Common modules (singletons): math, world, camera, game, util, ui, input, contact, …  How can these be represented in JavaScript?
JavaScript Prototypes varc = { x: 0, y: 0,      radius: 1,     color: black }; var c1 = Object.create(c); c1.x = 3; c1.color = "green"; var c2 = Object.create(c); c1.x = 4; c1.radius = 15; var c3 = Object.create(c); assert(c2.color === "black"); The prototype is NOT a "class" object
Shared Behavior in Prototypes varc = { x: 0, y: 0, radius: 1, color: black,     area: function () {return this.radius * Math.PI * Math.PI;},     . . . }; Because we don't want separate function copies in each object
Inheritance ,[object Object]
  But how to do "super"?  Do we care?,[object Object]
A Module Pattern <package>.M = (function () { var privatePropertyOrMethod1 = …;     … var M = {};     M.publicProperty1 = …;     M.publicMethod1 = function (…) {…};     …     return M; }()); Already familiar to JavaScript professionals (We just prefer avoiding object literals)
Type Pattern <package>.T = (function () { var T = {};     ... T.create = function (…) { vart = Object.create(this);         ...         return t;     }     return T; }()); Instantiate with:  varx = <package>.T.create(…); The "type" object and the prototype are one!  Differs from operator new, which equates the type with the constructor (prototype separate) Shared properties and methods go here Assign the own properties here
Root Types <package>.GameObject = (function () { varGameObject = {}; GameObject.GameObject = GameObject; GameObject.create = function (id) { varg = Object.create(this); g.id = id;         return g;     } GameObject.update = function () { alert("Updating game object " + this.id);     }     return GameObject; }()); Self reference will allow multiple levels of "super" Of course we are going to override this on the next slide
Subtypes <package>.Projectile = (function () { var Projectile = Object.create(<package>.GameObject); Projectile.Projectile = Projectile; Projectile.create = function (id, name) { varp = <package>.GameObject.create.call(this, id); p.name = name;         return p;     } Projectile.update = function () {  // override! this.GameObject.update.call(this); alert("Updating projectile " + this.name);     }        return Projectile; }()); Note use of "this" instead of the package name – it shows we are using an ancestor type
Subtypes, Slightly Cleaner <package>.Projectile = (function (supertype) { var Projectile = Object.create(supertype); Projectile.Projectile = Projectile; Projectile.create = function (id, name) { varp = supertype.create.call(this, id); p.name = name;         return p;     } Projectile.update = function () {  // override! supertype.update.call(this); alert("Updating projectile " + this.name);     }        return Projectile; }(package.GameObject)); Or mention an ancestor type directly
How it all Looks Private data from closures not shown
Applications http://manicmonkeymadness.googlecode.com
Why is this Useful? No extra scripts to include No framework to learn  No need to say "new Base" and ".extend" "Super" functionality is still available if needed Programmer can apply the pattern selectively It's real JavaScript  Closures and Function.call are hardcore Maintains prototypal feel, even though class-like Type.create()
JavaScript Game Engines The Render Engine Impact Aves (Zynga Germany) Effect Isogenic gameQuery Rocket Engine (acquired by Disney) See engine lists and comparisons at https://github.com/bebraw/jswiki/wiki/Game-Engines and http://www.cssgalleries.com/2011/02/the-big-list-of-javascript-game-engines/
Summary Games benefit from an object-oriented, event-driven architecture Many approaches exist for modeling an OO software architecture in JavaScript We presented framework-free, engine independent modeling patterns Patterns were applied in a real HTML5, no-Flash application

Más contenido relacionado

La actualidad más candente

PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootJosué Neis
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
Performance Testing using Real Browsers with JMeter & Webdriver
Performance Testing using Real Browsers with JMeter & WebdriverPerformance Testing using Real Browsers with JMeter & Webdriver
Performance Testing using Real Browsers with JMeter & WebdriverBlazeMeter
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introductionJonathan Holloway
 
Using MongoDB With Groovy
Using MongoDB With GroovyUsing MongoDB With Groovy
Using MongoDB With GroovyJames Williams
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - ExplainedSmita Prasad
 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Javahendersk
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action Alex Movila
 

La actualidad más candente (20)

PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Spring boot
Spring bootSpring boot
Spring boot
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Performance Testing using Real Browsers with JMeter & Webdriver
Performance Testing using Real Browsers with JMeter & WebdriverPerformance Testing using Real Browsers with JMeter & Webdriver
Performance Testing using Real Browsers with JMeter & Webdriver
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Using MongoDB With Groovy
Using MongoDB With GroovyUsing MongoDB With Groovy
Using MongoDB With Groovy
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 
Using Mockito
Using MockitoUsing Mockito
Using Mockito
 
Java - Lombok
Java - LombokJava - Lombok
Java - Lombok
 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Java
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Collection framework
Collection frameworkCollection framework
Collection framework
 

Similar a Modeling Patterns for JavaScript Browser-Based Games

JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webpjcozzi
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015jbandi
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application FrameworkJady Yang
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4alexsaves
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsMike Wilcox
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller ColumnsJonathan Fine
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptRohan Chandane
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e bigAndy Peterson
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for DesignersR. Sosa
 

Similar a Modeling Patterns for JavaScript Browser-Based Games (20)

JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
 
JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
Modern frontend in react.js
Modern frontend in react.jsModern frontend in react.js
Modern frontend in react.js
 
GWT Extreme!
GWT Extreme!GWT Extreme!
GWT Extreme!
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 

Más de Ray Toal

Git workshop
Git workshopGit workshop
Git workshopRay Toal
 
Learning and Modern Programming Languages
Learning and Modern Programming LanguagesLearning and Modern Programming Languages
Learning and Modern Programming LanguagesRay Toal
 
Java best practices
Java best practicesJava best practices
Java best practicesRay Toal
 
unittest in 5 minutes
unittest in 5 minutesunittest in 5 minutes
unittest in 5 minutesRay Toal
 
Convention-Based Syntactic Descriptions
Convention-Based Syntactic DescriptionsConvention-Based Syntactic Descriptions
Convention-Based Syntactic DescriptionsRay Toal
 
An Annotation Framework for Statically-Typed Syntax Trees
An Annotation Framework for Statically-Typed Syntax TreesAn Annotation Framework for Statically-Typed Syntax Trees
An Annotation Framework for Statically-Typed Syntax TreesRay Toal
 
Economics of Open Source Software
Economics of Open Source SoftwareEconomics of Open Source Software
Economics of Open Source SoftwareRay Toal
 

Más de Ray Toal (7)

Git workshop
Git workshopGit workshop
Git workshop
 
Learning and Modern Programming Languages
Learning and Modern Programming LanguagesLearning and Modern Programming Languages
Learning and Modern Programming Languages
 
Java best practices
Java best practicesJava best practices
Java best practices
 
unittest in 5 minutes
unittest in 5 minutesunittest in 5 minutes
unittest in 5 minutes
 
Convention-Based Syntactic Descriptions
Convention-Based Syntactic DescriptionsConvention-Based Syntactic Descriptions
Convention-Based Syntactic Descriptions
 
An Annotation Framework for Statically-Typed Syntax Trees
An Annotation Framework for Statically-Typed Syntax TreesAn Annotation Framework for Statically-Typed Syntax Trees
An Annotation Framework for Statically-Typed Syntax Trees
 
Economics of Open Source Software
Economics of Open Source SoftwareEconomics of Open Source Software
Economics of Open Source Software
 

Último

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Último (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Modeling Patterns for JavaScript Browser-Based Games

  • 1. Modeling Patterns for JavaScript Browser-Based Games JarodLong Ray Toal Loyola Marymount University Los Angeles, CA USA 2011-05-16
  • 2. Topics Overview of Contributions Challenges for Browser-Based Games What’s new with JavaScript Patterns vs. Frameworks Contributions in Detail JavaScript and HTML5 Game Engines Summary
  • 3. Contributions Development of JavaScript design patterns specifically for modules and types Note: patterns, not frameworks Patterns are independent of game engine Application of these patterns in a 2-D, physics-based, HTML5 game Survey of JavaScript game engines
  • 4. Browser-Based Game Issues Rich domain models OOP was motivated by graphical applications Graphics and physics engines Can mix Canvas and the DOM don’t forget CSS! (esp. CSS3) Full source code visibility Ajax High score lists difficult to implement
  • 5. JavaScript The most popular language for programming the client-side web (competes with Flash and Java) Created in 1996 but only “understood” in mid 2000s Recent Advances ECMAScript 5 V8 and other modern engines (>100x faster) Server-side (e.g., node.js) (BIG FUTURE IN THIS)
  • 6. JavaScript Overview Array and object literals varx = [3, “true”, 2.2]; var point = {lat: 27.95, lon: -140.4}; A functional programming language -- closer to Scheme than C myArray.map(function (x) {return x * x;}); data.map(square).filter(isOdd).reduce(plus); Prototypes, not classes varmyCircle = Object.create(yourCircle); myCircle.color = “rgb(23,100, 122)”;
  • 7. Software Modeling Games are naturally event-driven and feature an object-oriented architecture Modules and Types Common types: vector, sprite, fortress, level, weapon, enemy, projectile, … Common modules (singletons): math, world, camera, game, util, ui, input, contact, … How can these be represented in JavaScript?
  • 8. JavaScript Prototypes varc = { x: 0, y: 0, radius: 1, color: black }; var c1 = Object.create(c); c1.x = 3; c1.color = "green"; var c2 = Object.create(c); c1.x = 4; c1.radius = 15; var c3 = Object.create(c); assert(c2.color === "black"); The prototype is NOT a "class" object
  • 9. Shared Behavior in Prototypes varc = { x: 0, y: 0, radius: 1, color: black, area: function () {return this.radius * Math.PI * Math.PI;}, . . . }; Because we don't want separate function copies in each object
  • 10.
  • 11.
  • 12. A Module Pattern <package>.M = (function () { var privatePropertyOrMethod1 = …; … var M = {}; M.publicProperty1 = …; M.publicMethod1 = function (…) {…}; … return M; }()); Already familiar to JavaScript professionals (We just prefer avoiding object literals)
  • 13. Type Pattern <package>.T = (function () { var T = {}; ... T.create = function (…) { vart = Object.create(this); ... return t; } return T; }()); Instantiate with: varx = <package>.T.create(…); The "type" object and the prototype are one! Differs from operator new, which equates the type with the constructor (prototype separate) Shared properties and methods go here Assign the own properties here
  • 14. Root Types <package>.GameObject = (function () { varGameObject = {}; GameObject.GameObject = GameObject; GameObject.create = function (id) { varg = Object.create(this); g.id = id; return g; } GameObject.update = function () { alert("Updating game object " + this.id); } return GameObject; }()); Self reference will allow multiple levels of "super" Of course we are going to override this on the next slide
  • 15. Subtypes <package>.Projectile = (function () { var Projectile = Object.create(<package>.GameObject); Projectile.Projectile = Projectile; Projectile.create = function (id, name) { varp = <package>.GameObject.create.call(this, id); p.name = name; return p; } Projectile.update = function () { // override! this.GameObject.update.call(this); alert("Updating projectile " + this.name); } return Projectile; }()); Note use of "this" instead of the package name – it shows we are using an ancestor type
  • 16. Subtypes, Slightly Cleaner <package>.Projectile = (function (supertype) { var Projectile = Object.create(supertype); Projectile.Projectile = Projectile; Projectile.create = function (id, name) { varp = supertype.create.call(this, id); p.name = name; return p; } Projectile.update = function () { // override! supertype.update.call(this); alert("Updating projectile " + this.name); } return Projectile; }(package.GameObject)); Or mention an ancestor type directly
  • 17. How it all Looks Private data from closures not shown
  • 19. Why is this Useful? No extra scripts to include No framework to learn No need to say "new Base" and ".extend" "Super" functionality is still available if needed Programmer can apply the pattern selectively It's real JavaScript Closures and Function.call are hardcore Maintains prototypal feel, even though class-like Type.create()
  • 20. JavaScript Game Engines The Render Engine Impact Aves (Zynga Germany) Effect Isogenic gameQuery Rocket Engine (acquired by Disney) See engine lists and comparisons at https://github.com/bebraw/jswiki/wiki/Game-Engines and http://www.cssgalleries.com/2011/02/the-big-list-of-javascript-game-engines/
  • 21. Summary Games benefit from an object-oriented, event-driven architecture Many approaches exist for modeling an OO software architecture in JavaScript We presented framework-free, engine independent modeling patterns Patterns were applied in a real HTML5, no-Flash application