evildead9000 Posted September 28, 2019 Share Posted September 28, 2019 (edited) Hello all once again! I'm not quite sure how to go about implementing my next bit of code, but here goes. I have two characters on-screen; let's say A, which is at the top left of the screen and B, which is in the center of the screen. The player enters an angle to fire a projectile; let's say 45 degrees. I would like another character to appear, as if were fired by letter A, at said angle toward B. Kind of like an Artillery Duel of sorts. (the game where two cannons fire at each other from different sides of the screen using angles.) However, if the angle is incorrect the projectile will miss B. Afterwards, B will move closer to A. I was thinking that I would need to create a peek loop to check all chars on screen (or of a specific area) until A is found, then repeat for B. Once both locations are collected, get the angle of B in relation to A. Afterwards, the projectile would be poked into a location next to A and move toward B at the angle the player entered. Whew! With that said, I'm not sure I'm in the right ball park of how to implement. Please provide some feedback as to whether this is a decent approach and if not, let me know a better one. I think once I understand this, I could really move forward with my code. So far I've tested numerous different parts and have made okay progress. Thanks much! Also, is it possibly better to first get line coordinates from A to B (as if to draw a line from one to the other) to obtain the HIT angle? Then draw another line from A toward B at the angle the player entered. Edited September 28, 2019 by evildead9000 Quote Link to comment Share on other sites More sharing options...
White Flame Posted September 28, 2019 Share Posted September 28, 2019 How did A and B get onscreen in the first place? The code must have determined a location for them. Don't search the screen, keep the x/y coordinates of each from when you draw them, so you can refer back to their locations directly. 2 Quote Link to comment Share on other sites More sharing options...
evildead9000 Posted September 28, 2019 Author Share Posted September 28, 2019 True! I should've thought about that! Now at randomized placement I will store the locations. So with both coordinates what would the simplest next step be? Is the rest of my logic above decent or too many steps? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.