User prompt
Quiero un poder que rompa balas
User prompt
Quiero que halla diferentes niveles al pasar los jefes ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Quiero que halla un enemigo que paralice al jugador por 3 segundos
User prompt
Quiero que halla un nuevo enemigo y que sea un ladrón
User prompt
Arregla que el escudo resista una bala y si lo toca una bala que explote y que el jugador tenga tres vidas
User prompt
Quiero un fondo y un menú y que el jefe sea más grande para que el jugador pueda darle más facil
User prompt
Que el escudo resista un golpe y aparezca de la nada y cuando aparece el jefe la arma del jugador dispare una bala cada 2 dos segundos y el jefe aguanta 10 balas
User prompt
Quiero que al tocar el escudo el jugador se quede con el escudo puesto y que el jugador al moverse a una dirección el asset del jugador y las balas donde estén apuntando el asset valla a la posición
User prompt
Que al pasar 37 segundos aparezca un jefe y que el jugador tenga un arma y el jefe dispara al jugador pero el jugador con el arma tiene que dispararle
User prompt
Quiero que el escudo aparezca en el mapa y el jugador tener que ir hacia el escudo
User prompt
Que aparezca un escudo que proteja al jugador de una bala y aparezca cada cierto tiempo
User prompt
Quiero que cuando pase 60 segundos haya una nueva bala
Code edit (1 edits merged)
Please save this source code
User prompt
Bullet Dodge
Initial prompt
Quiero hacer un juego frenético sobre un humano esquinando balas
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Boss = Container.expand(function () {
var self = Container.call(this);
//{boss_1}
var bossGraphics = self.attachAsset('player', {
anchorX: 0.5,
//{boss_2}
anchorY: 0.5,
//{boss_3}
scaleX: 2.5,
scaleY: 2.5
}); //{boss_4}
bossGraphics.tint = 0xff0000; //{boss_5}
self.width = bossGraphics.width;
self.height = bossGraphics.height;
self.health = 10;
self.shootCooldown = 0;
self.shootInterval = 30;
self.update = function () {
//{boss_6}
if (self.shootCooldown > 0) {
self.shootCooldown--;
} //{boss_7}
}; //{boss_8}
return self; //{boss_9}
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = 0;
self.vy = 0;
self.width = bulletGraphics.width;
self.height = bulletGraphics.height;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.width = playerGraphics.width;
self.height = playerGraphics.height;
self.rotation = 0;
self.hasShield = false;
self.moveTowards = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > self.speed) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
self.rotation = Math.atan2(dy, dx);
} else {
self.x = targetX;
self.y = targetY;
}
// Keep player within bounds
var padding = 40;
if (self.x < padding) self.x = padding;
if (self.x > 2048 - padding) self.x = 2048 - padding;
if (self.y < padding) self.y = padding;
if (self.y > 2732 - padding) self.y = 2732 - padding;
};
return self;
});
//{boss_10}
var PlayerWeapon = Container.expand(function () {
var self = Container.call(this);
//{weapon_1}
var weaponGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
//{weapon_2}
anchorY: 0.5 //{weapon_3}
}); //{weapon_4}
weaponGraphics.tint = 0x00ff00; //{weapon_5}
self.vx = 0;
self.vy = 0;
self.width = weaponGraphics.width;
self.height = weaponGraphics.height;
self.update = function () {
//{weapon_6}
self.x += self.vx;
self.y += self.vy;
}; //{weapon_7}
return self; //{weapon_8}
});
//{weapon_9}
var Shield = Container.expand(function () {
var self = Container.call(this);
var shieldGraphics = self.attachAsset('shield', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = shieldGraphics.width;
self.height = shieldGraphics.height;
self.active = true;
self.pulsePhase = 0;
self.durability = 1;
self.update = function () {
if (self.active) {
self.pulsePhase += 0.05;
self.alpha = 0.7 + Math.sin(self.pulsePhase) * 0.3;
}
};
return self;
});
//{weapon_9}
var Thief = Container.expand(function () {
var self = Container.call(this);
//{thief_1}
var thiefGraphics = self.attachAsset('player', {
anchorX: 0.5,
//{thief_2}
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
}); //{thief_3}
thiefGraphics.tint = 0xffaa00; //{thief_4}
self.width = thiefGraphics.width;
self.height = thiefGraphics.height;
self.speed = 5;
self.health = 3;
self.lastX = self.x;
self.lastY = self.y;
self.update = function () {
//{thief_5}
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > self.speed) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
self.lastX = self.x;
self.lastY = self.y;
}; //{thief_6}
return self; //{thief_7}
});
/****
* Initialize Game
****/
//{thief_8}
var game = new LK.Game({
backgroundColor: 0x2d2d44
});
/****
* Game Code
****/
//{0_assets}
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
var bullets = [];
var playerWeapons = [];
var shield = null;
var shieldSpawnInterval = 600;
var score = 0;
var gameTime = 0;
var playerLives = 3;
var spawnRate = 60;
var bulletSpeed = 3;
var difficulty = 0;
var boss = null;
var weaponCooldown = 0;
var weaponFireInterval = 120;
var thieves = [];
var thiefSpawnInterval = 180;
var scoreTxt = new Text2('0', {
size: 120,
fill: '#ffffff'
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var livesTxt = new Text2('Lives: 3', {
size: 100,
fill: '#ffffff'
});
livesTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(livesTxt);
var dragTarget = null;
game.down = function (x, y, obj) {
dragTarget = {
x: x,
y: y
};
player.moveTowards(x, y);
};
game.move = function (x, y, obj) {
if (dragTarget) {
dragTarget.x = x;
dragTarget.y = y;
player.moveTowards(x, y);
}
};
game.up = function (x, y, obj) {
dragTarget = null;
};
game.update = function () {
gameTime++;
score = Math.floor(gameTime / 60);
scoreTxt.setText(score);
// Increase difficulty over time
if (gameTime % 300 === 0) {
difficulty++;
spawnRate = Math.max(20, 60 - difficulty * 5);
bulletSpeed = 3 + difficulty * 0.5;
}
// Spawn new bullet every 60 seconds
if (gameTime % 3600 === 0 && gameTime > 0) {
var newBullet = new Bullet();
bullets.push(newBullet);
game.addChild(newBullet);
var spawnSide = Math.floor(Math.random() * 4);
var targetX = player.x + (Math.random() - 0.5) * 400;
var targetY = player.y + (Math.random() - 0.5) * 400;
targetX = Math.max(0, Math.min(2048, targetX));
targetY = Math.max(0, Math.min(2732, targetY));
switch (spawnSide) {
case 0:
newBullet.x = Math.random() * 2048;
newBullet.y = -50;
break;
case 1:
newBullet.x = Math.random() * 2048;
newBullet.y = 2732 + 50;
break;
case 2:
newBullet.x = -50;
newBullet.y = Math.random() * 2732;
break;
case 3:
newBullet.x = 2048 + 50;
newBullet.y = Math.random() * 2732;
break;
}
var dx = targetX - newBullet.x;
var dy = targetY - newBullet.y;
var distance = Math.sqrt(dx * dx + dy * dy);
newBullet.vx = dx / distance * bulletSpeed;
newBullet.vy = dy / distance * bulletSpeed;
}
// Spawn bullets
if (gameTime % spawnRate === 0) {
var newBullet = new Bullet();
bullets.push(newBullet);
game.addChild(newBullet);
// Spawn from random edge
var spawnSide = Math.floor(Math.random() * 4);
var targetX = player.x + (Math.random() - 0.5) * 400;
var targetY = player.y + (Math.random() - 0.5) * 400;
targetX = Math.max(0, Math.min(2048, targetX));
targetY = Math.max(0, Math.min(2732, targetY));
switch (spawnSide) {
case 0:
// Top
newBullet.x = Math.random() * 2048;
newBullet.y = -50;
break;
case 1:
// Bottom
newBullet.x = Math.random() * 2048;
newBullet.y = 2732 + 50;
break;
case 2:
// Left
newBullet.x = -50;
newBullet.y = Math.random() * 2732;
break;
case 3:
// Right
newBullet.x = 2048 + 50;
newBullet.y = Math.random() * 2732;
break;
}
var dx = targetX - newBullet.x;
var dy = targetY - newBullet.y;
var distance = Math.sqrt(dx * dx + dy * dy);
newBullet.vx = dx / distance * bulletSpeed;
newBullet.vy = dy / distance * bulletSpeed;
}
// Spawn boss at 37 seconds
if (gameTime === 2220 && !boss) {
boss = game.addChild(new Boss());
boss.x = 2048 / 2;
boss.y = 200;
}
// Spawn thieves
if (gameTime % thiefSpawnInterval === 0 && gameTime > 2220) {
var newThief = game.addChild(new Thief());
var spawnSide = Math.floor(Math.random() * 4);
switch (spawnSide) {
case 0:
newThief.x = Math.random() * 2048;
newThief.y = -50;
break;
case 1:
newThief.x = Math.random() * 2048;
newThief.y = 2732 + 50;
break;
case 2:
newThief.x = -50;
newThief.y = Math.random() * 2732;
break;
case 3:
newThief.x = 2048 + 50;
newThief.y = Math.random() * 2732;
break;
}
newThief.lastX = newThief.x;
newThief.lastY = newThief.y;
thieves.push(newThief);
} //{thief_spawn_end}
// Handle player weapon firing cooldown
if (boss) {
if (weaponCooldown > 0) {
weaponCooldown--;
} else {
var newWeapon = new PlayerWeapon(); //{weapon_fire_1}
playerWeapons.push(newWeapon); //{weapon_fire_2}
game.addChild(newWeapon); //{weapon_fire_3}
var dx = Math.cos(player.rotation); //{weapon_fire_4}
var dy = Math.sin(player.rotation); //{weapon_fire_5}
newWeapon.x = player.x; //{weapon_fire_6}
newWeapon.y = player.y; //{weapon_fire_7}
newWeapon.vx = dx * 8; //{weapon_fire_8}
newWeapon.vy = dy * 8; //{weapon_fire_9}
newWeapon.rotation = player.rotation; //{weapon_fire_10}
weaponCooldown = weaponFireInterval; //{weapon_fire_11}
} //{weapon_fire_12}
} //{weapon_fire_13}
// Boss shoots bullets at player
if (boss && boss.shootCooldown === 0) {
var newBossBullet = new Bullet(); //{boss_shoot_1}
bullets.push(newBossBullet); //{boss_shoot_2}
game.addChild(newBossBullet); //{boss_shoot_3}
var dx = player.x - boss.x; //{boss_shoot_4}
var dy = player.y - boss.y; //{boss_shoot_5}
var distance = Math.sqrt(dx * dx + dy * dy); //{boss_shoot_6}
newBossBullet.x = boss.x; //{boss_shoot_7}
newBossBullet.y = boss.y; //{boss_shoot_8}
newBossBullet.vx = dx / distance * bulletSpeed; //{boss_shoot_9}
newBossBullet.vy = dy / distance * bulletSpeed; //{boss_shoot_10}
boss.shootCooldown = boss.shootInterval; //{boss_shoot_11}
} //{boss_shoot_12}
// Spawn shield periodically
if (gameTime % shieldSpawnInterval === 0 && gameTime > 0) {
if (shield) {
shield.destroy();
} //{shield_spawn1}
shield = game.addChild(new Shield());
shield.x = Math.random() * (2048 - 240) + 120;
shield.y = Math.random() * (2732 - 240) + 120;
shield.active = true;
} //{shield_spawn2}
// Update shield
if (shield && shield.active) {
if (player.hasShield) {
shield.x = player.x;
shield.y = player.y;
shield.rotation = player.rotation;
} else {
shield.update();
if (shield.intersects(player)) {
player.hasShield = true;
shield.durability = 1;
} //{shield_pickup_1}
} //{shield_pos1}
} //{shield_pos1_end}
// Update player weapons
for (var w = playerWeapons.length - 1; w >= 0; w--) {
var weapon = playerWeapons[w];
weapon.update();
// Check if weapon is off screen
if (weapon.x < -100 || weapon.x > 2148 || weapon.y < -100 || weapon.y > 2832) {
weapon.destroy(); //{weapon_offscreen_1}
playerWeapons.splice(w, 1); //{weapon_offscreen_2}
continue; //{weapon_offscreen_3}
} //{weapon_offscreen_4}
// Check collision with boss
if (boss && weapon.intersects(boss)) {
boss.health--; //{weapon_boss_1}
weapon.destroy(); //{weapon_boss_2}
playerWeapons.splice(w, 1); //{weapon_boss_3}
LK.effects.flashObject(boss, 0xffff00, 200); //{weapon_boss_4}
if (boss.health <= 0) {
boss.destroy(); //{weapon_boss_5}
boss = null; //{weapon_boss_6}
LK.setScore(LK.getScore() + 50); //{weapon_boss_7}
scoreTxt.setText(LK.getScore()); //{weapon_boss_8}
} //{weapon_boss_9}
continue; //{weapon_boss_10}
} //{weapon_boss_11}
} //{weapon_update_end}
// Update thieves and handle collisions
for (var t = thieves.length - 1; t >= 0; t--) {
var thief = thieves[t];
thief.update();
// Check if thief is off screen
if (thief.x < -100 || thief.x > 2148 || thief.y < -100 || thief.y > 2832) {
thief.destroy(); //{thief_offscreen_1}
thieves.splice(t, 1); //{thief_offscreen_2}
continue; //{thief_offscreen_3}
} //{thief_offscreen_4}
// Check collision with player weapon
for (var w = playerWeapons.length - 1; w >= 0; w--) {
var weapon = playerWeapons[w];
if (weapon.intersects(thief)) {
thief.health--; //{thief_weapon_1}
weapon.destroy(); //{thief_weapon_2}
playerWeapons.splice(w, 1); //{thief_weapon_3}
LK.effects.flashObject(thief, 0xffff00, 200); //{thief_weapon_4}
if (thief.health <= 0) {
thief.destroy(); //{thief_weapon_5}
thieves.splice(t, 1); //{thief_weapon_6}
LK.setScore(LK.getScore() + 10); //{thief_weapon_7}
scoreTxt.setText(LK.getScore()); //{thief_weapon_8}
t--; //{thief_weapon_9}
} //{thief_weapon_10}
break; //{thief_weapon_11}
} //{thief_weapon_12}
} //{thief_weapon_13}
if (t >= 0 && thief.intersects(player)) {
if (player.hasShield) {
player.hasShield = false;
shield = null;
} else {
playerLives--;
livesTxt.setText('Lives: ' + playerLives);
}
thief.destroy(); //{thief_player_1}
thieves.splice(t, 1); //{thief_player_2}
LK.getSound('hit').play(); //{thief_player_3}
LK.effects.flashScreen(0xff0000, 500); //{thief_player_4}
if (playerLives <= 0) {
LK.showGameOver(); //{thief_player_5}
} //{thief_player_6}
} //{thief_player_7}
} //{thief_update_end}
// Update and check bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
bullet.update();
// Check if bullet is off screen
if (bullet.x < -100 || bullet.x > 2148 || bullet.y < -100 || bullet.y > 2832) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check collision with shield first
if (shield && shield.active && player.hasShield && bullet.intersects(shield)) {
shield.durability--;
bullet.destroy();
bullets.splice(i, 1);
if (shield.durability <= 0) {
LK.effects.flashObject(shield, 0xffff00, 200);
shield.destroy();
player.hasShield = false;
shield = null;
} //{shield_durability_1}
continue;
} //{shield_col1}
// Check collision with player
if (bullet.intersects(player)) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
playerLives--;
livesTxt.setText('Lives: ' + playerLives);
bullet.destroy();
bullets.splice(i, 1);
if (playerLives <= 0) {
LK.showGameOver();
}
continue;
}
}
};
//{thief_8} ===================================================================
--- original.js
+++ change.js
@@ -119,12 +119,45 @@
}
};
return self;
});
+//{weapon_9}
+var Thief = Container.expand(function () {
+ var self = Container.call(this);
+ //{thief_1}
+ var thiefGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ //{thief_2}
+ anchorY: 0.5,
+ scaleX: 1.5,
+ scaleY: 1.5
+ }); //{thief_3}
+ thiefGraphics.tint = 0xffaa00; //{thief_4}
+ self.width = thiefGraphics.width;
+ self.height = thiefGraphics.height;
+ self.speed = 5;
+ self.health = 3;
+ self.lastX = self.x;
+ self.lastY = self.y;
+ self.update = function () {
+ //{thief_5}
+ var dx = player.x - self.x;
+ var dy = player.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > self.speed) {
+ self.x += dx / distance * self.speed;
+ self.y += dy / distance * self.speed;
+ }
+ self.lastX = self.x;
+ self.lastY = self.y;
+ }; //{thief_6}
+ return self; //{thief_7}
+});
/****
* Initialize Game
****/
+//{thief_8}
var game = new LK.Game({
backgroundColor: 0x2d2d44
});
@@ -153,8 +186,10 @@
var difficulty = 0;
var boss = null;
var weaponCooldown = 0;
var weaponFireInterval = 120;
+var thieves = [];
+var thiefSpawnInterval = 180;
var scoreTxt = new Text2('0', {
size: 120,
fill: '#ffffff'
});
@@ -272,8 +307,34 @@
boss = game.addChild(new Boss());
boss.x = 2048 / 2;
boss.y = 200;
}
+ // Spawn thieves
+ if (gameTime % thiefSpawnInterval === 0 && gameTime > 2220) {
+ var newThief = game.addChild(new Thief());
+ var spawnSide = Math.floor(Math.random() * 4);
+ switch (spawnSide) {
+ case 0:
+ newThief.x = Math.random() * 2048;
+ newThief.y = -50;
+ break;
+ case 1:
+ newThief.x = Math.random() * 2048;
+ newThief.y = 2732 + 50;
+ break;
+ case 2:
+ newThief.x = -50;
+ newThief.y = Math.random() * 2732;
+ break;
+ case 3:
+ newThief.x = 2048 + 50;
+ newThief.y = Math.random() * 2732;
+ break;
+ }
+ newThief.lastX = newThief.x;
+ newThief.lastY = newThief.y;
+ thieves.push(newThief);
+ } //{thief_spawn_end}
// Handle player weapon firing cooldown
if (boss) {
if (weaponCooldown > 0) {
weaponCooldown--;
@@ -353,8 +414,53 @@
} //{weapon_boss_9}
continue; //{weapon_boss_10}
} //{weapon_boss_11}
} //{weapon_update_end}
+ // Update thieves and handle collisions
+ for (var t = thieves.length - 1; t >= 0; t--) {
+ var thief = thieves[t];
+ thief.update();
+ // Check if thief is off screen
+ if (thief.x < -100 || thief.x > 2148 || thief.y < -100 || thief.y > 2832) {
+ thief.destroy(); //{thief_offscreen_1}
+ thieves.splice(t, 1); //{thief_offscreen_2}
+ continue; //{thief_offscreen_3}
+ } //{thief_offscreen_4}
+ // Check collision with player weapon
+ for (var w = playerWeapons.length - 1; w >= 0; w--) {
+ var weapon = playerWeapons[w];
+ if (weapon.intersects(thief)) {
+ thief.health--; //{thief_weapon_1}
+ weapon.destroy(); //{thief_weapon_2}
+ playerWeapons.splice(w, 1); //{thief_weapon_3}
+ LK.effects.flashObject(thief, 0xffff00, 200); //{thief_weapon_4}
+ if (thief.health <= 0) {
+ thief.destroy(); //{thief_weapon_5}
+ thieves.splice(t, 1); //{thief_weapon_6}
+ LK.setScore(LK.getScore() + 10); //{thief_weapon_7}
+ scoreTxt.setText(LK.getScore()); //{thief_weapon_8}
+ t--; //{thief_weapon_9}
+ } //{thief_weapon_10}
+ break; //{thief_weapon_11}
+ } //{thief_weapon_12}
+ } //{thief_weapon_13}
+ if (t >= 0 && thief.intersects(player)) {
+ if (player.hasShield) {
+ player.hasShield = false;
+ shield = null;
+ } else {
+ playerLives--;
+ livesTxt.setText('Lives: ' + playerLives);
+ }
+ thief.destroy(); //{thief_player_1}
+ thieves.splice(t, 1); //{thief_player_2}
+ LK.getSound('hit').play(); //{thief_player_3}
+ LK.effects.flashScreen(0xff0000, 500); //{thief_player_4}
+ if (playerLives <= 0) {
+ LK.showGameOver(); //{thief_player_5}
+ } //{thief_player_6}
+ } //{thief_player_7}
+ } //{thief_update_end}
// Update and check bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
bullet.update();
@@ -391,5 +497,5 @@
continue;
}
}
};
-//{weapon_9}
\ No newline at end of file
+//{thief_8}
\ No newline at end of file