User prompt
import pygame import random # Initialize Pygame pygame.init() # Screen dimensions (1D - just width) width = 800 height = 600 # Even though it's 1D, we need a height for the window screen = pygame.display.set_mode((width, height)) pygame.display.set_caption("1D Shooter") # Colors white = (255, 255, 255) black = (0, 0, 0) red = (255, 0, 0) # Player player_width = 50 player_height = 20 player_x = width // 2 - player_width // 2 player_y = height - player_height - 10 # Bottom of the screen player_speed = 5 # Bullet bullet_width = 5 bullet_height = 10 bullet_speed = 10 bullets = # Store active bullets # Target target_width = 30 target_height = 20 target_x = random.randint(0, width - target_width) target_y = 50 target_speed = 2 # Game variables score = 0 font = pygame.font.Font(None, 36) game_over = False # Game loop running = True clock = pygame.time.Clock() while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: # Shoot bullet_x = player_x + player_width // 2 - bullet_width // 2 bullet_y = player_y - bullet_height bullets.append([bullet_x, bullet_y]) # Player movement keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and player_x > 0: player_x -= player_speed if keys[pygame.K_RIGHT] and player_x < width - player_width: player_x += player_speed # Bullet movement and collision for bullet in bullets[:]: # Iterate over a copy to safely remove items bullet -= bullet_speed if bullet < 0: bullets.remove(bullet) elif ( bullet < target_x + target_width and bullet + bullet_width > target_x and bullet < target_y + target_height and bullet + bullet_height > target_y ): bullets.remove(bullet) target_x = random.randint(0, width - target_width) score += 1 target_speed += 0.1 # Increase difficulty # Target movement (simple horizontal movement) target_x += target_speed if target_x > width - target_width or target_x < 0: target_speed *= -1 # Draw everything screen.fill(black) # Draw player pygame.draw.rect(screen, white, (player_x, player_y, player_width, player_height)) # Draw bullets for bullet in bullets: pygame.draw.rect(screen, red, (bullet, bullet, bullet_width, bullet_height)) # Draw target pygame.draw.rect(screen, white, (target_x, target_y, target_width, target_height)) # Draw score score_text = font.render("Score: " + str(score), 1, white) screen.blit(score_text, (10, 10)) # Update the display pygame.display.flip() # Control frame rate clock.tick(60) pygame.quit()
Initial prompt
Crusher shooting tycoon
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define a class for the main character
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Character update logic
};
});
// Define a class for obstacles
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Obstacle update logic
};
});
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.x += self.speed;
if (self.x > 2048 - 100 || self.x < 0) {
self.speed *= -1;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize game variables
var character = game.addChild(new Character());
character.x = 1024; // Center horizontally
character.y = 2600; // Near the bottom
var bullets = [];
var target = game.addChild(new Target());
target.x = Math.random() * 2048;
target.y = 200;
var score = 0;
// Function to handle character movement
function moveCharacter(x, y, obj) {
character.x = x;
character.y = y;
}
// Function to create obstacles
function createObstacle() {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048; // Random horizontal position
obstacle.y = 0; // Start at the top
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Game update function
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
bullet.update();
if (bullet.intersects(target)) {
bullet.destroy();
bullets.splice(i, 1);
target.x = Math.random() * 2048;
score++;
target.speed += 0.1; // Increase difficulty
}
}
// Fire bullet
if (LK.ticks % 30 == 0) {
var newBullet = new Bullet();
newBullet.x = character.x;
newBullet.y = character.y;
bullets.push(newBullet);
game.addChild(newBullet);
}
};
// Handle touch/mouse events
game.down = function (x, y, obj) {
moveCharacter(x, y, obj);
};
game.move = function (x, y, obj) {
moveCharacter(x, y, obj);
};
game.up = function (x, y, obj) {
// Stop character movement
};
// Display score
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Update score display
function updateScore() {
scoreTxt.setText("Score: " + score);
}
// Set interval to update score display
LK.setInterval(updateScore, 1000); ===================================================================
--- original.js
+++ change.js
@@ -1,104 +1,134 @@
-/****
+/****
* Classes
-****/
+****/
+var Bullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -10;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y < 0) {
+ self.destroy();
+ }
+ };
+});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define a class for the main character
var Character = Container.expand(function () {
- var self = Container.call(this);
- var characterGraphics = self.attachAsset('character', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Character update logic
- };
+ var self = Container.call(this);
+ var characterGraphics = self.attachAsset('character', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Character update logic
+ };
});
// Define a class for obstacles
var Obstacle = Container.expand(function () {
- var self = Container.call(this);
- var obstacleGraphics = self.attachAsset('obstacle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Obstacle update logic
- };
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Obstacle update logic
+ };
});
+var Target = Container.expand(function () {
+ var self = Container.call(this);
+ var targetGraphics = self.attachAsset('target', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2;
+ self.update = function () {
+ self.x += self.speed;
+ if (self.x > 2048 - 100 || self.x < 0) {
+ self.speed *= -1;
+ }
+ };
+});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize game variables
var character = game.addChild(new Character());
character.x = 1024; // Center horizontally
-character.y = 2400; // Near the bottom
-var obstacles = [];
+character.y = 2600; // Near the bottom
+var bullets = [];
+var target = game.addChild(new Target());
+target.x = Math.random() * 2048;
+target.y = 200;
var score = 0;
// Function to handle character movement
function moveCharacter(x, y, obj) {
- character.x = x;
- character.y = y;
+ character.x = x;
+ character.y = y;
}
// Function to create obstacles
function createObstacle() {
- var obstacle = new Obstacle();
- obstacle.x = Math.random() * 2048; // Random horizontal position
- obstacle.y = 0; // Start at the top
- obstacles.push(obstacle);
- game.addChild(obstacle);
+ var obstacle = new Obstacle();
+ obstacle.x = Math.random() * 2048; // Random horizontal position
+ obstacle.y = 0; // Start at the top
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
}
// Game update function
game.update = function () {
- // Update obstacles
- for (var i = obstacles.length - 1; i >= 0; i--) {
- var obstacle = obstacles[i];
- obstacle.y += 5; // Move downwards
- // Check for collision with character
- if (character.intersects(obstacle)) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- return;
- }
- // Remove off-screen obstacles
- if (obstacle.y > 2732) {
- obstacle.destroy();
- obstacles.splice(i, 1);
- score++;
- }
- }
- // Create new obstacles periodically
- if (LK.ticks % 60 == 0) {
- createObstacle();
- }
+ // Update bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var bullet = bullets[i];
+ bullet.update();
+ if (bullet.intersects(target)) {
+ bullet.destroy();
+ bullets.splice(i, 1);
+ target.x = Math.random() * 2048;
+ score++;
+ target.speed += 0.1; // Increase difficulty
+ }
+ }
+ // Fire bullet
+ if (LK.ticks % 30 == 0) {
+ var newBullet = new Bullet();
+ newBullet.x = character.x;
+ newBullet.y = character.y;
+ bullets.push(newBullet);
+ game.addChild(newBullet);
+ }
};
// Handle touch/mouse events
game.down = function (x, y, obj) {
- moveCharacter(x, y, obj);
+ moveCharacter(x, y, obj);
};
game.move = function (x, y, obj) {
- moveCharacter(x, y, obj);
+ moveCharacter(x, y, obj);
};
game.up = function (x, y, obj) {
- // Stop character movement
+ // Stop character movement
};
// Display score
var scoreTxt = new Text2('0', {
- size: 150,
- fill: 0xFFFFFF
+ size: 150,
+ fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Update score display
function updateScore() {
- scoreTxt.setText(score);
+ scoreTxt.setText("Score: " + score);
}
// Set interval to update score display
LK.setInterval(updateScore, 1000);
\ No newline at end of file