User prompt
make that there are more ennemy pig
Code edit (1 edits merged)
Please save this source code
User prompt
make that the ennemy pigs bigger
User prompt
make that you clic on the spacebar, a bullet goes from the pig to the nearest ennemy pig
User prompt
Make the pig bigger
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in or related to this line: 'if (enemyPigs[i].intersects(playerPig)) {' Line Number: 136
User prompt
make that if the pig is touched by a ennemy pig he will die
User prompt
make that if the bullet touch a enemyPig he will die
User prompt
Please fix the bug: 'Uncaught TypeError: window.addEventListener is not a function' in or related to this line: 'window.addEventListener('keydown', function (event) {' Line Number: 98
User prompt
Make that if you clic spacebar the pig choots a bullet
User prompt
make the pig can move every where in the map
Initial prompt
pig wars
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,19 @@
/****
* Classes
****/
+// Create a class for the bullet
+var Bullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Bullet's behavior goes here
+ self.y -= 5;
+ };
+});
// Create a class for the enemy pigs
var EnemyPig = Container.expand(function () {
var self = Container.call(this);
var pigGraphics = self.attachAsset('enemyPig', {
@@ -75,9 +87,23 @@
enemyPigs.push(enemyPig);
game.addChild(enemyPig);
}, 2000);
// Update the game state every frame
+window.addEventListener('keydown', function (event) {
+ if (event.code === 'Space') {
+ var bullet = new Bullet();
+ bullet.x = playerPig.x;
+ bullet.y = playerPig.y;
+ game.addChild(bullet);
+ }
+});
game.update = function () {
+ // Update the bullets
+ for (var i = game.children.length - 1; i >= 0; i--) {
+ if (game.children[i] instanceof Bullet && game.children[i].y < -game.children[i].height / 2) {
+ game.removeChild(game.children[i]);
+ }
+ }
// Move the enemy pigs down the screen
for (var i = 0; i < enemyPigs.length; i++) {
enemyPigs[i].y += 5;
// If an enemy pig has reached the bottom of the screen, remove it
A pig with a gun. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
monster pig horrorific. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.