User prompt
make a movement button
User prompt
make enemies come to me ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
when I hold the mouse it shoots
User prompt
make a more comfrotable movment system ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
then make a better movment mechanic ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make a movment system for the carechter
Code edit (1 edits merged)
Please save this source code
User prompt
Mango Shooters
Initial prompt
Game Title: Mango Shooters mechanics: FPS game, you shoot with your mouse and move with w,a,s,d. Enemies are: Mango and Mustard, Mango has 100 HP and Mustard has 200 HP. You have a AK 47 that deals 2 damage per bullet. You kill them in a destroyed city Objective: kill Mangos and Mustards and get coins, every mango you kill is 1 point, every mustard you kill is 2 coin
/****
* 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.speed = 15;
self.damage = 2;
self.update = function () {
self.y -= self.speed;
};
return self;
});
var Mango = Container.expand(function () {
var self = Container.call(this);
var mangoGraphics = self.attachAsset('mango', {
anchorX: 0.5,
anchorY: 0.5
});
self.maxHealth = 100;
self.health = self.maxHealth;
self.speed = 2;
self.coinValue = 1;
self.lastHealth = self.health;
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health < 0) self.health = 0;
};
self.update = function () {
self.y += self.speed;
// Flash red when taking damage
if (self.lastHealth > self.health) {
LK.effects.flashObject(self, 0xff0000, 300);
}
self.lastHealth = self.health;
};
return self;
});
var Mustard = Container.expand(function () {
var self = Container.call(this);
var mustardGraphics = self.attachAsset('mustard', {
anchorX: 0.5,
anchorY: 0.5
});
self.maxHealth = 200;
self.health = self.maxHealth;
self.speed = 1.5;
self.coinValue = 2;
self.lastHealth = self.health;
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health < 0) self.health = 0;
};
self.update = function () {
self.y += self.speed;
// Flash red when taking damage
if (self.lastHealth > self.health) {
LK.effects.flashObject(self, 0xff0000, 300);
}
self.lastHealth = self.health;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Game variables
var player;
var bullets = [];
var enemies = [];
var coins = 0;
var playerHealth = 100;
var gameStarted = false;
var enemySpawnTimer = 0;
var enemySpawnRate = 120; // frames between spawns
var difficultyTimer = 0;
// Create city background
var cityBuildings = [];
for (var i = 0; i < 12; i++) {
var buildingType = Math.floor(Math.random() * 3) + 1;
var building = LK.getAsset('cityBuilding' + buildingType, {
anchorX: 0.5,
anchorY: 1
});
building.x = i * 180 + 100;
building.y = 2732;
building.alpha = 0.3;
game.addChild(building);
cityBuildings.push(building);
}
// Create player
player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 150;
// UI Elements
var coinText = new Text2('Coins: 0', {
size: 60,
fill: 0xFFFFFF
});
coinText.anchor.set(0, 0);
coinText.x = 150;
coinText.y = 50;
LK.gui.topLeft.addChild(coinText);
var healthText = new Text2('Health: 100', {
size: 60,
fill: 0xFF0000
});
healthText.anchor.set(1, 0);
LK.gui.topRight.addChild(healthText);
// Game functions
function spawnEnemy() {
var enemy;
var spawnX = Math.random() * (2048 - 100) + 50;
// 70% chance for Mango, 30% chance for Mustard
if (Math.random() < 0.7) {
enemy = new Mango();
} else {
enemy = new Mustard();
}
enemy.x = spawnX;
enemy.y = -50;
enemy.lastY = enemy.y;
enemies.push(enemy);
game.addChild(enemy);
}
function fireBullet(targetX, targetY) {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y - 40;
bullet.lastY = bullet.y;
// Calculate angle to target
var deltaX = targetX - bullet.x;
var deltaY = targetY - bullet.y;
var angle = Math.atan2(deltaY, deltaX);
// Set bullet direction
bullet.velocityX = Math.cos(angle) * bullet.speed;
bullet.velocityY = Math.sin(angle) * bullet.speed;
// Override update to use calculated velocity
bullet.update = function () {
bullet.x += bullet.velocityX;
bullet.y += bullet.velocityY;
};
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
}
// Event handlers
game.down = function (x, y, obj) {
if (gameStarted) {
fireBullet(x, y);
} else {
gameStarted = true;
}
};
// Main game loop
game.update = function () {
if (!gameStarted) {
return;
}
// Spawn enemies
enemySpawnTimer++;
if (enemySpawnTimer >= enemySpawnRate) {
spawnEnemy();
enemySpawnTimer = 0;
}
// Increase difficulty over time
difficultyTimer++;
if (difficultyTimer >= 1800) {
// Every 30 seconds
if (enemySpawnRate > 30) {
enemySpawnRate -= 5;
}
difficultyTimer = 0;
}
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Remove bullets that go off screen
if (bullet.lastY <= 2732 && (bullet.y > 2732 || bullet.y < -50 || bullet.x < -50 || bullet.x > 2098)) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
bullet.lastY = bullet.y;
}
// Update enemies and check collisions
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
// Remove enemies that reach bottom (player takes damage)
if (enemy.lastY < 2732 && enemy.y >= 2732) {
playerHealth -= 20;
healthText.setText('Health: ' + playerHealth);
LK.effects.flashScreen(0xff0000, 500);
if (playerHealth <= 0) {
LK.setScore(coins);
LK.showGameOver();
return;
}
enemy.destroy();
enemies.splice(j, 1);
continue;
}
// Check bullet collisions
for (var k = bullets.length - 1; k >= 0; k--) {
var bullet = bullets[k];
if (bullet.intersects(enemy)) {
enemy.takeDamage(bullet.damage);
LK.getSound('enemyHit').play();
// Remove bullet
bullet.destroy();
bullets.splice(k, 1);
// Check if enemy is dead
if (enemy.health <= 0) {
coins += enemy.coinValue;
coinText.setText('Coins: ' + coins);
LK.getSound('enemyDeath').play();
enemy.destroy();
enemies.splice(j, 1);
}
break;
}
}
enemy.lastY = enemy.y;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,251 @@
-/****
+/****
+* 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.speed = 15;
+ self.damage = 2;
+ self.update = function () {
+ self.y -= self.speed;
+ };
+ return self;
+});
+var Mango = Container.expand(function () {
+ var self = Container.call(this);
+ var mangoGraphics = self.attachAsset('mango', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.maxHealth = 100;
+ self.health = self.maxHealth;
+ self.speed = 2;
+ self.coinValue = 1;
+ self.lastHealth = self.health;
+ self.takeDamage = function (damage) {
+ self.health -= damage;
+ if (self.health < 0) self.health = 0;
+ };
+ self.update = function () {
+ self.y += self.speed;
+ // Flash red when taking damage
+ if (self.lastHealth > self.health) {
+ LK.effects.flashObject(self, 0xff0000, 300);
+ }
+ self.lastHealth = self.health;
+ };
+ return self;
+});
+var Mustard = Container.expand(function () {
+ var self = Container.call(this);
+ var mustardGraphics = self.attachAsset('mustard', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.maxHealth = 200;
+ self.health = self.maxHealth;
+ self.speed = 1.5;
+ self.coinValue = 2;
+ self.lastHealth = self.health;
+ self.takeDamage = function (damage) {
+ self.health -= damage;
+ if (self.health < 0) self.health = 0;
+ };
+ self.update = function () {
+ self.y += self.speed;
+ // Flash red when taking damage
+ if (self.lastHealth > self.health) {
+ LK.effects.flashObject(self, 0xff0000, 300);
+ }
+ self.lastHealth = self.health;
+ };
+ return self;
+});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.health = 100;
+ self.maxHealth = 100;
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2c3e50
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var player;
+var bullets = [];
+var enemies = [];
+var coins = 0;
+var playerHealth = 100;
+var gameStarted = false;
+var enemySpawnTimer = 0;
+var enemySpawnRate = 120; // frames between spawns
+var difficultyTimer = 0;
+// Create city background
+var cityBuildings = [];
+for (var i = 0; i < 12; i++) {
+ var buildingType = Math.floor(Math.random() * 3) + 1;
+ var building = LK.getAsset('cityBuilding' + buildingType, {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ building.x = i * 180 + 100;
+ building.y = 2732;
+ building.alpha = 0.3;
+ game.addChild(building);
+ cityBuildings.push(building);
+}
+// Create player
+player = game.addChild(new Player());
+player.x = 2048 / 2;
+player.y = 2732 - 150;
+// UI Elements
+var coinText = new Text2('Coins: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+coinText.anchor.set(0, 0);
+coinText.x = 150;
+coinText.y = 50;
+LK.gui.topLeft.addChild(coinText);
+var healthText = new Text2('Health: 100', {
+ size: 60,
+ fill: 0xFF0000
+});
+healthText.anchor.set(1, 0);
+LK.gui.topRight.addChild(healthText);
+// Game functions
+function spawnEnemy() {
+ var enemy;
+ var spawnX = Math.random() * (2048 - 100) + 50;
+ // 70% chance for Mango, 30% chance for Mustard
+ if (Math.random() < 0.7) {
+ enemy = new Mango();
+ } else {
+ enemy = new Mustard();
+ }
+ enemy.x = spawnX;
+ enemy.y = -50;
+ enemy.lastY = enemy.y;
+ enemies.push(enemy);
+ game.addChild(enemy);
+}
+function fireBullet(targetX, targetY) {
+ var bullet = new Bullet();
+ bullet.x = player.x;
+ bullet.y = player.y - 40;
+ bullet.lastY = bullet.y;
+ // Calculate angle to target
+ var deltaX = targetX - bullet.x;
+ var deltaY = targetY - bullet.y;
+ var angle = Math.atan2(deltaY, deltaX);
+ // Set bullet direction
+ bullet.velocityX = Math.cos(angle) * bullet.speed;
+ bullet.velocityY = Math.sin(angle) * bullet.speed;
+ // Override update to use calculated velocity
+ bullet.update = function () {
+ bullet.x += bullet.velocityX;
+ bullet.y += bullet.velocityY;
+ };
+ bullets.push(bullet);
+ game.addChild(bullet);
+ LK.getSound('shoot').play();
+}
+// Event handlers
+game.down = function (x, y, obj) {
+ if (gameStarted) {
+ fireBullet(x, y);
+ } else {
+ gameStarted = true;
+ }
+};
+// Main game loop
+game.update = function () {
+ if (!gameStarted) {
+ return;
+ }
+ // Spawn enemies
+ enemySpawnTimer++;
+ if (enemySpawnTimer >= enemySpawnRate) {
+ spawnEnemy();
+ enemySpawnTimer = 0;
+ }
+ // Increase difficulty over time
+ difficultyTimer++;
+ if (difficultyTimer >= 1800) {
+ // Every 30 seconds
+ if (enemySpawnRate > 30) {
+ enemySpawnRate -= 5;
+ }
+ difficultyTimer = 0;
+ }
+ // Update bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var bullet = bullets[i];
+ // Remove bullets that go off screen
+ if (bullet.lastY <= 2732 && (bullet.y > 2732 || bullet.y < -50 || bullet.x < -50 || bullet.x > 2098)) {
+ bullet.destroy();
+ bullets.splice(i, 1);
+ continue;
+ }
+ bullet.lastY = bullet.y;
+ }
+ // Update enemies and check collisions
+ for (var j = enemies.length - 1; j >= 0; j--) {
+ var enemy = enemies[j];
+ // Remove enemies that reach bottom (player takes damage)
+ if (enemy.lastY < 2732 && enemy.y >= 2732) {
+ playerHealth -= 20;
+ healthText.setText('Health: ' + playerHealth);
+ LK.effects.flashScreen(0xff0000, 500);
+ if (playerHealth <= 0) {
+ LK.setScore(coins);
+ LK.showGameOver();
+ return;
+ }
+ enemy.destroy();
+ enemies.splice(j, 1);
+ continue;
+ }
+ // Check bullet collisions
+ for (var k = bullets.length - 1; k >= 0; k--) {
+ var bullet = bullets[k];
+ if (bullet.intersects(enemy)) {
+ enemy.takeDamage(bullet.damage);
+ LK.getSound('enemyHit').play();
+ // Remove bullet
+ bullet.destroy();
+ bullets.splice(k, 1);
+ // Check if enemy is dead
+ if (enemy.health <= 0) {
+ coins += enemy.coinValue;
+ coinText.setText('Coins: ' + coins);
+ LK.getSound('enemyDeath').play();
+ enemy.destroy();
+ enemies.splice(j, 1);
+ }
+ break;
+ }
+ }
+ enemy.lastY = enemy.y;
+ }
+};
\ No newline at end of file