BlueGit

blue-star speeltuin

grasse

timfa Tim · pushed by timfa

Authored 2022-10-15 · 4 years ago

Hash
45deaf4be0c85c8c8e7bfd044ff3be2df9f72619
Parent
caf93735
5 files changed +41 −3
build/framework.js +8 −1
@@ -91,6 +91,11 @@ class GameObject
91 91 this.scene.removeObject(this);
92 92 }
93 93 }
94
95 draw()
96 {
97 this.renderer.draw();
98 }
94 99 }
95 100 /*
96 101 * End File:
@@ -538,6 +543,8 @@ class Scene
538 543
539 544 this.activeObjects.push(obj);
540 545 obj.scene = this;
546
547 obj.addedToScene && obj.addedToScene();
541 548 }
542 549
543 550 removeObject(obj)
@@ -600,7 +607,7 @@ class Scene
600 607 for(var i = 0; i < this.activeObjects.length; i++)
601 608 {
602 609 if(!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
603 this.activeObjects[i].renderer.draw(this.context);
610 this.activeObjects[i].draw(this.context);
604 611 }
605 612 }
606 613 }
@@ -91,6 +91,11 @@ class GameObject
91 this.scene.removeObject(this);
91 this.scene.removeObject(this);
92 }
92 }
93 }
93 }
94
95 draw()
96 {
97 this.renderer.draw();
98 }
94}
99}
95/*
100/*
96 * End File:
101 * End File:
@@ -538,6 +543,8 @@ class Scene
538
543
539 this.activeObjects.push(obj);
544 this.activeObjects.push(obj);
540 obj.scene = this;
545 obj.scene = this;
546
547 obj.addedToScene && obj.addedToScene();
541 }
548 }
542
549
543 removeObject(obj)
550 removeObject(obj)
@@ -600,7 +607,7 @@ class Scene
600 for(var i = 0; i < this.activeObjects.length; i++)
607 for(var i = 0; i < this.activeObjects.length; i++)
601 {
608 {
602 if(!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
609 if(!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
603 this.activeObjects[i].renderer.draw(this.context);
610 this.activeObjects[i].draw(this.context);
604 }
611 }
605 }
612 }
606}
613}
build/images/grass_dark.png added Binary file +0 −0

The contents of this binary file are not shown.

build/images/grass_light.png added Binary file +0 −0

The contents of this binary file are not shown.

src/game.js +5 −2
@@ -4,14 +4,17 @@ window.onload = function()
4 4 var game = new Game();
5 5
6 6 var scene = new Scene(0, 0, 1, 1, Scene.DisplayModes.relativeToParent);
7 game.activeScenes.push(scene);
7 game.loadScene(scene);
8 8
9 9 game.images =
10 10 {
11 arrow: new image("images/arrow.png")
11 arrow: new image("images/arrow.png"),
12 grass_light: new image("images/grass_light.png"),
13 grass_dark: new image("images/grass_dark.png")
12 14 }
13 15
14 16 game.startGame();
15 17
18 scene.addObject(new GrassTiler(50, 50, game.images.arrow, 0));
16 19 scene.addObject(new Arrow(50, 50, game.images.arrow, 0));
17 20 }
@@ -4,14 +4,17 @@ window.onload = function()
4 var game = new Game();
4 var game = new Game();
5
5
6 var scene = new Scene(0, 0, 1, 1, Scene.DisplayModes.relativeToParent);
6 var scene = new Scene(0, 0, 1, 1, Scene.DisplayModes.relativeToParent);
7 game.activeScenes.push(scene);
7 game.loadScene(scene);
8
8
9 game.images =
9 game.images =
10 {
10 {
11 arrow: new image("images/arrow.png")
11 arrow: new image("images/arrow.png"),
12 grass_light: new image("images/grass_light.png"),
13 grass_dark: new image("images/grass_dark.png")
12 }
14 }
13
15
14 game.startGame();
16 game.startGame();
15
17
18 scene.addObject(new GrassTiler(50, 50, game.images.arrow, 0));
16 scene.addObject(new Arrow(50, 50, game.images.arrow, 0));
19 scene.addObject(new Arrow(50, 50, game.images.arrow, 0));
17}
20}
src/objects/grasstiler.js added +28 −0
@@ -0,0 +1,28 @@
1 class GrassTiler extends GameObject
2 {
3 ground_light = null;
4 ground_dark = null;
5
6 addedToScene()
7 {
8 this.ground_dark = this.scene.game.images.grass_dark;
9 this.ground_light = this.scene.game.images.grass_light;
10 }
11
12 draw(context)
13 {
14 let width = this.scene.real_size.x + this.ground_dark.width
15 let height = this.scene.real_size.y + this.ground_dark.height
16 let count = 0;
17 for(let x = 0; x < width; x += this.ground_dark.width)
18 {
19 for(let y = 0; y < height; y += this.ground_light.height)
20 {
21 count++;
22 ((count) %2 == 1? this.ground_dark : this.ground_light).draw(this.scene, 0, 0, this.ground_dark.width, this.ground_dark.height, x, y, this.ground_dark.width, this.ground_light.height, 0, 1)
23 }
24
25 count = x/64 % 2;
26 }
27 }
28 }
@@ -0,0 +1,28 @@
1class GrassTiler extends GameObject
2{
3 ground_light = null;
4 ground_dark = null;
5
6 addedToScene()
7 {
8 this.ground_dark = this.scene.game.images.grass_dark;
9 this.ground_light = this.scene.game.images.grass_light;
10 }
11
12 draw(context)
13 {
14 let width = this.scene.real_size.x + this.ground_dark.width
15 let height = this.scene.real_size.y + this.ground_dark.height
16 let count = 0;
17 for(let x = 0; x < width; x += this.ground_dark.width)
18 {
19 for(let y = 0; y < height; y += this.ground_light.height)
20 {
21 count++;
22 ((count) %2 == 1? this.ground_dark : this.ground_light).draw(this.scene, 0, 0, this.ground_dark.width, this.ground_dark.height, x, y, this.ground_dark.width, this.ground_light.height, 0, 1)
23 }
24
25 count = x/64 % 2;
26 }
27 }
28}