User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'self.addChild(tharGraphics);' Line Number: 37
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'self.addChild.call(self, tharGraphics);' Line Number: 37
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'self.addChild(tharGraphics);' Line Number: 37
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'self.addChild.call(self, tharGraphics);' Line Number: 37
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'self.addChild(tharGraphics);' Line Number: 36
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var tharGraphics = self.attachAsset('thar', {' Line Number: 32
Initial prompt
Hindustani vehicles simulator
===================================================================
--- original.js
+++ change.js
@@ -1,67 +1,71 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
// Vehicle class to represent different vehicles
var Vehicle = Container.expand(function () {
- var self = Container.call(this);
- self.speed = 0;
- self.direction = 0;
- self.update = function () {
- self.x += self.speed * Math.cos(self.direction);
- self.y += self.speed * Math.sin(self.direction);
- };
- self.setSpeed = function (newSpeed) {
- self.speed = newSpeed;
- };
- self.setDirection = function (newDirection) {
- self.direction = newDirection;
- };
+ var self = Container.call(this);
+ self.speed = 0;
+ self.direction = 0;
+ self.update = function () {
+ self.x += self.speed * Math.cos(self.direction);
+ self.y += self.speed * Math.sin(self.direction);
+ };
+ self.setSpeed = function (newSpeed) {
+ self.speed = newSpeed;
+ };
+ self.setDirection = function (newDirection) {
+ self.direction = newDirection;
+ };
});
// Thar class extending Vehicle
var Thar = Vehicle.expand(function () {
- var self = Vehicle.call(this);
- var tharGraphics = self.attachAsset('thar', {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ var self = Vehicle.call(this);
+ var tharGraphics = LK.getAsset('thar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(tharGraphics);
});
// Scorpio class extending Vehicle
var Scorpio = Vehicle.expand(function () {
- var self = Vehicle.call(this);
- var scorpioGraphics = self.attachAsset('scorpio', {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ var self = Vehicle.call(this);
+ var scorpioGraphics = LK.getAsset('scorpio', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(scorpioGraphics);
});
// Fortuner class extending Vehicle
var Fortuner = Vehicle.expand(function () {
- var self = Vehicle.call(this);
- var fortunerGraphics = self.attachAsset('fortuner', {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ var self = Vehicle.call(this);
+ var fortunerGraphics = LK.getAsset('fortuner', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(fortunerGraphics);
});
// Bullet class extending Vehicle
var BulletBike = Vehicle.expand(function () {
- var self = Vehicle.call(this);
- var bulletGraphics = self.attachAsset('bullet', {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ var self = Vehicle.call(this);
+ var bulletGraphics = LK.getAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(bulletGraphics);
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize vehicles
var thar = game.addChild(new Thar());
thar.x = 1024; // Center horizontally
thar.y = 1366; // Center vertically
@@ -77,29 +81,29 @@
// Array to hold all vehicles
var vehicles = [thar, fortuner, scorpio, bulletBike];
// Function to handle vehicle movement
function handleMove(x, y, obj) {
- vehicles.forEach(function (vehicle) {
- if (vehicle.intersects(obj)) {
- vehicle.setSpeed(5);
- vehicle.setDirection(Math.atan2(y - vehicle.y, x - vehicle.x));
- }
- });
+ vehicles.forEach(function (vehicle) {
+ if (vehicle.intersects(obj)) {
+ vehicle.setSpeed(5);
+ vehicle.setDirection(Math.atan2(y - vehicle.y, x - vehicle.x));
+ }
+ });
}
// Event listeners for game
game.down = function (x, y, obj) {
- handleMove(x, y, obj);
+ handleMove(x, y, obj);
};
game.move = function (x, y, obj) {
- handleMove(x, y, obj);
+ handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
- vehicles.forEach(function (vehicle) {
- vehicle.setSpeed(0);
- });
+ vehicles.forEach(function (vehicle) {
+ vehicle.setSpeed(0);
+ });
};
// Update function for game
game.update = function () {
- vehicles.forEach(function (vehicle) {
- vehicle.update();
- });
+ vehicles.forEach(function (vehicle) {
+ vehicle.update();
+ });
};
\ No newline at end of file
Mahindra scorpio in black color and realistic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Mahindra thar 4Γ4 in black color and realistic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Toyota fortunar in white colour and full realistic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Royal Enfield bullet in black colour and full realistic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.