Cross Over To HTML5 Game Development: Use Your Programming Experience To Create Mobile Games 1st Edition Zarrar Chishti (Auth.)
Cross Over To HTML5 Game Development: Use Your Programming Experience To Create Mobile Games 1st Edition Zarrar Chishti (Auth.)
com
https://textbookfull.com/product/cross-over-to-
html5-game-development-use-your-programming-
experience-to-create-mobile-games-1st-edition-
zarrar-chishti-auth/
Pro HTML5 Games. Learn to build your own Games using HTML5
and JavaScript Aditya Ravi Shankar
https://textbookfull.com/product/pro-html5-games-learn-to-build-your-
own-games-using-html5-and-javascript-aditya-ravi-shankar/
textbookfull.com
https://textbookfull.com/product/create-computer-games-design-and-
build-your-own-game-patrick-mccabe/
textbookfull.com
https://textbookfull.com/product/global-journalism-in-comparative-
perspective-1st-edition-dhiman-chattopadhyay/
textbookfull.com
Basic Concepts Of Inorganic Chemistry 2nd Edition D.N.
Singh
https://textbookfull.com/product/basic-concepts-of-inorganic-
chemistry-2nd-edition-d-n-singh/
textbookfull.com
https://textbookfull.com/product/the-braganzas-the-rise-and-fall-of-
the-ruling-dynasties-of-portugal-and-brazil-1640-1910-malyn-newitt/
textbookfull.com
https://textbookfull.com/product/pro-d3-js-use-d3-js-to-create-
maintainable-modular-and-testable-charts-marcos-iglesias/
textbookfull.com
https://textbookfull.com/product/philosophy-and-the-patience-of-film-
in-cavell-and-nancy-1st-edition-daniele-rugo-auth/
textbookfull.com
https://textbookfull.com/product/ruined-1st-edition-anders/
textbookfull.com
From Aspirin to Viagra Stories of the Drugs that Changed
the World Vladimir Marko
https://textbookfull.com/product/from-aspirin-to-viagra-stories-of-
the-drugs-that-changed-the-world-vladimir-marko/
textbookfull.com
Cross Over to
HTML5 Game
Development
Use Your Programming Experience to
Create Mobile Games
—
Zarrar Chishti
Cross Over to HTML5
Game Development
Use Your Programming
Experience to Create
Mobile Games
Zarrar Chishti
Cross Over to HTML5 Game Development: Use Your Programming
Experience to Create Mobile Games
Zarrar Chishti
Glasgow, United Kingdom
Chapter 1: Introduction������������������������������������������������������������������������1
Introducing Our Game: Space Zombies������������������������������������������������������1
Setting up Your Work Environment�������������������������������������������������������������4
Part 1: Setting up Our Folders������������������������������������������������������������������������������������� 4
Part 2: Setting up Our Files������������������������������������������������������������������������������������������ 6
iii
Table of Contents
iv
Table of Contents
Zombie Down!����������������������������������������������������������������������������������������119
Part 1: Create Six Bubble Zombie Elements������������������������������������������������������������ 120
Part 2: Activate the Counter Bubble Zombie������������������������������������������������������������ 129
Part 3: Animate the Bubble Zombies����������������������������������������������������������������������� 136
Index�������������������������������������������������������������������������������������������������247
v
About the Author
Zarrar Chishti is a software and games
development consultant with over 500 games
developed for companies around the world. He
is sought after to advise on the development
of viral games for major marketing campaigns.
His consultancy and development firm include
prestigious companies such as Turner Media,
British Airways and Channel 4 among the
many clients that keep coming back when a
new product or service is being launched.
After graduating from Glasgow University
in 1996 with a prestigious joint honors degree in Software Engineering,
Zarrar contracted as a software developer in both London and L.A. for 5
years. In 2001 he opened his own software firm in Glasgow and within 2
years was employing 10 staff. This was to grow to 30 in 2005 when he began
to offer games development to his clients.
One of the most notable game projects Zarrar has produced includes
an interactive comic for the popular Ben 10 TV series. The project was a
notable success that took his firm 10 months to deliver. It was rolled out
in over 25 countries in localized language editions. Other projects include
building a series of games for the ever popular Big Brother TV franchise
and an employee training game for Legal and General.
vii
About the Technical Reviewer
Massimo Nardone has more than 22 years
of experiences in security, web/mobile
development, and cloud and IT architecture.
His true IT passions are security and Android.
He has programmed and taught how to
program with Android, Perl, PHP, Java, VB,
Python, C/C++ and MySQL for more than 20
years.
He holds a master’s degree in computing
science from the University of Salerno, Italy.
He has worked as a project manager, software engineer, research
engineer, chief security architect, information security manager, PCI/SCADA
auditor and senior lead IT security/cloud/SCADA architect for many years.
His technical skills include security, Android, cloud, Java, MySQL,
Drupal, Cobol, Perl, web and mobile development, MongoDB, D3, Joomla,
Couchbase, C/C++, WebGL, Python, Pro Rails, Django CMS, Jekyll,
Scratch, and more.
He currently works as chief information security office (CISO) for
Cargotec Oyj.
He worked as visiting lecturer and supervisor for exercises at the
Networking Laboratory of the Helsinki University of Technology (Aalto
University). He holds four international patents (PKI, SIP, SAML, and Proxy
areas).
Massimo has reviewed more than 40 IT books for various publishing
companies. He is the coauthor of Pro Android Games (Apress, 2015).
ix
Acknowledgments
To Pops - you were an amazing dad who has left a massive hole in our lives.
To my closest friend, who has been (and continues to be) there for me
at the times when it matters the most: my brother Ibrar. Thank you to my
parents, who gave me the most amazing education and start to life. My one
constant and partner in crime, my wife Sadia. My son, whom I am so proud
of (incidentally, he was my initial editor for the book) and my “janno-jaan”
daughters: Sara, Aisha, and Rushda. I would be in a tremendous amount
of trouble if I did not also acknowledge Bella, our Bengal cat.
I would like to say a heartfelt thank you to my agent, Carole. You agreed
to represent me, despite my thick Scottish accent! Your guidance and
patience at the start will always be remembered and appreciated. Also,
thank you to the awesome and gorgeous team at Apress: Aaron and Jessica.
I had a great time working with you both and you made this “noob” feel
like part of the team.
I want to thank two people who have inspired me to write books. My
Latin teacher Mr. Temperely and my favorite author of all time, David Blixt.
I would also like send my love and appreciation to all my staff, both past
and present: Alasdair, George, Paul (the Great), Les, and Claire. Also, my
thanks to those clients that gave me my initial start despite having little or
no experience.
Finally, I would like to thank the nurses and doctors at Monklands
Haematology department who looked after my wife, Sadia. I will always
remember your commitment, passion, and support that you gave to her.
Thank you for sending her home to us.
xi
Preface
Welcome to the wonderful world of HTML5 game development. Are you
looking for a new challenge or looking to expand your current skill set?
Then get ready to start your journey. This book has been written with a
simple goal in mind: to provide the means for anyone to develop their first
HTML5 game.
This is a great time to break into the most lucrative game development
platform in the world. The global demand for the HTML5 game
development platform has expanded so quickly that it is currently crying
out for seasoned developers from more traditional environments to
cross over. Never before has there been such a widely accepted platform
by literally every manufacturer and operating system. This, in turn,
has convinced marketing departments to move away from traditional
platforms, such as dedicated mobile apps, for the more widely accepted
HTML5 format.
In short, there has never been a better time for a seasoned IT
programmer to cross over and capitalize in this lucrative market with their
much sought-after talents and experience.
I have spent the last five years training developers from a wide range
of programming disciplines to cross-train in HTML5 game development.
Whatever your vocation, whether it be an application databases systems
developer or a professional web developer, with this book you will learn to
evolve your current coding skills to enable you to become eligible for the
biggest gaming platform in the world.
From the first chapter, you immediately see encouraging results as
you power through a challenging and fun project that has been uniquely
designed and developed for this book.
xiii
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Preface
You can build this game using the computer/laptop that you already
have—as long as it switches on and you can run the already installed
Notepad program (if you are using Windows) or TextEdit (if you are on an
Apple Mac).
xiv
Preface
In this section, you will see the actual code that will need to be written. It is
important to ensure that you copy the code exactly as it is written.
On most occasions, you will only need to write the lines that are
written in bold. Also, the lines of code that existed before but have just
been modified are in red.
xv
Preface
In this section, you will see interesting facts and explanations of the code
that has just been written. If you wish to build on your coding knowledge
as you proceed, then you will find a great source of information here.
However, feel free to ignore this section if you just want to get on with
building your game.
Did something go wrong? Did the code you just wrote not work? Not to
worry. You will find common (and some not so common) mistakes here
with solutions on how to fix them.
xvi
CHAPTER 1
Introduction
“If you have a garden and a library,
you have everything you need.”
Marcus Tullius Cicero
(106 BC – 43 BC)
I have been developing software since 1996 and I have developed games
for small and large companies for over a decade now. Like any form of
development in the real world, you need to know why you are building
the game before you think of coding strategies and build processes. In the
gaming world, this comes in the form of the game’s story. This includes the
background, reasons to play, and the goals of the game.
Let’s have a look at a few of the graphics that we will use for the
development.
2
Chapter 1 Introduction
3
Chapter 1 Introduction
4
Chapter 1 Introduction
Once you have your root folder, the next step is to create the subfolders
that you will need for the game. Create four folders inside My_Work_Files.
Name the folders as follows:
• CSS
• Images
• Raw Images
• js
The CSS folder will hold special code files that help structure the design of
the game. All the files in this folder will end in .css.
The js folder will hold all of our JavaScript files, which will form the
engine for our game. They will contain commands and instructions that will
control what happens in our game. All the files in this folder will end in .js.
5
Chapter 1 Introduction
The Images folder, as the name suggests, will contain all the image or
media files that we will need for the game.
The Raw Images folder will not technically be used for raw images. In
our case, we will use this folder as special temporary housing for all of our
media. We will move them into the Images folder when we need them.
Although using an IDE has its benefits, I think that it is worth keeping
in mind this excellent quote about using IDEs for multiple languages:
“Although many IDEs can handle more than one language, few do it
well. Plus, it’s likely overkill if you are just getting started.”
Now that the folders are set up, let’s create the files that you will use to
develop the game.
First, you need to create a default.html file. If you are using an IDE,
click File ➤ Create New and select HTML. If you are using Notepad, open a
new file and save it as default.html.
Your folder should now look like this:
7
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 1 Introduction
Finally, we need to create a file within the CSS folder. Repeat the steps
from earlier (i.e., create a New File and then Save As). The file name to
enter is
> SZ_master.css.
8
Chapter 1 Introduction
9
Chapter 1 Introduction
Dedicated Server
This is the most expensive option. Essentially, you own the computer that
is connected to the Internet. This is only an option if you are either a huge
company or a reseller.
10
Chapter 1 Introduction
Shared Server
This is generally the most economical option for hosting. It is very much
for people like you, who are renting a piece of the server. The main
advantage is the ridiculously low cost, of course. However, as your game
development expertise increases, you may find this option to be limiting
and unfit for your specific needs.
Cloud Hosting
Whereas the prior two options rely on one physical computer, cloud
hosting allows an unlimited number of computers to act as one system.
http://zarrarchishtiauthor.com/downloads/
Click the Download button. This will initiate a download. The browser
will let you know when it has completed. Navigate to your download folder
and locate the downloaded file.
It should be a file called raw_media_1.rar. Now you need to extract the
files from this zipped file in a new folder called Raw Media. Double-click
this folder and you will see the following four folders:
• > Images
• > JS
• > sounds
• > html_web
11
Chapter 1 Introduction
First, copy all four folders to your Raw Images folder, which is in the
My_Work_Files folder.
At this stage, we are only interested in the files inside the JS folder. As
we progress through the game, we will go back to the other folders and
copy the files as needed. Double-click the JS folder (in the Raw Images
folder). Using the same technique as before to copy files, go ahead and
copy all the files, and then paste them into your own js folder (in the My_
Work_Files folder).
Your js folder (in the My_Work_Files folder) should now look like this:
12
Random documents with unrelated
content Scribd suggests to you:
T ake of that gold calx (which was precipitated with the oyl of
sand) one part, and three or four parts of the liquor of crystals
or of sand, mix the gold calx in a good crucible with the liquor, and
set this mixture into a gentle heat, so that the moystness may
evaporate from the oyl of sand which is not easily done; for the
peble or sand, by reason of their dryness keep and hold the
moystness, and will not let it go easily; it riseth in the pot or
crucible, as borax or Allome doth when you calcine them; therefore
the crucible, must not be filled above half, that the liquor together
with the gold may have room enough, and do not run over the pot:
and when it riseth no more, then strengthen the fire, till the pot be
red-hot. The mixture standing fast, put a lid upon it, which may
close well, that no coals, ashes, or other impurity may fall into it,
and give it so strong fire in a winde furnace, that the liquor together
with the gold calx may melt like water; keep it melting so long, till
the liquor and gold together be like unto a transparent fair ruby,
which will be done in an hours time or thereabouts; then pour it
forth into a clean copper morter, let it cool, and then make it into
powder, and pour spirit of wine upon it for to extract, which will look
like unto thin blood: and will prove more effectual in use, than the
above described Tincture.
The residue from which the Tincture is extracted, must be boyled
with lead, and precipitated and driven off as you do oares, and you
will get the remaining gold, which went not into the spirit of wine;
but it is very pale and turned like unto silver in colour, which if it be
melted by Antimony, it recovereth its former colour without any
considerable loss in the weight. How the melting in crucibles, and
boyling of the remaining gold is to be done, shall be more punctually
set down in the fourth part; I know several other fine processes, for
to extract the colour easily out of gold; but because the gold must
be first made fit for it by melting in a crucible, and that it is not
pertinent to speak of that operation here in this second part,
therefore it shall be reserved for the fourth, where you shall be
informed at large, not onely how to prepare Gold, Antimony and
other minerals, and make them fit for extraction, but also how to
reduce them into a transparent, soluble and fire-proof Ruby (which
are none of the meanest medicines) and as it was done here with
the gold, so you may proceed likewise with other metals and
minerals for to extract their colours. And therefore being needless to
describe each metals tincture by it self, all the processes of them
shall be disclosed in one, viz. in that of gold. The book would grow
too big, if I should describe them severally, which I count needless
to do. Let this suffice for this Second part, that we have taught, how
to extract out of the gold its colour after a common way. Which
indeed are good medicines, but for ought I know of no use in
Alchymy. But he that seeketh to have a true Tincture out of gold, let
him endeavour first to destroy the gold by the universal Mercury,
and to turn the inside outward, and the outside inward, and proceed
further according unto art, then the soul of gold will easily joyn it
self with the spirit of wine, and come to be a good medicine,
whereof more in my treatise de auro potabili is handled. If one know
the Chalybs of Sandivogius, which is well to be had, he might with
little labour quickly get a good medicine: but because we shew our
selves still ungrateful children unto God, therefore it is no marvel,
that he withdraweth his hand from us, and leaveth us in errors.
To distill a blood red oyl of vitriol by the help of the spirit of urin.
Vitriol of copper.
I f you take common crude tartar, and pour of this spirit upon it,
and set it in digestion, the spirit will extract a blood-red tincture,
and if the spirit be abstracted from it, there will remain a pleasant
red oyl, of no small vertue and power.
T his spirit also dissolveth crystals and other stones, they being
first dissolved, precipitated and reduced to impalpable
powders, turning them into oyles and liquors, good to be used in
Alchymy and Physick.
I f you dissolve silver in Aqua fortis, and pour so much of this spirit
into it till it ceaseth to make a noise, some of the silver will
precipitate in the form of a black powder, the rest of the silver
remaineth in the liquor: the phlegm abstracted from it in Balneo, till
it get a skin at the top, and then set into a cool place, there will
grow white crystals in it, which being taken out and dryed are a
good purge in madness, dropsie, feavers and other diseases, safely
and without danger to be used to young and old. The rest of the
liquor which did not crystallise may be extracted with spirit of wine,
and the fæces being cast away the extraction will be pleasanter. The
spirit of wine abstracted from it, there will remain a medicine of no
small value in all diseases of the brain.
A fter the same manner you may make spirits out of all kind of
horns and claws of beasts: but since by reason of their ill smel
the use of them is not liked of (though in several heavy diseases, as
in the fits of the mother and Epilepsie, they do admirably well:)
therefore I will acquiesce. However it is worth observing, that the
spirit made of mans hair is not to be rejected in metallical
operations, for it dissolveth common sulphur, and reduceth it into a
milk, which by further ripening may be turned into blood, the like
whereunto no spirit is able to do. The same spirit may also of it self,
without addition of sulphur be fixed into a ruby; but that which is
ripened with sulphur is the better; and if it be brought so far by the
fire, that it have lost its stink, and be made fixed than it will be able
sufficiently to pay for the pains and coals bestowed upon it.
N. B. Hither belongeth the Process to pour dissolved metals upon
filed hartshorn, and so to distil them.
B oyl the soot in common watter, till the water turn blood red (urin
is better than water) and set this solution (being in an earthen
pot) in winter time into the greatest frost so long till all in the pot be
frozen into one piece and turned white: then break the pot and the
ice, and in the midst thereof you will find the hot oyl unfrozen and
liquid in colour like blood, which is not much inferior in vertue unto
that which is distilled, yet afterward it may be rectified, and so
exalted in its vertue, when you please, and it is to be noted, that this
separation doeth only succeed in the greatest frost and cold, and not
else.
I f you mix sugar with red corals made into powder and distil it,
there will besides the spirit come over a blood-red tincture like a
heavy oyl, which is to be joyned with the spirit by digestion in
Balneo, and it will be as vertuous as that which was made with
Antimony diaphoreticum. It doth perfectly and lastingly cure the
epilepsie in young and old; it cleanseth the blood from all filth, so
that the Leprosie together with its several species may be cured
thereby, &c. Its use is the same as was taught above of the
Antimonized spirit of sugar.
Of oyl Olive.
I n the same manner may be distilled also the oyl of wax, the use
whereof is in all like unto the former; and for all cold infirmities
of the nerves, this is found more effectual yet than the former.
T hus I conclude this second part; I could have set down more
medicinal processes in this Treatise: but having as many as will
be a sufficient guide for the distilling of other things also, I thought
it good here to acquiesce; and whatsoever hath been here omitted,
shall be supplyed in the following parts.
F I N I S.
T H E
THIRD PART
O F
Philosophical Furnaces:
In which is described the Nature of the Third Furnace; by the help
whereof, and that without Stills, and Caldrons, and other
Copper, Iron, Tin, and Leaden Instruments, various Vegetable
burning Spirits, Extracts, Oyls, Salts, &c. by the help of a
certain little Copper Instrument, and Wooden Vessels are made
for Chymical and Medicinal Uses.
N
ow this Instrument is made of strong Copper plates after the
following manner. You must make two strong hemispheares
of Copper or Latten of the bigness of a mans head (or
thereabout) and join them together with a most strong soder, and
that without tin, whereof the one must have a pipe: Now the pipe
must be of a most exact roundness, that it may most accurately fit
the hole that is made with an auger or wimble to keep the water
from flowing out like to a tap, of the length of one span at least,
wider on the hinder part towards the globe, than on the forepart,
which also must be according to the bigness of the globe, greater or
lesser, and be exactly joined with the best soder to its hemisphear,
and the diameter of the forepart being very round like a tap, and
most exactly filling the round hole must be of two fingers breath.
Now there is required to the foresaid instrument or globe, a certain
peculiar little furnace made of iron or copper, viz. most strong copper
plates, covered within with stones or the best lute, into which is put
that globe like a retort, so that it may ly upon two iron bars of the
distance of a span, or span and half from the grate; the neck
whereof (that pipe) goeth forth of the furnace one span at least. The
furnace also must have below a place for the ashes, and above a
cover with its hole for the letting forth of the smoke, and for
regulating the fire, as you may see by the annexed figure. It must
also below have a treefoot, on which the furnace must be set, and
on the sides two handles by the help whereof it may be removed
from place to place; the which is very necessary; for it is not only
used for the distilling of burning spirits by wooden Vessels instead of
copper, but also for such distillation, and digestion that is performed
in gourds, bolt-heads, and other instruments of glass, stone, copper,
tin, &c. which are to be set in Balneo: also in the boyling of beer,
metheglin, wine, and other drinks, which are to be performed by the
help of wooden Vessels.
I
n the first place I shall speak of wooden Vessels that are to be
used instead of Copper stills, in the distilling of burning spirits
out of wine, beer, lees, malt, wheat, meal, roots, hearbs,
flowers, seeds, and other vegetables, as also oyls of vegetables.
See that thou hast an oken barrel, like to those wherein wine and
beer are kept, of a just bigness, viz. answerable to the bigness of
the globe, as is sufficient for the coction: for a barrel that is too big
will make the coction slow, and tedious. A greater globe may be
fitted to a lesser barrel, but not on the contrary, a great barrel to a
little globe: For by how much the bigger the globe is, and the less
the barrel, so much the sooner is the work hastned. Now seeing that
this Art was invented for the saving of costs, which otherwise would
have been expended in providing of stils, cauldrons, furnaces, &c. it
is best not to have too great a globe, which requires a greater
furnace, and is more hardly to be carryed, because it is to be
covered within with lute, or a wall; for it is sufficient if it be big
enough for the coction. Wherefore I will give you a just and due
proportion of both, viz. of the globe, and vessel, which in distillations
and other operations, the curteous reader may imitate.
A globe of the bigness of a mans head, containing three or four
cannes, whereof each containeth four pints, is sufficient for the
heating of a barrel of 30, 40, 50, 60. and 100 gallons, which by how
much the more remote from 100 and nearer to 30, so much the
sooner is it heated, and the coction furthered; and on the contrary,
by how much the nearer it is to 100 and more remote from 30, so
much the slower is the coction. I do not therefore advise that a huge
barrel be chosen for a small globe, by reason of a long and tedious
operation: And if all and every thing be not so accurately observed
to a hair, yet it matters not much, because it sufficeth to do the
same thing by the help of one small copper instrument of divers
forms. For in this way of distilling, wooden vessels that are requisite
to the distilling of spirits, and boyling of Bear, and for baths are more
easily provided, then so many copper vessels in the common way.
For by this means not only costs are spared, but also it is in stead of
building of furnaces, because when any barrel hath been used, you
may remove it, and set another in the place of it for another
operation, the which cannot be done with stills and cauldrons
fastened into a furnace. And this invention is for those that want
Artificers, as Coppersmiths, &c. because wooden instruments are
more easily provided: also by the help of this globe may most secret
operations be performed.
For the furnace with the copper globe may be built in one place,
and in another place the Balneum, viz. the places divided with a
wall, so that he that looks to the fire may not know what is done in
the Elaboratory; for oftentimes the care of the fire is committed to
heedless servants, that break glass instruments by their
carelesseness, by which means oftentimes a most pretious medicine
is lost; which danger this invention is without.
Wherefore this copper globe with its wooden vessels is more
convenient then those copper stills and cauldrons. But this I would
have thee know that this new invented distillation is slower, then the
common way which is performed by stills, and consequently requires
a long fire. I desire therefore the rich that dwell in large and
spacious houses, that they would use the old way of distilling; but
the poor, who have but little houshold conveniences, and the
covetous, that they would use this little copper globe with its
wooden vessels: for although there be a longer fire required, yet
these are not to be compared to those costs which are otherwise
expended upon so many copper vessels of so many divers forms. Let
him therefore keep to his copper vessels, who cannot understand
me, for it concernes not me. Without doubt there are some whom
this my new invented way of distilling will please, before other, being
communicated for the sake of the poor labouring house-keepers,
that cannot boyl Beer, and distill burning spirits for lack of vessels:
for a globe of five or four pound is more easily provided, then other
copper vessels of 60, 80, 100 pound: also those wooden vessels are
more easily provided than furnaces, which some for want of place
only cannot build. Choose therefore which way thou wilt, for these
things which I have wrote, I have wrote for the poors sake rather
than for the rich. Certainly rich men that have spacious Elaboratories
need not to be ashamed to follow this way, for it is free for every
man to go a shorter way, unless they had rather prefer the old way
before a new and compendious, whom I cannot help, being
contented with a publication which is made for the sake of my
neighbour, whether it be taken well or ill, with a good minde,
certainly knowing that more profit then disprofit may be obtained by
the help thereof. It shall not therefore repent him of his labor, who
knows rightly to prepare and use this copper, and wooden vessels.