1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var sprites
= (function() {
12 sprites
.init = function(w
, h
) {
17 sprites
.add = function(img
) {
19 x
: Math
.random() * (width
- img
.width
),
20 y
: Math
.random() * (height
- img
.height
),
21 dx
: SPRITE_SPEED
* (Math
.random() < .5 ? -1 : 1),
22 dy
: SPRITE_SPEED
* (Math
.random() < .5 ? -1 : 1) };
25 sprites
.draw = function(context
) {
26 for (var i
= 0, len
= objs
.length
; i
< len
; ++i
) {
30 if ((obj
.x
> (width
- obj
.img
.width
)) || (obj
.x
< 0))
34 if ((obj
.y
> (height
- obj
.img
.height
)) || (obj
.y
< 0))
37 context
.drawImage(obj
.img
, obj
.x
, obj
.y
);