Hey guys,
In my game I’ve been trying to shoot a fireball. So far I’ve been successful in getting it to shoot from the character, but I’ve run into a little problem. I have two variables for my player’s location, playerX and playerY, and when you move these are overwritten based on which key you hit (Ex. right = playerX += 25). The problem i’m having is that the fireball draws from the original X and Y, where the character is originally drawn in, not the new X and Y coordinates from when I move. I would post the code but it’s a bit messy and lengthy. Any suggestions? ???
P.S. I’m pretty fluent in Java, but still a begginner in Game development so anything helps
I think what he is saying is that the fireball is made where the players starting x and starting y is. I would have to see the code, but others might be able to help you.
So what your saying (Example):
Let’s say you have a 40x40 sprite for your player.
Lets say you’re shooting always to the right.
First of all, decrease that gargantious amount of movement from twenty five, to a way smaller number, otherwyse if you add collision for example, your player will just HOP through the X/Y you said he couldnt.
After you’ve fixed that huge hop of X/Y increment we can work:
Of course you’re going to want to draw it off of the playerX + like 3 (So it appears infront of him), now for the playerY:
int startingBulletX = Player.getX() + 3;
int startingBulletY = Player.getY() + Player.getHeight() / 2 - Bullet.getHeight();
So it appears infront of the player, and DIRECTLY in the center of the player - the bullets height, now I still have yet myself figure out how to change the bullets direction, based off of the players current direction of travel, i’ve gotten to the point where it’s implemented, but if the player moves the bullets direction changes.
And so…
Hoping this helps in some way, hoping it isn’t 100% irrelevant to what you need.
If it is just rephrase the question, and throw some code snippets out.