/****
* Classes
****/
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Coin logic
};
});
// Leaderboard class
var Leaderboard = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
// Update leaderboard
};
});
// Map class
var Map = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
// Update map
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -3;
self.update = function () {
self.y += self.speed;
self.speed -= 0.01; // Increase speed over time
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Surfer class
var Surfer = Container.expand(function () {
var self = Container.call(this);
var surferGraphics = self.attachAsset('surfer', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Surfer movement logic
self.speed += 0.01; // Increase speed over time
};
self.down = function (x, y, obj) {
// Handle surfer control
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize game elements
var surfer = game.addChild(new Surfer());
surfer.x = 1024; // Center horizontally
surfer.y = 2400; // Near bottom of the screen
var obstacles = [];
var coins = [];
var score = 0;
// Initialize leaderboard and map
var leaderboard = game.addChild(new Leaderboard());
var map = game.addChild(new Map());
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Game update logic
game.update = function () {
// Update surfer
surfer.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (obstacles[i].y < -50) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
if (surfer.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
// Update coins
for (var j = coins.length - 1; j >= 0; j--) {
coins[j].update();
if (coins[j].y < -50) {
coins[j].destroy();
coins.splice(j, 1);
}
if (surfer.intersects(coins[j])) {
score += 10;
scoreTxt.setText('Score: ' + score);
coins[j].destroy();
coins.splice(j, 1);
return;
}
}
// Spawn obstacles
if (LK.ticks % 60 == 0) {
var newObstacle = new Obstacle();
newObstacle.x = Math.random() * 2048;
newObstacle.y = 2732;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
// Spawn coins
if (LK.ticks % 120 == 0) {
var newCoin = new Coin();
newCoin.x = Math.random() * 2048; // Randomize horizontally
newCoin.y = Math.random() * 2732; // Randomize vertically
coins.push(newCoin);
game.addChild(newCoin);
}
};
// Handle surfer movement
game.down = function (x, y, obj) {
surfer.x = x;
surfer.y = y;
}; /****
* Classes
****/
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Coin logic
};
});
// Leaderboard class
var Leaderboard = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
// Update leaderboard
};
});
// Map class
var Map = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
// Update map
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -3;
self.update = function () {
self.y += self.speed;
self.speed -= 0.01; // Increase speed over time
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Surfer class
var Surfer = Container.expand(function () {
var self = Container.call(this);
var surferGraphics = self.attachAsset('surfer', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Surfer movement logic
self.speed += 0.01; // Increase speed over time
};
self.down = function (x, y, obj) {
// Handle surfer control
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize game elements
var surfer = game.addChild(new Surfer());
surfer.x = 1024; // Center horizontally
surfer.y = 2400; // Near bottom of the screen
var obstacles = [];
var coins = [];
var score = 0;
// Initialize leaderboard and map
var leaderboard = game.addChild(new Leaderboard());
var map = game.addChild(new Map());
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Game update logic
game.update = function () {
// Update surfer
surfer.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (obstacles[i].y < -50) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
if (surfer.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
// Update coins
for (var j = coins.length - 1; j >= 0; j--) {
coins[j].update();
if (coins[j].y < -50) {
coins[j].destroy();
coins.splice(j, 1);
}
if (surfer.intersects(coins[j])) {
score += 10;
scoreTxt.setText('Score: ' + score);
coins[j].destroy();
coins.splice(j, 1);
return;
}
}
// Spawn obstacles
if (LK.ticks % 60 == 0) {
var newObstacle = new Obstacle();
newObstacle.x = Math.random() * 2048;
newObstacle.y = 2732;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
// Spawn coins
if (LK.ticks % 120 == 0) {
var newCoin = new Coin();
newCoin.x = Math.random() * 2048; // Randomize horizontally
newCoin.y = Math.random() * 2732; // Randomize vertically
coins.push(newCoin);
game.addChild(newCoin);
}
};
// Handle surfer movement
game.down = function (x, y, obj) {
surfer.x = x;
surfer.y = y;
};