/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var AnswerButton = Container.expand(function (graphDisplay, index) {
var self = Container.call(this);
var buttonBg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.graphDisplay = graphDisplay;
self.index = index;
self.isSelected = false;
self.showingResult = false;
// Add graph to button
graphDisplay.scaleX = 0.6;
graphDisplay.scaleY = 0.6;
self.addChild(graphDisplay);
self.select = function () {
if (self.showingResult) return;
self.isSelected = true;
buttonBg.removeChild();
self.attachAsset('buttonSelected', {
anchorX: 0.5,
anchorY: 0.5
});
};
self.deselect = function () {
if (self.showingResult) return;
self.isSelected = false;
buttonBg.removeChild();
buttonBg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
};
self.showCorrect = function () {
self.showingResult = true;
buttonBg.removeChild();
self.attachAsset('buttonCorrect', {
anchorX: 0.5,
anchorY: 0.5
});
};
self.showWrong = function () {
self.showingResult = true;
buttonBg.removeChild();
self.attachAsset('buttonWrong', {
anchorX: 0.5,
anchorY: 0.5
});
};
self.down = function (x, y, obj) {
if (self.showingResult) return;
if (selectedButton && selectedButton !== self) {
selectedButton.deselect();
}
self.select();
selectedButton = self;
};
return self;
});
var GraphDisplay = Container.expand(function (equation, isCorrect) {
var self = Container.call(this);
// Create border first (behind background)
var border = self.attachAsset('graphBorder', {
anchorX: 0.5,
anchorY: 0.5
});
// Create background
var background = self.attachAsset('graphBackground', {
anchorX: 0.5,
anchorY: 0.5
});
self.feedbackBorder = null;
// Create grid lines (improved spacing for larger graph)
for (var i = 0; i < 9; i++) {
var gridLineH = self.attachAsset('gridLine', {
anchorX: 0.5,
anchorY: 0.5,
y: -180 + i * 45
});
var gridLineV = self.attachAsset('gridLineVertical', {
anchorX: 0.5,
anchorY: 0.5,
x: -225 + i * 56.25
});
}
// Create axes
var xAxis = self.attachAsset('axis', {
anchorX: 0.5,
anchorY: 0.5,
y: 0
});
var yAxis = self.attachAsset('axisVertical', {
anchorX: 0.5,
anchorY: 0.5,
x: 0
});
// Draw parabola points (improved for larger graph with more continuous curve)
self.drawParabola = function (a, h, k) {
for (var x = -4; x <= 4; x += 0.05) {
var y = a * (x - h) * (x - h) + k;
if (y >= -3 && y <= 3) {
var point = self.attachAsset('parabolaPoint', {
anchorX: 0.5,
anchorY: 0.5,
x: x * 56.25,
y: -y * 45
});
}
}
// Add vertex marker to highlight the vertex point
if (k >= -3 && k <= 3) {
var vertex = self.attachAsset('vertexMarker', {
anchorX: 0.5,
anchorY: 0.5,
x: h * 56.25,
y: -k * 45
});
}
};
self.showGreenBorder = function () {
if (self.feedbackBorder) {
self.feedbackBorder.destroy();
}
self.feedbackBorder = self.attachAsset('greenBorder', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Move border to back
self.setChildIndex(self.feedbackBorder, 0);
// Make border frame style - set alpha to create border effect
self.feedbackBorder.alpha = 0.8;
// Animate border appearance
tween(self.feedbackBorder, {
alpha: 0.8
}, {
duration: 300,
easing: tween.easeOut
});
};
self.showRedBorder = function () {
if (self.feedbackBorder) {
self.feedbackBorder.destroy();
}
self.feedbackBorder = self.attachAsset('redBorder', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Move border to back
self.setChildIndex(self.feedbackBorder, 0);
// Make border frame style - set alpha to create border effect
self.feedbackBorder.alpha = 0.8;
// Animate border appearance
tween(self.feedbackBorder, {
alpha: 0.8
}, {
duration: 300,
easing: tween.easeOut
});
};
self.equation = equation;
self.isCorrect = isCorrect;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xF5F5F5
});
/****
* Game Code
****/
// Game state variables
var currentLevel = 1;
var totalLevels = 10;
var correctAnswers = 0;
var selectedButton = null;
var answerButtons = [];
var questionText = null;
var levelText = null;
var submitButton = null;
var feedbackText = null;
var nextButton = null;
var isShowingFeedback = false;
// Question data - randomized each game with more variety
var allQuestions = [
// Level 1-3: Simple standard parabolas
[{
equation: "f(x) = x²",
a: 1,
h: 0,
k: 0,
explanation: "Die Standardparabel öffnet sich nach oben mit Scheitelpunkt im Ursprung."
}, {
equation: "f(x) = x² - 1",
a: 1,
h: 0,
k: -1,
explanation: "Die Parabel ist um 1 Einheit nach unten verschoben."
}, {
equation: "f(x) = x² + 3",
a: 1,
h: 0,
k: 3,
explanation: "Die Parabel ist um 3 Einheiten nach oben verschoben."
}, {
equation: "f(x) = x² - 3",
a: 1,
h: 0,
k: -3,
explanation: "Die Parabel ist um 3 Einheiten nach unten verschoben."
}], [{
equation: "f(x) = x² + 2",
a: 1,
h: 0,
k: 2,
explanation: "Die Parabel ist um 2 Einheiten nach oben verschoben."
}, {
equation: "f(x) = x² - 2",
a: 1,
h: 0,
k: -2,
explanation: "Die Parabel ist um 2 Einheiten nach unten verschoben."
}, {
equation: "f(x) = x² + 1",
a: 1,
h: 0,
k: 1,
explanation: "Die Parabel ist um 1 Einheit nach oben verschoben."
}, {
equation: "f(x) = x² + 4",
a: 1,
h: 0,
k: 4,
explanation: "Die Parabel ist um 4 Einheiten nach oben verschoben."
}], [{
equation: "f(x) = (x-2)²",
a: 1,
h: 2,
k: 0,
explanation: "Die Parabel ist um 2 Einheiten nach rechts verschoben."
}, {
equation: "f(x) = (x+2)²",
a: 1,
h: -2,
k: 0,
explanation: "Die Parabel ist um 2 Einheiten nach links verschoben."
}, {
equation: "f(x) = (x-1)²",
a: 1,
h: 1,
k: 0,
explanation: "Die Parabel ist um 1 Einheit nach rechts verschoben."
}, {
equation: "f(x) = (x+3)²",
a: 1,
h: -3,
k: 0,
explanation: "Die Parabel ist um 3 Einheiten nach links verschoben."
}, {
equation: "f(x) = (x-3)²",
a: 1,
h: 3,
k: 0,
explanation: "Die Parabel ist um 3 Einheiten nach rechts verschoben."
}],
// Level 4-6: Shifted or reflected parabolas (expanded variety)
[{
equation: "f(x) = -x²",
a: -1,
h: 0,
k: 0,
explanation: "Die Parabel ist nach unten geöffnet (gespiegelt)."
}, {
equation: "f(x) = -x² + 1",
a: -1,
h: 0,
k: 1,
explanation: "Die Parabel ist gespiegelt und um 1 nach oben verschoben."
}, {
equation: "f(x) = -x² - 1",
a: -1,
h: 0,
k: -1,
explanation: "Die Parabel ist gespiegelt und um 1 nach unten verschoben."
}, {
equation: "f(x) = -x² + 2",
a: -1,
h: 0,
k: 2,
explanation: "Die Parabel ist gespiegelt und um 2 nach oben verschoben."
}, {
equation: "f(x) = -x² - 2",
a: -1,
h: 0,
k: -2,
explanation: "Die Parabel ist gespiegelt und um 2 nach unten verschoben."
}], [{
equation: "f(x) = (x+1)² - 3",
a: 1,
h: -1,
k: -3,
explanation: "Die Parabel ist um 1 nach links und 3 nach unten verschoben."
}, {
equation: "f(x) = (x-1)² + 2",
a: 1,
h: 1,
k: 2,
explanation: "Die Parabel ist um 1 nach rechts und 2 nach oben verschoben."
}, {
equation: "f(x) = (x+2)² - 1",
a: 1,
h: -2,
k: -1,
explanation: "Die Parabel ist um 2 nach links und 1 nach unten verschoben."
}, {
equation: "f(x) = (x-3)² + 1",
a: 1,
h: 3,
k: 1,
explanation: "Die Parabel ist um 3 nach rechts und 1 nach oben verschoben."
}, {
equation: "f(x) = (x+3)² + 2",
a: 1,
h: -3,
k: 2,
explanation: "Die Parabel ist um 3 nach links und 2 nach oben verschoben."
}], [{
equation: "f(x) = -(x-1)² + 2",
a: -1,
h: 1,
k: 2,
explanation: "Die Parabel ist gespiegelt, um 1 nach rechts und 2 nach oben verschoben."
}, {
equation: "f(x) = -(x+1)² - 1",
a: -1,
h: -1,
k: -1,
explanation: "Die Parabel ist gespiegelt, um 1 nach links und 1 nach unten verschoben."
}, {
equation: "f(x) = -(x-2)² + 1",
a: -1,
h: 2,
k: 1,
explanation: "Die Parabel ist gespiegelt, um 2 nach rechts und 1 nach oben verschoben."
}, {
equation: "f(x) = -(x+2)² + 3",
a: -1,
h: -2,
k: 3,
explanation: "Die Parabel ist gespiegelt, um 2 nach links und 3 nach oben verschoben."
}, {
equation: "f(x) = -(x-3)² - 1",
a: -1,
h: 3,
k: -1,
explanation: "Die Parabel ist gespiegelt, um 3 nach rechts und 1 nach unten verschoben."
}],
// Level 7-9: Parabolas with different stretch factors (expanded variety)
[{
equation: "f(x) = 2x²",
a: 2,
h: 0,
k: 0,
explanation: "Die Parabel ist um den Faktor 2 gestreckt (schmaler)."
}, {
equation: "f(x) = 3x²",
a: 3,
h: 0,
k: 0,
explanation: "Die Parabel ist um den Faktor 3 gestreckt (sehr schmal)."
}, {
equation: "f(x) = 0.5x²",
a: 0.5,
h: 0,
k: 0,
explanation: "Die Parabel ist um den Faktor 0.5 gestaucht (breiter)."
}, {
equation: "f(x) = 4x²",
a: 4,
h: 0,
k: 0,
explanation: "Die Parabel ist um den Faktor 4 stark gestreckt (sehr schmal)."
}, {
equation: "f(x) = 0.25x²",
a: 0.25,
h: 0,
k: 0,
explanation: "Die Parabel ist um den Faktor 0.25 stark gestaucht (sehr breit)."
}], [{
equation: "f(x) = -0.5x²",
a: -0.5,
h: 0,
k: 0,
explanation: "Die Parabel ist gespiegelt und um den Faktor 0.5 gestaucht (breiter)."
}, {
equation: "f(x) = -2x²",
a: -2,
h: 0,
k: 0,
explanation: "Die Parabel ist gespiegelt und um den Faktor 2 gestreckt (schmaler)."
}, {
equation: "f(x) = -1.5x²",
a: -1.5,
h: 0,
k: 0,
explanation: "Die Parabel ist gespiegelt und um den Faktor 1.5 gestreckt."
}, {
equation: "f(x) = -3x²",
a: -3,
h: 0,
k: 0,
explanation: "Die Parabel ist gespiegelt und um den Faktor 3 gestreckt (sehr schmal)."
}, {
equation: "f(x) = -0.25x²",
a: -0.25,
h: 0,
k: 0,
explanation: "Die Parabel ist gespiegelt und um den Faktor 0.25 gestaucht (sehr breit)."
}], [{
equation: "f(x) = 0.5(x-1)² + 1",
a: 0.5,
h: 1,
k: 1,
explanation: "Die Parabel ist gestaucht, um 1 nach rechts und 1 nach oben verschoben."
}, {
equation: "f(x) = 2(x+1)² - 1",
a: 2,
h: -1,
k: -1,
explanation: "Die Parabel ist gestreckt, um 1 nach links und 1 nach unten verschoben."
}, {
equation: "f(x) = 1.5(x-2)² + 2",
a: 1.5,
h: 2,
k: 2,
explanation: "Die Parabel ist leicht gestreckt, um 2 nach rechts und 2 nach oben verschoben."
}, {
equation: "f(x) = 3(x+2)² - 2",
a: 3,
h: -2,
k: -2,
explanation: "Die Parabel ist stark gestreckt, um 2 nach links und 2 nach unten verschoben."
}, {
equation: "f(x) = 0.25(x-3)² + 1",
a: 0.25,
h: 3,
k: 1,
explanation: "Die Parabel ist stark gestaucht, um 3 nach rechts und 1 nach oben verschoben."
}],
// Level 10: Mixed challenge (expanded variety)
[{
equation: "f(x) = -2(x+2)² - 1",
a: -2,
h: -2,
k: -1,
explanation: "Die Parabel ist gespiegelt, um den Faktor 2 gestreckt und verschoben."
}, {
equation: "f(x) = -0.5(x-3)² + 2",
a: -0.5,
h: 3,
k: 2,
explanation: "Die Parabel ist gespiegelt, gestaucht und verschoben."
}, {
equation: "f(x) = 3(x+1)² - 2",
a: 3,
h: -1,
k: -2,
explanation: "Die Parabel ist stark gestreckt und verschoben."
}, {
equation: "f(x) = -4(x-1)² + 3",
a: -4,
h: 1,
k: 3,
explanation: "Die Parabel ist gespiegelt, stark gestreckt, um 1 nach rechts und 3 nach oben verschoben."
}, {
equation: "f(x) = 0.25(x+3)² - 3",
a: 0.25,
h: -3,
k: -3,
explanation: "Die Parabel ist stark gestaucht, um 3 nach links und 3 nach unten verschoben."
}, {
equation: "f(x) = -1.5(x+2)² + 2",
a: -1.5,
h: -2,
k: 2,
explanation: "Die Parabel ist gespiegelt, gestreckt, um 2 nach links und 2 nach oben verschoben."
}]];
// Select random questions for this game session
var questions = [];
for (var i = 0; i < allQuestions.length; i++) {
var randomIndex = Math.floor(Math.random() * allQuestions[i].length);
questions.push(allQuestions[i][randomIndex]);
}
// UI Setup
function setupUI() {
// Level indicator
levelText = new Text2('Level ' + currentLevel + '/' + totalLevels, {
size: 50,
fill: 0x333333
});
levelText.anchor.set(0.5, 0);
levelText.x = 1024;
levelText.y = 80;
game.addChild(levelText);
// Question text
questionText = new Text2('', {
size: 60,
fill: 0x333333
});
questionText.anchor.set(0.5, 0.5);
questionText.x = 1024;
questionText.y = 200;
game.addChild(questionText);
// Submit button
submitButton = new Container();
var submitBg = submitButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
var submitText = new Text2('Antwort bestätigen', {
size: 40,
fill: 0xFFFFFF
});
submitText.anchor.set(0.5, 0.5);
submitButton.addChild(submitText);
submitButton.x = 1024;
submitButton.y = 2200;
submitButton.down = function () {
if (selectedButton && !isShowingFeedback) {
checkAnswer();
}
};
game.addChild(submitButton);
// Feedback text
feedbackText = new Text2('', {
size: 35,
fill: 0x333333
});
feedbackText.anchor.set(0.5, 0.5);
feedbackText.x = 1024;
feedbackText.y = 2350;
feedbackText.visible = false;
game.addChild(feedbackText);
// Next button
nextButton = new Container();
var nextBg = nextButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
var nextText = new Text2('Weiter', {
size: 40,
fill: 0xFFFFFF
});
nextText.anchor.set(0.5, 0.5);
nextButton.addChild(nextText);
nextButton.x = 1024;
nextButton.y = 2450;
nextButton.visible = false;
nextButton.down = function () {
if (isShowingFeedback) {
nextLevel();
}
};
game.addChild(nextButton);
}
function generateWrongGraphs(correctA, correctH, correctK) {
var wrongGraphs = [];
// Generate first wrong graph - different 'a' value
var wrongA1 = correctA === 1 ? -1 : correctA === -1 ? 1 : correctA * -1;
wrongGraphs.push({
a: wrongA1,
h: correctH,
k: correctK
});
// Generate second wrong graph - different position
var wrongH = correctH === 0 ? 1 : 0;
var wrongK = correctK === 0 ? -1 : 0;
wrongGraphs.push({
a: correctA,
h: wrongH,
k: wrongK
});
return wrongGraphs;
}
function setupLevel() {
// Clear previous level
for (var i = 0; i < answerButtons.length; i++) {
answerButtons[i].destroy();
}
answerButtons = [];
selectedButton = null;
isShowingFeedback = false;
// Update UI
levelText.setText('Level ' + currentLevel + '/' + totalLevels);
var currentQuestion = questions[currentLevel - 1];
questionText.setText(currentQuestion.equation);
feedbackText.visible = false;
nextButton.visible = false;
submitButton.visible = true;
// Create answer options
var correctGraph = new GraphDisplay(currentQuestion.equation, true);
correctGraph.drawParabola(currentQuestion.a, currentQuestion.h, currentQuestion.k);
var wrongGraphs = generateWrongGraphs(currentQuestion.a, currentQuestion.h, currentQuestion.k);
var wrongGraph1 = new GraphDisplay('', false);
wrongGraph1.drawParabola(wrongGraphs[0].a, wrongGraphs[0].h, wrongGraphs[0].k);
var wrongGraph2 = new GraphDisplay('', false);
wrongGraph2.drawParabola(wrongGraphs[1].a, wrongGraphs[1].h, wrongGraphs[1].k);
// Randomize positions
var graphs = [correctGraph, wrongGraph1, wrongGraph2];
var shuffledGraphs = [];
while (graphs.length > 0) {
var randomIndex = Math.floor(Math.random() * graphs.length);
shuffledGraphs.push(graphs[randomIndex]);
graphs.splice(randomIndex, 1);
}
// Create buttons
for (var i = 0; i < 3; i++) {
var button = new AnswerButton(shuffledGraphs[i], i);
button.x = 1024;
button.y = 400 + i * 450;
answerButtons.push(button);
game.addChild(button);
}
}
function checkAnswer() {
if (!selectedButton) return;
isShowingFeedback = true;
var currentQuestion = questions[currentLevel - 1];
var isCorrect = selectedButton.graphDisplay.isCorrect;
// Show results on all buttons with enhanced visual feedback
for (var i = 0; i < answerButtons.length; i++) {
if (answerButtons[i].graphDisplay.isCorrect) {
answerButtons[i].showCorrect();
answerButtons[i].graphDisplay.showGreenBorder();
// Add subtle scale animation for correct answer
tween(answerButtons[i], {
scaleX: 1.05,
scaleY: 1.05
}, {
duration: 200,
easing: tween.easeOut
});
tween(answerButtons[i], {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
} else if (answerButtons[i] === selectedButton && !isCorrect) {
answerButtons[i].showWrong();
answerButtons[i].graphDisplay.showRedBorder();
// Add shake animation for wrong answer
var originalX = answerButtons[i].x;
tween(answerButtons[i], {
x: originalX - 10
}, {
duration: 50,
easing: tween.easeOut
});
tween(answerButtons[i], {
x: originalX + 10
}, {
duration: 50,
easing: tween.easeOut
});
tween(answerButtons[i], {
x: originalX
}, {
duration: 50,
easing: tween.easeOut
});
}
}
if (isCorrect) {
correctAnswers++;
feedbackText.setText('Richtig! Gut gemacht!');
feedbackText.tint = 0x4CAF50;
LK.getSound('correct').play();
LK.setScore(LK.getScore() + 10);
} else {
feedbackText.setText('Falsch. ' + currentQuestion.explanation);
feedbackText.tint = 0xF44336;
LK.getSound('wrong').play();
}
feedbackText.visible = true;
submitButton.visible = false;
nextButton.visible = true;
}
function nextLevel() {
if (currentLevel >= totalLevels) {
showFinalScore();
return;
}
currentLevel++;
setupLevel();
}
function showFinalScore() {
var scoreText = '';
if (correctAnswers >= 9) {
scoreText = 'Quadratik-Profi!';
} else if (correctAnswers >= 6) {
scoreText = 'Auf gutem Weg!';
} else {
scoreText = 'Übung macht den Meister!';
}
var finalText = new Text2(scoreText + '\n' + correctAnswers + '/' + totalLevels + ' richtig', {
size: 60,
fill: 0x333333
});
finalText.anchor.set(0.5, 0.5);
finalText.x = 1024;
finalText.y = 1200;
game.addChild(finalText);
// Set final score
LK.setScore(correctAnswers * 10);
// Auto show game over after 3 seconds
LK.setTimeout(function () {
if (correctAnswers >= 9) {
LK.showYouWin();
} else {
LK.showGameOver();
}
}, 3000);
}
// Initialize game
setupUI();
setupLevel(); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var AnswerButton = Container.expand(function (graphDisplay, index) {
var self = Container.call(this);
var buttonBg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.graphDisplay = graphDisplay;
self.index = index;
self.isSelected = false;
self.showingResult = false;
// Add graph to button
graphDisplay.scaleX = 0.6;
graphDisplay.scaleY = 0.6;
self.addChild(graphDisplay);
self.select = function () {
if (self.showingResult) return;
self.isSelected = true;
buttonBg.removeChild();
self.attachAsset('buttonSelected', {
anchorX: 0.5,
anchorY: 0.5
});
};
self.deselect = function () {
if (self.showingResult) return;
self.isSelected = false;
buttonBg.removeChild();
buttonBg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
};
self.showCorrect = function () {
self.showingResult = true;
buttonBg.removeChild();
self.attachAsset('buttonCorrect', {
anchorX: 0.5,
anchorY: 0.5
});
};
self.showWrong = function () {
self.showingResult = true;
buttonBg.removeChild();
self.attachAsset('buttonWrong', {
anchorX: 0.5,
anchorY: 0.5
});
};
self.down = function (x, y, obj) {
if (self.showingResult) return;
if (selectedButton && selectedButton !== self) {
selectedButton.deselect();
}
self.select();
selectedButton = self;
};
return self;
});
var GraphDisplay = Container.expand(function (equation, isCorrect) {
var self = Container.call(this);
// Create border first (behind background)
var border = self.attachAsset('graphBorder', {
anchorX: 0.5,
anchorY: 0.5
});
// Create background
var background = self.attachAsset('graphBackground', {
anchorX: 0.5,
anchorY: 0.5
});
self.feedbackBorder = null;
// Create grid lines (improved spacing for larger graph)
for (var i = 0; i < 9; i++) {
var gridLineH = self.attachAsset('gridLine', {
anchorX: 0.5,
anchorY: 0.5,
y: -180 + i * 45
});
var gridLineV = self.attachAsset('gridLineVertical', {
anchorX: 0.5,
anchorY: 0.5,
x: -225 + i * 56.25
});
}
// Create axes
var xAxis = self.attachAsset('axis', {
anchorX: 0.5,
anchorY: 0.5,
y: 0
});
var yAxis = self.attachAsset('axisVertical', {
anchorX: 0.5,
anchorY: 0.5,
x: 0
});
// Draw parabola points (improved for larger graph with more continuous curve)
self.drawParabola = function (a, h, k) {
for (var x = -4; x <= 4; x += 0.05) {
var y = a * (x - h) * (x - h) + k;
if (y >= -3 && y <= 3) {
var point = self.attachAsset('parabolaPoint', {
anchorX: 0.5,
anchorY: 0.5,
x: x * 56.25,
y: -y * 45
});
}
}
// Add vertex marker to highlight the vertex point
if (k >= -3 && k <= 3) {
var vertex = self.attachAsset('vertexMarker', {
anchorX: 0.5,
anchorY: 0.5,
x: h * 56.25,
y: -k * 45
});
}
};
self.showGreenBorder = function () {
if (self.feedbackBorder) {
self.feedbackBorder.destroy();
}
self.feedbackBorder = self.attachAsset('greenBorder', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Move border to back
self.setChildIndex(self.feedbackBorder, 0);
// Make border frame style - set alpha to create border effect
self.feedbackBorder.alpha = 0.8;
// Animate border appearance
tween(self.feedbackBorder, {
alpha: 0.8
}, {
duration: 300,
easing: tween.easeOut
});
};
self.showRedBorder = function () {
if (self.feedbackBorder) {
self.feedbackBorder.destroy();
}
self.feedbackBorder = self.attachAsset('redBorder', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Move border to back
self.setChildIndex(self.feedbackBorder, 0);
// Make border frame style - set alpha to create border effect
self.feedbackBorder.alpha = 0.8;
// Animate border appearance
tween(self.feedbackBorder, {
alpha: 0.8
}, {
duration: 300,
easing: tween.easeOut
});
};
self.equation = equation;
self.isCorrect = isCorrect;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xF5F5F5
});
/****
* Game Code
****/
// Game state variables
var currentLevel = 1;
var totalLevels = 10;
var correctAnswers = 0;
var selectedButton = null;
var answerButtons = [];
var questionText = null;
var levelText = null;
var submitButton = null;
var feedbackText = null;
var nextButton = null;
var isShowingFeedback = false;
// Question data - randomized each game with more variety
var allQuestions = [
// Level 1-3: Simple standard parabolas
[{
equation: "f(x) = x²",
a: 1,
h: 0,
k: 0,
explanation: "Die Standardparabel öffnet sich nach oben mit Scheitelpunkt im Ursprung."
}, {
equation: "f(x) = x² - 1",
a: 1,
h: 0,
k: -1,
explanation: "Die Parabel ist um 1 Einheit nach unten verschoben."
}, {
equation: "f(x) = x² + 3",
a: 1,
h: 0,
k: 3,
explanation: "Die Parabel ist um 3 Einheiten nach oben verschoben."
}, {
equation: "f(x) = x² - 3",
a: 1,
h: 0,
k: -3,
explanation: "Die Parabel ist um 3 Einheiten nach unten verschoben."
}], [{
equation: "f(x) = x² + 2",
a: 1,
h: 0,
k: 2,
explanation: "Die Parabel ist um 2 Einheiten nach oben verschoben."
}, {
equation: "f(x) = x² - 2",
a: 1,
h: 0,
k: -2,
explanation: "Die Parabel ist um 2 Einheiten nach unten verschoben."
}, {
equation: "f(x) = x² + 1",
a: 1,
h: 0,
k: 1,
explanation: "Die Parabel ist um 1 Einheit nach oben verschoben."
}, {
equation: "f(x) = x² + 4",
a: 1,
h: 0,
k: 4,
explanation: "Die Parabel ist um 4 Einheiten nach oben verschoben."
}], [{
equation: "f(x) = (x-2)²",
a: 1,
h: 2,
k: 0,
explanation: "Die Parabel ist um 2 Einheiten nach rechts verschoben."
}, {
equation: "f(x) = (x+2)²",
a: 1,
h: -2,
k: 0,
explanation: "Die Parabel ist um 2 Einheiten nach links verschoben."
}, {
equation: "f(x) = (x-1)²",
a: 1,
h: 1,
k: 0,
explanation: "Die Parabel ist um 1 Einheit nach rechts verschoben."
}, {
equation: "f(x) = (x+3)²",
a: 1,
h: -3,
k: 0,
explanation: "Die Parabel ist um 3 Einheiten nach links verschoben."
}, {
equation: "f(x) = (x-3)²",
a: 1,
h: 3,
k: 0,
explanation: "Die Parabel ist um 3 Einheiten nach rechts verschoben."
}],
// Level 4-6: Shifted or reflected parabolas (expanded variety)
[{
equation: "f(x) = -x²",
a: -1,
h: 0,
k: 0,
explanation: "Die Parabel ist nach unten geöffnet (gespiegelt)."
}, {
equation: "f(x) = -x² + 1",
a: -1,
h: 0,
k: 1,
explanation: "Die Parabel ist gespiegelt und um 1 nach oben verschoben."
}, {
equation: "f(x) = -x² - 1",
a: -1,
h: 0,
k: -1,
explanation: "Die Parabel ist gespiegelt und um 1 nach unten verschoben."
}, {
equation: "f(x) = -x² + 2",
a: -1,
h: 0,
k: 2,
explanation: "Die Parabel ist gespiegelt und um 2 nach oben verschoben."
}, {
equation: "f(x) = -x² - 2",
a: -1,
h: 0,
k: -2,
explanation: "Die Parabel ist gespiegelt und um 2 nach unten verschoben."
}], [{
equation: "f(x) = (x+1)² - 3",
a: 1,
h: -1,
k: -3,
explanation: "Die Parabel ist um 1 nach links und 3 nach unten verschoben."
}, {
equation: "f(x) = (x-1)² + 2",
a: 1,
h: 1,
k: 2,
explanation: "Die Parabel ist um 1 nach rechts und 2 nach oben verschoben."
}, {
equation: "f(x) = (x+2)² - 1",
a: 1,
h: -2,
k: -1,
explanation: "Die Parabel ist um 2 nach links und 1 nach unten verschoben."
}, {
equation: "f(x) = (x-3)² + 1",
a: 1,
h: 3,
k: 1,
explanation: "Die Parabel ist um 3 nach rechts und 1 nach oben verschoben."
}, {
equation: "f(x) = (x+3)² + 2",
a: 1,
h: -3,
k: 2,
explanation: "Die Parabel ist um 3 nach links und 2 nach oben verschoben."
}], [{
equation: "f(x) = -(x-1)² + 2",
a: -1,
h: 1,
k: 2,
explanation: "Die Parabel ist gespiegelt, um 1 nach rechts und 2 nach oben verschoben."
}, {
equation: "f(x) = -(x+1)² - 1",
a: -1,
h: -1,
k: -1,
explanation: "Die Parabel ist gespiegelt, um 1 nach links und 1 nach unten verschoben."
}, {
equation: "f(x) = -(x-2)² + 1",
a: -1,
h: 2,
k: 1,
explanation: "Die Parabel ist gespiegelt, um 2 nach rechts und 1 nach oben verschoben."
}, {
equation: "f(x) = -(x+2)² + 3",
a: -1,
h: -2,
k: 3,
explanation: "Die Parabel ist gespiegelt, um 2 nach links und 3 nach oben verschoben."
}, {
equation: "f(x) = -(x-3)² - 1",
a: -1,
h: 3,
k: -1,
explanation: "Die Parabel ist gespiegelt, um 3 nach rechts und 1 nach unten verschoben."
}],
// Level 7-9: Parabolas with different stretch factors (expanded variety)
[{
equation: "f(x) = 2x²",
a: 2,
h: 0,
k: 0,
explanation: "Die Parabel ist um den Faktor 2 gestreckt (schmaler)."
}, {
equation: "f(x) = 3x²",
a: 3,
h: 0,
k: 0,
explanation: "Die Parabel ist um den Faktor 3 gestreckt (sehr schmal)."
}, {
equation: "f(x) = 0.5x²",
a: 0.5,
h: 0,
k: 0,
explanation: "Die Parabel ist um den Faktor 0.5 gestaucht (breiter)."
}, {
equation: "f(x) = 4x²",
a: 4,
h: 0,
k: 0,
explanation: "Die Parabel ist um den Faktor 4 stark gestreckt (sehr schmal)."
}, {
equation: "f(x) = 0.25x²",
a: 0.25,
h: 0,
k: 0,
explanation: "Die Parabel ist um den Faktor 0.25 stark gestaucht (sehr breit)."
}], [{
equation: "f(x) = -0.5x²",
a: -0.5,
h: 0,
k: 0,
explanation: "Die Parabel ist gespiegelt und um den Faktor 0.5 gestaucht (breiter)."
}, {
equation: "f(x) = -2x²",
a: -2,
h: 0,
k: 0,
explanation: "Die Parabel ist gespiegelt und um den Faktor 2 gestreckt (schmaler)."
}, {
equation: "f(x) = -1.5x²",
a: -1.5,
h: 0,
k: 0,
explanation: "Die Parabel ist gespiegelt und um den Faktor 1.5 gestreckt."
}, {
equation: "f(x) = -3x²",
a: -3,
h: 0,
k: 0,
explanation: "Die Parabel ist gespiegelt und um den Faktor 3 gestreckt (sehr schmal)."
}, {
equation: "f(x) = -0.25x²",
a: -0.25,
h: 0,
k: 0,
explanation: "Die Parabel ist gespiegelt und um den Faktor 0.25 gestaucht (sehr breit)."
}], [{
equation: "f(x) = 0.5(x-1)² + 1",
a: 0.5,
h: 1,
k: 1,
explanation: "Die Parabel ist gestaucht, um 1 nach rechts und 1 nach oben verschoben."
}, {
equation: "f(x) = 2(x+1)² - 1",
a: 2,
h: -1,
k: -1,
explanation: "Die Parabel ist gestreckt, um 1 nach links und 1 nach unten verschoben."
}, {
equation: "f(x) = 1.5(x-2)² + 2",
a: 1.5,
h: 2,
k: 2,
explanation: "Die Parabel ist leicht gestreckt, um 2 nach rechts und 2 nach oben verschoben."
}, {
equation: "f(x) = 3(x+2)² - 2",
a: 3,
h: -2,
k: -2,
explanation: "Die Parabel ist stark gestreckt, um 2 nach links und 2 nach unten verschoben."
}, {
equation: "f(x) = 0.25(x-3)² + 1",
a: 0.25,
h: 3,
k: 1,
explanation: "Die Parabel ist stark gestaucht, um 3 nach rechts und 1 nach oben verschoben."
}],
// Level 10: Mixed challenge (expanded variety)
[{
equation: "f(x) = -2(x+2)² - 1",
a: -2,
h: -2,
k: -1,
explanation: "Die Parabel ist gespiegelt, um den Faktor 2 gestreckt und verschoben."
}, {
equation: "f(x) = -0.5(x-3)² + 2",
a: -0.5,
h: 3,
k: 2,
explanation: "Die Parabel ist gespiegelt, gestaucht und verschoben."
}, {
equation: "f(x) = 3(x+1)² - 2",
a: 3,
h: -1,
k: -2,
explanation: "Die Parabel ist stark gestreckt und verschoben."
}, {
equation: "f(x) = -4(x-1)² + 3",
a: -4,
h: 1,
k: 3,
explanation: "Die Parabel ist gespiegelt, stark gestreckt, um 1 nach rechts und 3 nach oben verschoben."
}, {
equation: "f(x) = 0.25(x+3)² - 3",
a: 0.25,
h: -3,
k: -3,
explanation: "Die Parabel ist stark gestaucht, um 3 nach links und 3 nach unten verschoben."
}, {
equation: "f(x) = -1.5(x+2)² + 2",
a: -1.5,
h: -2,
k: 2,
explanation: "Die Parabel ist gespiegelt, gestreckt, um 2 nach links und 2 nach oben verschoben."
}]];
// Select random questions for this game session
var questions = [];
for (var i = 0; i < allQuestions.length; i++) {
var randomIndex = Math.floor(Math.random() * allQuestions[i].length);
questions.push(allQuestions[i][randomIndex]);
}
// UI Setup
function setupUI() {
// Level indicator
levelText = new Text2('Level ' + currentLevel + '/' + totalLevels, {
size: 50,
fill: 0x333333
});
levelText.anchor.set(0.5, 0);
levelText.x = 1024;
levelText.y = 80;
game.addChild(levelText);
// Question text
questionText = new Text2('', {
size: 60,
fill: 0x333333
});
questionText.anchor.set(0.5, 0.5);
questionText.x = 1024;
questionText.y = 200;
game.addChild(questionText);
// Submit button
submitButton = new Container();
var submitBg = submitButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
var submitText = new Text2('Antwort bestätigen', {
size: 40,
fill: 0xFFFFFF
});
submitText.anchor.set(0.5, 0.5);
submitButton.addChild(submitText);
submitButton.x = 1024;
submitButton.y = 2200;
submitButton.down = function () {
if (selectedButton && !isShowingFeedback) {
checkAnswer();
}
};
game.addChild(submitButton);
// Feedback text
feedbackText = new Text2('', {
size: 35,
fill: 0x333333
});
feedbackText.anchor.set(0.5, 0.5);
feedbackText.x = 1024;
feedbackText.y = 2350;
feedbackText.visible = false;
game.addChild(feedbackText);
// Next button
nextButton = new Container();
var nextBg = nextButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
var nextText = new Text2('Weiter', {
size: 40,
fill: 0xFFFFFF
});
nextText.anchor.set(0.5, 0.5);
nextButton.addChild(nextText);
nextButton.x = 1024;
nextButton.y = 2450;
nextButton.visible = false;
nextButton.down = function () {
if (isShowingFeedback) {
nextLevel();
}
};
game.addChild(nextButton);
}
function generateWrongGraphs(correctA, correctH, correctK) {
var wrongGraphs = [];
// Generate first wrong graph - different 'a' value
var wrongA1 = correctA === 1 ? -1 : correctA === -1 ? 1 : correctA * -1;
wrongGraphs.push({
a: wrongA1,
h: correctH,
k: correctK
});
// Generate second wrong graph - different position
var wrongH = correctH === 0 ? 1 : 0;
var wrongK = correctK === 0 ? -1 : 0;
wrongGraphs.push({
a: correctA,
h: wrongH,
k: wrongK
});
return wrongGraphs;
}
function setupLevel() {
// Clear previous level
for (var i = 0; i < answerButtons.length; i++) {
answerButtons[i].destroy();
}
answerButtons = [];
selectedButton = null;
isShowingFeedback = false;
// Update UI
levelText.setText('Level ' + currentLevel + '/' + totalLevels);
var currentQuestion = questions[currentLevel - 1];
questionText.setText(currentQuestion.equation);
feedbackText.visible = false;
nextButton.visible = false;
submitButton.visible = true;
// Create answer options
var correctGraph = new GraphDisplay(currentQuestion.equation, true);
correctGraph.drawParabola(currentQuestion.a, currentQuestion.h, currentQuestion.k);
var wrongGraphs = generateWrongGraphs(currentQuestion.a, currentQuestion.h, currentQuestion.k);
var wrongGraph1 = new GraphDisplay('', false);
wrongGraph1.drawParabola(wrongGraphs[0].a, wrongGraphs[0].h, wrongGraphs[0].k);
var wrongGraph2 = new GraphDisplay('', false);
wrongGraph2.drawParabola(wrongGraphs[1].a, wrongGraphs[1].h, wrongGraphs[1].k);
// Randomize positions
var graphs = [correctGraph, wrongGraph1, wrongGraph2];
var shuffledGraphs = [];
while (graphs.length > 0) {
var randomIndex = Math.floor(Math.random() * graphs.length);
shuffledGraphs.push(graphs[randomIndex]);
graphs.splice(randomIndex, 1);
}
// Create buttons
for (var i = 0; i < 3; i++) {
var button = new AnswerButton(shuffledGraphs[i], i);
button.x = 1024;
button.y = 400 + i * 450;
answerButtons.push(button);
game.addChild(button);
}
}
function checkAnswer() {
if (!selectedButton) return;
isShowingFeedback = true;
var currentQuestion = questions[currentLevel - 1];
var isCorrect = selectedButton.graphDisplay.isCorrect;
// Show results on all buttons with enhanced visual feedback
for (var i = 0; i < answerButtons.length; i++) {
if (answerButtons[i].graphDisplay.isCorrect) {
answerButtons[i].showCorrect();
answerButtons[i].graphDisplay.showGreenBorder();
// Add subtle scale animation for correct answer
tween(answerButtons[i], {
scaleX: 1.05,
scaleY: 1.05
}, {
duration: 200,
easing: tween.easeOut
});
tween(answerButtons[i], {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
} else if (answerButtons[i] === selectedButton && !isCorrect) {
answerButtons[i].showWrong();
answerButtons[i].graphDisplay.showRedBorder();
// Add shake animation for wrong answer
var originalX = answerButtons[i].x;
tween(answerButtons[i], {
x: originalX - 10
}, {
duration: 50,
easing: tween.easeOut
});
tween(answerButtons[i], {
x: originalX + 10
}, {
duration: 50,
easing: tween.easeOut
});
tween(answerButtons[i], {
x: originalX
}, {
duration: 50,
easing: tween.easeOut
});
}
}
if (isCorrect) {
correctAnswers++;
feedbackText.setText('Richtig! Gut gemacht!');
feedbackText.tint = 0x4CAF50;
LK.getSound('correct').play();
LK.setScore(LK.getScore() + 10);
} else {
feedbackText.setText('Falsch. ' + currentQuestion.explanation);
feedbackText.tint = 0xF44336;
LK.getSound('wrong').play();
}
feedbackText.visible = true;
submitButton.visible = false;
nextButton.visible = true;
}
function nextLevel() {
if (currentLevel >= totalLevels) {
showFinalScore();
return;
}
currentLevel++;
setupLevel();
}
function showFinalScore() {
var scoreText = '';
if (correctAnswers >= 9) {
scoreText = 'Quadratik-Profi!';
} else if (correctAnswers >= 6) {
scoreText = 'Auf gutem Weg!';
} else {
scoreText = 'Übung macht den Meister!';
}
var finalText = new Text2(scoreText + '\n' + correctAnswers + '/' + totalLevels + ' richtig', {
size: 60,
fill: 0x333333
});
finalText.anchor.set(0.5, 0.5);
finalText.x = 1024;
finalText.y = 1200;
game.addChild(finalText);
// Set final score
LK.setScore(correctAnswers * 10);
// Auto show game over after 3 seconds
LK.setTimeout(function () {
if (correctAnswers >= 9) {
LK.showYouWin();
} else {
LK.showGameOver();
}
}, 3000);
}
// Initialize game
setupUI();
setupLevel();