Remix started
Copy Duck Race
User prompt
Make the player (white duck) not to move if I don't speak βͺπ‘ Consider importing and using the following plugins: @upit/facekit.v1
User prompt
Make the brown ducks to move quicker and make the player (white duck) not to move unless I speak βͺπ‘ Consider importing and using the following plugins: @upit/facekit.v1
User prompt
Please remove the waves below
User prompt
Please make the white duck move only if I speak and not if it hears any sounds. Specifically, it is okay if I don't speak, it does not move, but when the other ducks do a sound it moves. I do not want this βͺπ‘ Consider importing and using the following plugins: @upit/facekit.v1
User prompt
Ok perfect. Now I want to make the player (white duck) to move if the sound it hears is very high decibells. Also I want to have in the screen on the above the volume of decibells βͺπ‘ Consider importing and using the following plugins: @upit/facekit.v1
User prompt
Make the other ducks to move more slow
User prompt
I mean Hz make it to have very low Hz to make the player (white duck) move
Code edit (3 edits merged)
Please save this source code
User prompt
The player (white duck) does not move
User prompt
Make the player not move unless I speak
User prompt
Make it to move based on the frequency of the voice βͺπ‘ Consider importing and using the following plugins: @upit/facekit.v1
User prompt
It does not move. Make it move when I speak βͺπ‘ Consider importing and using the following plugins: @upit/facekit.v1
User prompt
Make it move when and only I speak βͺπ‘ Consider importing and using the following plugins: @upit/facekit.v1
User prompt
Make the player (white duck) to move if only I speak βͺπ‘ Consider importing and using the following plugins: @upit/facekit.v1
Code edit (1 edits merged)
Please save this source code
User prompt
I want the player duck (white duck) not to move from the sounds of the other ducks. Move only If I speak βͺπ‘ Consider importing and using the following plugins: @upit/facekit.v1
Code edit (2 edits merged)
Please save this source code
User prompt
Now I want to put a line on the top of the screen showing the Hz of my voice. If the Hz are low the bar will be in low, and of the Hz are high the bar will be high. Make it to be seen that it goes up and down. Also put appropriate colors. For that reason, also make the player duck (white duck) to move in a speed where if the Hz are low, the speed should also be low. If the Hz are high, the speed should also be high βͺπ‘ Consider importing and using the following plugins: @upit/facekit.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Shape is not defined' in or related to this line: 'var frequencyBar = new Shape({' Line Number: 79
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Make the bar horizontial
User prompt
Make the bar starting a little bit down from the top of the screen. Also make it starting from the left in a few cm from the end of the screen
===================================================================
--- original.js
+++ change.js
@@ -13,13 +13,12 @@
var duckGraphics = self.attachAsset('duck', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 1; // Initial speed of the duck
- self.speedVariation = 0; // Variable to keep track of the speed variation
+ self.speed = 1;
+ self.speedVariation = 0;
self.update = function () {
if (countdown == 0) {
- // Update the duck's speed using the tween plugin
tween(self, {
speedVariation: Math.random() * 2 - 1
}, {
duration: Math.random() * 1000,
@@ -28,19 +27,39 @@
self.x += self.speed + self.speedVariation;
}
};
});
-// PlayerDuck class representing the player's duck, speed varies with frequency
+// HzBar class for displaying voice pitch
+var HzBar = Container.expand(function () {
+ var self = Container.call(this);
+ var barGraphics = self.attachAsset('hzBar', {
+ anchorX: 0,
+ anchorY: 0
+ });
+ self.update = function () {
+ var pitchHeight = Math.min(100, facekit.pitch / 2); // Convert pitch to a usable height
+ self.height = pitchHeight;
+ if (pitchHeight < 33) {
+ self.tint = 0x00FF00; // Green for low pitch
+ } else if (pitchHeight < 66) {
+ self.tint = 0xFFFF00; // Yellow for medium pitch
+ } else {
+ self.tint = 0xFF0000; // Red for high pitch
+ }
+ };
+ return self;
+});
+// PlayerDuck class representing the player's duck
var PlayerDuck = Container.expand(function () {
var self = Container.call(this);
var playerDuckGraphics = self.attachAsset('playerDuck', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
- if (countdown == 0 && facekit.volume > 0.5) {
- var speedBasedOnFrequency = Math.max(1, facekit.frequency / 50); // Scale speed based on frequency
- self.x += speedBasedOnFrequency;
+ if (countdown == 0 && facekit.volume > 0.5 && facekit.mouthOpen) {
+ self.speed = facekit.pitch / 100; // Speed based on pitch
+ self.x += self.speed;
}
};
return self;
});
@@ -48,15 +67,15 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB // Light blue background to simulate sky
+ backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
-// Initialize game elements
+// Full width, initial height 20
var ducks = [];
var countdown = 3;
var countdownText = new Text2(countdown.toString(), {
size: 150,
@@ -65,26 +84,20 @@
var volumeText = new Text2('Volume: 0', {
size: 50,
fill: 0xFFFFFF
});
-var frequencyBar = LK.getAsset('obstacle', {
- height: 20,
- width: 200,
- fill: 0x00FF00,
- anchorX: 0,
- anchorY: 0
-});
-frequencyBar.anchor.set(0.5, 0);
-LK.gui.top.addChild(frequencyBar);
+var hzBar = game.addChild(new HzBar());
+hzBar.x = 0;
+hzBar.y = 0;
volumeText.anchor.set(0.5, 0);
LK.gui.top.addChild(volumeText);
countdownText.anchor.set(0.5, 0);
LK.gui.center.addChild(countdownText);
var startX = 100;
for (var i = 0; i < 5; i++) {
var duck = game.addChild(new Duck());
- duck.x = startX; // Starting position of the duck
- duck.y = 600 + i * 200 + i * 20; // Aligned vertically
+ duck.x = startX;
+ duck.y = 600 + i * 200 + i * 20;
ducks.push(duck);
}
var playerDuck = game.addChild(new PlayerDuck());
var finishLine = game.addChild(LK.getAsset('finishLine', {}));
@@ -92,23 +105,18 @@
finishLine.y = 0;
var lastDuck = ducks[ducks.length - 1];
playerDuck.y = lastDuck.y + lastDuck.height + 100;
playerDuck.x = startX;
-// Update function called every frame
game.update = function () {
if (countdown > 0 && LK.ticks % 60 == 0) {
countdown--;
countdownText.setText(countdown.toString());
if (countdown == 0) {
LK.gui.center.removeChild(countdownText);
- for (var j = 0; j < ducks.length; j++) {
- ducks[j].speedVariation = 0;
- }
}
}
volumeText.setText('Volume: ' + Math.round(facekit.volume));
- frequencyBar.width = Math.min(300, facekit.frequency * 0.3); // Update bar width based on frequency
- frequencyBar.fill = frequencyBar.width < 150 ? 0xFF4500 : 0x32CD32; // Change color based on frequency level
+ hzBar.update(); // Update the Hz bar each frame
if (playerDuck.x > finishLine.x) {
LK.showYouWin();
return;
}