/**** * 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 += 0.345; // Gravity effect increased by 15% if (self.y >= 2732 / 2) { // Ground level self.y = 2732 / 2; 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 = -5; self.update = function () { self.x += self.speed; if (self.x < -100) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFFFFF //Init game with white background }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 })); // Initialize score display var scoreTxt = new Text2('0', { size: 225, // Increase the size by 50% fill: 0x000000 // Change the color to black }); scoreTxt.anchor.set(0.5, 0); // Anchor at the top LK.gui.top.addChild(scoreTxt); // Position at the top of the screen // Initialize Dino var dino = game.addChild(new Dino()); dino.x = 2048 / 2; dino.y = 2732 - dino.height / 2; // Array to keep track of obstacles var obstacles = []; // Function to spawn obstacles function spawnObstacle() { var obstacle = new Obstacle(); obstacle.x = 2048; obstacle.y = 2732 / 2; 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(); } else if (dino.x > obstacles[i].x + obstacles[i].width && !obstacles[i].passed) { obstacles[i].passed = true; LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); } } if (LK.ticks % 74 == 0) { // Spawn obstacle every 1.23 seconds spawnObstacle(); } }; // Handle touch events for jumping game.down = function (x, y, obj) { dino.jump(); }; LK.on('pause', function () { var pauseText = new Text2('HELE Bİ NEFESLEN RAFIĞIM YAV', { size: 100, fill: 0x000000 // Black color }); pauseText.anchor.set(0.5, 0.5); // Anchor at the center pauseText.x = 2048 / 2; // Position at the center of the screen pauseText.y = 2732 / 2; // Position at the center of the screen game.addChild(pauseText); }); // Add developer text to the top right corner of the screen var developerText = new Text2('Developer: Yusuf Sami', { size: 50, fill: 0x000000 // Black color }); developerText.anchor.set(1, 0); // Anchor at the top right LK.gui.topRight.addChild(developerText); // Position at the top right of the screen; // Add game title text to the center of the screen, 20% down from the middle var gameTitleText = new Text2('DAĞDA BOMBADAN KURTULMA YOLLARI', { size: 114, // Decrease the size by 5% fill: 0x000000 // Black color }); gameTitleText.anchor.set(0.5, 0.5); // Anchor at the center gameTitleText.x = 2048 / 2; // Position at the center of the screen gameTitleText.y = 2732 / 2 * 1.2; // Position 20% down from the middle of the screen game.addChild(gameTitleText);
/****
* 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 += 0.345; // Gravity effect increased by 15%
if (self.y >= 2732 / 2) {
// Ground level
self.y = 2732 / 2;
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 = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFFFF //Init game with white background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
}));
// Initialize score display
var scoreTxt = new Text2('0', {
size: 225,
// Increase the size by 50%
fill: 0x000000 // Change the color to black
});
scoreTxt.anchor.set(0.5, 0); // Anchor at the top
LK.gui.top.addChild(scoreTxt); // Position at the top of the screen
// Initialize Dino
var dino = game.addChild(new Dino());
dino.x = 2048 / 2;
dino.y = 2732 - dino.height / 2;
// Array to keep track of obstacles
var obstacles = [];
// Function to spawn obstacles
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = 2048;
obstacle.y = 2732 / 2;
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();
} else if (dino.x > obstacles[i].x + obstacles[i].width && !obstacles[i].passed) {
obstacles[i].passed = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
}
}
if (LK.ticks % 74 == 0) {
// Spawn obstacle every 1.23 seconds
spawnObstacle();
}
};
// Handle touch events for jumping
game.down = function (x, y, obj) {
dino.jump();
};
LK.on('pause', function () {
var pauseText = new Text2('HELE Bİ NEFESLEN RAFIĞIM YAV', {
size: 100,
fill: 0x000000 // Black color
});
pauseText.anchor.set(0.5, 0.5); // Anchor at the center
pauseText.x = 2048 / 2; // Position at the center of the screen
pauseText.y = 2732 / 2; // Position at the center of the screen
game.addChild(pauseText);
});
// Add developer text to the top right corner of the screen
var developerText = new Text2('Developer: Yusuf Sami', {
size: 50,
fill: 0x000000 // Black color
});
developerText.anchor.set(1, 0); // Anchor at the top right
LK.gui.topRight.addChild(developerText); // Position at the top right of the screen;
// Add game title text to the center of the screen, 20% down from the middle
var gameTitleText = new Text2('DAĞDA BOMBADAN KURTULMA YOLLARI', {
size: 114,
// Decrease the size by 5%
fill: 0x000000 // Black color
});
gameTitleText.anchor.set(0.5, 0.5); // Anchor at the center
gameTitleText.x = 2048 / 2; // Position at the center of the screen
gameTitleText.y = 2732 / 2 * 1.2; // Position 20% down from the middle of the screen
game.addChild(gameTitleText);