Skip to content

Commit c2a094c

Browse files
authored
Merge pull request #12 from mikedotJS/feat/sort-actors
Sort actors by Y values
2 parents 2bde590 + 3217fff commit c2a094c

File tree

7 files changed

+22
-2
lines changed

7 files changed

+22
-2
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import { pirateActor } from "./pirate";
2+
import { thiefActor } from "./thief";
23

3-
export const actors = [pirateActor];
4+
export const actors = [pirateActor, thiefActor];

examples/monkey-island/rooms/scumm-bar/actors/pirate/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import imagePath from "./pirate.gif";
1+
import imagePath from "./image.gif";
22

33
export const pirateActor = {
44
x: 380,
5.61 KB
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import imagePath from "./image.gif";
2+
3+
export const thiefActor = {
4+
x: 500,
5+
y: 340,
6+
id: "thief",
7+
name: "Thief",
8+
imagePath,
9+
width: 202,
10+
height: 274,
11+
inventory: []
12+
};

src/room/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export class Room extends Renderable implements IRoom {
6161
init(): void {
6262
super.init();
6363

64+
// Sort actors by Y values
65+
this.actors = new Map(
66+
Array.from(this.actors.entries()).sort(([, a], [, b]) => a.y - b.y)
67+
);
68+
69+
// Init actors
6470
this.actors.forEach(actor => {
6571
actor.init();
6672
});

src/room/interface.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ export interface IRoom extends IRenderable {
2929

3030
registerItem(item: IItem): void;
3131
registerActor(actor: IActor): void;
32+
init(): void;
3233
}

0 commit comments

Comments
 (0)