Code edit (4 edits merged)
Please save this source code
User prompt
after the player taps again to move the fish, restart the fish from the same high speed, allowing it to sprint again to it's new destination
Code edit (1 edits merged)
Please save this source code
User prompt
the fish should have a deceleration speed. it needs to start with high velocity, as if it sprints, then slow down as it reaches it's destination.
User prompt
fix the fish movement by applying the fix from above
User prompt
the player fish should move to the location indicated by the player. wherever the player taps om thre screen, the fish should go to that location
User prompt
the player's fish stopped movign altogether. it should go to the location the player is tapping to
User prompt
instead of following the player's curor, wait for an input from th player. the player fish should go to the point where the player tapped on the screen. if the player taps before the fish reaches it's destiantion, nothging happens, the fish needs to reach it's destination before receiving a new command
Initial prompt
Grow Fish by eat smaller fish
===================================================================
--- original.js
+++ change.js
@@ -1,61 +1,87 @@
-/****
+/****
* Classes
****/
// Player fish class
var PlayerFish = Container.expand(function () {
- var self = Container.call(this);
- var playerGraphics = self.attachAsset('playerFish', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.move = function (direction) {
- self.x += direction.x * self.speed;
- self.y += direction.y * self.speed;
- };
- self.grow = function () {
- self.scaleX += 0.1;
- self.scaleY += 0.1;
- };
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('playerFish', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.destination = null;
+ self.move = function () {
+ if (self.destination) {
+ var direction = {
+ x: self.destination.x - self.x,
+ y: self.destination.y - self.y
+ };
+ var magnitude = Math.sqrt(direction.x * direction.x + direction.y * direction.y);
+ if (magnitude < self.speed) {
+ self.x = self.destination.x;
+ self.y = self.destination.y;
+ self.destination = null; // Reached destination
+ } else {
+ direction.x /= magnitude;
+ direction.y /= magnitude;
+ self.x += direction.x * self.speed;
+ self.y += direction.y * self.speed;
+ }
+ }
+ };
+ self.grow = function () {
+ self.scaleX += 0.1;
+ self.scaleY += 0.1;
+ };
});
// Enemy fish class
var EnemyFish = Container.expand(function () {
- var self = Container.call(this);
- var enemyGraphics = self.attachAsset('enemyFish', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 3;
- self.move = function () {
- self.x -= self.speed;
- };
+ var self = Container.call(this);
+ var enemyGraphics = self.attachAsset('enemyFish', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 3;
+ self.move = function () {
+ self.x -= self.speed;
+ };
});
// Food fish class
var FoodFish = Container.expand(function () {
- var self = Container.call(this);
- var foodGraphics = self.attachAsset('foodFish', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 2;
- self.move = function () {
- self.x -= self.speed;
- };
+ var self = Container.call(this);
+ var foodGraphics = self.attachAsset('foodFish', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2;
+ self.move = function () {
+ self.x -= self.speed;
+ };
});
-/****
+/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
****/
-// Initialize player, enemies, and food arrays
+// Touch down event to set player's destination
// Define assets for the player fish, enemy fish, and food fish
+// Initialize player, enemies, and food arrays
+game.on('down', function (obj) {
+ if (!player.destination) {
+ var touchPosition = obj.event.getLocalPosition(game);
+ player.destination = {
+ x: touchPosition.x,
+ y: touchPosition.y
+ };
+ }
+});
var player;
var enemies = [];
var food = [];
// Create the player fish
@@ -63,64 +89,52 @@
player.x = game.width / 2;
player.y = game.height / 2;
// Game tick event
LK.on('tick', function () {
- // Move enemies and check for off-screen
- for (var i = enemies.length - 1; i >= 0; i--) {
- enemies[i].move();
- if (enemies[i].x < -enemies[i].width) {
- enemies[i].destroy();
- enemies.splice(i, 1);
- }
- }
- // Move food and check for off-screen
- for (var j = food.length - 1; j >= 0; j--) {
- food[j].move();
- if (food[j].x < -food[j].width) {
- food[j].destroy();
- food.splice(j, 1);
- }
- }
- // Check for player collision with enemies
- for (var k = 0; k < enemies.length; k++) {
- if (player.intersects(enemies[k])) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- return;
- }
- }
- // Check for player collision with food
- for (var l = 0; l < food.length; l++) {
- if (player.intersects(food[l])) {
- player.grow();
- food[l].destroy();
- food.splice(l, 1);
- }
- }
- // Spawn enemies and food
- if (LK.ticks % 120 === 0) {
- var newEnemy = new EnemyFish();
- newEnemy.x = game.width;
- newEnemy.y = Math.random() * game.height;
- enemies.push(newEnemy);
- game.addChild(newEnemy);
- }
- if (LK.ticks % 60 === 0) {
- var newFood = new FoodFish();
- newFood.x = game.width;
- newFood.y = Math.random() * game.height;
- food.push(newFood);
- game.addChild(newFood);
- }
-});
-// Touch move event for player movement
-game.on('move', function (obj) {
- var touchPosition = obj.event.getLocalPosition(game);
- var direction = {
- x: touchPosition.x - player.x,
- y: touchPosition.y - player.y
- };
- var magnitude = Math.sqrt(direction.x * direction.x + direction.y * direction.y);
- direction.x /= magnitude;
- direction.y /= magnitude;
- player.move(direction);
+ // Move enemies and check for off-screen
+ for (var i = enemies.length - 1; i >= 0; i--) {
+ enemies[i].move();
+ if (enemies[i].x < -enemies[i].width) {
+ enemies[i].destroy();
+ enemies.splice(i, 1);
+ }
+ }
+ // Move food and check for off-screen
+ for (var j = food.length - 1; j >= 0; j--) {
+ food[j].move();
+ if (food[j].x < -food[j].width) {
+ food[j].destroy();
+ food.splice(j, 1);
+ }
+ }
+ // Check for player collision with enemies
+ for (var k = 0; k < enemies.length; k++) {
+ if (player.intersects(enemies[k])) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Check for player collision with food
+ for (var l = 0; l < food.length; l++) {
+ if (player.intersects(food[l])) {
+ player.grow();
+ food[l].destroy();
+ food.splice(l, 1);
+ }
+ }
+ // Spawn enemies and food
+ if (LK.ticks % 120 === 0) {
+ var newEnemy = new EnemyFish();
+ newEnemy.x = game.width;
+ newEnemy.y = Math.random() * game.height;
+ enemies.push(newEnemy);
+ game.addChild(newEnemy);
+ }
+ if (LK.ticks % 60 === 0) {
+ var newFood = new FoodFish();
+ newFood.x = game.width;
+ newFood.y = Math.random() * game.height;
+ food.push(newFood);
+ game.addChild(newFood);
+ }
});
\ No newline at end of file
Design a minimalistic, pixelated background for a cyberpunk AI city, focusing on a futuristic yet understated aesthetic to ensure it doesn't overshadow game elements.. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cute red enemy flying drone. angry eyes. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Design a pixel art scene for a game item: a TV broadcasting a news alert about an imminent AI uprising. Include flashing warning signs and depict the newscaster in a state of high alert to convey urgency and tension, ensuring all elements are styled to fit within a pixelated game environment.. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
notepad word document file icon. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
yellow warning sign. flat pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red flame. flat pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
blue text saying "+1". pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red danger warning sign. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.