User prompt
Make a good and realistic graphic game but good
User prompt
Make a realistic bike driving game ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Create a game like a free city and our character a man can explore the full city and drive every vehicle and trains in the game
User prompt
Create a game like minecraft
Code edit (1 edits merged)
Please save this source code
User prompt
Bubble Pop Frenzy
Initial prompt
Make a game
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Block = Container.expand(function (type, gridX, gridY) {
var self = Container.call(this);
self.blockType = type || 'grass';
self.gridX = gridX;
self.gridY = gridY;
var assetName = 'grassBlock';
if (self.blockType === 'stone') {
assetName = 'stoneBlock';
} else if (self.blockType === 'wood') {
assetName = 'woodBlock';
} else if (self.blockType === 'dirt') {
assetName = 'dirtBlock';
}
var blockGraphics = self.attachAsset(assetName, {
anchorX: 0,
anchorY: 0
});
self.down = function (x, y, obj) {
if (miningMode) {
breakBlock(self);
} else {
// Show block info or interact
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1
});
self.speed = 5;
self.selectedBlock = 'grass';
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var world = [];
var worldWidth = 25;
var worldHeight = 20;
var blockSize = 80;
var cameraX = 0;
var cameraY = 0;
var miningMode = false;
var buildMode = true;
// Player
var player = new Player();
player.x = 1024;
player.y = 1000;
game.addChild(player);
// UI Elements
var modeText = new Text2('BUILD MODE', {
size: 60,
fill: 0xFFFFFF
});
modeText.anchor.set(0.5, 0);
LK.gui.top.addChild(modeText);
var inventoryUI = LK.getAsset('inventory', {
anchorX: 0.5,
anchorY: 1
});
LK.gui.bottom.addChild(inventoryUI);
var selectedBlockText = new Text2('GRASS BLOCK', {
size: 40,
fill: 0xFFFFFF
});
selectedBlockText.anchor.set(0.5, 0);
selectedBlockText.y = -80;
LK.gui.bottom.addChild(selectedBlockText);
// Initialize world with base terrain
function generateWorld() {
for (var x = 0; x < worldWidth; x++) {
world[x] = [];
for (var y = 0; y < worldHeight; y++) {
world[x][y] = null;
// Generate base terrain
if (y >= 15) {
var blockType = 'dirt';
if (y === 15) blockType = 'grass';
if (y >= 18) blockType = 'stone';
var block = new Block(blockType, x, y);
block.x = x * blockSize;
block.y = y * blockSize;
world[x][y] = block;
game.addChild(block);
}
}
}
}
function getGridPosition(worldX, worldY) {
return {
x: Math.floor(worldX / blockSize),
y: Math.floor(worldY / blockSize)
};
}
function placeBlock(gridX, gridY, blockType) {
if (gridX < 0 || gridX >= worldWidth || gridY < 0 || gridY >= worldHeight) return;
if (world[gridX][gridY] !== null) return;
var block = new Block(blockType, gridX, gridY);
block.x = gridX * blockSize;
block.y = gridY * blockSize;
world[gridX][gridY] = block;
game.addChild(block);
LK.getSound('place').play();
}
function breakBlock(block) {
if (!block) return;
var gridX = block.gridX;
var gridY = block.gridY;
world[gridX][gridY] = null;
block.destroy();
LK.getSound('break').play();
}
function switchMode() {
miningMode = !miningMode;
buildMode = !buildMode;
if (miningMode) {
modeText.setText('MINING MODE');
} else {
modeText.setText('BUILD MODE');
}
}
function switchBlock() {
var blockTypes = ['grass', 'dirt', 'stone', 'wood'];
var currentIndex = blockTypes.indexOf(player.selectedBlock);
var nextIndex = (currentIndex + 1) % blockTypes.length;
player.selectedBlock = blockTypes[nextIndex];
selectedBlockText.setText(player.selectedBlock.toUpperCase() + ' BLOCK');
}
generateWorld();
game.down = function (x, y, obj) {
if (buildMode && !miningMode) {
var gridPos = getGridPosition(x, y);
placeBlock(gridPos.x, gridPos.y, player.selectedBlock);
}
};
game.up = function (x, y, obj) {
// Double tap to switch modes
var currentTime = Date.now();
if (currentTime - (game.lastTapTime || 0) < 300) {
switchMode();
}
game.lastTapTime = currentTime;
};
game.move = function (x, y, obj) {
// Update player position to follow touch/mouse when in build mode
if (buildMode) {
player.x = x;
if (player.y > y - 100) {
player.y = y - 100;
}
}
};
game.update = function () {
// Simple gravity for player
if (player.y < 2732 - 200) {
var gridPos = getGridPosition(player.x, player.y + 120);
if (gridPos.x >= 0 && gridPos.x < worldWidth && gridPos.y >= 0 && gridPos.y < worldHeight) {
if (world[gridPos.x][gridPos.y] === null) {
player.y += 3; // Gravity
}
}
}
// Keep player in bounds
if (player.x < 30) player.x = 30;
if (player.x > 2048 - 30) player.x = 2048 - 30;
if (player.y > 2732 - 200) player.y = 2732 - 200;
// Auto-switch blocks every 3 seconds for demo
if (LK.ticks % 180 === 0) {
switchBlock();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -5,76 +5,44 @@
/****
* Classes
****/
-var Bubble = Container.expand(function (type) {
+var Block = Container.expand(function (type, gridX, gridY) {
var self = Container.call(this);
- self.bubbleType = type || 'blue';
- self.pointValue = 10;
- self.speed = 2;
- self.isPowerUp = false;
- var assetName = 'blueBubble';
- if (self.bubbleType === 'red') {
- assetName = 'redBubble';
- self.pointValue = 15;
- } else if (self.bubbleType === 'green') {
- assetName = 'greenBubble';
- self.pointValue = 20;
- } else if (self.bubbleType === 'yellow') {
- assetName = 'yellowBubble';
- self.pointValue = 25;
- } else if (self.bubbleType === 'purple') {
- assetName = 'purpleBubble';
- self.pointValue = 30;
- } else if (self.bubbleType === 'power') {
- assetName = 'powerBubble';
- self.pointValue = 50;
- self.isPowerUp = true;
+ self.blockType = type || 'grass';
+ self.gridX = gridX;
+ self.gridY = gridY;
+ var assetName = 'grassBlock';
+ if (self.blockType === 'stone') {
+ assetName = 'stoneBlock';
+ } else if (self.blockType === 'wood') {
+ assetName = 'woodBlock';
+ } else if (self.blockType === 'dirt') {
+ assetName = 'dirtBlock';
}
- var bubbleGraphics = self.attachAsset(assetName, {
- anchorX: 0.5,
- anchorY: 0.5
+ var blockGraphics = self.attachAsset(assetName, {
+ anchorX: 0,
+ anchorY: 0
});
- self.floating = true;
self.down = function (x, y, obj) {
- if (self.floating) {
- self.floating = false;
- self.pop();
- }
- };
- self.pop = function () {
- if (self.isPowerUp) {
- LK.getSound('powerup').play();
- activatePowerUp();
+ if (miningMode) {
+ breakBlock(self);
} else {
- LK.getSound('pop').play();
+ // Show block info or interact
}
- LK.setScore(LK.getScore() + self.pointValue);
- scoreTxt.setText(LK.getScore());
- // Pop animation
- tween(self, {
- scaleX: 1.5,
- scaleY: 1.5,
- alpha: 0
- }, {
- duration: 200,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- self.destroy();
- var index = bubbles.indexOf(self);
- if (index > -1) {
- bubbles.splice(index, 1);
- }
- }
- });
};
- self.update = function () {
- if (self.floating) {
- 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: 1
+ });
+ self.speed = 5;
+ self.selectedBlock = 'grass';
+ return self;
+});
/****
* Initialize Game
****/
@@ -84,116 +52,139 @@
/****
* Game Code
****/
-var bubbles = [];
-var lives = 3;
-var spawnTimer = 0;
-var spawnRate = 60; // Initial spawn rate (frames between spawns)
-var bubbleSpeed = 2;
-var powerUpActive = false;
-var powerUpTimer = 0;
+var world = [];
+var worldWidth = 25;
+var worldHeight = 20;
+var blockSize = 80;
+var cameraX = 0;
+var cameraY = 0;
+var miningMode = false;
+var buildMode = true;
+// Player
+var player = new Player();
+player.x = 1024;
+player.y = 1000;
+game.addChild(player);
// UI Elements
-var scoreTxt = new Text2('0', {
- size: 80,
- fill: 0xFFFFFF
-});
-scoreTxt.anchor.set(0.5, 0);
-LK.gui.top.addChild(scoreTxt);
-var livesTxt = new Text2('Lives: 3', {
+var modeText = new Text2('BUILD MODE', {
size: 60,
fill: 0xFFFFFF
});
-livesTxt.anchor.set(1, 0);
-livesTxt.x = -20;
-livesTxt.y = 20;
-LK.gui.topRight.addChild(livesTxt);
-var powerUpTxt = new Text2('', {
- size: 50,
- fill: 0xFFFF00
+modeText.anchor.set(0.5, 0);
+LK.gui.top.addChild(modeText);
+var inventoryUI = LK.getAsset('inventory', {
+ anchorX: 0.5,
+ anchorY: 1
});
-powerUpTxt.anchor.set(0.5, 0);
-powerUpTxt.y = 100;
-LK.gui.top.addChild(powerUpTxt);
-function spawnBubble() {
- var bubbleTypes = ['blue', 'red', 'green', 'yellow', 'purple'];
- var bubbleType = bubbleTypes[Math.floor(Math.random() * bubbleTypes.length)];
- // 5% chance for power-up bubble
- if (Math.random() < 0.05) {
- bubbleType = 'power';
+LK.gui.bottom.addChild(inventoryUI);
+var selectedBlockText = new Text2('GRASS BLOCK', {
+ size: 40,
+ fill: 0xFFFFFF
+});
+selectedBlockText.anchor.set(0.5, 0);
+selectedBlockText.y = -80;
+LK.gui.bottom.addChild(selectedBlockText);
+// Initialize world with base terrain
+function generateWorld() {
+ for (var x = 0; x < worldWidth; x++) {
+ world[x] = [];
+ for (var y = 0; y < worldHeight; y++) {
+ world[x][y] = null;
+ // Generate base terrain
+ if (y >= 15) {
+ var blockType = 'dirt';
+ if (y === 15) blockType = 'grass';
+ if (y >= 18) blockType = 'stone';
+ var block = new Block(blockType, x, y);
+ block.x = x * blockSize;
+ block.y = y * blockSize;
+ world[x][y] = block;
+ game.addChild(block);
+ }
+ }
}
- var bubble = new Bubble(bubbleType);
- bubble.x = Math.random() * (2048 - 120) + 60;
- bubble.y = 2732 + 60;
- bubble.speed = bubbleSpeed + Math.random() * 2;
- bubbles.push(bubble);
- game.addChild(bubble);
- // Gentle floating animation
- bubble.scaleX = 0.8;
- bubble.scaleY = 0.8;
- tween(bubble, {
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 500,
- easing: tween.easeOut
- });
}
-function activatePowerUp() {
- powerUpActive = true;
- powerUpTimer = 300; // 5 seconds at 60fps
- powerUpTxt.setText('SLOW TIME!');
- // Slow down all bubbles
- for (var i = 0; i < bubbles.length; i++) {
- bubbles[i].speed *= 0.3;
- }
+function getGridPosition(worldX, worldY) {
+ return {
+ x: Math.floor(worldX / blockSize),
+ y: Math.floor(worldY / blockSize)
+ };
}
-function loseLife() {
- lives--;
- livesTxt.setText('Lives: ' + lives);
- LK.getSound('lose').play();
- LK.effects.flashScreen(0xff0000, 500);
- if (lives <= 0) {
- LK.showGameOver();
+function placeBlock(gridX, gridY, blockType) {
+ if (gridX < 0 || gridX >= worldWidth || gridY < 0 || gridY >= worldHeight) return;
+ if (world[gridX][gridY] !== null) return;
+ var block = new Block(blockType, gridX, gridY);
+ block.x = gridX * blockSize;
+ block.y = gridY * blockSize;
+ world[gridX][gridY] = block;
+ game.addChild(block);
+ LK.getSound('place').play();
+}
+function breakBlock(block) {
+ if (!block) return;
+ var gridX = block.gridX;
+ var gridY = block.gridY;
+ world[gridX][gridY] = null;
+ block.destroy();
+ LK.getSound('break').play();
+}
+function switchMode() {
+ miningMode = !miningMode;
+ buildMode = !buildMode;
+ if (miningMode) {
+ modeText.setText('MINING MODE');
+ } else {
+ modeText.setText('BUILD MODE');
}
}
-function updateDifficulty() {
- var score = LK.getScore();
- // Increase bubble speed every 500 points
- bubbleSpeed = 2 + Math.floor(score / 500) * 0.5;
- // Decrease spawn rate (more frequent spawning) every 200 points
- spawnRate = Math.max(20, 60 - Math.floor(score / 200) * 5);
+function switchBlock() {
+ var blockTypes = ['grass', 'dirt', 'stone', 'wood'];
+ var currentIndex = blockTypes.indexOf(player.selectedBlock);
+ var nextIndex = (currentIndex + 1) % blockTypes.length;
+ player.selectedBlock = blockTypes[nextIndex];
+ selectedBlockText.setText(player.selectedBlock.toUpperCase() + ' BLOCK');
}
+generateWorld();
+game.down = function (x, y, obj) {
+ if (buildMode && !miningMode) {
+ var gridPos = getGridPosition(x, y);
+ placeBlock(gridPos.x, gridPos.y, player.selectedBlock);
+ }
+};
+game.up = function (x, y, obj) {
+ // Double tap to switch modes
+ var currentTime = Date.now();
+ if (currentTime - (game.lastTapTime || 0) < 300) {
+ switchMode();
+ }
+ game.lastTapTime = currentTime;
+};
+game.move = function (x, y, obj) {
+ // Update player position to follow touch/mouse when in build mode
+ if (buildMode) {
+ player.x = x;
+ if (player.y > y - 100) {
+ player.y = y - 100;
+ }
+ }
+};
game.update = function () {
- // Handle power-up timer
- if (powerUpActive) {
- powerUpTimer--;
- if (powerUpTimer <= 0) {
- powerUpActive = false;
- powerUpTxt.setText('');
- // Restore normal bubble speeds
- for (var i = 0; i < bubbles.length; i++) {
- bubbles[i].speed = bubbleSpeed + Math.random() * 2;
+ // Simple gravity for player
+ if (player.y < 2732 - 200) {
+ var gridPos = getGridPosition(player.x, player.y + 120);
+ if (gridPos.x >= 0 && gridPos.x < worldWidth && gridPos.y >= 0 && gridPos.y < worldHeight) {
+ if (world[gridPos.x][gridPos.y] === null) {
+ player.y += 3; // Gravity
}
}
}
- // Spawn bubbles
- spawnTimer++;
- if (spawnTimer >= spawnRate) {
- spawnBubble();
- spawnTimer = 0;
+ // Keep player in bounds
+ if (player.x < 30) player.x = 30;
+ if (player.x > 2048 - 30) player.x = 2048 - 30;
+ if (player.y > 2732 - 200) player.y = 2732 - 200;
+ // Auto-switch blocks every 3 seconds for demo
+ if (LK.ticks % 180 === 0) {
+ switchBlock();
}
- // Update bubbles and check for escaped bubbles
- for (var i = bubbles.length - 1; i >= 0; i--) {
- var bubble = bubbles[i];
- // Check if bubble escaped (reached top of screen)
- if (bubble.floating && bubble.y < -60) {
- bubble.destroy();
- bubbles.splice(i, 1);
- loseLife();
- }
- }
- // Update difficulty
- updateDifficulty();
- // Update score display
- scoreTxt.setText(LK.getScore());
};
\ No newline at end of file