полёт пули в игре html5+JS
Друзья всем привет! Мне нужна ваша помощь. У меня игра на HTML5 + JS на полотне canvas. На этом полотне есть объект, который стреляет пулями. Сама карта игры (canvas) достаточно большая, и пуля летит в направлении через всю карту. Как сделать, чтобы она пролетала, скажем, 100-200 пикселей и после этого исчезала?
Я точно не уверен, но думаю, что реализовать это можно здесь: if( this.weapon.fireRateTick < this.weapon.fireRate ){ this.weapon.fireRateTick += $.dt; } else { if( $.autofire || ( !$.autofire && $.mouse.down ) ){ $.audio.play( 'shoot' ); if( $.powerupTimers[ 2 ] > 0 || $.powerupTimers[ 3 ] > 0 || $.powerupTimers[ 4 ] > 0) { $.audio.play( 'shootAlt' ); } this.weapon.fireRateTick = this.weapon.fireRateTick - this.weapon.fireRate; this.weapon.fireFlag = 6; if( this.weapon.count > 1 ) { var spreadStart = -this.weapon.spread / 2; var spreadStep = this.weapon.spread / ( this.weapon.count - 1 ); } else { var spreadStart = 0; var spreadStep = 0; } var gunX = this.x + Math.cos( this.direction ) * ( this.radius + this.weapon.bullet.size ); var gunY = this.y + Math.sin( this.direction ) * ( this.radius + this.weapon.bullet.size ); for( var i = 0; i < this.weapon.count; i++ ) { $.bulletsFired++; var color = this.weapon.bullet.strokeStyle; if( $.powerupTimers[ 2 ] > 0 || $.powerupTimers[ 3 ] > 0 || $.powerupTimers[ 4 ] > 0) { var colors = []; if( $.powerupTimers[ 2 ] > 0 ) { colors.push( 'hsl(' + $.definitions.powerups[ 2 ].hue + ', ' + $.definitions.powerups[ 2 ].saturation + '%, ' + $.definitions.powerups[ 2 ].lightness + '%)' ); } if( $.powerupTimers[ 3 ] > 0 ) { colors.push( 'hsl(' + $.definitions.powerups[ 3 ].hue + ', ' + $.definitions.powerups[ 3 ].saturation + '%, ' + $.definitions.powerups[ 3 ].lightness + '%)' ); } if( $.powerupTimers[ 4 ] > 0 ) { colors.push( 'hsl(' + $.definitions.powerups[ 4 ].hue + ', ' + $.definitions.powerups[ 4 ].saturation + '%, ' + $.definitions.powerups[ 4 ].lightness + '%)' ); } color = colors[ Math.floor( $.util.rand( 0, colors.length ) ) ]; } $.bullets.push( new $.Bullet( { x: gunX, y: gunY, speed: this.weapon.bullet.speed, direction: this.direction + spreadStart + i * spreadStep, damage: this.weapon.bullet.damage, size: this.weapon.bullet.size, lineWidth: this.weapon.bullet.lineWidth, strokeStyle: color, piercing: this.weapon.bullet.piercing } ) ); } } } В участке кода, что я выделил жирным - можно устанавливать значения размера пули, скорости, её урона. Вероятно в этом участке указывать длину пути? Но каким образом? Прошу вашей помощи. |
Часовой пояс GMT +3, время: 05:37. |