Skip to content

Commit db903b1

Browse files
committed
Add set gravity and set speed blocks
1 parent 814b708 commit db903b1

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

blockly/src/minecraft/api.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ exports.playSound = function(id, soundName) {
99
BlocklyApps.highlight(id);
1010
BlocklyApps.playAudio(soundName);
1111
};
12+
13+
exports.setGravity = function(id, gravityValue) {
14+
BlocklyApps.highlight(id);
15+
window.game.controls.target().forces[1] = gravityValue;
16+
};
17+
18+
exports.setSpeed = function(id, speedValue) {
19+
BlocklyApps.highlight(id);
20+
window.game.controls.walk_max_speed = speedValue;
21+
};

blockly/src/minecraft/blocks.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,62 @@ exports.install = function(blockly, blockInstallOptions) {
6363
generator.minecraft_playSound = function() {
6464
return generateSetterCode(this, 'playSound');
6565
};
66+
67+
var EARTH_GRAVITY = -0.0000035999998999614036;
68+
var GRAVITY_VAL =
69+
[
70+
['Asteroid', (EARTH_GRAVITY / 20).toString()],
71+
['Moon', (EARTH_GRAVITY / 2).toString()],
72+
['Earth', (EARTH_GRAVITY).toString()],
73+
['Venus', (EARTH_GRAVITY * 2).toString()],
74+
['Jupiter', (EARTH_GRAVITY * 4).toString()]
75+
];
76+
77+
blockly.Blocks.minecraft_setGravity = {
78+
// Block for playing sound.
79+
helpUrl: '',
80+
init: function() {
81+
this.setHSV(184, 1.00, 0.74);
82+
this.appendDummyInput()
83+
.appendTitle('set gravity')
84+
.appendTitle(new blockly.FieldDropdown(GRAVITY_VAL), 'VALUE');
85+
this.setPreviousStatement(true);
86+
this.setNextStatement(true);
87+
this.setTooltip('set gravity');
88+
}
89+
};
90+
91+
generator.minecraft_setGravity = function() {
92+
return generateSetterCode(this, 'setGravity');
93+
};
94+
95+
var WALK_SPEED = 0.0056;
96+
var WALK_SPEEDS =
97+
[
98+
['Crawl', (WALK_SPEED / 2).toString()],
99+
['Walk', (WALK_SPEED).toString()],
100+
['Run', (WALK_SPEED * 2).toString()],
101+
['Sprint', (WALK_SPEED * 4).toString()],
102+
['Super Sprint', (WALK_SPEED * 8).toString()]
103+
];
104+
105+
blockly.Blocks.minecraft_setSpeed = {
106+
helpUrl: '',
107+
init: function() {
108+
this.setHSV(184, 1.00, 0.74);
109+
this.appendDummyInput()
110+
.appendTitle('set speed')
111+
.appendTitle(new blockly.FieldDropdown(WALK_SPEEDS), 'VALUE');
112+
this.setPreviousStatement(true);
113+
this.setNextStatement(true);
114+
this.setTooltip('set speed');
115+
}
116+
};
117+
118+
generator.minecraft_setSpeed = function() {
119+
return generateSetterCode(this, 'setSpeed');
120+
};
121+
66122
};
123+
124+
//game.controls.walk_max_speed

blockly/src/minecraft/levels.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ module.exports = {
1010
toolbox: blockUtils.createToolbox(
1111
blockUtils.blockOfType('when_run') +
1212
blockUtils.blockOfType('minecraft_playSound') +
13-
blockUtils.blockOfType('minecraft_log')
13+
blockUtils.blockOfType('minecraft_log') +
14+
blockUtils.blockOfType('minecraft_setGravity') +
15+
blockUtils.blockOfType('minecraft_setSpeed')
1416
),
1517
startBlocks: '',
1618
requiredBlocks: '',

0 commit comments

Comments
 (0)