topical media & game development

talk show tell print

mobile-game-ch17-cannon.htm / htm



  <!DOCTYPE HTML>
  <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Simple Cannon example</title>
      <script src='mobile-game-ch17-js-jquery.min.js'></script>
      <script src='mobile-game-ch17-js-underscore.js'></script>
      <script src='mobile-game-ch17-js-quintus.js'></script>
      <script src='mobile-game-ch17-js-quintus-sprites.js'></script>
    </head>
    <body>
      <script>
       var Q = Quintus().include("Sprites").setup()
  
       Q.load(['mobile-game-ch17-images-cannonball.png','mobile-game-ch17-images-cannonball2.png'],function() {
  
         var ball1 = new Q.Sprite({
           asset: 'mobile-game-ch17-images-cannonball.png',
           x0:    0,  // Initial X position
           vx0:  20,  // X velocity
           ax:    0,  // X acceleration
           y0:  380,  // Initial Y position
           vy0:-100,  // Y Velocity
           ay:   20,  // Constant Y acceleration
           t:     0   // Starting time
         });
  
         ball1.step = function(dt) {
           var p = this.p;
           p.t += dt;
  
           p.x = p.x0 + p.vx0 * p.t + 0.5 * p.ax * (p.t * p.t);
           p.y = p.y0 + p.vy0 * p.t + 0.5 * p.ay * (p.t * p.t);
         }
  
        Q.gameLoop(function(dt) {
          Q.clear(); 
  
          ball1.step(dt);
          ball1.draw(Q.ctx);
        });
  
      });
  
      </script>
    </body>
  </html>
  
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.