Browse Source

add better modding

Kyle Perik 5 months ago
parent
commit
aeba731a61
2 changed files with 34 additions and 15 deletions
  1. 22 13
      main.js
  2. 12 2
      setup.js

+ 22 - 13
main.js

@@ -38,16 +38,15 @@ pc.gameLoop(game_data.interval, last => {
38 38
     }
39 39
 
40 40
     var gridfactor = game_data.gridfactor;
41
-    var using_tool = last.keys.includes('x');
41
+    var using_tools = last.keys.map(k => ({ z: 0, x: 1, c: 2 }[k])).filter(a => a);
42 42
     var facing = (move.x != 0 || move.y != 0) ? move : last.facing;
43 43
     var tool_area = vdo(
44 44
         (p, f) => Math.floor(p / gridfactor + f) * gridfactor,
45 45
         player.pos, facing
46 46
     );
47
-    var is_mining = (
48
-        using_tool
49
-            && player.mods[0]
50
-            && player.mods[0].type === 'drill'
47
+    var is_mining = using_tools.some(
48
+        t => player.topmods[t]
49
+            && player.topmods[t].type === 'drill'
51 50
     );
52 51
 
53 52
     var objects = last.objects;
@@ -130,21 +129,31 @@ pc.gameLoop(game_data.interval, last => {
130 129
         gridfactor, gridfactor, 'rgba(255, 255, 255, .1)'
131 130
     );
132 131
 
132
+    // --- Rover ---
133
+    // Rover mod below
134
+    var type = game_data.types.find(t => t.name === player.bottommod);
135
+
136
+    draw_type(
137
+        type.name,
138
+        middle.x - 2,
139
+        middle.y - 1,
140
+    );
141
+
133 142
     // Rover
134 143
     pc.rect(
135
-        middle.x - 4,
136
-        middle.y - 4 - (state.player.engine_rel % 9 < 3 ? 1 : 0),
137
-        10, 10, '#355'
144
+        middle.x - 2,
145
+        middle.y - 2 - (player.engine_rel % 9 < 3 ? 1 : 0),
146
+        7, 5, '#355'
138 147
     );
139 148
 
140
-    // Rover mods
141
-    state.player.mods.map(m => {
142
-        var type = game_data.types.filter(t => t.name === m.type)[0];
149
+    // Rover top mods
150
+    state.player.topmods.map(m => {
151
+        var type = game_data.types.find(t => t.name === m.type);
143 152
 
144 153
         draw_type(
145 154
             type.name,
146
-            middle.x - 2,
147
-            middle.y - 1,
155
+            middle.x - 2 + (m.pos - 1) * 7,
156
+            middle.y - 4 - (m.pos == 1 ? 3 : 0) - (player.engine_rel % 9 < 3 ? 1 : 0),
148 157
         );
149 158
     });
150 159
 

+ 12 - 2
setup.js

@@ -26,6 +26,14 @@ const game_data = {
26 26
             { x: 4, y: 3, w: 3, h: 3 },
27 27
             { x: 3, y: 4, w: 1, h: 1 },
28 28
         ] },
29
+        { name: 'battery', color: '#eef', blocks: [
30
+            { x: 2, y: 0, w: 3, h: 1 },
31
+            { x: 2, y: 2, w: 3, h: 5 },
32
+            { x: 1, y: 1, w: 5, h: 1 },
33
+            { x: 1, y: 6, w: 5, h: 1 },
34
+            { x: 1, y: 1, w: 1, h: 6 },
35
+            { x: 5, y: 1, w: 1, h: 6 },
36
+        ] },
29 37
         { name: 'iron', color: '#eef', minable: true, blocks: [
30 38
             { x: 2, y: 0, w: 4, h: 4 },
31 39
             { x: 0, y: 2, w: 3, h: 3 },
@@ -64,9 +72,11 @@ var initialState = {
64 72
         engine_rel: 0,
65 73
         pos: { x: 10, y: 10 },
66 74
         vel: { x: 0, y: 0 },
67
-        mods: [
68
-            { type: 'drill' },
75
+        topmods: [
76
+            { type: 'battery', pos: 0 },
77
+            { type: 'drill', pos: 1 },
69 78
         ],
79
+        bottommod: 'wheels',
70 80
         resources: {
71 81
             iron: 2,
72 82
             copper: 10 // sample starting resources