User prompt
pon un paisaje de fondo
User prompt
ponle musical relajante
User prompt
pon una forma de mover el jugador
Code edit (1 edits merged)
Please save this source code
User prompt
Block Dodger
Initial prompt
import pygame import random import sys # Inicializar Pygame pygame.init() # Configuración de pantalla ANCHO, ALTO = 500, 500 pantalla = pygame.display.set_mode((ANCHO, ALTO)) pygame.display.set_caption("Esquiva los bloques") # Colores NEGRO = (0, 0, 0) AZUL = (50, 100, 255) ROJO = (255, 50, 50) # Jugador jugador = pygame.Rect(200, 450, 50, 50) # x, y, ancho, alto velocidad_jugador = 7 # Obstáculos obstaculos = [] velocidad_obstaculo = 5 # Reloj reloj = pygame.time.Clock() # Bucle principal while True: # Eventos for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() # Movimiento del jugador teclas = pygame.key.get_pressed() if teclas[pygame.K_LEFT] and jugador.left > 0: jugador.x -= velocidad_jugador if teclas[pygame.K_RIGHT] and jugador.right < ANCHO: jugador.x += velocidad_jugador # Crear obstáculos if random.randint(1, 20) == 1: # probabilidad de crear bloque obstaculos.append(pygame.Rect(random.randint(0, ANCHO-50), 0, 50, 50)) # Mover obstáculos for obstaculo in obstaculos: obstaculo.y += velocidad_obstaculo if obstaculo.colliderect(jugador): # Colisión print("¡Perdiste!") pygame.quit() sys.exit() # Dibujar pantalla.fill(NEGRO) pygame.draw.rect(pantalla, AZUL, jugador) for obstaculo in obstaculos: pygame.draw.rect(pantalla, ROJO, obstaculo) pygame.display.flip() reloj.tick(30) # 30 FPS
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Block = Container.expand(function () { var self = Container.call(this); var blockGraphics = self.attachAsset('block', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.lastY = 0; self.update = function () { self.y += self.speed; }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 }); /**** * Game Code ****/ var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 150; var blocks = []; var blockSpawnTimer = 0; var blockSpawnDelay = 60; var gameSpeed = 1; var survivalTime = 0; var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var dragNode = null; function handleMove(x, y, obj) { if (dragNode) { dragNode.x = Math.max(40, Math.min(2048 - 40, x)); } } game.move = handleMove; game.down = function (x, y, obj) { dragNode = player; handleMove(x, y, obj); }; game.up = function (x, y, obj) { dragNode = null; }; game.update = function () { survivalTime++; // Update score based on survival time var currentScore = Math.floor(survivalTime / 10); LK.setScore(currentScore); scoreTxt.setText(LK.getScore()); // Increase difficulty over time if (survivalTime % 300 === 0) { gameSpeed += 0.2; blockSpawnDelay = Math.max(20, blockSpawnDelay - 3); } // Spawn blocks blockSpawnTimer++; if (blockSpawnTimer >= blockSpawnDelay) { blockSpawnTimer = 0; var newBlock = new Block(); newBlock.x = Math.random() * (2048 - 120) + 60; newBlock.y = -50; newBlock.speed = 8 * gameSpeed; newBlock.lastY = newBlock.y; blocks.push(newBlock); game.addChild(newBlock); } // Update and check blocks for (var i = blocks.length - 1; i >= 0; i--) { var block = blocks[i]; // Check if block went off screen if (block.lastY <= 2732 + 50 && block.y > 2732 + 50) { block.destroy(); blocks.splice(i, 1); continue; } // Check collision with player if (block.intersects(player)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } block.lastY = block.y; } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,109 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Block = Container.expand(function () {
+ var self = Container.call(this);
+ var blockGraphics = self.attachAsset('block', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 8;
+ self.lastY = 0;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x222222
+});
+
+/****
+* Game Code
+****/
+var player = game.addChild(new Player());
+player.x = 2048 / 2;
+player.y = 2732 - 150;
+var blocks = [];
+var blockSpawnTimer = 0;
+var blockSpawnDelay = 60;
+var gameSpeed = 1;
+var survivalTime = 0;
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var dragNode = null;
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ dragNode.x = Math.max(40, Math.min(2048 - 40, x));
+ }
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ dragNode = player;
+ handleMove(x, y, obj);
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+game.update = function () {
+ survivalTime++;
+ // Update score based on survival time
+ var currentScore = Math.floor(survivalTime / 10);
+ LK.setScore(currentScore);
+ scoreTxt.setText(LK.getScore());
+ // Increase difficulty over time
+ if (survivalTime % 300 === 0) {
+ gameSpeed += 0.2;
+ blockSpawnDelay = Math.max(20, blockSpawnDelay - 3);
+ }
+ // Spawn blocks
+ blockSpawnTimer++;
+ if (blockSpawnTimer >= blockSpawnDelay) {
+ blockSpawnTimer = 0;
+ var newBlock = new Block();
+ newBlock.x = Math.random() * (2048 - 120) + 60;
+ newBlock.y = -50;
+ newBlock.speed = 8 * gameSpeed;
+ newBlock.lastY = newBlock.y;
+ blocks.push(newBlock);
+ game.addChild(newBlock);
+ }
+ // Update and check blocks
+ for (var i = blocks.length - 1; i >= 0; i--) {
+ var block = blocks[i];
+ // Check if block went off screen
+ if (block.lastY <= 2732 + 50 && block.y > 2732 + 50) {
+ block.destroy();
+ blocks.splice(i, 1);
+ continue;
+ }
+ // Check collision with player
+ if (block.intersects(player)) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ block.lastY = block.y;
+ }
+};
\ No newline at end of file