-
Notifications
You must be signed in to change notification settings - Fork 1
/
bullet02.html
64 lines (61 loc) · 2.08 KB
/
bullet02.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!--
Author: Josh Gillham
Version: 10-15-12
Descriptio:
Draws an bullet image onto the canvas and moves it acrossed the screen. In this example, the bullet is encapsulated with a class.
Ensure that apple.bmp is in the same folder.
-->
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Moving apple</title>
<!-- Load Paper.js libray -->
<script type="text/javascript" src="paper.js"></script>
<!-- Start Paperscript -->
<script type="text/paperscript" canvas="myCanvas">
// Create a instance at the center of the screen with
// an angle of 0.5 and a speed of 2.
var bullet= new Bullet( view.bounds.center, .5, 2 );
// Called every 1/60th of a second.
function onFrame( ) {
// Move the bullet acrossed the screen
bullet.update();
}
/**
* Creates a new bullet with these params. The image is loaded and
* placed at position. Everytime update is called, bullet is moved
* by angle at speed.
*
* @arg position the starting position.
* @arg angle the starting angle.
* @arg speed the starting speed.
*
* @return a new instance of Bullet with the following methods:
* -update() moves the bullet.
*/
function Bullet( position, angle, speed ) {
// Load the image.
var img= new Raster( 'apple' );
// Set the image position
img.position= position;
return {
/**
* Moves the bullet along angle at a speed.
*/
update: function() {
img.position+= new Point( { angle: angle, length: speed } );
}
};
}
</script>
</head>
<body>
Shows a bullet moving acrossed the screen. <br>
In this example, the bullet is encapsulated with a class.<br>
<!-- Link the canvas -->
<canvas id="myCanvas" resize=""></canvas>
<!-- Embed the image resource -->
<img style="width: 32px; height: 32px; Display: none;" alt="" src="apple.bmp" id="apple">
</body>
</html>