Hi, im fairly new to c++.I have a variable in my while loop that gets the x position of the mouse and constantly refreshes and outputs to the screen. My problem is that i want to get the exact x position wherever the mouse is when i press the 1 key,, and another value for x when i press the 2 key,, however the output of the variables i want fixed keep changing with x.heres my code:
#include <iostream>
#include <windows.h>
#include <string>
#include <fstream>
#include <math.h>
#include <conio.h>
using namespace std;
int enemyx;
int playerx;
int gameposOffset = 152;
int choice;
int key1;
int x;
int y;
int main()
{
POINT pt;
LPPOINT lpPoint;
HWND currenthwnd;
currenthwnd = GetForegroundWindow();
SetWindowPos ( currenthwnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE );
do{
SetActiveWindow(currenthwnd);
if( GetCursorPos( &pt ) != 0)
{
GetCursorPos(lpPoint);
x = (lpPoint->x)+1;
y = (lpPoint->y)+1;
}
cout << x <<","<<y;
if (key1=2){
key1=0;
playerx=x;
cout << endl << "Player pos:" << playerx;
}
system("cls");
}while(key1!=1);
return(1);
}
basically its a game i play and its supposed to tell me what degree i should put it to (im not that far in the program though) im still trying to get it to store the playerx and enemyx so that i can use my algorithim to calculate the angle to fire.
so the program should work like this in the future:
put the mouse over character,,, press 1 >> it stores that location,
put the mouse over enemy ,,, press 2 >> it stores that location,
use the algorithim i have to calculate the angle between the 2,,, i have the algorithim working,, i just need your guys help to get the storing of the location.