User prompt
Has que el meteorito este ala altura de la cabeza del dinosaurio
User prompt
Has otro obstáculo que sea un meteorito y que salga cada 5 segundos
User prompt
Has que las balas no giren
User prompt
Incrementa que suba más la velocidad cada 10 segundos aproximadamente lo doble ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Has que cada 10 segundos el dinosaurio se mueva más rápido ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Has que el dinosaurio se mueva infinitamente
User prompt
Hs que el piso sea infinito
User prompt
Hs que la cámara siga el movimiento del dinosaurio
User prompt
Has que el dinosaurio también avance hacia adelante ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Has que poco a poco se incrementa la velocidad
User prompt
Has que el dinosaurio salte más alto ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Has que las balas salgan ala altura del dinosaurio ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Añade que las balas también parezcan abajo y también añade una pantalla que salga cuando pierdas y dija suerte pa la próxima bot ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'storage.get is not a function' in or related to this line: 'var highScore = storage.get('highScore') || 0;' Line Number: 199 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Genera el juego del dinosaurio de Google pero debes de los dinosaurios de obstáculos los voladores pon bañas ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Añade que cuando selecciones en botón de drestuir bloques puedas seleccionar el bloque que quieras drestuir y el bloque seleccionado se destruya ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Añade un botón de pegar con su animación y un botón de destruir bloques y su animación ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Añade al personaje una pequeña animación dependiendo el botón de movimiento que piques ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Los botones que se vean en la parte izquierda de abajo de la pantalla
User prompt
Añade que con los botones de movimiento se pueda mover el personaje de derecha a izquierda y pueda saltar
User prompt
Añade un personaje y botones de movimiento
User prompt
Please fix the bug: 'self.getMiningTime is not a function' in or related to this line: 'self.maxMiningTime = self.getMiningTime(blockType);' Line Number: 33
Code edit (1 edits merged)
Please save this source code
User prompt
PixelCraft Builder
Initial prompt
Un estilo Minecraft en 2d
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Banana = Container.expand(function (x, y) {
var self = Container.call(this);
var bananaGraphics = self.attachAsset('banana', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.speed = gameSpeed;
self.lastX = self.x;
// Add slight rotation animation to bananas
tween(bananaGraphics, {
rotation: Math.PI * 2
}, {
duration: 2000,
easing: tween.linear
});
self.update = function () {
self.lastX = self.x;
self.x -= self.speed;
// Remove banana when it goes off screen
if (self.x < -50) {
self.destroy();
for (var i = 0; i < bananas.length; i++) {
if (bananas[i] === self) {
bananas.splice(i, 1);
break;
}
}
}
};
return self;
});
var Cloud = Container.expand(function (x, y) {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.speed = gameSpeed * 0.3; // Clouds move slower than obstacles
cloudGraphics.alpha = 0.7;
self.update = function () {
self.x -= self.speed;
// Remove cloud when it goes off screen and recycle
if (self.x < -100) {
self.x = 2148; // Reset to right side of screen
}
};
return self;
});
var Dinosaur = Container.expand(function () {
var self = Container.call(this);
var dinoGraphics = self.attachAsset('dinosaur', {
anchorX: 0.5,
anchorY: 1
});
self.x = 300;
self.y = GROUND_Y;
self.velocityY = 0;
self.onGround = true;
self.jumpPower = -18;
self.gravity = 1.2;
self.isJumping = false;
self.lastOnGround = true;
self.jump = function () {
if (self.onGround) {
self.velocityY = self.jumpPower;
self.onGround = false;
self.isJumping = true;
LK.getSound('jump').play();
// Animate dinosaur jumping with scale effect
tween(dinoGraphics, {
scaleY: 1.2,
scaleX: 0.9,
rotation: -0.1
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(dinoGraphics, {
scaleY: 1,
scaleX: 1,
rotation: 0
}, {
duration: 300,
easing: tween.easeIn
});
}
});
}
};
self.update = function () {
// Track last ground state
self.lastOnGround = self.onGround;
// Apply gravity
if (!self.onGround) {
self.velocityY += self.gravity;
}
// Apply velocity
self.y += self.velocityY;
// Ground collision
if (self.y >= GROUND_Y) {
self.y = GROUND_Y;
self.velocityY = 0;
self.onGround = true;
self.isJumping = false;
}
// Landing animation trigger
if (!self.lastOnGround && self.onGround) {
// Just landed
tween(dinoGraphics, {
scaleX: 1.1,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(dinoGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeIn
});
}
});
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xf5f5dc
});
/****
* Game Code
****/
var GROUND_Y = 2200; // Ground level
var gameSpeed = 8; // Game speed
var spawnTimer = 0;
var gameScore = 0;
var isGameRunning = true;
var dinosaur;
var bananas = [];
var clouds = [];
var ground;
var speedIncrease = 0;
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: GROUND_Y
}));
// Initialize dinosaur
dinosaur = new Dinosaur();
game.addChild(dinosaur);
// Create background clouds
for (var i = 0; i < 6; i++) {
var cloud = new Cloud(Math.random() * 2048 + 200, Math.random() * 400 + 200);
game.addChild(cloud);
clouds.push(cloud);
}
// Score display
var scoreText = new Text2('Score: 0', {
size: 48,
fill: 0x666666
});
scoreText.anchor.set(0, 0);
scoreText.x = 50;
scoreText.y = 50;
LK.gui.topLeft.addChild(scoreText);
// High score display
var highScore = storage.get('highScore') || 0;
var highScoreText = new Text2('High: ' + highScore, {
size: 36,
fill: 0x999999
});
highScoreText.anchor.set(0, 0);
highScoreText.x = 50;
highScoreText.y = 110;
LK.gui.topLeft.addChild(highScoreText);
function spawnBanana() {
// Random height for bananas (flying obstacles)
var bananaHeight = GROUND_Y - Math.random() * 200 - 100; // Between 100-300 pixels above ground
var banana = new Banana(2048 + 50, bananaHeight);
game.addChild(banana);
bananas.push(banana);
}
function checkCollisions() {
for (var i = 0; i < bananas.length; i++) {
var banana = bananas[i];
if (dinosaur.intersects(banana)) {
// Game over
LK.getSound('hit').play();
LK.effects.flashScreen(0xFF0000, 500);
isGameRunning = false;
// Save high score
if (gameScore > highScore) {
storage.set('highScore', gameScore);
}
LK.showGameOver();
return;
}
}
}
function updateScore() {
if (isGameRunning) {
gameScore += 1;
scoreText.setText('Score: ' + gameScore);
// Increase game speed gradually
if (gameScore > 0 && gameScore % 100 === 0) {
speedIncrease += 0.5;
gameSpeed = 8 + speedIncrease;
// Update all banana speeds
for (var i = 0; i < bananas.length; i++) {
bananas[i].speed = gameSpeed;
}
}
}
}
// Touch/tap to jump
game.down = function (x, y, obj) {
if (isGameRunning) {
dinosaur.jump();
}
};
game.update = function () {
if (!isGameRunning) return;
// Update score
updateScore();
// Spawn bananas
spawnTimer++;
var spawnRate = Math.max(80 - Math.floor(gameScore / 100) * 5, 40); // Spawn rate increases with score
if (spawnTimer >= spawnRate) {
spawnBanana();
spawnTimer = 0;
}
// Update clouds
for (var i = 0; i < clouds.length; i++) {
clouds[i].speed = (gameSpeed + speedIncrease) * 0.3;
}
// Check collisions
checkCollisions();
// Clean up off-screen bananas
for (var i = bananas.length - 1; i >= 0; i--) {
if (bananas[i].x < -100) {
bananas[i].destroy();
bananas.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -6,766 +6,262 @@
/****
* Classes
****/
-var Block = Container.expand(function (blockType, x, y) {
+var Banana = Container.expand(function (x, y) {
var self = Container.call(this);
- self.blockType = blockType;
- self.gridX = x;
- self.gridY = y;
- self.miningProgress = 0;
- self.getMiningTime = function (type) {
- switch (type) {
- case 'grass':
- return 30;
- case 'dirt':
- return 30;
- case 'wood':
- return 60;
- case 'stone':
- return 90;
- case 'coal':
- return 120;
- case 'iron':
- return 150;
- default:
- return 60;
- }
- };
- self.maxMiningTime = self.getMiningTime(blockType);
- var blockGraphics = self.attachAsset(blockType, {
- anchorX: 0,
- anchorY: 0
+ var bananaGraphics = self.attachAsset('banana', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- self.x = x * BLOCK_SIZE;
- self.y = y * BLOCK_SIZE;
- self.startMining = function () {
- self.miningProgress = 0;
- blockGraphics.alpha = 1;
- };
- self.updateMining = function () {
- self.miningProgress++;
- blockGraphics.alpha = 1 - self.miningProgress / self.maxMiningTime * 0.5;
- if (self.miningProgress >= self.maxMiningTime) {
- self.finishMining();
- return true;
+ self.x = x;
+ self.y = y;
+ self.speed = gameSpeed;
+ self.lastX = self.x;
+ // Add slight rotation animation to bananas
+ tween(bananaGraphics, {
+ rotation: Math.PI * 2
+ }, {
+ duration: 2000,
+ easing: tween.linear
+ });
+ self.update = function () {
+ self.lastX = self.x;
+ self.x -= self.speed;
+ // Remove banana when it goes off screen
+ if (self.x < -50) {
+ self.destroy();
+ for (var i = 0; i < bananas.length; i++) {
+ if (bananas[i] === self) {
+ bananas.splice(i, 1);
+ break;
+ }
+ }
}
- return false;
};
- self.finishMining = function () {
- inventory.addItem(self.blockType, 1);
- LK.getSound('mine').play();
- self.destroy();
- worldBlocks[self.gridX + '_' + self.gridY] = null;
- };
return self;
});
-var Inventory = Container.expand(function () {
+var Cloud = Container.expand(function (x, y) {
var self = Container.call(this);
- self.items = {};
- self.selectedSlot = 0;
- self.maxSlots = 8;
- self.slots = [];
- self.slotGraphics = [];
- for (var i = 0; i < self.maxSlots; i++) {
- var slot = self.attachAsset('inventorySlot', {
- anchorX: 0,
- anchorY: 0,
- x: i * 90 + 200,
- y: 50
- });
- var slotText = new Text2('', {
- size: 24,
- fill: 0xFFFFFF
- });
- slotText.anchor.set(0.5, 0.5);
- slotText.x = i * 90 + 240;
- slotText.y = 90;
- self.slots.push({
- type: null,
- count: 0,
- text: slotText
- });
- self.slotGraphics.push(slot);
- self.addChild(slotText);
- }
- var selectedGraphics = self.attachAsset('selectedSlot', {
- anchorX: 0,
- anchorY: 0,
- x: 200,
- y: 50
+ var cloudGraphics = self.attachAsset('cloud', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- self.addItem = function (type, count) {
- for (var i = 0; i < self.maxSlots; i++) {
- if (self.slots[i].type === type) {
- self.slots[i].count += count;
- self.updateSlotDisplay(i);
- return true;
- }
+ self.x = x;
+ self.y = y;
+ self.speed = gameSpeed * 0.3; // Clouds move slower than obstacles
+ cloudGraphics.alpha = 0.7;
+ self.update = function () {
+ self.x -= self.speed;
+ // Remove cloud when it goes off screen and recycle
+ if (self.x < -100) {
+ self.x = 2148; // Reset to right side of screen
}
- for (var i = 0; i < self.maxSlots; i++) {
- if (self.slots[i].type === null) {
- self.slots[i].type = type;
- self.slots[i].count = count;
- self.updateSlotDisplay(i);
- return true;
- }
- }
- return false;
};
- self.removeItem = function (type, count) {
- for (var i = 0; i < self.maxSlots; i++) {
- if (self.slots[i].type === type && self.slots[i].count >= count) {
- self.slots[i].count -= count;
- if (self.slots[i].count <= 0) {
- self.slots[i].type = null;
- self.slots[i].count = 0;
- }
- self.updateSlotDisplay(i);
- return true;
- }
- }
- return false;
- };
- self.updateSlotDisplay = function (index) {
- var slot = self.slots[index];
- if (slot.type) {
- slot.text.setText(slot.count.toString());
- } else {
- slot.text.setText('');
- }
- };
- self.selectSlot = function (index) {
- if (index >= 0 && index < self.maxSlots) {
- self.selectedSlot = index;
- selectedGraphics.x = index * 90 + 200;
- }
- };
- self.getSelectedItem = function () {
- return self.slots[self.selectedSlot];
- };
return self;
});
-var Player = Container.expand(function () {
+var Dinosaur = Container.expand(function () {
var self = Container.call(this);
- var playerGraphics = self.attachAsset('player', {
+ var dinoGraphics = self.attachAsset('dinosaur', {
anchorX: 0.5,
anchorY: 1
});
- self.health = 100;
- self.hunger = 100;
- self.gridX = Math.floor(WORLD_WIDTH / 2);
- self.gridY = 10;
- self.x = self.gridX * BLOCK_SIZE + BLOCK_SIZE / 2;
- self.y = (self.gridY + 1) * BLOCK_SIZE;
- self.velocityX = 0;
+ self.x = 300;
+ self.y = GROUND_Y;
self.velocityY = 0;
- self.onGround = false;
- self.moveSpeed = 3;
- self.jumpPower = -12;
- self.gravity = 0.5;
- self.moveLeft = function () {
- self.velocityX = -self.moveSpeed;
- // Animate player slightly tilting left and scaling
- tween(playerGraphics, {
- rotation: -0.1,
- scaleX: 0.9
- }, {
- duration: 200,
- easing: tween.easeOut
- });
- };
- self.moveRight = function () {
- self.velocityX = self.moveSpeed;
- // Animate player slightly tilting right and scaling
- tween(playerGraphics, {
- rotation: 0.1,
- scaleX: 0.9
- }, {
- duration: 200,
- easing: tween.easeOut
- });
- };
+ self.onGround = true;
+ self.jumpPower = -18;
+ self.gravity = 1.2;
+ self.isJumping = false;
+ self.lastOnGround = true;
self.jump = function () {
if (self.onGround) {
self.velocityY = self.jumpPower;
self.onGround = false;
- // Animate player jumping with scale effect
- tween(playerGraphics, {
+ self.isJumping = true;
+ LK.getSound('jump').play();
+ // Animate dinosaur jumping with scale effect
+ tween(dinoGraphics, {
scaleY: 1.2,
- scaleX: 0.8
+ scaleX: 0.9,
+ rotation: -0.1
}, {
- duration: 150,
+ duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
- tween(playerGraphics, {
+ tween(dinoGraphics, {
scaleY: 1,
- scaleX: 1
+ scaleX: 1,
+ rotation: 0
}, {
- duration: 150,
+ duration: 300,
easing: tween.easeIn
});
}
});
}
};
- self.stopMoving = function () {
- self.velocityX = 0;
- // Reset player rotation and scale when stopping
- tween(playerGraphics, {
- rotation: 0,
- scaleX: 1
- }, {
- duration: 300,
- easing: tween.easeOut
- });
- };
- self.attack = function () {
- // Attack animation - quick punch forward
- tween(playerGraphics, {
- scaleX: 1.3,
- x: playerGraphics.x + 10
- }, {
- duration: 100,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- tween(playerGraphics, {
- scaleX: 1,
- x: playerGraphics.x - 10
- }, {
- duration: 100,
- easing: tween.easeIn
- });
- }
- });
- };
- self.destroyBlock = function () {
- // Destroy animation - mining swing motion
- tween(playerGraphics, {
- rotation: -0.3,
- scaleY: 0.9
- }, {
- duration: 150,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- tween(playerGraphics, {
- rotation: 0.2,
- scaleY: 1.1
- }, {
- duration: 100,
- easing: tween.easeInOut,
- onFinish: function onFinish() {
- tween(playerGraphics, {
- rotation: 0,
- scaleY: 1
- }, {
- duration: 100,
- easing: tween.easeIn
- });
- }
- });
- }
- });
- };
- self.takeDamage = function (damage) {
- self.health = Math.max(0, self.health - damage);
- LK.getSound('hurt').play();
- LK.effects.flashObject(self, 0xFF0000, 500);
- if (self.health <= 0) {
- LK.showGameOver();
- }
- };
self.update = function () {
+ // Track last ground state
+ self.lastOnGround = self.onGround;
// Apply gravity
- self.velocityY += self.gravity;
+ if (!self.onGround) {
+ self.velocityY += self.gravity;
+ }
// Apply velocity
- self.x += self.velocityX;
self.y += self.velocityY;
- // Check collision with world boundaries
- if (self.x < BLOCK_SIZE / 2) {
- self.x = BLOCK_SIZE / 2;
- self.velocityX = 0;
- }
- if (self.x > (WORLD_WIDTH - 1) * BLOCK_SIZE + BLOCK_SIZE / 2) {
- self.x = (WORLD_WIDTH - 1) * BLOCK_SIZE + BLOCK_SIZE / 2;
- self.velocityX = 0;
- }
- // Check collision with ground and blocks
- var playerBottom = self.y;
- var playerGridX = Math.floor(self.x / BLOCK_SIZE);
- var playerGridY = Math.floor(playerBottom / BLOCK_SIZE);
// Ground collision
- self.onGround = false;
- if (playerGridY >= 0 && playerGridY < WORLD_HEIGHT) {
- var blockBelow = worldBlocks[playerGridX + '_' + playerGridY];
- if (blockBelow && self.velocityY >= 0) {
- var blockTop = playerGridY * BLOCK_SIZE;
- if (playerBottom >= blockTop && playerBottom <= blockTop + BLOCK_SIZE) {
- self.y = blockTop;
- self.velocityY = 0;
- self.onGround = true;
- }
- }
+ if (self.y >= GROUND_Y) {
+ self.y = GROUND_Y;
+ self.velocityY = 0;
+ self.onGround = true;
+ self.isJumping = false;
}
- // Ceiling collision
- if (self.velocityY < 0) {
- var playerTop = self.y - 64;
- var topGridY = Math.floor(playerTop / BLOCK_SIZE);
- if (topGridY >= 0) {
- var blockAbove = worldBlocks[playerGridX + '_' + topGridY];
- if (blockAbove) {
- self.velocityY = 0;
+ // Landing animation trigger
+ if (!self.lastOnGround && self.onGround) {
+ // Just landed
+ tween(dinoGraphics, {
+ scaleX: 1.1,
+ scaleY: 0.9
+ }, {
+ duration: 100,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(dinoGraphics, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100,
+ easing: tween.easeIn
+ });
}
- }
+ });
}
- // Apply friction when on ground
- if (self.onGround) {
- self.velocityX *= 0.8;
- }
- // Update grid position for other systems
- self.gridX = Math.floor(self.x / BLOCK_SIZE);
- self.gridY = Math.floor((self.y - BLOCK_SIZE / 2) / BLOCK_SIZE);
- self.hunger = Math.max(0, self.hunger - 0.1);
- if (self.hunger <= 0 && LK.ticks % 180 == 0) {
- self.takeDamage(5);
- }
};
return self;
});
-var Zombie = Container.expand(function (x, y) {
- var self = Container.call(this);
- var zombieGraphics = self.attachAsset('zombie', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.gridX = x;
- self.gridY = y;
- self.health = 50;
- self.speed = 1;
- self.attackCooldown = 0;
- self.x = x * BLOCK_SIZE + BLOCK_SIZE / 2;
- self.y = (y + 1) * BLOCK_SIZE;
- self.update = function () {
- if (self.attackCooldown > 0) {
- self.attackCooldown--;
- }
- var distToPlayer = Math.abs(self.x - player.x) + Math.abs(self.y - player.y);
- if (distToPlayer < 100) {
- var dx = player.x - self.x;
- var dy = player.y - self.y;
- var length = Math.sqrt(dx * dx + dy * dy);
- if (length > 0) {
- self.x += dx / length * self.speed;
- self.y += dy / length * self.speed;
- }
- if (distToPlayer < 60 && self.attackCooldown <= 0) {
- player.takeDamage(10);
- self.attackCooldown = 120;
- }
- }
- };
- return self;
-});
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB
+ backgroundColor: 0xf5f5dc
});
/****
* Game Code
****/
-var BLOCK_SIZE = 64;
-var WORLD_WIDTH = 32;
-var WORLD_HEIGHT = 50;
-var DAY_LENGTH = 3600; // 60 seconds
-var NIGHT_LENGTH = 1800; // 30 seconds
-var worldBlocks = {};
-var player;
-var inventory;
-var zombies = [];
-var currentTime = 0;
-var isNight = false;
-var miningBlock = null;
-var cameraX = 0;
-var cameraY = 0;
-var leftPressed = false;
-var rightPressed = false;
-var destroyMode = false;
-// Generate world
-function generateWorld() {
- // Generate grass layer
- for (var x = 0; x < WORLD_WIDTH; x++) {
- var grassHeight = 15 + Math.floor(Math.sin(x * 0.3) * 3);
- for (var y = grassHeight; y < WORLD_HEIGHT; y++) {
- var blockType;
- if (y === grassHeight) {
- blockType = 'grass';
- } else if (y < grassHeight + 5) {
- blockType = 'dirt';
- } else {
- var rand = Math.random();
- if (rand < 0.7) {
- blockType = 'stone';
- } else if (rand < 0.85) {
- blockType = 'coal';
- } else if (rand < 0.95) {
- blockType = 'iron';
- } else {
- blockType = 'wood';
- }
+var GROUND_Y = 2200; // Ground level
+var gameSpeed = 8; // Game speed
+var spawnTimer = 0;
+var gameScore = 0;
+var isGameRunning = true;
+var dinosaur;
+var bananas = [];
+var clouds = [];
+var ground;
+var speedIncrease = 0;
+// Create ground
+ground = game.addChild(LK.getAsset('ground', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: GROUND_Y
+}));
+// Initialize dinosaur
+dinosaur = new Dinosaur();
+game.addChild(dinosaur);
+// Create background clouds
+for (var i = 0; i < 6; i++) {
+ var cloud = new Cloud(Math.random() * 2048 + 200, Math.random() * 400 + 200);
+ game.addChild(cloud);
+ clouds.push(cloud);
+}
+// Score display
+var scoreText = new Text2('Score: 0', {
+ size: 48,
+ fill: 0x666666
+});
+scoreText.anchor.set(0, 0);
+scoreText.x = 50;
+scoreText.y = 50;
+LK.gui.topLeft.addChild(scoreText);
+// High score display
+var highScore = storage.get('highScore') || 0;
+var highScoreText = new Text2('High: ' + highScore, {
+ size: 36,
+ fill: 0x999999
+});
+highScoreText.anchor.set(0, 0);
+highScoreText.x = 50;
+highScoreText.y = 110;
+LK.gui.topLeft.addChild(highScoreText);
+function spawnBanana() {
+ // Random height for bananas (flying obstacles)
+ var bananaHeight = GROUND_Y - Math.random() * 200 - 100; // Between 100-300 pixels above ground
+ var banana = new Banana(2048 + 50, bananaHeight);
+ game.addChild(banana);
+ bananas.push(banana);
+}
+function checkCollisions() {
+ for (var i = 0; i < bananas.length; i++) {
+ var banana = bananas[i];
+ if (dinosaur.intersects(banana)) {
+ // Game over
+ LK.getSound('hit').play();
+ LK.effects.flashScreen(0xFF0000, 500);
+ isGameRunning = false;
+ // Save high score
+ if (gameScore > highScore) {
+ storage.set('highScore', gameScore);
}
- var block = new Block(blockType, x, y);
- game.addChild(block);
- worldBlocks[x + '_' + y] = block;
+ LK.showGameOver();
+ return;
}
}
}
-function updateCamera() {
- cameraX = player.x - 1024;
- cameraY = player.y - 1366;
- cameraX = Math.max(0, Math.min(cameraX, WORLD_WIDTH * BLOCK_SIZE - 2048));
- cameraY = Math.max(0, Math.min(cameraY, WORLD_HEIGHT * BLOCK_SIZE - 2732));
- game.x = -cameraX;
- game.y = -cameraY;
-}
-function updateDayNight() {
- currentTime++;
- var totalCycle = DAY_LENGTH + NIGHT_LENGTH;
- var cyclePosition = currentTime % totalCycle;
- var wasNight = isNight;
- isNight = cyclePosition > DAY_LENGTH;
- if (isNight && !wasNight) {
- // Night just started
- spawnZombies();
- } else if (!isNight && wasNight) {
- // Day just started
- removeAllZombies();
- }
- var skyColor;
- if (isNight) {
- skyColor = 0x1A1A2E;
- } else {
- skyColor = 0x87CEEB;
- }
- game.setBackgroundColor(skyColor);
-}
-function spawnZombies() {
- for (var i = 0; i < 3; i++) {
- var spawnX = Math.floor(Math.random() * WORLD_WIDTH);
- var spawnY = 10;
- // Find surface
- for (var y = 0; y < WORLD_HEIGHT; y++) {
- if (worldBlocks[spawnX + '_' + y]) {
- spawnY = y - 1;
- break;
+function updateScore() {
+ if (isGameRunning) {
+ gameScore += 1;
+ scoreText.setText('Score: ' + gameScore);
+ // Increase game speed gradually
+ if (gameScore > 0 && gameScore % 100 === 0) {
+ speedIncrease += 0.5;
+ gameSpeed = 8 + speedIncrease;
+ // Update all banana speeds
+ for (var i = 0; i < bananas.length; i++) {
+ bananas[i].speed = gameSpeed;
}
}
- var zombie = new Zombie(spawnX, spawnY);
- game.addChild(zombie);
- zombies.push(zombie);
}
}
-function removeAllZombies() {
- for (var i = zombies.length - 1; i >= 0; i--) {
- zombies[i].destroy();
- zombies.splice(i, 1);
- }
-}
-function getBlockAt(x, y) {
- var gridX = Math.floor(x / BLOCK_SIZE);
- var gridY = Math.floor(y / BLOCK_SIZE);
- return worldBlocks[gridX + '_' + gridY];
-}
-function placeBlock(x, y) {
- var gridX = Math.floor(x / BLOCK_SIZE);
- var gridY = Math.floor(y / BLOCK_SIZE);
- var key = gridX + '_' + gridY;
- if (worldBlocks[key]) return false;
- var selectedItem = inventory.getSelectedItem();
- if (!selectedItem.type || selectedItem.count <= 0) return false;
- // Check if block type can be placed
- var placeableBlocks = ['dirt', 'stone', 'wood'];
- if (placeableBlocks.indexOf(selectedItem.type) === -1) return false;
- var block = new Block(selectedItem.type, gridX, gridY);
- game.addChild(block);
- worldBlocks[key] = block;
- inventory.removeItem(selectedItem.type, 1);
- LK.getSound('place').play();
- return true;
-}
-// Initialize game
-generateWorld();
-player = new Player();
-game.addChild(player);
-inventory = new Inventory();
-LK.gui.bottom.addChild(inventory);
-// Add some starting items
-inventory.addItem('wood', 10);
-inventory.addItem('stone', 5);
-// Health display
-var healthText = new Text2('Health: 100', {
- size: 36,
- fill: 0xFFFFFF
-});
-healthText.anchor.set(0, 0);
-LK.gui.topRight.addChild(healthText);
-// Hunger display
-var hungerText = new Text2('Hunger: 100', {
- size: 36,
- fill: 0xFFFFFF
-});
-hungerText.anchor.set(0, 0);
-hungerText.y = 50;
-LK.gui.topRight.addChild(hungerText);
-// Time display
-var timeText = new Text2('Day', {
- size: 40,
- fill: 0xFFFFFF
-});
-timeText.anchor.set(0.5, 0);
-LK.gui.top.addChild(timeText);
-// Movement buttons
-var leftButton = LK.getAsset('moveButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 150,
- y: -200
-});
-var leftButtonText = new Text2('←', {
- size: 60,
- fill: 0xFFFFFF
-});
-leftButtonText.anchor.set(0.5, 0.5);
-leftButtonText.x = 150;
-leftButtonText.y = -200;
-var rightButton = LK.getAsset('moveButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 300,
- y: -200
-});
-var rightButtonText = new Text2('→', {
- size: 60,
- fill: 0xFFFFFF
-});
-rightButtonText.anchor.set(0.5, 0.5);
-rightButtonText.x = 300;
-rightButtonText.y = -200;
-var upButton = LK.getAsset('moveButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 225,
- y: -300
-});
-var upButtonText = new Text2('↑', {
- size: 60,
- fill: 0xFFFFFF
-});
-upButtonText.anchor.set(0.5, 0.5);
-upButtonText.x = 225;
-upButtonText.y = -300;
-var downButton = LK.getAsset('moveButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 225,
- y: -100
-});
-var downButtonText = new Text2('↓', {
- size: 60,
- fill: 0xFFFFFF
-});
-downButtonText.anchor.set(0.5, 0.5);
-downButtonText.x = 225;
-downButtonText.y = -100;
-// Attack button
-var attackButton = LK.getAsset('attackButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 450,
- y: -200
-});
-var attackButtonText = new Text2('⚔', {
- size: 60,
- fill: 0xFFFFFF
-});
-attackButtonText.anchor.set(0.5, 0.5);
-attackButtonText.x = 450;
-attackButtonText.y = -200;
-// Destroy button
-var destroyButton = LK.getAsset('destroyButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 600,
- y: -200
-});
-var destroyButtonText = new Text2('⛏', {
- size: 60,
- fill: 0xFFFFFF
-});
-destroyButtonText.anchor.set(0.5, 0.5);
-destroyButtonText.x = 600;
-destroyButtonText.y = -200;
-LK.gui.bottomLeft.addChild(leftButton);
-LK.gui.bottomLeft.addChild(leftButtonText);
-LK.gui.bottomLeft.addChild(rightButton);
-LK.gui.bottomLeft.addChild(rightButtonText);
-LK.gui.bottomLeft.addChild(upButton);
-LK.gui.bottomLeft.addChild(upButtonText);
-LK.gui.bottomLeft.addChild(downButton);
-LK.gui.bottomLeft.addChild(downButtonText);
-LK.gui.bottomLeft.addChild(attackButton);
-LK.gui.bottomLeft.addChild(attackButtonText);
-LK.gui.bottomLeft.addChild(destroyButton);
-LK.gui.bottomLeft.addChild(destroyButtonText);
+// Touch/tap to jump
game.down = function (x, y, obj) {
- // Convert screen coordinates to world coordinates
- var worldX = x + cameraX;
- var worldY = y + cameraY;
- var block = getBlockAt(worldX, worldY);
- if (block) {
- if (destroyMode) {
- // Instantly destroy the selected block with animation
- tween(block, {
- scaleX: 0,
- scaleY: 0,
- rotation: Math.PI,
- alpha: 0
- }, {
- duration: 300,
- easing: tween.easeIn,
- onFinish: function onFinish() {
- block.finishMining();
- }
- });
- destroyMode = false;
- // Reset destroy button visual state
- tween(destroyButton, {
- tint: 0xFFFFFF,
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 200,
- easing: tween.easeOut
- });
- } else {
- miningBlock = block;
- miningBlock.startMining();
- }
- } else {
- if (!destroyMode) {
- placeBlock(worldX, worldY);
- }
+ if (isGameRunning) {
+ dinosaur.jump();
}
};
-game.up = function (x, y, obj) {
- if (miningBlock) {
- miningBlock = null;
+game.update = function () {
+ if (!isGameRunning) return;
+ // Update score
+ updateScore();
+ // Spawn bananas
+ spawnTimer++;
+ var spawnRate = Math.max(80 - Math.floor(gameScore / 100) * 5, 40); // Spawn rate increases with score
+ if (spawnTimer >= spawnRate) {
+ spawnBanana();
+ spawnTimer = 0;
}
-};
-// Inventory slot selection
-LK.gui.bottom.down = function (x, y, obj) {
- if (y >= 50 && y <= 130) {
- var slotIndex = Math.floor((x - 200) / 90);
- if (slotIndex >= 0 && slotIndex < inventory.maxSlots) {
- inventory.selectSlot(slotIndex);
- }
+ // Update clouds
+ for (var i = 0; i < clouds.length; i++) {
+ clouds[i].speed = (gameSpeed + speedIncrease) * 0.3;
}
-};
-// Movement button handlers
-LK.gui.bottomLeft.down = function (x, y, obj) {
- // Left button
- if (x >= 90 && x <= 210 && y >= -260 && y <= -140) {
- leftPressed = true;
- player.moveLeft();
- }
- // Right button
- else if (x >= 240 && x <= 360 && y >= -260 && y <= -140) {
- rightPressed = true;
- player.moveRight();
- }
- // Up button (Jump)
- else if (x >= 165 && x <= 285 && y >= -360 && y <= -240) {
- player.jump();
- }
- // Attack button
- else if (x >= 390 && x <= 510 && y >= -260 && y <= -140) {
- player.attack();
- // Attack nearby zombies
- for (var i = 0; i < zombies.length; i++) {
- var zombie = zombies[i];
- var dist = Math.abs(player.x - zombie.x) + Math.abs(player.y - zombie.y);
- if (dist < 80) {
- zombie.health -= 25;
- LK.effects.flashObject(zombie, 0xFF0000, 300);
- }
+ // Check collisions
+ checkCollisions();
+ // Clean up off-screen bananas
+ for (var i = bananas.length - 1; i >= 0; i--) {
+ if (bananas[i].x < -100) {
+ bananas[i].destroy();
+ bananas.splice(i, 1);
}
}
- // Destroy button
- else if (x >= 540 && x <= 660 && y >= -260 && y <= -140) {
- player.destroyBlock();
- destroyMode = !destroyMode;
- // Visual feedback for destroy mode
- if (destroyMode) {
- tween(destroyButton, {
- tint: 0xFFFF00,
- scaleX: 1.1,
- scaleY: 1.1
- }, {
- duration: 200,
- easing: tween.easeOut
- });
- } else {
- tween(destroyButton, {
- tint: 0xFFFFFF,
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 200,
- easing: tween.easeOut
- });
- }
- }
-};
-// Movement button release handlers
-LK.gui.bottomLeft.up = function (x, y, obj) {
- // Left button
- if (x >= 90 && x <= 210 && y >= -260 && y <= -140) {
- leftPressed = false;
- if (!rightPressed) player.stopMoving();
- }
- // Right button
- else if (x >= 240 && x <= 360 && y >= -260 && y <= -140) {
- rightPressed = false;
- if (!leftPressed) player.stopMoving();
- }
-};
-game.update = function () {
- // Update day/night cycle
- updateDayNight();
- // Update camera
- updateCamera();
- // Update mining
- if (miningBlock) {
- if (miningBlock.updateMining()) {
- miningBlock = null;
- }
- }
- // Update zombies
- for (var i = zombies.length - 1; i >= 0; i--) {
- var zombie = zombies[i];
- if (zombie.health <= 0) {
- zombie.destroy();
- zombies.splice(i, 1);
- }
- }
- // Update UI
- healthText.setText('Health: ' + Math.floor(player.health));
- hungerText.setText('Hunger: ' + Math.floor(player.hunger));
- timeText.setText(isNight ? 'Night' : 'Day');
- // Win condition - survive for 5 day/night cycles
- if (currentTime > (DAY_LENGTH + NIGHT_LENGTH) * 5) {
- LK.showYouWin();
- }
};
\ No newline at end of file