/****
* Classes
****/
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1
});
self._move_migrated = function () {
self.x -= 5;
// Obstacles float in the air without moving towards the camera
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('glueStick', {
anchorX: 0.5,
anchorY: 1
});
self.size = {
x: 1,
y: 1,
z: 1
}; // Initial size of the player on all axes
self._update_migrated = function () {
self.widen = function () {
self.size.x += 0.2; // Increase the width of the player
playerGraphics.scale.set(self.size.x, self.size.y, self.size.z); // Scale the player graphics in 3D
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
};
self.grow = function () {
self.size.x += 0.1;
self.size.y += 0.1;
self.size.z += 0.1; // Increase the size of the player on all axes
playerGraphics.scale.set(self.size.x, self.size.y, self.size.z); // Scale the player graphics in 3D
};
});
// PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 1
});
self.type = 'glueStick'; // Default type is glueStick
self._move_migrated = function () {
self.x -= 5;
if (self.type === 'glueStick') {
if (Math.random() < 0.5) {
self.y = player.y - player.height; // Directly above the player
} else {
self.y = player.y;
self.x = player.x + (Math.random() < 0.5 ? -player.width : player.width); // Adjacent lane
}
self.z = Math.random() * 1000; // Random distance from the camera
}
};
self.setType = function (type) {
self.type = type;
// Additional logic to change the appearance based on type can be added here
};
});
var SizeChanger = Container.expand(function () {
var self = Container.call(this);
var sizeChangerGraphics = self.attachAsset('sizeChanger', {
anchorX: 0.5,
anchorY: 1
});
self.effect = 'grow'; // Default effect is to grow the player
self._move_migrated = function () {
self.x -= 5;
if (self.y < 200) {
self.y = 200;
} // Ensure the SizeChanger does not float above a certain height
};
self.setEffect = function (effect) {
self.effect = effect;
// Additional logic to change the appearance based on effect can be added here
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize important asset arrays
// Keyboard event handling
var obstacles = [];
var glueSticks = [];
var player = game.addChild(new Player());
// Set the player's initial position
player.x = 2048 / 4;
player.y = 2732 - 200; // Position the player near the bottom of the screen
// Game logic
LK.on('tick', function () {
// Update the player
player._update_migrated();
// Move and check for collisions with glue sticks
for (var j = glueSticks.length - 1; j >= 0; j--) {
glueSticks[j]._move_migrated();
if (player.intersects(glueSticks[j])) {
if (glueSticks[j].effect === 'grow') {
player.grow();
} else if (glueSticks[j].effect === 'widen') {
player.widen(); // This method needs to be implemented in the Player class
}
glueSticks[j].destroy();
glueSticks.splice(j, 1);
}
// Remove off-screen glue sticks
if (glueSticks[j] && glueSticks[j].x < -glueSticks[j].width) {
glueSticks[j].destroy();
glueSticks.splice(j, 1);
}
}
// Spawn obstacles and glue sticks with initial z-axis values
if (LK.ticks % 180 == 0) {
// Every 3 seconds
var newSizeChanger = new SizeChanger();
newSizeChanger.setEffect('grow'); // Set the effect to 'grow'
newSizeChanger.x = 2048;
newSizeChanger.y = Math.random() < 0.5 ? 2732 - 300 : 200;
newSizeChanger.z = 0; // Set initial z-axis value for depth
glueSticks.push(newSizeChanger);
game.addChild(newSizeChanger);
}
});
// Add event listener to handle player movement
game.move = function (x, y, obj) {
var game_position = game.toLocal(obj.global);
player.move(game_position.x, game_position.y);
}; /****
* Classes
****/
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1
});
self._move_migrated = function () {
self.x -= 5;
// Obstacles float in the air without moving towards the camera
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('glueStick', {
anchorX: 0.5,
anchorY: 1
});
self.size = {
x: 1,
y: 1,
z: 1
}; // Initial size of the player on all axes
self._update_migrated = function () {
self.widen = function () {
self.size.x += 0.2; // Increase the width of the player
playerGraphics.scale.set(self.size.x, self.size.y, self.size.z); // Scale the player graphics in 3D
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
};
self.grow = function () {
self.size.x += 0.1;
self.size.y += 0.1;
self.size.z += 0.1; // Increase the size of the player on all axes
playerGraphics.scale.set(self.size.x, self.size.y, self.size.z); // Scale the player graphics in 3D
};
});
// PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 1
});
self.type = 'glueStick'; // Default type is glueStick
self._move_migrated = function () {
self.x -= 5;
if (self.type === 'glueStick') {
if (Math.random() < 0.5) {
self.y = player.y - player.height; // Directly above the player
} else {
self.y = player.y;
self.x = player.x + (Math.random() < 0.5 ? -player.width : player.width); // Adjacent lane
}
self.z = Math.random() * 1000; // Random distance from the camera
}
};
self.setType = function (type) {
self.type = type;
// Additional logic to change the appearance based on type can be added here
};
});
var SizeChanger = Container.expand(function () {
var self = Container.call(this);
var sizeChangerGraphics = self.attachAsset('sizeChanger', {
anchorX: 0.5,
anchorY: 1
});
self.effect = 'grow'; // Default effect is to grow the player
self._move_migrated = function () {
self.x -= 5;
if (self.y < 200) {
self.y = 200;
} // Ensure the SizeChanger does not float above a certain height
};
self.setEffect = function (effect) {
self.effect = effect;
// Additional logic to change the appearance based on effect can be added here
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize important asset arrays
// Keyboard event handling
var obstacles = [];
var glueSticks = [];
var player = game.addChild(new Player());
// Set the player's initial position
player.x = 2048 / 4;
player.y = 2732 - 200; // Position the player near the bottom of the screen
// Game logic
LK.on('tick', function () {
// Update the player
player._update_migrated();
// Move and check for collisions with glue sticks
for (var j = glueSticks.length - 1; j >= 0; j--) {
glueSticks[j]._move_migrated();
if (player.intersects(glueSticks[j])) {
if (glueSticks[j].effect === 'grow') {
player.grow();
} else if (glueSticks[j].effect === 'widen') {
player.widen(); // This method needs to be implemented in the Player class
}
glueSticks[j].destroy();
glueSticks.splice(j, 1);
}
// Remove off-screen glue sticks
if (glueSticks[j] && glueSticks[j].x < -glueSticks[j].width) {
glueSticks[j].destroy();
glueSticks.splice(j, 1);
}
}
// Spawn obstacles and glue sticks with initial z-axis values
if (LK.ticks % 180 == 0) {
// Every 3 seconds
var newSizeChanger = new SizeChanger();
newSizeChanger.setEffect('grow'); // Set the effect to 'grow'
newSizeChanger.x = 2048;
newSizeChanger.y = Math.random() < 0.5 ? 2732 - 300 : 200;
newSizeChanger.z = 0; // Set initial z-axis value for depth
glueSticks.push(newSizeChanger);
game.addChild(newSizeChanger);
}
});
// Add event listener to handle player movement
game.move = function (x, y, obj) {
var game_position = game.toLocal(obj.global);
player.move(game_position.x, game_position.y);
};