Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
make this line work: ballGraphics.texture = LK.getAsset('newDeathSpriteId', {}).texture;
User prompt
Fix Bug: 'TypeError: ballGraphics.setTextureFromAsset is not a function' in or related to this line: '_iterator.f();' Line Number: 429
User prompt
Fix Bug: 'TypeError: ballGraphics.setTexture is not a function' in or related to this line: '_iterator.f();' Line Number: 429
User prompt
in the deathanim function, ball sprite should change to another one.
Code edit (10 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'setText')' in or related to this line: '_iterator.f();' Line Number: 466
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'setText')' in or related to this line: '_iterator.f();' Line Number: 466
Code edit (1 edits merged)
Please save this source code
User prompt
Every time the player gets points, they should be multiplied by the variable (multiplier-1).
User prompt
Every time the player gets points, they should be multiplied by the variable (multiplier-1).
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'toString')' in or related to this line: 'mulText.setText('x' + newVal.toString());' Line Number: 176
User prompt
Fix Bug: 'ReferenceError: valText is not defined' in or related to this line: 'valText.anchor.set(0.5, 0.5);' Line Number: 173
Code edit (3 edits merged)
Please save this source code
User prompt
scorelabels should fly off in a random upwards direction instead of just up.
Code edit (1 edits merged)
Please save this source code
User prompt
add all created scorelabels to the scoreLabels array on creation.
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'update')' in or related to this line: 'self.scoreLabel.update();' Line Number: 323
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'update')' in or related to this line: 'self.scoreLabel.update();' Line Number: 323
Code edit (1 edits merged)
Please save this source code
/****
* Classes
****/
var ScoreLabel = Container.expand(function (scoreValue, posX, posY) {
var self = Container.call(this);
var scoreText = new Text2(scoreValue.toString(), {
size: 75,
fill: "#ffffff"
});
scoreText.anchor.set(0.5, 0.5);
self.addChild(scoreText);
self.x = posX;
self.y = posY;
// Animation for the score label to drift upwards and fade out
var driftFrames = 60;
self.update = function () {
if (driftFrames > 0) {
self.y -= 2;
scoreText.alpha -= 1 / driftFrames;
driftFrames--;
} else {
self.destroy();
}
};
self.updateScore = function (newScore) {
scoreText.setText(newScore.toString());
};
});
/*
TODO:
--------------------
Bugs:
The red platforms have to be really shining up in red, dangerous looking.
Now that player graphic is bigger, it sometimes collides with platforms from below. Either adjust size, spacing
or jump height/logic.
The platforms array grows in length over time. Try to remove deleted elements from it, but make backup first,
because this is where the AI started optimizing to make the game page freeze last time.
Maybe remove the immunity from normal powerups, it's confusing.
Show points when player hits platform or gets powerup.
---------------------
Interface/graphics:
Show instructions on screen at start.
Maybe tint platforms based on their overall depth.
Consider a background graphic or color.
Consider smileyfaces on the platforms - angry ones on the red ones.
When player dies, maybe make them fall out of screen, facing player, screaming, waving hands, like in the old
Rick Dangerous games for Amiga.
--------------
Powerup ideas:
A powerup that removes all nearby platforms and give score for them
Maybe make a disco powerup that changes light, colors or visuals somehow
Consider a score multiplier powerup - either where player's score is instantly doubled,
or where score for each following platform hit is doubled.
Consider platforms that increase or decrease the size/weight of the character.
Like a powerup platform that turns the player into a squirrel, no bouncing, just running and falling off platforms,
changing direction on player click. (But players would probably die from this, killing the joke?)
Or maybe just a platform with a piece of cake on it, and when player lands there he gets 10 points and swells up
(no gameplay side effects) for 5 seconds. Could actually be all kinds of funny pickups like that.
A beer that inverses controls (but again, players will be frustrated by rapid changes)
A companion character that follows you with a slight delay. Maybe a dog or bird that can be delivered to a dog house
or cage or a tree/forest on a deeper platform for points?
Or different hats that the player will wear until a new one is picked up?
There could be a scene just before gameover, showing how many dogs were saved, how many cakes were eaten,
how many hats were worn, etc. Or a festive explosion of all the items and platforms the player touched
during the game.
----------
Gameplay:
Consider difficulty ramping. More red platforms?
Make sure red platforms never fully block the way. Probably means platforms should have row-id's, so rows can be checked.
-----------
Theming:
Consider appropriate player character.
A frog? A kangaroo? A spring? A tennisball? A rabbit? A two-headed squirrel? A something on a pogostick?
A Rick Dangerous finding treasures on the platforms?
A Pirate Ship finding bounty on platforms? Maybe beats platforms with less strength than they have?
A cat eating sushi on each platform?
A princess saving animals on every tenth platform?
Maybe all those characters, each triggered by a powerup until a new one is picked up.
Maybe new mode unlocked per 200 platforms or so?
----------
*/
var PlayerScoreLabel = Container.expand(function () {
var self = Container.call(this);
var scoreText = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreText.anchor.set(0.5, 0);
self.addChild(scoreText);
self.updateScore = function (newScore) {
scoreText.setText(newScore.toString());
};
self.updateScore(0); // Initialize with 0 score
});
var DepthLabel = Container.expand(function () {
var self = Container.call(this);
var depthText = new Text2('0', {
size: 75,
fill: "#dddddd"
});
depthText.anchor.set(0.5, 0);
depthText.x = -150;
self.addChild(depthText);
self.updateDepthLabel = function (newDepth) {
depthText.setText(maxDepth.toString());
};
self.updateDepthLabel(0); // Initialize with 0 score
});
// Platform class to create movable platforms
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial position
//self.x = game.width / 2;
//self.y = game.height - 100;
self.width = 200;
self.height = 60; //20;
self.toxic = false;
self.row = 0;
self.col = 0;
self.powerup = false;
self.collidable = true;
// Set platform tint based on toxicity
self.setTint = function () {
if (platformGraphics) {
platformGraphics.tint = this.toxic ? 0xff0000 : 0xffffff;
}
};
self.setTint();
});
var PowerupBurst = Container.expand(function () {
var self = Container.call(this);
var powerupBurstGraphics = self.attachAsset('powerupBurst', {
anchorX: 0.5,
anchorY: 0.5
});
self.col = 0;
self.row = 0;
self.toxic = false;
self.powerup = true;
self.powerupType = "Burst";
self.collidable = true;
self.velocityBoost = 50;
self.immunityBoost = 10;
self.scoreBoost = 10;
});
var PowerupFollow = Container.expand(function () {
var self = Container.call(this);
var powerupFollowGraphics = self.attachAsset('powerupFollow', {
anchorX: 0.5,
anchorY: 0
});
self.col = 0;
self.row = 0;
self.toxic = false;
self.powerup = true;
self.powerupType = "Follow";
self.followActivated = false;
self.collidable = true;
self.velocityBoost = 50;
self.immunityBoost = 1;
self.scoreBoost = 10;
self.vely = 1;
self.freeGraphicName = 'powerupFollowFree';
self.update = function () {
if (this.followActivated) {
if (self.x > 1024) {
this.x += 4;
} else {
this.x -= 4;
}
this.vely *= 1.1;
this.width *= 1.01;
this.height *= 1.01;
this.y -= this.vely;
if (self.x < -self.width / 2 || self.x > 2048 + self.width / 2) {
self.destroy();
}
}
};
});
var PowerupBluebird = Container.expand(function () {
var self = Container.call(this);
var powerupBluebirdGraphics = self.attachAsset('powerupBluebird', {
anchorX: 0.5,
anchorY: 0
});
self.col = 0;
self.row = 0;
self.toxic = false;
self.powerup = true;
self.powerupType = "Follow";
self.freeGraphicName = "bluebirdFreeGraphic";
self.followActivated = false;
self.collidable = true;
self.velocityBoost = 50;
self.immunityBoost = 1;
self.scoreBoost = 20;
self.vely = 1;
self.update = function () {
if (this.followActivated) {
if (self.x > 1024) {
this.x += 4;
} else {
this.x -= 4;
}
this.vely *= 1.1;
this.width *= 1.01;
this.height *= 1.01;
this.y -= this.vely;
if (self.x < -self.width / 2 || self.x > 2048 + self.width / 2) {
self.destroy();
}
}
};
});
var PowerupGreenbird = Container.expand(function () {
var self = Container.call(this);
var powerupGreenbirdGraphics = self.attachAsset('powerupGreenbird', {
anchorX: 0.5,
anchorY: 0
});
self.col = 0;
self.row = 0;
self.toxic = false;
self.powerup = true;
self.powerupType = "Follow";
self.freeGraphicName = "greenbirdFreeGraphic";
self.followActivated = false;
self.collidable = true;
self.velocityBoost = 50;
self.immunityBoost = 1;
self.scoreBoost = 30;
self.vely = 1;
self.update = function () {
if (this.followActivated) {
if (self.x > 1024) {
this.x += 4;
} else {
this.x -= 4;
}
this.vely *= 1.1;
this.width *= 1.01;
this.height *= 1.01;
this.y -= this.vely;
if (self.x < -self.width / 2 || self.x > 2048 + self.width / 2) {
self.destroy();
}
}
};
});
var PowerupScore = Container.expand(function () {
var self = Container.call(this);
var powerupScoreGraphics = self.attachAsset('powerupScore', {
anchorX: 0.5,
anchorY: 0.5
});
self.col = 0;
self.row = 0;
self.toxic = false;
self.powerup = true;
self.powerupType = "Score";
self.collidable = true;
self.scoreVal = 0;
self.velocityBoost = 25;
self.immunityBoost = 3;
self.scoreBoost = 0;
var valText = new Text2('0', {
size: 50,
fill: "#000000",
outline: true
});
valText.anchor.set(0.5, 0.5);
self.addChild(valText);
self.updateLabel = function (newVal) {
valText.setText(self.scoreVal.toString());
self.scoreBoost = newVal;
};
self.updateLabel(self.scoreVal);
});
// Platform class to create movable platforms
var SideBarrier = Container.expand(function () {
var self = Container.call(this);
var sideBarrierGraphics = self.attachAsset('sideBarrier', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = 300;
self.height = 300;
self.toxic = false;
self.row = 0;
self.col = 0;
self.powerup = false;
self.collidable = false;
// Set platform tint based on toxicity
self.setTint = function () {
self.tint = sideBarrierGraphics.tint = self.toxic ? 0xff0000 : 0xff0101;
};
this.setTint();
});
// Ball class to create the bouncing ball
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial position and velocity
self.x = game.width / 2 + 100;
self.y = game.height / 4;
self.velocity = {
//x: -10,
x: 0,
y: -20
};
self.immunity = 0;
self.followers = 0;
// Function to update ball position
self.update = function () {
self.scoreLabel.update();
if (self.x > 500 && self.x < 1548) {
self.x += self.velocity.x;
} else {
platforms.forEach(function (platform) {
platform.x -= self.velocity.x;
});
}
self.velocity.y += 1; // simple gravity
if (self.y < 500) {
self.y += self.velocity.y;
} else {
platforms.forEach(function (platform) {
platform.y -= self.velocity.y;
});
}
// Update score labels
platforms.forEach(function (platform) {
if (platform instanceof ScoreLabel) {
platform.update();
}
});
};
// Function to bounce the ball off platforms with a bounce counter
self.bounceCounter = 0;
self.bounce = function (platforms) {
//platforms.forEach(function (platform) {
var _iterator = _createForOfIteratorHelper(platforms),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var platform = _step.value;
if (platform && platform.collidable && platform.alpha == 1) {
if (self.intersects(platform) && self.velocity.y > 0) {
// If player has immunity left (from a powerup) he just passes through the platform.
if (self.immunity > 0) {
self.immunity--;
//platform.alpha = 0.2;
platform.alpha = 0;
// If immunity is spent, player jumps up, so he has time to dodge a possibly toxic platform below.
if (self.immunity == 0) {
self.velocity.y = -30;
}
break;
}
if (platform.toxic) {
LK.showGameOver();
break;
}
//self.velocity.y = -20;
self.velocity.y *= -1;
//self.velocity.y = Math.min ()
if (self.velocity.y < -40) {
self.velocity.y = -40;
}
//self.velocity.x *= -1;
//platform.alpha = 0.2;
platform.alpha = 0;
LK.setScore(LK.getScore() + 1);
// Create and display score label
var scoreLabel = new ScoreLabel(1, self.x, self.y);
scoreLabel.updateScore(LK.getScore() + 1);
game.addChild(scoreLabel);
if (platform.powerup == true) {
//self.velocity.y = 50;
self.velocity.y = platform.velocityBoost;
//self.immunity = 10;
self.immunity = platform.immunityBoost;
//LK.setScore(LK.getScore() + 10);
LK.setScore(LK.getScore() + platform.scoreBoost);
// Create and display score label
var scoreLabel = new ScoreLabel(platform.scoreBoost, self.x, self.y);
scoreLabel.updateScore(LK.getScore() + platform.scoreBoost);
game.addChild(scoreLabel);
if (platform.powerupType != "Follow") {
platform.destroy();
} else {
self.followers += 1;
/*
if (platform.powerupFollowGraphics && platform.powerupFollowGraphicsFree) {
platform.powerupFollowGraphics.visible = false;
platform.powerupFollowGraphicsFree.visible = true;
}*/
platform.removeChild(platform.getChildAt(0));
//platform.attachAsset('powerupFollowFree', {
platform.attachAsset(platform.freeGraphicName, {
anchorX: 0.5,
anchorY: 0.5
});
platform.followActivated = true;
platform.alpha = 1;
platform.collidable = false;
}
}
playerScoreLabel.updateScore(LK.getScore());
if (platform.row > maxDepth) {
maxDepth = platform.row;
maxDepthLabel.updateDepthLabel(maxDepth);
}
}
}
}
} catch (err) {
_iterator.e(err);
} finally {
if (_iterator) {
_iterator.f();
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Create background graphic and add it to the game
// Initialize background graphic asset
var backgroundGraphic = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
// Centered on x-axis
y: 1366 // Centered on y-axis
}));
backgroundGraphic.zIndex = -1; // Ensure it's beneath everything
backgroundGraphic.alpha = 0.8;
function _createForOfIteratorHelper(o, allowArrayLike) {
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (!it) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) {
o = it;
}
var i = 0;
var F = function F() {};
return {
s: F,
n: function n() {
if (i >= o.length) {
return {
done: true
};
}
return {
done: false,
value: o[i++]
};
},
e: function e(_e) {
throw _e;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var normalCompletion = true,
didErr = false,
err;
return {
s: function s() {
it = it.call(o);
},
n: function n() {
var step = it.next();
normalCompletion = step.done;
return step;
},
e: function e(_e2) {
didErr = true;
err = _e2;
},
f: function f() {
try {
if (!normalCompletion && it && typeof it["return"] === 'function') {
it["return"]();
}
} finally {
if (didErr) {
throw err;
}
}
}
};
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) {
return;
}
if (typeof o === "string") {
return _arrayLikeToArray(o, minLen);
}
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) {
n = o.constructor.name;
}
if (n === "Map" || n === "Set") {
return Array.from(o);
}
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) {
return _arrayLikeToArray(o, minLen);
}
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) {
len = arr.length;
}
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
return arr2;
}
var platforms = [];
var moveLeftFrames = 0;
var moveRightFrames = 0;
var rowAmount = 13;
var maxDepth = 0;
// Create player score label
var playerScoreLabel = new PlayerScoreLabel();
LK.gui.top.addChild(playerScoreLabel);
var maxDepthLabel = new DepthLabel();
LK.gui.topRight.addChild(maxDepthLabel);
// Create 14 rows of 5 platforms each at game start
for (var row = 0; row < rowAmount; row++) {
/*
var leftBarrier = new SideBarrier();
leftBarrier.x = 2048 / 2 - 1100; //-75;
leftBarrier.y = game.height - 2000 + row * 300;
leftBarrier.row = row;
leftBarrier.col = -1;
platforms.push(leftBarrier);
game.addChild(leftBarrier);
*/
for (var col = 0; col < 5; col++) {
var platform = new Platform();
if (row < rowAmount / 2) {
//platform.alpha = 0.2;
platform.alpha = 0;
platform.toxic = false;
} else if (row === Math.ceil(rowAmount / 2)) {
platform.alpha = 1;
platform.toxic = false;
} else {
//platform.alpha = Math.random() < 0.5 ? 1 : 0.2;
platform.alpha = Math.random() < 0.5 ? 1 : 0;
platform.toxic = Math.random() < 0.1 ? true : false;
}
platform.setTint();
platform.y = game.height - 2000 + row * 300; // Position platforms vertically
//platform.x = col * (platform.width + 10) + (game.width - 5 * platform.width - 4 * 10) / 2; // Position platforms horizontally
//platform.x = 200 + col * (platform.width + 200);
platform.x = 2048 / 2 + (2 - col) * (platform.width + 200);
platform.row = row;
platform.col = col;
platforms.push(platform);
game.addChild(platform);
}
/*
var rightBarrier = new SideBarrier();
rightBarrier.x = 2048 / 2 + 1100; //2075;
rightBarrier.y = game.height - 2000 + row * 300;
rightBarrier.row = row;
rightBarrier.col = 5;
platforms.push(rightBarrier);
game.addChild(rightBarrier);
*/
}
var ball = new Ball();
ball.x = 1024;
game.addChild(ball);
// Handle touch move events to move platforms
function handleMove(obj) {
var event = obj.event;
var position = event.getLocalPosition(game);
// Move ball depending on whether click is left or right of it.
if (position.x > ball.x) {
// Take previous clicks into account, so ball can't fly off stage.
if (ball.x < 2048 - (300 + moveRightFrames * 40)) {
moveRightFrames += 10;
}
} else {
// Take previous clicks into account, so ball can't fly off stage.
if (ball.x > 300 + moveLeftFrames * 40) {
moveLeftFrames += 10;
}
}
}
// Add event listener for touch down
game.on('down', handleMove);
// Game tick event
LK.on('tick', function () {
if (LK.ticks % 120 == 0) {
console.log('Platforms.length is now: ' + platforms.length);
}
// Update ball position
ball.update(platforms);
// Check for ball bouncing off platforms
ball.bounce(platforms);
if (moveLeftFrames > 0) {
moveLeftFrames--;
/*
platforms.forEach(function (platform) {
platform.x -= 40;
});
*/
ball.x -= 40;
}
if (moveRightFrames > 0) {
moveRightFrames--;
/*
platforms.forEach(function (platform) {
platform.x += 40;
});
*/
ball.x += 40;
}
platforms.forEach(function (platform) {
if (platform.update) {
platform.update();
}
if (platform instanceof ScoreLabel) {
platform.update();
} else if (platform.y < -900) {
platform.y += rowAmount * 300;
platform.row += rowAmount;
// Only randomize normal platforms, not sidebarriers.
if (platform.height < 100) {
//platform.alpha = Math.random() < 0.5 ? 1 : 0.2;
platform.alpha = Math.random() < 0.5 ? 1 : 0;
platform.toxic = Math.random() < 0.1 ? true : false;
platform.setTint();
// Chance that powerups are spawned on normal platforms
if (platform.alpha == 1 && platform.powerup == false && !platform.toxic) {
if (Math.random() < 0.01) {
var t = new PowerupBurst();
t.x = platform.x;
t.y = platform.y - t.height;
platforms.push(t);
game.addChild(t);
} else if (platform.row % 25 == 0 && Math.random() < 0.5) {
var t = new PowerupScore();
t.x = platform.x;
t.y = platform.y - t.height;
t.scoreVal = platform.row;
t.updateLabel(t.scoreVal);
platforms.push(t);
game.addChild(t);
} else if (Math.random() < 0.1) {
if (maxDepth < 30) {
var t = new PowerupFollow();
} else if (maxDepth < 100) {
if (Math.random() < 0.5) {
var t = new PowerupFollow();
} else {
var t = new PowerupBluebird();
}
} else if (maxDepth < 200) {
var r = Math.random();
if (r < 0.33) {
var t = new PowerupFollow();
} else if (r < 0.66) {
var t = new PowerupBluebird();
} else {
var t = new PowerupGreenbird();
}
} else {
var t = new PowerupBluebird();
}
t.x = platform.x;
t.y = platform.y - t.height;
platforms.push(t);
game.addChild(t);
}
}
}
// Powerups don't automatically respawn below when they move off screen top edge.
if (platform.powerup == true) {
platform.destroy();
}
}
});
});
A happy blue elephant.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
erase.
Make the bird sit inside a birdcage.
Three green arrows pointing down.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A sad little bluebird sitting down.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A happy little bluebird flying.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A happy little green bird flying.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A lush jungle scenery with huge old trees covered in vines and overwrowth, blue sky and forested mountains in the background.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A dark wooden message board with vines and jungle moss growing on top.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A happy little blue elephant, looking scared, facing the viewer, legs flailing as it falls through the air.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A delicious peanut.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
delete