Skip to content

Commit 987aff3

Browse files
committed
make interactive statues
1 parent 6da0396 commit 987aff3

File tree

7 files changed

+140
-82
lines changed

7 files changed

+140
-82
lines changed

engine/objects.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class Obj {
3636

3737
static addObject (obj) {
3838
if (!obj.properties) obj.properties = {}
39+
if (Array.isArray(obj.properties)) {
40+
const tmpProps = {}
41+
obj.properties.forEach(({ name, value }) => {
42+
tmpProps[name] = value
43+
})
44+
obj.properties = tmpProps
45+
}
3946
Obj.prototypes.find(prot => prot.name === obj.type).properties
4047
.forEach(({ name, value }) => {
4148
obj.properties[name] = JSON.parse(value)
@@ -119,6 +126,7 @@ class Obj {
119126
this.width, // destination width
120127
this.height // destination height
121128
)
129+
if (this.type === 'statue') this.statue()
122130
if (drawCollitions) {
123131
// draw collition on object
124132
this.ctx.rect(
@@ -132,10 +140,12 @@ class Obj {
132140
}
133141

134142
setState (value) {
143+
console.log(value)
135144
if (this.type === 'fuse') {
136145
game.hasEnergy = !value
137146
}
138147
this.state = value
148+
if (this.type === 'statue') this.statue()
139149
game.triggerSight()
140150
}
141151

@@ -156,6 +166,29 @@ class Obj {
156166
}
157167
}
158168

169+
statue () {
170+
const proto = this.properties
171+
const source = proto[proto.variant]
172+
this.ctx.clearRect(
173+
this.x + 4,
174+
this.y - 4,
175+
source.w,
176+
source.h
177+
)
178+
if (this.state) return
179+
this.ctx.drawImage(
180+
tileset,
181+
source.x, // source x
182+
source.y, // source y
183+
source.w, // source width
184+
source.h, // source height
185+
this.x + 4, // desination x
186+
this.y - 4, // destination y
187+
source.w, // destination width
188+
source.h // destination height
189+
)
190+
}
191+
159192
safe () {
160193
if (this.combinationFailed) return
161194
if (!this.combination) {

engine/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const setPalette = tileset => {
106106
}
107107

108108
const preload = level => {
109-
Player.create(ctxPlayer1, 72, 240, true)
109+
Player.create(ctxPlayer1, 296, 336, true)
110110
// Player.create(ctxPlayer1, -8, 0, true)
111111
Player.create(ctxPlayer2, -8, 32)
112112
fetch(`${level}/map.json`)

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<br />
166166
TO DO:
167167
<ol>
168+
<li>Add basic objects</li>
168169
<li>Interactive objects (steal stuff)</li>
169170
<li>If player steps on light, that triggers the alarm</li>
170171
<li>Being able to scape from the game area</li>

levels/0001/0001.tiled-session

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"openFiles": [
5252
],
5353
"project": "0001.tiled-project",
54-
"property.type": "bool",
54+
"property.type": "string",
5555
"recentFiles": [
5656
"map.tmx",
5757
"map.json",

levels/0001/map.json

Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,11 @@
234234
0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0,
235235
0, 0, 0, 0, 27, 27, 27, 27, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0,
236236
0, 0, 0, 0, 27, 27, 27, 27, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0,
237-
0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
237+
0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
238238
0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
239239
0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0,
240240
0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0,
241-
0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0,
241+
0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 27, 0, 0, 0, 0, 27, 0, 27, 0, 0, 0, 0, 0,
242242
0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0,
243243
0, 27, 27, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 27, 27,
244244
0, 0, 0, 0, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0,
@@ -695,22 +695,27 @@
695695
{
696696
"name":"col",
697697
"type":"string",
698-
"value":"{ \"x\": 0, \"y\": 0, \"w\": 8, \"h\": 16 }"
698+
"value":"{ \"x\": 0, \"y\": 16, \"w\": 16, \"h\": 16 }"
699699
},
700700
{
701-
"name":"constraints",
701+
"name":"false",
702702
"type":"string",
703-
"value":"[\"up\", \"down\"]"
703+
"value":"{ \"x\": 96, \"y\": 272 }"
704704
},
705705
{
706-
"name":"false",
706+
"name":"golden",
707707
"type":"string",
708-
"value":"{ \"x\": 80, \"y\": 32 }"
708+
"value":"{\"x\": 112, \"y\": 272, \"w\": 8, \"h\": 12}"
709+
},
710+
{
711+
"name":"silver",
712+
"type":"string",
713+
"value":"{\"x\": 112, \"y\": 288, \"w\": 8, \"h\": 12}"
709714
},
710715
{
711716
"name":"true",
712717
"type":"string",
713-
"value":"{ \"x\": 48, \"y\": 32 }"
718+
"value":"{ \"x\": 96, \"y\": 272 }"
714719
}],
715720
"rotation":0,
716721
"type":"prototype",
@@ -724,10 +729,15 @@
724729
"id":79,
725730
"name":"computer",
726731
"properties":[
732+
{
733+
"name":"changeConditions",
734+
"type":"bool",
735+
"value":true
736+
},
727737
{
728738
"name":"col",
729739
"type":"string",
730-
"value":"{ \"x\": 0, \"y\": 0, \"w\": 8, \"h\": 16 }"
740+
"value":"{ \"x\": 8, \"y\": 16, \"w\": 16, \"h\": 16 }"
731741
},
732742
{
733743
"name":"constraints",
@@ -737,12 +747,17 @@
737747
{
738748
"name":"false",
739749
"type":"string",
740-
"value":"{ \"x\": 80, \"y\": 32 }"
750+
"value":"{ \"x\": 64, \"y\": 272 }"
751+
},
752+
{
753+
"name":"restrictFrom",
754+
"type":"string",
755+
"value":"[\"left\", \"right\"]"
741756
},
742757
{
743758
"name":"true",
744759
"type":"string",
745-
"value":"{ \"x\": 48, \"y\": 32 }"
760+
"value":"{ \"x\": 64, \"y\": 272 }"
746761
}],
747762
"rotation":0,
748763
"type":"prototype",
@@ -792,6 +807,51 @@
792807
"width":16,
793808
"x":128,
794809
"y":-16
810+
},
811+
{
812+
"height":32,
813+
"id":81,
814+
"name":"",
815+
"properties":[
816+
{
817+
"name":"variant",
818+
"type":"string",
819+
"value":"golden"
820+
}],
821+
"rotation":0,
822+
"type":"statue",
823+
"visible":true,
824+
"width":16,
825+
"x":304,
826+
"y":304
827+
},
828+
{
829+
"height":32,
830+
"id":82,
831+
"name":"",
832+
"properties":[
833+
{
834+
"name":"variant",
835+
"type":"string",
836+
"value":"silver"
837+
}],
838+
"rotation":0,
839+
"type":"statue",
840+
"visible":true,
841+
"width":16,
842+
"x":384,
843+
"y":304
844+
},
845+
{
846+
"height":32,
847+
"id":85,
848+
"name":"",
849+
"rotation":0,
850+
"type":"computer",
851+
"visible":true,
852+
"width":32,
853+
"x":208,
854+
"y":240
795855
}],
796856
"opacity":1,
797857
"type":"objectgroup",
@@ -869,57 +929,18 @@
869929
"height":48,
870930
"id":55,
871931
"name":"",
872-
"properties":[
873-
{
874-
"name":"next",
875-
"type":"object",
876-
"value":56
877-
}],
878-
"rotation":0,
879-
"type":"guard",
880-
"visible":true,
881-
"width":32,
882-
"x":224,
883-
"y":304
884-
},
885-
{
886-
"height":48,
887-
"id":56,
888-
"name":"",
889-
"properties":[
890-
{
891-
"name":"next",
892-
"type":"object",
893-
"value":57
894-
}],
895-
"rotation":0,
896-
"type":"guard",
897-
"visible":true,
898-
"width":32,
899-
"x":224,
900-
"y":240
901-
},
902-
{
903-
"height":48,
904-
"id":57,
905-
"name":"",
906932
"properties":[
907933
{
908934
"name":"next",
909935
"type":"object",
910936
"value":58
911-
},
912-
{
913-
"name":"start",
914-
"type":"bool",
915-
"value":false
916937
}],
917938
"rotation":0,
918939
"type":"guard",
919940
"visible":true,
920941
"width":32,
921942
"x":160,
922-
"y":240
943+
"y":304
923944
},
924945
{
925946
"height":48,
@@ -1035,7 +1056,7 @@
10351056
"type":"guard",
10361057
"visible":true,
10371058
"width":32,
1038-
"x":368,
1059+
"x":336,
10391060
"y":384
10401061
},
10411062
{
@@ -1057,7 +1078,7 @@
10571078
"type":"guard",
10581079
"visible":true,
10591080
"width":32,
1060-
"x":368,
1081+
"x":336,
10611082
"y":320
10621083
},
10631084
{
@@ -1079,7 +1100,7 @@
10791100
"type":"guard",
10801101
"visible":true,
10811102
"width":32,
1082-
"x":368,
1103+
"x":336,
10831104
"y":384
10841105
},
10851106
{
@@ -1123,7 +1144,7 @@
11231144
"y":0
11241145
}],
11251146
"nextlayerid":23,
1126-
"nextobjectid":81,
1147+
"nextobjectid":86,
11271148
"orientation":"orthogonal",
11281149
"properties":[
11291150
{

0 commit comments

Comments
 (0)