Hi! I was user “GiantSpider” who made two other posts a few weeks ago, but my login didn’t work for the new forum so I’m just using Google now.
I want to try to resolve my issue without posting all my code if possible - better for both you and me. But here is the “shoot qi blast” method where I create the projectile object:
Blockquote
(not sure how to use this new forum’s code quoting thingie)
protected void shoot_qb(int x, int y, double dir, Mob mob, Mouse mouse) {
if (qb_charging == false) {
Projectile p = new QiBlast(x, y, dir, mob, mouse);
projectiles.add§;
}
}
For some reason if I click the mouse to shoot blasts quickly sometimes I instead shoot one, two, or even three extra blasts. The weird thing - which may be a hint to the solution - is that while one of the blasts always fires in the direction the character is facing, the other ones fire off in random directions. I don’t even know how that’s possible given how my code is put together. In the update function for the qi blast I have:
Blockquote
dx = getx - (Game.screen_width / 2);
dy = gety - (Game.screen_height / 2);
angle = Math.atan2(dy, dx);
nx = speed * Math.cos(angle);
ny = speed * Math.sin(angle);
and
Blockquote
x += nx;
y += ny;
getx and gety are the mouse pointer locations on the screen. The player is in the middle of the screen so you can surmise what the rest means. I’ll probably post more code but I think this should be enough for someone more experienced to know what is going wrong. I’ll keep at it but I’ve been stuck on this for awhile. You are only supposed to charge and shoot one blast at a time, and it shoots toward the mouse pointer from the center of the screen. You can have multiple blasts active if they have already been fired, but that’s not what’s happening here.