BlueGit

timfa frameworkv3

Merge branch 'dev3'

timfa Tim Falken · pushed by timfa

Authored 2021-07-01 · 5 years ago

Hash
9775c678d64da2bac43a3e11489b6bb5e5304528
4 files changed +16 −6
framework/engine.js +3 −4
@@ -17,7 +17,7 @@ var Game =
17 17
18 18 queuedCallbacks: [],
19 19
20 initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)
20 initialize: function(windowX, windowY, windowWidth, windowHeight, loadedCallback)
21 21 {
22 22 console.log("GAME: Initializing. Loading dependencies...");
23 23 Engine.x = windowX;
@@ -28,7 +28,8 @@ var Game =
28 28 GameWindow.init(Engine.x, Engine.y, Engine.w, Engine.h);
29 29 GameInput.g_init();
30 30 TextInput.g_init();
31 window.setInterval(Game.gameStep, 1000 / fps);
31 window.setInterval(Game.gameStep, 1);
32 GameWindow.redraw();
32 33 loadedCallback();
33 34 },
34 35
@@ -94,8 +95,6 @@ var Game =
94 95
95 96 if (typeof Game.userUpdateCallback == 'function') { Game.userUpdateCallback(stepTimeCurr); }
96 97
97 GameWindow.redraw();
98
99 98 this.stepPrevious = stepTime;
100 99 },
101 100
@@ -17,7 +17,7 @@ var Game =
17
17
18 queuedCallbacks: [],
18 queuedCallbacks: [],
19
19
20 initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)
20 initialize: function(windowX, windowY, windowWidth, windowHeight, loadedCallback)
21 {
21 {
22 console.log("GAME: Initializing. Loading dependencies...");
22 console.log("GAME: Initializing. Loading dependencies...");
23 Engine.x = windowX;
23 Engine.x = windowX;
@@ -28,7 +28,8 @@ var Game =
28 GameWindow.init(Engine.x, Engine.y, Engine.w, Engine.h);
28 GameWindow.init(Engine.x, Engine.y, Engine.w, Engine.h);
29 GameInput.g_init();
29 GameInput.g_init();
30 TextInput.g_init();
30 TextInput.g_init();
31 window.setInterval(Game.gameStep, 1000 / fps);
31 window.setInterval(Game.gameStep, 1);
32 GameWindow.redraw();
32 loadedCallback();
33 loadedCallback();
33 },
34 },
34
35
@@ -94,8 +95,6 @@ var Game =
94
95
95 if (typeof Game.userUpdateCallback == 'function') { Game.userUpdateCallback(stepTimeCurr); }
96 if (typeof Game.userUpdateCallback == 'function') { Game.userUpdateCallback(stepTimeCurr); }
96
97
97 GameWindow.redraw();
98
99 this.stepPrevious = stepTime;
98 this.stepPrevious = stepTime;
100 },
99 },
101
100
framework/object.js +2 −0
@@ -20,6 +20,8 @@ var GameObject =
20 20 GameObject.allObjects = [];
21 21
22 22 GameObject.allObjects.push(newObj);
23
24 Game.reorderObjects();
23 25
24 26 return newObj;
25 27 },
@@ -20,6 +20,8 @@ var GameObject =
20 GameObject.allObjects = [];
20 GameObject.allObjects = [];
21
21
22 GameObject.allObjects.push(newObj);
22 GameObject.allObjects.push(newObj);
23
24 Game.reorderObjects();
23
25
24 return newObj;
26 return newObj;
25 },
27 },
framework/vector.js +7 −0
@@ -106,6 +106,13 @@ function vector(x, y)
106 106 return newVector;
107 107 }
108 108
109 this.rotate = function(degrees)
110 {
111 var ca = Math.cos(degrees * (Math.PI / 180));
112 var sa = Math.sin(degrees * (Math.PI / 180));
113 return new vector(ca*this.x - sa*this.y, sa*this.x + ca*this.y);
114 }
115
109 116 this.deltaAngle = function(otherVector)
110 117 {
111 118 var a = this.toAngle() * (Math.PI / 180);
@@ -106,6 +106,13 @@ function vector(x, y)
106 return newVector;
106 return newVector;
107 }
107 }
108
108
109 this.rotate = function(degrees)
110 {
111 var ca = Math.cos(degrees * (Math.PI / 180));
112 var sa = Math.sin(degrees * (Math.PI / 180));
113 return new vector(ca*this.x - sa*this.y, sa*this.x + ca*this.y);
114 }
115
109 this.deltaAngle = function(otherVector)
116 this.deltaAngle = function(otherVector)
110 {
117 {
111 var a = this.toAngle() * (Math.PI / 180);
118 var a = this.toAngle() * (Math.PI / 180);
framework/window.js +4 −2
@@ -67,13 +67,15 @@ var GameWindow =
67 67 GameWindow.canvas.width = GameWindow.width;
68 68 GameWindow.canvas.height = GameWindow.height;
69 69
70 this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + this.backgroundColor.g + "," + this.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
71 this.canvasContext.fillRect(0, 0, this.width, this.height);
70 GameWindow.canvasContext.fillStyle = "rgb(" + GameWindow.backgroundColor.r + "," + GameWindow.backgroundColor.g + "," + GameWindow.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
71 GameWindow.canvasContext.fillRect(0, 0, GameWindow.width, GameWindow.height);
72 72
73 73 for(var i = 0; i < Game.activeScene.activeObjects.length; i++)
74 74 {
75 75 if(Game.activeScene.activeObjects[i].active && Game.activeScene.activeObjects[i].renderer.visible)
76 76 Game.activeScene.activeObjects[i].g_draw(GameWindow.canvasContext);
77 77 }
78
79 requestAnimationFrame(GameWindow.redraw);
78 80 }
79 81 }
@@ -67,13 +67,15 @@ var GameWindow =
67 GameWindow.canvas.width = GameWindow.width;
67 GameWindow.canvas.width = GameWindow.width;
68 GameWindow.canvas.height = GameWindow.height;
68 GameWindow.canvas.height = GameWindow.height;
69
69
70 this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + this.backgroundColor.g + "," + this.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
70 GameWindow.canvasContext.fillStyle = "rgb(" + GameWindow.backgroundColor.r + "," + GameWindow.backgroundColor.g + "," + GameWindow.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
71 this.canvasContext.fillRect(0, 0, this.width, this.height);
71 GameWindow.canvasContext.fillRect(0, 0, GameWindow.width, GameWindow.height);
72
72
73 for(var i = 0; i < Game.activeScene.activeObjects.length; i++)
73 for(var i = 0; i < Game.activeScene.activeObjects.length; i++)
74 {
74 {
75 if(Game.activeScene.activeObjects[i].active && Game.activeScene.activeObjects[i].renderer.visible)
75 if(Game.activeScene.activeObjects[i].active && Game.activeScene.activeObjects[i].renderer.visible)
76 Game.activeScene.activeObjects[i].g_draw(GameWindow.canvasContext);
76 Game.activeScene.activeObjects[i].g_draw(GameWindow.canvasContext);
77 }
77 }
78
79 requestAnimationFrame(GameWindow.redraw);
78 }
80 }
79}
81}