/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Define the Hobbit class var Hobbit = Container.expand(function () { var self = Container.call(this); self.assetContainer = new Container(); self.addChild(self.assetContainer); self.animationState = 0; self.hobbitGraphics = self.assetContainer.attachAsset('hobbit', { anchorX: 0.5, anchorY: 0.5 }); self.switchAsset = function () { if (self.animationState == 0) { self.assetContainer.removeChild(self.hobbitGraphics); self.hobbitGraphics = self.assetContainer.attachAsset('hobbitMirrored', { anchorX: 0.5, anchorY: 0.5 }); self.animationState = 1; } else { self.assetContainer.removeChild(self.hobbitGraphics); self.hobbitGraphics = self.assetContainer.attachAsset('hobbit', { anchorX: 0.5, anchorY: 0.5 }); self.animationState = 0; } }; self.speed = 5; self.update = function () { // Update logic for the hobbit if (this.jumping) { this.jumpSpeed -= this.gravity; this.y -= this.jumpSpeed; if (this.y > this.ground) { this.y = this.ground; this.jumping = false; } } if (gameStarted && LK.ticks % 10 == 0) { this.switchAsset(); } }; self.jump = function () { if (!this.jumping && this.y >= this.ground && this.intersects(track)) { this.jumping = true; this.jumpSpeed = this.jumpPower; } }; }); var Obstacle = Container.expand(function () { var self = Container.call(this); self.assetType = Math.random() < 0.5 ? 'Rock' : 'Sheep'; console.log("Creating obstacle of type:", self.assetType); self.asset = self.attachAsset(self.assetType, { anchorX: 0.5, anchorY: 0.5 }); self.asset.alpha = 0; // Set initial alpha to 0 self.scale.set(1, 1); // Set initial scale to 1 for both x and y self.speed = 5; self.update = function () { self.y += self.speed; if (self.x < 2048 / 2) { self.x -= Math.sin(LK.ticks / driftFrequency) * driftSpeed; // Add horizontal drift to the left } else { self.x += Math.sin(LK.ticks / driftFrequency) * driftSpeed; // Add horizontal drift to the right } // Increment alpha for fade-in effect if (self.asset.alpha < 1) { self.asset.alpha += 0.05; // Adjust the increment value as needed } self.scale.x += 0.0081; self.scale.y += 0.0081; if (self.y > 2732 + self.height / 2) { self.destroy(); } else { self.asset.visible = true; } }; }); // Define the StartButton class var StartButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('button', { anchorX: 0.5, anchorY: 0.5 }); self.down = function () { startButton.destroy(); gameStarted = true; // Set gameStarted to true when the start button is clicked }; }); // Define the Track class var Track = Container.expand(function () { var self = Container.call(this); var trackGraphics = self.attachAsset('track', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for the track }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var driftSpeed = 2; // Speed of horizontal drift var driftFrequency = 100; // Frequency of horizontal drift var horizon = LK.getAsset('Horizon', { anchorX: 0.5, anchorY: 0.0, x: 2048 / 2, y: 0 }); game.addChild(horizon); // Initialize game variables var hobbit = game.addChild(new Hobbit()); hobbit.x = 2048 / 2; hobbit.y = 2732 - hobbit.height / 2; // Position hobbit at the bottom center of the screen hobbit.visible = true; // Ensure hobbit is visible var gameStarted = false; // Track if the game has started or not var score = 3; hobbit.hitPoints = score; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); LK.gui.top.addChild(scoreTxt); var dragNode = null; var obstacles = []; var track = game.addChildAt(new Track(), 1); track.x = 2048 / 2; track.y = 2732 * 3 / 4; // Handle move events function handleMove(x, y, obj) { if (dragNode) { // Ensure the hobbit stays within the track boundaries if (x > track.x - track.width / 2 && x < track.x + track.width / 2) { dragNode.x = x; } } } // Mouse or touch move on game object game.move = handleMove; // Allow dragging of the hobbit to start from anywhere game.down = function (x, y, obj) { if (obj.target === startButton && startButton.visible) { startButton.destroy(); gameStarted = true; // Set gameStarted to true when the start button is clicked } else if (gameStarted) { dragNode = hobbit; handleMove(x, y, obj); hobbit.jump(); } }; // Mouse or touch up on game object game.up = function (x, y, obj) { dragNode = null; }; // Update game logic game.update = function () { if (gameStarted) { // Update score scoreTxt.setText(hobbit.hitPoints); // Generate obstacles if (LK.ticks % 60 == 0) { var newObstacle = new Obstacle(); newObstacle.x = Math.random() * 2048; newObstacle.y = horizon.height; obstacles.push(newObstacle); game.addChildAt(newObstacle, 3); } // Update obstacles for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].update(); if (obstacles[i].y > 2732 + obstacles[i].height / 2) { obstacles[i].destroy(); obstacles.splice(i, 1); } else if (hobbit.intersects(obstacles[i])) { hobbit.hitPoints -= 1; scoreTxt.setText(hobbit.hitPoints); obstacles[i].destroy(); obstacles.splice(i, 1); // Play collide sound var collideSound = LK.getSound('Collide'); if (collideSound) { collideSound.play(); } if (hobbit.hitPoints <= 0) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } } } // Check if hobbit is off track if (gameStarted && !hobbit.intersects(track)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Check if hobbit collides with an obstacle for (var i = 0; i < obstacles.length; i++) { if (hobbit.intersects(obstacles[i]) && (obstacles[i].assetType == 'Rock' || obstacles[i].assetType == 'Sheep')) { hobbit.hitPoints -= 1; scoreTxt.setText(hobbit.hitPoints); obstacles[i].destroy(); obstacles.splice(i, 1); // Play collide sound var collideSound = LK.getSound('Collide'); if (collideSound) { collideSound.play(); } if (hobbit.hitPoints <= 0) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } } }; // Initialize the start button var startButton = game.addChild(new StartButton()); startButton.x = 2048 / 2; startButton.y = 2732 / 2; startButton.visible = true; // Ensure start button is visible startButton.interactive = true; // Ensure start button is interactive startButton.alpha = 1; // Ensure start button is not transparent
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Define the Hobbit class
var Hobbit = Container.expand(function () {
var self = Container.call(this);
self.assetContainer = new Container();
self.addChild(self.assetContainer);
self.animationState = 0;
self.hobbitGraphics = self.assetContainer.attachAsset('hobbit', {
anchorX: 0.5,
anchorY: 0.5
});
self.switchAsset = function () {
if (self.animationState == 0) {
self.assetContainer.removeChild(self.hobbitGraphics);
self.hobbitGraphics = self.assetContainer.attachAsset('hobbitMirrored', {
anchorX: 0.5,
anchorY: 0.5
});
self.animationState = 1;
} else {
self.assetContainer.removeChild(self.hobbitGraphics);
self.hobbitGraphics = self.assetContainer.attachAsset('hobbit', {
anchorX: 0.5,
anchorY: 0.5
});
self.animationState = 0;
}
};
self.speed = 5;
self.update = function () {
// Update logic for the hobbit
if (this.jumping) {
this.jumpSpeed -= this.gravity;
this.y -= this.jumpSpeed;
if (this.y > this.ground) {
this.y = this.ground;
this.jumping = false;
}
}
if (gameStarted && LK.ticks % 10 == 0) {
this.switchAsset();
}
};
self.jump = function () {
if (!this.jumping && this.y >= this.ground && this.intersects(track)) {
this.jumping = true;
this.jumpSpeed = this.jumpPower;
}
};
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
self.assetType = Math.random() < 0.5 ? 'Rock' : 'Sheep';
console.log("Creating obstacle of type:", self.assetType);
self.asset = self.attachAsset(self.assetType, {
anchorX: 0.5,
anchorY: 0.5
});
self.asset.alpha = 0; // Set initial alpha to 0
self.scale.set(1, 1); // Set initial scale to 1 for both x and y
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.x < 2048 / 2) {
self.x -= Math.sin(LK.ticks / driftFrequency) * driftSpeed; // Add horizontal drift to the left
} else {
self.x += Math.sin(LK.ticks / driftFrequency) * driftSpeed; // Add horizontal drift to the right
}
// Increment alpha for fade-in effect
if (self.asset.alpha < 1) {
self.asset.alpha += 0.05; // Adjust the increment value as needed
}
self.scale.x += 0.0081;
self.scale.y += 0.0081;
if (self.y > 2732 + self.height / 2) {
self.destroy();
} else {
self.asset.visible = true;
}
};
});
// Define the StartButton class
var StartButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function () {
startButton.destroy();
gameStarted = true; // Set gameStarted to true when the start button is clicked
};
});
// Define the Track class
var Track = Container.expand(function () {
var self = Container.call(this);
var trackGraphics = self.attachAsset('track', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for the track
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var driftSpeed = 2; // Speed of horizontal drift
var driftFrequency = 100; // Frequency of horizontal drift
var horizon = LK.getAsset('Horizon', {
anchorX: 0.5,
anchorY: 0.0,
x: 2048 / 2,
y: 0
});
game.addChild(horizon);
// Initialize game variables
var hobbit = game.addChild(new Hobbit());
hobbit.x = 2048 / 2;
hobbit.y = 2732 - hobbit.height / 2; // Position hobbit at the bottom center of the screen
hobbit.visible = true; // Ensure hobbit is visible
var gameStarted = false; // Track if the game has started or not
var score = 3;
hobbit.hitPoints = score;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
var dragNode = null;
var obstacles = [];
var track = game.addChildAt(new Track(), 1);
track.x = 2048 / 2;
track.y = 2732 * 3 / 4;
// Handle move events
function handleMove(x, y, obj) {
if (dragNode) {
// Ensure the hobbit stays within the track boundaries
if (x > track.x - track.width / 2 && x < track.x + track.width / 2) {
dragNode.x = x;
}
}
}
// Mouse or touch move on game object
game.move = handleMove;
// Allow dragging of the hobbit to start from anywhere
game.down = function (x, y, obj) {
if (obj.target === startButton && startButton.visible) {
startButton.destroy();
gameStarted = true; // Set gameStarted to true when the start button is clicked
} else if (gameStarted) {
dragNode = hobbit;
handleMove(x, y, obj);
hobbit.jump();
}
};
// Mouse or touch up on game object
game.up = function (x, y, obj) {
dragNode = null;
};
// Update game logic
game.update = function () {
if (gameStarted) {
// Update score
scoreTxt.setText(hobbit.hitPoints);
// Generate obstacles
if (LK.ticks % 60 == 0) {
var newObstacle = new Obstacle();
newObstacle.x = Math.random() * 2048;
newObstacle.y = horizon.height;
obstacles.push(newObstacle);
game.addChildAt(newObstacle, 3);
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (obstacles[i].y > 2732 + obstacles[i].height / 2) {
obstacles[i].destroy();
obstacles.splice(i, 1);
} else if (hobbit.intersects(obstacles[i])) {
hobbit.hitPoints -= 1;
scoreTxt.setText(hobbit.hitPoints);
obstacles[i].destroy();
obstacles.splice(i, 1);
// Play collide sound
var collideSound = LK.getSound('Collide');
if (collideSound) {
collideSound.play();
}
if (hobbit.hitPoints <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}
}
// Check if hobbit is off track
if (gameStarted && !hobbit.intersects(track)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Check if hobbit collides with an obstacle
for (var i = 0; i < obstacles.length; i++) {
if (hobbit.intersects(obstacles[i]) && (obstacles[i].assetType == 'Rock' || obstacles[i].assetType == 'Sheep')) {
hobbit.hitPoints -= 1;
scoreTxt.setText(hobbit.hitPoints);
obstacles[i].destroy();
obstacles.splice(i, 1);
// Play collide sound
var collideSound = LK.getSound('Collide');
if (collideSound) {
collideSound.play();
}
if (hobbit.hitPoints <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}
};
// Initialize the start button
var startButton = game.addChild(new StartButton());
startButton.x = 2048 / 2;
startButton.y = 2732 / 2;
startButton.visible = true; // Ensure start button is visible
startButton.interactive = true; // Ensure start button is interactive
startButton.alpha = 1; // Ensure start button is not transparent
A retro pixel art start button. Forest theme, 16 bit, hobbit themed game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A 16 bit pixel art horizon line of a pastural hobbit village. A beautiful verdant village in the distance with rolling hills and blue skies. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A pixel art gradient from black to grassy green. Mostly green rectangle.
A 16 bit potato. Delicious, hearty potato 🥔 no border, no UI. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A pixel art sprite of a hobbit. Top down view from behind so the player only sees the hobbits top of head. Full body Top down aerial view, from behind, he is running, Nintendo art style 16 bit, retro. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art boulder with dirt and blades of grass around the bottom. No ground or background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.