User prompt
officer 2li mermi atsın ve 1000 scoredan sonra gelsin
User prompt
ölünce etrafına 10 mermi saçan rectangle ı ekleyelim
User prompt
100 yedigen ölünce officer gelsin
User prompt
add the yedigen monster and let yedigen shoot us
User prompt
health_powerup should come every 500 points
User prompt
I need a life-giving force
User prompt
add different monsters, like a hexagon
Code edit (1 edits merged)
Please save this source code
User prompt
Tank Arena Battle
Initial prompt
Do you know a game called diep io?
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.damage = 1;
self.range = 400;
self.distanceTraveled = 0;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.distanceTraveled += Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY);
if (self.distanceTraveled > self.range) {
self.shouldDestroy = true;
}
};
return self;
});
var Enemy = Container.expand(function (type) {
var self = Container.call(this);
self.type = type || 'triangle';
self.health = 1;
self.maxHealth = 1;
self.speed = 1;
self.damage = 10;
self.points = 10;
var assetName = 'triangle';
if (self.type === 'square') {
assetName = 'square';
self.health = 2;
self.maxHealth = 2;
self.points = 20;
self.speed = 0.8;
} else if (self.type === 'pentagon') {
assetName = 'pentagon';
self.health = 3;
self.maxHealth = 3;
self.points = 30;
self.speed = 0.6;
} else if (self.type === 'hexagon') {
assetName = 'hexagon';
self.health = 5;
self.maxHealth = 5;
self.points = 50;
self.speed = 0.4;
} else if (self.type === 'yedigen') {
assetName = 'yedigen';
self.health = 7;
self.maxHealth = 7;
self.points = 70;
self.speed = 0.3;
}
var enemyGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.lastShot = 0;
self.fireRate = 120; // frames between shots
self.fireRange = 250;
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xffffff, 100);
if (self.health <= 0) {
self.shouldDestroy = true;
LK.setScore(LK.getScore() + self.points);
LK.getSound('enemyHit').play();
}
};
self.shootAtTank = function () {
var bullet = game.addChild(new Bullet());
bullet.x = self.x;
bullet.y = self.y;
bullet.damage = 1;
bullet.isEnemyBullet = true;
var angle = getAngle(self, tank);
var speed = 8;
bullet.velocityX = Math.cos(angle) * speed;
bullet.velocityY = Math.sin(angle) * speed;
bullets.push(bullet);
};
self.update = function () {
// Move towards tank
var dx = tank.x - self.x;
var dy = tank.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.velocityX = dx / distance * self.speed;
self.velocityY = dy / distance * self.speed;
}
self.x += self.velocityX;
self.y += self.velocityY;
// Yedigen shooting behavior
if (self.type === 'yedigen') {
var distanceToTank = Math.sqrt(dx * dx + dy * dy);
if (distanceToTank <= self.fireRange && gameTime - self.lastShot >= self.fireRate) {
self.shootAtTank();
self.lastShot = gameTime;
}
}
};
return self;
});
var PowerUp = Container.expand(function (type) {
var self = Container.call(this);
self.type = type || 'fireRate';
var powerupGraphics = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
// Different colors for different power-up types
if (self.type === 'damage') {
powerupGraphics.tint = 0xff0000;
} else if (self.type === 'speed') {
powerupGraphics.tint = 0x0000ff;
} else if (self.type === 'health') {
powerupGraphics.tint = 0x00ff00;
}
self.lifeTime = 0;
self.maxLifeTime = 600; // 10 seconds at 60fps
self.update = function () {
self.lifeTime++;
if (self.lifeTime > self.maxLifeTime) {
self.shouldDestroy = true;
}
// Pulsing effect
var scale = 1 + Math.sin(self.lifeTime * 0.1) * 0.2;
powerupGraphics.scaleX = scale;
powerupGraphics.scaleY = scale;
};
return self;
});
var Tank = Container.expand(function () {
var self = Container.call(this);
var tankGraphics = self.attachAsset('tank', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.fireRate = 30; // frames between shots
self.damage = 1;
self.speed = 5;
self.lastShot = 0;
self.fireRange = 300;
self.healthRegenRate = 0;
self.healthRegenTimer = 0;
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health <= 0) {
self.health = 0;
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else {
LK.effects.flashObject(self, 0xff0000, 200);
}
};
self.update = function () {
if (self.healthRegenRate > 0) {
self.healthRegenTimer++;
if (self.healthRegenTimer >= 60) {
// Every second
self.health = Math.min(self.maxHealth, self.health + self.healthRegenRate);
self.healthRegenTimer = 0;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Game variables
var tank;
var bullets = [];
var enemies = [];
var powerups = [];
var arena;
var arenaRadius = 600;
var gameTime = 0;
var waveLevel = 1;
var enemySpawnTimer = 0;
var powerupSpawnTimer = 0;
var dragNode = null;
var lastHealthPowerupScore = 0;
// UI
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var healthTxt = new Text2('Health: 100', {
size: 60,
fill: 0xFF0000
});
healthTxt.anchor.set(0, 0);
healthTxt.x = 120;
healthTxt.y = 120;
LK.gui.topLeft.addChild(healthTxt);
// Create arena
arena = game.addChild(LK.getAsset('arena', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create tank
tank = game.addChild(new Tank());
tank.x = 1024;
tank.y = 1366;
// Utility functions
function getDistance(obj1, obj2) {
var dx = obj1.x - obj2.x;
var dy = obj1.y - obj2.y;
return Math.sqrt(dx * dx + dy * dy);
}
function getAngle(from, to) {
return Math.atan2(to.y - from.y, to.x - from.x);
}
function isInsideArena(obj) {
return getDistance(obj, arena) <= arenaRadius;
}
function spawnEnemy() {
var types = ['triangle', 'square', 'pentagon', 'hexagon', 'yedigen'];
var type = types[Math.floor(Math.random() * types.length)];
var enemy = game.addChild(new Enemy(type));
// Spawn at random position on arena edge
var angle = Math.random() * Math.PI * 2;
enemy.x = arena.x + Math.cos(angle) * (arenaRadius - 50);
enemy.y = arena.y + Math.sin(angle) * (arenaRadius - 50);
enemies.push(enemy);
}
function spawnPowerUp() {
var types = ['fireRate', 'damage', 'speed', 'health'];
var type = types[Math.floor(Math.random() * types.length)];
var powerup = game.addChild(new PowerUp(type));
// Spawn at random position inside arena
var angle = Math.random() * Math.PI * 2;
var radius = Math.random() * (arenaRadius - 100);
powerup.x = arena.x + Math.cos(angle) * radius;
powerup.y = arena.y + Math.sin(angle) * radius;
powerups.push(powerup);
}
function fireBullet() {
if (gameTime - tank.lastShot < tank.fireRate) return;
// Find nearest enemy
var nearestEnemy = null;
var nearestDistance = tank.fireRange;
for (var i = 0; i < enemies.length; i++) {
var distance = getDistance(tank, enemies[i]);
if (distance < nearestDistance) {
nearestDistance = distance;
nearestEnemy = enemies[i];
}
}
if (nearestEnemy) {
var bullet = game.addChild(new Bullet());
bullet.x = tank.x;
bullet.y = tank.y;
bullet.damage = tank.damage;
var angle = getAngle(tank, nearestEnemy);
var speed = 10;
bullet.velocityX = Math.cos(angle) * speed;
bullet.velocityY = Math.sin(angle) * speed;
bullets.push(bullet);
tank.lastShot = gameTime;
LK.getSound('shoot').play();
}
}
function applyPowerUp(type) {
if (type === 'fireRate') {
tank.fireRate = Math.max(10, tank.fireRate * 0.8);
LK.effects.flashObject(tank, 0x00ff00, 300);
} else if (type === 'damage') {
tank.damage += 1;
LK.effects.flashObject(tank, 0xff0000, 300);
} else if (type === 'speed') {
tank.speed += 1;
LK.effects.flashObject(tank, 0x0000ff, 300);
} else if (type === 'health') {
tank.health = Math.min(tank.maxHealth, tank.health + 20);
tank.healthRegenRate = Math.min(5, tank.healthRegenRate + 1);
LK.effects.flashObject(tank, 0x00ff00, 500);
}
LK.getSound('powerup').play();
}
// Event handlers
game.down = function (x, y, obj) {
dragNode = tank;
tank.x = x;
tank.y = y;
// Keep tank inside arena
var distanceFromCenter = getDistance(tank, arena);
if (distanceFromCenter > arenaRadius - 60) {
var angle = getAngle(arena, tank);
tank.x = arena.x + Math.cos(angle) * (arenaRadius - 60);
tank.y = arena.y + Math.sin(angle) * (arenaRadius - 60);
}
};
game.move = function (x, y, obj) {
if (dragNode) {
tank.x = x;
tank.y = y;
// Keep tank inside arena
var distanceFromCenter = getDistance(tank, arena);
if (distanceFromCenter > arenaRadius - 60) {
var angle = getAngle(arena, tank);
tank.x = arena.x + Math.cos(angle) * (arenaRadius - 60);
tank.y = arena.y + Math.sin(angle) * (arenaRadius - 60);
}
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Main game loop
game.update = function () {
gameTime++;
// Update score display
scoreTxt.setText('Score: ' + LK.getScore());
healthTxt.setText('Health: ' + tank.health);
// Fire bullets
fireBullet();
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
if (bullet.shouldDestroy || !isInsideArena(bullet)) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check bullet-enemy collisions (only for tank bullets)
if (!bullet.isEnemyBullet) {
for (var j = enemies.length - 1; j >= 0; j--) {
if (bullet.intersects(enemies[j])) {
enemies[j].takeDamage(bullet.damage);
bullet.shouldDestroy = true;
break;
}
}
} else {
// Check enemy bullet-tank collision
if (bullet.intersects(tank)) {
tank.takeDamage(bullet.damage);
bullet.shouldDestroy = true;
}
}
}
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
if (enemy.shouldDestroy) {
enemy.destroy();
enemies.splice(i, 1);
continue;
}
// Check tank-enemy collision
if (enemy.intersects(tank)) {
tank.takeDamage(enemy.damage);
enemy.shouldDestroy = true;
}
}
// Update powerups
for (var i = powerups.length - 1; i >= 0; i--) {
var powerup = powerups[i];
if (powerup.shouldDestroy) {
powerup.destroy();
powerups.splice(i, 1);
continue;
}
// Check tank-powerup collision
if (powerup.intersects(tank)) {
applyPowerUp(powerup.type);
powerup.destroy();
powerups.splice(i, 1);
}
}
// Spawn enemies
enemySpawnTimer++;
var spawnRate = Math.max(60, 180 - Math.floor(gameTime / 600) * 20);
if (enemySpawnTimer >= spawnRate) {
spawnEnemy();
enemySpawnTimer = 0;
}
// Spawn powerups
powerupSpawnTimer++;
if (powerupSpawnTimer >= 900) {
// Every 15 seconds
spawnPowerUp();
powerupSpawnTimer = 0;
}
// Spawn health power-up every 500 points
var currentScore = LK.getScore();
if (currentScore >= lastHealthPowerupScore + 500 && currentScore > 0) {
var healthPowerup = game.addChild(new PowerUp('health'));
// Spawn at random position inside arena
var angle = Math.random() * Math.PI * 2;
var radius = Math.random() * (arenaRadius - 100);
healthPowerup.x = arena.x + Math.cos(angle) * radius;
healthPowerup.y = arena.y + Math.sin(angle) * radius;
powerups.push(healthPowerup);
lastHealthPowerupScore = Math.floor(currentScore / 500) * 500;
}
// Increase difficulty over time
if (gameTime % 1800 === 0) {
// Every 30 seconds
waveLevel++;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -53,15 +53,24 @@
self.health = 5;
self.maxHealth = 5;
self.points = 50;
self.speed = 0.4;
+ } else if (self.type === 'yedigen') {
+ assetName = 'yedigen';
+ self.health = 7;
+ self.maxHealth = 7;
+ self.points = 70;
+ self.speed = 0.3;
}
var enemyGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
+ self.lastShot = 0;
+ self.fireRate = 120; // frames between shots
+ self.fireRange = 250;
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xffffff, 100);
if (self.health <= 0) {
@@ -69,8 +78,20 @@
LK.setScore(LK.getScore() + self.points);
LK.getSound('enemyHit').play();
}
};
+ self.shootAtTank = function () {
+ var bullet = game.addChild(new Bullet());
+ bullet.x = self.x;
+ bullet.y = self.y;
+ bullet.damage = 1;
+ bullet.isEnemyBullet = true;
+ var angle = getAngle(self, tank);
+ var speed = 8;
+ bullet.velocityX = Math.cos(angle) * speed;
+ bullet.velocityY = Math.sin(angle) * speed;
+ bullets.push(bullet);
+ };
self.update = function () {
// Move towards tank
var dx = tank.x - self.x;
var dy = tank.y - self.y;
@@ -80,8 +101,16 @@
self.velocityY = dy / distance * self.speed;
}
self.x += self.velocityX;
self.y += self.velocityY;
+ // Yedigen shooting behavior
+ if (self.type === 'yedigen') {
+ var distanceToTank = Math.sqrt(dx * dx + dy * dy);
+ if (distanceToTank <= self.fireRange && gameTime - self.lastShot >= self.fireRate) {
+ self.shootAtTank();
+ self.lastShot = gameTime;
+ }
+ }
};
return self;
});
var PowerUp = Container.expand(function (type) {
@@ -212,9 +241,9 @@
function isInsideArena(obj) {
return getDistance(obj, arena) <= arenaRadius;
}
function spawnEnemy() {
- var types = ['triangle', 'square', 'pentagon', 'hexagon'];
+ var types = ['triangle', 'square', 'pentagon', 'hexagon', 'yedigen'];
var type = types[Math.floor(Math.random() * types.length)];
var enemy = game.addChild(new Enemy(type));
// Spawn at random position on arena edge
var angle = Math.random() * Math.PI * 2;
@@ -320,14 +349,22 @@
bullet.destroy();
bullets.splice(i, 1);
continue;
}
- // Check bullet-enemy collisions
- for (var j = enemies.length - 1; j >= 0; j--) {
- if (bullet.intersects(enemies[j])) {
- enemies[j].takeDamage(bullet.damage);
+ // Check bullet-enemy collisions (only for tank bullets)
+ if (!bullet.isEnemyBullet) {
+ for (var j = enemies.length - 1; j >= 0; j--) {
+ if (bullet.intersects(enemies[j])) {
+ enemies[j].takeDamage(bullet.damage);
+ bullet.shouldDestroy = true;
+ break;
+ }
+ }
+ } else {
+ // Check enemy bullet-tank collision
+ if (bullet.intersects(tank)) {
+ tank.takeDamage(bullet.damage);
bullet.shouldDestroy = true;
- break;
}
}
}
// Update enemies
düz tank tekerlekleri olan iki parçalı tank. In-Game asset. 2d. High contrast. No shadows
No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. f. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
tank mermisi. In-Game asset. 2d. High contrast. No shadows
officer. In-Game asset. 2d. High contrast. No shadows
yedigen. In-Game asset. 2d. High contrast. No shadows
dikdörtgen. In-Game asset. 2d. High contrast. No shadows