User prompt
make enemy die when weapon touch them and spawn a coin when an enemy die
User prompt
move character to left
User prompt
turn weapon quickly when throwed
User prompt
make it 0.4
User prompt
add a duration time between two weapon lets say 0.3 seconds
User prompt
Eğer ikinci arka planın gerçekten yatayda ters çevrilmiş (mirrored) görünmesini istiyorsanız, yalnızca kopyalayıp sağa yerleştirmek yetmeyebilir. Bunun yerine, ikinci background nesnesini yatayda ters çevirmek için flipX yerine scaleX kullanabilirsiniz. Aşağıdaki örnekte, bg2 için anchorX'i 1 yapıp scaleX'i -1 olarak ayarlıyoruz. Böylece bg2, bg1'in aynası gibi görüntülenecektir: js Kopyala Düzenle var ScrollingBackground = Container.expand(function () { var self = Container.call(this); // İlk arka plan (normal) self.bg1 = LK.getAsset('background', { anchorX: 0, anchorY: 0 }); self.bg1.x = 0; self.bg1.y = 0; self.addChild(self.bg1); // İkinci arka plan (mirrored) self.bg2 = LK.getAsset('background', { anchorX: 1, // Sağ kenar referans alınır anchorY: 0 }); // scaleX'i -1 yaparak yatayda ters çeviriyoruz self.bg2.scaleX = -1; // bg1'in sağ kenarının hemen yanında yerleştiriyoruz self.bg2.x = self.bg1.width; self.bg2.y = 0; self.addChild(self.bg2); self.speed = 2; self.update = function () { // Her iki arka planı sola kaydır self.bg1.x -= self.speed; self.bg2.x -= self.speed; // bg1 tamamen ekran dışına çıkarsa, sağındaki bg2'nin hemen ardından yeniden konumlandır if (self.bg1.x + self.bg1.width <= 0) { self.bg1.x = self.bg2.x + self.bg2.width; } // bg2 için de aynı işlemi uygula if (self.bg2.x - self.bg2.width >= 2048) { self.bg2.x = self.bg1.x - self.bg1.width; } }; }); Bu kodda: bg2 için anchorX 1 olarak ayarlandı, böylece nesnenin sağ kenarı referans noktası oldu. scaleX = -1 kullanılarak bg2 yatayda ters çevrildi. Ardından bg2, bg1'in sağ kenarına yerleştirildi. Bu şekilde, arka plan gerçekten mirrored (ters çevrilmiş) olarak görünecektir. Eğer motorunuz flipX özelliğini destekliyorsa, onun yerine de deneyebilirsiniz; ancak scaleX yöntemi daha kontrollü bir ters çevirme sağlar.
Code edit (1 edits merged)
Please save this source code
User prompt
characterin lokasyonunu biraz sola al
User prompt
even faster
User prompt
make it faster
User prompt
Silahın (weapon) tıklanan yere fırlaması için hız vektörünü doğru şekilde ayarlaman gerekiyor. Şu an Weapon sınıfındaki update fonksiyonunda, her karede hedefin (tıklanan yerin) koordinatlarını tekrar hesaplıyorsun. Bunun yerine, silahın ilk oluşturulduğunda hedefe doğru bir hız vektörü belirlemen lazım.
User prompt
it doesnt follow the location tapped just stays where it spawned
User prompt
spawn weapon on the character and make it follow to the location tapped
User prompt
make weapon follow the location tapped
User prompt
ilk zıplarken weapon spawn olmasın
User prompt
karakter havadayken ekrana tıklandığında weapon spawn et
Remix started
Copy Mario vs Monsters
/**** * Classes ****/ // Define a class for enemies var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Define a class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.jumpHeight = 40; self.isJumping = false; self.velocityY = 0; self.update = function () { if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Decreased gravity effect by 30% if (self.y >= 2732 / 2) { // Ground level self.y = 2732 / 2; self.isJumping = false; self.velocityY = 0; } } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpHeight; } }; }); // Define a class for the weapon var Weapon = Container.expand(function () { var self = Container.call(this); var weaponGraphics = self.attachAsset('weapon', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Move the weapon towards the target location self.x += self.directionX * self.speed; self.y += self.directionY * self.speed; // If the weapon has reached the target location, destroy it if (Math.abs(game.down.x - self.x) < self.speed && Math.abs(game.down.y - self.y) < self.speed) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0 })); background.x = 0; background.y = 0; // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; // Initialize enemies var enemies = []; var enemySpawnInterval = 100; var enemySpawnCounter = 0; // Create a new Text2 object to display the score var scoreText = new Text2('0', { size: 100, fill: 0xFFFFFF }); // Add the score text to the game GUI at the top center of the screen LK.gui.top.addChild(scoreText); scoreText.x = 2048 / 2; scoreText.y = 0; // Handle game updates game.update = function () { player.update(); // Spawn enemies enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { var enemy = new Enemy(); enemy.x = 2048; enemy.y = 2732 / 2; enemies.push(enemy); game.addChild(enemy); // Randomize the spawn interval for the next enemy enemySpawnInterval = Math.floor(Math.random() * 150) + 50; enemySpawnCounter = 0; } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } else if (player.x > enemies[j].x && !enemies[j].passed) { enemies[j].passed = true; LK.setScore(LK.getScore() + 1); scoreText.setText(LK.getScore()); } } }; // Handle player jump game.down = function (x, y, obj) { if (player.isJumping) { var weapon = new Weapon(); weapon.x = player.x; weapon.y = player.y; // Calculate the distance between the weapon and the target location var dx = x - weapon.x; var dy = y - weapon.y; var distance = Math.sqrt(dx * dx + dy * dy); // Normalize the distance to get the direction weapon.directionX = dx / distance; weapon.directionY = dy / distance; game.addChild(weapon); } player.jump(); };
===================================================================
--- original.js
+++ change.js
@@ -55,20 +55,13 @@
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
- // Calculate the distance between the weapon and the target location
- var dx = game.down.x - self.x;
- var dy = game.down.y - self.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- // Normalize the distance to get the direction
- var directionX = dx / distance;
- var directionY = dy / distance;
// Move the weapon towards the target location
- self.x += directionX * self.speed;
- self.y += directionY * self.speed;
+ self.x += self.directionX * self.speed;
+ self.y += self.directionY * self.speed;
// If the weapon has reached the target location, destroy it
- if (distance < self.speed) {
+ if (Math.abs(game.down.x - self.x) < self.speed && Math.abs(game.down.y - self.y) < self.speed) {
self.destroy();
}
};
});
@@ -139,8 +132,15 @@
if (player.isJumping) {
var weapon = new Weapon();
weapon.x = player.x;
weapon.y = player.y;
+ // Calculate the distance between the weapon and the target location
+ var dx = x - weapon.x;
+ var dy = y - weapon.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ // Normalize the distance to get the direction
+ weapon.directionX = dx / distance;
+ weapon.directionY = dy / distance;
game.addChild(weapon);
}
player.jump();
};
\ No newline at end of file
Single 2D Mario Character. In-Game asset. 2d. Blank background.
2D Single Monster. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
marionun ingiliz boru anahtarı aleti. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
red heart mario. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
completely black simple counter without sharp edges
sea and sky,pixel,realistic but detailles benzer renkler mavi ve mavi Single Game Texture. In-Game asset. 2d. Blank background. low contrast. No shadows