Grab a constant value from a changing variable? (urgent, please help ASAP)
in
Programming Questions
•
2 years ago
Hi, I've been really frustrated trying to figure out what I need to do in this situation. Say I have an int y, and currently y = 50. I need to store that 50 in a new variable, let's say v. If I do int v = y, then if y changes to 100, so does v. How do I grab the current value of y and store it in v, so that v stays as 50 even if y changes to a different value?
I'm making a space shooting game and I've figured out mostly everything I need to, the problem is I can't figure out how to shoot in a straight line. The cursor moves vertically when pressing w or s and the missiles shoot horizontally when pressing d. when I press 'd', I want a missile to traverse across the screen from left to right in a straight line. However, if I change the position of the cursor, the missile's vertical coordinate changes to match the cursor. Initially I want the missile to be in the same Y coordinate as the cursor, but if the cursor's Y coordinate changes, the missile's must stay the same. I'm stumped and trying to get this working the day before this project is due and I also have another final to study for. Can anyone help me?
I'm making a space shooting game and I've figured out mostly everything I need to, the problem is I can't figure out how to shoot in a straight line. The cursor moves vertically when pressing w or s and the missiles shoot horizontally when pressing d. when I press 'd', I want a missile to traverse across the screen from left to right in a straight line. However, if I change the position of the cursor, the missile's vertical coordinate changes to match the cursor. Initially I want the missile to be in the same Y coordinate as the cursor, but if the cursor's Y coordinate changes, the missile's must stay the same. I'm stumped and trying to get this working the day before this project is due and I also have another final to study for. Can anyone help me?
1