Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
jQuery Game Development Essentials
jQuery Game Development Essentials

jQuery Game Development Essentials: Learn how to make fun and addictive multi-platform games using jQuery with this book and ebook.

eBook
AU$14.99 AU$53.99
Paperback
AU$67.99
Subscription
Free Trial
Renews at AU$24.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

jQuery Game Development Essentials

Chapter 2. Creating Our First Game

If you lay your eyes on an electronic device, chances are that there is a browser running on it! You probably have more than one installed on each of your PCs and some more running on your portable devices. If you want to distribute your games to a wide audience for a minimal cost of entry, making it run in the browser makes a lot of sense.

Flash was for a long time the go-to platform for games in browsers, but it has been losing speed in the last few years. There are many reasons for this and there have been countless arguments about whether this is a good thing or not. There is, however, a consensus on the fact that you can now make games run in the browser without plugins at a reasonable speed.

This book will focus on 2D games as they are the ones that run well on current browsers and the features they depend on are standardized. This means that an update of the browser shouldn't break your games and that for the most part you don't have to worry too much...

How does this book work?


Making games has this amazing advantage that you immediately see the result of the code you just wrote move before your eyes. This is the reason why everything you learn in this book will directly be applied to some practical examples. In this chapter, we will write a small game together inspired by the classic Frogger. In the following chapters, we will then make a platformer and a role playing game (RPG).

I really encourage you to write your own version of the games presented here and modify the code provided to see the effects it has. There is no better way of learning than to get your hands dirty!

Let's get serious – the game


The game we will implement now is inspired by Frogger. In this old school arcade game, you played the role of a frog trying to cross the screen by jumping on logs and avoiding cars.

In our version, the player is a developer who has to cross the network cable by jumping packets and then cross the browser "road" by avoiding bugs. To sum up, the game specifications are as follows:

  • If the player presses the up arrow key once, the "frog" will go forward one step.

  • By pressing the right and left arrow key, the player can move horizontally.

  • In the first part (the network cable) the player has to jump on packets coming from the left of the screen and moving to the right. The packets are organized in lines where packets of each line travel at different speeds. Once the player is on a packet, he/she will move along with it. If a packet drives the player outside of the screen, or if the player jumps on the cable without reaching a packet, he/she will die and start at the beginning...

Learning the basics


Throughout this book, we will use DOM elements to render game elements. Another popular solution would be to use the Canvas element. There are plus and minus points for both technologies and there are a few effects that are simply not possible to produce with only DOM elements.

However, for the beginner, the DOM offers the advantage of being easier to debug, to work on almost all existing browsers (yes, even on Internet Explorer 6), and in most cases to offer reasonable speed for games. The DOM also abstracts the dirty business of having to target individual pixels and tracking which part of the screen has to be redrawn.

