User prompt
Poison should disappear after being touched by the snake
User prompt
The function of the poison will be similar to the food but in the negative side i.e., there will be a reduction in points
User prompt
Snake is not able to eat the purple box and the purple box is not showing any affect. correct that bug
User prompt
The purple box appears in the start of the game which is not correct instead the purple box which is poison will always appear after every 7-8 moves and the maximum limit for the purple box to appear will be 12. Further, the effect of the purple box is to reduce the size of snake by 2 box and reduce the point by -20 and also if the purple box should disappear after 10 second. Note: The yellow box functionality should not change.
User prompt
Please fix the bug: 'TypeError: setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 155
User prompt
Fix the necessary bugs
User prompt
fix the bug
User prompt
Fix the Bugs
User prompt
In the current game there are areas of improvement that has to be done. Based on the points given below do the necessary improvements accordingly. • The Game title and the Score are overlapping in the screen which makes it difficult to see the title and score, so separate both lives and score title. • Add a border line which doesn’t allows the snake to jump out of the screen i.e., when the snake touches the border line then the snake should bounce back to the viewport. • The snake movement is limited to x-axis so allow the snake to move in both X & Y axis. • Every time first the food should appear and randomly after 7-12 (number range varies from 7 to 12 times) turns along with the food the poison is also generated. Note: The poison will disappear after 10 second and again after the 7-12 turns the poison will reappear.
User prompt
When the game starts there are multiple food (yellow box) and poison (purple box) in the start, so have only 1 food/poison in the start and once it is consumed by the snake then the next food/poison will appear on the screen. Note: Food should be the first thing to appear by default.
Initial prompt
Snake Xenzia 2024
===================================================================
--- original.js
+++ change.js
@@ -1,171 +1,173 @@
-/****
+/****
* Classes
-****/
+****/
// Food class
var Food = Container.expand(function () {
- var self = Container.call(this);
- var foodGraphics = self.attachAsset('food', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.x = Math.random() * 2048;
- self.y = Math.random() * 2732;
+ var self = Container.call(this);
+ var foodGraphics = self.attachAsset('food', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = Math.random() * 2048;
+ self.y = Math.random() * 2732;
});
// Poison class
var Poison = Container.expand(function () {
- var self = Container.call(this);
- var poisonGraphics = self.attachAsset('poison', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.x = Math.random() * 2048;
- self.y = Math.random() * 2732;
+ var self = Container.call(this);
+ var poisonGraphics = self.attachAsset('poison', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = Math.random() * 2048;
+ self.y = Math.random() * 2732;
});
//<Assets used in the game will automatically appear here>
// Snake class
var Snake = Container.expand(function () {
- var self = Container.call(this);
- self.segments = [];
- self.direction = {
- x: 1,
- y: 0
- };
- self.speed = 10;
- self.grow = false;
- self.init = function () {
- for (var i = 0; i < 5; i++) {
- var segment = self.attachAsset('snakeSegment', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- segment.x = 1024 - i * 20;
- segment.y = 1366;
- self.segments.push(segment);
- }
- };
- self.update = function () {
- var newHead = {
- x: self.segments[0].x + self.direction.x * self.speed,
- y: self.segments[0].y + self.direction.y * self.speed
- };
- if (self.grow) {
- var newSegment = self.attachAsset('snakeSegment', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- newSegment.x = newHead.x;
- newSegment.y = newHead.y;
- self.segments.unshift(newSegment);
- self.grow = false;
- } else {
- for (var i = self.segments.length - 1; i > 0; i--) {
- self.segments[i].x = self.segments[i - 1].x;
- self.segments[i].y = self.segments[i - 1].y;
- }
- self.segments[0].x = newHead.x;
- self.segments[0].y = newHead.y;
- }
- };
- self.init();
+ var self = Container.call(this);
+ self.segments = [];
+ self.direction = {
+ x: 1,
+ y: 0
+ };
+ self.speed = 10;
+ self.grow = false;
+ self.init = function () {
+ for (var i = 0; i < 5; i++) {
+ var segment = self.attachAsset('snakeSegment', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ segment.x = 1024 - i * 20;
+ segment.y = 1366;
+ self.segments.push(segment);
+ }
+ };
+ self.update = function () {
+ var newHead = {
+ x: self.segments[0].x + self.direction.x * self.speed,
+ y: self.segments[0].y + self.direction.y * self.speed
+ };
+ if (self.grow) {
+ var newSegment = self.attachAsset('snakeSegment', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ newSegment.x = newHead.x;
+ newSegment.y = newHead.y;
+ self.segments.unshift(newSegment);
+ self.grow = false;
+ } else {
+ for (var i = self.segments.length - 1; i > 0; i--) {
+ self.segments[i].x = self.segments[i - 1].x;
+ self.segments[i].y = self.segments[i - 1].y;
+ }
+ self.segments[0].x = newHead.x;
+ self.segments[0].y = newHead.y;
+ }
+ };
+ self.init();
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var snake = game.addChild(new Snake());
var foods = [];
var poisons = [];
var score = 0;
var lives = 3;
var scoreTxt = new Text2('Score: 0', {
- size: 50,
- fill: "#ffffff"
+ size: 50,
+ fill: "#ffffff"
});
var livesTxt = new Text2('Lives: 3', {
- size: 50,
- fill: "#ffffff"
+ size: 50,
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
livesTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
LK.gui.top.addChild(livesTxt);
function spawnFood() {
- var food = new Food();
- foods.push(food);
- game.addChild(food);
+ var food = new Food();
+ foods.push(food);
+ game.addChild(food);
}
function spawnPoison() {
- var poison = new Poison();
- poisons.push(poison);
- game.addChild(poison);
+ var poison = new Poison();
+ poisons.push(poison);
+ game.addChild(poison);
}
function updateScore() {
- scoreTxt.setText('Score: ' + score);
+ scoreTxt.setText('Score: ' + score);
}
function updateLives() {
- livesTxt.setText('Lives: ' + lives);
- if (lives <= 0) {
- LK.showGameOver();
- }
+ livesTxt.setText('Lives: ' + lives);
+ if (lives <= 0) {
+ LK.showGameOver();
+ }
}
game.update = function () {
- snake.update();
- for (var i = foods.length - 1; i >= 0; i--) {
- if (snake.segments[0].intersects(foods[i])) {
- score += 10;
- updateScore();
- snake.grow = true;
- foods[i].destroy();
- foods.splice(i, 1);
- spawnFood();
- }
- }
- for (var i = poisons.length - 1; i >= 0; i--) {
- if (snake.segments[0].intersects(poisons[i])) {
- lives -= 1;
- updateLives();
- poisons[i].destroy();
- poisons.splice(i, 1);
- spawnPoison();
- }
- }
- if (LK.ticks % 300 == 0) {
- spawnFood();
- }
- if (LK.ticks % 500 == 0) {
- spawnPoison();
- }
+ snake.update();
+ for (var i = foods.length - 1; i >= 0; i--) {
+ if (snake.segments[0].intersects(foods[i])) {
+ score += 10;
+ updateScore();
+ snake.grow = true;
+ foods[i].destroy();
+ foods.splice(i, 1);
+ if (foods.length == 0) {
+ spawnFood();
+ }
+ }
+ }
+ for (var i = poisons.length - 1; i >= 0; i--) {
+ if (snake.segments[0].intersects(poisons[i])) {
+ lives -= 1;
+ updateLives();
+ poisons[i].destroy();
+ poisons.splice(i, 1);
+ if (poisons.length == 0) {
+ spawnPoison();
+ }
+ }
+ }
};
game.down = function (x, y, obj) {
- var head = snake.segments[0];
- if (x > head.x) {
- snake.direction = {
- x: 1,
- y: 0
- };
- } else if (x < head.x) {
- snake.direction = {
- x: -1,
- y: 0
- };
- } else if (y > head.y) {
- snake.direction = {
- x: 0,
- y: 1
- };
- } else if (y < head.y) {
- snake.direction = {
- x: 0,
- y: -1
- };
- }
+ var head = snake.segments[0];
+ if (x > head.x) {
+ snake.direction = {
+ x: 1,
+ y: 0
+ };
+ } else if (x < head.x) {
+ snake.direction = {
+ x: -1,
+ y: 0
+ };
+ } else if (y > head.y) {
+ snake.direction = {
+ x: 0,
+ y: 1
+ };
+ } else if (y < head.y) {
+ snake.direction = {
+ x: 0,
+ y: -1
+ };
+ }
};
-spawnFood();
-spawnPoison();
\ No newline at end of file
+if (foods.length == 0) {
+ spawnFood();
+}
+if (poisons.length == 0) {
+ spawnPoison();
+}
\ No newline at end of file
Apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Poisonous Skull. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pause icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
heart icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Snake Face. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Ostrich egg. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.