Search the Community
Showing results for tags 'bullet'.
-
Hi, I'm new with Phaser, I'm wondering how can I create a group of enemies that appears at the side of the screen in a random Y position between 550px and 745 px, after they appear they need to start to fire to my character Right now I have a function to create the bullets and how they will be fired: createBullets:function(laserToFire,track,offsetX, offsetY, bulletDirection,fireRate,bulletSpeed){ weapon = gameSP.add.weapon(10, laserToFire); weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; weapon.bulletSpeed = bulletSpeed; weapon.fireRate = fireRate; weapon.trackSprite(track, offsetX, offsetY); weapon.fireAngle = bulletDirection;right } So what I'm looking to do is to have each one of my enemies within the group to fire to my character. Thanks in advance.
-
Hello. I am using weapon.fire() function and I want to set special property for bullet, that apear after calling this function. I tried to use forEach: weapon.bullets.forEach(function(bullet){ if(bullet.target == undefined){ bullet.taget = 'prop1'; return; } }); weapon.fire(); but this does not work.
-
I am making a platformer game which I have implemented a weapon fire method to shoot some projectiles. I find that I am unable to fire these projectiles along the X axis rather than the Y. Here is a that section of the code within the create function: weapon = this.game.add.weapon(1, 'bullet'); weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; and the code within create for the bullet: if(this.cursors.down.isDown){ weapon.bulletAngleOffset = 90; weapon.bulletSpeed = 300; weapon.x = this.fNobleRanger.x; weapon.y = this.fNobleRanger.y; weapon.fire(); } The projectile is firing from my desired sprite, however the projectile shoots up and then falls back down. I want to shoot the projectile along the X axis instead. Any tips? I am silly. Found out about fireAngle, but to further this question: is it possible to have this item not be affected by game physic gravity?
-
In my platformer, the player has a number of different weapons (gun, energy blast, homing missile) and there may be a number of enemies (up to maybe 6) who will have one of the same weapons. From my understanding of the weapon plugin and tutorials, I should then be making a different weapon object for each of the players weapons and for each enemy. As I am wanting to attach a particle emitter to missiles I'm then going to extend the bullet class to make a missile. Question 1: I want autofire from enemies to fireAtSprite rather than just fire, I'm assuming the best way to do this is to extend the weapon class and overwrite the fire() method to call fireAtSprite() instead? Or is there a better way? Question 2: Where do I put the collision checks for the bullets? I can see a couple of options but would really like to know the performance implications as to which would be better. 1) Put an arcade collision call in the extended bullet update method to handle hitting scenery and hitting enemies - this seems neat in some ways as the code for the bullet hitting something sits with the bullet itself, however it feels like I'm going to end up with a lot of separate collision calls. 2) Put an arcade collision call in the state update along the lines of: this.enemies.forEach(function(enemy){ this.game.physics.arcade.collide(enemy.weapon.bullets, this.collisionLayer, this.shotCollisionLayer, null, this); this.game.physics.arcade.collide(enemy.weapon.bullets, this.player, this.shotPlayer, null, this); }, this); 3) In the custom bullet constructor, add all enemy bullets to an enemyBulletsArray and collide this in the state update method this.game.physics.arcade.collide(this.enemyBulletsArray, this.collisionLayer, this.shotCollisionLayer, null, this); this.game.physics.arcade.collide(this.enemyBulletsArray, this.player, this.shotPlayer, null, this); Many thanks, Gordon
-
Hi, I'm currently in the process of making my first game having completed the zenva course and am confused by the weapon plugin. My game is a platformer shootemup type, where there will be the player and multiple enemies shooting a variety of ammo types. The zenva course covers making bulletpools and sharing them between enemy sprites, but does not mention the weapon plugin. On the face of it the weapon plugin looks great, sorting out a whole load of features neatly. However if each enemy has its own weapon tracking it, does that mean that it then gets its own bullet pool, all of which then need to be destroyed once the enemy is killed? This seems to somewhat defeat the point of the bullet pool. My question is then: can the bullet pools be shared between enemies OR should I just rely on the entire bulletpool being recycled along with the enemy itself as it is itself pooled OR should I just not bother with the weaponplugin at all? Any help or suggestions much appreciated, Thanks, Gordon
-
Hi guys! I'm new to Phaser, with basic knowledge of JS. I have a problem with my platform game, which I've started with this tutorial. https://phaser.io/news/2015/09/platformer-tutorial-part2 The code is different from every tutorial I've seen on Phaser main webpage, so It's hard for me to get in to. (no update, create, preload function in main is the beggining of all my problems)... I wanted to add a shooting system, which I learned from this: https://phaser.io/examples/v2/arcade-physics/group-vs-group I applied this code to the platformer engine, and I am not sure if I did it correctly. I have created shooting system in Player object, because I didn't know how to do it other way. This code look like this: //In player: Platformer.Player = function (game_state, position, properties) { "use strict"; Platformer.Prefab.call(this, game_state, position, properties); (...) //bullets bullets = game.add.group(); bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; bullets.callAll('events.onOutOfBounds.add', 'events.onOutOfBounds', resetBullet, this); bullets.setAll('checkWorldBounds', true); bullets.createMultiple(100, 'pocisk'); function resetBullet (bullet) { bullet.kill(); } //In player.prototype.update : Platformer.Player.prototype = Object.create(Platformer.Prefab.prototype); Platformer.Player.prototype.constructor = Platformer.Player; Platformer.Player.prototype.update = function () { "use strict"; this.game_state.game.physics.arcade.collide(this, this.game_state.layers.collision); this.game_state.game.physics.arcade.overlap(this, this.game_state.groups.enemies, this.hit_enemy, null, this); (...) //bullets if (this.spaceKey.isDown) { this.fireBullet(); } this.fireBullet = function() { if (game.time.now > bulletTime) { bullet = bullets.getFirstExists(false); if (bullet) { this.game_state.game.physics.arcade.overlap(bullet, Platformer.Enemy, this.zderzenie, null, this); bullet.reset(this.body.x + 6, this.body.y - 8); bullet.body.allowGravity = false; if (this.profil==1) //direction of shooting bullet.body.velocity.x = 300; else bullet.body.velocity.x = -300; if(bullet.body.x==Platformer.Enemy.x && bullet.body.y==Platformer.Enemy.y) bullet.kill(); bulletTime = game.time.now + 250; } } } And it works, the player is shooting circles in left or right direction. The problem starts now. I need to somehow code the collision between the bullet and the enemy. As you can see above, I wrote thing like this : if(bullet.body.x==Platformer.Enemy.x && bullet.body.y==Platformer.Enemy.y) bullet.kill(); But this don't work. What can I do? It is the problem with seperate objects? Or maybe I know nothing and made serious stupid mistakes?
-
- phaser
- platformer
- (and 5 more)
-
Hello! I'm having a hell of a time trying figure out how to change Phaser Weapon plugins bullet speed after it's been shot. I also set "weapon.bulletSpeed" negative value, because by default it was going in opposite direction. I attached weapon to a spaceship sprite, but on "weapon.fire()" bullet goes backwards. Weapon definition. addWeapon: function(target) { var weapon; var weapon; weapon = game.add.weapon(100, 'bullet'); weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; weapon.bulletAngleOffset = 90; weapon.bulletSpeed = 5; weapon.trackSprite(target, (this.ship.height), 0); weapon.trackRotation = true; weapon.fireRate = 200; weapon.bulletRotateToVelocity = false; weapon.onFire.add(function() {this.blastSound.play()},this); return weapon; } this.ship = this.add.sprite(this.world.centerX, this.world.centerY +300, 'ship'); this.ship.anchor.setTo(0.5, 0.5); this.ship.scale.setTo(0.22); this.ship.angle = -90; game.physics.arcade.enable(this.ship); this.ship.body.drag.set(70); this.ship.body.maxVelocity.set(220); this.weapon = this.addWeapon(this.ship); I am trying to set the direction of the bullet to opposite, so I don't have to set bulletSpeed to negative value. change every bullets anchor. change the speed of particular bullet after it's been shot. It would be grate to hear any suggestion. Тhank you in advance.
- 4 replies
-
- bulletdirection
- bulletanchore
-
(and 4 more)
Tagged with:
-
Hey All, We are a little late posting to this forum and I hope this is an appropriate section to place our post in. We have a Shoot-em-up Game Jam (of sorts) running all the way through 2015, in monthly installments, called.. #ShmupJam. So the basic idea is anyone with the skills to make a shmup, or a first time game in this genre, can participate in the monthly jam. Each month the era moves forwards in time. **updated 7th May 2015** We’ve added compilation images for waves 1-4! Wave 05 is ACTIVE! - http://jams.gamejolt.io/shmupjam05/ Wave 04 Games – http://jams.gamejolt.io/shmupjam04/games Wave 03 Games – http://jams.gamejolt.io/shmupjam03/games Wave 02 Games – http://jams.gamejolt.io/shmupjam02/games Wave 01 Games – http://jams.gamejolt.io/Shmuproom01/games The rules are fairly open.. it's not really a competition, just for fun. The theory was that starting with some of the earliest games would ease us (in terms of technical demands) into the Jam, and each month we would have more and more of a framework and some experience to work with. Create something retro looking, modernize a classic.. perhaps simplicity could be the key to getting in a quick submission. You don't have to submit a full game, prototypes, visualizations or simple tech demo's are perfectly acceptable. Each jam runs for a whole month, and if you miss the deadline you could still get away submitting it to the next one. You might also check out our Shmup community over on deviant art the Shmuproom, which has all kinds of inspiration on it too. So.. if you are interested, please feel free to join in. You can leave comments on this thread (let us know which framework you using) or if you can get your games onto GameJolt even better. Thanks all, -kb
-
Hey everyone! So I'm pretty new to Phaser and I'm having a hard time making the player's bullets stop at a certain point (e.g killing the projectile at around 30px after its original position, etc). I want the player to have a limited projectile range and I'm just wondering how you can implement that because all my attempts of trying to figure it out have failed so far, so I'm seeking help from you guys... Thanks for any advise!
-
I´m having a problem with the weapon plugin. When I use the function weapon.fire() it fires a bullet 90 degrees from the canon sprite (the one the weapon plugin is tracking). Any idea what I am doing Wrong? Thnxs!
-
Update - the game is now available on Google Play as a native app: https://play.google.com/store/apps/details?id=com.afgt.naval The link http://www.askforgametask.com/mobile/games/naval/ Description Naval Battle is an HTML5 arcade game in which your mission is to destroy a fleet of enemy cargo ships before they deliver ammunition and provisions to the enemy troops. You are the commander of the VIC Victory, a fast light tank used by the Mobile Costal Artillery in defending a country against sea attacks. Your tank is armed with a limitless supply of anti-ship shells, but be aware that only one shell can be in view at a time! You have only 70 seconds to sink all enemy ships. They are not armed, but they are protected by the gun fire from a fortified enemy battery on the other side of the bay. And they are moving with different speeds. So you need to aim very carefully! The game ends if you fail to complete the mission within the 70-second time limit or if your tank is destroyed by enemy gun fire. Controls Use the left and right keys to move. Use the up or space key to fire. Screenshots
-
After some research on Internet how to make bullet hell game with Phaser, no good tutorial found, so I decided to use 3rd framework, then I found bulletml.js, so I give it a try, running 3rd demo, work great. (3rd one is orginal, no dependency, also, bunch of Japanese in comment and on github page, maybe I should learn it...). So I tried to modify it without Phaser, work great too. After saw what it can do, I tried to make it work with Phaser, little hard for me to understand demo's code (I'm still a beginner). So I tried, got error: Uncaught TypeError: this.onTextureUpdate is not a function and a bunch of warning. Anybody know why or it is impossible to do, or maybe suggestion on tutorial? (Also, Rich, can you consider use bulletml.js into Phaser.Weapon or Phaser.Bullet or Phaser.Particle or else? ) (Sorry for bad english )
-
Hi Guys, So I'm flying a space ship using the accelerometer and gyro.js, with gyro.js I calculate the angle the ship is flying in. Now I want to fire a laser when I touch my mobile device's screen. The laser should fire in the direction the ship is flying in, no matter where the user touches the screen. I've searched for a couple of hours, but still didn't find a way to make this work. Any ideas? function fire(angle) { if(game.time.now > bulletTime) { bullet = bullets.getFirstExists(false); if(bullet) { bullet.reset(player.x, player.y + 8); bullet.rotation = this.game.physics.arcade.moveToObject(bullet, game.input.activePointer, 500); bulletTime = game.time.now + 200; } }}This is what I have got so far, and this works. But it doesn't fire in the direction the ship is flying in. ps. I've calculated the angle with the following code: var anglePlayer = Math.atan2(o.y * 20, o.x * 20);anglePlayer *= 180/Math.PI;anglePlayer = 180 - anglePlayer;player.angle = anglePlayer;
-
Hello & Thanks , I am working on a javescript(only) game . I have the shooter(thrower) setup and moving via arrowKeys . And have initial setup for bullet(cowpie) . But I need help(example) setting cowpie up so that I can have multiple cowpies in play . var Cowpie = function () { var self = this; this.idTag = 'cowpie'; this.x = thrower.x; this.y = thrower.y; this.width= 64; this.height = 64; this.speedX = 0; this.speedY = 5; this.visible = true; this.directionY = -1; this.moveMe = false ; this.update = function() { self.y = self.y+ (self.speedY * self.directionY); // always -1 } self.moveMe = false ; } } // cowpie = new Cowpie(); cowpie.idTag ; // = 'cowpie'; cowpie.x ; // = 0; cowpie.y ; // = thrower.y; cowpie.width ; // = 64; cowpie.height ; // = 64; cowpie.speedX ; // = 0; cowpie.speedY ; // = -5; cowpie.visible ; // = true ; cowpie.directionY ; // = -1; cowpie.moveMe ; // = true ; . The running game is here: http://liesandcowpies.com/javascript/BenghaziGame-starter-05-Thrower-Cowpie.html The code shown below: <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta charset="utf-8" /> <title>move pieThrower</title> <!-- file:///C:/javascript-Pure/otherObj/BenghaziGame-starter-05-Thrower-Cowpie.html --> <!-- http://liesandcowpies.com/javascript/ --> <style> canvas { border:1px solid #d3d3d3; background-color: #f1f1f1; } #assets { visibility: hidden; } </style> </head> <body onload="startGame()"> fromWhere= <span id="fromWhere">fromWhere</span><br> idTag= <span id="idTag">idTag</span><br> this.idTag= <span id="thisIdTag">this.idTag</span><br> this.visible= <span id="this.visible"> this.visible</span><br> this.tripsMax= <span id="this.tripsMax"> this.tripsMax</span><br> this.tripsCnt= <span id="this.tripsCnt"> this.tripsCnt</span><br> this.directionX= <span id="this.directionX"> this.directionX</span><br> this.x= <span id="this.x"> this.x</span><br> thrower x,y,w,h= <span id="thrower.xywh">thrower.x,y,w,h</span><br> <div align="center"> <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2"> <tbody> <tr> <td style="width:70%";><p id="traceMsg">traceLog goes here:</p> </td> <td style="width:30%";> <canvas id="canvas" width="300" height="300"></canvas> </td> </tr> </tbody> </table> </div> <div id="assets"> <img id="truth01" src="sprites/truth01.png" width="64" height="64" /> <img id="truth02" src="sprites/truth02.png" width="64" height="64" /> <img id="lies01" src="sprites/lies01.png" width="64" height="64" /> <img id="lies02" src="sprites/lies02.png" width="64" height="64" /> <img id="cowpie" src="sprites/cowpie.png" width="32" height="32" /> <img id="thrower" src="sprites/thrower.png" width="64" height="64" /> <audio id="closeDoor" src="sounds/CloseDoor.ogg"></audio> </div> <script type='text/javascript'> // var oneTraceLine = ""; var traceYESorNO = false; var updateFor1stTime = 0; var fromWhere = "fromWhere"; var timesInTripsCk=0; var visible = true; var thisx=0; var tripsMax=0; priorTripsMax = 0; var thisIdTag; var holdThrower_x = 0; var idTag = "truth01"; var idTagTh = "thrower"; var tripsCnt=0; var directionX=1 ; var addit = 0; // canvas = document.getElementById("canvas"); // get the canvas ctx = canvas.getContext('2d'); // create canvas Context; var targetImgsCnt = 0; var idTag = "truth01"; var totalTrips = 0; var targetImgs = [document.getElementById("truth01"), document.getElementById("lies01"), //, document.getElementById("truth02"), document.getElementById("lies02"), document.getElementById("thrower"), document.getElementById("cowpie") ] ; // // function startGame() { var Cowpie = function () { var self = this; this.idTag = 'cowpie'; this.x = thrower.x; this.y = thrower.y; this.width= 64; this.height = 64; this.speedX = 0; this.speedY = 5; this.visible = true; this.directionY = -1; this.moveMe = false ; this.update = function() { self.y = self.y+ (self.speedY * self.directionY); // always -1 } self.moveMe = false ; } } // cowpie = new Cowpie(); cowpie.idTag ; // = 'cowpie'; cowpie.x ; // = 0; cowpie.y ; // = thrower.y; cowpie.width ; // = 64; cowpie.height ; // = 64; cowpie.speedX ; // = 0; cowpie.speedY ; // = -5; cowpie.visible ; // = true ; cowpie.directionY ; // = -1; cowpie.moveMe ; // = true ; // var Thrower = function () { var self = this; this.idTag = 'thrower'; this.x = (canvas.width / 2); this.y = canvas.height - 64; this.width= 64; this.height = 64; this.speedX = 1; this.speedY = 0; this.visible = true; this.directionX = 5; this.moveMe = false ; this.update = function() { self.x = self.x + (self.speedX * self.directionX); // always either +1 or -1 } self.moveMe = false ; } } // thrower = new Thrower(); thrower.idTag ; // = 'thrower'; thrower.x ; // = 0; thrower.y ; // = canvas.height - 64; thrower.width ; // = 64; thrower.height ; // = 64; thrower.speedX ; // = 1; thrower.speedY ; // = 0; thrower.visible ; // = true ; thrower.directionX ; // = 1; thrower.moveMe ; // = true ; // myGameArea.start(); } // function updateGameArea() { myGameArea.clear(); targetImgsCnt = 4; if(thrower.visible) { if(thrower.moveMe) {thrower.update();} ctx.drawImage(targetImgs[targetImgsCnt], thrower.x, thrower.y, thrower.width, thrower.height); /*120*/ document.getElementById("thrower.xywh").innerHTML = thrower.x; } } // var myGameArea = { start : function() { thrower.moveMe = false ; interval = setInterval(updateGameArea, 5); // updateGameArea(); }, clear : function() { ctx.clearRect(0, 0, canvas.width, canvas.height); }, stop : function() { clearInterval(this.interval); } } // document.addEventListener("keydown", keyDownHandler, false); document.addEventListener("keyup", keyUpHandler, false); document.addEventListener("mousemove", mouseMoveHandler, false); function keyDownHandler(e) { if(e.keyCode == 39 || event.keyCode == 68) { // rightPressed = true; // alert("keyDownHandler: rightPressed"); thrower.directionX = 7; thrower.moveMe = true; } else if(e.keyCode == 37 || event.keyCode == 65) { // leftPressed = true; // alert("keyDownHandler: leftPressed"); thrower.directionX = -7; thrower.moveMe = true; } } function keyUpHandler(e) { if(e.keyCode == 38 || event.keyCode == 87) { rightPressed = false; } else if(e.keyCode == 40 || event.keyCode == 83) { leftPressed = false; } } function mouseMoveHandler(e) { var relativeX = e.clientX - canvas.offsetLeft; // alert("function mouseMoveHandler(e)"); } // // file:///C:/javascript-Pure/otherObj/ // </script> </body> </html> Thanks
-
Hello & Thanks : I am having trouble getting bullets to go : I get error :Uncaught TypeError: Cannot read property 'velocity' of undefined m-vertical-collision.js:124 Pls , what do I need to make this puppy go ? Thanks
-
My character fires a bullet and how far it goes depends on what it hits or passes through. Box2D and other physics engines have useful callbacks for collision detection for moving objects, but this bullet would be rendered instantaneously so I figured raytracing would be the solution. How would I go about doing this?
-
Hello, I want to switch sprite or frame when i fire. I use this for the moment but it's only working when i load the game. It's possible to switch sprite or frame in createMultiple(quantity, key, frame, exists) ? APP.bullets = game.add.group(); APP.bullets.createMultiple(10, random_card()); APP.bullets.setAll('anchor.x', 0.5); APP.bullets.setAll('anchor.y', 1); APP.bullets.enableBody = true; game.physics.enable(APP.bullets);function random_card() { var bullet var rand = Math.floor(Math.random() * 3 + 1); switch (rand) { case 1: bullet = "bullet1"; return bullet; break; case 2: bullet = "bullet2"; return bullet; break; case 3: bullet = "bullet3"; return bullet; break; case 1: bullet = "bullet4"; return bullet; break; default: return "error!"; }}
-
Hi, I have an issue on my fire function. When i keep spacebar pressed collision between the bullet and the layer doesn't working. You can test it http://s475613576.onlinehome.fr/portfolio/jeu/jeu/warped/index.html create() {// bullet group APP.bullets = game.add.group(); APP.bullets.createMultiple(10, 'bullet'); APP.bullets.setAll('anchor.x', 0.5); APP.bullets.setAll('anchor.y', 1);}update(){if (APP.fireButton.isDown) { fireBullet(); }game.physics.arcade.overlap(APP.bullet, APP.layer, function(bullet, layer) { bullet.kill(); }, null, this);}}function fireBullet() { if (game.time.now > APP.bulletTime) { //game.sound.play('fire'); APP.bulletTime = game.time.now + APP.bulletRate; // Grab the first bullet we can from the pool APP.bullet = APP.bullets.getFirstExists(false); if (APP.bullet) { APP.bullet.lifespan = 2000; //kill after 2000ms game.physics.enable(APP.bullet); if (APP.facing === "right") { // And fire it APP.bullet.reset(APP.player.x + 15, APP.player.y + 15); APP.bullet.body.velocity.x = APP.bulletvelocity; } else if (APP.facing === "left") { APP.bullet.reset(APP.player.x, APP.player.y + 15); APP.bullet.body.velocity.x = -APP.bulletvelocity; } } }}Thank you for you're help .
-
Hello. I have seen several posts that talk about this topic. I do not understand what happens when the bullets hit platforms. Function when the collision occurs is not executed. This only happens when the bullet hits a group of platforms. This is my code create: this.bullets = this.game.add.group(); this.bullets.createMultiple(30, 'bullet'); this.bullets.forEach(utils.setupBullet, this); utils.setupBullet = function(bullet) { bullet.anchor.x = 0.5; bullet.anchor.y = 0.5; bullet.outOfBoundsKill = true; bullet.lifespan = 2300; bullet.body.setCircle(15); bullet.animations.add('default', [0, 1, 2, 1], 10, true); bullet.animations.play('default'); }; update: this.game.physics.overlap(this.bullets, this.layer, this.collisionBulletWall, null, this); collisionBulletWall: function(bullet, wall) { bullet.kill(); } any idea?