EasyGL Tutorial - User Input
#include <iostream.h>
#include "easygl.h"
int cx=100, int cy=100, int r=10; //Global values for our circle
//-----------------------------------------------------------
void Keyboard(); //Function
we will make to handel input
//------------------------------------------------------------
//------------------------------------------------------------
void EasyRender()
{
clearGraph();
//Setup a nice looking background
color(0.0, 0.2, 0.5, 0.8);
square(50, 50, 550, 550);
square(300, 300, 800, 800, 0.0, 0.5, 1.0, 0.6);
color(0.05, 0.1, 0.8, 0.8);
circle(cx, cy, r);
Keyboard(); //Call
Keyboard to check and act on input
update();
}
//------------------------------------------------------------
//------------------------------------------------------------
void Keyboard()
{
//Check to see if the key is down, and if so move
the circle
if(GetAsyncKeyState('W')) cy-=3;
//Move up
if(GetAsyncKeyState('S')) cy+=3;
//Move down
if(GetAsyncKeyState('A')) cx-=3;
//Move left
if(GetAsyncKeyState('D')) cx+=3;
//Move right
}
//------------------------------------------------------------
//------------------------------------------------------------
int main()
{
initEasyGL();
return 1;
}
//------------------------------------------------------------
/* Note: Keys that do not have a ASCII value are a numeric representation
ex/ the arrow keys are often used in gaming instead of W,S,A, and
D
To check these Keys you simply use the following
VK_UP = up arrow
VK_DOWN
VK_RIGHT
VK_LEFT
ex: GetAsyncKeyState(VK_UP);
other definitions can be found in the MSDN help file
*/