fix rendering
@@ -27,7 +27,7 @@ function image(url, subImgTotal, perRow)
27
27
}
28
28
});
29
29
30
this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)
30
this.draw = function(scene, sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)
31
31
{
32
32
var shouldDraw = true;
33
33
@@ -37,15 +37,15 @@ function image(url, subImgTotal, perRow)
37
37
if(dy < -Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))
38
38
shouldDraw = false;
39
39
40
if(dx > GameWindow.width + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))
40
if(dx > scene.size.x + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))
41
41
shouldDraw = false;
42
42
43
if(dy > GameWindow.height + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))
43
if(dy > scene.size.y + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))
44
44
shouldDraw = false;
45
45
46
46
if(shouldDraw)
47
47
{
48
var context = GameWindow.canvasContext;
48
var context = scene.context;
49
49
context.save();
50
50
var oldAlpha = context.globalAlpha;
51
51
context.globalAlpha = alpha;
@@ -27,7 +27,7 @@ function image(url, subImgTotal, perRow)27
}27
}28
});28
});29
29
30
this.draw = function(sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)30
this.draw = function(scene, sx, sy, sw, sh, dx, dy, dw, dh, rotation, alpha)31
{ 31
{ 32
var shouldDraw = true;32
var shouldDraw = true;33
33
@@ -37,15 +37,15 @@ function image(url, subImgTotal, perRow)37
if(dy < -Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))37
if(dy < -Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))38
shouldDraw = false;38
shouldDraw = false;39
39
40
if(dx > GameWindow.width + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))40
if(dx > scene.size.x + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))41
shouldDraw = false;41
shouldDraw = false;42
42
43
if(dy > GameWindow.height + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))43
if(dy > scene.size.y + Math.sqrt(Math.pow(dw, 2) + Math.pow(dh, 2)))44
shouldDraw = false;44
shouldDraw = false;45
45
46
if(shouldDraw)46
if(shouldDraw)47
{47
{48
var context = GameWindow.canvasContext;48
var context = scene.context;49
context.save(); 49
context.save(); 50
var oldAlpha = context.globalAlpha;50
var oldAlpha = context.globalAlpha;51
context.globalAlpha = alpha;51
context.globalAlpha = alpha;@@ -40,7 +40,7 @@ class Renderer
40
40
}
41
41
42
42
var subImage = Math.round(this.subImage);
43
subImage %= this.image.subImages;
43
subImage %= this.sprite.subImages;
44
44
45
45
var c = subImage % this.sprite.subImagesPerRow;
46
46
var r = Math.floor(subImage / this.sprite.subImagesPerRow);
@@ -49,7 +49,8 @@ class Renderer
49
49
var sx = sw * c;
50
50
var sy = sh * r;
51
51
52
this.image.draw(
52
this.sprite.draw(
53
this.gameObject.scene,
53
54
sx, sy, sw, sh,
54
55
this.gameObject.transform.position.x,
55
56
this.gameObject.transform.position.y,
@@ -40,7 +40,7 @@ class Renderer40
}40
}41
41
42
var subImage = Math.round(this.subImage);42
var subImage = Math.round(this.subImage);43
subImage %= this.image.subImages;43
subImage %= this.sprite.subImages;44
44
45
var c = subImage % this.sprite.subImagesPerRow;45
var c = subImage % this.sprite.subImagesPerRow;46
var r = Math.floor(subImage / this.sprite.subImagesPerRow);46
var r = Math.floor(subImage / this.sprite.subImagesPerRow);@@ -49,7 +49,8 @@ class Renderer49
var sx = sw * c;49
var sx = sw * c;50
var sy = sh * r;50
var sy = sh * r;51
51
52
this.image.draw(52
this.sprite.draw(53
this.gameObject.scene,53
sx, sy, sw, sh, 54
sx, sy, sw, sh, 54
this.gameObject.transform.position.x, 55
this.gameObject.transform.position.x, 55
this.gameObject.transform.position.y, 56
this.gameObject.transform.position.y, @@ -25,6 +25,12 @@ class Transform
25
25
this.velocity = new vector(0, 0)
26
26
}
27
27
28
update(deltaTime)
29
{
30
this.position = this.position.add(this.velocity.stretch(deltaTime));
31
this.rotation += this.angularVelocity * deltaTime;
32
}
33
28
34
pointTowards(point)
29
35
{
30
36
var delta = point.subtract(this.position);
@@ -25,6 +25,12 @@ class Transform25
this.velocity = new vector(0, 0)25
this.velocity = new vector(0, 0)26
}26
}27
27
28
update(deltaTime)29
{30
this.position = this.position.add(this.velocity.stretch(deltaTime));31
this.rotation += this.angularVelocity * deltaTime;32
}33
28
pointTowards(point)34
pointTowards(point)29
{35
{30
var delta = point.subtract(this.position);36
var delta = point.subtract(this.position);@@ -22,6 +22,7 @@ class Scene
22
22
23
23
this.position = new vector(x, y);
24
24
this.size = new vector(width, height);
25
this.cameraPosition = new vector(0, 0)
25
26
this.fullscreen = fullscreen;
26
27
27
28
if(this.fullscreen)
@@ -116,8 +117,8 @@ class Scene
116
117
117
118
for(var i = 0; i < this.activeObjects.length; i++)
118
119
{
119
if(this.activeObjects[i].active && this.activeObjects[i].renderer.visible)
120
this.activeObjects[i].g_draw(this.context);
120
if(!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
121
this.activeObjects[i].renderer.draw(this.context);
121
122
}
122
123
}
123
124
}
@@ -22,6 +22,7 @@ class Scene22
22
23
this.position = new vector(x, y);23
this.position = new vector(x, y);24
this.size = new vector(width, height);24
this.size = new vector(width, height);25
this.cameraPosition = new vector(0, 0)25
this.fullscreen = fullscreen;26
this.fullscreen = fullscreen;26
27
27
if(this.fullscreen)28
if(this.fullscreen)@@ -116,8 +117,8 @@ class Scene116
117
117
for(var i = 0; i < this.activeObjects.length; i++)118
for(var i = 0; i < this.activeObjects.length; i++)118
{119
{119
if(this.activeObjects[i].active && this.activeObjects[i].renderer.visible)120
if(!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)120
this.activeObjects[i].g_draw(this.context);121
this.activeObjects[i].renderer.draw(this.context);121
}122
}122
}123
}123
}124
}