ceaselessly
Member
Hi there!
I'm working on an engine for a side-scrolling shooter. I'm having an unusual problem with creating bullet instances.
The player object is in charge of creating the bullet objects, and at seemingly random points in the room, the code that creates bullets stops creating them! Sometimes this happens when the player object is moving, and other times when it's still. Here's the code I've written for creating the bullets:
The more bizarre part of this is that the latter part of this code, the "//multi shot" block, works *fine* for the "bb2" and "bb3" bullet objects, i.e. those that it creates at an angle. So it appears the problem is isolated to any bullets I create where direction = 0. I'm baffled on this one! If anyone has any insights, or has encountered issues like this before, I'd be thrilled if you could give me a hand!
Here's the whole step event, if that helps:
Thanks!
I'm working on an engine for a side-scrolling shooter. I'm having an unusual problem with creating bullet instances.
The player object is in charge of creating the bullet objects, and at seemingly random points in the room, the code that creates bullets stops creating them! Sometimes this happens when the player object is moving, and other times when it's still. Here's the code I've written for creating the bullets:
Code:
if (keyshoot) && (shootdelay = 0)
{
//basic weapon
if (weap = 0)
{
bb = instance_create_depth(x+10,y,depth+1,o_bullet);
bb.master = self;
bb.direction = 0;
bb.speed = 25;
shootdelay = 2;
}
//multi-shot
if (weap = 1)
{
bb1 = instance_create_depth(x+10,y,depth+1,o_bullet);
bb2 = instance_create_depth(x+10,y,depth+1,o_bullet);
bb3 = instance_create_depth(x+10,y,depth+1,o_bullet);
bb1.master = self;
bb2.master = self;
bb3.master = self;
with (bb1)
{
direction = 0;
speed = 25;
}
with (bb2)
{
direction = 8;
speed = 25;
}
with (bb3)
{
direction = -8;
speed = 25;
}
shootdelay = 5;
}
}
Here's the whole step event, if that helps:
Code:
//key checks
keyup = keyboard_check(vk_up);
keydown = keyboard_check(vk_down);
keyleft = keyboard_check(vk_left);
keyright = keyboard_check(vk_right);
keyshoot = keyboard_check(ord("Z"));
keyweap = keyboard_check_pressed(vk_shift);
//movement
if (keyup) && (movey > -12)
{
movey -= 1;
}
if (keydown) && (movey < 12)
{
movey += 1;
}
if (keyleft) && (movex > -12)
{
movex -= 1;
}
if (keyright) && (movex < 12)
{
movex += 1;
}
//decel
if (!keyup) && (!keydown)
{
if (movey > 0) movey -= 1;
if (movey < 0) movey += 1;
}
if (!keyright) && (!keyleft)
{
if (movex > 0) movex -= 1;
if (movex < 0) movex += 1;
}
//movement based on acel/decel
hspeed = movex;
vspeed = movey;
//shooting
if (keyshoot) && (shootdelay = 0)
{
//basic weapon
if (weap = 0)
{
bb = instance_create_depth(x+10,y,depth+1,o_bullet);
bb.master = self;
bb.direction = 0;
bb.speed = 25;
shootdelay = 2;
}
//multi-shot
if (weap = 1)
{
bb1 = instance_create_depth(x+10,y,depth+1,o_bullet);
bb2 = instance_create_depth(x+10,y,depth+1,o_bullet);
bb3 = instance_create_depth(x+10,y,depth+1,o_bullet);
bb1.master = self;
bb2.master = self;
bb3.master = self;
with (bb1)
{
direction = 0;
speed = 25;
}
with (bb2)
{
direction = 8;
speed = 25;
}
with (bb3)
{
direction = -8;
speed = 25;
}
shootdelay = 5;
}
}
//check shoot delay
if (shootdelay > 0)
{
shootdelay -= 1;
}
//weapon cycling
if (keyweap)
{
if (weap < weapmax)
{
weap += 1;
}
else
{
weap = 0;
}
}
Thanks!