User prompt
Add more code
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(796); var healthPercent = self.health / self.maxHealth; __$(797); var energyPercent = self.energy / self.maxEnergy; __$(798); self.healthBar.width = 60 * healthPercent; __$(799); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1578
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(796); var healthPercent = self.health / self.maxHealth; __$(797); var energyPercent = self.energy / self.maxEnergy; __$(798); self.healthBar.width = 60 * healthPercent; __$(799); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1577
User prompt
Fix
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(796); var healthPercent = self.health / self.maxHealth; __$(797); var energyPercent = self.energy / self.maxEnergy; __$(798); self.healthBar.width = 60 * healthPercent; __$(799); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1578
User prompt
Healthbarwith and energy match the players and enemies
User prompt
Health of players and enemies appear above them as well as energy
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(783); var healthPercent = self.health / self.maxHealth; __$(784); var energyPercent = self.energy / self.maxEnergy; __$(785); self.healthBar.width = 60 * healthPercent; __$(786); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1559
User prompt
Remove bug
User prompt
Make it Max health and energy are defined by cards
User prompt
Add object
User prompt
Remove money
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(723); var healthPercent = self.health / self.maxHealth; __$(724); var energyPercent = self.energy / self.maxEnergy; __$(725); self.healthBar.width = 60 * healthPercent; __$(726); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1448
User prompt
Add: 1. **Global Scope Initialization**: Ensure that important variables, instances, arrays, and variables are initialized in the global scope of `gamecode.js`. This ensures they are accessible throughout the game.
2. **Class Separation**: Categorize elements with unique behaviors into separate classes. For example, create distinct classes for 'HeroBullets' and 'EnemyBullets', each with its own asset.
3. **Avoid Direct PIXI Usage**: Do not use PIXI directly. Instead, rely on the LK game engine's classes and methods, which are available in the global scope.
4. **Event Handling**: Use the event object provided to event listeners, accessed via `obj.event`. Avoid using `clientX` or `clientY` for coordinates; instead, use the `x` and `y` variables passed to event methods or `scope.toLocal(obj.global)`.
5. **Touchscreen Compatibility**: Ensure the game is compatible with touchscreen devices by avoiding keyboard inputs or controls.
6. **Asset Retrieval**: Use `LK.getAsset('
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(698); var healthPercent = self.health / self.maxHealth; __$(699); var energyPercent = self.energy / self.maxEnergy; __$(700); self.healthBar.width = 60 * healthPercent; __$(701); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1411
User prompt
Make Health and energy are defined by cards
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(687); var healthPercent = self.health / self.maxHealth; __$(688); var energyPercent = self.energy / self.maxEnergy; __$(689); self.healthBar.width = 60 * healthPercent; __$(690); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1398
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(683); var healthPercent = self.health / self.maxHealth; __$(684); var energyPercent = self.energy / self.maxEnergy; __$(685); self.healthBar.width = 60 * healthPercent; __$(686); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1394
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(681); var healthPercent = self.health / self.maxHealth; __$(682); var energyPercent = self.energy / self.maxEnergy; __$(683); self.healthBar.width = 60 * healthPercent; __$(684); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1392
User prompt
Add: All the money goes to Wondertainment Products
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(679); var healthPercent = self.health / self.maxHealth; __$(680); var energyPercent = self.energy / self.maxEnergy; __$(681); self.healthBar.width = 60 * healthPercent; __$(682); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1390
User prompt
Add: randomscp
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(653); var healthPercent = self.health / self.maxHealth; __$(654); var energyPercent = self.energy / self.maxEnergy; __$(655); self.healthBar.width = 60 * healthPercent; __$(656); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1340
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(652); var healthPercent = self.health / self.maxHealth; __$(653); var energyPercent = self.energy / self.maxEnergy; __$(654); self.healthBar.width = 60 * healthPercent; __$(655); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1339
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'self.updateBars = function () { __$(650); var healthPercent = self.health / self.maxHealth; __$(651); var energyPercent = self.energy / self.maxEnergy; __$(652); self.healthBar.width = 60 * healthPercent; __$(653); self.energyBar.width = 60 * energyPercent; }')' in or related to this line: 'self.updateBars = function () {' Line Number: 1337
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0, playerLevel: 1, containedAnomalies: 0 }); /**** * Classes ****/ var Button = Container.expand(function () { var self = Container.call(this); self.background = self.attachAsset('button', { anchorX: 0.5, anchorY: 0.5 }); self.text = new Text2('Button', { size: 24, fill: 0xFFFFFF }); self.text.anchor.set(0.5, 0.5); self.addChild(self.text); self.setText = function (text) { self.text.setText(text); }; self.setCallback = function (callback) { self.callback = callback; }; self.down = function (x, y, obj) { tween(self, { scaleX: 0.95, scaleY: 0.95 }, { duration: 100, easing: tween.easeOut }); }; self.up = function (x, y, obj) { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeOut }); if (self.callback) { self.callback(); } }; return self; }); var Card = Container.expand(function () { var self = Container.call(this); // Card properties self.cardType = 'none'; self.cardName = ''; self.cardDescription = ''; self.power = 0; self.cost = 0; self.revealed = false; // Card visuals self.back = self.attachAsset('cardBack', { anchorX: 0.5, anchorY: 0.5 }); self.front = self.attachAsset('cardFront', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); self.nameText = new Text2('', { size: 20, fill: 0x000000 }); self.nameText.anchor.set(0.5, 0); self.nameText.y = -70; self.addChild(self.nameText); self.descriptionText = new Text2('', { size: 16, fill: 0x000000 }); self.descriptionText.anchor.set(0.5, 0); self.descriptionText.y = 0; self.descriptionText.alpha = 0; self.addChild(self.descriptionText); self.powerText = new Text2('', { size: 24, fill: 0xFF0000 }); self.powerText.anchor.set(0.5, 0.5); self.powerText.x = 50; self.powerText.y = 70; self.powerText.alpha = 0; self.addChild(self.powerText); self.costText = new Text2('', { size: 24, fill: 0x0000FF }); self.costText.anchor.set(0.5, 0.5); self.costText.x = -50; self.costText.y = 70; self.costText.alpha = 0; self.addChild(self.costText); // Initialize a card with data self.init = function (data) { self.cardType = data.type; self.cardName = data.name; self.cardDescription = data.description; self.power = data.power || 0; self.cost = data.cost || 0; self.nameText.setText(self.cardName); self.descriptionText.setText(self.cardDescription); self.powerText.setText(self.power.toString()); self.costText.setText(self.cost.toString()); }; // Flip the card to reveal front self.reveal = function () { if (!self.revealed) { tween(self.back, { alpha: 0 }, { duration: 300, easing: tween.easeInOut }); tween(self.front, { alpha: 1 }, { duration: 300, easing: tween.easeInOut }); tween(self.descriptionText, { alpha: 1 }, { duration: 300, easing: tween.easeInOut }); tween(self.powerText, { alpha: 1 }, { duration: 300, easing: tween.easeInOut }); tween(self.costText, { alpha: 1 }, { duration: 300, easing: tween.easeInOut }); self.revealed = true; } }; // Flip card back self.hide = function () { if (self.revealed) { tween(self.back, { alpha: 1 }, { duration: 300, easing: tween.easeInOut }); tween(self.front, { alpha: 0 }, { duration: 300, easing: tween.easeInOut }); tween(self.descriptionText, { alpha: 0 }, { duration: 300, easing: tween.easeInOut }); tween(self.powerText, { alpha: 0 }, { duration: 300, easing: tween.easeInOut }); tween(self.costText, { alpha: 0 }, { duration: 300, easing: tween.easeInOut }); self.revealed = false; } }; // Card interaction events self.down = function (x, y, obj) { tween(self, { scaleX: 1.1, scaleY: 1.1 }, { duration: 100, easing: tween.easeOut }); }; self.up = function (x, y, obj) { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeOut }); if (!self.revealed) { self.reveal(); LK.getSound('cardDraw').play(); } // Trigger card selection in the game if (typeof cardSelected === 'function') { cardSelected(self); } }; return self; }); var Entity = Container.expand(function () { var self = Container.call(this); // Entity properties self.entityType = 'none'; self.health = 100; self.maxHealth = 100; self.energy = 100; self.maxEnergy = 100; self.power = 10; self.moveRange = 3; self.boardX = 0; self.boardY = 0; self.isMoving = false; self.isPlayer = false; // Entity visuals self.graphic = null; self.healthBarBg = self.attachAsset('barBackground', { anchorX: 0.5, anchorY: 0.5, y: -45 }); self.healthBar = self.attachAsset('healthBar', { anchorX: 0, anchorY: 0.5, x: -30, y: -45 }); self.energyBarBg = self.attachAsset('barBackground', { anchorX: 0.5, anchorY: 0.5, y: -35 }); self.energyBar = self.attachAsset('energyBar', { anchorX: 0, anchorY: 0.5, x: -30, y: -35 }); self.nameText = new Text2('', { size: 16, fill: 0xFFFFFF }); self.nameText.anchor.set(0.5, 1); self.nameText.y = -50; self.addChild(self.nameText); // Initialize entity with data self.init = function (data, isPlayerEntity) { self.entityType = data.type; self.health = data.health || 100; self.maxHealth = data.maxHealth || 100; self.energy = data.energy || 100; self.maxEnergy = data.maxEnergy || 100; self.power = data.power || 10; self.moveRange = data.moveRange || 3; self.isPlayer = isPlayerEntity || false; // Set up appropriate graphic based on type if (self.isPlayer) { self.graphic = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); } else if (self.entityType === 'opponent') { self.graphic = self.attachAsset('opponent', { anchorX: 0.5, anchorY: 0.5 }); } else if (self.entityType === 'anomaly') { self.graphic = self.attachAsset('anomaly', { anchorX: 0.5, anchorY: 0.5 }); } self.nameText.setText(data.name || self.entityType); self.healthBar = self.attachAsset('healthBar', { anchorX: 0, anchorY: 0.5, x: -30, y: -45 }); self.energyBar = self.attachAsset('energyBar', { anchorX: 0, anchorY: 0.5, x: -30, y: -35 }); self.updateBars(); self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization }; // Update health and energy bars self.updateBars = function () { var healthPercent = self.health / self.maxHealth; var energyPercent = self.energy / self.maxEnergy; self.healthBar.width = 60 * healthPercent; self.energyBar.width = 60 * energyPercent; }; // Take damage self.takeDamage = function (amount) { self.health -= amount; if (self.health <= 0) { self.health = 0; self.die(); } self.updateBars(); LK.effects.flashObject(self, 0xff0000, 300); }; // Use energy self.useEnergy = function (amount) { if (self.energy >= amount) { self.energy -= amount; self.updateBars(); return true; } return false; }; // Restore health self.heal = function (amount) { self.health += amount; if (self.health > self.maxHealth) { self.health = self.maxHealth; } self.updateBars(); LK.effects.flashObject(self, 0x00ff00, 300); }; // Restore energy self.restoreEnergy = function (amount) { self.energy += amount; if (self.energy > self.maxEnergy) { self.energy = self.maxEnergy; } self.updateBars(); LK.effects.flashObject(self, 0x0088ff, 300); }; // Move to a board position self.moveToPosition = function (boardX, boardY) { if (self.isMoving) { return; } self.isMoving = true; self.boardX = boardX; self.boardY = boardY; var targetX = BOARD_OFFSET_X + boardX * TILE_SIZE + TILE_SIZE / 2; var targetY = BOARD_OFFSET_Y + boardY * TILE_SIZE + TILE_SIZE / 2; tween(self, { x: targetX, y: targetY }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { self.isMoving = false; LK.getSound('playerMove').play(); // Check for anomaly at this position checkForAnomalyAtPosition(boardX, boardY); } }); }; // Attack another entity self.attack = function (target) { if (!target) { return; } if (self.useEnergy(20)) { LK.getSound('playerAttack').play(); // Animation var originalX = self.x; var originalY = self.y; var targetX = target.x; var targetY = target.y; // Move towards target tween(self, { x: originalX + (targetX - originalX) * 0.7, y: originalY + (targetY - originalY) * 0.7 }, { duration: 200, easing: tween.easeIn, onFinish: function onFinish() { // Apply damage target.takeDamage(self.power); // Move back tween(self, { x: originalX, y: originalY }, { duration: 300, easing: tween.easeOut }); } }); } }; // Die function self.die = function () { tween(self, { alpha: 0, scaleX: 0.5, scaleY: 0.5 }, { duration: 500, easing: tween.easeIn, onFinish: function onFinish() { self.destroy(); // Handle secondary player death and reappearance if (self.isPlayer) { console.log("Secondary player has died and will reappear outside the distortion"); } if (self.entityType === 'anomaly') { containAnomaly(self); } // Check if game is over checkGameState(); } }); }; // Entity interaction events self.down = function (x, y, obj) { if (gameState !== GAME_STATE.PLAYER_TURN) { return; } if (self.isPlayer) { // Select the player selectEntity(self); } else if (selectedEntity && selectedEntity.isPlayer) { // If player is selected and this is another entity, try to attack var dx = Math.abs(selectedEntity.boardX - self.boardX); var dy = Math.abs(selectedEntity.boardY - self.boardY); if (dx <= 1 && dy <= 1) { selectedEntity.attack(self); endPlayerTurn(); } } }; return self; }); var Highlight = Container.expand(function () { var self = Container.call(this); self.graphic = self.attachAsset('highlight', { anchorX: 0.5, anchorY: 0.5, alpha: 0.3 }); self.boardX = 0; self.boardY = 0; self.setPosition = function (bx, by) { self.boardX = bx; self.boardY = by; self.x = BOARD_OFFSET_X + bx * TILE_SIZE + TILE_SIZE / 2; self.y = BOARD_OFFSET_Y + by * TILE_SIZE + TILE_SIZE / 2; }; self.down = function (x, y, obj) { if (gameState !== GAME_STATE.PLAYER_TURN || !selectedEntity || !selectedEntity.isPlayer) { return; } // Calculate the distance between selected entity and this highlight var dx = Math.abs(selectedEntity.boardX - self.boardX); var dy = Math.abs(selectedEntity.boardY - self.boardY); var distance = Math.max(dx, dy); // Check if we can move there if (distance <= selectedEntity.moveRange) { // Check if the destination is empty if (isTileEmpty(self.boardX, self.boardY)) { selectedEntity.moveToPosition(self.boardX, self.boardY); clearHighlights(); endPlayerTurn(); } } }; return self; }); var MoneyCounter = Container.expand(function () { var self = Container.call(this); self.text = new Text2('Money: $0', { size: 40, fill: 0xFFFF00 }); self.text.anchor.set(0.5, 0); self.addChild(self.text); self.updateDisplay = function (amount) { self.text.setText('Money: $' + amount); }; return self; }); var RandomOpponent = Container.expand(function () { var self = Container.call(this); self.init = function () { self.entityType = 'randomOpponent'; self.health = Math.floor(Math.random() * 100) + 50; self.maxHealth = self.health; self.energy = Math.floor(Math.random() * 50) + 50; self.maxEnergy = self.energy; self.power = Math.floor(Math.random() * 20) + 10; self.moveRange = Math.floor(Math.random() * 3) + 1; self.graphic = self.attachAsset('RandomOpponent', { anchorX: 0.5, anchorY: 0.5 }); self.updateBars = function () { if (!self.healthBar) { self.healthBar = self.attachAsset('healthBar', { anchorX: 0, anchorY: 0.5, x: -30, y: -45 }); } if (!self.energyBar) { self.energyBar = self.attachAsset('energyBar', { anchorX: 0, anchorY: 0.5, x: -30, y: -35 }); } var healthPercent = self.health / self.maxHealth; var energyPercent = self.energy / self.maxEnergy; self.healthBar.width = 60 * healthPercent; self.energyBar.width = 60 * energyPercent; self.lastHealth = self.health; // Initialize lastHealth self.lastEnergy = self.energy; // Initialize lastEnergy }; self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.healthBar = self.attachAsset('healthBar', { anchorX: 0, anchorY: 0.5, x: -30, y: -45 }); self.energyBar = self.attachAsset('energyBar', { anchorX: 0, anchorY: 0.5, x: -30, y: -35 }); self.updateBars(); }; return self; }); var RandomSCP = Container.expand(function () { var self = Container.call(this); self.init = function () { self.entityType = 'randomSCP'; self.health = Math.floor(Math.random() * 100) + 50; self.maxHealth = self.health; self.energy = Math.floor(Math.random() * 50) + 50; self.maxEnergy = self.energy; self.power = Math.floor(Math.random() * 20) + 10; self.moveRange = Math.floor(Math.random() * 3) + 1; self.graphic = self.attachAsset('RandomSCP', { anchorX: 0.5, anchorY: 0.5 }); self.updateBars = function () { if (!self.healthBar) { self.healthBar = self.attachAsset('healthBar', { anchorX: 0, anchorY: 0.5, x: -30, y: -45 }); } if (!self.energyBar) { self.energyBar = self.attachAsset('energyBar', { anchorX: 0, anchorY: 0.5, x: -30, y: -35 }); } var healthPercent = self.health / self.maxHealth; var energyPercent = self.energy / self.maxEnergy; self.healthBar.width = 60 * healthPercent; self.energyBar.width = 60 * energyPercent; self.lastHealth = self.health; // Initialize lastHealth self.lastEnergy = self.energy; // Initialize lastEnergy }; self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization self.updateBars(); // Ensure updateBars is called after initialization }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Game rules as described in the manual var gameRules = ["No hits below the belt.", "Targeting will result in a 15 yard penalty and a loss of downs.", "Drink your Ovaltine.", "Suspend your disbelief a little bit.", "This isn’t a game for children, so kids who play it are really cool.", "Leave your loyalties at the door.", "Buy Wondertainment products."]; // Discard a card from the player's hand function discardCard() { if (playerHand.length > 0) { var card = playerHand.pop(); card.destroy(); } } // Draw a card for the opponent function drawOpponentCard() { if (opponentHand.length >= 5 || cardsInDeck <= 0) { return; } cardsInDeck--; var cardType = cardTypes[Math.floor(Math.random() * cardTypes.length)]; var card = new Card(); card.init(cardType); opponentHand.push(card); } // Game constants var BOARD_SIZE = 8; var TILE_SIZE = 120; var BOARD_OFFSET_X = (2048 - BOARD_SIZE * TILE_SIZE) / 2; var BOARD_OFFSET_Y = (2732 - BOARD_SIZE * TILE_SIZE) / 2 - 100; var GAME_STATE = { SETUP: 0, PLAYER_TURN: 1, OPPONENT_TURN: 2, GAME_OVER: 3 }; // Money counter var moneyCounter = 0; var moneyCounterDisplay; // Define moneyCounterDisplay in the global scope // Game variables var gameBoard = []; var gameState = GAME_STATE.SETUP; var playerEntities = []; var opponentEntities = []; var anomalies = []; var selectedEntity = null; var highlights = []; var cards = []; var score = 0; var turnCounter = 0; var playerHand = []; // Initialize player card hand in global scope var opponentHand = []; // Initialize opponent card hand in global scope var cardsInDeck = 20; // Game board and UI var boardGraphic = game.addChild(LK.getAsset('board', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: BOARD_OFFSET_Y + BOARD_SIZE * TILE_SIZE / 2 })); boardGraphic.width = BOARD_SIZE * TILE_SIZE; boardGraphic.height = BOARD_SIZE * TILE_SIZE; // Score text var scoreTxt = new Text2('Score: 0', { size: 50, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); scoreTxt.y = 20; // Turn indicator var turnTxt = new Text2('Player Turn', { size: 40, fill: 0xFFFFFF }); turnTxt.anchor.set(0.5, 0); LK.gui.top.addChild(turnTxt); turnTxt.y = 80; // Draw card button var drawCardBtn = new Button(); drawCardBtn.setText('Draw Card (' + cardsInDeck + ')'); drawCardBtn.x = 2048 - 150; drawCardBtn.y = 2732 - 100; game.addChild(drawCardBtn); drawCardBtn.setCallback(function () { if (gameState === GAME_STATE.PLAYER_TURN && playerHand.length < 5 && cardsInDeck > 0) { drawCard(); } }); // End turn button var endTurnBtn = new Button(); endTurnBtn.setText('End Turn'); endTurnBtn.x = 150; endTurnBtn.y = 2732 - 100; game.addChild(endTurnBtn); endTurnBtn.setCallback(function () { if (gameState === GAME_STATE.PLAYER_TURN) { endPlayerTurn(); } }); // Card deck initialization var cardTypes = [{ type: 'ability', name: 'Psychic Shield', description: 'Increase defense for 2 turns', power: 15, cost: 25 }, { type: 'weapon', name: 'Anomaly Neutralizer', description: 'Deal extra damage to anomalies', power: 30, cost: 40 }, { type: 'equipment', name: 'Energy Booster', description: 'Restore energy', power: 50, cost: 15 }, { type: 'ability', name: 'Containment Field', description: 'Trap anomalies for easy capture', power: 25, cost: 35 }, { type: 'weapon', name: 'Tactical Rifle', description: 'Medium range attack', power: 20, cost: 30 }]; // Initialize game board function initBoard() { gameBoard = []; // Randomly select a board setting var boardSettings = ['The Land of the Unclean', 'Echoes of the Mariana', 'Bigfoot’s Jungle', 'The Cosmic Starfish']; var selectedSetting = boardSettings[Math.floor(Math.random() * boardSettings.length)]; console.log("Selected Board Setting: " + selectedSetting); for (var y = 0; y < BOARD_SIZE; y++) { gameBoard[y] = []; for (var x = 0; x < BOARD_SIZE; x++) { gameBoard[y][x] = { entities: [], type: 'empty' }; } } // Initialize hostile entities based on the selected setting initHostileEntities(selectedSetting); } // Check if a tile is empty function isTileEmpty(x, y) { if (x < 0 || x >= BOARD_SIZE || y < 0 || y >= BOARD_SIZE) { return false; } // Check for any entities on this tile for (var i = 0; i < playerEntities.length; i++) { if (playerEntities[i].boardX === x && playerEntities[i].boardY === y) { return false; } } for (var i = 0; i < opponentEntities.length; i++) { if (opponentEntities[i].boardX === x && opponentEntities[i].boardY === y) { return false; } } for (var i = 0; i < anomalies.length; i++) { if (anomalies[i].boardX === x && anomalies[i].boardY === y) { return false; } } return true; } // Initialize player entity function initPlayerEntity() { // Initialize primary players and their representatives for (var i = 0; i < 2; i++) { var player = new Entity(); player.init({ type: 'player', name: 'SCP Agent ' + (i + 1), health: 150, maxHealth: 150, energy: 100, maxEnergy: 100, power: 25, moveRange: 3 }, true); player.boardX = i; player.boardY = 0; player.x = BOARD_OFFSET_X + player.boardX * TILE_SIZE + TILE_SIZE / 2; player.y = BOARD_OFFSET_Y + player.boardY * TILE_SIZE + TILE_SIZE / 2; game.addChild(player); playerEntities.push(player); } } // Initialize opponent entities function initOpponents() { // Create 2 random opponents for (var i = 0; i < 2; i++) { var opponent = new RandomOpponent(); opponent.init(); // Place opponents on the opposite side opponent.boardX = BOARD_SIZE - 1 - i; opponent.boardY = BOARD_SIZE - 1; opponent.x = BOARD_OFFSET_X + opponent.boardX * TILE_SIZE + TILE_SIZE / 2; opponent.y = BOARD_OFFSET_Y + opponent.boardY * TILE_SIZE + TILE_SIZE / 2; game.addChild(opponent); opponentEntities.push(opponent); } } // Initialize anomalies function initAnomalies() { // Create 4 anomalies and 1 Wondertainment product for (var i = 0; i < 5; i++) { var anomaly = new Entity(); if (i === 4) { anomaly.init({ type: 'wondertainment', name: 'Wondertainment Product', health: 50, maxHealth: 50, energy: 30, maxEnergy: 30, power: 10, moveRange: 1 }); } else { anomaly.init({ type: 'anomaly', name: 'SCP-' + (Math.floor(Math.random() * 899) + 100), health: 80, maxHealth: 80, energy: 50, maxEnergy: 50, power: 15, moveRange: 1 }); } // Find a random empty position for the anomaly var randomX, randomY; do { randomX = Math.floor(Math.random() * BOARD_SIZE); randomY = Math.floor(Math.random() * BOARD_SIZE); } while (!isTileEmpty(randomX, randomY)); anomaly.boardX = randomX; anomaly.boardY = randomY; anomaly.x = BOARD_OFFSET_X + anomaly.boardX * TILE_SIZE + TILE_SIZE / 2; anomaly.y = BOARD_OFFSET_Y + anomaly.boardY * TILE_SIZE + TILE_SIZE / 2; game.addChild(anomaly); anomalies.push(anomaly); } } // Show movement highlights function showMovementHighlights() { if (!selectedEntity) { return; } clearHighlights(); var range = selectedEntity.moveRange; for (var y = 0; y < BOARD_SIZE; y++) { for (var x = 0; x < BOARD_SIZE; x++) { var dx = Math.abs(selectedEntity.boardX - x); var dy = Math.abs(selectedEntity.boardY - y); var dist = Math.max(dx, dy); if (dist <= range) { var highlight = new Highlight(); highlight.setPosition(x, y); game.addChild(highlight); highlights.push(highlight); } } } } // Clear highlights function clearHighlights() { for (var i = 0; i < highlights.length; i++) { highlights[i].destroy(); } highlights = []; } // Select an entity function selectEntity(entity) { // Deselect previous entity if (selectedEntity) { tween(selectedEntity, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeOut }); } // Select new entity selectedEntity = entity; if (selectedEntity) { tween(selectedEntity, { scaleX: 1.1, scaleY: 1.1 }, { duration: 100, easing: tween.easeOut }); showMovementHighlights(); } } // Draw a card function drawCard() { if (playerHand.length >= 5 || cardsInDeck <= 0) { return; } cardsInDeck--; drawCardBtn.setText('Draw Card (' + cardsInDeck + ')'); var cardType = cardTypes[Math.floor(Math.random() * cardTypes.length)]; var card = new Card(); card.init(cardType); card.x = 2048 / 2; card.y = 2732 - 150; // Position cards in hand var cardSpacing = 170; var handWidth = (playerHand.length + 1) * cardSpacing; var startX = (2048 - handWidth) / 2 + cardSpacing / 2; card.x = startX + playerHand.length * cardSpacing; game.addChild(card); playerHand.push(card); LK.getSound('cardDraw').play(); } // Use a card function cardSelected(card) { if (gameState !== GAME_STATE.PLAYER_TURN || !selectedEntity || !selectedEntity.isPlayer) { return; } // Apply card effect if (card.cardType === 'ability') { selectedEntity.restoreEnergy(card.power); } else if (card.cardType === 'weapon') { selectedEntity.power += card.power; // Temporary power boost LK.setTimeout(function () { selectedEntity.power -= card.power; }, 5000); } else if (card.cardType === 'equipment') { selectedEntity.heal(card.power); } // Remove card from hand var index = playerHand.indexOf(card); if (index !== -1) { playerHand.splice(index, 1); card.destroy(); // Reorganize hand var cardSpacing = 170; var handWidth = playerHand.length * cardSpacing; var startX = (2048 - handWidth) / 2 + cardSpacing / 2; for (var i = 0; i < playerHand.length; i++) { tween(playerHand[i], { x: startX + i * cardSpacing }, { duration: 300, easing: tween.easeInOut }); } } } // Check for anomaly at position function checkForAnomalyAtPosition(x, y) { for (var i = 0; i < anomalies.length; i++) { if (anomalies[i].boardX === x && anomalies[i].boardY === y) { // Initiate containment var anomaly = anomalies[i]; // Lower health to make containment easier for demo anomaly.takeDamage(40); if (anomaly.health <= 0) { if (anomaly.entityType === 'wondertainment') { console.log("Collected a Wondertainment product!"); playerEntities[0].hasContainedWondertainmentProduct = true; console.log("All the money goes to Wondertainment Products"); } // Increase money counter when an anomaly is contained moneyCounter += 50; moneyCounterDisplay.updateDisplay(moneyCounter); containAnomaly(anomaly); } } } } // Contain an anomaly function containAnomaly(anomaly) { LK.getSound('anomalyContain').play(); var index = anomalies.indexOf(anomaly); if (index !== -1) { anomalies.splice(index, 1); // Increase score score += 100; scoreTxt.setText('Score: ' + score); // Update stored anomaly count storage.containedAnomalies = (storage.containedAnomalies || 0) + 1; // Check if all anomalies are contained if (anomalies.length === 0) { // Win condition LK.setScore(score); if (score > storage.highScore) { storage.highScore = score; } LK.showYouWin(); } } } // End player turn function endPlayerTurn() { if (gameState !== GAME_STATE.PLAYER_TURN) { return; } // Draw a card at the end of the turn drawCard(); // Discard if more than 10 cards if (playerHand.length > 10) { discardCard(); } gameState = GAME_STATE.OPPONENT_TURN; turnTxt.setText('Opponent Turn'); clearHighlights(); selectEntity(null); // Opponent turn timer LK.setTimeout(executeOpponentTurn, 1000); } // Execute opponent turn function executeOpponentTurn() { // Process each opponent for (var i = 0; i < opponentEntities.length; i++) { var opponent = opponentEntities[i]; // Find nearest target (player or anomaly) var target = null; var minDist = 999; // Check player entities for (var j = 0; j < playerEntities.length; j++) { var dx = Math.abs(opponent.boardX - playerEntities[j].boardX); var dy = Math.abs(opponent.boardY - playerEntities[j].boardY); var dist = dx + dy; if (dist < minDist) { minDist = dist; target = playerEntities[j]; } } // Take action based on distance if (target) { if (minDist <= 1) { // Attack if adjacent LK.setTimeout(function (attacker, defender) { return function () { attacker.attack(defender); }; }(opponent, target), 500 * i); } else { // Move toward target var moveX = opponent.boardX; var moveY = opponent.boardY; if (target.boardX > opponent.boardX) { moveX++; } else if (target.boardX < opponent.boardX) { moveX--; } if (target.boardY > opponent.boardY) { moveY++; } else if (target.boardY < opponent.boardY) { moveY--; } // Check if the tile is empty if (isTileEmpty(moveX, moveY)) { LK.setTimeout(function (entity, x, y) { return function () { entity.moveToPosition(x, y); }; }(opponent, moveX, moveY), 500 * i); } } } } // Process each anomaly (simple random movement) for (var i = 0; i < anomalies.length; i++) { var anomaly = anomalies[i]; // Random movement var directions = [{ x: 1, y: 0 }, { x: -1, y: 0 }, { x: 0, y: 1 }, { x: 0, y: -1 }]; var validMoves = []; for (var j = 0; j < directions.length; j++) { var moveX = anomaly.boardX + directions[j].x; var moveY = anomaly.boardY + directions[j].y; if (moveX >= 0 && moveX < BOARD_SIZE && moveY >= 0 && moveY < BOARD_SIZE && isTileEmpty(moveX, moveY)) { validMoves.push({ x: moveX, y: moveY }); } } if (validMoves.length > 0) { var randomMove = validMoves[Math.floor(Math.random() * validMoves.length)]; LK.setTimeout(function (entity, x, y) { return function () { entity.moveToPosition(x, y); }; }(anomaly, randomMove.x, randomMove.y), 1000 + 300 * i); } } // End opponent turn after all moves LK.setTimeout(startPlayerTurn, 2000); } // Start player turn function startPlayerTurn() { gameState = GAME_STATE.PLAYER_TURN; turnTxt.setText('Player Turn'); turnCounter++; // Restore energy for player entities for (var i = 0; i < playerEntities.length; i++) { playerEntities[i].restoreEnergy(20); } // Check game state checkGameState(); } // Check game state function checkGameState() { // Check if all anomalies are contained // Check for MR. SURVIVOR victory condition if (playerEntities.length === 1 && !playerEntities[0].hasMetOtherWinConditions) { console.log("Victory Condition: MR. SURVIVOR"); LK.showYouWin(); return; } // Check for MR. FOUNDATION victory condition if (playerEntities.some(function (player) { return player.hasContainedAllEntitiesAndPlayers; })) { console.log("Victory Condition: MR. FOUNDATION"); LK.showYouWin(); return; } // Check for MR. CONTAINMENT victory condition if (playerEntities.some(function (player) { return player.hasContainedMajorityAnomalies; })) { console.log("Victory Condition: MR. CONTAINMENT"); LK.showYouWin(); return; } // Check for MR. COALITION victory condition if (playerEntities.some(function (player) { return player.hasDestroyedMajorityAnomalies; })) { console.log("Victory Condition: MR. COALITION"); LK.showYouWin(); return; } // Check for MR. ESCHATOLOGY victory condition if (playerEntities.some(function (player) { return player.hasSummonedThreeSupremeDivineBeings; })) { console.log("Victory Condition: MR. ESCHATOLOGY"); LK.showYouWin(); return; } // Check for MR. GENOCIDE victory condition if (playerEntities.some(function (player) { return player.hasKilledAllPlayers; })) { console.log("Victory Condition: MR. GENOCIDE"); LK.showYouWin(); return; } // Check for MR. COLLECTOR victory condition if (playerEntities.some(function (player) { return player.hasContainedWondertainmentProduct; })) { console.log("Victory Condition: MR. COLLECTOR"); LK.showYouWin(); return; } // Check for MR. FINDER victory condition if (playerEntities.some(function (player) { return player.hasFoundAnomalousItem; })) { console.log("Victory Condition: MR. FINDER"); LK.showYouWin(); return; } if (playerEntities.length === 0) { LK.setScore(score); LK.showGameOver(); return; } // Check if all opponents are defeated if (opponentEntities.length === 0) { score += 500; scoreTxt.setText('Score: ' + score); LK.setScore(score); if (score > storage.highScore) { storage.highScore = score; } LK.showYouWin(); return; } // Check if maximum turns reached if (turnCounter >= 30) { LK.setScore(score); if (score > storage.highScore) { storage.highScore = score; } LK.showGameOver(); return; } } // Initialize game function initGame() { // Clear everything clearHighlights(); for (var i = 0; i < playerEntities.length; i++) { playerEntities[i].destroy(); } playerEntities = []; for (var i = 0; i < opponentEntities.length; i++) { opponentEntities[i].destroy(); } opponentEntities = []; for (var i = 0; i < anomalies.length; i++) { anomalies[i].destroy(); } anomalies = []; for (var i = 0; i < playerHand.length; i++) { playerHand[i].destroy(); } playerHand = []; for (var i = 0; i < opponentHand.length; i++) { opponentHand[i].destroy(); } opponentHand = []; // Reset money counter moneyCounter = 0; if (moneyCounterDisplay) { moneyCounterDisplay.updateDisplay(moneyCounter); } // Setup variables score = 0; scoreTxt.setText('Score: ' + score); turnCounter = 0; gameState = GAME_STATE.SETUP; selectedEntity = null; cardsInDeck = 20; drawCardBtn.setText('Draw Card (' + cardsInDeck + ')'); // Add money counter display moneyCounterDisplay = new MoneyCounter(); moneyCounterDisplay.x = 2048 / 2; moneyCounterDisplay.y = 150; LK.gui.top.addChild(moneyCounterDisplay); // Initialize game elements initBoard(); initPlayerEntity(); initOpponents(); initAnomalies(); // Add spatial distortion effect console.log("Applying spatial distortion effect to the game area"); // Start game gameState = GAME_STATE.PLAYER_TURN; turnTxt.setText('Player Turn'); // Draw initial cards for player and opponent for (var i = 0; i < 7; i++) { drawCard(); drawOpponentCard(); } // Play background music LK.playMusic('bgmusic', { loop: true }); } // Game navigation game.down = function (x, y, obj) { // Empty handler for board clicks not handled by entities }; game.move = function (x, y, obj) { // Empty handler for mouse movement }; // Main game loop game.update = function () { // Initialize game if we're in setup if (gameState === GAME_STATE.SETUP) { initGame(); } }; // Start the game initGame(); function initHostileEntities(setting) { switch (setting) { case 'The Land of the Unclean': // Initialize specific entities for this setting console.log("Initializing entities for The Land of the Unclean"); break; case 'Echoes of the Mariana': // Initialize specific entities for this setting console.log("Initializing entities for Echoes of the Mariana"); break; case 'Bigfoot’s Jungle': // Initialize specific entities for this setting console.log("Initializing entities for Bigfoot’s Jungle"); break; case 'The Cosmic Starfish': // Initialize specific entities for this setting console.log("Initializing entities for The Cosmic Starfish"); break; default: console.log("Unknown setting"); } } self.updateBars = function () { var healthPercent = self.health / self.maxHealth; var energyPercent = self.energy / self.maxEnergy; self.healthBar.width = 60 * healthPercent; self.energyBar.width = 60 * energyPercent; };
===================================================================
--- original.js
+++ change.js
@@ -610,8 +610,9 @@
self.updateBars(); // Ensure updateBars is called after initialization
self.updateBars(); // Ensure updateBars is called after initialization
self.updateBars(); // Ensure updateBars is called after initialization
self.updateBars(); // Ensure updateBars is called after initialization
+ self.updateBars(); // Ensure updateBars is called after initialization
};
return self;
});
Healthbar. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Player. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Opponent. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
EnergyBar. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Board. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Anomaly. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
animal. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
SCP. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
SCP card. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
anomalyneutralizer card. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
containmentfield card. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
cardFront. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
barBackground. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
darknessbetweendimensions. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
manual. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
moneyCounterDisplay. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Wondertainment product. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
EndTurnButton. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
randomscp. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Attack. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Containment. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
White Card called “Panacea” which was used to heal. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
modified Colt AR-15. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
giant flaming angel's sword. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
hidden golden anomaly. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Orangutan. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows