3D Game Programming

(C. Jardin) #1

CHAPTER 17


Project: Learning about JavaScript Objects


We’ve made some pretty incredible progress so far. We have an avatar that
can walk around the screen and bump into obstacles. We built an animated
model of the solar system and a simulation of the moon’s movements. We
also tried out our new skills to create a couple of pretty cool games.

We’ve made so much progress, in fact, that we’ve reached the limit of what
we can do with JavaScript—at least without introducing something new. To
understand why we need to learn about this new concept, consider our avatar.
We can make plenty of games where our avatar could play by itself, but what
if the player wanted to play with others?

If two players were to be on the screen at the same time, how would we add
all those hands, feet, and bodies to the screen and not mix them up? How
would we make each one move independently? How would we assign different
colors and shapes to each avatar?

Things quickly get out of control if we try to accomplish all these things with
what we know so far. So it’s time to learn about objects and see what we can
do with them.

This Is a Challenging Chapter

There are a lot of new concepts in this chapter. You may find it best
to skim through the first time and then come back in more depth
later.

18.1 Getting Started


Create a new project in the ICE Code Editor. For this exercise, let’s use the
3D starter project template and call it Objects.

When you’re done with this chapter, you will


  • Know what that new keyword we keep
    using means

  • Be able to define your own objects

  • Know how to copy objects


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf