Skip to content

Commit 5fa2b24

Browse files
bella054SKairinos
andauthored
fix: I have changed the formatting of the generated Python syntax and removed the parentheses from the generated while loops (#1777)
* I added the Youtube link for Level 7 * fix: I have added the link in the hint * fix: I fixed the layout of the videos * I have added the video into level 7 of Python Den * fix: I added the clown horn, sleigh bells, and sleigh crash sounds to only play during December * fix: I have changed the formatting of the generated Python syntax and removed the parentheses from the generated while loops * minor tweaks --------- Co-authored-by: Stefan Kairinos <[email protected]> Co-authored-by: SKairinos <[email protected]>
1 parent 8575ce7 commit 5fa2b24

9 files changed

+285
-142
lines changed

game/messages.py

+157-73
Large diffs are not rendered by default.

game/static/game/js/blocklyCustomBlocks.js

+90-62
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ function initCustomBlocksDescription() {
1616
this.setColour(50);
1717
this.appendDummyInput()
1818
.appendField(Blockly.Msg.START_TITLE)
19-
.appendField(new Blockly.FieldImage(
20-
new Date().getMonth() === 11 && CHARACTER_NAME === "Van"
21-
? ocargo.Drawing.imageDir + "characters/top_view/Sleigh.svg"
22-
: ocargo.Drawing.imageDir + CHARACTER_EN_FACE_URL,
23-
ocargo.BlocklyControl.BLOCK_CHARACTER_HEIGHT,
24-
ocargo.BlocklyControl.BLOCK_CHARACTER_WIDTH
25-
)
26-
);
19+
.appendField(
20+
new Blockly.FieldImage(
21+
new Date().getMonth() === 11 && CHARACTER_NAME === "Van"
22+
? ocargo.Drawing.imageDir + "characters/top_view/Sleigh.svg"
23+
: ocargo.Drawing.imageDir + CHARACTER_EN_FACE_URL,
24+
ocargo.BlocklyControl.BLOCK_CHARACTER_HEIGHT,
25+
ocargo.BlocklyControl.BLOCK_CHARACTER_WIDTH
26+
)
27+
);
2728
this.setNextStatement(true, "Action");
2829
this.setTooltip(Blockly.Msg.START_TOOLTIP);
2930
this.setDeletable(false);
@@ -183,22 +184,30 @@ function initCustomBlocksDescription() {
183184
},
184185
};
185186

186-
Blockly.Blocks['sound_horn'] = {
187-
init: function() {
188-
this.setColour(160);
189-
this.appendDummyInput()
190-
.appendField(Blockly.Msg.SOUND_HORN_TITLE)
191-
.appendField(new Blockly.FieldImage(ocargo.Drawing.imageDir + 'empty.svg',
192-
43,
193-
ocargo.BlocklyControl.BLOCK_HEIGHT))
194-
.appendField(new Blockly.FieldImage(ocargo.Drawing.imageDir + 'empty.svg',
195-
ocargo.BlocklyControl.IMAGE_WIDTH,
196-
ocargo.BlocklyControl.BLOCK_HEIGHT));
197-
this.setPreviousStatement(true, 'Action');
198-
this.setNextStatement(true, 'Action');
199-
this.setTooltip(Blockly.Msg.SOUND_HORN_TOOLTIP);
200-
}
201-
};
187+
Blockly.Blocks["sound_horn"] = {
188+
init: function () {
189+
this.setColour(160);
190+
this.appendDummyInput()
191+
.appendField(Blockly.Msg.SOUND_HORN_TITLE)
192+
.appendField(
193+
new Blockly.FieldImage(
194+
ocargo.Drawing.imageDir + "empty.svg",
195+
43,
196+
ocargo.BlocklyControl.BLOCK_HEIGHT
197+
)
198+
)
199+
.appendField(
200+
new Blockly.FieldImage(
201+
ocargo.Drawing.imageDir + "empty.svg",
202+
ocargo.BlocklyControl.IMAGE_WIDTH,
203+
ocargo.BlocklyControl.BLOCK_HEIGHT
204+
)
205+
);
206+
this.setPreviousStatement(true, "Action");
207+
this.setNextStatement(true, "Action");
208+
this.setTooltip(Blockly.Msg.SOUND_HORN_TOOLTIP);
209+
},
210+
};
202211

203212
/*****************/
204213
/* Conditions */
@@ -277,33 +286,50 @@ function initCustomBlocksDescription() {
277286
},
278287
};
279288

280-
Blockly.Blocks['cow_crossing'] = {
281-
init: function() {
282-
this.setColour(210);
283-
this.setOutput(true, 'Boolean');
284-
let imageUrl = ocargo.Drawing.animalType == ocargo.Cow.PIGEON ? ocargo.Drawing.pigeonUrl : ocargo.Drawing.whiteCowUrl
285-
this.appendDummyInput()
286-
.appendField(ocargo.Drawing.animalType == ocargo.Cow.PIGEON ? Blockly.Msg.PIGEON_CROSSING_TITLE: Blockly.Msg.COW_CROSSING_TITLE)
287-
.appendField(new Blockly.FieldImage(ocargo.Drawing.imageDir + imageUrl,
288-
ocargo.BlocklyControl.COW_WIDTH,
289-
ocargo.BlocklyControl.BLOCK_HEIGHT), 'IMAGE');
290-
}
291-
};
289+
Blockly.Blocks["cow_crossing"] = {
290+
init: function () {
291+
this.setColour(210);
292+
this.setOutput(true, "Boolean");
293+
let imageUrl =
294+
ocargo.Drawing.animalType == ocargo.Cow.PIGEON
295+
? ocargo.Drawing.pigeonUrl
296+
: ocargo.Drawing.whiteCowUrl;
297+
this.appendDummyInput()
298+
.appendField(
299+
ocargo.Drawing.animalType == ocargo.Cow.PIGEON
300+
? Blockly.Msg.PIGEON_CROSSING_TITLE
301+
: Blockly.Msg.COW_CROSSING_TITLE
302+
)
303+
.appendField(
304+
new Blockly.FieldImage(
305+
ocargo.Drawing.imageDir + imageUrl,
306+
ocargo.BlocklyControl.COW_WIDTH,
307+
ocargo.BlocklyControl.BLOCK_HEIGHT
308+
),
309+
"IMAGE"
310+
);
311+
},
312+
};
292313

293-
Blockly.Blocks['pigeon_crossing_IMAGE_ONLY'] = {
294-
init: function() {
295-
this.setColour(210);
296-
this.setOutput(true, 'Boolean');
297-
this.appendDummyInput()
298-
.appendField("pigeons")
299-
.appendField(new Blockly.FieldImage(ocargo.Drawing.imageDir + ocargo.Drawing.pigeonUrl,
300-
ocargo.BlocklyControl.COW_WIDTH,
301-
ocargo.BlocklyControl.BLOCK_HEIGHT), 'IMAGE');
302-
}
303-
}
304-
/****************/
305-
/* Procedures */
306-
/****************/
314+
Blockly.Blocks["pigeon_crossing_IMAGE_ONLY"] = {
315+
init: function () {
316+
this.setColour(210);
317+
this.setOutput(true, "Boolean");
318+
this.appendDummyInput()
319+
.appendField("pigeons")
320+
.appendField(
321+
new Blockly.FieldImage(
322+
ocargo.Drawing.imageDir + ocargo.Drawing.pigeonUrl,
323+
ocargo.BlocklyControl.COW_WIDTH,
324+
ocargo.BlocklyControl.BLOCK_HEIGHT
325+
),
326+
"IMAGE"
327+
);
328+
},
329+
};
330+
/****************/
331+
/* Procedures */
332+
/****************/
307333

308334
Blockly.Blocks["call_proc"] = {
309335
// Block for calling a defined procedure
@@ -559,22 +585,21 @@ function initCustomBlocksPython() {
559585
return "my_van.wait()\n";
560586
};
561587

562-
Blockly.Python['deliver'] = function(block) {
563-
return 'my_van.deliver()\n';
564-
};
565-
566-
Blockly.Python['sound_horn'] = function(block) {
567-
return 'my_van.sound_horn()\n';
568-
};
588+
Blockly.Python["deliver"] = function (block) {
589+
return "my_van.deliver()\n";
590+
};
569591

592+
Blockly.Python["sound_horn"] = function (block) {
593+
return "my_van.sound_horn()\n";
594+
};
570595

571596
Blockly.Python["road_exists"] = function (block) {
572597
if (block.inputList[0].fieldRow[1].value_ === "FORWARD") {
573-
var python = "my_van.is_road('FORWARD')";
598+
var python = "my_van.is_road_forward()";
574599
} else if (block.inputList[0].fieldRow[1].value_ === "LEFT") {
575-
var python = "my_van.is_road('LEFT')";
600+
var python = "my_van.is_road_left()";
576601
} else {
577-
var python = "my_van.is_road('RIGHT')";
602+
var python = "my_van.is_road_right()";
578603
}
579604

580605
return [python, Blockly.Python.ORDER_NONE];
@@ -584,9 +609,9 @@ function initCustomBlocksPython() {
584609
Blockly.Python["traffic_light"] = function (block) {
585610
var python;
586611
if (block.inputList[0].fieldRow[1].value_ === ocargo.TrafficLight.RED) {
587-
python = "my_van.at_traffic_light('RED')";
612+
python = "my_van.is_red_traffic_light()";
588613
} else {
589-
python = "my_van.at_traffic_light('GREEN')";
614+
python = "my_van.is_green_traffic_light()";
590615
}
591616

592617
return [python, Blockly.Python.ORDER_NONE]; //TODO: figure out what this ordering relates to
@@ -628,6 +653,9 @@ function initCustomBlocksPython() {
628653
"condition",
629654
Blockly.Python.ORDER_ATOMIC
630655
);
656+
657+
condition = condition.replace(/\((.*)\)/, "$1");
658+
631659
var subBlock = Blockly.Python.statementToCode(block, "body");
632660
var code = "while " + condition + ":\n" + subBlock;
633661
return code;

game/static/game/js/sound.js

+38-7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ ocargo.sound.pigeonSound = new Howl({
4747
urls: ['/static/game/sound/pigeon.mp3', '/static/game/sound/pigeon.ogg']
4848
});
4949

50+
/// festive sounds ///**
51+
ocargo.sound.clownHornSound = new Howl({
52+
urls: ['/static/game/sound/clown_horn.mp3', '/static/game/sound/clown_horn.ogg']
53+
});
54+
55+
ocargo.sound.sleighBellsSound = new Howl({
56+
urls: ['/static/game/sound/sleigh_bells.mp3', '/static/game/sound/sleigh_bells.ogg']
57+
});
58+
59+
ocargo.sound.sleighCrashSound = new Howl({
60+
urls: ['/static/game/sound/sleigh_crash.mp3', '/static/game/sound/sleigh_crash.ogg']
61+
});
62+
63+
function isDecember()
64+
{
65+
const currentMonth = new Date().getMonth();
66+
return currentMonth === 11;
67+
}
68+
5069
function safePlay(sound) {
5170
try {
5271
sound.play();
@@ -63,15 +82,19 @@ function safeStop(sound) {
6382

6483

6584
ocargo.sound.starting = function() {
66-
if (CHARACTER_NAME === 'Van') {
67-
safePlay(ocargo.sound.startingSound);
68-
} else if (CHARACTER_NAME === "Electric van") {
69-
safePlay(ocargo.sound.electricVanStartingSound);
85+
if (!isDecember()) {
86+
if (CHARACTER_NAME === 'Van') {
87+
safePlay(ocargo.sound.startingSound);
88+
} else if (CHARACTER_NAME === "Electric van") {
89+
safePlay(ocargo.sound.electricVanStartingSound);
90+
}
7091
}
7192
};
7293

7394
ocargo.sound.start_engine = function() {
74-
if (CHARACTER_NAME === 'Van') {
95+
if (isDecember()) {
96+
safePlay(ocargo.sound.sleighBellsSound);
97+
} else if (CHARACTER_NAME === 'Van') {
7598
safePlay(ocargo.sound.engineSound);
7699
}
77100
};
@@ -105,7 +128,11 @@ ocargo.sound.pigeon = function() {
105128
}
106129

107130
ocargo.sound.sound_horn = function() {
131+
if (isDecember()) {
132+
safePlay(ocargo.sound.clownHornSound);
133+
} else {
108134
safePlay(ocargo.sound.hornSound);
135+
}
109136
};
110137

111138
ocargo.sound.crash = function (animationDuration) {
@@ -117,11 +144,15 @@ ocargo.sound.crashIntoCow = function (animationDuration) {
117144
};
118145

119146
ocargo.sound._crashSound = function () {
120-
if (CHARACTER_NAME === 'Van') {
121-
safePlay(ocargo.sound.crashSound);
147+
if (isDecember()) {
148+
safePlay(ocargo.sound.sleighCrashSound);
149+
} else {
150+
if (CHARACTER_NAME === 'Van') {
151+
safePlay(ocargo.sound.crashSound);
122152
} else {
123153
safePlay(ocargo.sound.failureSound);
124154
}
155+
}
125156
};
126157

127158
ocargo.sound.tension = function() {

game/static/game/sound/clown_horn.mp3

84.9 KB
Binary file not shown.

game/static/game/sound/clown_horn.ogg

24.9 KB
Binary file not shown.
15 KB
Binary file not shown.
8.57 KB
Binary file not shown.
136 KB
Binary file not shown.
48 KB
Binary file not shown.

0 commit comments

Comments
 (0)