User prompt
make wide obcatcle spawn less frequent
User prompt
create a new type of obctacle. make it more wider as wide as the screen. The hero must jump across it with clicl
User prompt
Make obtacles bigger and harder to pass
User prompt
make hero move horizontally
User prompt
Make obtacle descend from random spots from the top
User prompt
Please fix the bug: 'TypeError: LK.isKeyDown is not a function' in or related to this line: 'if (LK.isKeyDown('ArrowLeft')) {' Line Number: 21
User prompt
make hero move in a horizontal way
User prompt
make obstacles descend from the top
User prompt
Please turn the field 90 degrees ledt
Initial prompt
History Runner
/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Hero update logic if (keyState['ArrowLeft']) { self.x -= self.speed; } if (keyState['ArrowRight']) { self.x += self.speed; } }; self.jump = function () { // Hero jump logic }; }); // 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.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var keyState = {}; window.addEventListener('keydown', function (e) { keyState[e.key] = true; }); window.addEventListener('keyup', function (e) { keyState[e.key] = false; }); var hero; var obstacles = []; var scoreTxt; var score = 0; var gameSpeed = 5; // Initialize hero function initHero() { hero = new Hero(); hero.x = 200; hero.y = 2500; game.addChild(hero); } // Initialize score text function initScore() { scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); } // Update score function updateScore() { score += 1; scoreTxt.setText(score); } // Spawn obstacle function spawnObstacle() { var obstacle = new Obstacle(); obstacle.x = 2048; obstacle.y = -obstacle.height; obstacles.push(obstacle); game.addChild(obstacle); } // Handle game over function handleGameOver() { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Handle move event function handleMove(x, y, obj) { if (hero) { hero.x = x; } } // Handle down event function handleDown(x, y, obj) { if (hero) { hero.jump(); } } // Game update function game.update = function () { // Update hero if (hero) { hero.update(); } // Update obstacles for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].update(); if (hero && hero.intersects(obstacles[i])) { handleGameOver(); } } // Spawn new obstacle if (LK.ticks % (120 / gameSpeed) == 0) { spawnObstacle(); } // Update score if (LK.ticks % 60 == 0) { updateScore(); } }; // Initialize game elements initHero(); initScore(); // Set event listeners game.move = handleMove; game.down = handleDown;
===================================================================
--- original.js
+++ change.js
@@ -11,12 +11,12 @@
});
self.speed = 10;
self.update = function () {
// Hero update logic
- if (LK.isKeyDown('ArrowLeft')) {
+ if (keyState['ArrowLeft']) {
self.x -= self.speed;
}
- if (LK.isKeyDown('ArrowRight')) {
+ if (keyState['ArrowRight']) {
self.x += self.speed;
}
};
self.jump = function () {
@@ -42,14 +42,21 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
+var keyState = {};
+window.addEventListener('keydown', function (e) {
+ keyState[e.key] = true;
+});
+window.addEventListener('keyup', function (e) {
+ keyState[e.key] = false;
+});
var hero;
var obstacles = [];
var scoreTxt;
var score = 0;
a caveman with a club, seen from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of a delicious meat. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A animated image of a stone boulder. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A animated image of a mommoth. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A animated image of a aggressive caveman with a club. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A road in a jungle with a cave nearby
An animated image of a wooden wheel with a sign: The invention of the wheel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of a desert with a pyramid. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an egyptian warrior. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an aggressive egyptian warrior. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of a wooden arrow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of a lion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an unfinished pyramid, with a label 'The building of the Pyramids of Giza. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an ancient greek city with an Acropolis. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an ancient greek warrior. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of an aggressive ancient greek warrior. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image of the colosseum. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image a medieval city with a castle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image a medieval knight. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image an aggressive medieval knight. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An animated image a fierce wolf. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.