Even though Internet Explorer supports most of the features we will see in this book, I would not recommend creating a game that supports it. Indeed, its market share is negligible nowadays (http://www.ie6countdown.com/) and you will encounter some performance issues.

Now from some game terminology, sprites are the moving part of a game. They may be animated...

Initializing the game


The framework part of the game is done. Now we want to implement the graphics and game logic. We can divide the game's code into two parts, one that will be executed only once at the beginning, and one that will be called periodically. We will call the first one the initialization.

This part should be executed as soon as the images are done loading; this is the reason why we will pass it as the end callback for the startPreloading function. This means that at the very beginning we need to add all the images that we will use to the preload list. Then once the user launches the game (for example, by clicking an image with the ID startButton) we will call the preloader.

The following code uses the standard jQuery way to execute a function once the page is ready. I won't give you the complete code here because some of it is quite repetitive, but I will give at least one example of each of the actions performed here and you can always look at the complete source code if you...

Main loop


The main loop will typically contain a finite state machine (FSM). An FSM is defined by a series of states and the list of transitions from one state to another. The FSM for a simple game where the player would have to click three boxes that appear one after the other would look like the following diagram:

When you implement an FSM, you really need to consider two things: how the game should behave in each state, and what conditions make the game transition to a new state. The advantage of FSMs is that they provide a formal way to organize your game logic. It will make it easier to read your code and you can add/or change your logic at a later time if you need it. I would recommend you to first draw the FSM for your game and keep it somewhere to help you debug your game.

For our Frogger game there are 10 states. The initial state is START and the two final states are GAMEOVER and WON. Here is a description of what happens exactly in each state:

  • All states: The packets and bugs move...

Collision detection


We will use some sort of collision detection, but a very simple version that is designed only for this situation. In the later chapters, we will see more general solutions, but this isn't necessary here.

There are six spots where collision detection matters in this game; the three lines of packets in the first part, and the three lines of bugs in the second part. Both represent the exact same situation. There is a succession of elements separated by some empty space. The distance between each element is constant along with its size. We don't need to know on which packet the player has jumped or which bugs hit the player, what matters is only if the player stands on a packet or if he/she was hit by a bug.

For this reason we will use the modulo technique we used before to reduce the problem complexity. What we will consider is the following situation:

To know if the player touches the element or not we just need to compare its x co-ordinate with the element position.

The following...

Summary


We now have a game that completely implements the specification that we defined at the beginning of the chapter. The code is not yet optimized and that will be the subject of our next chapter, but to make a game that is nice to play it would really need more polish. You could add a high-score system, integration with social networks, and sound and touch device compatibility.

We will cover those topics and more in the future chapters. However, there are a lot of things you can do with what you have already learned now to make the game better: you may want to add an animation for when the player dies, a nicer GUI, nicer graphics, the ability to jump back, and more than one level. It's these small things that will make your game stand out and you should really invest a big part of your time to give this professional finish to your game!

Left arrow icon Right arrow icon

Key benefits

  • Discover how you can create a fantastic RPG, arcade game, or platformer using jQuery!
  • Learn how you can integrate your game with various social networks, creating multiplayer experiences and also ensuring compatibility with mobile devices.
  • Create your very own framework, harnessing the very best design patterns and proven techniques along the way.
  • The updated code files can be found here

Description

jQuery is a leading multi-browser JavaScript library that developers across the world utilize on a daily basis to help simplify client-side scripting. Using the friendly and powerful jQuery to create games based on DOM manipulations and CSS transforms allows you to target a vast array of browsers and devices without having to worry about individual peculiarities."jQuery Game Development Essentials" will teach you how to use the environment, language, and framework that you're familiar with in an entirely new way so that you can create beautiful and addictive games. With concrete examples and detailed technical explanations you will learn how to apply game development techniques in a highly practical context.This essential reference explains classic game development techniques like sprite animations, tile-maps, collision detection, and parallax scrolling in a context specific to jQuery. In addition, there is coverage of advanced topics specific to creating games with the popular JavaScript library, such as integration with social networks alongside multiplayer and mobile support. jQuery Game Development Essentials will take you on a journey that will utilize your existing skills as a web developer so that you can create fantastic, addictive games that run right in the browser.

Who is this book for?

Knowledge of JavaScript and jQuery as well as basic experience with frontend development is all you need to start making games in a matter of hours with this essential guide. Whilst also suitable for those who simply want to start making games with jQuery, it's specifically targeted at web developers that want to experiment with and utilize their existing skills.

What you will learn

  • Create sprite-based, multi-platform games using the latest web standards and jQuery
  • Use powerful techniques directly from the games industry to make your own games harness stunning visual effects without compromising on performance
  • Learn how you can develop real-time multiplayer games and integrate them with social networks
  • Overcome the limitations of mobile browsers allowing you to take full advantage of their various features with minimum hassle
  • Develop a platformer, an arcade game, or even your very own RPG with jQuery at the core
  • Discover how you can easily implement features like parallax scrolling
  • Utilize your existing skills in jQuery in a fun and exciting new context

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 25, 2013
Length: 244 pages
Edition : 1st
Language : English
ISBN-13 : 9781849695077
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 25, 2013
Length: 244 pages
Edition : 1st
Language : English
ISBN-13 : 9781849695077
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
AU$249.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts
AU$349.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 128.98
Learning jQuery - Fourth Edition
AU$60.99
jQuery Game Development Essentials
AU$67.99
Total AU$ 128.98 Stars icon
Banner background image

Table of Contents

10 Chapters
jQuery for Games Chevron down icon Chevron up icon
Creating Our First Game Chevron down icon Chevron up icon
Better, Faster, but not Harder Chevron down icon Chevron up icon
Looking Sideways Chevron down icon Chevron up icon
Putting Things into Perspective Chevron down icon Chevron up icon
Adding Levels to Your Games Chevron down icon Chevron up icon
Making a Multiplayer Game Chevron down icon Chevron up icon
Let's Get Social Chevron down icon Chevron up icon
Making Your Game Mobile Chevron down icon Chevron up icon
Making Some Noise Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(11 Ratings)
5 star 45.5%
4 star 36.4%
3 star 18.2%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Marin Nikolovski May 21, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I think that "jQuery Game Development Essentials" is an excellent book, because it gives its readers a lot of information how to create games with jQuery and JavaScript. The topics in this book are well chosen and cover a lot of game development techniques that are needed for creating a single-player and multiplayer games and integrating them with social networks like Twitter and Facebook.The book is divided into several chapters and by reading them the readers will learn:* about the general principles and design patterns that are used for video game development;* how to create a single-player platformer;* how to extend the single-player code in order to create a multiplayer game;* how to optimize the code, so that the games that are developed can utilize the resources that are available to them to the maximum;* how to protect the developed game from hacking;* how to integrate the developed games with Twitter and Facebook.Each chapter is written in a clear way and begins with an introduction of the goal that should be achieved, followed by a detailed tutorial of how it can be achieved, ending with a conclusion that describes what was done in the chapter. Each tutorial contains step-by-step explanations, followed by a sample code. They are also accompanied by links to useful articles or references to other books that the readers can use in order to broaden their knowledge.Although I'm mostly pleased with this book, I have some remarks about it:* The book only gives a short introduction into jQuery and JavaScript - the book is filled with a lot of sample codes and, in order to analyze them successfully, you need to have a solid knowledge of jQuery and JavaScript. However, this is not a very big problem, because the author pinpoints some external articles and books that can help the readers to learn everything they need to know about them.* The step-by-step explanations that are given in the book are general and are not enough to develop a game (the author is missing some of the steps). But, this is not a very big problem, because the book comes with sample projects that the readers can analyze and debug, so that they can observe in real-time what is actually happening.I recommend this book to anyone who is planning to, or is already doing game development. It is full of content and you can learn a lot from it. The author gives his best to cover as much topics as possible and make the readers more familiar with the crucial design patterns that are used in game development. The best part of reading this book is the fact that the explanations that are given in it are general, so they can be reused in the other programming languages as well. I have been developing games for several years and I found this book very useful. Definitely worth buying it!
Amazon Verified review Amazon
mmoDust May 28, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book starts off with the following: "Writing games is not only fun but also a very good way to learn a technology through and through" and I could not agree more.I have been programming for 30+ years and at this point I want to try and future proof my knowledge by learning what looks to be very important to our future HTML and JS and jQuery is designed to make this much easier and efficient. I ran into this book while searching for HTML Game programming info and it seemed like it would be a great way to leverage jQuery for Game Creation and learn a bit on how HTML Games work in general and this book did not disappoint.From the beginning this book covers it all from the basics of what jQuery can do for you in Game Development down to how Audio works and extra ways to make things just work for your audience. The author also includes handy links to other references for more information on how to continue your learning which I thought was very helpful.The writing style is very friendly and it feels as if the author is there with you helping you learn rather than a dry instructional book. The code style is snippets of functional code and not complete start to end of each function which helps to keep the book focused on what you are learning for that chapter. The entire code is included as a download with the book so I never ran into an issue if I needed more information.This is a review of the eBook version and if you have the choice I would go with the ePub format as it is formatted very well with great use of color to keep things formatted for easy reading.
Amazon Verified review Amazon
MzEdd Apr 10, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very readable. Straight to the meat of js games in bite size chunks. All code emailed to you on request as promised in the book.
Amazon Verified review Amazon
A.R.S. Sep 14, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I'm a basic-intermediate programmer of jquery, and what I liked of this book is that, in addition to teaching the topics it states, it teaches you how a professional programs. Other jquery books usually give the general theory of the language, but this book explains efficient ways to program and explains many particular aspects of javascript and jquery. It is an expert programmer explaining you how you should program and why.The book has some editing issues, but they are not important for you to take advantage of all that it offers.
Amazon Verified review Amazon
Thriving Panda May 22, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I did a review on my blog at grimpanda.com, but I thought I would share it here as well, so I copied/pasted the most relevant bits. I loved this book!In the preface, the author asserts that the book is recommended for beginners of web development who have at least some knowledge in Javascript/jQuery. While this is certainly true, let me be the first to say that it's usefulness extends far beyond the new developer. If you can sit down at your keyboard and write a fully featured jQuery multiplayer mobile/browser game without needing any assistance, this book isn't for you. If, on the other hand, you are weak in any area ranging from jQuery utilization, building your own game engine frameworks, server code for efficient multiplayer game features, utilizing social networking effectively in your game or launching all of this onto a mobile device, then this book *is* for you.StructureToo often I pick up a book and get a couple chapters in only to realize that they pulled out all of the stops right at the beginning and then ran out of air. Even more common are books that present information in fragments that are difficult to implement in any meaningful way. In the end, the reader is left with another space on the bookshelf filled with a nothing more than a very poor, overly-worded reference.Not so with jQuery Game Development Essentials. Selim Arsever, the books author, leads the reader carefully down a path of understanding and knowledge gathering. Arsever begins by familiarizing the reader with critical concepts, before moving easily into an approachable but powerful game example. The simple, single screen game, teaches the programmer important cornerstones such as collision detection, game states, and input calculation; A foundation the reader can build upon solidly while continuing the journey forwards to more developing more robust skills.LanguageThroughout the publication, Arsever keeps the reader engaged by using easy to read, simple language. While your skillset and understanding will continue to ramp up as you progress through the chapters, the difficulty does not. Again, this is due in large part to the books meticulous ability of explaining the foundation before moving on to the more advanced sections.That is probably my favorite feature of this book. Pretty often I am able to follow books in this category in the beginning. Inevitably however, I end up getting mired down in the language as the text progresses. Usually, I end up just pasting code and giving up on reading the chapters explaining it. This leaves me feeling unsatisfied and well... a little sad! Not so in this book! I was able to read through each and every chapter as if it were the first. I really can't stress my happiness with this major detail.Building BlocksAs I've already mentioned, the book carefully leads the reader from concept to concept in text, and mirrors that growth in the actual coding. There is no useless information in this book. No fluff code, or stupid games that teach nothing. Each page is designed to progress you that much further in your journey down this awesome road.While not strictly so, the layout sort of follows a "learn it, build it, improve it" workflow. Arsever will introduce key concepts, discuss them in an intuitive manner, then have you working with relevant code. Only after introducing the simplest possible answer to a problem will the reader then move on to make it more robust. In this manner, it is very easy to take in the information in a modular method.After you have a decent working prototype, he will usually spend quite a bit making sure that we can take the basics to something modern and exciting. Anything from integrating social networking into your game to allowing your new game to respond to user touch!TLCHere's another aspect of the book that really drew me in. There are many times throughout the publication that Arsever takes time to `care'. I say `care' because he obviously spent a great deal of time thinking about YOU the reader. He doesn't just shove directions down your throat, but takes the time to inform you what tools are available for the upcoming tasks. He understands that not everyone can afford the most expensive tools, so wherever possible he links us to open source and freely available alternatives.On top of that, he points points out whenever possible, areas that might need additional attention. For example, he knows that social website API's change often, and instead of simply leaving you with some code that may not work over time, he explains how you can stay up to date in the future. These little things really impress me. I don't feel like I was taken for a quick buck or two and left hanging. I feel more like I'm being taught and privileged enough to learn from the best.Wrapping UpIn jQuery Game Development Essentials you will move from a single screen web game to a multiplayer RPG to distributing your creations across mobile networks. It not only promises this, but does so in spades. Selim Arsever gets you from 0 to 60, no, 0 to 100 in red carpet fashion. He shrugs off the pitfalls of other books in the genre without issue. It's easy enough to follow from cover to cover, that if you are a complete beginner you will have no trouble. It's feature packed enough that even a seasoned programmer will find more than enough helpful information to take their experience and knowledge to the next level.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.