BlueGit

timfa frameworkv3

remove outdated comments

timfa Tim Falken · pushed by timfa

Authored 2018-08-14 · 8 years ago

Hash
61a474fb2d538818f06ccdfd90cf6afd759363af
Parent
a9a9589a
9 files changed +103 −136
framework/audio.js +0 −4
@@ -1,10 +1,7 @@
1 //<DOC> category GameAudio
2
3 1 var GameAudio =
4 2 {
5 3 active: false,
6 4
7 //<DOC> <function> GameAudio.init(collection, containingFolder)<br><br>Starts the audio system, using an array of audio names 'collection' and a path 'containingFolder' in which the sounds can be found. Do not include file extentions in sound names!
8 5 init: function(collection, containingFolder)
9 6 {
10 7 console.log("GAME: Loading sounds. (Note: Only supported from online-source, will fail when executed on local files.)");
@@ -43,7 +40,6 @@ var GameAudio =
43 40 }
44 41 },
45 42
46 //<DOC> <function> GameAudio.play(name)<br><br>plays a sound with the name 'name'.
47 43 play: function(name)
48 44 {
49 45 if(this.active)
@@ -1,10 +1,7 @@
1//<DOC> category GameAudio
2
3var GameAudio =
1var GameAudio =
4{
2{
5 active: false,
3 active: false,
6
4
7 //<DOC> <function> GameAudio.init(collection, containingFolder)<br><br>Starts the audio system, using an array of audio names 'collection' and a path 'containingFolder' in which the sounds can be found. Do not include file extentions in sound names!
8 init: function(collection, containingFolder)
5 init: function(collection, containingFolder)
9 {
6 {
10 console.log("GAME: Loading sounds. (Note: Only supported from online-source, will fail when executed on local files.)");
7 console.log("GAME: Loading sounds. (Note: Only supported from online-source, will fail when executed on local files.)");
@@ -43,7 +40,6 @@ var GameAudio =
43 }
40 }
44 },
41 },
45
42
46 //<DOC> <function> GameAudio.play(name)<br><br>plays a sound with the name 'name'.
47 play: function(name)
43 play: function(name)
48 {
44 {
49 if(this.active)
45 if(this.active)
framework/engine.js +0 −8
@@ -1,5 +1,3 @@
1 //engine
2
3 1 var Engine =
4 2 {
5 3 x: 0,
@@ -8,19 +6,15 @@ var Engine =
8 6 h: 0,//stored for window-building
9 7 }
10 8
11 //<DOC> category Game
12 9 var Game =
13 10 {
14 11 stepPrevious: 0,
15 12
16 //<DOC> <parameter> Game.activeScene.activeObjects<br><br>array containing all existing objects.
17 13 activeScene: new Scene(),
18 14 userUpdateCallback: null,
19 15
20 //<DOC> <parameter> Game.stepsSinceStart<br><br> Total amount of update steps since the start of the game.
21 16 stepsSinceStart: 0,
22 17
23 //<DOC> <function> Game.initialize(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)<br><br>Starts the game, and creates a window at ('windowX', 'windowY'), using 'windowWidth' and 'windowHeight' as sizes for the game window in pixels. 'fps' controls the game's frames-per-second'. As soon as the game is loaded up, it'll call the function 'loadedCallback', so you can properly start the game.
24 18 initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)
25 19 {
26 20 console.log("GAME: Initializing. Loading dependencies...");
@@ -45,13 +39,11 @@ var Game =
45 39 Game.activeScene = newScene;
46 40 },
47 41
48 //<DOC> <function> Game.setUpdateFunction(callback)<br><br>Assigns a function 'callback(deltaTime)' to be called every frame of the game. You can use this to run global code for your game.
49 42 setUpdateFunction: function(callback)
50 43 {
51 44 Game.userUpdateCallback = callback;
52 45 },
53 46
54 //<DOC> <function> Game.clearScene()<br><br>destroys every object in the scene.
55 47 clearScene: function()
56 48 {
57 49 Game.activeScene.destroy();
@@ -1,5 +1,3 @@
1//engine
2
3var Engine =
1var Engine =
4{
2{
5 x: 0,
3 x: 0,
@@ -8,19 +6,15 @@ var Engine =
8 h: 0,//stored for window-building
6 h: 0,//stored for window-building
9}
7}
10
8
11//<DOC> category Game
12var Game =
9var Game =
13{
10{
14 stepPrevious: 0,
11 stepPrevious: 0,
15
12
16 //<DOC> <parameter> Game.activeScene.activeObjects<br><br>array containing all existing objects.
17 activeScene: new Scene(),
13 activeScene: new Scene(),
18 userUpdateCallback: null,
14 userUpdateCallback: null,
19
15
20 //<DOC> <parameter> Game.stepsSinceStart<br><br> Total amount of update steps since the start of the game.
21 stepsSinceStart: 0,
16 stepsSinceStart: 0,
22
17
23 //<DOC> <function> Game.initialize(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)<br><br>Starts the game, and creates a window at ('windowX', 'windowY'), using 'windowWidth' and 'windowHeight' as sizes for the game window in pixels. 'fps' controls the game's frames-per-second'. As soon as the game is loaded up, it'll call the function 'loadedCallback', so you can properly start the game.
24 initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)
18 initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)
25 {
19 {
26 console.log("GAME: Initializing. Loading dependencies...");
20 console.log("GAME: Initializing. Loading dependencies...");
@@ -45,13 +39,11 @@ var Game =
45 Game.activeScene = newScene;
39 Game.activeScene = newScene;
46 },
40 },
47
41
48 //<DOC> <function> Game.setUpdateFunction(callback)<br><br>Assigns a function 'callback(deltaTime)' to be called every frame of the game. You can use this to run global code for your game.
49 setUpdateFunction: function(callback)
42 setUpdateFunction: function(callback)
50 {
43 {
51 Game.userUpdateCallback = callback;
44 Game.userUpdateCallback = callback;
52 },
45 },
53
46
54 //<DOC> <function> Game.clearScene()<br><br>destroys every object in the scene.
55 clearScene: function()
47 clearScene: function()
56 {
48 {
57 Game.activeScene.destroy();
49 Game.activeScene.destroy();
framework/image.js +0 −5
@@ -1,13 +1,9 @@
1 //<DOC> <category> Image
2 //<DOC> <function> Constructor: new image(urlToImage, subImages = 1, subImagesPerRow = 1)
3 1 function image(url, subImgTotal, perRow)
4 2 {
5 3 subImgTotal = subImgTotal || 1;
6 4 perRow = perRow || 1;
7 5
8 //<DOC> <parameter> image.subImages<br><br>The total number of subimages in the image. Defaults to 1.
9 6 this.subImages = subImgTotal;
10 //<DOC> <parameter> image.subImagesPerRow<br><br>The total number of subimages per row. Defaults to 1.
11 7 this.subImagesPerRow = perRow;
12 8
13 9 var body = document.body;
@@ -31,7 +27,6 @@ function image(url, subImgTotal, perRow)
31 27 }
32 28 });
33 29
34 //<DOC> <function> image.draw(sourceX, sourceY, sourceWidth, destX, destY, destWidth, destHeight, rotation, alpha)<br><br>Draw the image on screen.
35 30 this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)
36 31 {
37 32 var shouldDraw = true;
@@ -1,13 +1,9 @@
1//<DOC> <category> Image
2//<DOC> <function> Constructor: new image(urlToImage, subImages = 1, subImagesPerRow = 1)
3function image(url, subImgTotal, perRow)
1function image(url, subImgTotal, perRow)
4{
2{
5 subImgTotal = subImgTotal || 1;
3 subImgTotal = subImgTotal || 1;
6 perRow = perRow || 1;
4 perRow = perRow || 1;
7
5
8 //<DOC> <parameter> image.subImages<br><br>The total number of subimages in the image. Defaults to 1.
9 this.subImages = subImgTotal;
6 this.subImages = subImgTotal;
10 //<DOC> <parameter> image.subImagesPerRow<br><br>The total number of subimages per row. Defaults to 1.
11 this.subImagesPerRow = perRow;
7 this.subImagesPerRow = perRow;
12
8
13 var body = document.body;
9 var body = document.body;
@@ -31,7 +27,6 @@ function image(url, subImgTotal, perRow)
31 }
27 }
32 });
28 });
33
29
34 //<DOC> <function> image.draw(sourceX, sourceY, sourceWidth, destX, destY, destWidth, destHeight, rotation, alpha)<br><br>Draw the image on screen.
35 this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)
30 this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)
36 {
31 {
37 var shouldDraw = true;
32 var shouldDraw = true;
framework/input.js +3 −3
@@ -1,4 +1,4 @@
1 //<DOC> category GameInput
1
2 2
3 3 var GameInput =
4 4 {
@@ -111,7 +111,7 @@ var GameInput =
111 111 }
112 112 },
113 113
114 //<DOC> <function> GameInput.IsPressed(keyCode)<br><br>Returns true if the key with given code 'keyCode' was pressed this frame. Only returns true the frame the key is pressed once until the key is released and pressed again.
114
115 115 isPressed: function(keyCode)
116 116 {
117 117 if(GameInput.g_ppressKeyStatus[keyCode] == null)
@@ -120,7 +120,7 @@ var GameInput =
120 120 return GameInput.g_ppressKeyStatus[keyCode];
121 121 },
122 122
123 //<DOC> <function> GameInput.isHeld(keyCode)<br><br>returns true if the key with given code 'keyCode' is currently pressed.
123
124 124 isHeld: function(keyCode)
125 125 {
126 126 if(GameInput.g_pKeyStatus[keyCode] == null)
@@ -1,4 +1,4 @@
1//<DOC> category GameInput
1
2
2
3var GameInput =
3var GameInput =
4{
4{
@@ -111,7 +111,7 @@ var GameInput =
111 }
111 }
112 },
112 },
113
113
114 //<DOC> <function> GameInput.IsPressed(keyCode)<br><br>Returns true if the key with given code 'keyCode' was pressed this frame. Only returns true the frame the key is pressed once until the key is released and pressed again.
114
115 isPressed: function(keyCode)
115 isPressed: function(keyCode)
116 {
116 {
117 if(GameInput.g_ppressKeyStatus[keyCode] == null)
117 if(GameInput.g_ppressKeyStatus[keyCode] == null)
@@ -120,7 +120,7 @@ var GameInput =
120 return GameInput.g_ppressKeyStatus[keyCode];
120 return GameInput.g_ppressKeyStatus[keyCode];
121 },
121 },
122
122
123 //<DOC> <function> GameInput.isHeld(keyCode)<br><br>returns true if the key with given code 'keyCode' is currently pressed.
123
124 isHeld: function(keyCode)
124 isHeld: function(keyCode)
125 {
125 {
126 if(GameInput.g_pKeyStatus[keyCode] == null)
126 if(GameInput.g_pKeyStatus[keyCode] == null)
framework/object.js +28 −28
@@ -1,4 +1,4 @@
1 //<DOC> category GameObject
1
2 2
3 3 var GameObject =
4 4 {
@@ -6,7 +6,7 @@ var GameObject =
6 6
7 7 destroyed: false,
8 8
9 //<DOC> <function> GameObject.create(template, x, y)<br><br>Creates a new Game Object using the object template 'template' at the position ('x', 'y')
9
10 10 create: function(template, x, y, image, layer)
11 11 {
12 12 var newObj = $.extend(true, {}, template);
@@ -33,28 +33,28 @@ var GameObject =
33 33
34 34 object: function(x, y, image) //DO NOT use any functions with prefix g_ in your game!
35 35 {
36 //<DOC> <parameter> object.active<br><br>Object is visible and executes it's code when this parameter is true. Set to false to hide and disable the object temporarily.
36
37 37 this.active = true;
38 //<DOC> <parameter> object.name<br><br>The name of the current object. Defaults to "Object".
38
39 39 this.name = "Object";
40 //<DOC> <parameter> object.image<br><br>An image object.
40
41 41 this.image = "";
42 42
43 //<DOC> <parameter> object.ignoreCollisions<br><br>Ignores this object when checking for collisions. Useful for background objects.
43
44 44 this.ignoreCollisions = false;
45 45
46 //<DOC> <parameter> object.renderer<br><br>Used for methods and variables related to drawing the object on the screen.
46
47 47 this.renderer = {
48 //<DOC> <parameter> object.renderer.image<br><br>The image to draw.
48
49 49 image: image,
50 50
51 //<DOC> <parameter> object.renderer.subImage<br><br>The current subimage to draw using the default draw method
51
52 52 subImage: 0,
53 53
54 //<DOC> <parameter> object.renderer.alpha<br><br>Image transparency (0-1) default: 1
54
55 55 alpha: 1,
56 56
57 //<DOC> <parameter> object.renderer.visible<br><br>Value indicating if the object should be drawn (true/false)
57
58 58 visible: true,
59 59
60 60 //used to correct NaN
@@ -62,7 +62,7 @@ var GameObject =
62 62
63 63 g_layerDepth: 0,
64 64
65 //<DOC> <function> image.draw(x, y, w, h, rotation, alpha = 1)<br><br>Draw an image at (x,y), size (w,h), at an angle in degrees.
65
66 66 draw: function(x, y, w, h, rotation)
67 67 {
68 68 if(isNaN(this.subImage))
@@ -109,21 +109,21 @@ var GameObject =
109 109
110 110 this.transform =
111 111 {
112 //<DOC> <parameter> object.transform.position<br><br>A vector() containing the object's position. (measured from object center)
112
113 113 position: new vector(x, y),
114 //<DOC> <parameter> object.transform.velocity<br><br>A vector() containing the object's speed. (measured from object center)
114
115 115 velocity: new vector(0, 0),
116 //<DOC> <parameter> object.transform.rotation<br><br>the object's rotation in degrees. Default is zero.
116
117 117 rotation: 0,
118 118
119 //<DOC> <parameter> object.transform.width<br><br>the width of the object, defaults to 32.
119
120 120 width: image? image.width : 0,
121 //<DOC> <parameter> object.transform.height<br><br>the height of the object, defaults to 32.
121
122 122 height: image? image.height: 0,
123 123
124 124 scale: new vector(1, 1),
125 125
126 //<DOC> <function> object.transform.pointTowards(point)<br><br>Adjust object.transform.rotation to point at vector2() 'point'.
126
127 127 pointTowards: function(point)
128 128 {
129 129 var delta = point.subtract(this.position);
@@ -131,25 +131,25 @@ var GameObject =
131 131 this.rotation = delta.toAngle();
132 132 },
133 133
134 //<DOC> <function> object.transform.left()<br><br>A single pixel left of the object, accounting for rotation.
134
135 135 left: function()
136 136 {
137 137 return this.g_dir(0);
138 138 },
139 139
140 //<DOC> <function> object.transform.right()<br><br>A single pixel right of the object, accounting for rotation.
140
141 141 right: function()
142 142 {
143 143 return this.g_dir(180);
144 144 },
145 145
146 //<DOC> <function> object.transform.forward()<br><br>A single pixel forwards of the object, accounting for rotation.
146
147 147 forward: function()
148 148 {
149 149 return this.g_dir(90);
150 150 },
151 151
152 //<DOC> <function> object.transform.back()<br><br>A single pixel backwards of the object, accounting for rotation.
152
153 153 back: function()
154 154 {
155 155 return this.g_dir(270);
@@ -169,7 +169,7 @@ var GameObject =
169 169 {
170 170 Game.activeScene.addObject(this);
171 171
172 //<DOC> <function> object.start()<br><br>Called on object's creation. Override this on your own object templates!
172
173 173 if (typeof this.start == 'function') { this.start(); }
174 174 }
175 175
@@ -206,7 +206,7 @@ var GameObject =
206 206 {
207 207 if(this.draw)
208 208 {
209 //<DOC> <function> object.draw()<br><br>Called on each draw step. If not overridden, default draw is used!
209
210 210 this.draw();
211 211 }
212 212 else
@@ -263,7 +263,7 @@ var GameObject =
263 263 }
264 264 else
265 265 {
266 //<DOC> <function> object.update(deltaTime)<br><br>Called on each frame start! (Before collision checks of this frame) Override this on your own object templates!
266
267 267 if (typeof this.update == 'function') { this.update(deltaTime); }
268 268
269 269 this.transform.position.x += this.transform.velocity.x;
@@ -337,7 +337,7 @@ var GameObject =
337 337 }
338 338 }
339 339
340 //<DOC> <function> object.onCollision(other)<br><br>Called on object collision. Parameter 'other' is a reference to the object you're colliding with! Override this on your own object templates!
340
341 341 if(hit)
342 342 if (!this.destroyed && typeof this.onCollision == 'function') { this.onCollision(o2); }
343 343 }
@@ -346,12 +346,12 @@ var GameObject =
346 346 }
347 347 }
348 348
349 //<DOC> <function> object.destroy()<br><br>Destroys the current object at the end of the current update step.
349
350 350 this.destroy = function()
351 351 {
352 352 if(!this.g_destroy)
353 353 {
354 //<DOC> <function> object.onDestroy()<br><br>Called on object's destruction. Override this on your own object templates!
354
355 355 if (typeof this.onDestroy == 'function') { this.onDestroy(); }
356 356
357 357 this.destroyed = true;
@@ -1,4 +1,4 @@
1//<DOC> category GameObject
1
2
2
3var GameObject =
3var GameObject =
4{
4{
@@ -6,7 +6,7 @@ var GameObject =
6
6
7 destroyed: false,
7 destroyed: false,
8
8
9 //<DOC> <function> GameObject.create(template, x, y)<br><br>Creates a new Game Object using the object template 'template' at the position ('x', 'y')
9
10 create: function(template, x, y, image, layer)
10 create: function(template, x, y, image, layer)
11 {
11 {
12 var newObj = $.extend(true, {}, template);
12 var newObj = $.extend(true, {}, template);
@@ -33,28 +33,28 @@ var GameObject =
33
33
34 object: function(x, y, image) //DO NOT use any functions with prefix g_ in your game!
34 object: function(x, y, image) //DO NOT use any functions with prefix g_ in your game!
35 {
35 {
36 //<DOC> <parameter> object.active<br><br>Object is visible and executes it's code when this parameter is true. Set to false to hide and disable the object temporarily.
36
37 this.active = true;
37 this.active = true;
38 //<DOC> <parameter> object.name<br><br>The name of the current object. Defaults to "Object".
38
39 this.name = "Object";
39 this.name = "Object";
40 //<DOC> <parameter> object.image<br><br>An image object.
40
41 this.image = "";
41 this.image = "";
42
42
43 //<DOC> <parameter> object.ignoreCollisions<br><br>Ignores this object when checking for collisions. Useful for background objects.
43
44 this.ignoreCollisions = false;
44 this.ignoreCollisions = false;
45
45
46 //<DOC> <parameter> object.renderer<br><br>Used for methods and variables related to drawing the object on the screen.
46
47 this.renderer = {
47 this.renderer = {
48 //<DOC> <parameter> object.renderer.image<br><br>The image to draw.
48
49 image: image,
49 image: image,
50
50
51 //<DOC> <parameter> object.renderer.subImage<br><br>The current subimage to draw using the default draw method
51
52 subImage: 0,
52 subImage: 0,
53
53
54 //<DOC> <parameter> object.renderer.alpha<br><br>Image transparency (0-1) default: 1
54
55 alpha: 1,
55 alpha: 1,
56
56
57 //<DOC> <parameter> object.renderer.visible<br><br>Value indicating if the object should be drawn (true/false)
57
58 visible: true,
58 visible: true,
59
59
60 //used to correct NaN
60 //used to correct NaN
@@ -62,7 +62,7 @@ var GameObject =
62
62
63 g_layerDepth: 0,
63 g_layerDepth: 0,
64
64
65 //<DOC> <function> image.draw(x, y, w, h, rotation, alpha = 1)<br><br>Draw an image at (x,y), size (w,h), at an angle in degrees.
65
66 draw: function(x, y, w, h, rotation)
66 draw: function(x, y, w, h, rotation)
67 {
67 {
68 if(isNaN(this.subImage))
68 if(isNaN(this.subImage))
@@ -109,21 +109,21 @@ var GameObject =
109
109
110 this.transform =
110 this.transform =
111 {
111 {
112 //<DOC> <parameter> object.transform.position<br><br>A vector() containing the object's position. (measured from object center)
112
113 position: new vector(x, y),
113 position: new vector(x, y),
114 //<DOC> <parameter> object.transform.velocity<br><br>A vector() containing the object's speed. (measured from object center)
114
115 velocity: new vector(0, 0),
115 velocity: new vector(0, 0),
116 //<DOC> <parameter> object.transform.rotation<br><br>the object's rotation in degrees. Default is zero.
116
117 rotation: 0,
117 rotation: 0,
118
118
119 //<DOC> <parameter> object.transform.width<br><br>the width of the object, defaults to 32.
119
120 width: image? image.width : 0,
120 width: image? image.width : 0,
121 //<DOC> <parameter> object.transform.height<br><br>the height of the object, defaults to 32.
121
122 height: image? image.height: 0,
122 height: image? image.height: 0,
123
123
124 scale: new vector(1, 1),
124 scale: new vector(1, 1),
125
125
126 //<DOC> <function> object.transform.pointTowards(point)<br><br>Adjust object.transform.rotation to point at vector2() 'point'.
126
127 pointTowards: function(point)
127 pointTowards: function(point)
128 {
128 {
129 var delta = point.subtract(this.position);
129 var delta = point.subtract(this.position);
@@ -131,25 +131,25 @@ var GameObject =
131 this.rotation = delta.toAngle();
131 this.rotation = delta.toAngle();
132 },
132 },
133
133
134 //<DOC> <function> object.transform.left()<br><br>A single pixel left of the object, accounting for rotation.
134
135 left: function()
135 left: function()
136 {
136 {
137 return this.g_dir(0);
137 return this.g_dir(0);
138 },
138 },
139
139
140 //<DOC> <function> object.transform.right()<br><br>A single pixel right of the object, accounting for rotation.
140
141 right: function()
141 right: function()
142 {
142 {
143 return this.g_dir(180);
143 return this.g_dir(180);
144 },
144 },
145
145
146 //<DOC> <function> object.transform.forward()<br><br>A single pixel forwards of the object, accounting for rotation.
146
147 forward: function()
147 forward: function()
148 {
148 {
149 return this.g_dir(90);
149 return this.g_dir(90);
150 },
150 },
151
151
152 //<DOC> <function> object.transform.back()<br><br>A single pixel backwards of the object, accounting for rotation.
152
153 back: function()
153 back: function()
154 {
154 {
155 return this.g_dir(270);
155 return this.g_dir(270);
@@ -169,7 +169,7 @@ var GameObject =
169 {
169 {
170 Game.activeScene.addObject(this);
170 Game.activeScene.addObject(this);
171
171
172 //<DOC> <function> object.start()<br><br>Called on object's creation. Override this on your own object templates!
172
173 if (typeof this.start == 'function') { this.start(); }
173 if (typeof this.start == 'function') { this.start(); }
174 }
174 }
175
175
@@ -206,7 +206,7 @@ var GameObject =
206 {
206 {
207 if(this.draw)
207 if(this.draw)
208 {
208 {
209 //<DOC> <function> object.draw()<br><br>Called on each draw step. If not overridden, default draw is used!
209
210 this.draw();
210 this.draw();
211 }
211 }
212 else
212 else
@@ -263,7 +263,7 @@ var GameObject =
263 }
263 }
264 else
264 else
265 {
265 {
266 //<DOC> <function> object.update(deltaTime)<br><br>Called on each frame start! (Before collision checks of this frame) Override this on your own object templates!
266
267 if (typeof this.update == 'function') { this.update(deltaTime); }
267 if (typeof this.update == 'function') { this.update(deltaTime); }
268
268
269 this.transform.position.x += this.transform.velocity.x;
269 this.transform.position.x += this.transform.velocity.x;
@@ -337,7 +337,7 @@ var GameObject =
337 }
337 }
338 }
338 }
339
339
340 //<DOC> <function> object.onCollision(other)<br><br>Called on object collision. Parameter 'other' is a reference to the object you're colliding with! Override this on your own object templates!
340
341 if(hit)
341 if(hit)
342 if (!this.destroyed && typeof this.onCollision == 'function') { this.onCollision(o2); }
342 if (!this.destroyed && typeof this.onCollision == 'function') { this.onCollision(o2); }
343 }
343 }
@@ -346,12 +346,12 @@ var GameObject =
346 }
346 }
347 }
347 }
348
348
349 //<DOC> <function> object.destroy()<br><br>Destroys the current object at the end of the current update step.
349
350 this.destroy = function()
350 this.destroy = function()
351 {
351 {
352 if(!this.g_destroy)
352 if(!this.g_destroy)
353 {
353 {
354 //<DOC> <function> object.onDestroy()<br><br>Called on object's destruction. Override this on your own object templates!
354
355 if (typeof this.onDestroy == 'function') { this.onDestroy(); }
355 if (typeof this.onDestroy == 'function') { this.onDestroy(); }
356
356
357 this.destroyed = true;
357 this.destroyed = true;
framework/vector.js +14 −14
@@ -1,25 +1,25 @@
1 //<DOC> category vector()
1
2 2
3 3 function vector(x, y)
4 4 {
5 //<DOC> <parameter> vector.x<br><br>the X axis of the vector.
5
6 6 this.x = x;
7 //<DOC> <parameter> vector.y<br><br>the Y axis of the vector.
7
8 8 this.y = y;
9 9
10 //<DOC> <function> vector.length()<br><br>returns the length of the vector.
10
11 11 this.length = function()
12 12 {
13 13 return Math.sqrt((this.x * this.x) + (this.y * this.y));
14 14 }
15 15
16 //<DOC> <function> vector.toAngle()<br><br>Get the angle towards the vector's direction in degrees.
16
17 17 this.toAngle = function()
18 18 {
19 19 return (Math.atan2(this.y, this.x) * 180 / Math.PI) + 90;
20 20 }
21 21
22 //<DOC> <function> vector.normalize()<br><br>returns a normalized copy of the vector. Original vector is not modified.
22
23 23 this.normalize = function()
24 24 {
25 25 var newVector = this.getCopy();
@@ -34,7 +34,7 @@ function vector(x, y)
34 34 return newVector;
35 35 }
36 36
37 //<DOC> <function> vector.lerpTo(otherVector, t)<br><br> Returns a new vector between this vector and 'otherVector' at point 't'. 0t = original vector, 1t = 'otherVector', 0.5t is halfway in between.
37
38 38 this.lerpTo = function(otherVector, t)
39 39 {
40 40 var delta = otherVector.subtract(this);
@@ -42,7 +42,7 @@ function vector(x, y)
42 42 return this.add(delta.stretch(t));
43 43 }
44 44
45 //<DOC> <function> vector.distanceTo(otherVector)<br><br>returns the distance to another vector.
45
46 46 this.distanceTo = function(otherVector)
47 47 {
48 48 var dX = this.x - otherVector.x;
@@ -51,7 +51,7 @@ function vector(x, y)
51 51 return new vector(dX, dY).length();
52 52 }
53 53
54 //<DOC> <function> vector.add(otherVector)<br><br>adds the two vectors together, and returns as a copy. Original vector is not modified.
54
55 55 this.add = function(otherVector)
56 56 {
57 57 var newVector = this.getCopy();
@@ -62,7 +62,7 @@ function vector(x, y)
62 62 return newVector;
63 63 }
64 64
65 //<DOC> <function> vector.subtract(otherVector)<br><br>subtracts the second vector from this vector, and returns as a copy. Original vector is not modified.
65
66 66 this.subtract = function(otherVector)
67 67 {
68 68 var newVector = this.getCopy();
@@ -73,7 +73,7 @@ function vector(x, y)
73 73 return newVector;
74 74 }
75 75
76 //<DOC> <function> vector.multiply(otherVector)<br><br>multiplies the first vector X by the second vector's X, and the first's Y by the second's Y, and returns as a copy. Original vector is not modified.
76
77 77 this.multiply = function(otherVector)
78 78 {
79 79 var newVector = this.getCopy();
@@ -84,7 +84,7 @@ function vector(x, y)
84 84 return newVector;
85 85 }
86 86
87 //<DOC> <function> vector.divide(otherVector)<br><br>divides the first vector by the second, and returns as a copy. Original vector is not modified.
87
88 88 this.divide = function(otherVector)
89 89 {
90 90 var newVector = this.getCopy();
@@ -95,7 +95,7 @@ function vector(x, y)
95 95 return newVector;
96 96 }
97 97
98 //<DOC> <function> vector.stretch(length)<br><br>Multiplies the vector by the given numeric value, and returns as a copy. Original vector is not modified.
98
99 99 this.stretch = function(length)
100 100 {
101 101 var newVector = this.getCopy();
@@ -119,7 +119,7 @@ function vector(x, y)
119 119 return this.x * otherVector.y - this.y * otherVector.x;
120 120 }
121 121
122 //<DOC> <function> vector.getCopy()<br><br>returns a copy of this vector.
122
123 123 this.getCopy = function()
124 124 {
125 125 return new vector(this.x, this.y);
@@ -1,25 +1,25 @@
1//<DOC> category vector()
1
2
2
3function vector(x, y)
3function vector(x, y)
4{
4{
5 //<DOC> <parameter> vector.x<br><br>the X axis of the vector.
5
6 this.x = x;
6 this.x = x;
7 //<DOC> <parameter> vector.y<br><br>the Y axis of the vector.
7
8 this.y = y;
8 this.y = y;
9
9
10 //<DOC> <function> vector.length()<br><br>returns the length of the vector.
10
11 this.length = function()
11 this.length = function()
12 {
12 {
13 return Math.sqrt((this.x * this.x) + (this.y * this.y));
13 return Math.sqrt((this.x * this.x) + (this.y * this.y));
14 }
14 }
15
15
16 //<DOC> <function> vector.toAngle()<br><br>Get the angle towards the vector's direction in degrees.
16
17 this.toAngle = function()
17 this.toAngle = function()
18 {
18 {
19 return (Math.atan2(this.y, this.x) * 180 / Math.PI) + 90;
19 return (Math.atan2(this.y, this.x) * 180 / Math.PI) + 90;
20 }
20 }
21
21
22 //<DOC> <function> vector.normalize()<br><br>returns a normalized copy of the vector. Original vector is not modified.
22
23 this.normalize = function()
23 this.normalize = function()
24 {
24 {
25 var newVector = this.getCopy();
25 var newVector = this.getCopy();
@@ -34,7 +34,7 @@ function vector(x, y)
34 return newVector;
34 return newVector;
35 }
35 }
36
36
37 //<DOC> <function> vector.lerpTo(otherVector, t)<br><br> Returns a new vector between this vector and 'otherVector' at point 't'. 0t = original vector, 1t = 'otherVector', 0.5t is halfway in between.
37
38 this.lerpTo = function(otherVector, t)
38 this.lerpTo = function(otherVector, t)
39 {
39 {
40 var delta = otherVector.subtract(this);
40 var delta = otherVector.subtract(this);
@@ -42,7 +42,7 @@ function vector(x, y)
42 return this.add(delta.stretch(t));
42 return this.add(delta.stretch(t));
43 }
43 }
44
44
45 //<DOC> <function> vector.distanceTo(otherVector)<br><br>returns the distance to another vector.
45
46 this.distanceTo = function(otherVector)
46 this.distanceTo = function(otherVector)
47 {
47 {
48 var dX = this.x - otherVector.x;
48 var dX = this.x - otherVector.x;
@@ -51,7 +51,7 @@ function vector(x, y)
51 return new vector(dX, dY).length();
51 return new vector(dX, dY).length();
52 }
52 }
53
53
54 //<DOC> <function> vector.add(otherVector)<br><br>adds the two vectors together, and returns as a copy. Original vector is not modified.
54
55 this.add = function(otherVector)
55 this.add = function(otherVector)
56 {
56 {
57 var newVector = this.getCopy();
57 var newVector = this.getCopy();
@@ -62,7 +62,7 @@ function vector(x, y)
62 return newVector;
62 return newVector;
63 }
63 }
64
64
65 //<DOC> <function> vector.subtract(otherVector)<br><br>subtracts the second vector from this vector, and returns as a copy. Original vector is not modified.
65
66 this.subtract = function(otherVector)
66 this.subtract = function(otherVector)
67 {
67 {
68 var newVector = this.getCopy();
68 var newVector = this.getCopy();
@@ -73,7 +73,7 @@ function vector(x, y)
73 return newVector;
73 return newVector;
74 }
74 }
75
75
76 //<DOC> <function> vector.multiply(otherVector)<br><br>multiplies the first vector X by the second vector's X, and the first's Y by the second's Y, and returns as a copy. Original vector is not modified.
76
77 this.multiply = function(otherVector)
77 this.multiply = function(otherVector)
78 {
78 {
79 var newVector = this.getCopy();
79 var newVector = this.getCopy();
@@ -84,7 +84,7 @@ function vector(x, y)
84 return newVector;
84 return newVector;
85 }
85 }
86
86
87 //<DOC> <function> vector.divide(otherVector)<br><br>divides the first vector by the second, and returns as a copy. Original vector is not modified.
87
88 this.divide = function(otherVector)
88 this.divide = function(otherVector)
89 {
89 {
90 var newVector = this.getCopy();
90 var newVector = this.getCopy();
@@ -95,7 +95,7 @@ function vector(x, y)
95 return newVector;
95 return newVector;
96 }
96 }
97
97
98 //<DOC> <function> vector.stretch(length)<br><br>Multiplies the vector by the given numeric value, and returns as a copy. Original vector is not modified.
98
99 this.stretch = function(length)
99 this.stretch = function(length)
100 {
100 {
101 var newVector = this.getCopy();
101 var newVector = this.getCopy();
@@ -119,7 +119,7 @@ function vector(x, y)
119 return this.x * otherVector.y - this.y * otherVector.x;
119 return this.x * otherVector.y - this.y * otherVector.x;
120 }
120 }
121
121
122 //<DOC> <function> vector.getCopy()<br><br>returns a copy of this vector.
122
123 this.getCopy = function()
123 this.getCopy = function()
124 {
124 {
125 return new vector(this.x, this.y);
125 return new vector(this.x, this.y);
framework/window.js +6 −6
@@ -1,10 +1,10 @@
1 //<DOC> category GameWindow
1
2 2
3 3 var GameWindow =
4 4 {
5 //<DOC> <parameter> GameWindow.width<br>The game window's width. Cannot be changed.
5
6 6 width: 0,
7 //<DOC> <parameter> GameWindow.height<br>The game window's height. Cannot be changed.
7
8 8 height: 0,
9 9
10 10 g_width: 0,
@@ -12,7 +12,7 @@ var GameWindow =
12 12
13 13 fullscreen: false,
14 14
15 //<DOC> <parameter> GameWindow.backgroundColor<br>Background color. Contains an r, g and b component (0-255).
15
16 16 backgroundColor:
17 17 {
18 18 r: 255,
@@ -40,10 +40,10 @@ var GameWindow =
40 40 //$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');
41 41 GameWindow.windowElement = document.getElementById(GameWindow.elementID);
42 42
43 //<DOC> <parameter> GameWindow.canvas <br><br> The game's canvas element
43
44 44 GameWindow.canvas = document.getElementById(GameWindow.elementID);
45 45
46 //<DOC> <parameter> GameWindow.canvasContext <br><br>The game's canvasContext. Use this for drawing.
46
47 47 GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
48 48
49 49 console.log("GAME: Window initialized: [" + width + ", " + height + "]");
@@ -1,10 +1,10 @@
1//<DOC> category GameWindow
1
2
2
3var GameWindow =
3var GameWindow =
4{
4{
5 //<DOC> <parameter> GameWindow.width<br>The game window's width. Cannot be changed.
5
6 width: 0,
6 width: 0,
7 //<DOC> <parameter> GameWindow.height<br>The game window's height. Cannot be changed.
7
8 height: 0,
8 height: 0,
9
9
10 g_width: 0,
10 g_width: 0,
@@ -12,7 +12,7 @@ var GameWindow =
12
12
13 fullscreen: false,
13 fullscreen: false,
14
14
15 //<DOC> <parameter> GameWindow.backgroundColor<br>Background color. Contains an r, g and b component (0-255).
15
16 backgroundColor:
16 backgroundColor:
17 {
17 {
18 r: 255,
18 r: 255,
@@ -40,10 +40,10 @@ var GameWindow =
40 //$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');
40 //$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');
41 GameWindow.windowElement = document.getElementById(GameWindow.elementID);
41 GameWindow.windowElement = document.getElementById(GameWindow.elementID);
42
42
43 //<DOC> <parameter> GameWindow.canvas <br><br> The game's canvas element
43
44 GameWindow.canvas = document.getElementById(GameWindow.elementID);
44 GameWindow.canvas = document.getElementById(GameWindow.elementID);
45
45
46 //<DOC> <parameter> GameWindow.canvasContext <br><br>The game's canvasContext. Use this for drawing.
46
47 GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
47 GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
48
48
49 console.log("GAME: Window initialized: [" + width + ", " + height + "]");
49 console.log("GAME: Window initialized: [" + width + ", " + height + "]");
js/framework.js +51 −68
@@ -1,10 +1,7 @@
1 //<DOC> category GameAudio
2
3 1 var GameAudio =
4 2 {
5 3 active: false,
6 4
7 //<DOC> <function> GameAudio.init(collection, containingFolder)<br><br>Starts the audio system, using an array of audio names 'collection' and a path 'containingFolder' in which the sounds can be found. Do not include file extentions in sound names!
8 5 init: function(collection, containingFolder)
9 6 {
10 7 console.log("GAME: Loading sounds. (Note: Only supported from online-source, will fail when executed on local files.)");
@@ -43,7 +40,6 @@ var GameAudio =
43 40 }
44 41 },
45 42
46 //<DOC> <function> GameAudio.play(name)<br><br>plays a sound with the name 'name'.
47 43 play: function(name)
48 44 {
49 45 if(this.active)
@@ -448,8 +444,6 @@ var ease = {
448 444 }
449 445 };
450 446
451 //engine
452
453 447 var Engine =
454 448 {
455 449 x: 0,
@@ -458,19 +452,15 @@ var Engine =
458 452 h: 0,//stored for window-building
459 453 }
460 454
461 //<DOC> category Game
462 455 var Game =
463 456 {
464 457 stepPrevious: 0,
465 458
466 //<DOC> <parameter> Game.activeScene.activeObjects<br><br>array containing all existing objects.
467 459 activeScene: new Scene(),
468 460 userUpdateCallback: null,
469 461
470 //<DOC> <parameter> Game.stepsSinceStart<br><br> Total amount of update steps since the start of the game.
471 462 stepsSinceStart: 0,
472 463
473 //<DOC> <function> Game.initialize(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)<br><br>Starts the game, and creates a window at ('windowX', 'windowY'), using 'windowWidth' and 'windowHeight' as sizes for the game window in pixels. 'fps' controls the game's frames-per-second'. As soon as the game is loaded up, it'll call the function 'loadedCallback', so you can properly start the game.
474 464 initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)
475 465 {
476 466 console.log("GAME: Initializing. Loading dependencies...");
@@ -495,13 +485,11 @@ var Game =
495 485 Game.activeScene = newScene;
496 486 },
497 487
498 //<DOC> <function> Game.setUpdateFunction(callback)<br><br>Assigns a function 'callback(deltaTime)' to be called every frame of the game. You can use this to run global code for your game.
499 488 setUpdateFunction: function(callback)
500 489 {
501 490 Game.userUpdateCallback = callback;
502 491 },
503 492
504 //<DOC> <function> Game.clearScene()<br><br>destroys every object in the scene.
505 493 clearScene: function()
506 494 {
507 495 Game.activeScene.destroy();
@@ -576,16 +564,12 @@ Math.clamp = function(number, min, max)
576 564 return Math.min(max, Math.max(min, number));
577 565 }
578 566
579 //<DOC> <category> Image
580 //<DOC> <function> Constructor: new image(urlToImage, subImages = 1, subImagesPerRow = 1)
581 567 function image(url, subImgTotal, perRow)
582 568 {
583 569 subImgTotal = subImgTotal || 1;
584 570 perRow = perRow || 1;
585 571
586 //<DOC> <parameter> image.subImages<br><br>The total number of subimages in the image. Defaults to 1.
587 572 this.subImages = subImgTotal;
588 //<DOC> <parameter> image.subImagesPerRow<br><br>The total number of subimages per row. Defaults to 1.
589 573 this.subImagesPerRow = perRow;
590 574
591 575 var body = document.body;
@@ -609,7 +593,6 @@ function image(url, subImgTotal, perRow)
609 593 }
610 594 });
611 595
612 //<DOC> <function> image.draw(sourceX, sourceY, sourceWidth, destX, destY, destWidth, destHeight, rotation, alpha)<br><br>Draw the image on screen.
613 596 this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)
614 597 {
615 598 var shouldDraw = true;
@@ -644,7 +627,7 @@ function image(url, subImgTotal, perRow)
644 627 }
645 628 }
646 629
647 //<DOC> category GameInput
630
648 631
649 632 var GameInput =
650 633 {
@@ -757,7 +740,7 @@ var GameInput =
757 740 }
758 741 },
759 742
760 //<DOC> <function> GameInput.IsPressed(keyCode)<br><br>Returns true if the key with given code 'keyCode' was pressed this frame. Only returns true the frame the key is pressed once until the key is released and pressed again.
743
761 744 isPressed: function(keyCode)
762 745 {
763 746 if(GameInput.g_ppressKeyStatus[keyCode] == null)
@@ -766,7 +749,7 @@ var GameInput =
766 749 return GameInput.g_ppressKeyStatus[keyCode];
767 750 },
768 751
769 //<DOC> <function> GameInput.isHeld(keyCode)<br><br>returns true if the key with given code 'keyCode' is currently pressed.
752
770 753 isHeld: function(keyCode)
771 754 {
772 755 if(GameInput.g_pKeyStatus[keyCode] == null)
@@ -800,7 +783,7 @@ var GameInput =
800 783 }
801 784 }//
802 785
803 //<DOC> category GameObject
786
804 787
805 788 var GameObject =
806 789 {
@@ -808,7 +791,7 @@ var GameObject =
808 791
809 792 destroyed: false,
810 793
811 //<DOC> <function> GameObject.create(template, x, y)<br><br>Creates a new Game Object using the object template 'template' at the position ('x', 'y')
794
812 795 create: function(template, x, y, image, layer)
813 796 {
814 797 var newObj = $.extend(true, {}, template);
@@ -835,28 +818,28 @@ var GameObject =
835 818
836 819 object: function(x, y, image) //DO NOT use any functions with prefix g_ in your game!
837 820 {
838 //<DOC> <parameter> object.active<br><br>Object is visible and executes it's code when this parameter is true. Set to false to hide and disable the object temporarily.
821
839 822 this.active = true;
840 //<DOC> <parameter> object.name<br><br>The name of the current object. Defaults to "Object".
823
841 824 this.name = "Object";
842 //<DOC> <parameter> object.image<br><br>An image object.
825
843 826 this.image = "";
844 827
845 //<DOC> <parameter> object.ignoreCollisions<br><br>Ignores this object when checking for collisions. Useful for background objects.
828
846 829 this.ignoreCollisions = false;
847 830
848 //<DOC> <parameter> object.renderer<br><br>Used for methods and variables related to drawing the object on the screen.
831
849 832 this.renderer = {
850 //<DOC> <parameter> object.renderer.image<br><br>The image to draw.
833
851 834 image: image,
852 835
853 //<DOC> <parameter> object.renderer.subImage<br><br>The current subimage to draw using the default draw method
836
854 837 subImage: 0,
855 838
856 //<DOC> <parameter> object.renderer.alpha<br><br>Image transparency (0-1) default: 1
839
857 840 alpha: 1,
858 841
859 //<DOC> <parameter> object.renderer.visible<br><br>Value indicating if the object should be drawn (true/false)
842
860 843 visible: true,
861 844
862 845 //used to correct NaN
@@ -864,7 +847,7 @@ var GameObject =
864 847
865 848 g_layerDepth: 0,
866 849
867 //<DOC> <function> image.draw(x, y, w, h, rotation, alpha = 1)<br><br>Draw an image at (x,y), size (w,h), at an angle in degrees.
850
868 851 draw: function(x, y, w, h, rotation)
869 852 {
870 853 if(isNaN(this.subImage))
@@ -911,21 +894,21 @@ var GameObject =
911 894
912 895 this.transform =
913 896 {
914 //<DOC> <parameter> object.transform.position<br><br>A vector() containing the object's position. (measured from object center)
897
915 898 position: new vector(x, y),
916 //<DOC> <parameter> object.transform.velocity<br><br>A vector() containing the object's speed. (measured from object center)
899
917 900 velocity: new vector(0, 0),
918 //<DOC> <parameter> object.transform.rotation<br><br>the object's rotation in degrees. Default is zero.
901
919 902 rotation: 0,
920 903
921 //<DOC> <parameter> object.transform.width<br><br>the width of the object, defaults to 32.
904
922 905 width: image? image.width : 0,
923 //<DOC> <parameter> object.transform.height<br><br>the height of the object, defaults to 32.
906
924 907 height: image? image.height: 0,
925 908
926 909 scale: new vector(1, 1),
927 910
928 //<DOC> <function> object.transform.pointTowards(point)<br><br>Adjust object.transform.rotation to point at vector2() 'point'.
911
929 912 pointTowards: function(point)
930 913 {
931 914 var delta = point.subtract(this.position);
@@ -933,25 +916,25 @@ var GameObject =
933 916 this.rotation = delta.toAngle();
934 917 },
935 918
936 //<DOC> <function> object.transform.left()<br><br>A single pixel left of the object, accounting for rotation.
919
937 920 left: function()
938 921 {
939 922 return this.g_dir(0);
940 923 },
941 924
942 //<DOC> <function> object.transform.right()<br><br>A single pixel right of the object, accounting for rotation.
925
943 926 right: function()
944 927 {
945 928 return this.g_dir(180);
946 929 },
947 930
948 //<DOC> <function> object.transform.forward()<br><br>A single pixel forwards of the object, accounting for rotation.
931
949 932 forward: function()
950 933 {
951 934 return this.g_dir(90);
952 935 },
953 936
954 //<DOC> <function> object.transform.back()<br><br>A single pixel backwards of the object, accounting for rotation.
937
955 938 back: function()
956 939 {
957 940 return this.g_dir(270);
@@ -971,7 +954,7 @@ var GameObject =
971 954 {
972 955 Game.activeScene.addObject(this);
973 956
974 //<DOC> <function> object.start()<br><br>Called on object's creation. Override this on your own object templates!
957
975 958 if (typeof this.start == 'function') { this.start(); }
976 959 }
977 960
@@ -1008,7 +991,7 @@ var GameObject =
1008 991 {
1009 992 if(this.draw)
1010 993 {
1011 //<DOC> <function> object.draw()<br><br>Called on each draw step. If not overridden, default draw is used!
994
1012 995 this.draw();
1013 996 }
1014 997 else
@@ -1065,7 +1048,7 @@ var GameObject =
1065 1048 }
1066 1049 else
1067 1050 {
1068 //<DOC> <function> object.update(deltaTime)<br><br>Called on each frame start! (Before collision checks of this frame) Override this on your own object templates!
1051
1069 1052 if (typeof this.update == 'function') { this.update(deltaTime); }
1070 1053
1071 1054 this.transform.position.x += this.transform.velocity.x;
@@ -1139,7 +1122,7 @@ var GameObject =
1139 1122 }
1140 1123 }
1141 1124
1142 //<DOC> <function> object.onCollision(other)<br><br>Called on object collision. Parameter 'other' is a reference to the object you're colliding with! Override this on your own object templates!
1125
1143 1126 if(hit)
1144 1127 if (!this.destroyed && typeof this.onCollision == 'function') { this.onCollision(o2); }
1145 1128 }
@@ -1148,12 +1131,12 @@ var GameObject =
1148 1131 }
1149 1132 }
1150 1133
1151 //<DOC> <function> object.destroy()<br><br>Destroys the current object at the end of the current update step.
1134
1152 1135 this.destroy = function()
1153 1136 {
1154 1137 if(!this.g_destroy)
1155 1138 {
1156 //<DOC> <function> object.onDestroy()<br><br>Called on object's destruction. Override this on your own object templates!
1139
1157 1140 if (typeof this.onDestroy == 'function') { this.onDestroy(); }
1158 1141
1159 1142 this.destroyed = true;
@@ -1351,28 +1334,28 @@ timingUtil =
1351 1334 }
1352 1335 }
1353 1336
1354 //<DOC> category vector()
1337
1355 1338
1356 1339 function vector(x, y)
1357 1340 {
1358 //<DOC> <parameter> vector.x<br><br>the X axis of the vector.
1341
1359 1342 this.x = x;
1360 //<DOC> <parameter> vector.y<br><br>the Y axis of the vector.
1343
1361 1344 this.y = y;
1362 1345
1363 //<DOC> <function> vector.length()<br><br>returns the length of the vector.
1346
1364 1347 this.length = function()
1365 1348 {
1366 1349 return Math.sqrt((this.x * this.x) + (this.y * this.y));
1367 1350 }
1368 1351
1369 //<DOC> <function> vector.toAngle()<br><br>Get the angle towards the vector's direction in degrees.
1352
1370 1353 this.toAngle = function()
1371 1354 {
1372 1355 return (Math.atan2(this.y, this.x) * 180 / Math.PI) + 90;
1373 1356 }
1374 1357
1375 //<DOC> <function> vector.normalize()<br><br>returns a normalized copy of the vector. Original vector is not modified.
1358
1376 1359 this.normalize = function()
1377 1360 {
1378 1361 var newVector = this.getCopy();
@@ -1387,7 +1370,7 @@ function vector(x, y)
1387 1370 return newVector;
1388 1371 }
1389 1372
1390 //<DOC> <function> vector.lerpTo(otherVector, t)<br><br> Returns a new vector between this vector and 'otherVector' at point 't'. 0t = original vector, 1t = 'otherVector', 0.5t is halfway in between.
1373
1391 1374 this.lerpTo = function(otherVector, t)
1392 1375 {
1393 1376 var delta = otherVector.subtract(this);
@@ -1395,7 +1378,7 @@ function vector(x, y)
1395 1378 return this.add(delta.stretch(t));
1396 1379 }
1397 1380
1398 //<DOC> <function> vector.distanceTo(otherVector)<br><br>returns the distance to another vector.
1381
1399 1382 this.distanceTo = function(otherVector)
1400 1383 {
1401 1384 var dX = this.x - otherVector.x;
@@ -1404,7 +1387,7 @@ function vector(x, y)
1404 1387 return new vector(dX, dY).length();
1405 1388 }
1406 1389
1407 //<DOC> <function> vector.add(otherVector)<br><br>adds the two vectors together, and returns as a copy. Original vector is not modified.
1390
1408 1391 this.add = function(otherVector)
1409 1392 {
1410 1393 var newVector = this.getCopy();
@@ -1415,7 +1398,7 @@ function vector(x, y)
1415 1398 return newVector;
1416 1399 }
1417 1400
1418 //<DOC> <function> vector.subtract(otherVector)<br><br>subtracts the second vector from this vector, and returns as a copy. Original vector is not modified.
1401
1419 1402 this.subtract = function(otherVector)
1420 1403 {
1421 1404 var newVector = this.getCopy();
@@ -1426,7 +1409,7 @@ function vector(x, y)
1426 1409 return newVector;
1427 1410 }
1428 1411
1429 //<DOC> <function> vector.multiply(otherVector)<br><br>multiplies the first vector X by the second vector's X, and the first's Y by the second's Y, and returns as a copy. Original vector is not modified.
1412
1430 1413 this.multiply = function(otherVector)
1431 1414 {
1432 1415 var newVector = this.getCopy();
@@ -1437,7 +1420,7 @@ function vector(x, y)
1437 1420 return newVector;
1438 1421 }
1439 1422
1440 //<DOC> <function> vector.divide(otherVector)<br><br>divides the first vector by the second, and returns as a copy. Original vector is not modified.
1423
1441 1424 this.divide = function(otherVector)
1442 1425 {
1443 1426 var newVector = this.getCopy();
@@ -1448,7 +1431,7 @@ function vector(x, y)
1448 1431 return newVector;
1449 1432 }
1450 1433
1451 //<DOC> <function> vector.stretch(length)<br><br>Multiplies the vector by the given numeric value, and returns as a copy. Original vector is not modified.
1434
1452 1435 this.stretch = function(length)
1453 1436 {
1454 1437 var newVector = this.getCopy();
@@ -1472,20 +1455,20 @@ function vector(x, y)
1472 1455 return this.x * otherVector.y - this.y * otherVector.x;
1473 1456 }
1474 1457
1475 //<DOC> <function> vector.getCopy()<br><br>returns a copy of this vector.
1458
1476 1459 this.getCopy = function()
1477 1460 {
1478 1461 return new vector(this.x, this.y);
1479 1462 }
1480 1463 }
1481 1464
1482 //<DOC> category GameWindow
1465
1483 1466
1484 1467 var GameWindow =
1485 1468 {
1486 //<DOC> <parameter> GameWindow.width<br>The game window's width. Cannot be changed.
1469
1487 1470 width: 0,
1488 //<DOC> <parameter> GameWindow.height<br>The game window's height. Cannot be changed.
1471
1489 1472 height: 0,
1490 1473
1491 1474 g_width: 0,
@@ -1493,7 +1476,7 @@ var GameWindow =
1493 1476
1494 1477 fullscreen: false,
1495 1478
1496 //<DOC> <parameter> GameWindow.backgroundColor<br>Background color. Contains an r, g and b component (0-255).
1479
1497 1480 backgroundColor:
1498 1481 {
1499 1482 r: 255,
@@ -1521,10 +1504,10 @@ var GameWindow =
1521 1504 //$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');
1522 1505 GameWindow.windowElement = document.getElementById(GameWindow.elementID);
1523 1506
1524 //<DOC> <parameter> GameWindow.canvas <br><br> The game's canvas element
1507
1525 1508 GameWindow.canvas = document.getElementById(GameWindow.elementID);
1526 1509
1527 //<DOC> <parameter> GameWindow.canvasContext <br><br>The game's canvasContext. Use this for drawing.
1510
1528 1511 GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
1529 1512
1530 1513 console.log("GAME: Window initialized: [" + width + ", " + height + "]");
@@ -1,10 +1,7 @@
1//<DOC> category GameAudio
2
3var GameAudio =
1var GameAudio =
4{
2{
5 active: false,
3 active: false,
6
4
7 //<DOC> <function> GameAudio.init(collection, containingFolder)<br><br>Starts the audio system, using an array of audio names 'collection' and a path 'containingFolder' in which the sounds can be found. Do not include file extentions in sound names!
8 init: function(collection, containingFolder)
5 init: function(collection, containingFolder)
9 {
6 {
10 console.log("GAME: Loading sounds. (Note: Only supported from online-source, will fail when executed on local files.)");
7 console.log("GAME: Loading sounds. (Note: Only supported from online-source, will fail when executed on local files.)");
@@ -43,7 +40,6 @@ var GameAudio =
43 }
40 }
44 },
41 },
45
42
46 //<DOC> <function> GameAudio.play(name)<br><br>plays a sound with the name 'name'.
47 play: function(name)
43 play: function(name)
48 {
44 {
49 if(this.active)
45 if(this.active)
@@ -448,8 +444,6 @@ var ease = {
448 }
444 }
449};
445};
450
446
451//engine
452
453var Engine =
447var Engine =
454{
448{
455 x: 0,
449 x: 0,
@@ -458,19 +452,15 @@ var Engine =
458 h: 0,//stored for window-building
452 h: 0,//stored for window-building
459}
453}
460
454
461//<DOC> category Game
462var Game =
455var Game =
463{
456{
464 stepPrevious: 0,
457 stepPrevious: 0,
465
458
466 //<DOC> <parameter> Game.activeScene.activeObjects<br><br>array containing all existing objects.
467 activeScene: new Scene(),
459 activeScene: new Scene(),
468 userUpdateCallback: null,
460 userUpdateCallback: null,
469
461
470 //<DOC> <parameter> Game.stepsSinceStart<br><br> Total amount of update steps since the start of the game.
471 stepsSinceStart: 0,
462 stepsSinceStart: 0,
472
463
473 //<DOC> <function> Game.initialize(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)<br><br>Starts the game, and creates a window at ('windowX', 'windowY'), using 'windowWidth' and 'windowHeight' as sizes for the game window in pixels. 'fps' controls the game's frames-per-second'. As soon as the game is loaded up, it'll call the function 'loadedCallback', so you can properly start the game.
474 initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)
464 initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)
475 {
465 {
476 console.log("GAME: Initializing. Loading dependencies...");
466 console.log("GAME: Initializing. Loading dependencies...");
@@ -495,13 +485,11 @@ var Game =
495 Game.activeScene = newScene;
485 Game.activeScene = newScene;
496 },
486 },
497
487
498 //<DOC> <function> Game.setUpdateFunction(callback)<br><br>Assigns a function 'callback(deltaTime)' to be called every frame of the game. You can use this to run global code for your game.
499 setUpdateFunction: function(callback)
488 setUpdateFunction: function(callback)
500 {
489 {
501 Game.userUpdateCallback = callback;
490 Game.userUpdateCallback = callback;
502 },
491 },
503
492
504 //<DOC> <function> Game.clearScene()<br><br>destroys every object in the scene.
505 clearScene: function()
493 clearScene: function()
506 {
494 {
507 Game.activeScene.destroy();
495 Game.activeScene.destroy();
@@ -576,16 +564,12 @@ Math.clamp = function(number, min, max)
576 return Math.min(max, Math.max(min, number));
564 return Math.min(max, Math.max(min, number));
577}
565}
578
566
579//<DOC> <category> Image
580//<DOC> <function> Constructor: new image(urlToImage, subImages = 1, subImagesPerRow = 1)
581function image(url, subImgTotal, perRow)
567function image(url, subImgTotal, perRow)
582{
568{
583 subImgTotal = subImgTotal || 1;
569 subImgTotal = subImgTotal || 1;
584 perRow = perRow || 1;
570 perRow = perRow || 1;
585
571
586 //<DOC> <parameter> image.subImages<br><br>The total number of subimages in the image. Defaults to 1.
587 this.subImages = subImgTotal;
572 this.subImages = subImgTotal;
588 //<DOC> <parameter> image.subImagesPerRow<br><br>The total number of subimages per row. Defaults to 1.
589 this.subImagesPerRow = perRow;
573 this.subImagesPerRow = perRow;
590
574
591 var body = document.body;
575 var body = document.body;
@@ -609,7 +593,6 @@ function image(url, subImgTotal, perRow)
609 }
593 }
610 });
594 });
611
595
612 //<DOC> <function> image.draw(sourceX, sourceY, sourceWidth, destX, destY, destWidth, destHeight, rotation, alpha)<br><br>Draw the image on screen.
613 this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)
596 this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)
614 {
597 {
615 var shouldDraw = true;
598 var shouldDraw = true;
@@ -644,7 +627,7 @@ function image(url, subImgTotal, perRow)
644 }
627 }
645}
628}
646
629
647//<DOC> category GameInput
630
648
631
649var GameInput =
632var GameInput =
650{
633{
@@ -757,7 +740,7 @@ var GameInput =
757 }
740 }
758 },
741 },
759
742
760 //<DOC> <function> GameInput.IsPressed(keyCode)<br><br>Returns true if the key with given code 'keyCode' was pressed this frame. Only returns true the frame the key is pressed once until the key is released and pressed again.
743
761 isPressed: function(keyCode)
744 isPressed: function(keyCode)
762 {
745 {
763 if(GameInput.g_ppressKeyStatus[keyCode] == null)
746 if(GameInput.g_ppressKeyStatus[keyCode] == null)
@@ -766,7 +749,7 @@ var GameInput =
766 return GameInput.g_ppressKeyStatus[keyCode];
749 return GameInput.g_ppressKeyStatus[keyCode];
767 },
750 },
768
751
769 //<DOC> <function> GameInput.isHeld(keyCode)<br><br>returns true if the key with given code 'keyCode' is currently pressed.
752
770 isHeld: function(keyCode)
753 isHeld: function(keyCode)
771 {
754 {
772 if(GameInput.g_pKeyStatus[keyCode] == null)
755 if(GameInput.g_pKeyStatus[keyCode] == null)
@@ -800,7 +783,7 @@ var GameInput =
800 }
783 }
801}//
784}//
802
785
803//<DOC> category GameObject
786
804
787
805var GameObject =
788var GameObject =
806{
789{
@@ -808,7 +791,7 @@ var GameObject =
808
791
809 destroyed: false,
792 destroyed: false,
810
793
811 //<DOC> <function> GameObject.create(template, x, y)<br><br>Creates a new Game Object using the object template 'template' at the position ('x', 'y')
794
812 create: function(template, x, y, image, layer)
795 create: function(template, x, y, image, layer)
813 {
796 {
814 var newObj = $.extend(true, {}, template);
797 var newObj = $.extend(true, {}, template);
@@ -835,28 +818,28 @@ var GameObject =
835
818
836 object: function(x, y, image) //DO NOT use any functions with prefix g_ in your game!
819 object: function(x, y, image) //DO NOT use any functions with prefix g_ in your game!
837 {
820 {
838 //<DOC> <parameter> object.active<br><br>Object is visible and executes it's code when this parameter is true. Set to false to hide and disable the object temporarily.
821
839 this.active = true;
822 this.active = true;
840 //<DOC> <parameter> object.name<br><br>The name of the current object. Defaults to "Object".
823
841 this.name = "Object";
824 this.name = "Object";
842 //<DOC> <parameter> object.image<br><br>An image object.
825
843 this.image = "";
826 this.image = "";
844
827
845 //<DOC> <parameter> object.ignoreCollisions<br><br>Ignores this object when checking for collisions. Useful for background objects.
828
846 this.ignoreCollisions = false;
829 this.ignoreCollisions = false;
847
830
848 //<DOC> <parameter> object.renderer<br><br>Used for methods and variables related to drawing the object on the screen.
831
849 this.renderer = {
832 this.renderer = {
850 //<DOC> <parameter> object.renderer.image<br><br>The image to draw.
833
851 image: image,
834 image: image,
852
835
853 //<DOC> <parameter> object.renderer.subImage<br><br>The current subimage to draw using the default draw method
836
854 subImage: 0,
837 subImage: 0,
855
838
856 //<DOC> <parameter> object.renderer.alpha<br><br>Image transparency (0-1) default: 1
839
857 alpha: 1,
840 alpha: 1,
858
841
859 //<DOC> <parameter> object.renderer.visible<br><br>Value indicating if the object should be drawn (true/false)
842
860 visible: true,
843 visible: true,
861
844
862 //used to correct NaN
845 //used to correct NaN
@@ -864,7 +847,7 @@ var GameObject =
864
847
865 g_layerDepth: 0,
848 g_layerDepth: 0,
866
849
867 //<DOC> <function> image.draw(x, y, w, h, rotation, alpha = 1)<br><br>Draw an image at (x,y), size (w,h), at an angle in degrees.
850
868 draw: function(x, y, w, h, rotation)
851 draw: function(x, y, w, h, rotation)
869 {
852 {
870 if(isNaN(this.subImage))
853 if(isNaN(this.subImage))
@@ -911,21 +894,21 @@ var GameObject =
911
894
912 this.transform =
895 this.transform =
913 {
896 {
914 //<DOC> <parameter> object.transform.position<br><br>A vector() containing the object's position. (measured from object center)
897
915 position: new vector(x, y),
898 position: new vector(x, y),
916 //<DOC> <parameter> object.transform.velocity<br><br>A vector() containing the object's speed. (measured from object center)
899
917 velocity: new vector(0, 0),
900 velocity: new vector(0, 0),
918 //<DOC> <parameter> object.transform.rotation<br><br>the object's rotation in degrees. Default is zero.
901
919 rotation: 0,
902 rotation: 0,
920
903
921 //<DOC> <parameter> object.transform.width<br><br>the width of the object, defaults to 32.
904
922 width: image? image.width : 0,
905 width: image? image.width : 0,
923 //<DOC> <parameter> object.transform.height<br><br>the height of the object, defaults to 32.
906
924 height: image? image.height: 0,
907 height: image? image.height: 0,
925
908
926 scale: new vector(1, 1),
909 scale: new vector(1, 1),
927
910
928 //<DOC> <function> object.transform.pointTowards(point)<br><br>Adjust object.transform.rotation to point at vector2() 'point'.
911
929 pointTowards: function(point)
912 pointTowards: function(point)
930 {
913 {
931 var delta = point.subtract(this.position);
914 var delta = point.subtract(this.position);
@@ -933,25 +916,25 @@ var GameObject =
933 this.rotation = delta.toAngle();
916 this.rotation = delta.toAngle();
934 },
917 },
935
918
936 //<DOC> <function> object.transform.left()<br><br>A single pixel left of the object, accounting for rotation.
919
937 left: function()
920 left: function()
938 {
921 {
939 return this.g_dir(0);
922 return this.g_dir(0);
940 },
923 },
941
924
942 //<DOC> <function> object.transform.right()<br><br>A single pixel right of the object, accounting for rotation.
925
943 right: function()
926 right: function()
944 {
927 {
945 return this.g_dir(180);
928 return this.g_dir(180);
946 },
929 },
947
930
948 //<DOC> <function> object.transform.forward()<br><br>A single pixel forwards of the object, accounting for rotation.
931
949 forward: function()
932 forward: function()
950 {
933 {
951 return this.g_dir(90);
934 return this.g_dir(90);
952 },
935 },
953
936
954 //<DOC> <function> object.transform.back()<br><br>A single pixel backwards of the object, accounting for rotation.
937
955 back: function()
938 back: function()
956 {
939 {
957 return this.g_dir(270);
940 return this.g_dir(270);
@@ -971,7 +954,7 @@ var GameObject =
971 {
954 {
972 Game.activeScene.addObject(this);
955 Game.activeScene.addObject(this);
973
956
974 //<DOC> <function> object.start()<br><br>Called on object's creation. Override this on your own object templates!
957
975 if (typeof this.start == 'function') { this.start(); }
958 if (typeof this.start == 'function') { this.start(); }
976 }
959 }
977
960
@@ -1008,7 +991,7 @@ var GameObject =
1008 {
991 {
1009 if(this.draw)
992 if(this.draw)
1010 {
993 {
1011 //<DOC> <function> object.draw()<br><br>Called on each draw step. If not overridden, default draw is used!
994
1012 this.draw();
995 this.draw();
1013 }
996 }
1014 else
997 else
@@ -1065,7 +1048,7 @@ var GameObject =
1065 }
1048 }
1066 else
1049 else
1067 {
1050 {
1068 //<DOC> <function> object.update(deltaTime)<br><br>Called on each frame start! (Before collision checks of this frame) Override this on your own object templates!
1051
1069 if (typeof this.update == 'function') { this.update(deltaTime); }
1052 if (typeof this.update == 'function') { this.update(deltaTime); }
1070
1053
1071 this.transform.position.x += this.transform.velocity.x;
1054 this.transform.position.x += this.transform.velocity.x;
@@ -1139,7 +1122,7 @@ var GameObject =
1139 }
1122 }
1140 }
1123 }
1141
1124
1142 //<DOC> <function> object.onCollision(other)<br><br>Called on object collision. Parameter 'other' is a reference to the object you're colliding with! Override this on your own object templates!
1125
1143 if(hit)
1126 if(hit)
1144 if (!this.destroyed && typeof this.onCollision == 'function') { this.onCollision(o2); }
1127 if (!this.destroyed && typeof this.onCollision == 'function') { this.onCollision(o2); }
1145 }
1128 }
@@ -1148,12 +1131,12 @@ var GameObject =
1148 }
1131 }
1149 }
1132 }
1150
1133
1151 //<DOC> <function> object.destroy()<br><br>Destroys the current object at the end of the current update step.
1134
1152 this.destroy = function()
1135 this.destroy = function()
1153 {
1136 {
1154 if(!this.g_destroy)
1137 if(!this.g_destroy)
1155 {
1138 {
1156 //<DOC> <function> object.onDestroy()<br><br>Called on object's destruction. Override this on your own object templates!
1139
1157 if (typeof this.onDestroy == 'function') { this.onDestroy(); }
1140 if (typeof this.onDestroy == 'function') { this.onDestroy(); }
1158
1141
1159 this.destroyed = true;
1142 this.destroyed = true;
@@ -1351,28 +1334,28 @@ timingUtil =
1351 }
1334 }
1352}
1335}
1353
1336
1354//<DOC> category vector()
1337
1355
1338
1356function vector(x, y)
1339function vector(x, y)
1357{
1340{
1358 //<DOC> <parameter> vector.x<br><br>the X axis of the vector.
1341
1359 this.x = x;
1342 this.x = x;
1360 //<DOC> <parameter> vector.y<br><br>the Y axis of the vector.
1343
1361 this.y = y;
1344 this.y = y;
1362
1345
1363 //<DOC> <function> vector.length()<br><br>returns the length of the vector.
1346
1364 this.length = function()
1347 this.length = function()
1365 {
1348 {
1366 return Math.sqrt((this.x * this.x) + (this.y * this.y));
1349 return Math.sqrt((this.x * this.x) + (this.y * this.y));
1367 }
1350 }
1368
1351
1369 //<DOC> <function> vector.toAngle()<br><br>Get the angle towards the vector's direction in degrees.
1352
1370 this.toAngle = function()
1353 this.toAngle = function()
1371 {
1354 {
1372 return (Math.atan2(this.y, this.x) * 180 / Math.PI) + 90;
1355 return (Math.atan2(this.y, this.x) * 180 / Math.PI) + 90;
1373 }
1356 }
1374
1357
1375 //<DOC> <function> vector.normalize()<br><br>returns a normalized copy of the vector. Original vector is not modified.
1358
1376 this.normalize = function()
1359 this.normalize = function()
1377 {
1360 {
1378 var newVector = this.getCopy();
1361 var newVector = this.getCopy();
@@ -1387,7 +1370,7 @@ function vector(x, y)
1387 return newVector;
1370 return newVector;
1388 }
1371 }
1389
1372
1390 //<DOC> <function> vector.lerpTo(otherVector, t)<br><br> Returns a new vector between this vector and 'otherVector' at point 't'. 0t = original vector, 1t = 'otherVector', 0.5t is halfway in between.
1373
1391 this.lerpTo = function(otherVector, t)
1374 this.lerpTo = function(otherVector, t)
1392 {
1375 {
1393 var delta = otherVector.subtract(this);
1376 var delta = otherVector.subtract(this);
@@ -1395,7 +1378,7 @@ function vector(x, y)
1395 return this.add(delta.stretch(t));
1378 return this.add(delta.stretch(t));
1396 }
1379 }
1397
1380
1398 //<DOC> <function> vector.distanceTo(otherVector)<br><br>returns the distance to another vector.
1381
1399 this.distanceTo = function(otherVector)
1382 this.distanceTo = function(otherVector)
1400 {
1383 {
1401 var dX = this.x - otherVector.x;
1384 var dX = this.x - otherVector.x;
@@ -1404,7 +1387,7 @@ function vector(x, y)
1404 return new vector(dX, dY).length();
1387 return new vector(dX, dY).length();
1405 }
1388 }
1406
1389
1407 //<DOC> <function> vector.add(otherVector)<br><br>adds the two vectors together, and returns as a copy. Original vector is not modified.
1390
1408 this.add = function(otherVector)
1391 this.add = function(otherVector)
1409 {
1392 {
1410 var newVector = this.getCopy();
1393 var newVector = this.getCopy();
@@ -1415,7 +1398,7 @@ function vector(x, y)
1415 return newVector;
1398 return newVector;
1416 }
1399 }
1417
1400
1418 //<DOC> <function> vector.subtract(otherVector)<br><br>subtracts the second vector from this vector, and returns as a copy. Original vector is not modified.
1401
1419 this.subtract = function(otherVector)
1402 this.subtract = function(otherVector)
1420 {
1403 {
1421 var newVector = this.getCopy();
1404 var newVector = this.getCopy();
@@ -1426,7 +1409,7 @@ function vector(x, y)
1426 return newVector;
1409 return newVector;
1427 }
1410 }
1428
1411
1429 //<DOC> <function> vector.multiply(otherVector)<br><br>multiplies the first vector X by the second vector's X, and the first's Y by the second's Y, and returns as a copy. Original vector is not modified.
1412
1430 this.multiply = function(otherVector)
1413 this.multiply = function(otherVector)
1431 {
1414 {
1432 var newVector = this.getCopy();
1415 var newVector = this.getCopy();
@@ -1437,7 +1420,7 @@ function vector(x, y)
1437 return newVector;
1420 return newVector;
1438 }
1421 }
1439
1422
1440 //<DOC> <function> vector.divide(otherVector)<br><br>divides the first vector by the second, and returns as a copy. Original vector is not modified.
1423
1441 this.divide = function(otherVector)
1424 this.divide = function(otherVector)
1442 {
1425 {
1443 var newVector = this.getCopy();
1426 var newVector = this.getCopy();
@@ -1448,7 +1431,7 @@ function vector(x, y)
1448 return newVector;
1431 return newVector;
1449 }
1432 }
1450
1433
1451 //<DOC> <function> vector.stretch(length)<br><br>Multiplies the vector by the given numeric value, and returns as a copy. Original vector is not modified.
1434
1452 this.stretch = function(length)
1435 this.stretch = function(length)
1453 {
1436 {
1454 var newVector = this.getCopy();
1437 var newVector = this.getCopy();
@@ -1472,20 +1455,20 @@ function vector(x, y)
1472 return this.x * otherVector.y - this.y * otherVector.x;
1455 return this.x * otherVector.y - this.y * otherVector.x;
1473 }
1456 }
1474
1457
1475 //<DOC> <function> vector.getCopy()<br><br>returns a copy of this vector.
1458
1476 this.getCopy = function()
1459 this.getCopy = function()
1477 {
1460 {
1478 return new vector(this.x, this.y);
1461 return new vector(this.x, this.y);
1479 }
1462 }
1480}
1463}
1481
1464
1482//<DOC> category GameWindow
1465
1483
1466
1484var GameWindow =
1467var GameWindow =
1485{
1468{
1486 //<DOC> <parameter> GameWindow.width<br>The game window's width. Cannot be changed.
1469
1487 width: 0,
1470 width: 0,
1488 //<DOC> <parameter> GameWindow.height<br>The game window's height. Cannot be changed.
1471
1489 height: 0,
1472 height: 0,
1490
1473
1491 g_width: 0,
1474 g_width: 0,
@@ -1493,7 +1476,7 @@ var GameWindow =
1493
1476
1494 fullscreen: false,
1477 fullscreen: false,
1495
1478
1496 //<DOC> <parameter> GameWindow.backgroundColor<br>Background color. Contains an r, g and b component (0-255).
1479
1497 backgroundColor:
1480 backgroundColor:
1498 {
1481 {
1499 r: 255,
1482 r: 255,
@@ -1521,10 +1504,10 @@ var GameWindow =
1521 //$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');
1504 //$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');
1522 GameWindow.windowElement = document.getElementById(GameWindow.elementID);
1505 GameWindow.windowElement = document.getElementById(GameWindow.elementID);
1523
1506
1524 //<DOC> <parameter> GameWindow.canvas <br><br> The game's canvas element
1507
1525 GameWindow.canvas = document.getElementById(GameWindow.elementID);
1508 GameWindow.canvas = document.getElementById(GameWindow.elementID);
1526
1509
1527 //<DOC> <parameter> GameWindow.canvasContext <br><br>The game's canvasContext. Use this for drawing.
1510
1528 GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
1511 GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
1529
1512
1530 console.log("GAME: Window initialized: [" + width + ", " + height + "]");
1513 console.log("GAME: Window initialized: [" + width + ", " + height + "]");
js/lastbuild.txt +1 −0
@@ -31,3 +31,4 @@
31 31 10:59
32 32 11:07
33 33 11:12
34 13:17
@@ -31,3 +31,4 @@
31 10:59
31 10:59
32 11:07
32 11:07
33 11:12
33 11:12
34 13:17