|
6 | 6 | let active = null
|
7 | 7 |
|
8 | 8 | const places = {
|
9 |
| - "Alice's House": {x: 310, y: 90}, |
10 |
| - "Bob's House": {x: 312, y: 196}, |
11 |
| - "Cabin": {x: 378, y: 60}, |
12 |
| - "Post Office": {x: 215, y: 60}, |
13 |
| - "Town Hall": {x: 213, y: 200}, |
14 |
| - "Daria's House": {x: 170, y: 282}, |
15 |
| - "Ernie's House": {x: 69, y: 283}, |
16 |
| - "Grete's House": {x: 37, y: 193}, |
17 |
| - "Farm": {x: 61, y: 119}, |
18 |
| - "Shop": {x: 113, y: 211}, |
19 |
| - "Marketplace": {x: 200, y: 98} |
| 9 | + "Alice's House": {x: 279, y: 100}, |
| 10 | + "Bob's House": {x: 295, y: 203}, |
| 11 | + "Cabin": {x: 372, y: 67}, |
| 12 | + "Daria's House": {x: 183, y: 285}, |
| 13 | + "Ernie's House": {x: 50, y: 283}, |
| 14 | + "Farm": {x: 36, y: 118}, |
| 15 | + "Grete's House": {x: 35, y: 187}, |
| 16 | + "Marketplace": {x: 162, y: 110}, |
| 17 | + "Post Office": {x: 205, y: 57}, |
| 18 | + "Shop": {x: 137, y: 212}, |
| 19 | + "Town Hall": {x: 202, y: 213} |
20 | 20 | }
|
| 21 | + const placeKeys = Object.keys(places) |
21 | 22 |
|
22 | 23 | const speed = 2
|
23 | 24 |
|
|
30 | 31 |
|
31 | 32 | let outer = (window.__sandbox ? window.__sandbox.output.div : document.body), doc = outer.ownerDocument
|
32 | 33 | this.node = outer.appendChild(doc.createElement("div"))
|
33 |
| - this.node.style.cssText = "position: relative; line-height: 0.1; padding-left: 10px" |
| 34 | + this.node.style.cssText = "position: relative; line-height: 0.1; margin-left: 10px" |
34 | 35 | this.map = this.node.appendChild(doc.createElement("img"))
|
35 | 36 | this.map.src = "img/village2x.png"
|
36 | 37 | this.map.style.cssText = "vertical-align: -8px"
|
37 | 38 | this.robotElt = this.node.appendChild(doc.createElement("div"))
|
38 | 39 | this.robotElt.style.cssText = `position: absolute; transition: left ${0.8 / speed}s, top ${0.8 / speed}s;`
|
39 | 40 | let robotPic = this.robotElt.appendChild(doc.createElement("img"))
|
40 |
| - robotPic.src = "img/robot2x.png" |
| 41 | + robotPic.src = "img/robot_moving2x.gif" |
41 | 42 | this.parcels = []
|
42 | 43 |
|
43 | 44 | this.text = this.node.appendChild(doc.createElement("span"))
|
|
57 | 58 |
|
58 | 59 | updateView() {
|
59 | 60 | let pos = places[this.worldState.place]
|
60 |
| - this.robotElt.style.top = (pos.y - this.robotElt.offsetHeight) + "px" |
61 |
| - this.robotElt.style.left = (pos.x - (this.robotElt.offsetWidth / 2)) + "px" |
| 61 | + this.robotElt.style.top = (pos.y - 38) + "px" |
| 62 | + this.robotElt.style.left = (pos.x - 16) + "px" |
62 | 63 |
|
63 | 64 | this.text.textContent = ` Turn ${this.turn} `
|
64 | 65 | }
|
|
70 | 71 | let height = heights[place] || (heights[place] = 0)
|
71 | 72 | heights[place] += 11
|
72 | 73 | let node = document.createElement("div")
|
73 |
| - node.style.cssText = "position: absolute; height: 10px; width: 10px; background-image: url(img/parcel2x.png); font-size: 10px; text-align: center; line-height: 10px; font-family: sans-serif" |
74 |
| - node.textContent = address.charAt(0) |
| 74 | + let offset = placeKeys.indexOf(address) * 10 |
| 75 | + node.style.cssText = "position: absolute; height: 10px; width: 10px; background-image: url(img/parcel2x.png); background-position: 0 -" + offset + "px"; |
75 | 76 | if (place == this.worldState.place) {
|
76 |
| - node.style.right = "-5px" |
77 |
| - node.style.bottom = (24 + height) + "px" |
| 77 | + node.style.left = "27px" |
| 78 | + node.style.bottom = (20 + height) + "px" |
78 | 79 | this.robotElt.appendChild(node)
|
79 | 80 | } else {
|
80 | 81 | let pos = places[place]
|
|
95 | 96 | if (this.worldState.parcels.length == 0) {
|
96 | 97 | this.button.remove()
|
97 | 98 | this.text.textContent = ` Finished after ${this.turn} turns`
|
| 99 | + this.robotElt.firstChild.src = "img/robot_idle2x.png" |
98 | 100 | } else {
|
99 | 101 | this.schedule()
|
100 | 102 | }
|
|
108 | 110 | if (this.timeout == null) {
|
109 | 111 | this.schedule()
|
110 | 112 | this.button.textContent = "Stop"
|
| 113 | + this.robotElt.firstChild.src = "img/robot_moving2x.gif" |
111 | 114 | } else {
|
112 | 115 | clearTimeout(this.timeout)
|
113 | 116 | this.timeout = null
|
114 | 117 | this.button.textContent = "Start"
|
| 118 | + this.robotElt.firstChild.src = "img/robot_idle2x.png" |
115 | 119 | }
|
116 | 120 | }
|
117 | 121 | }
|
|
0 commit comments