C
Cosmic Grain
Guest
Right now this is the code that handles all of the player's bullets in my game, and I really need a new one:
The bullets travel at a speed of 35, which is why I ended up trying to find some "fancier" bullet code that works with faster bullets, and this code came into being due to help from someone else. But.. This one has quite a few flaws. For one, bullets can actually still miss if an enemy is small enough. Bullets will often be destroyed before visually hitting enemies. And I can't really make it look more convincing with impact graphics because spawning the impact effect at the bullet's position when it's destroyed looks like this...
I tried methods using collision line a while back, but those didn't work as it seems collision_line only works with very small bullets.
So I'm wondering if I could get some help in developing a better code for my bullets, because up until now I've sort of just been using this one while I code other things, knowing I'll need to change it eventually. Also note that the switch statement for detecting bullet type as well as the impact sound code work fine. I just need a better way to handle the bullet's movement, due to its speed. Anyway, I appreciate any assistance!
Code:
if (vspeed > -bspd) speed += bspd;
if (speed > bspd) speed = bspd;
var col;
var segments = speed div sprite_get_height(obj_pbullet.sprite_index);
for(var i = 0; i <= segments; i++)
{
var dist = segments * i
col = instance_place(x + lengthdir_x(dist, direction), y + lengthdir_y(dist, direction), obj_enemy)
if col
{
instance_destroy();
if audio_is_playing(snd_ehurt)
{
audio_stop_sound(snd_ehurt);
audio_play_sound(snd_ehurt, 31, false);
}
else
{
audio_play_sound(snd_ehurt, 31, false);
}
//Determine how much damage the enemy takes based on the type of bullet that hits it
switch (sprite_index)
{
case spr_pbullet1:
case spr_pbullet4:
case spr_pbullet5:
case spr_pbullet6:
col.ehp -= 5;
break;
case spr_pbullet2:
col.ehp -= 8;
break;
case spr_pbullet3:
col.ehp -= 4;
break;
}
with col
{
image_blend = make_colour_hsv (130,80,255);
alarm[0] = 3;
}
}
break;
}
Shooting at a test object with a test impact effect
(pardon the messy gif, used gyazo gif)
I tried methods using collision line a while back, but those didn't work as it seems collision_line only works with very small bullets.
So I'm wondering if I could get some help in developing a better code for my bullets, because up until now I've sort of just been using this one while I code other things, knowing I'll need to change it eventually. Also note that the switch statement for detecting bullet type as well as the impact sound code work fine. I just need a better way to handle the bullet's movement, due to its speed. Anyway, I appreciate any assistance!
Last edited by a moderator: