User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'model')' in or related to this line: 'LK.init.model('clueModel', {' Line Number: 66
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'model')' in or related to this line: 'LK.init.model('clue', {' Line Number: 65
User prompt
Make it 3d and realistic
Initial prompt
Crokey
/****
* Classes
****/
// Class for clues
var Clue = Container.expand(function () {
var self = Container.call(this);
var clueGraphics = self.attachAsset('clueModel', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.collect = function () {
self.collected = true;
self.destroy();
};
});
// Class for the horror teacher
var HorrorTeacher = Container.expand(function () {
var self = Container.call(this);
var teacherGraphics = self.attachAsset('teacherModel', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
// Update logic for the horror teacher
};
});
//<Assets used in the game will automatically appear here>
// Class for the student character
var Student = Container.expand(function () {
var self = Container.call(this);
var studentGraphics = self.attachAsset('studentModel', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Update logic for the student
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
LK.init.model('clue', {
id: 'clueModel',
scale: 1.0
});
LK.init.model('student', {
id: 'studentModel',
scale: 1.0
});
LK.init.model('teacher', {
id: 'teacherModel',
scale: 1.0
});
var student;
var horrorTeacher;
var clues = [];
var scoreTxt;
var score = 0;
// Initialize game elements
function initGame() {
// Create and position the student
student = game.addChild(new Student());
student.x = 1024;
student.y = 1366;
// Create and position the horror teacher
horrorTeacher = game.addChild(new HorrorTeacher());
horrorTeacher.x = 500;
horrorTeacher.y = 500;
// Create and position clues
for (var i = 0; i < 5; i++) {
var clue = game.addChild(new Clue());
clue.x = Math.random() * 2048;
clue.y = Math.random() * 2732;
clues.push(clue);
}
// Create and position the score text
scoreTxt = new Text2('Score: 0', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
}
// Update game elements
game.update = function () {
// Update student and horror teacher
student.update();
horrorTeacher.update();
// Check for clue collection
for (var i = clues.length - 1; i >= 0; i--) {
if (student.intersects(clues[i])) {
clues[i].collect();
clues.splice(i, 1);
score += 10;
scoreTxt.setText('Score: ' + score);
}
}
// Check for game over condition
if (student.intersects(horrorTeacher)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
// Handle touch/mouse events
game.down = function (x, y, obj) {
student.move(x, y);
};
// Initialize the game
initGame(); ===================================================================
--- original.js
+++ change.js
@@ -1,113 +1,125 @@
-/****
+/****
* Classes
-****/
+****/
// Class for clues
var Clue = Container.expand(function () {
- var self = Container.call(this);
- var clueGraphics = self.attachAsset('clue', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.collected = false;
- self.collect = function () {
- self.collected = true;
- self.destroy();
- };
+ var self = Container.call(this);
+ var clueGraphics = self.attachAsset('clueModel', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.collected = false;
+ self.collect = function () {
+ self.collected = true;
+ self.destroy();
+ };
});
// Class for the horror teacher
var HorrorTeacher = Container.expand(function () {
- var self = Container.call(this);
- var teacherGraphics = self.attachAsset('teacher', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 3;
- self.update = function () {
- // Update logic for the horror teacher
- };
+ var self = Container.call(this);
+ var teacherGraphics = self.attachAsset('teacherModel', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 3;
+ self.update = function () {
+ // Update logic for the horror teacher
+ };
});
//<Assets used in the game will automatically appear here>
// Class for the student character
var Student = Container.expand(function () {
- var self = Container.call(this);
- var studentGraphics = self.attachAsset('student', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.update = function () {
- // Update logic for the student
- };
- self.move = function (x, y) {
- self.x = x;
- self.y = y;
- };
+ var self = Container.call(this);
+ var studentGraphics = self.attachAsset('studentModel', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ // Update logic for the student
+ };
+ self.move = function (x, y) {
+ self.x = x;
+ self.y = y;
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize arrays and variables
+LK.init.model('clue', {
+ id: 'clueModel',
+ scale: 1.0
+});
+LK.init.model('student', {
+ id: 'studentModel',
+ scale: 1.0
+});
+LK.init.model('teacher', {
+ id: 'teacherModel',
+ scale: 1.0
+});
var student;
var horrorTeacher;
var clues = [];
var scoreTxt;
var score = 0;
// Initialize game elements
function initGame() {
- // Create and position the student
- student = game.addChild(new Student());
- student.x = 1024;
- student.y = 1366;
- // Create and position the horror teacher
- horrorTeacher = game.addChild(new HorrorTeacher());
- horrorTeacher.x = 500;
- horrorTeacher.y = 500;
- // Create and position clues
- for (var i = 0; i < 5; i++) {
- var clue = game.addChild(new Clue());
- clue.x = Math.random() * 2048;
- clue.y = Math.random() * 2732;
- clues.push(clue);
- }
- // Create and position the score text
- scoreTxt = new Text2('Score: 0', {
- size: 100,
- fill: "#ffffff"
- });
- scoreTxt.anchor.set(0.5, 0);
- LK.gui.top.addChild(scoreTxt);
+ // Create and position the student
+ student = game.addChild(new Student());
+ student.x = 1024;
+ student.y = 1366;
+ // Create and position the horror teacher
+ horrorTeacher = game.addChild(new HorrorTeacher());
+ horrorTeacher.x = 500;
+ horrorTeacher.y = 500;
+ // Create and position clues
+ for (var i = 0; i < 5; i++) {
+ var clue = game.addChild(new Clue());
+ clue.x = Math.random() * 2048;
+ clue.y = Math.random() * 2732;
+ clues.push(clue);
+ }
+ // Create and position the score text
+ scoreTxt = new Text2('Score: 0', {
+ size: 100,
+ fill: "#ffffff"
+ });
+ scoreTxt.anchor.set(0.5, 0);
+ LK.gui.top.addChild(scoreTxt);
}
// Update game elements
game.update = function () {
- // Update student and horror teacher
- student.update();
- horrorTeacher.update();
- // Check for clue collection
- for (var i = clues.length - 1; i >= 0; i--) {
- if (student.intersects(clues[i])) {
- clues[i].collect();
- clues.splice(i, 1);
- score += 10;
- scoreTxt.setText('Score: ' + score);
- }
- }
- // Check for game over condition
- if (student.intersects(horrorTeacher)) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
+ // Update student and horror teacher
+ student.update();
+ horrorTeacher.update();
+ // Check for clue collection
+ for (var i = clues.length - 1; i >= 0; i--) {
+ if (student.intersects(clues[i])) {
+ clues[i].collect();
+ clues.splice(i, 1);
+ score += 10;
+ scoreTxt.setText('Score: ' + score);
+ }
+ }
+ // Check for game over condition
+ if (student.intersects(horrorTeacher)) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
};
// Handle touch/mouse events
game.down = function (x, y, obj) {
- student.move(x, y);
+ student.move(x, y);
};
// Initialize the game
initGame();
\ No newline at end of file