/**** * Classes ****/ var EnemyBeyblade = Container.expand(function () { var self = Container.call(this); self.beybladeGraphics = self.attachAsset('PB2', { anchorX: 0.5, anchorY: 0.5 }); self.rotationSpeed = 0.1; self.lifePercentage = 100; // Initialize lifePercentage self.update = function () { self.beybladeGraphics.rotation += self.rotationSpeed; // Move towards playerBeyblade var directionX = playerBeyblade.x - self.x; var directionY = playerBeyblade.y - self.y; var magnitude = Math.sqrt(directionX * directionX + directionY * directionY); self.x += directionX / magnitude * 2; // Move 2 units per update towards playerBeyblade self.y += directionY / magnitude * 2; // Move 2 units per update towards playerBeyblade // Check for collision with PB1 and adjust position to prevent overlap if (self.intersects(playerBeyblade)) { // Calculate the overlap distance var overlapX = (self.x - playerBeyblade.x) / 2; var overlapY = (self.y - playerBeyblade.y) / 2; // Adjust positions to resolve overlap self.x += overlapX; self.y += overlapY; playerBeyblade.x -= overlapX; playerBeyblade.y -= overlapY; // Check if PB2 has left the arena var minX = arena.x - arena.arenaGraphics.width / 2 + this.beybladeGraphics.width / 2; var maxX = arena.x + arena.arenaGraphics.width / 2 - this.beybladeGraphics.width / 2; var minY = arena.y - arena.arenaGraphics.height / 2 + this.beybladeGraphics.height / 2; var maxY = arena.y + arena.arenaGraphics.height / 2 - this.beybladeGraphics.height / 2; if (this.x <= minX || this.x >= maxX || this.y <= minY || this.y >= maxY) { var winText = new Text2('The player won!', { size: 200, fill: 0xFFFFFF }); winText.anchor.set(0.5, 0.5); winText.x = 1024; // Center horizontally winText.y = 1366; // Center vertically LK.gui.center.addChild(winText); // Award 1 point to the player playerScore += 1; scoreText.setText("Player: ".concat(playerScore, " | Computer: ").concat(computerScore)); // Removed game over trigger when PB2 is defeated return; // Ensure no further updates occur after game over } } }; }); var LifeLinePB1 = Container.expand(function () { var self = Container.call(this); var lifeLineGraphics = self.attachAsset('lifeLinePB1', { anchorX: 0.5, anchorY: 0.5 }); self.setLifePercentage = function (percentage) { lifeLineGraphics.scaleX = percentage / 100; }; self.setPosition = function (x, y) { self.x = x; self.y = y; }; }); var LifeLinePB2 = Container.expand(function () { var self = Container.call(this); var lifeLineGraphics = self.attachAsset('lifeLinePB2', { anchorX: 0.5, anchorY: 0.5 }); self.setLifePercentage = function (percentage) { lifeLineGraphics.scaleX = percentage / 100; }; self.setPosition = function (x, y) { self.x = x; self.y = y; }; }); var SparkEffect = Container.expand(function () { var self = Container.call(this); var sparkGraphics = self.attachAsset('spark', { anchorX: 0.5, anchorY: 0.5 }); self.fadeSpeed = 0.05; // Speed at which the spark fades out self.update = function () { sparkGraphics.alpha -= self.fadeSpeed; if (sparkGraphics.alpha <= 0) { self.destroy(); } }; }); var WheelTrack = Container.expand(function () { var self = Container.call(this); var trackGraphics = self.attachAsset('whirlwind', { anchorX: 0.5, anchorY: 0.5 }); self.fadeSpeed = 0.01; // Speed at which the track fades out self.update = function () { trackGraphics.alpha -= self.fadeSpeed; if (trackGraphics.alpha <= 0) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ LK.playMusic('arena', { loop: true }); // Play arena sound in loop var enemyBeyblade = new EnemyBeyblade(); enemyBeyblade.lifePercentage = 100; // Start with full life var lifeLinePB1 = new LifeLinePB1(); lifeLinePB1.visible = true; // Show the lifeline for PB1 lifeLinePB1.setPosition(1024, 2732 - 100); // Center bottom of the map, above PB2 lifeline game.addChild(lifeLinePB1); var lifeLinePB2 = new LifeLinePB2(); lifeLinePB2.visible = true; // Show the lifeline for PB2 lifeLinePB2.setPosition(1024, 2732 - 50); // Center bottom of the map game.addChild(lifeLinePB2); // Initialize player and enemy beyblades //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Player Beyblade class function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _classCallCheck(a, n) { if (!(a instanceof n)) { throw new TypeError("Cannot call a class as a function"); } } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) { return e; } if (void 0 !== e) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) { throw new TypeError("Super expression must either be null or a function"); } t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } var Arena = /*#__PURE__*/function (_Container) { function Arena() { var _this; _classCallCheck(this, Arena); _this = _callSuper(this, Arena); _this.arenaGraphics = _this.attachAsset('arena', { anchorX: 0.5, anchorY: 0.5 }); return _this; } _inherits(Arena, _Container); return _createClass(Arena); }(Container); // Enemy Beyblade class var EnemyBeyblade = /*#__PURE__*/function (_Container2) { function EnemyBeyblade() { var _this2; _classCallCheck(this, EnemyBeyblade); _this2 = _callSuper(this, EnemyBeyblade); _this2.beybladeGraphics = _this2.attachAsset('PB2', { anchorX: 0.5, anchorY: 0.5 }); _this2.rotationSpeed = 0.1; _this2.lifePercentage = 100; // Initialize lifePercentage return _this2; } _inherits(EnemyBeyblade, _Container2); return _createClass(EnemyBeyblade, [{ key: "update", value: function update() { this.beybladeGraphics.rotation += this.rotationSpeed; // Move towards playerBeyblade var directionX = playerBeyblade.x - this.x; var directionY = playerBeyblade.y - this.y; var magnitude = Math.sqrt(directionX * directionX + directionY * directionY); this.x += directionX / magnitude * 2; // Move 2 units per update towards playerBeyblade this.y += directionY / magnitude * 2; // Move 2 units per update towards playerBeyblade // Check for collision with PB1 and adjust position to prevent overlap if (this.lifePercentage <= 0) { // Award 1 point to the player playerScore += 1; scoreText.setText("Player: ".concat(playerScore, " | Computer: ").concat(computerScore)); // Reset the round playerBeyblade.x = 1024; // Reset player position playerBeyblade.y = 1366; playerBeyblade.lifePercentage = 100; lifeLinePB1.setLifePercentage(playerBeyblade.lifePercentage); this.x = 1024; // Reset enemy position this.y = 732; this.lifePercentage = 100; lifeLinePB2.setLifePercentage(this.lifePercentage); return; // Ensure no further updates occur after resetting } // Constrain PB2 within the arena boundaries var minX = arena.x - arena.arenaGraphics.width / 2 + this.beybladeGraphics.width / 2; var maxX = arena.x + arena.arenaGraphics.width / 2 - this.beybladeGraphics.width / 2; var minY = arena.y - arena.arenaGraphics.height / 2 + this.beybladeGraphics.height / 2; var maxY = arena.y + arena.arenaGraphics.height / 2 - this.beybladeGraphics.height / 2; this.x = Math.max(minX, Math.min(maxX, this.x)); this.y = Math.max(minY, Math.min(maxY, this.y)); if (this.intersects(playerBeyblade)) { // Calculate the overlap distance var overlapX = (this.x - playerBeyblade.x) / 2; var overlapY = (this.y - playerBeyblade.y) / 2; // Adjust positions to resolve overlap this.x += overlapX; this.y += overlapY; playerBeyblade.x -= overlapX; playerBeyblade.y -= overlapY; } } }]); }(Container); var PB1 = /*#__PURE__*/function (_Container3) { function PB1() { var _this3; _classCallCheck(this, PB1); _this3 = _callSuper(this, PB1); _this3.beybladeGraphics = _this3.attachAsset('PB1', { anchorX: 0.5, anchorY: 0.5 }); _this3.rotationSpeed = 0.1; return _this3; } _inherits(PB1, _Container3); return _createClass(PB1, [{ key: "update", value: function update() { this.beybladeGraphics.rotation += this.rotationSpeed; // Check for collision with PB2 and adjust position to prevent overlap if (this.intersects(enemyBeyblade)) { // Decrease PB1's life by 5% this.lifePercentage = Math.max(0, this.lifePercentage - 5); lifeLinePB1.setLifePercentage(this.lifePercentage); lifeLinePB1.visible = true; // Ensure the lifeline for PB1 is visible // Increase hit impact on PB2 if PB1 is invincible if (this.isInvincible) { enemyBeyblade.lifePercentage = Math.max(0, enemyBeyblade.lifePercentage - 15); // Increase impact } else { enemyBeyblade.lifePercentage = Math.max(0, enemyBeyblade.lifePercentage - 10); } lifeLinePB2.setLifePercentage(enemyBeyblade.lifePercentage); // Calculate the overlap distance var overlapX = (this.x - enemyBeyblade.x) / 2; var overlapY = (this.y - enemyBeyblade.y) / 2; // Adjust positions to resolve overlap this.x += overlapX; this.y += overlapY; enemyBeyblade.x -= overlapX; enemyBeyblade.y -= overlapY; } // Constrain PB1 within the arena boundaries var minX = arena.x - arena.arenaGraphics.width / 2 + this.beybladeGraphics.width / 2; var maxX = arena.x + arena.arenaGraphics.width / 2 - this.beybladeGraphics.width / 2; var minY = arena.y - arena.arenaGraphics.height / 2 + this.beybladeGraphics.height / 2; var maxY = arena.y + arena.arenaGraphics.height / 2 - this.beybladeGraphics.height / 2; this.x = Math.max(minX, Math.min(maxX, this.x)); this.y = Math.max(minY, Math.min(maxY, this.y)); // Check if PB1 has left the arena if (this.x <= minX || this.x >= maxX || this.y <= minY || this.y >= maxY) { // Reset the round computerScore += 1; scoreText.setText("Player: ".concat(playerScore, " | Computer: ").concat(computerScore)); this.x = 1024; // Reset player position this.y = 1366; this.lifePercentage = 100; lifeLinePB1.setLifePercentage(this.lifePercentage); enemyBeyblade.x = 1024; // Reset enemy position enemyBeyblade.y = 732; enemyBeyblade.lifePercentage = 100; lifeLinePB2.setLifePercentage(enemyBeyblade.lifePercentage); return; // Ensure no further updates occur after resetting } } }, { key: "down", value: function down(x, y, obj) { this.x = x; this.y = y; } }]); }(Container); var wallpaper = game.addChild(LK.getAsset('wallpaper', { anchorX: 0.5, anchorY: 0.5 })); wallpaper.x = 1024; // Center horizontally wallpaper.y = 1366; // Center vertically var arena = new Arena(); arena.x = 1024; // Center horizontally arena.y = 1366; // Center vertically game.addChild(arena); var whirlwind = LK.getAsset('whirlwind', { anchorX: 0.5, anchorY: 0.5 }); whirlwind.x = 1024; // Center horizontally whirlwind.y = 1366; // Center vertically var playerBeyblade = new PB1(); game.addChild(whirlwind); playerBeyblade.lastWasIntersecting = false; playerBeyblade.lastWasIntersectingShield = false; playerBeyblade.x = 1024; // Center horizontally playerBeyblade.y = 1366; // Center vertically game.addChild(playerBeyblade); var enemyBeyblade = new EnemyBeyblade(); enemyBeyblade.x = 1024; // Center horizontally enemyBeyblade.y = 732; // Position near the top game.addChild(enemyBeyblade); var lifeLinePB1 = new LifeLinePB1(); lifeLinePB1.visible = true; // Ensure the lifeline for PB1 is visible like the red lifeline for PB2 lifeLinePB1.setPosition(1024, 2732 - 100); // Center bottom of the map, above PB2 lifeline game.addChild(lifeLinePB1); var lifeLinePB2 = new LifeLinePB2(); lifeLinePB2.visible = true; // Show the lifeline for PB2 lifeLinePB2.setPosition(1024, 2732 - 50); // Center bottom of the map game.addChild(lifeLinePB2); var j1 = LK.getAsset('j1', { anchorX: 0.5, anchorY: 0.5 }); j1.x = j1.width / 2 + 20; // Position at the left and move right by an additional 10 units j1.y = 2732 - j1.height / 2 - 20; // Move up by an additional 10 units game.addChild(j1); var j2 = LK.getAsset('j2', { anchorX: 0.5, anchorY: 0.5 }); j2.x = j1.x; // Center j2 horizontally on j1 j2.y = j1.y; // Center j2 vertically on j1 game.addChild(j2); // Initialize timer variables var playerScore = 0; var computerScore = 0; var scoreText = new Text2('Player: 0 | Computer: 0', { size: 75, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); // Align to the top-center LK.gui.top.addChild(scoreText); scoreText.setText("Player: ".concat(playerScore, " | Computer: ").concat(computerScore)); // Ensure initial text is set var timerDuration = 60; // 60 seconds var timerText = new Text2('01:00', { size: 100, fill: 0xFFFFFF }); timerText.anchor.set(1, 0); // Align to the top-right corner LK.gui.topRight.addChild(timerText); // Add the timer text to the top-right of the screen // Update the timer every second var timerInterval = LK.setInterval(function () { timerDuration--; var minutes = Math.floor(timerDuration / 60); var seconds = timerDuration % 60; timerText.setText((minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds); // Check if the timer has reached zero if (timerDuration <= 0) { LK.clearInterval(timerInterval); LK.showGameOver(); // Trigger game over when timer reaches zero } }, 1000); // Game update loop game.update = function () { // Create wheel track effect for player beyblade var playerWheelTrack = new WheelTrack(); playerWheelTrack.x = playerBeyblade.x; playerWheelTrack.y = playerBeyblade.y; game.addChild(playerWheelTrack); // Create wheel track effect for player beyblade var playerWheelTrack = new WheelTrack(); playerWheelTrack.x = playerBeyblade.x; playerWheelTrack.y = playerBeyblade.y; game.addChild(playerWheelTrack); // Create wheel track effect for enemy beyblade var enemyWheelTrack = new WheelTrack(); enemyWheelTrack.x = enemyBeyblade.x; enemyWheelTrack.y = enemyBeyblade.y; game.addChild(enemyWheelTrack); playerBeyblade.update(); enemyBeyblade.update(); if (j2.holdPosition) { j2.x = j1.x; j2.y = j1.y; } // Check for collision with enemyBeyblade if (playerBeyblade.lastWasIntersecting === false && playerBeyblade.intersects(enemyBeyblade)) { // Handle collision console.log("Collision detected between playerBeyblade and enemyBeyblade"); // Create spark effect at the collision point var sparkEffect = new SparkEffect(); sparkEffect.x = (playerBeyblade.x + enemyBeyblade.x) / 2; sparkEffect.y = (playerBeyblade.y + enemyBeyblade.y) / 2; game.addChild(sparkEffect); if (!playerBeyblade.isInvincible) { // Decrease PB1's life by 5% if not invincible playerBeyblade.lifePercentage = Math.max(0, playerBeyblade.lifePercentage - 5); lifeLinePB1.setLifePercentage(playerBeyblade.lifePercentage); lifeLinePB1.visible = true; // Ensure the lifeline for PB1 is visible } } playerBeyblade.lastWasIntersecting = playerBeyblade.intersects(enemyBeyblade); }; // Handle player beyblade movement game.down = function (x, y, obj) { // Move j2 back to the center of j1 j2.x = j1.x; j2.y = j1.y; j2.holdPosition = true; // Set hold position flag }; game.move = function (x, y, obj) { // Calculate the boundaries for j2 within j1 var dx = x - j1.x; var dy = y - j1.y; var distance = Math.sqrt(dx * dx + dy * dy); var radius = j1.width / 2 - j2.width / 2; if (distance > radius) { dx *= radius / distance; dy *= radius / distance; } var lastJ2X = j2.x; // Track last X position of j2 j2.x = j1.x + dx; playerBeyblade.x += (j2.x - lastJ2X) * 10; // Move PB1 based on joystick movement var lastJ2Y = j2.y; // Track last Y position of j2 j2.y = j1.y + dy; playerBeyblade.y += (j2.y - lastJ2Y) * 10; // Move PB1 based on joystick movement j2.holdPosition = false; // Ensure hold position is false during move }; game.up = function (x, y, obj) { // Move j2 back to the center of j1 j2.x = j1.x; j2.y = j1.y; j2.holdPosition = false; // Release hold position flag };
/****
* Classes
****/
var EnemyBeyblade = Container.expand(function () {
var self = Container.call(this);
self.beybladeGraphics = self.attachAsset('PB2', {
anchorX: 0.5,
anchorY: 0.5
});
self.rotationSpeed = 0.1;
self.lifePercentage = 100; // Initialize lifePercentage
self.update = function () {
self.beybladeGraphics.rotation += self.rotationSpeed;
// Move towards playerBeyblade
var directionX = playerBeyblade.x - self.x;
var directionY = playerBeyblade.y - self.y;
var magnitude = Math.sqrt(directionX * directionX + directionY * directionY);
self.x += directionX / magnitude * 2; // Move 2 units per update towards playerBeyblade
self.y += directionY / magnitude * 2; // Move 2 units per update towards playerBeyblade
// Check for collision with PB1 and adjust position to prevent overlap
if (self.intersects(playerBeyblade)) {
// Calculate the overlap distance
var overlapX = (self.x - playerBeyblade.x) / 2;
var overlapY = (self.y - playerBeyblade.y) / 2;
// Adjust positions to resolve overlap
self.x += overlapX;
self.y += overlapY;
playerBeyblade.x -= overlapX;
playerBeyblade.y -= overlapY;
// Check if PB2 has left the arena
var minX = arena.x - arena.arenaGraphics.width / 2 + this.beybladeGraphics.width / 2;
var maxX = arena.x + arena.arenaGraphics.width / 2 - this.beybladeGraphics.width / 2;
var minY = arena.y - arena.arenaGraphics.height / 2 + this.beybladeGraphics.height / 2;
var maxY = arena.y + arena.arenaGraphics.height / 2 - this.beybladeGraphics.height / 2;
if (this.x <= minX || this.x >= maxX || this.y <= minY || this.y >= maxY) {
var winText = new Text2('The player won!', {
size: 200,
fill: 0xFFFFFF
});
winText.anchor.set(0.5, 0.5);
winText.x = 1024; // Center horizontally
winText.y = 1366; // Center vertically
LK.gui.center.addChild(winText);
// Award 1 point to the player
playerScore += 1;
scoreText.setText("Player: ".concat(playerScore, " | Computer: ").concat(computerScore));
// Removed game over trigger when PB2 is defeated
return; // Ensure no further updates occur after game over
}
}
};
});
var LifeLinePB1 = Container.expand(function () {
var self = Container.call(this);
var lifeLineGraphics = self.attachAsset('lifeLinePB1', {
anchorX: 0.5,
anchorY: 0.5
});
self.setLifePercentage = function (percentage) {
lifeLineGraphics.scaleX = percentage / 100;
};
self.setPosition = function (x, y) {
self.x = x;
self.y = y;
};
});
var LifeLinePB2 = Container.expand(function () {
var self = Container.call(this);
var lifeLineGraphics = self.attachAsset('lifeLinePB2', {
anchorX: 0.5,
anchorY: 0.5
});
self.setLifePercentage = function (percentage) {
lifeLineGraphics.scaleX = percentage / 100;
};
self.setPosition = function (x, y) {
self.x = x;
self.y = y;
};
});
var SparkEffect = Container.expand(function () {
var self = Container.call(this);
var sparkGraphics = self.attachAsset('spark', {
anchorX: 0.5,
anchorY: 0.5
});
self.fadeSpeed = 0.05; // Speed at which the spark fades out
self.update = function () {
sparkGraphics.alpha -= self.fadeSpeed;
if (sparkGraphics.alpha <= 0) {
self.destroy();
}
};
});
var WheelTrack = Container.expand(function () {
var self = Container.call(this);
var trackGraphics = self.attachAsset('whirlwind', {
anchorX: 0.5,
anchorY: 0.5
});
self.fadeSpeed = 0.01; // Speed at which the track fades out
self.update = function () {
trackGraphics.alpha -= self.fadeSpeed;
if (trackGraphics.alpha <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
LK.playMusic('arena', {
loop: true
}); // Play arena sound in loop
var enemyBeyblade = new EnemyBeyblade();
enemyBeyblade.lifePercentage = 100; // Start with full life
var lifeLinePB1 = new LifeLinePB1();
lifeLinePB1.visible = true; // Show the lifeline for PB1
lifeLinePB1.setPosition(1024, 2732 - 100); // Center bottom of the map, above PB2 lifeline
game.addChild(lifeLinePB1);
var lifeLinePB2 = new LifeLinePB2();
lifeLinePB2.visible = true; // Show the lifeline for PB2
lifeLinePB2.setPosition(1024, 2732 - 50); // Center bottom of the map
game.addChild(lifeLinePB2);
// Initialize player and enemy beyblades
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Player Beyblade class
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) {
return t;
}
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) {
return i;
}
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _classCallCheck(a, n) {
if (!(a instanceof n)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _callSuper(t, o, e) {
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
}
function _possibleConstructorReturn(t, e) {
if (e && ("object" == _typeof(e) || "function" == typeof e)) {
return e;
}
if (void 0 !== e) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(t);
}
function _assertThisInitialized(e) {
if (void 0 === e) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return e;
}
function _isNativeReflectConstruct() {
try {
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
} catch (t) {}
return (_isNativeReflectConstruct = function _isNativeReflectConstruct() {
return !!t;
})();
}
function _getPrototypeOf(t) {
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
return t.__proto__ || Object.getPrototypeOf(t);
}, _getPrototypeOf(t);
}
function _inherits(t, e) {
if ("function" != typeof e && null !== e) {
throw new TypeError("Super expression must either be null or a function");
}
t.prototype = Object.create(e && e.prototype, {
constructor: {
value: t,
writable: !0,
configurable: !0
}
}), Object.defineProperty(t, "prototype", {
writable: !1
}), e && _setPrototypeOf(t, e);
}
function _setPrototypeOf(t, e) {
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
return t.__proto__ = e, t;
}, _setPrototypeOf(t, e);
}
var Arena = /*#__PURE__*/function (_Container) {
function Arena() {
var _this;
_classCallCheck(this, Arena);
_this = _callSuper(this, Arena);
_this.arenaGraphics = _this.attachAsset('arena', {
anchorX: 0.5,
anchorY: 0.5
});
return _this;
}
_inherits(Arena, _Container);
return _createClass(Arena);
}(Container); // Enemy Beyblade class
var EnemyBeyblade = /*#__PURE__*/function (_Container2) {
function EnemyBeyblade() {
var _this2;
_classCallCheck(this, EnemyBeyblade);
_this2 = _callSuper(this, EnemyBeyblade);
_this2.beybladeGraphics = _this2.attachAsset('PB2', {
anchorX: 0.5,
anchorY: 0.5
});
_this2.rotationSpeed = 0.1;
_this2.lifePercentage = 100; // Initialize lifePercentage
return _this2;
}
_inherits(EnemyBeyblade, _Container2);
return _createClass(EnemyBeyblade, [{
key: "update",
value: function update() {
this.beybladeGraphics.rotation += this.rotationSpeed;
// Move towards playerBeyblade
var directionX = playerBeyblade.x - this.x;
var directionY = playerBeyblade.y - this.y;
var magnitude = Math.sqrt(directionX * directionX + directionY * directionY);
this.x += directionX / magnitude * 2; // Move 2 units per update towards playerBeyblade
this.y += directionY / magnitude * 2; // Move 2 units per update towards playerBeyblade
// Check for collision with PB1 and adjust position to prevent overlap
if (this.lifePercentage <= 0) {
// Award 1 point to the player
playerScore += 1;
scoreText.setText("Player: ".concat(playerScore, " | Computer: ").concat(computerScore));
// Reset the round
playerBeyblade.x = 1024; // Reset player position
playerBeyblade.y = 1366;
playerBeyblade.lifePercentage = 100;
lifeLinePB1.setLifePercentage(playerBeyblade.lifePercentage);
this.x = 1024; // Reset enemy position
this.y = 732;
this.lifePercentage = 100;
lifeLinePB2.setLifePercentage(this.lifePercentage);
return; // Ensure no further updates occur after resetting
}
// Constrain PB2 within the arena boundaries
var minX = arena.x - arena.arenaGraphics.width / 2 + this.beybladeGraphics.width / 2;
var maxX = arena.x + arena.arenaGraphics.width / 2 - this.beybladeGraphics.width / 2;
var minY = arena.y - arena.arenaGraphics.height / 2 + this.beybladeGraphics.height / 2;
var maxY = arena.y + arena.arenaGraphics.height / 2 - this.beybladeGraphics.height / 2;
this.x = Math.max(minX, Math.min(maxX, this.x));
this.y = Math.max(minY, Math.min(maxY, this.y));
if (this.intersects(playerBeyblade)) {
// Calculate the overlap distance
var overlapX = (this.x - playerBeyblade.x) / 2;
var overlapY = (this.y - playerBeyblade.y) / 2;
// Adjust positions to resolve overlap
this.x += overlapX;
this.y += overlapY;
playerBeyblade.x -= overlapX;
playerBeyblade.y -= overlapY;
}
}
}]);
}(Container);
var PB1 = /*#__PURE__*/function (_Container3) {
function PB1() {
var _this3;
_classCallCheck(this, PB1);
_this3 = _callSuper(this, PB1);
_this3.beybladeGraphics = _this3.attachAsset('PB1', {
anchorX: 0.5,
anchorY: 0.5
});
_this3.rotationSpeed = 0.1;
return _this3;
}
_inherits(PB1, _Container3);
return _createClass(PB1, [{
key: "update",
value: function update() {
this.beybladeGraphics.rotation += this.rotationSpeed;
// Check for collision with PB2 and adjust position to prevent overlap
if (this.intersects(enemyBeyblade)) {
// Decrease PB1's life by 5%
this.lifePercentage = Math.max(0, this.lifePercentage - 5);
lifeLinePB1.setLifePercentage(this.lifePercentage);
lifeLinePB1.visible = true; // Ensure the lifeline for PB1 is visible
// Increase hit impact on PB2 if PB1 is invincible
if (this.isInvincible) {
enemyBeyblade.lifePercentage = Math.max(0, enemyBeyblade.lifePercentage - 15); // Increase impact
} else {
enemyBeyblade.lifePercentage = Math.max(0, enemyBeyblade.lifePercentage - 10);
}
lifeLinePB2.setLifePercentage(enemyBeyblade.lifePercentage);
// Calculate the overlap distance
var overlapX = (this.x - enemyBeyblade.x) / 2;
var overlapY = (this.y - enemyBeyblade.y) / 2;
// Adjust positions to resolve overlap
this.x += overlapX;
this.y += overlapY;
enemyBeyblade.x -= overlapX;
enemyBeyblade.y -= overlapY;
}
// Constrain PB1 within the arena boundaries
var minX = arena.x - arena.arenaGraphics.width / 2 + this.beybladeGraphics.width / 2;
var maxX = arena.x + arena.arenaGraphics.width / 2 - this.beybladeGraphics.width / 2;
var minY = arena.y - arena.arenaGraphics.height / 2 + this.beybladeGraphics.height / 2;
var maxY = arena.y + arena.arenaGraphics.height / 2 - this.beybladeGraphics.height / 2;
this.x = Math.max(minX, Math.min(maxX, this.x));
this.y = Math.max(minY, Math.min(maxY, this.y));
// Check if PB1 has left the arena
if (this.x <= minX || this.x >= maxX || this.y <= minY || this.y >= maxY) {
// Reset the round
computerScore += 1;
scoreText.setText("Player: ".concat(playerScore, " | Computer: ").concat(computerScore));
this.x = 1024; // Reset player position
this.y = 1366;
this.lifePercentage = 100;
lifeLinePB1.setLifePercentage(this.lifePercentage);
enemyBeyblade.x = 1024; // Reset enemy position
enemyBeyblade.y = 732;
enemyBeyblade.lifePercentage = 100;
lifeLinePB2.setLifePercentage(enemyBeyblade.lifePercentage);
return; // Ensure no further updates occur after resetting
}
}
}, {
key: "down",
value: function down(x, y, obj) {
this.x = x;
this.y = y;
}
}]);
}(Container);
var wallpaper = game.addChild(LK.getAsset('wallpaper', {
anchorX: 0.5,
anchorY: 0.5
}));
wallpaper.x = 1024; // Center horizontally
wallpaper.y = 1366; // Center vertically
var arena = new Arena();
arena.x = 1024; // Center horizontally
arena.y = 1366; // Center vertically
game.addChild(arena);
var whirlwind = LK.getAsset('whirlwind', {
anchorX: 0.5,
anchorY: 0.5
});
whirlwind.x = 1024; // Center horizontally
whirlwind.y = 1366; // Center vertically
var playerBeyblade = new PB1();
game.addChild(whirlwind);
playerBeyblade.lastWasIntersecting = false;
playerBeyblade.lastWasIntersectingShield = false;
playerBeyblade.x = 1024; // Center horizontally
playerBeyblade.y = 1366; // Center vertically
game.addChild(playerBeyblade);
var enemyBeyblade = new EnemyBeyblade();
enemyBeyblade.x = 1024; // Center horizontally
enemyBeyblade.y = 732; // Position near the top
game.addChild(enemyBeyblade);
var lifeLinePB1 = new LifeLinePB1();
lifeLinePB1.visible = true; // Ensure the lifeline for PB1 is visible like the red lifeline for PB2
lifeLinePB1.setPosition(1024, 2732 - 100); // Center bottom of the map, above PB2 lifeline
game.addChild(lifeLinePB1);
var lifeLinePB2 = new LifeLinePB2();
lifeLinePB2.visible = true; // Show the lifeline for PB2
lifeLinePB2.setPosition(1024, 2732 - 50); // Center bottom of the map
game.addChild(lifeLinePB2);
var j1 = LK.getAsset('j1', {
anchorX: 0.5,
anchorY: 0.5
});
j1.x = j1.width / 2 + 20; // Position at the left and move right by an additional 10 units
j1.y = 2732 - j1.height / 2 - 20; // Move up by an additional 10 units
game.addChild(j1);
var j2 = LK.getAsset('j2', {
anchorX: 0.5,
anchorY: 0.5
});
j2.x = j1.x; // Center j2 horizontally on j1
j2.y = j1.y; // Center j2 vertically on j1
game.addChild(j2);
// Initialize timer variables
var playerScore = 0;
var computerScore = 0;
var scoreText = new Text2('Player: 0 | Computer: 0', {
size: 75,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0); // Align to the top-center
LK.gui.top.addChild(scoreText);
scoreText.setText("Player: ".concat(playerScore, " | Computer: ").concat(computerScore)); // Ensure initial text is set
var timerDuration = 60; // 60 seconds
var timerText = new Text2('01:00', {
size: 100,
fill: 0xFFFFFF
});
timerText.anchor.set(1, 0); // Align to the top-right corner
LK.gui.topRight.addChild(timerText); // Add the timer text to the top-right of the screen
// Update the timer every second
var timerInterval = LK.setInterval(function () {
timerDuration--;
var minutes = Math.floor(timerDuration / 60);
var seconds = timerDuration % 60;
timerText.setText((minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds);
// Check if the timer has reached zero
if (timerDuration <= 0) {
LK.clearInterval(timerInterval);
LK.showGameOver(); // Trigger game over when timer reaches zero
}
}, 1000);
// Game update loop
game.update = function () {
// Create wheel track effect for player beyblade
var playerWheelTrack = new WheelTrack();
playerWheelTrack.x = playerBeyblade.x;
playerWheelTrack.y = playerBeyblade.y;
game.addChild(playerWheelTrack);
// Create wheel track effect for player beyblade
var playerWheelTrack = new WheelTrack();
playerWheelTrack.x = playerBeyblade.x;
playerWheelTrack.y = playerBeyblade.y;
game.addChild(playerWheelTrack);
// Create wheel track effect for enemy beyblade
var enemyWheelTrack = new WheelTrack();
enemyWheelTrack.x = enemyBeyblade.x;
enemyWheelTrack.y = enemyBeyblade.y;
game.addChild(enemyWheelTrack);
playerBeyblade.update();
enemyBeyblade.update();
if (j2.holdPosition) {
j2.x = j1.x;
j2.y = j1.y;
}
// Check for collision with enemyBeyblade
if (playerBeyblade.lastWasIntersecting === false && playerBeyblade.intersects(enemyBeyblade)) {
// Handle collision
console.log("Collision detected between playerBeyblade and enemyBeyblade");
// Create spark effect at the collision point
var sparkEffect = new SparkEffect();
sparkEffect.x = (playerBeyblade.x + enemyBeyblade.x) / 2;
sparkEffect.y = (playerBeyblade.y + enemyBeyblade.y) / 2;
game.addChild(sparkEffect);
if (!playerBeyblade.isInvincible) {
// Decrease PB1's life by 5% if not invincible
playerBeyblade.lifePercentage = Math.max(0, playerBeyblade.lifePercentage - 5);
lifeLinePB1.setLifePercentage(playerBeyblade.lifePercentage);
lifeLinePB1.visible = true; // Ensure the lifeline for PB1 is visible
}
}
playerBeyblade.lastWasIntersecting = playerBeyblade.intersects(enemyBeyblade);
};
// Handle player beyblade movement
game.down = function (x, y, obj) {
// Move j2 back to the center of j1
j2.x = j1.x;
j2.y = j1.y;
j2.holdPosition = true; // Set hold position flag
};
game.move = function (x, y, obj) {
// Calculate the boundaries for j2 within j1
var dx = x - j1.x;
var dy = y - j1.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var radius = j1.width / 2 - j2.width / 2;
if (distance > radius) {
dx *= radius / distance;
dy *= radius / distance;
}
var lastJ2X = j2.x; // Track last X position of j2
j2.x = j1.x + dx;
playerBeyblade.x += (j2.x - lastJ2X) * 10; // Move PB1 based on joystick movement
var lastJ2Y = j2.y; // Track last Y position of j2
j2.y = j1.y + dy;
playerBeyblade.y += (j2.y - lastJ2Y) * 10; // Move PB1 based on joystick movement
j2.holdPosition = false; // Ensure hold position is false during move
};
game.up = function (x, y, obj) {
// Move j2 back to the center of j1
j2.x = j1.x;
j2.y = j1.y;
j2.holdPosition = false; // Release hold position flag
};
Photorealistic Concrete pavement, top view
Simple black circle with transparent background
Simple one black lined circle with transparent background
PHOTOREALISTIC Simple black circular arena with honeycomb pattern. In the center is a neon green circle with a circle colored red along the edge. TOP VIEW.
Blue beyblade, TOP VIEW
Photorealistic Red beyblade, top view
fire sparks
fire spark