Code edit (3 edits merged)
Please save this source code
User prompt
Let's move the instruction text up 300 pixels.
User prompt
Let's triple the size of the water splash.
Code edit (1 edits merged)
Please save this source code
User prompt
Only display the text hi there when there is absolutely nothing moving on screen and all of the obstacles are motionless.
User prompt
If there is no movement happening on the game screen, display the words Hi there in the middle of the screen.
User prompt
Do you know why the crow's text is not appearing on screen? Is it a child of something else?
User prompt
Do you know why the crow's text and the lyric sound are not playing after every eight obstacles?
User prompt
The anchor for the crow's text should not be a child of anything. It should be on its own.
User prompt
Since the alert sound doesn't always trigger, let's move it so that it triggers after every 8 obstacles.
User prompt
with a very large gap between obstacles.
Code edit (1 edits merged)
Please save this source code
User prompt
The right and left edge of the ocean tiles should slightly overlap by about 20 pixels.
User prompt
That didn't seem to work. I'm still seeing very, very small gaps between the top and bottom obstacle. That gap needs to be wider vertically.
User prompt
I see. It's a little too hard at the beginning sometimes, so let's make it so the smallest gap is 400 pixels.
User prompt
Increase the size of the jets by 25%.
User prompt
Increase the size of the fish by 50 percent.
User prompt
Reset the player character's rotation when the player flaps.
User prompt
Slow the rotation of the player character by half.
User prompt
Reset the rotation of the player's character when the player flaps.
User prompt
Reset the rotation when the player flaps.
User prompt
This should also apply to the flap animation.
User prompt
As the pelican is falling towards the ground, we want to rotate it clockwise until the right side is facing straight down. And it will never go beyond facing straight down. It will...
/****
* Classes
****/
// Boat class
var Boat = Container.expand(function () {
var self = Container.call(this);
var boatGraphics = self.attachAsset('boat', {
anchorX: 0.5,
anchorY: 0.5
});
boatGraphics.alpha = 0.8; // Set opacity to 80%
self.speed = -0.75; // Slow the boat by half its speed
self.update = function () {
self.x += self.speed;
if (self.x < -boatGraphics.width) {
self.destroy(); // Destroy the boat when it goes off screen
}
};
});
// City class
var City = Container.expand(function () {
var self = Container.call(this);
var cityGraphics = self.attachAsset('cityTile', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 5
});
cityGraphics.alpha = 0.2; // Set opacity to 20%
self.speed = -0.1; // Move from right to left, half the ocean speed
self.update = function () {
self.x += self.speed;
if (self.x < -cityGraphics.width) {
self.x = 2048; // Reset position to the right
}
};
});
// Cloud class
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 5
});
cloudGraphics.alpha = 0.4; // Set opacity to 30%
self.speed = -1; // Move from right to left
self.update = function () {
self.x += self.speed;
if (self.x < -cloudGraphics.width) {
self.x = 2048 + cloudGraphics.width; // Reset position to the right
}
};
});
// Fish class
var Fish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('pelican', {
anchorX: 0.5,
anchorY: 0.5
});
fishGraphics.alpha = 0.8; // Set alpha to 80% opaque
self.speed = 2;
self.direction = 1; // 1 for right, -1 for left
self.update = function () {
self.x += self.speed * self.direction;
if (self.x > 2048 || self.x < 0) {
self.direction *= -1; // Change direction
fishGraphics.scale.x *= -1; // Flip the direction of the image
}
};
});
// The assets will be automatically created and loaded by the LK engine
// Jet class
var Jet = Container.expand(function () {
var self = Container.call(this);
var jetGraphics = self.attachAsset('jet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.update = function () {
self.x -= self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
self.children.forEach(function (child) {
if (child instanceof Text2) {
child.x = self.x;
}
});
if (self.x < -100) {
self.destroy();
}
};
self.createPipe = function (gapY, gapHeight) {
var topPipe = LK.getAsset('obstacle', {
anchorX: 0.5,
anchorY: 1.0,
height: gapY
});
var bottomPipe = LK.getAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.0,
y: gapY + gapHeight,
height: 2732 - (gapY + gapHeight)
});
self.addChild(topPipe);
self.addChild(bottomPipe);
};
});
// Pelican class
var Pelican = Container.expand(function () {
var self = Container.call(this);
var pelicanGraphics = self.attachAsset('pelicanSVG', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.speed = 0;
self.update = function () {
self.speed += 0.5; // Gravity effect
self.y += self.speed;
if (self.y < 0) {
self.y = 0;
}
if (self.y > 2732) {
LK.effects.flashScreen(0xff0000, 1000);
LK.stopMusic();
LK.stopMusic();
LK.showGameOver();
}
// Rotate pelican clockwise as it falls
if (self.speed > 0) {
pelicanGraphics.rotation += 0.05; // Rotate clockwise
if (pelicanGraphics.rotation > Math.PI / 2) {
pelicanGraphics.rotation = Math.PI / 2; // Limit rotation to face straight down
}
}
// Check if pelican is in the ocean layer
if (self.y > 2732 * 0.8) {
pelicanGraphics.alpha = 0.8; // Set to 80% opaque
if (self.y < 2732 * 0.8 + 10) {
// Check if pelican is at the top part of the ocean layer
createSplashEffect(self.x, self.y);
}
} else {
pelicanGraphics.alpha = 1; // Set to fully opaque
}
};
self.dive = function () {
self.speed = 10; // Increase speed for diving
};
self.fly = function () {
self.speed = -15; // Increase upward speed for flying
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Add instructions text at the start of the game
var instructionsText = new Text2('Tap to fly, avoid obstacles, and catch fish!', {
size: 100,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 6
});
instructionsText.anchor.set(0.5, 0.5);
instructionsText.x = 2048 / 2;
instructionsText.y = 2732 / 2;
game.addChild(instructionsText);
// Remove the instructions text after 5 seconds
LK.setTimeout(function () {
instructionsText.destroy();
}, 5000);
// Initialize city layers to create a continuous loop similar to the ocean
var city1 = game.addChild(new City());
city1.x = 0;
city1.y = 2732 * 0.8 - city1.height / 2 + 155; // Consolidated vertical position adjustment
var city2 = game.addChild(new City());
city2.y = 2732 * 0.8 - city2.height / 2 + 155; // Consolidated vertical position adjustment
city2.x = 2048; // Offset the second city to create a continuous loop
// Initialize cloud layers with random heights
var cloud1 = game.addChild(new Cloud());
cloud1.x = 2048 / 2;
cloud1.y = Math.random() * 2732 * 0.5; // Random height within the top half
var cloud2 = game.addChild(new Cloud());
cloud2.x = 2048 / 2 + 1024; // Offset the second cloud
cloud2.y = Math.random() * 2732 * 0.5; // Random height within the top half
function createSplashEffect(x, y) {
var splash = LK.getAsset('splash', {
anchorX: 0.5,
anchorY: 0.5
});
splash.x = x;
splash.y = y;
splash.alpha = 1;
splash.update = function () {
this.alpha -= 0.05; // Fade out the splash
if (this.alpha <= 0) {
this.destroy();
}
};
LK.getSound('splash').play(); // Play splash sound
game.addChild(splash);
}
game.pipesPassed = 0;
game.jetsAppear = false;
// Forest green color
// No start screen, game begins immediately
// Forest green color for pipes
// Forest green color for pipes
// Add a light blue layer at the bottom 20% of the screen
var bottomLayer1 = LK.getAsset('ocean', {
width: 2048,
height: 2732 * 0.2,
color: 0xADD8E6,
anchorX: 0.5,
anchorY: 0.0
});
bottomLayer1.x = 2048 / 2;
bottomLayer1.y = 2732 * 0.8;
game.addChild(city1);
game.addChild(city2);
game.addChild(bottomLayer1);
var bottomLayer2 = LK.getAsset('ocean', {
width: 2048,
height: 2732 * 0.2,
color: 0xADD8E6,
anchorX: 0.5,
anchorY: 0.0
});
bottomLayer2.x = 2048 / 2 + 2048;
bottomLayer2.y = 2732 * 0.8;
game.addChild(bottomLayer2);
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 8
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var pelican = game.addChild(new Pelican());
var fish = game.addChild(new Fish());
fish.x = 1024; // Start in the middle of the screen
fish.y = 2732 * 0.9; // Position in the bottom layer
pelican.speed = 0; // Initial speed
pelican.x = 500;
pelican.y = 1366;
var obstacles = [];
var oceanSwayDirection = 1;
var oceanSwaySpeed = 0.5;
game.update = function () {
// Add a gentle sway to the ocean layer
bottomLayer1.x -= oceanSwaySpeed * 0.2;
bottomLayer2.x -= oceanSwaySpeed * 0.2;
if (bottomLayer1.x < -2048 / 2) {
bottomLayer1.x = bottomLayer2.x + 2048;
}
if (bottomLayer2.x < -2048 / 2) {
bottomLayer2.x = bottomLayer1.x + 2048;
}
bottomLayer1.y += oceanSwaySpeed * oceanSwayDirection * 0.5;
bottomLayer2.y += oceanSwaySpeed * oceanSwayDirection * 0.5;
if (bottomLayer1.y > 2732 * 0.8 + 0.5 || bottomLayer1.y < 2732 * 0.8 - 0.5) {
oceanSwayDirection *= -1;
}
if (LK.ticks % 400 == 0 && !game.jetsAppear) {
var newObstacle = new Obstacle();
newObstacle.x = 2048;
var gapY = Math.random() * (2000 - 600); // Random gap position
var pelicanHeight = LK.getAsset('pelican', {}).height;
var maxGapHeight = pelicanHeight * 10;
var initialGapHeight = 2000 * 0.2;
var minGapHeight = initialGapHeight / 2;
var gapHeight = Math.max(minGapHeight, Math.min(initialGapHeight, maxGapHeight) - LK.getScore() * 0.1); // Decrease gapHeight over time but not less than half its initial size
newObstacle.createPipe(gapY, gapHeight);
obstacles.push(newObstacle);
game.addChild(newObstacle);
game.pipesPassed++;
if (game.pipesPassed % 8 == 0) {
game.jetsAppear = true;
game.jetsTimer = 0;
LK.getSound('alert').play();
}
}
for (var i = obstacles.length - 1; i >= 0; i--) {
if (obstacles[i].x < -50) {
obstacles[i].destroy();
obstacles.splice(i, 1);
LK.setScore(LK.getScore() + 1); // Add 1 point to the score
scoreTxt.setText(LK.getScore()); // Update the score text
}
if (obstacles[i] instanceof Obstacle && pelican.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.stopMusic();
LK.getSound('arcadefail').play();
LK.showGameOver();
}
fish.update();
cloud1.update();
cloud2.update();
city1.update();
city2.update();
if (pelican.intersects(fish)) {
fish.destroy();
fish = game.addChild(new Fish());
fish.x = 1024; // Reset fish position
fish.y = 2732 * 0.9;
LK.setScore(LK.getScore() + 10); // Add 10 points to the score
scoreTxt.setText(LK.getScore()); // Update the score text
LK.getSound('specialscore1').play(); // Play the sound Special Score 1
// Create and display a new unique graphic when the fish is eaten
var yumGraphic = LK.getAsset('yumGraphic', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
yumGraphic.x = pelican.x;
yumGraphic.y = pelican.y;
yumGraphic.alpha = 1;
yumGraphic.update = function () {
this.y -= 2; // Move the graphic upwards
this.alpha -= 0.02; // Fade out the graphic
if (this.alpha <= 0) {
this.destroy();
}
};
game.addChild(yumGraphic);
// Create and display the "+10" text
var plusTenText = new Text2('+10', {
size: 150,
fill: "#000000",
stroke: "#ffffff",
strokeThickness: 8
});
plusTenText.anchor.set(0.5, 0);
plusTenText.x = pelican.x;
plusTenText.y = pelican.y - 300; // Position it higher above the "YUM" graphic
plusTenText.alpha = 1;
plusTenText.update = function () {
this.y -= 2; // Move the text upwards
this.alpha -= 0.02; // Fade out the text
if (this.alpha <= 0) {
this.destroy();
}
};
game.addChild(plusTenText);
}
// Add a boat every 30 seconds
if (LK.ticks % 1800 == 0) {
// 1800 ticks = 30 seconds at 60 FPS
var newBoat = new Boat();
newBoat.x = 2048 + newBoat.width; // Start from the right side of the screen
newBoat.y = 2732 * 0.8 - 30; // Move the boat up by another 10 pixels
game.addChild(newBoat);
}
// Add the jet to the game
if (game.jetsAppear) {
game.jetsTimer++;
if (game.jetsTimer >= 300) {
// 5 seconds have passed
game.jetsAppear = false;
} else if (LK.ticks % 60 == 0) {
// Every second
if (game.jetsTimer == 0) {
// When the first jet appears
// Play the alert sound
LK.getSound('alert').play();
var crowsText = new Text2('CROWS!', {
size: 200,
fill: "#ffffff"
});
crowsText.anchor.set(0.5, 0.5);
crowsText.x = 2048 / 2;
crowsText.y = 2732 / 2;
game.addChild(crowsText);
// Remove the "CROWS!" text after 2 seconds
LK.setTimeout(function () {
crowsText.destroy();
}, 2000);
}
for (var i = 0; i < 3; i++) {
var newJet = new Jet();
newJet.x = 2048 + i * 500; // Start from the right side of the screen and spread out the jets
newJet.y = Math.random() * 2732; // Random y position
game.addChild(newJet);
}
}
}
// Check for collision with the jet
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof Jet && pelican.intersects(game.children[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Increment score for every two seconds the pelican stays alive
if (LK.ticks % 120 == 0) {
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
}
}
};
game.down = function (x, y, obj) {
pelican.fly();
LK.getSound('flap').play();
// Create and display the "FLAP" image
var flapImage = LK.getAsset('flapImage', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
flapImage.x = pelican.x;
flapImage.y = pelican.y;
flapImage.alpha = 1; // Ensure the flap image is fully opaque
flapImage.update = function () {
this.alpha -= 0.1; // Fade out the image more quickly to last about a quarter second
if (this.alpha <= 0) {
this.destroy();
pelican.visible = true; // Make the pelican visible again
}
};
game.addChild(flapImage);
pelican.visible = false; // Hide the pelican when the flap image is on screen
};
game.up = function (x, y, obj) {
// No action needed on mouse up
};
// Start the music when the game begins
LK.playMusic('soundtrack', {
volume: 0.3
});
8-bit profile of pelican flying straight. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit profile of fish for arcade game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit profile of pelican flapping it's wings downward. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit silhouette of tugboat. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8-bit "YUM" dialog bubble. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.