/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 1.0 }); self.health = 50; self.maxHealth = 50; self.moveSpeed = 1; self.attackCooldown = 0; self.isAttacking = false; self.direction = 1; // 1 for right, -1 for left self.attackRange = 120; self.update = function () { // Move towards hero var distanceToHero = Math.abs(self.x - hero.x); if (distanceToHero > self.attackRange) { if (self.x < hero.x) { self.x += self.moveSpeed; self.direction = 1; enemyGraphics.scaleX = 1; // Face right } else { self.x -= self.moveSpeed; self.direction = -1; enemyGraphics.scaleX = -1; // Face left } } else { // Attack hero if (self.attackCooldown <= 0) { self.attack(); self.attackCooldown = 90; } } if (self.attackCooldown > 0) { self.attackCooldown--; } // Keep enemy in bounds if (self.x < 0) { self.x = 0; } if (self.x > 2048) { self.x = 2048; } }; self.attack = function () { self.isAttacking = true; // Flash enemy when attacking enemyGraphics.tint = 0xFF0000; LK.setTimeout(function () { enemyGraphics.tint = 0xFFFFFF; }, 200); // Check if hero is in range and deal damage var distanceToHero = Math.abs(self.x - hero.x); if (distanceToHero <= self.attackRange) { hero.takeDamage(10); } LK.setTimeout(function () { self.isAttacking = false; }, 300); }; self.takeDamage = function (damage) { self.health -= damage; LK.effects.flashObject(self, 0xFFFFFF, 200); if (self.health <= 0) { LK.setScore(LK.getScore() + 100); return true; // Enemy is dead } return false; }; return self; }); var HealthPack = Container.expand(function () { var self = Container.call(this); var healthGraphics = self.attachAsset('healthPack', { anchorX: 0.5, anchorY: 0.5 }); self.bobOffset = 0; self.update = function () { // Bobbing animation self.bobOffset += 0.1; self.y += Math.sin(self.bobOffset) * 0.5; // Check collision with hero if (self.intersects(hero)) { hero.heal(30); LK.getSound('powerUpSound').play(); LK.setScore(LK.getScore() + 50); return true; // Mark for removal } // Remove if off screen if (self.x < -100 || self.x > 2148) { return true; } return false; }; return self; }); var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 1.0 }); self.health = 100; self.maxHealth = 100; self.isAttacking = false; self.attackCooldown = 0; self.invulnerable = false; self.invulnerableTime = 0; self.moveSpeed = 2; self.horizontalSpeed = 5; self.jumpPower = 15; self.velocityY = 0; self.gravity = 0.8; self.isOnGround = true; self.groundY = 2732; self.direction = 1; // 1 for right, -1 for left self.moveLeft = function () { self.x -= self.horizontalSpeed; self.direction = -1; heroGraphics.scaleX = -1; // Flip sprite to face left }; self.moveRight = function () { self.x += self.horizontalSpeed; self.direction = 1; heroGraphics.scaleX = 1; // Face right (normal) }; self.jump = function () { if (self.isOnGround) { self.velocityY = -self.jumpPower; self.isOnGround = false; } }; self.turnTowardsNearestEnemy = function () { var nearestDistance = Infinity; var nearestEnemy = null; for (var i = 0; i < enemies.length; i++) { var distance = Math.abs(enemies[i].x - self.x); if (distance < nearestDistance) { nearestDistance = distance; nearestEnemy = enemies[i]; } } if (nearestEnemy) { if (nearestEnemy.x < self.x && self.direction === 1) { // Enemy is to the left, turn left self.direction = -1; heroGraphics.scaleX = -1; } else if (nearestEnemy.x > self.x && self.direction === -1) { // Enemy is to the right, turn right self.direction = 1; heroGraphics.scaleX = 1; } } }; self.punch = function () { if (self.attackCooldown <= 0 && !self.isAttacking) { self.turnTowardsNearestEnemy(); // Turn to face nearest enemy before attacking self.isAttacking = true; self.attackCooldown = 30; // Create punch effect var punchEffect = new PunchEffect(); punchEffect.setDirection(self.direction); // Set punch effect direction punchEffect.x = self.x + 80 * self.direction; // Direction-based positioning punchEffect.y = self.y - 80; game.addChild(punchEffect); punchEffects.push(punchEffect); LK.getSound('punch').play(); // Flash hero white briefly heroGraphics.tint = 0xFFFFFF; LK.setTimeout(function () { heroGraphics.tint = 0xFFFFFF; }, 100); } }; self.uppercut = function () { if (self.attackCooldown <= 0 && !self.isAttacking) { self.turnTowardsNearestEnemy(); // Turn to face nearest enemy before attacking self.isAttacking = true; self.attackCooldown = 45; // Create uppercut effect var punchEffect = new PunchEffect(); punchEffect.setDirection(self.direction); // Set punch effect direction punchEffect.x = self.x + 80 * self.direction; // Direction-based positioning punchEffect.y = self.y - 120; game.addChild(punchEffect); punchEffects.push(punchEffect); LK.getSound('punch').play(); // Jump effect tween(self, { y: self.y - 50 }, { duration: 200, easing: tween.easeOut }); tween(self, { y: self.y }, { duration: 200, easing: tween.easeIn }); } }; self.lowKick = function () { if (self.attackCooldown <= 0 && !self.isAttacking) { self.turnTowardsNearestEnemy(); // Turn to face nearest enemy before attacking self.isAttacking = true; self.attackCooldown = 35; // Create kick effect var punchEffect = new PunchEffect(); punchEffect.setDirection(self.direction); // Set punch effect direction punchEffect.x = self.x + 90 * self.direction; // Direction-based positioning punchEffect.y = self.y - 40; game.addChild(punchEffect); punchEffects.push(punchEffect); LK.getSound('punch').play(); } }; self.takeDamage = function (damage) { if (!self.invulnerable) { self.health -= damage; self.invulnerable = true; self.invulnerableTime = 60; // Flash red when taking damage LK.effects.flashObject(self, 0xFF0000, 500); if (self.health <= 0) { self.health = 0; LK.showGameOver(); } } }; self.heal = function (amount) { self.health = Math.min(self.health + amount, self.maxHealth); }; self.update = function () { // Apply gravity and jumping physics if (!self.isOnGround) { self.velocityY += self.gravity; self.y += self.velocityY; // Check if landed if (self.y >= self.groundY) { self.y = self.groundY; self.velocityY = 0; self.isOnGround = true; } } // Update cooldowns if (self.attackCooldown > 0) { self.attackCooldown--; } else { self.isAttacking = false; } if (self.invulnerableTime > 0) { self.invulnerableTime--; if (self.invulnerableTime <= 0) { self.invulnerable = false; } } // Keep hero in bounds if (self.x > 2048 - 100) { self.x = 2048 - 100; } if (self.x < 100) { self.x = 100; } }; return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerGraphics = self.attachAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); self.bobOffset = 0; self.rotationSpeed = 0.05; self.update = function () { // Rotating and bobbing animation self.bobOffset += 0.1; self.y += Math.sin(self.bobOffset) * 0.5; powerGraphics.rotation += self.rotationSpeed; // Check collision with hero if (self.intersects(hero)) { // Apply speed boost effect var originalSpeed = hero.horizontalSpeed; var originalMoveSpeed = hero.moveSpeed; // Increase speed by 2x hero.horizontalSpeed *= 2; hero.moveSpeed *= 2; // Flash hero to show speed boost is active tween(hero, { tint: 0x00FF00 }, { duration: 200 }); // Reset speed after 5 seconds LK.setTimeout(function () { hero.horizontalSpeed = originalSpeed; hero.moveSpeed = originalMoveSpeed; // Flash back to normal tween(hero, { tint: 0xFFFFFF }, { duration: 200 }); }, 5000); LK.getSound('powerUpSound').play(); LK.setScore(LK.getScore() + 200); return true; // Mark for removal } // Remove if off screen if (self.x < -100 || self.x > 2148) { return true; } return false; }; return self; }); var PunchEffect = Container.expand(function () { var self = Container.call(this); var punchGraphics = self.attachAsset('punch', { anchorX: 0.5, anchorY: 0.5 }); self.lifetime = 20; self.direction = 1; // Default direction self.setDirection = function (dir) { self.direction = dir; if (dir === -1) { punchGraphics.scaleX = -1; // Flip for left direction } else { punchGraphics.scaleX = 1; // Normal for right direction } }; self.update = function () { self.lifetime--; punchGraphics.alpha = self.lifetime / 20; if (self.lifetime <= 0) { return true; // Mark for removal } return false; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x34495E }); /**** * Game Code ****/ var hero; var enemies = []; var punchEffects = []; var healthPacks = []; var powerUps = []; var enemySpawnTimer = 0; var powerUpSpawnTimer = 0; var scrollOffset = 0; var lastGestureTime = 0; var gestureThreshold = 10; // Create background var background = game.attachAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); // Create hero hero = game.addChild(new Hero()); hero.x = 200; hero.y = 2732; // Position at bottom of screen // Create UI elements var healthBar = new Text2('Health: 100', { size: 60, fill: 0x27AE60 }); healthBar.anchor.set(0, 0); LK.gui.topLeft.addChild(healthBar); var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); var comboText = new Text2('', { size: 80, fill: 0xF39C12 }); comboText.anchor.set(0.5, 0); comboText.y = 100; LK.gui.top.addChild(comboText); // Game variables var comboCount = 0; var comboTimer = 0; var lastHitTime = 0; // Touch controls var touchStartX = 0; var touchStartY = 0; var touchStartTime = 0; var isHolding = false; var holdTimer = 0; // Movement controls var leftPressed = false; var rightPressed = false; var jumpPressed = false; game.down = function (x, y, obj) { touchStartX = x; touchStartY = y; touchStartTime = LK.ticks; isHolding = true; holdTimer = 0; // Determine if touch is for movement or combat if (x < 2048 / 3) { // Left third of screen - move left leftPressed = true; } else if (x > 2048 * 2 / 3) { // Right third of screen - move right rightPressed = true; } // Middle third reserved for combat actions }; game.up = function (x, y, obj) { if (!isHolding) return; var deltaX = x - touchStartX; var deltaY = y - touchStartY; var holdDuration = LK.ticks - touchStartTime; isHolding = false; // Reset movement flags leftPressed = false; rightPressed = false; // Handle combat gestures only if in middle third of screen if (touchStartX >= 2048 / 3 && touchStartX <= 2048 * 2 / 3) { // Check for hold gesture (power attack) if (holdDuration > 30) { hero.uppercut(); return; } // Check for swipe gestures if (Math.abs(deltaX) > gestureThreshold || Math.abs(deltaY) > gestureThreshold) { if (Math.abs(deltaY) > Math.abs(deltaX)) { if (deltaY < -gestureThreshold) { // Swipe up - jump hero.jump(); } else if (deltaY > gestureThreshold) { // Swipe down - low kick hero.lowKick(); } } } else { // Tap - punch hero.punch(); } } else { // Handle jump for left/right areas on swipe up if (deltaY < -gestureThreshold && Math.abs(deltaY) > Math.abs(deltaX)) { hero.jump(); } } }; // Spawn enemies function spawnEnemy() { var enemy = new Enemy(); // Random spawn position (left or right side) if (Math.random() > 0.5) { enemy.x = -100; } else { enemy.x = 2148; } enemy.y = 2732; // Position at bottom of screen // Scale enemy speed exponentially based on game time (every 30 seconds = 1800 ticks) var timeMultiplier = Math.floor(LK.ticks / 1800); enemy.moveSpeed = 1 * Math.pow(1.5, timeMultiplier); // Base speed 1, multiplied by 1.5 each interval enemies.push(enemy); game.addChild(enemy); } // Spawn health pack function spawnHealthPack() { var healthPack = new HealthPack(); healthPack.x = Math.random() * 1800 + 124; healthPack.y = 2650; // Position closer to bottom of screen healthPacks.push(healthPack); game.addChild(healthPack); } // Spawn power up function spawnPowerUp() { var powerUp = new PowerUp(); powerUp.x = Math.random() * 1800 + 124; powerUp.y = 2600; // Position closer to bottom of screen powerUps.push(powerUp); game.addChild(powerUp); } // Update combo system function updateCombo() { if (comboTimer > 0) { comboTimer--; if (comboTimer <= 0) { comboCount = 0; comboText.setText(''); } } } // Check punch collisions function checkPunchCollisions() { for (var i = punchEffects.length - 1; i >= 0; i--) { var punch = punchEffects[i]; for (var j = enemies.length - 1; j >= 0; j--) { var enemy = enemies[j]; if (punch.intersects(enemy)) { if (enemy.takeDamage(25)) { // Enemy defeated enemy.destroy(); enemies.splice(j, 1); // Update combo comboCount++; comboTimer = 180; if (comboCount > 1) { comboText.setText('COMBO x' + comboCount); LK.setScore(LK.getScore() + comboCount * 50); } LK.getSound('enemyHit').play(); } break; } } } } // Start background music LK.playMusic('bgMusic'); // Main game loop game.update = function () { // Handle continuous movement if (leftPressed) { hero.moveLeft(); } if (rightPressed) { hero.moveRight(); } // Update combo system updateCombo(); // Spawn enemies enemySpawnTimer++; if (enemySpawnTimer >= 180) { spawnEnemy(); enemySpawnTimer = 0; } // Spawn power-ups occasionally powerUpSpawnTimer++; if (powerUpSpawnTimer >= 600) { if (Math.random() > 0.7) { spawnHealthPack(); } else { spawnPowerUp(); } powerUpSpawnTimer = 0; } // Update punch effects for (var i = punchEffects.length - 1; i >= 0; i--) { if (punchEffects[i].update()) { punchEffects[i].destroy(); punchEffects.splice(i, 1); } } // Update enemies for (var i = enemies.length - 1; i >= 0; i--) { // Remove enemies that are too far off screen if (enemies[i].x < -200 || enemies[i].x > 2248) { enemies[i].destroy(); enemies.splice(i, 1); } } // Update health packs for (var i = healthPacks.length - 1; i >= 0; i--) { if (healthPacks[i].update()) { healthPacks[i].destroy(); healthPacks.splice(i, 1); } } // Update power ups for (var i = powerUps.length - 1; i >= 0; i--) { if (powerUps[i].update()) { powerUps[i].destroy(); powerUps.splice(i, 1); } } // Check punch collisions checkPunchCollisions(); // Update UI healthBar.setText('Health: ' + hero.health); scoreText.setText('Score: ' + LK.getScore()); // Win condition if (LK.getScore() >= 5000) { LK.showYouWin(); } // Increase difficulty over time if (LK.ticks % 1800 === 0) { enemySpawnTimer = Math.max(60, enemySpawnTimer - 10); // Gradually increase all existing enemies' speed exponentially for (var i = 0; i < enemies.length; i++) { var enemy = enemies[i]; var newSpeed = enemy.moveSpeed * 1.8; // Multiply speed by 1.8 every 30 seconds for exponential growth // Use tween to smoothly transition to new speed over 2 seconds tween(enemy, { moveSpeed: newSpeed }, { duration: 2000, easing: tween.easeOut }); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 1.0
});
self.health = 50;
self.maxHealth = 50;
self.moveSpeed = 1;
self.attackCooldown = 0;
self.isAttacking = false;
self.direction = 1; // 1 for right, -1 for left
self.attackRange = 120;
self.update = function () {
// Move towards hero
var distanceToHero = Math.abs(self.x - hero.x);
if (distanceToHero > self.attackRange) {
if (self.x < hero.x) {
self.x += self.moveSpeed;
self.direction = 1;
enemyGraphics.scaleX = 1; // Face right
} else {
self.x -= self.moveSpeed;
self.direction = -1;
enemyGraphics.scaleX = -1; // Face left
}
} else {
// Attack hero
if (self.attackCooldown <= 0) {
self.attack();
self.attackCooldown = 90;
}
}
if (self.attackCooldown > 0) {
self.attackCooldown--;
}
// Keep enemy in bounds
if (self.x < 0) {
self.x = 0;
}
if (self.x > 2048) {
self.x = 2048;
}
};
self.attack = function () {
self.isAttacking = true;
// Flash enemy when attacking
enemyGraphics.tint = 0xFF0000;
LK.setTimeout(function () {
enemyGraphics.tint = 0xFFFFFF;
}, 200);
// Check if hero is in range and deal damage
var distanceToHero = Math.abs(self.x - hero.x);
if (distanceToHero <= self.attackRange) {
hero.takeDamage(10);
}
LK.setTimeout(function () {
self.isAttacking = false;
}, 300);
};
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xFFFFFF, 200);
if (self.health <= 0) {
LK.setScore(LK.getScore() + 100);
return true; // Enemy is dead
}
return false;
};
return self;
});
var HealthPack = Container.expand(function () {
var self = Container.call(this);
var healthGraphics = self.attachAsset('healthPack', {
anchorX: 0.5,
anchorY: 0.5
});
self.bobOffset = 0;
self.update = function () {
// Bobbing animation
self.bobOffset += 0.1;
self.y += Math.sin(self.bobOffset) * 0.5;
// Check collision with hero
if (self.intersects(hero)) {
hero.heal(30);
LK.getSound('powerUpSound').play();
LK.setScore(LK.getScore() + 50);
return true; // Mark for removal
}
// Remove if off screen
if (self.x < -100 || self.x > 2148) {
return true;
}
return false;
};
return self;
});
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 1.0
});
self.health = 100;
self.maxHealth = 100;
self.isAttacking = false;
self.attackCooldown = 0;
self.invulnerable = false;
self.invulnerableTime = 0;
self.moveSpeed = 2;
self.horizontalSpeed = 5;
self.jumpPower = 15;
self.velocityY = 0;
self.gravity = 0.8;
self.isOnGround = true;
self.groundY = 2732;
self.direction = 1; // 1 for right, -1 for left
self.moveLeft = function () {
self.x -= self.horizontalSpeed;
self.direction = -1;
heroGraphics.scaleX = -1; // Flip sprite to face left
};
self.moveRight = function () {
self.x += self.horizontalSpeed;
self.direction = 1;
heroGraphics.scaleX = 1; // Face right (normal)
};
self.jump = function () {
if (self.isOnGround) {
self.velocityY = -self.jumpPower;
self.isOnGround = false;
}
};
self.turnTowardsNearestEnemy = function () {
var nearestDistance = Infinity;
var nearestEnemy = null;
for (var i = 0; i < enemies.length; i++) {
var distance = Math.abs(enemies[i].x - self.x);
if (distance < nearestDistance) {
nearestDistance = distance;
nearestEnemy = enemies[i];
}
}
if (nearestEnemy) {
if (nearestEnemy.x < self.x && self.direction === 1) {
// Enemy is to the left, turn left
self.direction = -1;
heroGraphics.scaleX = -1;
} else if (nearestEnemy.x > self.x && self.direction === -1) {
// Enemy is to the right, turn right
self.direction = 1;
heroGraphics.scaleX = 1;
}
}
};
self.punch = function () {
if (self.attackCooldown <= 0 && !self.isAttacking) {
self.turnTowardsNearestEnemy(); // Turn to face nearest enemy before attacking
self.isAttacking = true;
self.attackCooldown = 30;
// Create punch effect
var punchEffect = new PunchEffect();
punchEffect.setDirection(self.direction); // Set punch effect direction
punchEffect.x = self.x + 80 * self.direction; // Direction-based positioning
punchEffect.y = self.y - 80;
game.addChild(punchEffect);
punchEffects.push(punchEffect);
LK.getSound('punch').play();
// Flash hero white briefly
heroGraphics.tint = 0xFFFFFF;
LK.setTimeout(function () {
heroGraphics.tint = 0xFFFFFF;
}, 100);
}
};
self.uppercut = function () {
if (self.attackCooldown <= 0 && !self.isAttacking) {
self.turnTowardsNearestEnemy(); // Turn to face nearest enemy before attacking
self.isAttacking = true;
self.attackCooldown = 45;
// Create uppercut effect
var punchEffect = new PunchEffect();
punchEffect.setDirection(self.direction); // Set punch effect direction
punchEffect.x = self.x + 80 * self.direction; // Direction-based positioning
punchEffect.y = self.y - 120;
game.addChild(punchEffect);
punchEffects.push(punchEffect);
LK.getSound('punch').play();
// Jump effect
tween(self, {
y: self.y - 50
}, {
duration: 200,
easing: tween.easeOut
});
tween(self, {
y: self.y
}, {
duration: 200,
easing: tween.easeIn
});
}
};
self.lowKick = function () {
if (self.attackCooldown <= 0 && !self.isAttacking) {
self.turnTowardsNearestEnemy(); // Turn to face nearest enemy before attacking
self.isAttacking = true;
self.attackCooldown = 35;
// Create kick effect
var punchEffect = new PunchEffect();
punchEffect.setDirection(self.direction); // Set punch effect direction
punchEffect.x = self.x + 90 * self.direction; // Direction-based positioning
punchEffect.y = self.y - 40;
game.addChild(punchEffect);
punchEffects.push(punchEffect);
LK.getSound('punch').play();
}
};
self.takeDamage = function (damage) {
if (!self.invulnerable) {
self.health -= damage;
self.invulnerable = true;
self.invulnerableTime = 60;
// Flash red when taking damage
LK.effects.flashObject(self, 0xFF0000, 500);
if (self.health <= 0) {
self.health = 0;
LK.showGameOver();
}
}
};
self.heal = function (amount) {
self.health = Math.min(self.health + amount, self.maxHealth);
};
self.update = function () {
// Apply gravity and jumping physics
if (!self.isOnGround) {
self.velocityY += self.gravity;
self.y += self.velocityY;
// Check if landed
if (self.y >= self.groundY) {
self.y = self.groundY;
self.velocityY = 0;
self.isOnGround = true;
}
}
// Update cooldowns
if (self.attackCooldown > 0) {
self.attackCooldown--;
} else {
self.isAttacking = false;
}
if (self.invulnerableTime > 0) {
self.invulnerableTime--;
if (self.invulnerableTime <= 0) {
self.invulnerable = false;
}
}
// Keep hero in bounds
if (self.x > 2048 - 100) {
self.x = 2048 - 100;
}
if (self.x < 100) {
self.x = 100;
}
};
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.bobOffset = 0;
self.rotationSpeed = 0.05;
self.update = function () {
// Rotating and bobbing animation
self.bobOffset += 0.1;
self.y += Math.sin(self.bobOffset) * 0.5;
powerGraphics.rotation += self.rotationSpeed;
// Check collision with hero
if (self.intersects(hero)) {
// Apply speed boost effect
var originalSpeed = hero.horizontalSpeed;
var originalMoveSpeed = hero.moveSpeed;
// Increase speed by 2x
hero.horizontalSpeed *= 2;
hero.moveSpeed *= 2;
// Flash hero to show speed boost is active
tween(hero, {
tint: 0x00FF00
}, {
duration: 200
});
// Reset speed after 5 seconds
LK.setTimeout(function () {
hero.horizontalSpeed = originalSpeed;
hero.moveSpeed = originalMoveSpeed;
// Flash back to normal
tween(hero, {
tint: 0xFFFFFF
}, {
duration: 200
});
}, 5000);
LK.getSound('powerUpSound').play();
LK.setScore(LK.getScore() + 200);
return true; // Mark for removal
}
// Remove if off screen
if (self.x < -100 || self.x > 2148) {
return true;
}
return false;
};
return self;
});
var PunchEffect = Container.expand(function () {
var self = Container.call(this);
var punchGraphics = self.attachAsset('punch', {
anchorX: 0.5,
anchorY: 0.5
});
self.lifetime = 20;
self.direction = 1; // Default direction
self.setDirection = function (dir) {
self.direction = dir;
if (dir === -1) {
punchGraphics.scaleX = -1; // Flip for left direction
} else {
punchGraphics.scaleX = 1; // Normal for right direction
}
};
self.update = function () {
self.lifetime--;
punchGraphics.alpha = self.lifetime / 20;
if (self.lifetime <= 0) {
return true; // Mark for removal
}
return false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x34495E
});
/****
* Game Code
****/
var hero;
var enemies = [];
var punchEffects = [];
var healthPacks = [];
var powerUps = [];
var enemySpawnTimer = 0;
var powerUpSpawnTimer = 0;
var scrollOffset = 0;
var lastGestureTime = 0;
var gestureThreshold = 10;
// Create background
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Create hero
hero = game.addChild(new Hero());
hero.x = 200;
hero.y = 2732; // Position at bottom of screen
// Create UI elements
var healthBar = new Text2('Health: 100', {
size: 60,
fill: 0x27AE60
});
healthBar.anchor.set(0, 0);
LK.gui.topLeft.addChild(healthBar);
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var comboText = new Text2('', {
size: 80,
fill: 0xF39C12
});
comboText.anchor.set(0.5, 0);
comboText.y = 100;
LK.gui.top.addChild(comboText);
// Game variables
var comboCount = 0;
var comboTimer = 0;
var lastHitTime = 0;
// Touch controls
var touchStartX = 0;
var touchStartY = 0;
var touchStartTime = 0;
var isHolding = false;
var holdTimer = 0;
// Movement controls
var leftPressed = false;
var rightPressed = false;
var jumpPressed = false;
game.down = function (x, y, obj) {
touchStartX = x;
touchStartY = y;
touchStartTime = LK.ticks;
isHolding = true;
holdTimer = 0;
// Determine if touch is for movement or combat
if (x < 2048 / 3) {
// Left third of screen - move left
leftPressed = true;
} else if (x > 2048 * 2 / 3) {
// Right third of screen - move right
rightPressed = true;
}
// Middle third reserved for combat actions
};
game.up = function (x, y, obj) {
if (!isHolding) return;
var deltaX = x - touchStartX;
var deltaY = y - touchStartY;
var holdDuration = LK.ticks - touchStartTime;
isHolding = false;
// Reset movement flags
leftPressed = false;
rightPressed = false;
// Handle combat gestures only if in middle third of screen
if (touchStartX >= 2048 / 3 && touchStartX <= 2048 * 2 / 3) {
// Check for hold gesture (power attack)
if (holdDuration > 30) {
hero.uppercut();
return;
}
// Check for swipe gestures
if (Math.abs(deltaX) > gestureThreshold || Math.abs(deltaY) > gestureThreshold) {
if (Math.abs(deltaY) > Math.abs(deltaX)) {
if (deltaY < -gestureThreshold) {
// Swipe up - jump
hero.jump();
} else if (deltaY > gestureThreshold) {
// Swipe down - low kick
hero.lowKick();
}
}
} else {
// Tap - punch
hero.punch();
}
} else {
// Handle jump for left/right areas on swipe up
if (deltaY < -gestureThreshold && Math.abs(deltaY) > Math.abs(deltaX)) {
hero.jump();
}
}
};
// Spawn enemies
function spawnEnemy() {
var enemy = new Enemy();
// Random spawn position (left or right side)
if (Math.random() > 0.5) {
enemy.x = -100;
} else {
enemy.x = 2148;
}
enemy.y = 2732; // Position at bottom of screen
// Scale enemy speed exponentially based on game time (every 30 seconds = 1800 ticks)
var timeMultiplier = Math.floor(LK.ticks / 1800);
enemy.moveSpeed = 1 * Math.pow(1.5, timeMultiplier); // Base speed 1, multiplied by 1.5 each interval
enemies.push(enemy);
game.addChild(enemy);
}
// Spawn health pack
function spawnHealthPack() {
var healthPack = new HealthPack();
healthPack.x = Math.random() * 1800 + 124;
healthPack.y = 2650; // Position closer to bottom of screen
healthPacks.push(healthPack);
game.addChild(healthPack);
}
// Spawn power up
function spawnPowerUp() {
var powerUp = new PowerUp();
powerUp.x = Math.random() * 1800 + 124;
powerUp.y = 2600; // Position closer to bottom of screen
powerUps.push(powerUp);
game.addChild(powerUp);
}
// Update combo system
function updateCombo() {
if (comboTimer > 0) {
comboTimer--;
if (comboTimer <= 0) {
comboCount = 0;
comboText.setText('');
}
}
}
// Check punch collisions
function checkPunchCollisions() {
for (var i = punchEffects.length - 1; i >= 0; i--) {
var punch = punchEffects[i];
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
if (punch.intersects(enemy)) {
if (enemy.takeDamage(25)) {
// Enemy defeated
enemy.destroy();
enemies.splice(j, 1);
// Update combo
comboCount++;
comboTimer = 180;
if (comboCount > 1) {
comboText.setText('COMBO x' + comboCount);
LK.setScore(LK.getScore() + comboCount * 50);
}
LK.getSound('enemyHit').play();
}
break;
}
}
}
}
// Start background music
LK.playMusic('bgMusic');
// Main game loop
game.update = function () {
// Handle continuous movement
if (leftPressed) {
hero.moveLeft();
}
if (rightPressed) {
hero.moveRight();
}
// Update combo system
updateCombo();
// Spawn enemies
enemySpawnTimer++;
if (enemySpawnTimer >= 180) {
spawnEnemy();
enemySpawnTimer = 0;
}
// Spawn power-ups occasionally
powerUpSpawnTimer++;
if (powerUpSpawnTimer >= 600) {
if (Math.random() > 0.7) {
spawnHealthPack();
} else {
spawnPowerUp();
}
powerUpSpawnTimer = 0;
}
// Update punch effects
for (var i = punchEffects.length - 1; i >= 0; i--) {
if (punchEffects[i].update()) {
punchEffects[i].destroy();
punchEffects.splice(i, 1);
}
}
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
// Remove enemies that are too far off screen
if (enemies[i].x < -200 || enemies[i].x > 2248) {
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Update health packs
for (var i = healthPacks.length - 1; i >= 0; i--) {
if (healthPacks[i].update()) {
healthPacks[i].destroy();
healthPacks.splice(i, 1);
}
}
// Update power ups
for (var i = powerUps.length - 1; i >= 0; i--) {
if (powerUps[i].update()) {
powerUps[i].destroy();
powerUps.splice(i, 1);
}
}
// Check punch collisions
checkPunchCollisions();
// Update UI
healthBar.setText('Health: ' + hero.health);
scoreText.setText('Score: ' + LK.getScore());
// Win condition
if (LK.getScore() >= 5000) {
LK.showYouWin();
}
// Increase difficulty over time
if (LK.ticks % 1800 === 0) {
enemySpawnTimer = Math.max(60, enemySpawnTimer - 10);
// Gradually increase all existing enemies' speed exponentially
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
var newSpeed = enemy.moveSpeed * 1.8; // Multiply speed by 1.8 every 30 seconds for exponential growth
// Use tween to smoothly transition to new speed over 2 seconds
tween(enemy, {
moveSpeed: newSpeed
}, {
duration: 2000,
easing: tween.easeOut
});
}
}
};
dan the man oyunundakş karakterden esinlenerek çizildi . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
koca dişli kocaman kulaklarında ki kocaman altın küpelerle kaslı vücudundaki koca göğüslerindeki priceng'i ile yeşil çirkin ork. elinde de balta. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
bir meteor ve meteorun arkasından çıkan asit. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
sağlık çantası. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
arka planda sağ üst köşede güneş var. arka planda oyunun üst kısmında soldan sağa hareket eden bulutlar var. ve arka planda kocaman dağlar var ve üst kısımları karlarla kaplı. arka planda oyuncuya yakın ağaç ve çimler bulunmakta. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
mavi enerji içeceği. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat