Skip to main content

Cannonball and Slingshot

  • Chapter
The Essential Guide to HTML5
  • 1663 Accesses

Abstract

In this chapter, you learned how to create two ballistics applications. It is important to understand how they are the same and how they are different. The programming techniques and HTML5 features include

  • programmer-defined objects

  • setInterval to set up a timing event for the animation, as done for the bouncing ball

  • building an array using the push method and using the array as a list of what to display

  • modifying arrays using the splice method

  • the use of trig functions with calculations to rotate the cannon and to resolve the horizontal and vertical velocities so as to simulate gravity

  • using a form for player input

  • handling mouse events (mousedown, mousemove, mouseup), with addEventListener to obtain player input

  • move drawing arcs, rectangles, lines and images on a canvas

The technique of programmer-defined objects and the use of an array of objects to display will come up again in later chapters. The next chapter focuses on a familiar game known as either memory or concentration. It will use a different timing event as well as the Date function, introduced in Chapter 1.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 34.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2010 by Jeanine Meyer

About this chapter

Cite this chapter

Meyer, J. (2010). Cannonball and Slingshot. In: The Essential Guide to HTML5. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4302-3384-8_4

Download citation

Publish with us

Policies and ethics