Initial prompt
Duck Race
User prompt
add the facekit plugin ↪💡 Consider importing and using the following plugins: @upit/facekit.v1
User prompt
there should be a list of ducks
User prompt
all ducks should be aligned vertically on the left side of the game
Code edit (1 edits merged)
Please save this source code
User prompt
remove the obstacles
Code edit (5 edits merged)
Please save this source code
User prompt
make the playerDuck instance move to the right when the player uses the microphone input ↪💡 Consider importing and using the following plugins: @upit/facekit.v1
User prompt
make a countdown, which starts at 3 at game start. Before that no duck should move
User prompt
when the countdown is 0, move all the other ducks to the right side, which are not the playerInstance
User prompt
make the speed of the opponent ducks variable during the whole movement. Basically they should go fast and then slow down and go fast ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
address the TODO
User prompt
create a playerDuck graphic and assign it to the playerDuck instance
User prompt
make the playerDuck its own class
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var playerDuckGraphics = self.attachAsset('playerDuck', {' Line Number: 43
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var playerDuckGraphics = self.attachAsset('playerDuck', {' Line Number: 43
Code edit (3 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
the playerDuck instance is not showb
Code edit (3 edits merged)
Please save this source code
User prompt
create a "finishLine" graphic and place it at the right side
Code edit (8 edits merged)
Please save this source code
User prompt
the opponent ducks are moving at the same speed. Make it that they slow down / speed up randomly
===================================================================
--- original.js
+++ change.js
@@ -1,88 +1,105 @@
-/****
+/****
+* Plugins
+****/
+var facekit = LK.import("@upit/facekit.v1");
+
+/****
* Classes
-****/
-//<Assets used in the game will automatically appear here>
-//<Write imports for supported plugins here>
+****/
// Duck class representing the player's duck
var Duck = Container.expand(function () {
- var self = Container.call(this);
- var duckGraphics = self.attachAsset('duck', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5; // Initial speed of the duck
- self.update = function () {
- self.x += self.speed;
- };
+ var self = Container.call(this);
+ var duckGraphics = self.attachAsset('duck', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5; // Initial speed of the duck
+ self.update = function () {
+ self.x = facekit.mouthCenter.x;
+ self.y = facekit.mouthCenter.y;
+ };
});
// Obstacle class representing obstacles on the track
var Obstacle = Container.expand(function () {
- var self = Container.call(this);
- var obstacleGraphics = self.attachAsset('obstacle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Obstacles can have their own behavior if needed
- };
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Obstacles can have their own behavior if needed
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB // Light blue background to simulate sky
+ backgroundColor: 0x87CEEB // Light blue background to simulate sky
});
-/****
+/****
* Game Code
-****/
+****/
+//<Assets used in the game will automatically appear here>
// Initialize game elements
var duck = game.addChild(new Duck());
duck.x = 100; // Starting position of the duck
duck.y = 1366; // Centered vertically
var obstacles = [];
var score = 0;
// Function to create obstacles
function createObstacle() {
- var obstacle = new Obstacle();
- obstacle.x = Math.random() * 2048; // Random x position
- obstacle.y = Math.random() * 2732; // Random y position
- obstacles.push(obstacle);
- game.addChild(obstacle);
+ var obstacle = new Obstacle();
+ obstacle.x = Math.random() * 2048; // Random x position
+ obstacle.y = Math.random() * 2732; // Random y position
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
}
// Create initial obstacles
for (var i = 0; i < 5; i++) {
- createObstacle();
+ createObstacle();
}
// Update function called every frame
game.update = function () {
- duck.update();
- // Check for collisions with obstacles
- for (var i = obstacles.length - 1; i >= 0; i--) {
- var obstacle = obstacles[i];
- if (duck.intersects(obstacle)) {
- // Collision detected, end game
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- return;
- }
- }
- // Check if duck has reached the end of the track
- if (duck.x > 2048) {
- // Duck wins the race
- LK.showYouWin();
- }
+ duck.update();
+ // Check for collisions with obstacles
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ var obstacle = obstacles[i];
+ if (duck.intersects(obstacle)) {
+ // Collision detected, end game
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Check if duck has reached the end of the track
+ if (duck.x > 2048) {
+ // Duck wins the race
+ LK.showYouWin();
+ }
};
// Event listener for touch input to increase duck speed
game.down = function (x, y, obj) {
- duck.speed += 2; // Increase speed on touch
+ if (facekit.volume > 0.6) {
+ duck.speed += 5; // Increase speed when the volume is loud
+ } else if (facekit.volume > 0.3) {
+ duck.speed += 3; // Increase speed when the volume is moderate
+ } else {
+ duck.speed += 2; // Increase speed when the volume is quiet
+ }
};
// Event listener for touch release to reset duck speed
game.up = function (x, y, obj) {
- duck.speed = 5; // Reset speed
+ if (facekit.volume > 0.6) {
+ duck.speed = 5; // Reset speed to 5 when the volume is loud
+ } else if (facekit.volume > 0.3) {
+ duck.speed = 3; // Reset speed to 3 when the volume is moderate
+ } else {
+ duck.speed = 2; // Reset speed to 2 when the volume is quiet
+ }
};
// Create new obstacles periodically
var obstacleTimer = LK.setInterval(function () {
- createObstacle();
+ createObstacle();
}, 2000);
\ No newline at end of file