/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the Dino character
var Dino = Container.expand(function () {
var self = Container.call(this);
var dinoGraphics = self.attachAsset('dino', {
anchorX: 0.5,
anchorY: 0.5
});
self.yVelocity = 0;
self.isJumping = false;
self.jump = function () {
if (!self.isJumping) {
self.yVelocity = -20;
self.isJumping = true;
}
};
self.update = function () {
self.y += self.yVelocity;
self.yVelocity += 1; // Gravity effect
if (self.y >= 200) {
// Ground level
self.y = 200;
self.yVelocity = 0;
self.isJumping = false;
}
};
});
// Class for Obstacles
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize Dino
var dino = game.addChild(new Dino());
dino.x = 200;
dino.y = 200;
// Array to keep track of obstacles
var obstacles = [];
// Function to spawn obstacles
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = 2048;
obstacle.y = 200;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Handle game updates
game.update = function () {
dino.update();
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (dino.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
if (LK.ticks % 60 == 0) {
// Spawn obstacle every second
spawnObstacle();
}
};
// Handle touch events for jumping
game.down = function (x, y, obj) {
dino.jump();
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the Dino character
var Dino = Container.expand(function () {
var self = Container.call(this);
var dinoGraphics = self.attachAsset('dino', {
anchorX: 0.5,
anchorY: 0.5
});
self.yVelocity = 0;
self.isJumping = false;
self.jump = function () {
if (!self.isJumping) {
self.yVelocity = -20;
self.isJumping = true;
}
};
self.update = function () {
self.y += self.yVelocity;
self.yVelocity += 1; // Gravity effect
if (self.y >= 200) {
// Ground level
self.y = 200;
self.yVelocity = 0;
self.isJumping = false;
}
};
});
// Class for Obstacles
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize Dino
var dino = game.addChild(new Dino());
dino.x = 200;
dino.y = 200;
// Array to keep track of obstacles
var obstacles = [];
// Function to spawn obstacles
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = 2048;
obstacle.y = 200;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Handle game updates
game.update = function () {
dino.update();
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (dino.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
if (LK.ticks % 60 == 0) {
// Spawn obstacle every second
spawnObstacle();
}
};
// Handle touch events for jumping
game.down = function (x, y, obj) {
dino.jump();
};