User prompt
after the ship entirely sunk, i want to make it seem as sunk not black.
User prompt
bring a little bit down
User prompt
bring rotate button to middle and make it bigger
User prompt
make sure that my assets do not spoiling when i rotate the ships.
User prompt
make button where i can rotate the ship on the top
User prompt
hey I have uploaded the sprites of the each ship to the assets folder. Like for the 1 parted ship there is only one ship sprite, for the 2 parted ship there are two seperate sprite for each part of it and when merged it looks like a full ship. What I want you to do is to apply those photos according to the ships form and ordered.
User prompt
bring to previous version
User prompt
when i place ships make them as a whole not like slice slice
User prompt
Please fix the bug: 'TypeError: Cannot use 'in' operator to search for 'scaleX' in null' in or related to this line: 'tween(self.shipPartGraphic, {' Line Number: 154
User prompt
look! when i place my sheep i wanna place them at once i mean completely but when i blow up or enemy blows up mine each part should individually be blown up when i click first gap missed then second missed then third oh i found then when i found the other part the parts of ship should be seen ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
refine it
User prompt
i cannot see my ships
User prompt
no i dont mean it bring previous version back
User prompt
make them seen when i place and click also ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
i want to make 4 different ships. Then i will slice them into parts. For example i clicked and found a one part then second part when i click parts of ship should be seen then when i click other part again it should be visible. When i click last part, the whole ship should be seen as a sunk ship. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
in order to make ship appearance i will make ship png and slice it then when i click on ship one part of it will be blown and then i will click rest of it. After fully found the whole ship will be seen as blown up as a whole. So now i need to add all parts one by one
User prompt
make some blow up effect whenever i blow or enemy blows my ship ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make cross lines visible and also when i attack enemy's ships i cannot blow them up. Additionally make the water area larger.
Code edit (1 edits merged)
Please save this source code
User prompt
Naval Strike: Battleship Duel
Initial prompt
A game like sea batlle. Where we place our ships and guess to blow them.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var GridTile = Container.expand(function (x, y, isPlayerGrid) {
var self = Container.call(this);
self.gridX = x;
self.gridY = y;
self.isPlayerGrid = isPlayerGrid;
self.hasShip = false;
self.isHit = false;
self.shipId = null;
self.shipPartIndex = null;
self.shipPartGraphic = null;
var background = self.attachAsset('waterTile', {
anchorX: 0.5,
anchorY: 0.5
});
self.marker = null;
self.setShip = function (shipId, partIndex) {
self.hasShip = true;
self.shipId = shipId;
self.shipPartIndex = partIndex;
// Don't show ship parts during placement
};
self.markHit = function () {
if (!self.isHit) {
self.isHit = true;
if (self.hasShip) {
self.marker = self.attachAsset('hitMarker', {
anchorX: 0.5,
anchorY: 0.5
});
// Explosion effect for ship hit
self.marker.scaleX = 0.1;
self.marker.scaleY = 0.1;
self.marker.alpha = 0.8;
tween(self.marker, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 1
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.marker, {
scaleX: 1,
scaleY: 1
}, {
duration: 300,
easing: tween.easeInOut
});
}
});
// Flash the background tile
tween(background, {
tint: 0xff4444
}, {
duration: 150,
onFinish: function onFinish() {
tween(background, {
tint: 0xffffff
}, {
duration: 150
});
}
});
} else {
self.marker = self.attachAsset('missMarker', {
anchorX: 0.5,
anchorY: 0.5
});
// Small splash effect for miss
self.marker.scaleX = 0.3;
self.marker.scaleY = 0.3;
tween(self.marker, {
scaleX: 1,
scaleY: 1
}, {
duration: 400,
easing: tween.bounceOut
});
}
}
};
self.blowUpShipPart = function () {
if (self.shipPartGraphic) {
self.removeChild(self.shipPartGraphic);
var assetName = self.shipId + 'PartBlown';
self.shipPartGraphic = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
// Explosion effect for individual part
self.shipPartGraphic.scaleX = 0.2;
self.shipPartGraphic.scaleY = 0.2;
self.shipPartGraphic.alpha = 0.5;
self.shipPartGraphic.tint = 0xff4444;
tween(self.shipPartGraphic, {
scaleX: 1.2,
scaleY: 1.2,
alpha: 1
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.shipPartGraphic, {
scaleX: 1,
scaleY: 1,
tint: 0x666666
}, {
duration: 400,
easing: tween.easeInOut
});
}
});
}
};
self.markMiss = function () {
if (!self.isHit) {
self.isHit = true;
self.marker = self.attachAsset('missMarker', {
anchorX: 0.5,
anchorY: 0.5
});
}
};
self.markSunk = function () {
if (self.marker) {
self.removeChild(self.marker);
}
if (self.shipPartGraphic) {
self.removeChild(self.shipPartGraphic);
self.shipPartGraphic = null;
}
var completeAssetName = self.shipId + 'CompleteBlown';
self.marker = self.attachAsset(completeAssetName, {
anchorX: 0.5,
anchorY: 0.5
});
// Dramatic sinking explosion effect
self.marker.scaleX = 0.2;
self.marker.scaleY = 0.2;
self.marker.alpha = 0;
self.marker.tint = 0xff0000;
// First phase: rapid expansion with red flash
tween(self.marker, {
scaleX: 2,
scaleY: 2,
alpha: 1
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// Second phase: settle to normal size and fade to dark
tween(self.marker, {
scaleX: 1,
scaleY: 1,
tint: 0x333333
}, {
duration: 500,
easing: tween.easeInOut
});
}
});
// Background explosion flash
tween(background, {
tint: 0xff6600
}, {
duration: 200,
onFinish: function onFinish() {
tween(background, {
tint: 0x004466
}, {
duration: 400,
onFinish: function onFinish() {
tween(background, {
tint: 0xffffff
}, {
duration: 200
});
}
});
}
});
};
self.down = function (x, y, obj) {
if (gamePhase === 'placement') {
handleShipPlacement(self.gridX, self.gridY);
} else if (gamePhase === 'battle' && !self.isPlayerGrid && !self.isHit) {
handleAttack(self.gridX, self.gridY);
}
};
return self;
});
var Ship = Container.expand(function (id, size, name) {
var self = Container.call(this);
self.id = id;
self.size = size;
self.name = name;
self.positions = [];
self.hits = 0;
self.isHorizontal = true;
self.isPlaced = false;
self.isSunk = false;
self.getPositions = function () {
return self.positions;
};
self.hit = function () {
self.hits++;
if (self.hits >= self.size) {
self.isSunk = true;
return true;
}
return false;
};
self.placeAt = function (startX, startY, horizontal) {
self.positions = [];
self.isHorizontal = horizontal;
self.isPlaced = true;
for (var i = 0; i < self.size; i++) {
if (horizontal) {
self.positions.push({
x: startX + i,
y: startY
});
} else {
self.positions.push({
x: startX,
y: startY + i
});
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x001122
});
/****
* Game Code
****/
// Carrier parts (5 parts)
// Battleship parts (4 parts)
// Cruiser parts (3 parts)
// Destroyer parts (2 parts)
var GRID_SIZE = 10;
var TILE_SIZE = 90;
var GRID_SPACING = 120;
var gamePhase = 'placement'; // 'placement', 'battle', 'gameOver'
var currentPlayer = 'player'; // 'player', 'ai'
var playerGrid = [];
var aiGrid = [];
var playerShips = [];
var aiShips = [];
var currentShipIndex = 0;
var selectedRotation = true; // true = horizontal, false = vertical
// Ship definitions
var shipDefinitions = [{
id: 'destroyer',
size: 2,
name: 'Destroyer'
}, {
id: 'cruiser',
size: 3,
name: 'Cruiser'
}, {
id: 'battleship',
size: 4,
name: 'Battleship'
}, {
id: 'carrier',
size: 5,
name: 'Carrier'
}];
// UI Elements
var phaseText = new Text2('Place your ships', {
size: 60,
fill: 0xFFFFFF
});
phaseText.anchor.set(0.5, 0);
LK.gui.top.addChild(phaseText);
var instructionText = new Text2('Tap to place Destroyer (2)', {
size: 40,
fill: 0xCCCCCC
});
instructionText.anchor.set(0.5, 0);
instructionText.y = 80;
LK.gui.top.addChild(instructionText);
var rotateText = new Text2('Tap anywhere to rotate', {
size: 30,
fill: 0xFFFF00
});
rotateText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(rotateText);
// Initialize grids
function initializeGrids() {
var playerGridStartX = 2048 / 4 - GRID_SIZE * TILE_SIZE / 2;
var aiGridStartX = 3 * 2048 / 4 - GRID_SIZE * TILE_SIZE / 2;
var gridStartY = 2732 / 2 - GRID_SIZE * TILE_SIZE / 2;
// Create player grid
for (var x = 0; x < GRID_SIZE; x++) {
playerGrid[x] = [];
for (var y = 0; y < GRID_SIZE; y++) {
var tile = new GridTile(x, y, true);
tile.x = playerGridStartX + x * TILE_SIZE;
tile.y = gridStartY + y * TILE_SIZE;
playerGrid[x][y] = tile;
game.addChild(tile);
}
}
// Create AI grid
for (var x = 0; x < GRID_SIZE; x++) {
aiGrid[x] = [];
for (var y = 0; y < GRID_SIZE; y++) {
var tile = new GridTile(x, y, false);
tile.x = aiGridStartX + x * TILE_SIZE;
tile.y = gridStartY + y * TILE_SIZE;
aiGrid[x][y] = tile;
game.addChild(tile);
}
}
}
// Create ships
function createShips() {
for (var i = 0; i < shipDefinitions.length; i++) {
var def = shipDefinitions[i];
var ship = new Ship(def.id, def.size, def.name);
playerShips.push(ship);
var aiShip = new Ship(def.id, def.size, def.name);
aiShips.push(aiShip);
}
}
function canPlaceShip(grid, x, y, size, horizontal) {
for (var i = 0; i < size; i++) {
var checkX = horizontal ? x + i : x;
var checkY = horizontal ? y : y + i;
if (checkX >= GRID_SIZE || checkY >= GRID_SIZE) {
return false;
}
if (grid[checkX][checkY].hasShip) {
return false;
}
}
return true;
}
function placeShip(grid, ship, x, y, horizontal) {
ship.placeAt(x, y, horizontal);
var positions = ship.getPositions();
for (var i = 0; i < positions.length; i++) {
var pos = positions[i];
grid[pos.x][pos.y].setShip(ship.id, i);
}
}
function handleShipPlacement(x, y) {
if (currentShipIndex >= shipDefinitions.length) return;
var currentShip = playerShips[currentShipIndex];
if (canPlaceShip(playerGrid, x, y, currentShip.size, selectedRotation)) {
placeShip(playerGrid, currentShip, x, y, selectedRotation);
currentShipIndex++;
if (currentShipIndex >= shipDefinitions.length) {
// All ships placed, start AI placement
placeAIShips();
startBattlePhase();
} else {
var nextShip = shipDefinitions[currentShipIndex];
instructionText.setText('Tap to place ' + nextShip.name + ' (' + nextShip.size + ')');
}
}
}
function placeAIShips() {
for (var i = 0; i < aiShips.length; i++) {
var ship = aiShips[i];
var placed = false;
var attempts = 0;
while (!placed && attempts < 100) {
var x = Math.floor(Math.random() * GRID_SIZE);
var y = Math.floor(Math.random() * GRID_SIZE);
var horizontal = Math.random() < 0.5;
if (canPlaceShip(aiGrid, x, y, ship.size, horizontal)) {
placeShip(aiGrid, ship, x, y, horizontal);
placed = true;
}
attempts++;
}
}
}
function startBattlePhase() {
gamePhase = 'battle';
phaseText.setText('Battle Phase');
instructionText.setText('Attack enemy grid!');
rotateText.setText('');
}
function handleAttack(x, y) {
if (gamePhase !== 'battle' || currentPlayer !== 'player') return;
var tile = aiGrid[x][y];
var isHit = tile.hasShip;
tile.markHit();
if (isHit) {
LK.getSound('hit').play();
// Check if ship is sunk
var hitShip = null;
for (var i = 0; i < aiShips.length; i++) {
var ship = aiShips[i];
var positions = ship.getPositions();
for (var j = 0; j < positions.length; j++) {
if (positions[j].x === x && positions[j].y === y) {
hitShip = ship;
break;
}
}
if (hitShip) break;
}
// First blow up the individual part
if (isHit && !aiGrid[x][y].isPlayerGrid) {
aiGrid[x][y].blowUpShipPart();
}
if (hitShip && hitShip.hit()) {
LK.getSound('sink').play();
// Mark all ship positions as sunk
var positions = hitShip.getPositions();
for (var k = 0; k < positions.length; k++) {
var pos = positions[k];
aiGrid[pos.x][pos.y].markSunk();
}
if (checkVictory(aiShips)) {
gamePhase = 'gameOver';
phaseText.setText('You Win!');
instructionText.setText('All enemy ships destroyed!');
LK.showYouWin();
return;
}
}
} else {
tile.markMiss();
LK.getSound('miss').play();
}
currentPlayer = 'ai';
instructionText.setText('AI is attacking...');
LK.setTimeout(function () {
aiAttack();
}, 1000);
}
function aiAttack() {
var validTargets = [];
for (var x = 0; x < GRID_SIZE; x++) {
for (var y = 0; y < GRID_SIZE; y++) {
if (!playerGrid[x][y].isHit) {
validTargets.push({
x: x,
y: y
});
}
}
}
if (validTargets.length === 0) return;
var target = validTargets[Math.floor(Math.random() * validTargets.length)];
var tile = playerGrid[target.x][target.y];
var isHit = tile.hasShip;
tile.markHit();
if (isHit) {
LK.getSound('hit').play();
// Check if ship is sunk
var hitShip = null;
for (var i = 0; i < playerShips.length; i++) {
var ship = playerShips[i];
var positions = ship.getPositions();
for (var j = 0; j < positions.length; j++) {
if (positions[j].x === target.x && positions[j].y === target.y) {
hitShip = ship;
break;
}
}
if (hitShip) break;
}
// First blow up the individual part
if (isHit && playerGrid[target.x][target.y].isPlayerGrid) {
playerGrid[target.x][target.y].blowUpShipPart();
}
if (hitShip && hitShip.hit()) {
LK.getSound('sink').play();
// Mark all ship positions as sunk
var positions = hitShip.getPositions();
for (var k = 0; k < positions.length; k++) {
var pos = positions[k];
playerGrid[pos.x][pos.y].markSunk();
}
if (checkVictory(playerShips)) {
gamePhase = 'gameOver';
phaseText.setText('You Lose!');
instructionText.setText('All your ships destroyed!');
LK.showGameOver();
return;
}
}
} else {
tile.markMiss();
LK.getSound('miss').play();
}
currentPlayer = 'player';
instructionText.setText('Your turn - Attack enemy grid!');
}
function checkVictory(ships) {
for (var i = 0; i < ships.length; i++) {
if (!ships[i].isSunk) {
return false;
}
}
return true;
}
// Handle rotation during placement
game.down = function (x, y, obj) {
if (gamePhase === 'placement') {
selectedRotation = !selectedRotation;
var rotationText = selectedRotation ? 'Horizontal' : 'Vertical';
rotateText.setText('Current: ' + rotationText + ' (Tap to change)');
}
};
// Initialize game
initializeGrids();
createShips();
// Set initial instruction
if (shipDefinitions.length > 0) {
instructionText.setText('Tap to place ' + shipDefinitions[0].name + ' (' + shipDefinitions[0].size + ')');
}
rotateText.setText('Current: Horizontal (Tap to change)'); ===================================================================
--- original.js
+++ change.js
@@ -24,13 +24,9 @@
self.setShip = function (shipId, partIndex) {
self.hasShip = true;
self.shipId = shipId;
self.shipPartIndex = partIndex;
- var assetName = shipId + 'PartNormal';
- self.shipPartGraphic = self.attachAsset(assetName, {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ // Don't show ship parts during placement
};
self.markHit = function () {
if (!self.isHit) {
self.isHit = true;
@@ -196,14 +192,8 @@
if (gamePhase === 'placement') {
handleShipPlacement(self.gridX, self.gridY);
} else if (gamePhase === 'battle' && !self.isPlayerGrid && !self.isHit) {
handleAttack(self.gridX, self.gridY);
- } else if (gamePhase === 'battle' && self.isPlayerGrid && self.hasShip && !self.isHit) {
- // Allow clicking on own ships during battle to see them
- self.markHit();
- if (self.hasShip) {
- self.blowUpShipPart();
- }
}
};
return self;
});