User prompt
Please fix the bug: 'TypeError: setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 91
User prompt
make it so it makes the tree spawn at the top of the screen and spawns in branches and before falling off it shakes for 2.05 seconds then falls off and stops shaking
User prompt
make a tree that makes the bananas fall down
User prompt
make a main menu and make a play button and when play button pressed it starts the game
User prompt
make the background into a jungle
Initial prompt
Gorilla 3D
/**** * Classes ****/ // Banana class var Banana = Container.expand(function () { var self = Container.call(this); var bananaGraphics = self.attachAsset('banana', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 5; // Move banana downwards if (self.y > 2732) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Gorilla class var Gorilla = Container.expand(function () { var self = Container.call(this); var gorillaGraphics = self.attachAsset('gorilla', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Gorilla update logic }; self.jump = function () { // Gorilla jump logic }; }); // Main Menu class var MainMenu = Container.expand(function () { var self = Container.call(this); var playButton = new Text2('Play', { size: 200, fill: "#ffffff" }); playButton.anchor.set(0.5, 0.5); playButton.x = 2048 / 2; playButton.y = 2732 / 2; self.addChild(playButton); playButton.down = function () { self.destroy(); startGame(); }; }); // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += 5; // Move obstacle downwards if (self.y > 2732) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228B22 // Init game with jungle green background }); /**** * Game Code ****/ var mainMenu = new MainMenu(); game.addChild(mainMenu); // Initialize arrays and variables var gorilla; var bananas = []; var obstacles = []; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); function startGame() { // Initialize gorilla gorilla = game.addChild(new Gorilla()); gorilla.x = 2048 / 2; gorilla.y = 2732 - 200; // Function to spawn bananas function spawnBanana() { var banana = new Banana(); banana.x = Math.random() * 2048; banana.y = -50; bananas.push(banana); game.addChild(banana); } // Function to spawn obstacles function spawnObstacle() { var obstacle = new Obstacle(); obstacle.x = Math.random() * 2048; obstacle.y = -50; obstacles.push(obstacle); game.addChild(obstacle); } // Handle game move events game.move = function (x, y, obj) { gorilla.x = x; }; // Update game logic game.update = function () { // Update bananas for (var i = bananas.length - 1; i >= 0; i--) { bananas[i].update(); if (gorilla.intersects(bananas[i])) { score += 1; scoreTxt.setText(score); bananas[i].destroy(); bananas.splice(i, 1); } } // Update obstacles for (var j = obstacles.length - 1; j >= 0; j--) { obstacles[j].update(); if (gorilla.intersects(obstacles[j])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Spawn bananas and obstacles if (LK.ticks % 60 == 0) { spawnBanana(); } if (LK.ticks % 120 == 0) { spawnObstacle(); } }; }
===================================================================
--- original.js
+++ change.js
@@ -29,8 +29,24 @@
self.jump = function () {
// Gorilla jump logic
};
});
+// Main Menu class
+var MainMenu = Container.expand(function () {
+ var self = Container.call(this);
+ var playButton = new Text2('Play', {
+ size: 200,
+ fill: "#ffffff"
+ });
+ playButton.anchor.set(0.5, 0.5);
+ playButton.x = 2048 / 2;
+ playButton.y = 2732 / 2;
+ self.addChild(playButton);
+ playButton.down = function () {
+ self.destroy();
+ startGame();
+ };
+});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
@@ -54,8 +70,10 @@
/****
* Game Code
****/
+var mainMenu = new MainMenu();
+game.addChild(mainMenu);
// Initialize arrays and variables
var gorilla;
var bananas = [];
var obstacles = [];
@@ -65,56 +83,58 @@
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
-// Initialize gorilla
-gorilla = game.addChild(new Gorilla());
-gorilla.x = 2048 / 2;
-gorilla.y = 2732 - 200;
-// Function to spawn bananas
-function spawnBanana() {
- var banana = new Banana();
- banana.x = Math.random() * 2048;
- banana.y = -50;
- bananas.push(banana);
- game.addChild(banana);
-}
-// Function to spawn obstacles
-function spawnObstacle() {
- var obstacle = new Obstacle();
- obstacle.x = Math.random() * 2048;
- obstacle.y = -50;
- obstacles.push(obstacle);
- game.addChild(obstacle);
-}
-// Handle game move events
-game.move = function (x, y, obj) {
- gorilla.x = x;
-};
-// Update game logic
-game.update = function () {
- // Update bananas
- for (var i = bananas.length - 1; i >= 0; i--) {
- bananas[i].update();
- if (gorilla.intersects(bananas[i])) {
- score += 1;
- scoreTxt.setText(score);
- bananas[i].destroy();
- bananas.splice(i, 1);
- }
+function startGame() {
+ // Initialize gorilla
+ gorilla = game.addChild(new Gorilla());
+ gorilla.x = 2048 / 2;
+ gorilla.y = 2732 - 200;
+ // Function to spawn bananas
+ function spawnBanana() {
+ var banana = new Banana();
+ banana.x = Math.random() * 2048;
+ banana.y = -50;
+ bananas.push(banana);
+ game.addChild(banana);
}
- // Update obstacles
- for (var j = obstacles.length - 1; j >= 0; j--) {
- obstacles[j].update();
- if (gorilla.intersects(obstacles[j])) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
+ // Function to spawn obstacles
+ function spawnObstacle() {
+ var obstacle = new Obstacle();
+ obstacle.x = Math.random() * 2048;
+ obstacle.y = -50;
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
}
- // Spawn bananas and obstacles
- if (LK.ticks % 60 == 0) {
- spawnBanana();
- }
- if (LK.ticks % 120 == 0) {
- spawnObstacle();
- }
-};
\ No newline at end of file
+ // Handle game move events
+ game.move = function (x, y, obj) {
+ gorilla.x = x;
+ };
+ // Update game logic
+ game.update = function () {
+ // Update bananas
+ for (var i = bananas.length - 1; i >= 0; i--) {
+ bananas[i].update();
+ if (gorilla.intersects(bananas[i])) {
+ score += 1;
+ scoreTxt.setText(score);
+ bananas[i].destroy();
+ bananas.splice(i, 1);
+ }
+ }
+ // Update obstacles
+ for (var j = obstacles.length - 1; j >= 0; j--) {
+ obstacles[j].update();
+ if (gorilla.intersects(obstacles[j])) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ }
+ // Spawn bananas and obstacles
+ if (LK.ticks % 60 == 0) {
+ spawnBanana();
+ }
+ if (LK.ticks % 120 == 0) {
+ spawnObstacle();
+ }
+ };
+}
\ No newline at end of file