/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Atom = Container.expand(function () {
var self = Container.call(this);
// Create shells (back to front)
var nShell = self.attachAsset('nShell', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3
});
var mShell = self.attachAsset('mShell', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3
});
var lShell = self.attachAsset('lShell', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3
});
var kShell = self.attachAsset('kShell', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3
});
// Nucleus on top
var nucleusGraphics = self.attachAsset('nucleus', {
anchorX: 0.5,
anchorY: 0.5
});
self.shells = [kShell, lShell, mShell, nShell];
self.shellCapacities = [2, 8, 8, 2]; // For first 20 elements
self.electronCounts = [0, 0, 0, 0];
self.addElectron = function () {
// Fill shells in order: K, L, M, N
for (var i = 0; i < self.shells.length; i++) {
if (self.electronCounts[i] < self.shellCapacities[i]) {
self.electronCounts[i]++;
self.updateShellVisual(i);
return true;
}
}
return false;
};
self.updateShellVisual = function (shellIndex) {
var fillRatio = self.electronCounts[shellIndex] / self.shellCapacities[shellIndex];
self.shells[shellIndex].alpha = 0.3 + fillRatio * 0.5;
// Animate shell completion
if (fillRatio === 1) {
tween(self.shells[shellIndex], {
alpha: 1
}, {
duration: 500,
onFinish: function onFinish() {
tween(self.shells[shellIndex], {
alpha: 0.8
}, {
duration: 200
});
}
});
}
};
self.getTotalElectrons = function () {
return self.electronCounts[0] + self.electronCounts[1] + self.electronCounts[2] + self.electronCounts[3];
};
self.reset = function () {
self.electronCounts = [0, 0, 0, 0];
for (var i = 0; i < self.shells.length; i++) {
self.shells[i].alpha = 0.3;
}
// Remove orbiting electrons when resetting
for (var i = game.children.length - 1; i >= 0; i--) {
var child = game.children[i];
if (child.isOrbiting) {
child.destroy();
}
}
};
return self;
});
var ElectronBall = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('electronBall', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.5;
self.active = true;
self.update = function () {
if (!self.active) {
return;
}
self.velocityY += self.gravity;
self.x += self.velocityX;
self.y += self.velocityY;
// Check bounds
if (self.y > 2732 + 100 || self.x < -100 || self.x > 2048 + 100) {
self.active = false;
}
};
return self;
});
var InfoPanel = Container.expand(function () {
var self = Container.call(this);
var background = LK.getAsset({
width: 1800,
height: 800,
color: 0x2c3e50,
shape: 'box'
}, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
self.addChild(background);
self.titleText = new Text2('', {
size: 80,
fill: 0xFFFFFF
});
self.titleText.anchor.set(0.5, 0);
self.titleText.x = 0;
self.titleText.y = -300;
self.addChild(self.titleText);
self.configText = new Text2('', {
size: 50,
fill: 0xECF0F1
});
self.configText.anchor.set(0.5, 0);
self.configText.x = 0;
self.configText.y = -200;
self.addChild(self.configText);
self.factText = new Text2('', {
size: 40,
fill: 0xBDC3C7
});
self.factText.anchor.set(0.5, 0);
self.factText.x = 0;
self.factText.y = -50;
self.addChild(self.factText);
self.continueText = new Text2('Devam etmek için dokunun', {
size: 45,
fill: 0xF39C12
});
self.continueText.anchor.set(0.5, 0);
self.continueText.x = 0;
self.continueText.y = 250;
self.addChild(self.continueText);
self.visible = false;
self.showElement = function (elementData) {
self.titleText.setText(elementData.name + ' (Z=' + elementData.atomicNumber + ')');
self.configText.setText('Elektron Dizilimi: ' + elementData.configuration);
self.factText.setText(elementData.fact);
self.visible = true;
};
self.hide = function () {
self.visible = false;
};
return self;
});
// Game will be initialized when main menu play button is pressed
var MainMenu = Container.expand(function () {
var self = Container.call(this);
var background = LK.getAsset({
width: 2048,
height: 2732,
color: 0x0f1419,
shape: 'box'
}, {
anchorX: 0,
anchorY: 0
});
self.addChild(background);
var titleText = new Text2('ELEKTROBOL', {
size: 120,
fill: 0x4A90E2
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 600;
self.addChild(titleText);
var subtitleText = new Text2('Elektron Dizilimi Basketbolu', {
size: 60,
fill: 0xFFFFFF
});
subtitleText.anchor.set(0.5, 0.5);
subtitleText.x = 1024;
subtitleText.y = 720;
self.addChild(subtitleText);
var descriptionText = new Text2('İlk 20 elementin elektron dizilimini öğren!\nElektron toplarını çekirdeğe at ve katmanları doldur.', {
size: 45,
fill: 0xBDC3C7
});
descriptionText.anchor.set(0.5, 0.5);
descriptionText.x = 1024;
descriptionText.y = 900;
self.addChild(descriptionText);
var playButton = LK.getAsset({
width: 400,
height: 100,
color: 0x4A90E2,
shape: 'box'
}, {
anchorX: 0.5,
anchorY: 0.5
});
playButton.x = 1024;
playButton.y = 1200;
self.addChild(playButton);
var playText = new Text2('OYNA', {
size: 60,
fill: 0xFFFFFF
});
playText.anchor.set(0.5, 0.5);
playText.x = 1024;
playText.y = 1200;
self.addChild(playText);
var instructionText = new Text2('Başlamak için OYNA butonuna dokunun', {
size: 40,
fill: 0x95A5A6
});
instructionText.anchor.set(0.5, 1);
instructionText.x = 1024;
instructionText.y = 2600;
self.addChild(instructionText);
// Make play button interactive
playButton.down = function (x, y, obj) {
startGame();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0f1419
});
/****
* Game Code
****/
// Element data for first 20 elements (Turkish)
var elementData = [{
name: 'Hidrojen',
atomicNumber: 1,
electrons: 1,
configuration: '1s¹',
fact: 'Evrendeki en bol element'
}, {
name: 'Helyum',
atomicNumber: 2,
electrons: 2,
configuration: '1s²',
fact: 'İkinci en hafif element, balonlarda kullanılır'
}, {
name: 'Lityum',
atomicNumber: 3,
electrons: 3,
configuration: '1s² 2s¹',
fact: 'En hafif metal, pillerde kullanılır'
}, {
name: 'Berilyum',
atomicNumber: 4,
electrons: 4,
configuration: '1s² 2s²',
fact: 'Havacılık uygulamalarında kullanılır'
}, {
name: 'Bor',
atomicNumber: 5,
electrons: 5,
configuration: '1s² 2s² 2p¹',
fact: 'Bitki gelişimi için gerekli'
}, {
name: 'Karbon',
atomicNumber: 6,
electrons: 6,
configuration: '1s² 2s² 2p²',
fact: 'Tüm organik bileşiklerin temeli'
}, {
name: 'Azot',
atomicNumber: 7,
electrons: 7,
configuration: '1s² 2s² 2p³',
fact: 'Dünya atmosferinin %78\'i'
}, {
name: 'Oksijen',
atomicNumber: 8,
electrons: 8,
configuration: '1s² 2s² 2p⁴',
fact: 'Nefes almak için gerekli'
}, {
name: 'Flor',
atomicNumber: 9,
electrons: 9,
configuration: '1s² 2s² 2p⁵',
fact: 'En reaktif element'
}, {
name: 'Neon',
atomicNumber: 10,
electrons: 10,
configuration: '1s² 2s² 2p⁶',
fact: 'Renkli tabelalar için kullanılır'
}, {
name: 'Sodyum',
atomicNumber: 11,
electrons: 11,
configuration: '1s² 2s² 2p⁶ 3s¹',
fact: 'Gerekli elektrolit'
}, {
name: 'Magnezyum',
atomicNumber: 12,
electrons: 12,
configuration: '1s² 2s² 2p⁶ 3s²',
fact: 'Kemikler için önemli'
}, {
name: 'Alüminyum',
atomicNumber: 13,
electrons: 13,
configuration: '1s² 2s² 2p⁶ 3s² 3p¹',
fact: 'Hafif metal'
}, {
name: 'Silisyum',
atomicNumber: 14,
electrons: 14,
configuration: '1s² 2s² 2p⁶ 3s² 3p²',
fact: 'Bilgisayar çipi malzemesi'
}, {
name: 'Fosfor',
atomicNumber: 15,
electrons: 15,
configuration: '1s² 2s² 2p⁶ 3s² 3p³',
fact: 'DNA için gerekli'
}, {
name: 'Kükürt',
atomicNumber: 16,
electrons: 16,
configuration: '1s² 2s² 2p⁶ 3s² 3p⁴',
fact: 'Sarı kristal element'
}, {
name: 'Klor',
atomicNumber: 17,
electrons: 17,
configuration: '1s² 2s² 2p⁶ 3s² 3p⁵',
fact: 'Suyu dezenfekte etmek için kullanılır'
}, {
name: 'Argon',
atomicNumber: 18,
electrons: 18,
configuration: '1s² 2s² 2p⁶ 3s² 3p⁶',
fact: 'Asil gaz, kimyasal olarak inert'
}, {
name: 'Potasyum',
atomicNumber: 19,
electrons: 19,
configuration: '1s² 2s² 2p⁶ 3s² 3p⁶ 4s¹',
fact: 'Sinir işlevi için önemli'
}, {
name: 'Kalsiyum',
atomicNumber: 20,
electrons: 20,
configuration: '1s² 2s² 2p⁶ 3s² 3p⁶ 4s²',
fact: 'Güçlü kemikler için gerekli'
}];
// Game state variables
var gameStarted = false;
var currentLevel = 0;
var mainMenu;
var atom;
var infoPanel;
var electronBalls = [];
var trajectoryDots = [];
var shooting = false;
var startX = 0;
var startY = 0;
var showingInfo = false;
// UI Elements
var levelText;
var scoreText;
var progressText;
var instructionText;
// Initialize main menu
mainMenu = game.addChild(new MainMenu());
function startGame() {
gameStarted = true;
mainMenu.destroy();
// Initialize game objects
atom = game.addChild(new Atom());
atom.x = 1024;
atom.y = 600;
infoPanel = game.addChild(new InfoPanel());
infoPanel.x = 1024;
infoPanel.y = 1366;
// Initialize UI
levelText = new Text2('Seviye 1: Hidrojen', {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
scoreText = new Text2('Puan: 0', {
size: 50,
fill: 0xFFFFFF
});
scoreText.anchor.set(1, 0);
scoreText.x = -50;
scoreText.y = 20;
LK.gui.topRight.addChild(scoreText);
progressText = new Text2('Elektronlar: 0/1', {
size: 45,
fill: 0x4A90E2
});
progressText.anchor.set(0.5, 0);
progressText.y = 80;
LK.gui.top.addChild(progressText);
instructionText = new Text2('Elektronları atmak için sürükle ve bırak', {
size: 40,
fill: 0x95A5A6
});
instructionText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionText);
updateUI();
}
function updateUI() {
if (!gameStarted) {
return;
}
var currentElement = elementData[currentLevel];
levelText.setText('Seviye ' + (currentLevel + 1) + ': ' + currentElement.name);
scoreText.setText('Puan: ' + LK.getScore());
progressText.setText('Elektronlar: ' + atom.getTotalElectrons() + '/' + currentElement.electrons);
}
function createTrajectoryPreview(startX, startY, endX, endY) {
// Clear existing dots
for (var i = 0; i < trajectoryDots.length; i++) {
trajectoryDots[i].destroy();
}
trajectoryDots = [];
var velocityX = (endX - startX) * 0.02;
var velocityY = (endY - startY) * 0.02;
var x = startX;
var y = startY;
var vX = velocityX;
var vY = velocityY;
for (var i = 0; i < 20; i++) {
vY += 0.5; // gravity
x += vX;
y += vY;
var dot = LK.getAsset('trajectoryDot', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 1 - i * 0.05
});
dot.x = x;
dot.y = y;
game.addChild(dot);
trajectoryDots.push(dot);
if (y > 2732) {
break;
}
}
}
function clearTrajectory() {
for (var i = 0; i < trajectoryDots.length; i++) {
trajectoryDots[i].destroy();
}
trajectoryDots = [];
}
function shootElectron(startX, startY, endX, endY) {
var electron = new ElectronBall();
electron.x = startX;
electron.y = startY;
electron.velocityX = (endX - startX) * 0.02;
electron.velocityY = (endY - startY) * 0.02;
electronBalls.push(electron);
game.addChild(electron);
LK.getSound('shoot').play();
}
function checkElectronHit(electron) {
var dx = electron.x - atom.x;
var dy = electron.y - atom.y;
var distance = Math.sqrt(dx * dx + dy * dy);
return distance < 80; // Hit radius
}
function completeLevel() {
LK.setScore(LK.getScore() + 500);
LK.getSound('complete').play();
// Show element info
infoPanel.showElement(elementData[currentLevel]);
showingInfo = true;
// Flash effect
LK.effects.flashScreen(0x4a90e2, 1000);
}
function nextLevel() {
currentLevel++;
if (currentLevel >= elementData.length) {
LK.showYouWin();
return;
}
atom.reset();
updateUI();
showingInfo = false;
infoPanel.hide();
}
game.down = function (x, y, obj) {
if (!gameStarted) {
return;
}
if (showingInfo) {
nextLevel();
return;
}
shooting = true;
startX = x;
startY = y;
};
game.move = function (x, y, obj) {
if (!gameStarted) {
return;
}
if (shooting && !showingInfo) {
createTrajectoryPreview(startX, startY, x, y);
}
};
game.up = function (x, y, obj) {
if (!gameStarted) {
return;
}
if (shooting && !showingInfo) {
shootElectron(startX, startY, x, y);
clearTrajectory();
shooting = false;
}
};
game.update = function () {
if (!gameStarted) {
return;
}
// Update electrons
for (var i = electronBalls.length - 1; i >= 0; i--) {
var electron = electronBalls[i];
if (!electron.active) {
electron.destroy();
electronBalls.splice(i, 1);
LK.setScore(Math.max(0, LK.getScore() - 50));
updateUI();
continue;
}
// Check for hits
if (checkElectronHit(electron)) {
if (atom.addElectron()) {
LK.setScore(LK.getScore() + 100);
LK.getSound('hit').play();
// Animate electron to orbital position instead of destroying
electron.active = false; // Stop physics updates
var targetShell = -1;
var electronIndex = 0;
// Find which shell this electron belongs to
var totalElectrons = atom.getTotalElectrons();
if (totalElectrons <= 2) {
targetShell = 0; // K shell
electronIndex = totalElectrons - 1;
} else if (totalElectrons <= 10) {
targetShell = 1; // L shell
electronIndex = totalElectrons - 3;
} else if (totalElectrons <= 18) {
targetShell = 2; // M shell
electronIndex = totalElectrons - 11;
} else {
targetShell = 3; // N shell
electronIndex = totalElectrons - 19;
}
// Calculate orbital position
var shellRadius = [120, 180, 240, 300][targetShell];
var angle = electronIndex / atom.shellCapacities[targetShell] * Math.PI * 2;
var targetX = atom.x + Math.cos(angle) * shellRadius;
var targetY = atom.y + Math.sin(angle) * shellRadius;
// Animate to orbital position
tween(electron, {
x: targetX,
y: targetY,
scaleX: 0.7,
scaleY: 0.7
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Start orbital animation
var orbitSpeed = 0.02;
electron.orbitAngle = angle;
electron.orbitRadius = shellRadius;
electron.isOrbiting = true;
}
});
// Check if level complete
if (atom.getTotalElectrons() === elementData[currentLevel].electrons) {
completeLevel();
}
}
electronBalls.splice(i, 1);
updateUI();
}
}
// Update orbiting electrons
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child.isOrbiting) {
child.orbitAngle += 0.02;
child.x = atom.x + Math.cos(child.orbitAngle) * child.orbitRadius;
child.y = atom.y + Math.sin(child.orbitAngle) * child.orbitRadius;
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Atom = Container.expand(function () {
var self = Container.call(this);
// Create shells (back to front)
var nShell = self.attachAsset('nShell', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3
});
var mShell = self.attachAsset('mShell', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3
});
var lShell = self.attachAsset('lShell', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3
});
var kShell = self.attachAsset('kShell', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3
});
// Nucleus on top
var nucleusGraphics = self.attachAsset('nucleus', {
anchorX: 0.5,
anchorY: 0.5
});
self.shells = [kShell, lShell, mShell, nShell];
self.shellCapacities = [2, 8, 8, 2]; // For first 20 elements
self.electronCounts = [0, 0, 0, 0];
self.addElectron = function () {
// Fill shells in order: K, L, M, N
for (var i = 0; i < self.shells.length; i++) {
if (self.electronCounts[i] < self.shellCapacities[i]) {
self.electronCounts[i]++;
self.updateShellVisual(i);
return true;
}
}
return false;
};
self.updateShellVisual = function (shellIndex) {
var fillRatio = self.electronCounts[shellIndex] / self.shellCapacities[shellIndex];
self.shells[shellIndex].alpha = 0.3 + fillRatio * 0.5;
// Animate shell completion
if (fillRatio === 1) {
tween(self.shells[shellIndex], {
alpha: 1
}, {
duration: 500,
onFinish: function onFinish() {
tween(self.shells[shellIndex], {
alpha: 0.8
}, {
duration: 200
});
}
});
}
};
self.getTotalElectrons = function () {
return self.electronCounts[0] + self.electronCounts[1] + self.electronCounts[2] + self.electronCounts[3];
};
self.reset = function () {
self.electronCounts = [0, 0, 0, 0];
for (var i = 0; i < self.shells.length; i++) {
self.shells[i].alpha = 0.3;
}
// Remove orbiting electrons when resetting
for (var i = game.children.length - 1; i >= 0; i--) {
var child = game.children[i];
if (child.isOrbiting) {
child.destroy();
}
}
};
return self;
});
var ElectronBall = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('electronBall', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.5;
self.active = true;
self.update = function () {
if (!self.active) {
return;
}
self.velocityY += self.gravity;
self.x += self.velocityX;
self.y += self.velocityY;
// Check bounds
if (self.y > 2732 + 100 || self.x < -100 || self.x > 2048 + 100) {
self.active = false;
}
};
return self;
});
var InfoPanel = Container.expand(function () {
var self = Container.call(this);
var background = LK.getAsset({
width: 1800,
height: 800,
color: 0x2c3e50,
shape: 'box'
}, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.9
});
self.addChild(background);
self.titleText = new Text2('', {
size: 80,
fill: 0xFFFFFF
});
self.titleText.anchor.set(0.5, 0);
self.titleText.x = 0;
self.titleText.y = -300;
self.addChild(self.titleText);
self.configText = new Text2('', {
size: 50,
fill: 0xECF0F1
});
self.configText.anchor.set(0.5, 0);
self.configText.x = 0;
self.configText.y = -200;
self.addChild(self.configText);
self.factText = new Text2('', {
size: 40,
fill: 0xBDC3C7
});
self.factText.anchor.set(0.5, 0);
self.factText.x = 0;
self.factText.y = -50;
self.addChild(self.factText);
self.continueText = new Text2('Devam etmek için dokunun', {
size: 45,
fill: 0xF39C12
});
self.continueText.anchor.set(0.5, 0);
self.continueText.x = 0;
self.continueText.y = 250;
self.addChild(self.continueText);
self.visible = false;
self.showElement = function (elementData) {
self.titleText.setText(elementData.name + ' (Z=' + elementData.atomicNumber + ')');
self.configText.setText('Elektron Dizilimi: ' + elementData.configuration);
self.factText.setText(elementData.fact);
self.visible = true;
};
self.hide = function () {
self.visible = false;
};
return self;
});
// Game will be initialized when main menu play button is pressed
var MainMenu = Container.expand(function () {
var self = Container.call(this);
var background = LK.getAsset({
width: 2048,
height: 2732,
color: 0x0f1419,
shape: 'box'
}, {
anchorX: 0,
anchorY: 0
});
self.addChild(background);
var titleText = new Text2('ELEKTROBOL', {
size: 120,
fill: 0x4A90E2
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 600;
self.addChild(titleText);
var subtitleText = new Text2('Elektron Dizilimi Basketbolu', {
size: 60,
fill: 0xFFFFFF
});
subtitleText.anchor.set(0.5, 0.5);
subtitleText.x = 1024;
subtitleText.y = 720;
self.addChild(subtitleText);
var descriptionText = new Text2('İlk 20 elementin elektron dizilimini öğren!\nElektron toplarını çekirdeğe at ve katmanları doldur.', {
size: 45,
fill: 0xBDC3C7
});
descriptionText.anchor.set(0.5, 0.5);
descriptionText.x = 1024;
descriptionText.y = 900;
self.addChild(descriptionText);
var playButton = LK.getAsset({
width: 400,
height: 100,
color: 0x4A90E2,
shape: 'box'
}, {
anchorX: 0.5,
anchorY: 0.5
});
playButton.x = 1024;
playButton.y = 1200;
self.addChild(playButton);
var playText = new Text2('OYNA', {
size: 60,
fill: 0xFFFFFF
});
playText.anchor.set(0.5, 0.5);
playText.x = 1024;
playText.y = 1200;
self.addChild(playText);
var instructionText = new Text2('Başlamak için OYNA butonuna dokunun', {
size: 40,
fill: 0x95A5A6
});
instructionText.anchor.set(0.5, 1);
instructionText.x = 1024;
instructionText.y = 2600;
self.addChild(instructionText);
// Make play button interactive
playButton.down = function (x, y, obj) {
startGame();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0f1419
});
/****
* Game Code
****/
// Element data for first 20 elements (Turkish)
var elementData = [{
name: 'Hidrojen',
atomicNumber: 1,
electrons: 1,
configuration: '1s¹',
fact: 'Evrendeki en bol element'
}, {
name: 'Helyum',
atomicNumber: 2,
electrons: 2,
configuration: '1s²',
fact: 'İkinci en hafif element, balonlarda kullanılır'
}, {
name: 'Lityum',
atomicNumber: 3,
electrons: 3,
configuration: '1s² 2s¹',
fact: 'En hafif metal, pillerde kullanılır'
}, {
name: 'Berilyum',
atomicNumber: 4,
electrons: 4,
configuration: '1s² 2s²',
fact: 'Havacılık uygulamalarında kullanılır'
}, {
name: 'Bor',
atomicNumber: 5,
electrons: 5,
configuration: '1s² 2s² 2p¹',
fact: 'Bitki gelişimi için gerekli'
}, {
name: 'Karbon',
atomicNumber: 6,
electrons: 6,
configuration: '1s² 2s² 2p²',
fact: 'Tüm organik bileşiklerin temeli'
}, {
name: 'Azot',
atomicNumber: 7,
electrons: 7,
configuration: '1s² 2s² 2p³',
fact: 'Dünya atmosferinin %78\'i'
}, {
name: 'Oksijen',
atomicNumber: 8,
electrons: 8,
configuration: '1s² 2s² 2p⁴',
fact: 'Nefes almak için gerekli'
}, {
name: 'Flor',
atomicNumber: 9,
electrons: 9,
configuration: '1s² 2s² 2p⁵',
fact: 'En reaktif element'
}, {
name: 'Neon',
atomicNumber: 10,
electrons: 10,
configuration: '1s² 2s² 2p⁶',
fact: 'Renkli tabelalar için kullanılır'
}, {
name: 'Sodyum',
atomicNumber: 11,
electrons: 11,
configuration: '1s² 2s² 2p⁶ 3s¹',
fact: 'Gerekli elektrolit'
}, {
name: 'Magnezyum',
atomicNumber: 12,
electrons: 12,
configuration: '1s² 2s² 2p⁶ 3s²',
fact: 'Kemikler için önemli'
}, {
name: 'Alüminyum',
atomicNumber: 13,
electrons: 13,
configuration: '1s² 2s² 2p⁶ 3s² 3p¹',
fact: 'Hafif metal'
}, {
name: 'Silisyum',
atomicNumber: 14,
electrons: 14,
configuration: '1s² 2s² 2p⁶ 3s² 3p²',
fact: 'Bilgisayar çipi malzemesi'
}, {
name: 'Fosfor',
atomicNumber: 15,
electrons: 15,
configuration: '1s² 2s² 2p⁶ 3s² 3p³',
fact: 'DNA için gerekli'
}, {
name: 'Kükürt',
atomicNumber: 16,
electrons: 16,
configuration: '1s² 2s² 2p⁶ 3s² 3p⁴',
fact: 'Sarı kristal element'
}, {
name: 'Klor',
atomicNumber: 17,
electrons: 17,
configuration: '1s² 2s² 2p⁶ 3s² 3p⁵',
fact: 'Suyu dezenfekte etmek için kullanılır'
}, {
name: 'Argon',
atomicNumber: 18,
electrons: 18,
configuration: '1s² 2s² 2p⁶ 3s² 3p⁶',
fact: 'Asil gaz, kimyasal olarak inert'
}, {
name: 'Potasyum',
atomicNumber: 19,
electrons: 19,
configuration: '1s² 2s² 2p⁶ 3s² 3p⁶ 4s¹',
fact: 'Sinir işlevi için önemli'
}, {
name: 'Kalsiyum',
atomicNumber: 20,
electrons: 20,
configuration: '1s² 2s² 2p⁶ 3s² 3p⁶ 4s²',
fact: 'Güçlü kemikler için gerekli'
}];
// Game state variables
var gameStarted = false;
var currentLevel = 0;
var mainMenu;
var atom;
var infoPanel;
var electronBalls = [];
var trajectoryDots = [];
var shooting = false;
var startX = 0;
var startY = 0;
var showingInfo = false;
// UI Elements
var levelText;
var scoreText;
var progressText;
var instructionText;
// Initialize main menu
mainMenu = game.addChild(new MainMenu());
function startGame() {
gameStarted = true;
mainMenu.destroy();
// Initialize game objects
atom = game.addChild(new Atom());
atom.x = 1024;
atom.y = 600;
infoPanel = game.addChild(new InfoPanel());
infoPanel.x = 1024;
infoPanel.y = 1366;
// Initialize UI
levelText = new Text2('Seviye 1: Hidrojen', {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
scoreText = new Text2('Puan: 0', {
size: 50,
fill: 0xFFFFFF
});
scoreText.anchor.set(1, 0);
scoreText.x = -50;
scoreText.y = 20;
LK.gui.topRight.addChild(scoreText);
progressText = new Text2('Elektronlar: 0/1', {
size: 45,
fill: 0x4A90E2
});
progressText.anchor.set(0.5, 0);
progressText.y = 80;
LK.gui.top.addChild(progressText);
instructionText = new Text2('Elektronları atmak için sürükle ve bırak', {
size: 40,
fill: 0x95A5A6
});
instructionText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionText);
updateUI();
}
function updateUI() {
if (!gameStarted) {
return;
}
var currentElement = elementData[currentLevel];
levelText.setText('Seviye ' + (currentLevel + 1) + ': ' + currentElement.name);
scoreText.setText('Puan: ' + LK.getScore());
progressText.setText('Elektronlar: ' + atom.getTotalElectrons() + '/' + currentElement.electrons);
}
function createTrajectoryPreview(startX, startY, endX, endY) {
// Clear existing dots
for (var i = 0; i < trajectoryDots.length; i++) {
trajectoryDots[i].destroy();
}
trajectoryDots = [];
var velocityX = (endX - startX) * 0.02;
var velocityY = (endY - startY) * 0.02;
var x = startX;
var y = startY;
var vX = velocityX;
var vY = velocityY;
for (var i = 0; i < 20; i++) {
vY += 0.5; // gravity
x += vX;
y += vY;
var dot = LK.getAsset('trajectoryDot', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 1 - i * 0.05
});
dot.x = x;
dot.y = y;
game.addChild(dot);
trajectoryDots.push(dot);
if (y > 2732) {
break;
}
}
}
function clearTrajectory() {
for (var i = 0; i < trajectoryDots.length; i++) {
trajectoryDots[i].destroy();
}
trajectoryDots = [];
}
function shootElectron(startX, startY, endX, endY) {
var electron = new ElectronBall();
electron.x = startX;
electron.y = startY;
electron.velocityX = (endX - startX) * 0.02;
electron.velocityY = (endY - startY) * 0.02;
electronBalls.push(electron);
game.addChild(electron);
LK.getSound('shoot').play();
}
function checkElectronHit(electron) {
var dx = electron.x - atom.x;
var dy = electron.y - atom.y;
var distance = Math.sqrt(dx * dx + dy * dy);
return distance < 80; // Hit radius
}
function completeLevel() {
LK.setScore(LK.getScore() + 500);
LK.getSound('complete').play();
// Show element info
infoPanel.showElement(elementData[currentLevel]);
showingInfo = true;
// Flash effect
LK.effects.flashScreen(0x4a90e2, 1000);
}
function nextLevel() {
currentLevel++;
if (currentLevel >= elementData.length) {
LK.showYouWin();
return;
}
atom.reset();
updateUI();
showingInfo = false;
infoPanel.hide();
}
game.down = function (x, y, obj) {
if (!gameStarted) {
return;
}
if (showingInfo) {
nextLevel();
return;
}
shooting = true;
startX = x;
startY = y;
};
game.move = function (x, y, obj) {
if (!gameStarted) {
return;
}
if (shooting && !showingInfo) {
createTrajectoryPreview(startX, startY, x, y);
}
};
game.up = function (x, y, obj) {
if (!gameStarted) {
return;
}
if (shooting && !showingInfo) {
shootElectron(startX, startY, x, y);
clearTrajectory();
shooting = false;
}
};
game.update = function () {
if (!gameStarted) {
return;
}
// Update electrons
for (var i = electronBalls.length - 1; i >= 0; i--) {
var electron = electronBalls[i];
if (!electron.active) {
electron.destroy();
electronBalls.splice(i, 1);
LK.setScore(Math.max(0, LK.getScore() - 50));
updateUI();
continue;
}
// Check for hits
if (checkElectronHit(electron)) {
if (atom.addElectron()) {
LK.setScore(LK.getScore() + 100);
LK.getSound('hit').play();
// Animate electron to orbital position instead of destroying
electron.active = false; // Stop physics updates
var targetShell = -1;
var electronIndex = 0;
// Find which shell this electron belongs to
var totalElectrons = atom.getTotalElectrons();
if (totalElectrons <= 2) {
targetShell = 0; // K shell
electronIndex = totalElectrons - 1;
} else if (totalElectrons <= 10) {
targetShell = 1; // L shell
electronIndex = totalElectrons - 3;
} else if (totalElectrons <= 18) {
targetShell = 2; // M shell
electronIndex = totalElectrons - 11;
} else {
targetShell = 3; // N shell
electronIndex = totalElectrons - 19;
}
// Calculate orbital position
var shellRadius = [120, 180, 240, 300][targetShell];
var angle = electronIndex / atom.shellCapacities[targetShell] * Math.PI * 2;
var targetX = atom.x + Math.cos(angle) * shellRadius;
var targetY = atom.y + Math.sin(angle) * shellRadius;
// Animate to orbital position
tween(electron, {
x: targetX,
y: targetY,
scaleX: 0.7,
scaleY: 0.7
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Start orbital animation
var orbitSpeed = 0.02;
electron.orbitAngle = angle;
electron.orbitRadius = shellRadius;
electron.isOrbiting = true;
}
});
// Check if level complete
if (atom.getTotalElectrons() === elementData[currentLevel].electrons) {
completeLevel();
}
}
electronBalls.splice(i, 1);
updateUI();
}
}
// Update orbiting electrons
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child.isOrbiting) {
child.orbitAngle += 0.02;
child.x = atom.x + Math.cos(child.orbitAngle) * child.orbitRadius;
child.y = atom.y + Math.sin(child.orbitAngle) * child.orbitRadius;
}
}
};