Making Isometric Social Real-Time Games with HTML5, CSS3, and Javascript
Mario Andres Pagella
Copyright 2011 Mario Andres Pagella
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (.
Nutshell Handbook, the Nutshell Handbook logo, and the OReilly logo are registered trademarks of OReilly Media, Inc. Making Isometric Social Real-Time Games with HTML5, CSS3, and Javascript , the image of coots, and related trade dress are trademarks of OReilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and OReilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
O'Reilly Media
Preface
Addictive, frustrating. Fun, boring. Engaging, repetitive. Casual, demanding .
These words may contradict each other, but they express the roller coaster of sentiments felt by real-time strategy games players like me. I remember spending countless hours playing brilliant games such as EA/Maxiss SimCity and SimCity 2000, Chris Sawyers Transport Tycoon, or Bullfrog Productions Theme Hospital, wondering why only a few of my friends (usually the geekiest ones) had played them.
Today, I see children and teenagers, grandmothers and soccer moms, and frat boys and computer geeks playing games such as Zyngas FarmVille or CityVille, Playdoms Social City, or Playfishs MyEmpire for hours, ignorant of the existence of those games predecessors : a golden age of isometric real-time games that theyll probably never play.
What changed?
This recent surge of isometric real-time games was caused partly by Zyngas incredible ability to keep the positive things and get rid of the negative things in this particular genre of games, and partly by a shift in consumer interests. They took away the frustration of figuring out why no one was moving to your city (in the case of SimCity) and replaced it with adding friends to be your growing neighbors. They took advantage of Facebooks social capabilities to change the nature of gaming. They made the boring parts more interactive by letting you not only place the objects, but also build them and manually collect the points they generate. After a whileusually a few weekswhen the game starts to feel repetitive, they present you with quests and make you interact with your friends. Finally, the constructions that you build will remain, generating profits and points even if you are not playing the game. (This concept is usually referred to in the industry as asynchronous play or asynchronous game mechanics .)
When you eliminate frustration, boredom, and repetition (the three bad aspects of isometric real-time games), you end up with an addictive, fun, engaging, and casual (or demanding, depending on how you want to play it) genre of games thatthanks to its social-related progress requirementscan go viral in a heartbeat. No wonder Zyngas valuation at the time of writing is $10 billion (surpassing Electronic Arts (EA), one of the biggest traditional game publishers in the world), or that Playdom was purchased by Disney for 760 million dollars. Coming up with the right values for each variable of the gameplay equation for your own game is extremely hard, but when you manage to get everything right, the very nature of this genre of social games can make it an instant hit.
The interfaces of isometric social real-time games are simple compared with conventional real-time strategy games: a living map editor where you can place objects on a matrix of tiles, which well usually refer to as the grid. Depending on the object, which in our case will be buildings, some of them may generate P amount of points every T amount of time. So even when were not playing the game, buildings will keep generating points.
As the final project in this book, were going to develop a game called Tourist Resort in which users will have to build a resort complex, decorate it with trees, and place various shops. Each shop will generate N amount of profit every T amount of time; this profit will then allow them to buy more buildings.
The Rise of HTML5
While social isometric game systems were improving, the technologies available to build them were also changing.
For many years, the tools available to develop rich and highly interactive online games that can run within web browsers remained the same; Virtual Reality Modeling Language (VRML), Java Applets, Macromedia Shockwave, Adobe Flash, Microsoft Silverlight, Unity3D, and others all meant using third-party and proprietary solutions, and if users wanted to use those applications, they had to download and install browser add-ons. Even worse was that developers also had to pay for really expensive IDEs (integrated development environments) to develop them.
Web technologies such as HTML, CSS, and JavaScript could not provide users with the same quality end-user experience that could be achieved with other tools such as Adobe Flash. Browsersparticularly with JavaScriptwere slow; they lacked support for native video, audio, and local storage; and some of them, such as Internet Explorer, neither supported transparencies in PNG images nor provided developers with tools to perform even basic bit-lock image transfers. They werent ready for anything but the simplest of games.
Thankfully, as time went by, most major web browsers started to implement the latest version of the HTML and CSS standards: HTML5 and CSS3. At the same time, they greatly improved the runtime performance of JavaScript applications. Nowadays, the most recent versions of modern browsers such as Mozilla Firefox, Apple Safari, Google Chrome, Opera, and Microsoft Internet Explorer 9as well as the browsers included in smart devices such as the iPhone, Blackberry phones, and WebOS-based and Android- based phoneshave already implemented most of the technologies that we need in order to develop a full-featured video game.
What You Need to Know
This book doesnt provide a definitive guide to HTML5, CSS3, or JavaScript. It assumes that you have at least a basic knowledge of how to work with all of those languages. Instead, throughout the different sections of this book, we discuss how to apply these technologies in the most performance-efficient way so that you can develop and launch a game that works today in any smartphone, tablet, or PC with a web browser that supports HTML5.
This book is intended for web developers trying to do game development or for game developers trying to adapt their knowledge to web development.
Our main approach for the development of an isometric social real-time strategy game will be to aim at the lowest common denominator: mobile devices. The rationale for this approach is that if it works on a mobile device at a decent speed, it will also work on more high-end devices such as personal computers.
Code Examples
All of the code and other supporting files for examples in this book are available at https://github.com/andrespagella/Making-Isometric-Real-time-Games.